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 <krzysztof.gibala@intel.com>
This commit is contained in:
Krzysztof Gibala
2022-02-06 14:45:13 +00:00
committed by Compute-Runtime-Automation
parent f02b6cd521
commit e518a8f3f9
4 changed files with 71 additions and 3 deletions

View File

@ -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));

View File

@ -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;

View File

@ -367,6 +367,7 @@ UseDrmCompletionFenceForAllAllocations = -1
ExperimentalEnableSourceLevelDebugger = 0
Force2dImageAsArray = -1
ForceExtendedBufferSize = -1
ForceExtendedUSMBufferSize = -1
MakeIndirectAllocationsResidentAsPack = -1
EnableChipsetUniqueUUID = -1
ForceSimdMessageSizeInWalker = -1

View File

@ -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")