From e518a8f3f9aaa62f8bddacd08208990b7fd59e59 Mon Sep 17 00:00:00 2001 From: Krzysztof Gibala Date: Sun, 6 Feb 2022 14:45:13 +0000 Subject: [PATCH] Add debug flag ForceExtendedUSMBufferSize Forces extended buffer size by adding pageSize specify by number when debug flag is >=1 in: - clHostMemAllocINTEL - clDeviceMemAllocINTEL - clSharedMemAllocINTEL Usage: ForceExtendedUSMBufferSize=2 size += (2 * pageSize) Signed-off-by: Krzysztof Gibala --- opencl/source/api/api.cpp | 14 ++++- .../api/cl_unified_shared_memory_tests.inl | 58 +++++++++++++++++++ .../test/unit_test/test_files/igdrcl.config | 1 + .../debug_settings/debug_variables_base.inl | 1 + 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/opencl/source/api/api.cpp b/opencl/source/api/api.cpp index cdf11c9bf6..c25ead07df 100644 --- a/opencl/source/api/api.cpp +++ b/opencl/source/api/api.cpp @@ -3799,9 +3799,11 @@ void *clHostMemAllocINTEL( size_t size, cl_uint alignment, cl_int *errcodeRet) { + if (DebugManager.flags.ForceExtendedUSMBufferSize.get() >= 1) { + size += (MemoryConstants::pageSize * DebugManager.flags.ForceExtendedUSMBufferSize.get()); + } Context *neoContext = nullptr; - ErrorCodeHelper err(errcodeRet, CL_SUCCESS); auto retVal = validateObjects(WithCastToInternal(context, &neoContext)); @@ -3838,9 +3840,12 @@ void *clDeviceMemAllocINTEL( size_t size, cl_uint alignment, cl_int *errcodeRet) { + if (DebugManager.flags.ForceExtendedUSMBufferSize.get() >= 1) { + size += (MemoryConstants::pageSize * DebugManager.flags.ForceExtendedUSMBufferSize.get()); + } + Context *neoContext = nullptr; ClDevice *neoDevice = nullptr; - ErrorCodeHelper err(errcodeRet, CL_SUCCESS); auto retVal = validateObjects(WithCastToInternal(context, &neoContext), WithCastToInternal(device, &neoDevice)); @@ -3883,8 +3888,11 @@ void *clSharedMemAllocINTEL( size_t size, cl_uint alignment, cl_int *errcodeRet) { - Context *neoContext = nullptr; + if (DebugManager.flags.ForceExtendedUSMBufferSize.get() >= 1) { + size += (MemoryConstants::pageSize * DebugManager.flags.ForceExtendedUSMBufferSize.get()); + } + Context *neoContext = nullptr; ErrorCodeHelper err(errcodeRet, CL_SUCCESS); auto retVal = validateObjects(WithCastToInternal(context, &neoContext)); diff --git a/opencl/test/unit_test/api/cl_unified_shared_memory_tests.inl b/opencl/test/unit_test/api/cl_unified_shared_memory_tests.inl index e88e0202bc..bc453018f0 100644 --- a/opencl/test/unit_test/api/cl_unified_shared_memory_tests.inl +++ b/opencl/test/unit_test/api/cl_unified_shared_memory_tests.inl @@ -47,6 +47,64 @@ TEST(clUnifiedSharedMemoryTests, whenClHostMemAllocIntelIsCalledThenItAllocatesH EXPECT_EQ(CL_SUCCESS, retVal); } +TEST(clUnifiedSharedMemoryTests, GivenForceExtendedUSMBufferSizeDebugFlagWhenUSMAllocationIsCreatedThenSizeIsProperlyExtended) { + DebugManagerStateRestore restorer; + + MockContext mockContext; + auto device = mockContext.getDevice(0u); + REQUIRE_SVM_OR_SKIP(device); + + constexpr auto bufferSize = 16; + auto pageSizeNumber = 2; + DebugManager.flags.ForceExtendedUSMBufferSize.set(pageSizeNumber); + auto extendedBufferSize = bufferSize + MemoryConstants::pageSize * pageSizeNumber; + + cl_int retVal = CL_SUCCESS; + auto usmAllocation = clHostMemAllocINTEL(&mockContext, nullptr, bufferSize, 0, &retVal); + EXPECT_EQ(CL_SUCCESS, retVal); + ASSERT_NE(nullptr, usmAllocation); + + auto allocationsManager = mockContext.getSVMAllocsManager(); + EXPECT_EQ(1u, allocationsManager->getNumAllocs()); + auto graphicsAllocation = allocationsManager->getSVMAlloc(usmAllocation); + EXPECT_EQ(graphicsAllocation->size, extendedBufferSize); + + retVal = clMemFreeINTEL(&mockContext, usmAllocation); + EXPECT_EQ(CL_SUCCESS, retVal); + + pageSizeNumber = 4; + DebugManager.flags.ForceExtendedUSMBufferSize.set(pageSizeNumber); + extendedBufferSize = bufferSize + MemoryConstants::pageSize * pageSizeNumber; + + usmAllocation = clDeviceMemAllocINTEL(&mockContext, mockContext.getDevice(0u), nullptr, bufferSize, 0, &retVal); + EXPECT_EQ(CL_SUCCESS, retVal); + ASSERT_NE(nullptr, usmAllocation); + + allocationsManager = mockContext.getSVMAllocsManager(); + EXPECT_EQ(1u, allocationsManager->getNumAllocs()); + graphicsAllocation = allocationsManager->getSVMAlloc(usmAllocation); + EXPECT_EQ(graphicsAllocation->size, extendedBufferSize); + + retVal = clMemFreeINTEL(&mockContext, usmAllocation); + EXPECT_EQ(CL_SUCCESS, retVal); + + pageSizeNumber = 8; + DebugManager.flags.ForceExtendedUSMBufferSize.set(pageSizeNumber); + extendedBufferSize = bufferSize + MemoryConstants::pageSize * pageSizeNumber; + + usmAllocation = clSharedMemAllocINTEL(&mockContext, nullptr, nullptr, bufferSize, 0, &retVal); + EXPECT_EQ(CL_SUCCESS, retVal); + ASSERT_NE(nullptr, usmAllocation); + + allocationsManager = mockContext.getSVMAllocsManager(); + EXPECT_EQ(1u, allocationsManager->getNumAllocs()); + graphicsAllocation = allocationsManager->getSVMAlloc(usmAllocation); + EXPECT_EQ(graphicsAllocation->size, extendedBufferSize); + + retVal = clMemFreeINTEL(&mockContext, usmAllocation); + EXPECT_EQ(CL_SUCCESS, retVal); +} + TEST(clUnifiedSharedMemoryTests, givenMappedAllocationWhenClMemFreeIntelIscalledThenMappingIsRemoved) { MockContext mockContext; diff --git a/opencl/test/unit_test/test_files/igdrcl.config b/opencl/test/unit_test/test_files/igdrcl.config index e743083b99..7b5f2b7ef3 100644 --- a/opencl/test/unit_test/test_files/igdrcl.config +++ b/opencl/test/unit_test/test_files/igdrcl.config @@ -367,6 +367,7 @@ UseDrmCompletionFenceForAllAllocations = -1 ExperimentalEnableSourceLevelDebugger = 0 Force2dImageAsArray = -1 ForceExtendedBufferSize = -1 +ForceExtendedUSMBufferSize = -1 MakeIndirectAllocationsResidentAsPack = -1 EnableChipsetUniqueUUID = -1 ForceSimdMessageSizeInWalker = -1 diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index 25fcb2853e..18557d5ca9 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -178,6 +178,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, EngineUsageHint, -1, "-1: default, >=0: engine u DECLARE_DEBUG_VARIABLE(int32_t, ForceBcsEngineIndex, -1, "-1: default, >=0 Copy Engine index") DECLARE_DEBUG_VARIABLE(int32_t, Force2dImageAsArray, -1, "-1: default, 0: WA Disabled, 1: Forces surface state of 2dImage to array") DECLARE_DEBUG_VARIABLE(int32_t, ForceExtendedBufferSize, -1, "-1: default, 0: disabled, >=1: Forces extended buffer size by specify pageSize number in clCreateBuffer, clCreateBufferWithProperties and clCreateBufferWithPropertiesINTEL calls") +DECLARE_DEBUG_VARIABLE(int32_t, ForceExtendedUSMBufferSize, -1, "-1: default, 0: disabled, >=1: Forces extended buffer size by specify pageSize number in clHostMemAllocINTEL, clDeviceMemAllocINTEL and clSharedMemAllocINTEL calls") DECLARE_DEBUG_VARIABLE(int32_t, ForceSimdMessageSizeInWalker, -1, "-1: default, >=0 Program given value in Walker command for SIMD size") /*LOGGING FLAGS*/ DECLARE_DEBUG_VARIABLE(int32_t, PrintDriverDiagnostics, -1, "prints driver diagnostics messages to standard output, value corresponds to hint level")