diff --git a/opencl/source/mem_obj/mem_obj.cpp b/opencl/source/mem_obj/mem_obj.cpp index 01b891872d..b02326796a 100644 --- a/opencl/source/mem_obj/mem_obj.cpp +++ b/opencl/source/mem_obj/mem_obj.cpp @@ -13,7 +13,6 @@ #include "shared/source/helpers/get_info.h" #include "shared/source/memory_manager/allocation_properties.h" #include "shared/source/memory_manager/memory_manager.h" -#include "shared/source/memory_manager/memory_pool.h" #include "shared/source/utilities/buffer_pool_allocator.inl" #include "shared/source/utilities/heap_allocator.h" @@ -436,7 +435,8 @@ bool MemObj::isTiledAllocation() const { bool MemObj::mappingOnCpuAllowed() const { auto graphicsAllocation = multiGraphicsAllocation.getDefaultGraphicsAllocation(); return !isTiledAllocation() && !peekSharingHandler() && !isMipMapped(this) && !DebugManager.flags.DisableZeroCopyForBuffers.get() && - !graphicsAllocation->isCompressionEnabled() && MemoryPoolHelper::isSystemMemoryPool(graphicsAllocation->getMemoryPool()); + !graphicsAllocation->isCompressionEnabled() && MemoryPoolHelper::isSystemMemoryPool(graphicsAllocation->getMemoryPool()) && + allowCpuAccess(); } bool MemObj::allowCpuAccess() const { diff --git a/opencl/test/unit_test/mem_obj/mem_obj_tests.cpp b/opencl/test/unit_test/mem_obj/mem_obj_tests.cpp index 06e1436f65..460e4f5ac8 100644 --- a/opencl/test/unit_test/mem_obj/mem_obj_tests.cpp +++ b/opencl/test/unit_test/mem_obj/mem_obj_tests.cpp @@ -348,6 +348,10 @@ TEST(MemObj, givenDefaultWhenAskedForCpuMappingThenReturnTrue) { EXPECT_TRUE(memObj.mappingOnCpuAllowed()); } +struct MyMockGmm : Gmm { + using Gmm::Gmm; + using Gmm::preferNoCpuAccess; +}; TEST(MemObj, givenCpuAccessNotAllowedWhenAskedForCpuMappingThenReturnFalse) { DebugManagerStateRestore dbgRestore; DebugManager.flags.EnableCpuCacheForResources.set(true); @@ -361,9 +365,10 @@ TEST(MemObj, givenCpuAccessNotAllowedWhenAskedForCpuMappingThenReturnFalse) { auto memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_COPY_HOST_PTR, 0, 0, &context.getDevice(0)->getDevice()); MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_COPY_HOST_PTR, 0, 64, allocation->getUnderlyingBuffer(), nullptr, GraphicsAllocationHelper::toMultiGraphicsAllocation(allocation), true, false, false); - + allocation->setDefaultGmm(new MyMockGmm(context.getDevice(0)->getGmmHelper(), nullptr, 1, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, false, {}, true)); EXPECT_TRUE(memObj.mappingOnCpuAllowed()); - static_cast(allocation)->overrideMemoryPool(MemoryPool::SystemCpuInaccessible); + + static_cast(memObj.getGraphicsAllocation(0)->getDefaultGmm())->preferNoCpuAccess = true; EXPECT_FALSE(memObj.mappingOnCpuAllowed()); }