Skip to content

Commit 1f21d34

Browse files
Add experimental CL_MEM_DEVICE_ID_INTEL property for memory object creation
Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
1 parent f833dc0 commit 1f21d34

File tree

4 files changed

+108
-5
lines changed

4 files changed

+108
-5
lines changed

opencl/extensions/public/cl_ext_private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ using cl_unified_shared_memory_type_intel = cl_uint;
7272
#define CL_MEM_LOCALLY_UNCACHED_SURFACE_STATE_RESOURCE (1 << 25)
7373
#define CL_MEM_48BIT_RESOURCE_INTEL (1 << 26)
7474

75+
#define CL_MEM_DEVICE_ID_INTEL 0x10011
76+
7577
// Used with clEnqueueVerifyMemory
7678
#define CL_MEM_COMPARE_EQUAL 0u
7779
#define CL_MEM_COMPARE_NOT_EQUAL 1u

opencl/source/helpers/cl_memory_properties_helpers.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ namespace NEO {
1616
bool ClMemoryPropertiesHelper::parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryProperties &memoryProperties,
1717
cl_mem_flags &flags, cl_mem_flags_intel &flagsIntel,
1818
cl_mem_alloc_flags_intel &allocflags, MemoryPropertiesHelper::ObjType objectType, Context &context) {
19-
Device *pDevice = &context.getDevice(0)->getDevice();
19+
bool deviceSet = false;
20+
Device *pDevice = context.getDevice(0)->getDevice().getRootDevice();
2021
uint64_t handle = 0;
2122
uint64_t handleType = 0;
2223
uintptr_t hostptr = 0;
24+
2325
if (properties != nullptr) {
2426
for (int i = 0; properties[i] != 0; i += 2) {
2527
switch (properties[i]) {
@@ -32,6 +34,19 @@ bool ClMemoryPropertiesHelper::parseMemoryProperties(const cl_mem_properties_int
3234
case CL_MEM_ALLOC_FLAGS_INTEL:
3335
allocflags |= static_cast<cl_mem_alloc_flags_intel>(properties[i + 1]);
3436
break;
37+
case CL_MEM_DEVICE_ID_INTEL: {
38+
if (deviceSet) {
39+
return false;
40+
}
41+
cl_device_id deviceId = reinterpret_cast<cl_device_id>(properties[i + 1]);
42+
auto pClDevice = NEO::castToObject<ClDevice>(deviceId);
43+
if ((pClDevice == nullptr) || (!context.isDeviceAssociated(*pClDevice))) {
44+
return false;
45+
}
46+
pDevice = &pClDevice->getDevice();
47+
deviceSet = true;
48+
break;
49+
}
3550
case CL_MEM_ALLOC_USE_HOST_PTR_INTEL:
3651
hostptr = static_cast<uintptr_t>(properties[i + 1]);
3752
break;
@@ -62,9 +77,8 @@ bool ClMemoryPropertiesHelper::parseMemoryProperties(const cl_mem_properties_int
6277
return isFieldValid(flags, MemObjHelper::validFlagsForImage) &&
6378
isFieldValid(flagsIntel, MemObjHelper::validFlagsForImageIntel);
6479
default:
65-
break;
80+
return true;
6681
}
67-
return true;
6882
}
6983

7084
} // namespace NEO

opencl/test/unit_test/helpers/memory_properties_helpers_tests.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,14 @@ TEST(MemoryProperties, givenClUncompressedHintFlagWhenCreateMemoryPropertiesThen
210210
}
211211

212212
struct MemoryPropertiesHelperTests : ::testing::Test {
213-
MockContext context;
213+
MockUnrestrictiveContext context;
214214
MemoryProperties memoryProperties;
215215
cl_mem_flags flags = 0;
216216
cl_mem_flags_intel flagsIntel = 0;
217217
cl_mem_alloc_flags_intel allocflags = 0;
218+
cl_mem_properties_intel rootDeviceId = reinterpret_cast<cl_mem_properties_intel>(static_cast<cl_device_id>(context.pRootDevice));
219+
cl_mem_properties_intel subDevice0Id = reinterpret_cast<cl_mem_properties_intel>(static_cast<cl_device_id>(context.pSubDevice0));
220+
cl_mem_properties_intel subDevice1Id = reinterpret_cast<cl_mem_properties_intel>(static_cast<cl_device_id>(context.pSubDevice1));
218221
};
219222

220223
TEST_F(MemoryPropertiesHelperTests, givenNullPropertiesWhenParsingMemoryPropertiesThenTrueIsReturned) {
@@ -244,6 +247,8 @@ TEST_F(MemoryPropertiesHelperTests, givenValidPropertiesWhenParsingMemoryPropert
244247
CL_MEM_UNCOMPRESSED_HINT_INTEL,
245248
CL_MEM_ALLOC_FLAGS_INTEL,
246249
CL_MEM_ALLOC_WRITE_COMBINED_INTEL, CL_MEM_ALLOC_DEFAULT_INTEL,
250+
CL_MEM_DEVICE_ID_INTEL,
251+
rootDeviceId,
247252
0};
248253

249254
EXPECT_TRUE(ClMemoryPropertiesHelper::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, allocflags,
@@ -510,3 +515,45 @@ TEST_F(MemoryPropertiesHelperTests, WhenCallingSetInitialPlacementThenCorrectVal
510515
EXPECT_EQ(initialPlacement, allocationProperties.usmInitialPlacement);
511516
}
512517
}
518+
519+
TEST_F(MemoryPropertiesHelperTests, givenDeviceSpecifiedMultipleTimesWhenParsingExtraMemoryPropertiesThenFalseIsReturned) {
520+
cl_mem_properties_intel propertiesToTest[][5] = {
521+
{CL_MEM_DEVICE_ID_INTEL, subDevice0Id, CL_MEM_DEVICE_ID_INTEL, subDevice0Id, 0},
522+
{CL_MEM_DEVICE_ID_INTEL, subDevice0Id, CL_MEM_DEVICE_ID_INTEL, subDevice1Id, 0}};
523+
524+
for (auto properties : propertiesToTest) {
525+
EXPECT_FALSE(ClMemoryPropertiesHelper::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, allocflags,
526+
MemoryPropertiesHelper::ObjType::UNKNOWN, context));
527+
}
528+
}
529+
530+
TEST_F(MemoryPropertiesHelperTests, givenInvalidDeviceIdWhenParsingExtraMemoryPropertiesThenFalseIsReturned) {
531+
cl_mem_properties_intel properties[] = {
532+
CL_MEM_DEVICE_ID_INTEL, rootDeviceId + 1,
533+
0};
534+
535+
EXPECT_FALSE(ClMemoryPropertiesHelper::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, allocflags,
536+
MemoryPropertiesHelper::ObjType::UNKNOWN, context));
537+
}
538+
539+
TEST_F(MemoryPropertiesHelperTests, givenRootDeviceIdWhenParsingExtraMemoryPropertiesThenValuesAreProperlySet) {
540+
cl_mem_properties_intel properties[] = {
541+
CL_MEM_DEVICE_ID_INTEL, rootDeviceId,
542+
0};
543+
544+
EXPECT_TRUE(ClMemoryPropertiesHelper::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, allocflags,
545+
MemoryPropertiesHelper::ObjType::UNKNOWN, context));
546+
EXPECT_EQ(0b11u, memoryProperties.pDevice->getDeviceBitfield().to_ulong());
547+
EXPECT_EQ(&context.pRootDevice->getDevice(), memoryProperties.pDevice);
548+
}
549+
550+
TEST_F(MemoryPropertiesHelperTests, givenSubDeviceIdWhenParsingExtraMemoryPropertiesThenValuesAreProperlySet) {
551+
cl_mem_properties_intel properties[] = {
552+
CL_MEM_DEVICE_ID_INTEL, subDevice1Id,
553+
0};
554+
555+
EXPECT_TRUE(ClMemoryPropertiesHelper::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, allocflags,
556+
MemoryPropertiesHelper::ObjType::UNKNOWN, context));
557+
EXPECT_EQ(0b10u, memoryProperties.pDevice->getDeviceBitfield().to_ulong());
558+
EXPECT_EQ(&context.pSubDevice1->getDevice(), memoryProperties.pDevice);
559+
}

opencl/test/unit_test/mem_obj/mem_obj_helper_tests.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2021 Intel Corporation
2+
* Copyright (C) 2018-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -250,6 +250,46 @@ TEST(MemObjHelperMultiTile, givenValidExtraPropertiesWhenValidatingExtraProperti
250250
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(memoryProperties, flags, flagsIntel, context));
251251
}
252252

253+
TEST(MemObjHelperMultiTile, givenOneSubDeviceSelectedWhenParsingMemoryPropertiesThenTrueIsReturnedForValidContexts) {
254+
UltClDeviceFactory deviceFactory{1, 4};
255+
256+
cl_device_id rootDeviceId = deviceFactory.rootDevices[0];
257+
MockContext rootContext(ClDeviceVector{&rootDeviceId, 1});
258+
259+
cl_device_id tile0Id = deviceFactory.subDevices[0];
260+
MockContext tile0Context(ClDeviceVector{&tile0Id, 1});
261+
262+
cl_device_id tile1Id = deviceFactory.subDevices[1];
263+
MockContext tile1Context(ClDeviceVector{&tile1Id, 1});
264+
265+
cl_device_id allDevices[] = {deviceFactory.rootDevices[0], deviceFactory.subDevices[0], deviceFactory.subDevices[1],
266+
deviceFactory.subDevices[2], deviceFactory.subDevices[3]};
267+
MockContext multiTileContext(ClDeviceVector{allDevices, 5});
268+
269+
EXPECT_EQ(deviceFactory.rootDevices[0]->getDeviceBitfield(), multiTileContext.getDevice(0)->getDeviceBitfield());
270+
271+
auto parseMemoryProperties = [](ClDevice *pClDevice, Context &context) -> bool {
272+
cl_mem_flags flags = 0;
273+
cl_mem_flags_intel flagsIntel = 0;
274+
cl_mem_alloc_flags_intel allocFlagsIntel = 0;
275+
MemoryProperties memoryProperties{0};
276+
auto deviceIdProperty = reinterpret_cast<cl_mem_properties_intel>(static_cast<cl_device_id>(pClDevice));
277+
cl_mem_properties_intel properties[] = {CL_MEM_DEVICE_ID_INTEL, deviceIdProperty, 0};
278+
return ClMemoryPropertiesHelper::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, allocFlagsIntel,
279+
MemoryPropertiesHelper::ObjType::BUFFER, context);
280+
};
281+
282+
EXPECT_TRUE(parseMemoryProperties(deviceFactory.subDevices[0], multiTileContext));
283+
EXPECT_TRUE(parseMemoryProperties(deviceFactory.subDevices[0], tile0Context));
284+
EXPECT_FALSE(parseMemoryProperties(deviceFactory.subDevices[0], tile1Context));
285+
EXPECT_FALSE(parseMemoryProperties(deviceFactory.subDevices[0], rootContext));
286+
287+
EXPECT_TRUE(parseMemoryProperties(deviceFactory.subDevices[1], multiTileContext));
288+
EXPECT_TRUE(parseMemoryProperties(deviceFactory.subDevices[1], tile1Context));
289+
EXPECT_FALSE(parseMemoryProperties(deviceFactory.subDevices[1], tile0Context));
290+
EXPECT_FALSE(parseMemoryProperties(deviceFactory.subDevices[1], rootContext));
291+
}
292+
253293
TEST(MemObjHelper, givenInvalidFlagsWhenValidatingExtraPropertiesThenFalseIsReturned) {
254294
MemoryProperties memoryProperties;
255295
cl_mem_flags flags = CL_MEM_COMPRESSED_HINT_INTEL | CL_MEM_UNCOMPRESSED_HINT_INTEL;

0 commit comments

Comments
 (0)