diff --git a/runtime/program/program.cpp b/runtime/program/program.cpp index 39621acaff..5f3eafb427 100644 --- a/runtime/program/program.cpp +++ b/runtime/program/program.cpp @@ -413,7 +413,7 @@ void Program::freeBlockResources() { void Program::cleanCurrentKernelInfo() { for (auto &kernelInfo : kernelInfoArray) { if (kernelInfo->kernelAllocation) { - this->pDevice->getMemoryManager()->freeGraphicsMemory(kernelInfo->kernelAllocation); + this->pDevice->getMemoryManager()->checkGpuUsageAndDestroyGraphicsAllocations(kernelInfo->kernelAllocation); } delete kernelInfo; } diff --git a/unit_tests/program/program_tests.cpp b/unit_tests/program/program_tests.cpp index c76509687e..1c54f9ff4e 100644 --- a/unit_tests/program/program_tests.cpp +++ b/unit_tests/program/program_tests.cpp @@ -627,6 +627,19 @@ TEST_P(ProgramFromBinaryTest, givenProgramWhenCleanKernelInfoIsCalledThenKernelA EXPECT_EQ(0u, pProgram->getNumKernels()); } +TEST_P(ProgramFromBinaryTest, givenProgramWhenCleanCurrentKernelInfoIsCalledButGpuIsNotYetDoneThenKernelAllocationIsPutOnDefferedFreeList) { + cl_device_id device = pDevice; + auto memoryManager = pDevice->getMemoryManager(); + EXPECT_TRUE(memoryManager->graphicsAllocations.peekIsEmpty()); + pProgram->build(1, &device, nullptr, nullptr, nullptr, true); + auto kernelAllocation = pProgram->getKernelInfo(size_t(0))->getGraphicsAllocation(); + kernelAllocation->taskCount = 100; + *pDevice->getTagAddress() = 0; + pProgram->cleanCurrentKernelInfo(); + EXPECT_FALSE(memoryManager->graphicsAllocations.peekIsEmpty()); + EXPECT_EQ(memoryManager->graphicsAllocations.peekHead(), kernelAllocation); +} + //////////////////////////////////////////////////////////////////////////////// // Program::Build (source) ////////////////////////////////////////////////////////////////////////////////