Add AllowUnrestrictedSize debug flag

This debug flag allows to allocate memory with size greater than
CL_DEVICE_MAX_MEM_ALLOC_SIZE.

Signed-off-by: Szymon Morek <szymon.morek@intel.com>
This commit is contained in:
Szymon Morek 2021-08-05 10:10:20 +00:00 committed by Compute-Runtime-Automation
parent ec28084ed4
commit 3c15023871
8 changed files with 79 additions and 3 deletions

View File

@ -4457,7 +4457,7 @@ void *CL_API_CALL clSVMAlloc(cl_context context,
}
auto pDevice = pContext->getDevice(0);
bool allowUnrestrictedSize = (flags & CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL);
bool allowUnrestrictedSize = (flags & CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL) || DebugManager.flags.AllowUnrestrictedSize.get();
if ((size == 0) ||
(!allowUnrestrictedSize && (size > pDevice->getSharedDeviceInfo().maxMemAllocSize))) {

View File

@ -59,7 +59,8 @@ MemoryProperties MemoryPropertiesHelper::createMemoryProperties(cl_mem_flags fla
memoryProperties.flags.noAccess = true;
}
if (isValueSet(flags, CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL) ||
isValueSet(flagsIntel, CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL)) {
isValueSet(flagsIntel, CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL) ||
DebugManager.flags.AllowUnrestrictedSize.get()) {
memoryProperties.flags.allowUnrestrictedSize = true;
}
if (isValueSet(flagsIntel, CL_MEM_LOCALLY_UNCACHED_RESOURCE)) {

View File

@ -124,7 +124,8 @@ cl_mem Buffer::validateInputAndCreateBuffer(cl_context context,
auto pDevice = pContext->getDevice(0);
bool allowCreateBuffersWithUnrestrictedSize = isValueSet(flags, CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL) ||
isValueSet(flagsIntel, CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL);
isValueSet(flagsIntel, CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL) ||
DebugManager.flags.AllowUnrestrictedSize.get();
if (size == 0 || (size > pDevice->getDevice().getDeviceInfo().maxMemAllocSize && !allowCreateBuffersWithUnrestrictedSize)) {
retVal = CL_INVALID_BUFFER_SIZE;

View File

@ -278,6 +278,26 @@ TEST_F(clCreateBufferTests, GivenBufferSizeOverMaxMemAllocSizeAndClMemAllowUnres
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST_F(clCreateBufferTests, GivenBufferSizeOverMaxMemAllocSizeAndDebugFlagSetWhenCreatingBufferThenClSuccessIsReturned) {
DebugManagerStateRestore restorer;
DebugManager.flags.AllowUnrestrictedSize.set(1);
auto pDevice = pContext->getDevice(0);
size_t size = static_cast<size_t>(pDevice->getDevice().getDeviceInfo().maxMemAllocSize) + 1;
auto memoryManager = static_cast<OsAgnosticMemoryManager *>(pDevice->getMemoryManager());
memoryManager->turnOnFakingBigAllocations();
if (memoryManager->peekForce32BitAllocations() || is32bit) {
GTEST_SKIP();
}
auto buffer = clCreateBuffer(pContext, 0, size, nullptr, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_NE(nullptr, buffer);
retVal = clReleaseMemObject(buffer);
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST_F(clCreateBufferTests, GivenNullHostPointerAndMemCopyHostPtrFlagWhenCreatingBufferThenNullIsReturned) {
cl_mem_flags flags = CL_MEM_USE_HOST_PTR;
static const unsigned int bufferSize = 16;

View File

@ -222,6 +222,15 @@ TEST_F(clSVMAllocTests, givenUnrestrictedFlagWhenCreatingSvmAllocThenAllowSizeBi
clSVMFree(pContext, svmPtr);
}
{
// debug flag + not allowed size
DebugManagerStateRestore restorer;
DebugManager.flags.AllowUnrestrictedSize.set(1);
svmPtr = clSVMAlloc(pContext, 0, notAllowedSize, 0);
EXPECT_NE(nullptr, svmPtr);
clSVMFree(pContext, svmPtr);
}
{
// unrestricted size flag + allowed size
svmPtr = clSVMAlloc(pContext, flags, allowedSize, 0);

View File

@ -1041,6 +1041,49 @@ TEST(clUnifiedSharedMemoryTests, givenUnifiedMemoryAllocationSizeGreaterThanMaxM
}
}
TEST(clUnifiedSharedMemoryTests, givenUnifiedMemoryAllocationSizeGreaterThanMaxMemAllocSizeAndDebugFlagSetWhenCreateAllocationThenSuccesIsReturned) {
DebugManagerStateRestore restorer;
DebugManager.flags.AllowUnrestrictedSize.set(1);
MockContext mockContext;
cl_int retVal = CL_SUCCESS;
auto allocationSize = static_cast<size_t>(mockContext.getDevice(0u)->getSharedDeviceInfo().maxMemAllocSize) + 1;
auto memoryManager = static_cast<OsAgnosticMemoryManager *>(mockContext.getDevice(0u)->getMemoryManager());
memoryManager->turnOnFakingBigAllocations();
if (memoryManager->peekForce32BitAllocations() || is32bit) {
GTEST_SKIP();
}
{
auto unfiedMemoryAllocation = clDeviceMemAllocINTEL(&mockContext, mockContext.getDevice(0u), 0, allocationSize, 0, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, unfiedMemoryAllocation);
retVal = clMemFreeINTEL(&mockContext, unfiedMemoryAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
}
{
auto unfiedMemoryAllocation = clSharedMemAllocINTEL(&mockContext, mockContext.getDevice(0u), 0, allocationSize, 0, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, unfiedMemoryAllocation);
retVal = clMemFreeINTEL(&mockContext, unfiedMemoryAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
}
{
auto unfiedMemoryAllocation = clHostMemAllocINTEL(&mockContext, 0, allocationSize, 0, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, unfiedMemoryAllocation);
retVal = clMemFreeINTEL(&mockContext, unfiedMemoryAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
}
}
TEST(clUnifiedSharedMemoryTests, givenUnifiedMemoryAllocationSizeGreaterThanMaxMemAllocSizeWhenCreateAllocationThenErrorIsReturned) {
MockContext mockContext;
cl_int retVal = CL_SUCCESS;

View File

@ -316,3 +316,4 @@ OverrideSystolicPipelineSelect = -1
OverrideSystolicInComputeWalker = -1
OverrideKernelSizeLimitForSmallDispatch = -1
SkipFlushingEventsOnGetStatusCalls = 0
AllowUnrestrictedSize = 0

View File

@ -332,3 +332,4 @@ DECLARE_DEBUG_VARIABLE(bool, UseCommandBufferHeaderSizeForWddmQueueSubmission, t
DECLARE_DEBUG_VARIABLE(bool, DisableDeepBind, false, "Disable passing RTLD_DEEPBIND flag to all dlopen calls.")
DECLARE_DEBUG_VARIABLE(bool, UseUmKmDataTranslator, false, "Use helper library for UMD<->KMD (WDDM) struct layout compatibility")
DECLARE_DEBUG_VARIABLE(bool, SkipFlushingEventsOnGetStatusCalls, false, "When set to 1, events are not causing internal flush when querying for CL_EVENT_COMMAND_EXECUTION_STATUS")
DECLARE_DEBUG_VARIABLE(bool, AllowUnrestrictedSize, false, "Allow allocating memory with greater size than MAX_MEM_ALLOC_SIZE")