mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 23:03:02 +08:00
Use ZE_AFFINITY_MASK for neo devices
Resolves: NEO-5438 Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
2eaf830aff
commit
8ed14d0c9f
@@ -177,80 +177,17 @@ DriverHandleImp::~DriverHandleImp() {
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t DriverHandleImp::parseAffinityMask(std::vector<std::unique_ptr<NEO::Device>> &neoDevices) {
|
||||
std::vector<std::vector<bool>> affinityMaskBitSet(neoDevices.size());
|
||||
for (uint32_t i = 0; i < affinityMaskBitSet.size(); i++) {
|
||||
affinityMaskBitSet[i].resize(neoDevices[i]->getNumAvailableDevices());
|
||||
}
|
||||
|
||||
size_t pos = 0;
|
||||
while (pos < this->affinityMaskString.size()) {
|
||||
size_t posNextDot = this->affinityMaskString.find_first_of(".", pos);
|
||||
size_t posNextComma = this->affinityMaskString.find_first_of(",", pos);
|
||||
std::string rootDeviceString = this->affinityMaskString.substr(pos, std::min(posNextDot, posNextComma) - pos);
|
||||
uint32_t rootDeviceIndex = static_cast<uint32_t>(std::stoul(rootDeviceString, nullptr, 0));
|
||||
if (rootDeviceIndex < neoDevices.size()) {
|
||||
pos += rootDeviceString.size();
|
||||
if (posNextDot != std::string::npos &&
|
||||
this->affinityMaskString.at(pos) == '.' && posNextDot < posNextComma) {
|
||||
pos++;
|
||||
std::string subDeviceString = this->affinityMaskString.substr(pos, posNextComma - pos);
|
||||
uint32_t subDeviceIndex = static_cast<uint32_t>(std::stoul(subDeviceString, nullptr, 0));
|
||||
if (subDeviceIndex < neoDevices[rootDeviceIndex]->getNumAvailableDevices()) {
|
||||
affinityMaskBitSet[rootDeviceIndex][subDeviceIndex] = true;
|
||||
}
|
||||
} else {
|
||||
std::fill(affinityMaskBitSet[rootDeviceIndex].begin(),
|
||||
affinityMaskBitSet[rootDeviceIndex].end(),
|
||||
true);
|
||||
}
|
||||
}
|
||||
if (posNextComma == std::string::npos) {
|
||||
break;
|
||||
}
|
||||
pos = posNextComma + 1;
|
||||
}
|
||||
|
||||
uint32_t offset = 0;
|
||||
uint32_t affinityMask = 0;
|
||||
for (uint32_t i = 0; i < affinityMaskBitSet.size(); i++) {
|
||||
for (uint32_t j = 0; j < affinityMaskBitSet[i].size(); j++) {
|
||||
if (affinityMaskBitSet[i][j] == true) {
|
||||
affinityMask |= (1UL << offset);
|
||||
}
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
|
||||
return affinityMask;
|
||||
}
|
||||
|
||||
ze_result_t DriverHandleImp::initialize(std::vector<std::unique_ptr<NEO::Device>> neoDevices) {
|
||||
|
||||
uint32_t affinityMask = std::numeric_limits<uint32_t>::max();
|
||||
|
||||
if (enablePciIdDeviceOrder) {
|
||||
sortNeoDevices(neoDevices);
|
||||
}
|
||||
|
||||
if (this->affinityMaskString.length() > 0) {
|
||||
affinityMask = parseAffinityMask(neoDevices);
|
||||
}
|
||||
|
||||
uint32_t currentMaskOffset = 0;
|
||||
for (auto &neoDevice : neoDevices) {
|
||||
if (!neoDevice->getHardwareInfo().capabilityTable.levelZeroSupported) {
|
||||
continue;
|
||||
}
|
||||
|
||||
uint32_t currentDeviceMask = (affinityMask >> currentMaskOffset) & ((1UL << neoDevice->getNumAvailableDevices()) - 1);
|
||||
bool isDeviceExposed = currentDeviceMask ? true : false;
|
||||
|
||||
currentMaskOffset += neoDevice->getNumAvailableDevices();
|
||||
if (!isDeviceExposed) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this->memoryManager == nullptr) {
|
||||
this->memoryManager = neoDevice->getMemoryManager();
|
||||
if (this->memoryManager == nullptr) {
|
||||
@@ -270,7 +207,9 @@ ze_result_t DriverHandleImp::initialize(std::vector<std::unique_ptr<NEO::Device>
|
||||
|
||||
this->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex());
|
||||
this->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()});
|
||||
auto device = Device::create(this, neoDevice.release(), currentDeviceMask, false);
|
||||
|
||||
auto pNeoDevice = neoDevice.release();
|
||||
auto device = Device::create(this, pNeoDevice, pNeoDevice->getExecutionEnvironment()->rootDeviceEnvironments[pNeoDevice->getRootDeviceIndex()]->deviceAffinityMask, false);
|
||||
this->devices.push_back(device);
|
||||
}
|
||||
|
||||
@@ -295,7 +234,6 @@ DriverHandle *DriverHandle::create(std::vector<std::unique_ptr<NEO::Device>> dev
|
||||
DriverHandleImp *driverHandle = new DriverHandleImp;
|
||||
UNRECOVERABLE_IF(nullptr == driverHandle);
|
||||
|
||||
driverHandle->affinityMaskString = envVariables.affinityMask;
|
||||
driverHandle->enableProgramDebugging = envVariables.programDebugging;
|
||||
driverHandle->enableSysman = envVariables.sysman;
|
||||
driverHandle->enablePciIdDeviceOrder = envVariables.pciIdDeviceOrder;
|
||||
|
||||
@@ -80,7 +80,6 @@ struct DriverHandleImp : public DriverHandle {
|
||||
size_t size,
|
||||
uint32_t rootDeviceIndex,
|
||||
uintptr_t *gpuAddress) override;
|
||||
uint32_t parseAffinityMask(std::vector<std::unique_ptr<NEO::Device>> &neoDevices);
|
||||
void createHostPointerManager();
|
||||
void sortNeoDevices(std::vector<std::unique_ptr<NEO::Device>> &neoDevices);
|
||||
|
||||
@@ -91,7 +90,6 @@ struct DriverHandleImp : public DriverHandle {
|
||||
std::mutex sharedMakeResidentAllocationsLock;
|
||||
std::map<void *, NEO::GraphicsAllocation *> sharedMakeResidentAllocations;
|
||||
|
||||
std::string affinityMaskString = "";
|
||||
std::vector<Device *> devices;
|
||||
// Spec extensions
|
||||
const std::vector<std::pair<std::string, uint32_t>> extensionsSupported = {
|
||||
|
||||
@@ -132,6 +132,29 @@ set(TEST_MODULES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_modules/test_kernel.cl
|
||||
)
|
||||
|
||||
add_custom_target(copy_l0_test_files)
|
||||
|
||||
add_custom_command(TARGET copy_l0_test_files
|
||||
POST_BUILD
|
||||
COMMAND echo deleting and re-creating "${CUSTOM_COMMAND_BINARY_DIR}/test_files" ...
|
||||
COMMAND ${CMAKE_COMMAND} -E remove_directory "${CUSTOM_COMMAND_BINARY_DIR}/test_files"
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${CUSTOM_COMMAND_BINARY_DIR}/test_files"
|
||||
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/test_files"
|
||||
)
|
||||
set_target_properties(copy_l0_test_files PROPERTIES FOLDER ${TARGET_NAME_L0})
|
||||
|
||||
if(UNIX)
|
||||
add_custom_command(TARGET copy_l0_test_files
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory "${NEO_SOURCE_DIR}/opencl/test/unit_test/test_files/linux" "${CUSTOM_COMMAND_BINARY_DIR}/test_files/linux"
|
||||
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/test_files"
|
||||
)
|
||||
|
||||
add_dependencies(${TARGET_NAME}
|
||||
copy_l0_test_files
|
||||
)
|
||||
endif()
|
||||
|
||||
macro(macro_for_each_gen)
|
||||
foreach(PLATFORM_TYPE ${PLATFORM_TYPES})
|
||||
if(${GEN_TYPE}_HAS_${PLATFORM_TYPE})
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "shared/source/os_interface/device_factory.h"
|
||||
#include "shared/source/os_interface/hw_info_config.h"
|
||||
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
|
||||
#include "shared/test/unit_test/helpers/ult_hw_config.h"
|
||||
#include "shared/test/unit_test/mocks/ult_device_factory.h"
|
||||
|
||||
#include "opencl/test/unit_test/mocks/mock_io_functions.h"
|
||||
@@ -329,24 +330,12 @@ struct MaskArray {
|
||||
struct DriverTestMultipleDeviceWithAffinityMask : public ::testing::WithParamInterface<std::tuple<std::string, std::string>>,
|
||||
public ::testing::Test {
|
||||
void SetUp() override {
|
||||
DebugManager.flags.CreateMultipleRootDevices.set(numRootDevices);
|
||||
DebugManager.flags.CreateMultipleSubDevices.set(numSubDevices);
|
||||
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
|
||||
|
||||
NEO::ExecutionEnvironment *executionEnvironment = new NEO::ExecutionEnvironment();
|
||||
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
|
||||
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
|
||||
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(NEO::defaultHwInfo.get());
|
||||
}
|
||||
|
||||
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
|
||||
devices.push_back(std::unique_ptr<NEO::MockDevice>(NEO::MockDevice::createWithExecutionEnvironment<NEO::MockDevice>(
|
||||
NEO::defaultHwInfo.get(),
|
||||
executionEnvironment, i)));
|
||||
}
|
||||
}
|
||||
|
||||
DebugManagerStateRestore restorer;
|
||||
std::vector<std::unique_ptr<NEO::Device>> devices;
|
||||
|
||||
const uint32_t numRootDevices = 2u;
|
||||
const uint32_t numSubDevices = 4u;
|
||||
@@ -354,17 +343,21 @@ struct DriverTestMultipleDeviceWithAffinityMask : public ::testing::WithParamInt
|
||||
|
||||
TEST_P(DriverTestMultipleDeviceWithAffinityMask,
|
||||
whenSettingAffinityMaskToRetrieveOneSubDeviceOnEachDeviceThenCorrectDevicesAreExposed) {
|
||||
VariableBackup<UltHwConfig> backup(&ultHwConfig);
|
||||
ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false;
|
||||
|
||||
L0::DriverHandleImp *driverHandle = new DriverHandleImp;
|
||||
|
||||
std::string subDevice0String = std::get<0>(GetParam());
|
||||
uint32_t subDevice0Index = std::stoi(subDevice0String, nullptr, 0);
|
||||
|
||||
std::string subDevice1String = std::get<1>(GetParam());
|
||||
uint32_t subDevice1Index = std::stoi(subDevice1String, nullptr, 0);
|
||||
|
||||
constexpr uint32_t totalRootDevices = 2;
|
||||
|
||||
driverHandle->affinityMaskString = "0." + subDevice0String + "," + "1." + subDevice1String;
|
||||
DebugManager.flags.ZE_AFFINITY_MASK.set("0." + subDevice0String + "," + "1." + subDevice1String);
|
||||
|
||||
NEO::ExecutionEnvironment *executionEnvironment = new NEO::ExecutionEnvironment();
|
||||
auto devices = NEO::DeviceFactory::createDevices(*executionEnvironment);
|
||||
|
||||
ze_result_t res = driverHandle->initialize(std::move(devices));
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
@@ -383,24 +376,10 @@ TEST_P(DriverTestMultipleDeviceWithAffinityMask,
|
||||
ze_device_handle_t hDevice = phDevices[i];
|
||||
EXPECT_NE(nullptr, hDevice);
|
||||
|
||||
DeviceImp *device = reinterpret_cast<DeviceImp *>(L0::Device::fromHandle(hDevice));
|
||||
|
||||
uint32_t subDeviceCount = 0;
|
||||
res = zeDeviceGetSubDevices(hDevice, &subDeviceCount, nullptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
EXPECT_EQ(1u, subDeviceCount);
|
||||
|
||||
ze_device_handle_t hSubDevice;
|
||||
res = zeDeviceGetSubDevices(hDevice, &subDeviceCount, &hSubDevice);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
DeviceImp *subDevice = reinterpret_cast<DeviceImp *>(L0::Device::fromHandle(hSubDevice));
|
||||
|
||||
if (i == 0) {
|
||||
EXPECT_EQ(subDevice->neoDevice, device->neoDevice->getDeviceById(subDevice0Index));
|
||||
} else {
|
||||
EXPECT_EQ(subDevice->neoDevice, device->neoDevice->getDeviceById(subDevice1Index));
|
||||
}
|
||||
EXPECT_EQ(0u, subDeviceCount);
|
||||
}
|
||||
|
||||
delete driverHandle;
|
||||
@@ -409,14 +388,19 @@ TEST_P(DriverTestMultipleDeviceWithAffinityMask,
|
||||
|
||||
TEST_P(DriverTestMultipleDeviceWithAffinityMask,
|
||||
whenSettingAffinityMaskToRetrieveAllDevicesInOneDeviceAndOneSubDeviceInOtherThenCorrectDevicesAreExposed) {
|
||||
VariableBackup<UltHwConfig> backup(&ultHwConfig);
|
||||
ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false;
|
||||
|
||||
L0::DriverHandleImp *driverHandle = new DriverHandleImp;
|
||||
|
||||
std::string subDevice1String = std::get<1>(GetParam());
|
||||
uint32_t subDevice1Index = std::stoi(subDevice1String, nullptr, 0);
|
||||
|
||||
constexpr uint32_t totalRootDevices = 2;
|
||||
|
||||
driverHandle->affinityMaskString = "0,1." + subDevice1String;
|
||||
DebugManager.flags.ZE_AFFINITY_MASK.set("0,1." + subDevice1String);
|
||||
|
||||
NEO::ExecutionEnvironment *executionEnvironment = new NEO::ExecutionEnvironment();
|
||||
auto devices = NEO::DeviceFactory::createDevices(*executionEnvironment);
|
||||
|
||||
ze_result_t res = driverHandle->initialize(std::move(devices));
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
@@ -435,8 +419,6 @@ TEST_P(DriverTestMultipleDeviceWithAffinityMask,
|
||||
ze_device_handle_t hDevice = phDevices[i];
|
||||
EXPECT_NE(nullptr, hDevice);
|
||||
|
||||
DeviceImp *device = reinterpret_cast<DeviceImp *>(L0::Device::fromHandle(hDevice));
|
||||
|
||||
uint32_t subDeviceCount = 0;
|
||||
res = zeDeviceGetSubDevices(hDevice, &subDeviceCount, nullptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
@@ -447,10 +429,7 @@ TEST_P(DriverTestMultipleDeviceWithAffinityMask,
|
||||
res = zeDeviceGetSubDevices(hDevice, &subDeviceCount, &hSubDevice);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
DeviceImp *subDevice = reinterpret_cast<DeviceImp *>(L0::Device::fromHandle(hSubDevice));
|
||||
|
||||
EXPECT_EQ(1u, subDeviceCount);
|
||||
EXPECT_EQ(subDevice->neoDevice, device->neoDevice->getDeviceById(subDevice1Index));
|
||||
EXPECT_EQ(0u, subDeviceCount);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,11 +446,17 @@ INSTANTIATE_TEST_SUITE_P(DriverTestMultipleDeviceWithAffinityMaskTests,
|
||||
|
||||
TEST_F(DriverTestMultipleDeviceWithAffinityMask,
|
||||
whenSettingAffinityMaskWithDeviceLargerThanAvailableDevicesThenRootDeviceValueIsIgnored) {
|
||||
VariableBackup<UltHwConfig> backup(&ultHwConfig);
|
||||
ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false;
|
||||
|
||||
L0::DriverHandleImp *driverHandle = new DriverHandleImp;
|
||||
|
||||
constexpr uint32_t totalRootDevices = 2;
|
||||
uint32_t subDevice1Index = 0;
|
||||
driverHandle->affinityMaskString = "0,23,1." + std::to_string(subDevice1Index);
|
||||
DebugManager.flags.ZE_AFFINITY_MASK.set("0,23,1." + std::to_string(subDevice1Index));
|
||||
|
||||
NEO::ExecutionEnvironment *executionEnvironment = new NEO::ExecutionEnvironment();
|
||||
auto devices = NEO::DeviceFactory::createDevices(*executionEnvironment);
|
||||
|
||||
ze_result_t res = driverHandle->initialize(std::move(devices));
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
@@ -490,8 +475,6 @@ TEST_F(DriverTestMultipleDeviceWithAffinityMask,
|
||||
ze_device_handle_t hDevice = phDevices[i];
|
||||
EXPECT_NE(nullptr, hDevice);
|
||||
|
||||
DeviceImp *device = reinterpret_cast<DeviceImp *>(L0::Device::fromHandle(hDevice));
|
||||
|
||||
uint32_t subDeviceCount = 0;
|
||||
res = zeDeviceGetSubDevices(hDevice, &subDeviceCount, nullptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
@@ -501,11 +484,7 @@ TEST_F(DriverTestMultipleDeviceWithAffinityMask,
|
||||
ze_device_handle_t hSubDevice;
|
||||
res = zeDeviceGetSubDevices(hDevice, &subDeviceCount, &hSubDevice);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
DeviceImp *subDevice = reinterpret_cast<DeviceImp *>(L0::Device::fromHandle(hSubDevice));
|
||||
|
||||
EXPECT_EQ(1u, subDeviceCount);
|
||||
EXPECT_EQ(subDevice->neoDevice, device->neoDevice->getDeviceById(subDevice1Index));
|
||||
EXPECT_EQ(0u, subDeviceCount);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -515,9 +494,15 @@ TEST_F(DriverTestMultipleDeviceWithAffinityMask,
|
||||
|
||||
TEST_F(DriverTestMultipleDeviceWithAffinityMask,
|
||||
whenSettingAffinityMaskWithSubDeviceLargerThanAvailableSubDevicesThenSubDeviceValueIsIgnored) {
|
||||
VariableBackup<UltHwConfig> backup(&ultHwConfig);
|
||||
ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false;
|
||||
|
||||
L0::DriverHandleImp *driverHandle = new DriverHandleImp;
|
||||
|
||||
driverHandle->affinityMaskString = "0,1.77";
|
||||
DebugManager.flags.ZE_AFFINITY_MASK.set("0,1.77");
|
||||
|
||||
NEO::ExecutionEnvironment *executionEnvironment = new NEO::ExecutionEnvironment();
|
||||
auto devices = NEO::DeviceFactory::createDevices(*executionEnvironment);
|
||||
|
||||
ze_result_t res = driverHandle->initialize(std::move(devices));
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
Reference in New Issue
Block a user