diff --git a/opencl/source/mem_obj/mem_obj.cpp b/opencl/source/mem_obj/mem_obj.cpp index e31c75d2a8..0665cbf0d1 100644 --- a/opencl/source/mem_obj/mem_obj.cpp +++ b/opencl/source/mem_obj/mem_obj.cpp @@ -94,6 +94,8 @@ MemObj::~MemObj() { } destroyGraphicsAllocation(graphicsAllocation, doAsyncDestructions); graphicsAllocation = nullptr; + } else if (graphicsAllocation && context->getBufferPoolAllocator().isPoolBuffer(associatedMemObject)) { + memoryManager->waitForEnginesCompletion(*graphicsAllocation); } if (!associatedMemObject) { releaseMapAllocation(rootDeviceIndex, doAsyncDestructions); diff --git a/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp b/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp index 0e09610a28..0ebed29e04 100644 --- a/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp +++ b/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp @@ -115,6 +115,25 @@ TEST_F(aggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledAndS EXPECT_EQ(retVal, CL_SUCCESS); } +TEST_F(aggregatedSmallBuffersEnabledTest, givenAggregatedSmallBuffersEnabledWhenClReleaseMemObjectCalledThenWaitForEnginesCompletionCalled) { + ASSERT_TRUE(poolAllocator->isAggregatedSmallBuffersEnabled()); + ASSERT_NE(poolAllocator->mainStorage, nullptr); + std::unique_ptr buffer(Buffer::create(context.get(), flags, size, hostPtr, retVal)); + + ASSERT_NE(buffer, nullptr); + ASSERT_EQ(retVal, CL_SUCCESS); + + ASSERT_NE(poolAllocator->mainStorage, nullptr); + auto mockBuffer = static_cast(buffer.get()); + ASSERT_TRUE(mockBuffer->isSubBuffer()); + ASSERT_EQ(poolAllocator->mainStorage, mockBuffer->associatedMemObject); + + ASSERT_EQ(mockMemoryManager->waitForEnginesCompletionCalled, 0u); + retVal = clReleaseMemObject(buffer.release()); + ASSERT_EQ(retVal, CL_SUCCESS); + EXPECT_EQ(mockMemoryManager->waitForEnginesCompletionCalled, 1u); +} + TEST_F(aggregatedSmallBuffersEnabledTest, givenCopyHostPointerWhenCreatingBufferButCopyFailedThenDoNotUsePool) { class MockCommandQueueFailFirstEnqueueWrite : public MockCommandQueue { public: