Add experimental CL_MEM_DEVICE_ID_INTEL property for memory object creation

Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
This commit is contained in:
Filip Hazubski 2022-08-05 10:26:51 +00:00 committed by Compute-Runtime-Automation
parent f833dc0291
commit 1f21d34fd3
4 changed files with 108 additions and 5 deletions

View File

@ -72,6 +72,8 @@ using cl_unified_shared_memory_type_intel = cl_uint;
#define CL_MEM_LOCALLY_UNCACHED_SURFACE_STATE_RESOURCE (1 << 25)
#define CL_MEM_48BIT_RESOURCE_INTEL (1 << 26)
#define CL_MEM_DEVICE_ID_INTEL 0x10011
// Used with clEnqueueVerifyMemory
#define CL_MEM_COMPARE_EQUAL 0u
#define CL_MEM_COMPARE_NOT_EQUAL 1u

View File

@ -16,10 +16,12 @@ namespace NEO {
bool ClMemoryPropertiesHelper::parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryProperties &memoryProperties,
cl_mem_flags &flags, cl_mem_flags_intel &flagsIntel,
cl_mem_alloc_flags_intel &allocflags, MemoryPropertiesHelper::ObjType objectType, Context &context) {
Device *pDevice = &context.getDevice(0)->getDevice();
bool deviceSet = false;
Device *pDevice = context.getDevice(0)->getDevice().getRootDevice();
uint64_t handle = 0;
uint64_t handleType = 0;
uintptr_t hostptr = 0;
if (properties != nullptr) {
for (int i = 0; properties[i] != 0; i += 2) {
switch (properties[i]) {
@ -32,6 +34,19 @@ bool ClMemoryPropertiesHelper::parseMemoryProperties(const cl_mem_properties_int
case CL_MEM_ALLOC_FLAGS_INTEL:
allocflags |= static_cast<cl_mem_alloc_flags_intel>(properties[i + 1]);
break;
case CL_MEM_DEVICE_ID_INTEL: {
if (deviceSet) {
return false;
}
cl_device_id deviceId = reinterpret_cast<cl_device_id>(properties[i + 1]);
auto pClDevice = NEO::castToObject<ClDevice>(deviceId);
if ((pClDevice == nullptr) || (!context.isDeviceAssociated(*pClDevice))) {
return false;
}
pDevice = &pClDevice->getDevice();
deviceSet = true;
break;
}
case CL_MEM_ALLOC_USE_HOST_PTR_INTEL:
hostptr = static_cast<uintptr_t>(properties[i + 1]);
break;
@ -62,9 +77,8 @@ bool ClMemoryPropertiesHelper::parseMemoryProperties(const cl_mem_properties_int
return isFieldValid(flags, MemObjHelper::validFlagsForImage) &&
isFieldValid(flagsIntel, MemObjHelper::validFlagsForImageIntel);
default:
break;
return true;
}
return true;
}
} // namespace NEO

View File

@ -210,11 +210,14 @@ TEST(MemoryProperties, givenClUncompressedHintFlagWhenCreateMemoryPropertiesThen
}
struct MemoryPropertiesHelperTests : ::testing::Test {
MockContext context;
MockUnrestrictiveContext context;
MemoryProperties memoryProperties;
cl_mem_flags flags = 0;
cl_mem_flags_intel flagsIntel = 0;
cl_mem_alloc_flags_intel allocflags = 0;
cl_mem_properties_intel rootDeviceId = reinterpret_cast<cl_mem_properties_intel>(static_cast<cl_device_id>(context.pRootDevice));
cl_mem_properties_intel subDevice0Id = reinterpret_cast<cl_mem_properties_intel>(static_cast<cl_device_id>(context.pSubDevice0));
cl_mem_properties_intel subDevice1Id = reinterpret_cast<cl_mem_properties_intel>(static_cast<cl_device_id>(context.pSubDevice1));
};
TEST_F(MemoryPropertiesHelperTests, givenNullPropertiesWhenParsingMemoryPropertiesThenTrueIsReturned) {
@ -244,6 +247,8 @@ TEST_F(MemoryPropertiesHelperTests, givenValidPropertiesWhenParsingMemoryPropert
CL_MEM_UNCOMPRESSED_HINT_INTEL,
CL_MEM_ALLOC_FLAGS_INTEL,
CL_MEM_ALLOC_WRITE_COMBINED_INTEL, CL_MEM_ALLOC_DEFAULT_INTEL,
CL_MEM_DEVICE_ID_INTEL,
rootDeviceId,
0};
EXPECT_TRUE(ClMemoryPropertiesHelper::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, allocflags,
@ -510,3 +515,45 @@ TEST_F(MemoryPropertiesHelperTests, WhenCallingSetInitialPlacementThenCorrectVal
EXPECT_EQ(initialPlacement, allocationProperties.usmInitialPlacement);
}
}
TEST_F(MemoryPropertiesHelperTests, givenDeviceSpecifiedMultipleTimesWhenParsingExtraMemoryPropertiesThenFalseIsReturned) {
cl_mem_properties_intel propertiesToTest[][5] = {
{CL_MEM_DEVICE_ID_INTEL, subDevice0Id, CL_MEM_DEVICE_ID_INTEL, subDevice0Id, 0},
{CL_MEM_DEVICE_ID_INTEL, subDevice0Id, CL_MEM_DEVICE_ID_INTEL, subDevice1Id, 0}};
for (auto properties : propertiesToTest) {
EXPECT_FALSE(ClMemoryPropertiesHelper::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, allocflags,
MemoryPropertiesHelper::ObjType::UNKNOWN, context));
}
}
TEST_F(MemoryPropertiesHelperTests, givenInvalidDeviceIdWhenParsingExtraMemoryPropertiesThenFalseIsReturned) {
cl_mem_properties_intel properties[] = {
CL_MEM_DEVICE_ID_INTEL, rootDeviceId + 1,
0};
EXPECT_FALSE(ClMemoryPropertiesHelper::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, allocflags,
MemoryPropertiesHelper::ObjType::UNKNOWN, context));
}
TEST_F(MemoryPropertiesHelperTests, givenRootDeviceIdWhenParsingExtraMemoryPropertiesThenValuesAreProperlySet) {
cl_mem_properties_intel properties[] = {
CL_MEM_DEVICE_ID_INTEL, rootDeviceId,
0};
EXPECT_TRUE(ClMemoryPropertiesHelper::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, allocflags,
MemoryPropertiesHelper::ObjType::UNKNOWN, context));
EXPECT_EQ(0b11u, memoryProperties.pDevice->getDeviceBitfield().to_ulong());
EXPECT_EQ(&context.pRootDevice->getDevice(), memoryProperties.pDevice);
}
TEST_F(MemoryPropertiesHelperTests, givenSubDeviceIdWhenParsingExtraMemoryPropertiesThenValuesAreProperlySet) {
cl_mem_properties_intel properties[] = {
CL_MEM_DEVICE_ID_INTEL, subDevice1Id,
0};
EXPECT_TRUE(ClMemoryPropertiesHelper::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, allocflags,
MemoryPropertiesHelper::ObjType::UNKNOWN, context));
EXPECT_EQ(0b10u, memoryProperties.pDevice->getDeviceBitfield().to_ulong());
EXPECT_EQ(&context.pSubDevice1->getDevice(), memoryProperties.pDevice);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -250,6 +250,46 @@ TEST(MemObjHelperMultiTile, givenValidExtraPropertiesWhenValidatingExtraProperti
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(memoryProperties, flags, flagsIntel, context));
}
TEST(MemObjHelperMultiTile, givenOneSubDeviceSelectedWhenParsingMemoryPropertiesThenTrueIsReturnedForValidContexts) {
UltClDeviceFactory deviceFactory{1, 4};
cl_device_id rootDeviceId = deviceFactory.rootDevices[0];
MockContext rootContext(ClDeviceVector{&rootDeviceId, 1});
cl_device_id tile0Id = deviceFactory.subDevices[0];
MockContext tile0Context(ClDeviceVector{&tile0Id, 1});
cl_device_id tile1Id = deviceFactory.subDevices[1];
MockContext tile1Context(ClDeviceVector{&tile1Id, 1});
cl_device_id allDevices[] = {deviceFactory.rootDevices[0], deviceFactory.subDevices[0], deviceFactory.subDevices[1],
deviceFactory.subDevices[2], deviceFactory.subDevices[3]};
MockContext multiTileContext(ClDeviceVector{allDevices, 5});
EXPECT_EQ(deviceFactory.rootDevices[0]->getDeviceBitfield(), multiTileContext.getDevice(0)->getDeviceBitfield());
auto parseMemoryProperties = [](ClDevice *pClDevice, Context &context) -> bool {
cl_mem_flags flags = 0;
cl_mem_flags_intel flagsIntel = 0;
cl_mem_alloc_flags_intel allocFlagsIntel = 0;
MemoryProperties memoryProperties{0};
auto deviceIdProperty = reinterpret_cast<cl_mem_properties_intel>(static_cast<cl_device_id>(pClDevice));
cl_mem_properties_intel properties[] = {CL_MEM_DEVICE_ID_INTEL, deviceIdProperty, 0};
return ClMemoryPropertiesHelper::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, allocFlagsIntel,
MemoryPropertiesHelper::ObjType::BUFFER, context);
};
EXPECT_TRUE(parseMemoryProperties(deviceFactory.subDevices[0], multiTileContext));
EXPECT_TRUE(parseMemoryProperties(deviceFactory.subDevices[0], tile0Context));
EXPECT_FALSE(parseMemoryProperties(deviceFactory.subDevices[0], tile1Context));
EXPECT_FALSE(parseMemoryProperties(deviceFactory.subDevices[0], rootContext));
EXPECT_TRUE(parseMemoryProperties(deviceFactory.subDevices[1], multiTileContext));
EXPECT_TRUE(parseMemoryProperties(deviceFactory.subDevices[1], tile1Context));
EXPECT_FALSE(parseMemoryProperties(deviceFactory.subDevices[1], tile0Context));
EXPECT_FALSE(parseMemoryProperties(deviceFactory.subDevices[1], rootContext));
}
TEST(MemObjHelper, givenInvalidFlagsWhenValidatingExtraPropertiesThenFalseIsReturned) {
MemoryProperties memoryProperties;
cl_mem_flags flags = CL_MEM_COMPRESSED_HINT_INTEL | CL_MEM_UNCOMPRESSED_HINT_INTEL;