Skip to content

Commit c9a2406

Browse files
kgibalaCompute-Runtime-Automation
authored andcommitted
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>
1 parent 6112e99 commit c9a2406

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

core/memory_manager/unified_memory_manager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ void *SVMAllocsManager::createUnifiedAllocationWithDeviceStorage(uint32_t rootDe
238238
SvmAllocationData allocData;
239239
allocData.gpuAllocation = allocationGpu;
240240
allocData.cpuAllocation = allocationCpu;
241+
allocData.device = unifiedMemoryProperties.device;
241242
allocData.size = size;
242243

243244
this->SVMAllocs.insert(allocData);

runtime/api/api.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3525,7 +3525,7 @@ void *clSharedMemAllocINTEL(
35253525

35263526
ErrorCodeHelper err(errcodeRet, CL_SUCCESS);
35273527

3528-
auto retVal = validateObjects(WithCastToInternal(context, &neoContext), WithCastToInternal(device, &neoDevice));
3528+
auto retVal = validateObjects(WithCastToInternal(context, &neoContext));
35293529

35303530
if (retVal != CL_SUCCESS) {
35313531
err.set(retVal);
@@ -3547,8 +3547,13 @@ void *clSharedMemAllocINTEL(
35473547
}
35483548

35493549
unifiedMemoryProperties.device = device;
3550-
unifiedMemoryProperties.subdeviceBitfield = neoDevice->getDefaultEngine().osContext->getDeviceBitfield();
3550+
if (!device) {
3551+
return neoContext->getSVMAllocsManager()->createUnifiedMemoryAllocation(neoContext->getDevice(0)->getRootDeviceIndex(), size, unifiedMemoryProperties);
3552+
}
3553+
3554+
validateObjects(WithCastToInternal(device, &neoDevice));
35513555

3556+
unifiedMemoryProperties.subdeviceBitfield = neoDevice->getDefaultEngine().osContext->getDeviceBitfield();
35523557
return neoContext->getSVMAllocsManager()->createSharedUnifiedMemoryAllocation(neoContext->getDevice(0)->getRootDeviceIndex(), size, unifiedMemoryProperties, neoContext->getSpecialQueue());
35533558
}
35543559

@@ -3626,7 +3631,7 @@ cl_int clGetMemAllocInfoINTEL(
36263631
return retVal;
36273632
}
36283633
case CL_MEM_ALLOC_FLAGS_INTEL: {
3629-
retVal = info.set<uint32_t>(unifiedMemoryAllocation->allocationFlagsProperty.allAllocFlags);
3634+
retVal = info.set<cl_mem_alloc_flags_intel>(unifiedMemoryAllocation->allocationFlagsProperty.allAllocFlags);
36303635
return retVal;
36313636
}
36323637
case CL_MEM_ALLOC_DEVICE_INTEL: {

unit_tests/api/cl_unified_shared_memory_tests.inl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,24 @@ TEST(clUnifiedSharedMemoryTests, givenSharedAllocationWhenItIsQueriedForDeviceTh
437437
EXPECT_EQ(CL_SUCCESS, retVal);
438438
}
439439

440+
TEST(clUnifiedSharedMemoryTests, givenSharedAllocationWithoutDeviceWhenItIsQueriedForDeviceThenNullIsReturned) {
441+
MockContext mockContext;
442+
cl_int retVal = CL_SUCCESS;
443+
size_t paramValueSizeRet = 0;
444+
auto unifiedMemorySharedAllocation = clSharedMemAllocINTEL(&mockContext, nullptr, nullptr, 4, 0, &retVal);
445+
446+
cl_device_id returnedDevice;
447+
448+
retVal = clGetMemAllocInfoINTEL(&mockContext, unifiedMemorySharedAllocation, CL_MEM_ALLOC_DEVICE_INTEL, sizeof(returnedDevice), &returnedDevice, &paramValueSizeRet);
449+
450+
EXPECT_EQ(CL_SUCCESS, retVal);
451+
EXPECT_EQ(paramValueSizeRet, sizeof(returnedDevice));
452+
EXPECT_EQ(returnedDevice, nullptr);
453+
454+
retVal = clMemFreeINTEL(&mockContext, unifiedMemorySharedAllocation);
455+
EXPECT_EQ(CL_SUCCESS, retVal);
456+
}
457+
440458
TEST(clUnifiedSharedMemoryTests, givenHostAllocationWhenItIsQueriedForDeviceThenProperDeviceIsReturned) {
441459
MockContext mockContext;
442460
cl_int retVal = CL_SUCCESS;

unit_tests/memory_manager/unified_memory_manager_tests.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ TEST_F(SVMMemoryAllocatorTest, whenSharedAllocationIsCreatedThenItIsStoredWithPr
250250
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties;
251251
unifiedMemoryProperties.memoryType = InternalMemoryType::SHARED_UNIFIED_MEMORY;
252252
auto allocationSize = 4096u;
253+
253254
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(0, 4096u, unifiedMemoryProperties, &cmdQ);
254255
EXPECT_NE(nullptr, ptr);
255256
auto allocation = svmManager->getSVMAlloc(ptr);
@@ -267,11 +268,13 @@ TEST_F(SVMMemoryAllocatorTest, whenSharedAllocationIsCreatedThenItIsStoredWithPr
267268

268269
TEST_F(SVMLocalMemoryAllocatorTest, whenSharedAllocationIsCreatedWithDebugFlagSetThenItIsStoredWithProperTypeInAllocationMapAndHasCpuAndGpuStorage) {
269270
MockCommandQueue cmdQ;
271+
MockContext mockContext;
270272
DebugManagerStateRestore restore;
271273
DebugManager.flags.AllocateSharedAllocationsWithCpuAndGpuStorage.set(true);
272274

273275
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties;
274276
unifiedMemoryProperties.memoryType = InternalMemoryType::SHARED_UNIFIED_MEMORY;
277+
unifiedMemoryProperties.device = mockContext.getDevice(0u);
275278
auto allocationSize = 4096u;
276279
auto ptr = svmManager->createSharedUnifiedMemoryAllocation(0, 4096u, unifiedMemoryProperties, &cmdQ);
277280
EXPECT_NE(nullptr, ptr);
@@ -280,6 +283,7 @@ TEST_F(SVMLocalMemoryAllocatorTest, whenSharedAllocationIsCreatedWithDebugFlagSe
280283
EXPECT_NE(nullptr, allocation->gpuAllocation);
281284
EXPECT_EQ(InternalMemoryType::SHARED_UNIFIED_MEMORY, allocation->memoryType);
282285
EXPECT_EQ(allocationSize, allocation->size);
286+
EXPECT_EQ(mockContext.getDevice(0u), allocation->device);
283287

284288
EXPECT_EQ(alignUp(allocationSize, 2u * MB), allocation->gpuAllocation->getUnderlyingBufferSize());
285289
EXPECT_EQ(alignUp(allocationSize, 2u * MB), allocation->cpuAllocation->getUnderlyingBufferSize());

0 commit comments

Comments
 (0)