mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Refactor clSharedMemAllocINTEL
- Choose allocation path according to given device, - Connect device in createUnifiedAllocationWithDeviceStorage - Fix type in clGetMemAllocInfoINTEL Change-Id: I9e743001b4c032a712c939c2917f16de0a61b100 Signed-off-by: Krzysztof Gibala <krzysztof.gibala@intel.com>
This commit is contained in:

committed by
sys_ocldev

parent
6112e99329
commit
c9a2406ea6
@ -238,6 +238,7 @@ void *SVMAllocsManager::createUnifiedAllocationWithDeviceStorage(uint32_t rootDe
|
||||
SvmAllocationData allocData;
|
||||
allocData.gpuAllocation = allocationGpu;
|
||||
allocData.cpuAllocation = allocationCpu;
|
||||
allocData.device = unifiedMemoryProperties.device;
|
||||
allocData.size = size;
|
||||
|
||||
this->SVMAllocs.insert(allocData);
|
||||
|
@ -3525,7 +3525,7 @@ void *clSharedMemAllocINTEL(
|
||||
|
||||
ErrorCodeHelper err(errcodeRet, CL_SUCCESS);
|
||||
|
||||
auto retVal = validateObjects(WithCastToInternal(context, &neoContext), WithCastToInternal(device, &neoDevice));
|
||||
auto retVal = validateObjects(WithCastToInternal(context, &neoContext));
|
||||
|
||||
if (retVal != CL_SUCCESS) {
|
||||
err.set(retVal);
|
||||
@ -3547,8 +3547,13 @@ void *clSharedMemAllocINTEL(
|
||||
}
|
||||
|
||||
unifiedMemoryProperties.device = device;
|
||||
unifiedMemoryProperties.subdeviceBitfield = neoDevice->getDefaultEngine().osContext->getDeviceBitfield();
|
||||
if (!device) {
|
||||
return neoContext->getSVMAllocsManager()->createUnifiedMemoryAllocation(neoContext->getDevice(0)->getRootDeviceIndex(), size, unifiedMemoryProperties);
|
||||
}
|
||||
|
||||
validateObjects(WithCastToInternal(device, &neoDevice));
|
||||
|
||||
unifiedMemoryProperties.subdeviceBitfield = neoDevice->getDefaultEngine().osContext->getDeviceBitfield();
|
||||
return neoContext->getSVMAllocsManager()->createSharedUnifiedMemoryAllocation(neoContext->getDevice(0)->getRootDeviceIndex(), size, unifiedMemoryProperties, neoContext->getSpecialQueue());
|
||||
}
|
||||
|
||||
@ -3626,7 +3631,7 @@ cl_int clGetMemAllocInfoINTEL(
|
||||
return retVal;
|
||||
}
|
||||
case CL_MEM_ALLOC_FLAGS_INTEL: {
|
||||
retVal = info.set<uint32_t>(unifiedMemoryAllocation->allocationFlagsProperty.allAllocFlags);
|
||||
retVal = info.set<cl_mem_alloc_flags_intel>(unifiedMemoryAllocation->allocationFlagsProperty.allAllocFlags);
|
||||
return retVal;
|
||||
}
|
||||
case CL_MEM_ALLOC_DEVICE_INTEL: {
|
||||
|
@ -437,6 +437,24 @@ TEST(clUnifiedSharedMemoryTests, givenSharedAllocationWhenItIsQueriedForDeviceTh
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
}
|
||||
|
||||
TEST(clUnifiedSharedMemoryTests, givenSharedAllocationWithoutDeviceWhenItIsQueriedForDeviceThenNullIsReturned) {
|
||||
MockContext mockContext;
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
size_t paramValueSizeRet = 0;
|
||||
auto unifiedMemorySharedAllocation = clSharedMemAllocINTEL(&mockContext, nullptr, nullptr, 4, 0, &retVal);
|
||||
|
||||
cl_device_id returnedDevice;
|
||||
|
||||
retVal = clGetMemAllocInfoINTEL(&mockContext, unifiedMemorySharedAllocation, CL_MEM_ALLOC_DEVICE_INTEL, sizeof(returnedDevice), &returnedDevice, ¶mValueSizeRet);
|
||||
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
EXPECT_EQ(paramValueSizeRet, sizeof(returnedDevice));
|
||||
EXPECT_EQ(returnedDevice, nullptr);
|
||||
|
||||
retVal = clMemFreeINTEL(&mockContext, unifiedMemorySharedAllocation);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
}
|
||||
|
||||
TEST(clUnifiedSharedMemoryTests, givenHostAllocationWhenItIsQueriedForDeviceThenProperDeviceIsReturned) {
|
||||
MockContext mockContext;
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
|
@ -250,6 +250,7 @@ TEST_F(SVMMemoryAllocatorTest, whenSharedAllocationIsCreatedThenItIsStoredWithPr
|
||||
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties;
|
||||
unifiedMemoryProperties.memoryType = InternalMemoryType::SHARED_UNIFIED_MEMORY;
|
||||
auto allocationSize = 4096u;
|
||||
|
||||
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(0, 4096u, unifiedMemoryProperties, &cmdQ);
|
||||
EXPECT_NE(nullptr, ptr);
|
||||
auto allocation = svmManager->getSVMAlloc(ptr);
|
||||
@ -267,11 +268,13 @@ TEST_F(SVMMemoryAllocatorTest, whenSharedAllocationIsCreatedThenItIsStoredWithPr
|
||||
|
||||
TEST_F(SVMLocalMemoryAllocatorTest, whenSharedAllocationIsCreatedWithDebugFlagSetThenItIsStoredWithProperTypeInAllocationMapAndHasCpuAndGpuStorage) {
|
||||
MockCommandQueue cmdQ;
|
||||
MockContext mockContext;
|
||||
DebugManagerStateRestore restore;
|
||||
DebugManager.flags.AllocateSharedAllocationsWithCpuAndGpuStorage.set(true);
|
||||
|
||||
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties;
|
||||
unifiedMemoryProperties.memoryType = InternalMemoryType::SHARED_UNIFIED_MEMORY;
|
||||
unifiedMemoryProperties.device = mockContext.getDevice(0u);
|
||||
auto allocationSize = 4096u;
|
||||
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(0, 4096u, unifiedMemoryProperties, &cmdQ);
|
||||
EXPECT_NE(nullptr, ptr);
|
||||
@ -280,6 +283,7 @@ TEST_F(SVMLocalMemoryAllocatorTest, whenSharedAllocationIsCreatedWithDebugFlagSe
|
||||
EXPECT_NE(nullptr, allocation->gpuAllocation);
|
||||
EXPECT_EQ(InternalMemoryType::SHARED_UNIFIED_MEMORY, allocation->memoryType);
|
||||
EXPECT_EQ(allocationSize, allocation->size);
|
||||
EXPECT_EQ(mockContext.getDevice(0u), allocation->device);
|
||||
|
||||
EXPECT_EQ(alignUp(allocationSize, 2u * MB), allocation->gpuAllocation->getUnderlyingBufferSize());
|
||||
EXPECT_EQ(alignUp(allocationSize, 2u * MB), allocation->cpuAllocation->getUnderlyingBufferSize());
|
||||
|
Reference in New Issue
Block a user