fix(ocl): allocation info from pool svm ptr

Fix querying allocation info from pooled svm ptr.
Handle requested allocation alignment.
Refactor sorted vector usage.
Do not associate device with host pool allocation.

Related-To: NEO-9700

Signed-off-by: Dominik Dabek <dominik.dabek@intel.com>
This commit is contained in:
Dominik Dabek
2024-01-03 13:15:24 +00:00
committed by Compute-Runtime-Automation
parent bbb8193be7
commit af1620a308
9 changed files with 309 additions and 59 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -4110,12 +4110,24 @@ CL_API_ENTRY cl_int CL_API_CALL clGetMemAllocInfoINTEL(
if (!unifiedMemoryAllocation) {
return changeGetInfoStatusToCLResultType(info.set<void *>(nullptr));
}
if (auto basePtrFromDevicePool = pContext->getDeviceMemAllocPool().getPooledAllocationBasePtr(ptr)) {
return changeGetInfoStatusToCLResultType(info.set<uint64_t>(castToUint64(basePtrFromDevicePool)));
}
if (auto basePtrFromHostPool = pContext->getHostMemAllocPool().getPooledAllocationBasePtr(ptr)) {
return changeGetInfoStatusToCLResultType(info.set<uint64_t>(castToUint64(basePtrFromHostPool)));
}
return changeGetInfoStatusToCLResultType(info.set<uint64_t>(unifiedMemoryAllocation->gpuAllocations.getDefaultGraphicsAllocation()->getGpuAddress()));
}
case CL_MEM_ALLOC_SIZE_INTEL: {
if (!unifiedMemoryAllocation) {
return changeGetInfoStatusToCLResultType(info.set<size_t>(0u));
}
if (auto sizeFromDevicePool = pContext->getDeviceMemAllocPool().getPooledAllocationSize(ptr)) {
return changeGetInfoStatusToCLResultType(info.set<size_t>(sizeFromDevicePool));
}
if (auto sizeFromHostPool = pContext->getHostMemAllocPool().getPooledAllocationSize(ptr)) {
return changeGetInfoStatusToCLResultType(info.set<size_t>(sizeFromHostPool));
}
return changeGetInfoStatusToCLResultType(info.set<size_t>(unifiedMemoryAllocation->size));
}
case CL_MEM_ALLOC_FLAGS_INTEL: {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -523,7 +523,6 @@ void Context::initializeUsmAllocationPools() {
subDeviceBitfields[neoDevice.getRootDeviceIndex()] = neoDevice.getDeviceBitfield();
SVMAllocsManager::UnifiedMemoryProperties memoryProperties(InternalMemoryType::hostUnifiedMemory, MemoryConstants::pageSize2M,
getRootDeviceIndices(), subDeviceBitfields);
memoryProperties.device = &neoDevice;
usmHostMemAllocPool.initialize(svmMemoryManager, memoryProperties, poolSize);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2023 Intel Corporation
* Copyright (C) 2019-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -711,6 +711,129 @@ TEST(clUnifiedSharedMemoryTests, whenClGetMemAllocInfoINTELisCalledWithAllocatio
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST(clUnifiedSharedMemoryTests, givenSVMAllocationPoolWhenClGetMemAllocInfoINTELisCalledWithAllocationSizeParamNameThenProperFieldsAreSet) {
DebugManagerStateRestore restorer;
debugManager.flags.EnableHostUsmAllocationPool.set(2);
debugManager.flags.EnableDeviceUsmAllocationPool.set(2);
MockContext mockContext;
auto device = mockContext.getDevice(0u);
REQUIRE_SVM_OR_SKIP(device);
cl_int retVal = CL_SUCCESS;
size_t paramValueSize = sizeof(size_t);
size_t paramValue = 0;
size_t paramValueSizeRet = 0;
const size_t allocationSize = 4u;
mockContext.initializeUsmAllocationPools();
{
auto unifiedMemoryHostAllocation = clHostMemAllocINTEL(&mockContext, nullptr, allocationSize, 0, &retVal);
auto allocationsManager = mockContext.getSVMAllocsManager();
auto graphicsAllocation = allocationsManager->getSVMAlloc(unifiedMemoryHostAllocation);
retVal = clGetMemAllocInfoINTEL(&mockContext, unifiedMemoryHostAllocation, CL_MEM_ALLOC_SIZE_INTEL, paramValueSize, &paramValue, &paramValueSizeRet);
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::hostUnifiedMemory);
EXPECT_EQ(allocationSize, paramValue);
EXPECT_EQ(sizeof(size_t), paramValueSizeRet);
EXPECT_EQ(CL_SUCCESS, retVal);
retVal = clGetMemAllocInfoINTEL(&mockContext, ptrOffset(unifiedMemoryHostAllocation, allocationSize - 1), CL_MEM_ALLOC_SIZE_INTEL, paramValueSize, &paramValue, &paramValueSizeRet);
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::hostUnifiedMemory);
EXPECT_EQ(allocationSize, paramValue);
EXPECT_EQ(sizeof(size_t), paramValueSizeRet);
EXPECT_EQ(CL_SUCCESS, retVal);
retVal = clMemFreeINTEL(&mockContext, unifiedMemoryHostAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
}
{
auto unifiedMemoryDeviceAllocation = clDeviceMemAllocINTEL(&mockContext, device, nullptr, 4, 0, &retVal);
auto allocationsManager = mockContext.getSVMAllocsManager();
auto graphicsAllocation = allocationsManager->getSVMAlloc(unifiedMemoryDeviceAllocation);
retVal = clGetMemAllocInfoINTEL(&mockContext, unifiedMemoryDeviceAllocation, CL_MEM_ALLOC_SIZE_INTEL, paramValueSize, &paramValue, &paramValueSizeRet);
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::deviceUnifiedMemory);
EXPECT_EQ(allocationSize, paramValue);
EXPECT_EQ(sizeof(size_t), paramValueSizeRet);
EXPECT_EQ(CL_SUCCESS, retVal);
retVal = clGetMemAllocInfoINTEL(&mockContext, ptrOffset(unifiedMemoryDeviceAllocation, allocationSize - 1), CL_MEM_ALLOC_SIZE_INTEL, paramValueSize, &paramValue, &paramValueSizeRet);
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::deviceUnifiedMemory);
EXPECT_EQ(allocationSize, paramValue);
EXPECT_EQ(sizeof(size_t), paramValueSizeRet);
EXPECT_EQ(CL_SUCCESS, retVal);
retVal = clMemFreeINTEL(&mockContext, unifiedMemoryDeviceAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
}
}
TEST(clUnifiedSharedMemoryTests, givenSVMAllocationPoolWhenClGetMemAllocInfoINTELisCalledWithAllocationBasePtrParamNameThenProperFieldsAreSet) {
DebugManagerStateRestore restorer;
debugManager.flags.EnableHostUsmAllocationPool.set(2);
debugManager.flags.EnableDeviceUsmAllocationPool.set(2);
MockContext mockContext;
auto device = mockContext.getDevice(0u);
REQUIRE_SVM_OR_SKIP(device);
cl_int retVal = CL_SUCCESS;
size_t paramValueSize = sizeof(uint64_t);
uint64_t paramValue = 0;
size_t paramValueSizeRet = 0;
mockContext.initializeUsmAllocationPools();
{
auto unifiedMemoryHostAllocation = clHostMemAllocINTEL(&mockContext, nullptr, 4, 0, &retVal);
auto allocationsManager = mockContext.getSVMAllocsManager();
auto graphicsAllocation = allocationsManager->getSVMAlloc(unifiedMemoryHostAllocation);
retVal = clGetMemAllocInfoINTEL(&mockContext, unifiedMemoryHostAllocation, CL_MEM_ALLOC_BASE_PTR_INTEL, paramValueSize, &paramValue, &paramValueSizeRet);
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::hostUnifiedMemory);
EXPECT_EQ(unifiedMemoryHostAllocation, addrToPtr(paramValue));
EXPECT_EQ(sizeof(uint64_t), paramValueSizeRet);
EXPECT_EQ(CL_SUCCESS, retVal);
retVal = clGetMemAllocInfoINTEL(&mockContext, ptrOffset(unifiedMemoryHostAllocation, 3), CL_MEM_ALLOC_BASE_PTR_INTEL, paramValueSize, &paramValue, &paramValueSizeRet);
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::hostUnifiedMemory);
EXPECT_EQ(unifiedMemoryHostAllocation, addrToPtr(paramValue));
EXPECT_EQ(sizeof(uint64_t), paramValueSizeRet);
EXPECT_EQ(CL_SUCCESS, retVal);
retVal = clMemFreeINTEL(&mockContext, unifiedMemoryHostAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
}
{
auto unifiedMemoryDeviceAllocation = clDeviceMemAllocINTEL(&mockContext, device, nullptr, 4, 0, &retVal);
auto allocationsManager = mockContext.getSVMAllocsManager();
auto graphicsAllocation = allocationsManager->getSVMAlloc(unifiedMemoryDeviceAllocation);
retVal = clGetMemAllocInfoINTEL(&mockContext, unifiedMemoryDeviceAllocation, CL_MEM_ALLOC_BASE_PTR_INTEL, paramValueSize, &paramValue, &paramValueSizeRet);
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::deviceUnifiedMemory);
EXPECT_EQ(unifiedMemoryDeviceAllocation, addrToPtr(paramValue));
EXPECT_EQ(sizeof(uint64_t), paramValueSizeRet);
EXPECT_EQ(CL_SUCCESS, retVal);
retVal = clGetMemAllocInfoINTEL(&mockContext, ptrOffset(unifiedMemoryDeviceAllocation, 3), CL_MEM_ALLOC_BASE_PTR_INTEL, paramValueSize, &paramValue, &paramValueSizeRet);
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::deviceUnifiedMemory);
EXPECT_EQ(unifiedMemoryDeviceAllocation, addrToPtr(paramValue));
EXPECT_EQ(sizeof(uint64_t), paramValueSizeRet);
EXPECT_EQ(CL_SUCCESS, retVal);
retVal = clMemFreeINTEL(&mockContext, unifiedMemoryDeviceAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
}
}
TEST(clUnifiedSharedMemoryTests, whenClGetMemAllocInfoINTELisCalledWithoutParamNameThenInvalidValueIsReturned) {
MockContext mockContext;
cl_int retVal = CL_SUCCESS;