diff --git a/runtime/api/api.cpp b/runtime/api/api.cpp index 2375407618..5617c89066 100644 --- a/runtime/api/api.cpp +++ b/runtime/api/api.cpp @@ -3467,6 +3467,10 @@ cl_int clMemFreeINTEL( return CL_INVALID_VALUE; } + if (neoContext->getSVMAllocsManager()->getSvmMapOperation(ptr)) { + neoContext->getSVMAllocsManager()->removeSvmMapOperation(ptr); + } + return CL_SUCCESS; } diff --git a/unit_tests/api/cl_unified_shared_memory_tests.inl b/unit_tests/api/cl_unified_shared_memory_tests.inl index 3b2c96d79e..a55d232613 100644 --- a/unit_tests/api/cl_unified_shared_memory_tests.inl +++ b/unit_tests/api/cl_unified_shared_memory_tests.inl @@ -38,6 +38,22 @@ TEST(clUnifiedSharedMemoryTests, whenClHostMemAllocIntelIsCalledThenItAllocatesH EXPECT_EQ(CL_SUCCESS, retVal); } +TEST(clUnifiedSharedMemoryTests, givenMappedAllocationWhenClMemFreeIntelIscalledThenMappingIsRemoved) { + + MockContext mockContext; + cl_int retVal = CL_SUCCESS; + auto unifiedMemorySharedAllocation = clSharedMemAllocINTEL(&mockContext, mockContext.getDevice(0u), nullptr, 4, 0, &retVal); + EXPECT_EQ(CL_SUCCESS, retVal); + ASSERT_NE(nullptr, unifiedMemorySharedAllocation); + + auto allocationsManager = mockContext.getSVMAllocsManager(); + allocationsManager->insertSvmMapOperation(unifiedMemorySharedAllocation, 4u, unifiedMemorySharedAllocation, 0u, false); + + retVal = clMemFreeINTEL(&mockContext, unifiedMemorySharedAllocation); + EXPECT_EQ(CL_SUCCESS, retVal); + EXPECT_EQ(nullptr, allocationsManager->getSvmMapOperation(unifiedMemorySharedAllocation)); +} + TEST(clUnifiedSharedMemoryTests, whenClDeviceMemAllocINTELisCalledWithWrongContextThenInvalidContextErrorIsReturned) { cl_int retVal = CL_SUCCESS; auto ptr = clDeviceMemAllocINTEL(0, 0, nullptr, 0, 0, &retVal);