diff --git a/opencl/source/mem_obj/buffer.cpp b/opencl/source/mem_obj/buffer.cpp index 76e284b4d8..3b4ba5d38b 100644 --- a/opencl/source/mem_obj/buffer.cpp +++ b/opencl/source/mem_obj/buffer.cpp @@ -106,6 +106,10 @@ cl_mem Buffer::validateInputAndCreateBuffer(cl_context context, return nullptr; } + if ((flags & CL_MEM_USE_HOST_PTR) && !!debugManager.flags.ForceZeroCopyForUseHostPtr.get()) { + flags |= CL_MEM_FORCE_HOST_MEMORY_INTEL; + } + MemoryProperties memoryProperties{}; cl_mem_alloc_flags_intel allocflags = 0; cl_mem_flags_intel emptyFlagsIntel = 0; diff --git a/opencl/test/unit_test/mem_obj/buffer_tests.cpp b/opencl/test/unit_test/mem_obj/buffer_tests.cpp index 3fd4fad4f7..d45f3d9309 100644 --- a/opencl/test/unit_test/mem_obj/buffer_tests.cpp +++ b/opencl/test/unit_test/mem_obj/buffer_tests.cpp @@ -1292,6 +1292,35 @@ TEST_P(ValidHostPtr, WhenValidateInputAndCreateBufferThenCorrectBufferIsSet) { clReleaseMemObject(buffer); } +using SingleBufferTest = Test; +TEST_F(SingleBufferTest, givenUseHostPtrFlagWhenForceZeroCopyFlagIsSetThenAddForceHostMemoryFlag) { + auto context = std::make_unique(pClDevice); + cl_int retVal = CL_SUCCESS; + unsigned char pHostPtr[testBufferSizeInBytes]; + { + cl_mem_flags flags = CL_MEM_USE_HOST_PTR; + auto buffer = BufferFunctions::validateInputAndCreateBuffer(context.get(), nullptr, flags, 0, testBufferSizeInBytes, pHostPtr, retVal); + EXPECT_EQ(retVal, CL_SUCCESS); + EXPECT_NE(nullptr, buffer); + auto neoBuffer = castToObject(buffer); + EXPECT_FALSE(neoBuffer->getFlags() & CL_MEM_FORCE_HOST_MEMORY_INTEL); + + clReleaseMemObject(buffer); + } + { + DebugManagerStateRestore restorer; + debugManager.flags.ForceZeroCopyForUseHostPtr.set(1); + cl_mem_flags flags = CL_MEM_USE_HOST_PTR; + auto buffer = BufferFunctions::validateInputAndCreateBuffer(context.get(), nullptr, flags, 0, testBufferSizeInBytes, pHostPtr, retVal); + EXPECT_EQ(retVal, CL_SUCCESS); + EXPECT_NE(nullptr, buffer); + auto neoBuffer = castToObject(buffer); + EXPECT_TRUE(neoBuffer->getFlags() & CL_MEM_FORCE_HOST_MEMORY_INTEL); + + clReleaseMemObject(buffer); + } +} + // Parameterized test that tests buffer creation with all flags that should be // valid with a valid host ptr cl_mem_flags validHostPtrFlags[] = { diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index 56939bd552..b83e3e6155 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -367,6 +367,7 @@ DECLARE_DEBUG_VARIABLE(bool, UseNoRingFlushesKmdMode, true, "Windows only, passe DECLARE_DEBUG_VARIABLE(bool, DisableZeroCopyForUseHostPtr, false, "When active all buffer allocations created with CL_MEM_USE_HOST_PTR flag will not share memory with CPU.") DECLARE_DEBUG_VARIABLE(bool, ForceNonCoherentModeForTimestamps, false, "When active timestamp buffers are allocated in non coherent memory.") DECLARE_DEBUG_VARIABLE(bool, SetAssumeNotInUse, true, "Set AssumeNotInUse flag in d3d destroy allocation.") +DECLARE_DEBUG_VARIABLE(bool, ForceZeroCopyForUseHostPtr, false, "When active all buffer allocations created with CL_MEM_USE_HOST_PTR flag will use share memory with CPU.") DECLARE_DEBUG_VARIABLE(int32_t, EnableReusingGpuTimestamps, -1, "Reuse GPU timestamp for next device time requests. -1: os-specific, 0: disable, 1: enable") DECLARE_DEBUG_VARIABLE(int32_t, AllowZeroCopyWithoutCoherency, -1, "Use cacheline flush instead of memory copy for map/unmap mem object") DECLARE_DEBUG_VARIABLE(int32_t, EnableHostPtrTracking, -1, "Enable host ptr tracking: -1 - default platform setting, 0 - disabled, 1 - enabled") diff --git a/shared/test/common/test_files/igdrcl.config b/shared/test/common/test_files/igdrcl.config index 77eb5517c5..abf32a2e32 100644 --- a/shared/test/common/test_files/igdrcl.config +++ b/shared/test/common/test_files/igdrcl.config @@ -643,4 +643,5 @@ DirectSubmissionControllerIdleDetection = -1 DebugUmdInterruptTimeout = -1 DebugUmdMaxReadWriteRetry = -1 DirectSubmissionControllerBcsTimeoutDivisor = -1 +ForceZeroCopyForUseHostPtr = 0 # Please don't edit below this line