Add support for deferred deletion of private surface.

- If it is in use add it to temporary allocation list
- If it is not in use destroy in place

Change-Id: I6304d1a3b641243f3f7eadff8e38d8515b132f68
This commit is contained in:
Mrozek, Michal
2018-01-18 16:41:35 +01:00
committed by sys_ocldev
parent 3e84c4df7a
commit c6233e1d06
2 changed files with 41 additions and 1 deletions

View File

@ -114,7 +114,11 @@ Kernel::~Kernel() {
crossThreadDataSize = 0;
if (privateSurface) {
device.getMemoryManager()->freeGraphicsMemory(privateSurface);
if (privateSurface->taskCount == ObjectNotUsed || privateSurface->taskCount <= *device.getTagAddress()) {
device.getMemoryManager()->freeGraphicsMemory(privateSurface);
} else {
device.getMemoryManager()->storeAllocation(std::unique_ptr<GraphicsAllocation>(privateSurface), TEMPORARY_ALLOCATION);
}
privateSurface = nullptr;
}

View File

@ -511,6 +511,42 @@ TEST_F(KernelPrivateSurfaceTest, testPrivateSurface) {
delete pKernelInfo;
}
TEST_F(KernelPrivateSurfaceTest, givenKernelWithPrivateSurfaceThatIsInUseByGpuWhenKernelIsBeingDestroyedThenAllocationIsAddedToDefferedFreeList) {
std::unique_ptr<KernelInfo> pKernelInfo(KernelInfo::create());
SPatchAllocateStatelessPrivateSurface tokenSPS;
tokenSPS.SurfaceStateHeapOffset = 64;
tokenSPS.DataParamOffset = 40;
tokenSPS.DataParamSize = 8;
tokenSPS.PerThreadPrivateMemorySize = 112;
pKernelInfo->patchInfo.pAllocateStatelessPrivateSurface = &tokenSPS;
SPatchDataParameterStream tokenDPS;
tokenDPS.DataParameterStreamSize = 64;
pKernelInfo->patchInfo.dataParameterStream = &tokenDPS;
SPatchExecutionEnvironment tokenEE;
tokenEE.CompiledSIMD32 = true;
pKernelInfo->patchInfo.executionEnvironment = &tokenEE;
MockContext context;
MockProgram program(&context);
std::unique_ptr<MockKernel> pKernel(new MockKernel(&program, *pKernelInfo, *pDevice));
pKernel->initialize();
auto memoryManager = pDevice->getMemoryManager();
auto privateSurface = pKernel->getPrivateSurface();
auto tagAddress = context.getDevice(0)->getTagAddress();
privateSurface->taskCount = *tagAddress + 1;
EXPECT_TRUE(memoryManager->graphicsAllocations.peekIsEmpty());
pKernel.reset(nullptr);
EXPECT_FALSE(memoryManager->graphicsAllocations.peekIsEmpty());
EXPECT_EQ(memoryManager->graphicsAllocations.peekHead(), privateSurface);
}
TEST_F(KernelPrivateSurfaceTest, testPrivateSurfaceAllocationFailure) {
ASSERT_NE(nullptr, pDevice);