mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 14:55:24 +08:00
Expose devices according to ZE_AFFINITY_MASK
Change-Id: Ic8025a818b006c25f790688ef51bda6eeb4f03ad Signed-off: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
80f9b5e45a
commit
8ce44b0689
@@ -96,7 +96,7 @@ ze_result_t Mock<DriverHandle>::doFreeMem(const void *ptr) {
|
||||
void Mock<DriverHandle>::setupDevices(std::vector<std::unique_ptr<NEO::Device>> neoDevices) {
|
||||
this->numDevices = static_cast<uint32_t>(neoDevices.size());
|
||||
for (auto &neoDevice : neoDevices) {
|
||||
auto device = Device::create(this, neoDevice.release());
|
||||
auto device = Device::create(this, neoDevice.release(), std::numeric_limits<uint32_t>::max());
|
||||
this->devices.push_back(device);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,21 +76,21 @@ HWTEST_F(TestBuiltinFunctionsLibImpl, givenInitFunctionWhenBultinsTableConstainN
|
||||
|
||||
HWTEST_F(TestBuiltinFunctionsLibImpl, givenCompilerInterfaceWhenCreateDeviceAndImageSupportedThenBuiltinsImageFunctionsAreLoaded) {
|
||||
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[neoDevice->getRootDeviceIndex()]->compilerInterface.reset(new NEO::MockCompilerInterface());
|
||||
std::unique_ptr<L0::Device> testDvice(Device::create(device->getDriverHandle(), neoDevice));
|
||||
std::unique_ptr<L0::Device> testDevice(Device::create(device->getDriverHandle(), neoDevice, std::numeric_limits<uint32_t>::max()));
|
||||
|
||||
if (device->getHwInfo().capabilityTable.supportsImages) {
|
||||
for (uint32_t builtId = 0; builtId < static_cast<uint32_t>(ImageBuiltin::COUNT); builtId++) {
|
||||
EXPECT_NE(nullptr, testDvice->getBuiltinFunctionsLib()->getImageFunction(static_cast<L0::ImageBuiltin>(builtId)));
|
||||
EXPECT_NE(nullptr, testDevice->getBuiltinFunctionsLib()->getImageFunction(static_cast<L0::ImageBuiltin>(builtId)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST_F(TestBuiltinFunctionsLibImpl, givenCompilerInterfaceWhenCreateDeviceThenBuiltinsFunctionsAreLoaded) {
|
||||
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[neoDevice->getRootDeviceIndex()]->compilerInterface.reset(new NEO::MockCompilerInterface());
|
||||
std::unique_ptr<L0::Device> testDvice(Device::create(device->getDriverHandle(), neoDevice));
|
||||
std::unique_ptr<L0::Device> testDevice(Device::create(device->getDriverHandle(), neoDevice, std::numeric_limits<uint32_t>::max()));
|
||||
|
||||
for (uint32_t builtId = 0; builtId < static_cast<uint32_t>(Builtin::COUNT); builtId++) {
|
||||
EXPECT_NE(nullptr, testDvice->getBuiltinFunctionsLib()->getFunction(static_cast<L0::Builtin>(builtId)));
|
||||
EXPECT_NE(nullptr, testDevice->getBuiltinFunctionsLib()->getFunction(static_cast<L0::Builtin>(builtId)));
|
||||
}
|
||||
}
|
||||
} // namespace ult
|
||||
|
||||
@@ -191,6 +191,32 @@ struct MultipleDevicesTest : public ::testing::Test {
|
||||
const uint32_t numSubDevices = 2u;
|
||||
};
|
||||
|
||||
TEST_F(MultipleDevicesTest, whenDeviceContainsSubDevicesThenItIsMultiDeviceCapable) {
|
||||
L0::Device *device0 = driverHandle->devices[0];
|
||||
EXPECT_TRUE(device0->isMultiDeviceCapable());
|
||||
|
||||
L0::Device *device1 = driverHandle->devices[1];
|
||||
EXPECT_TRUE(device1->isMultiDeviceCapable());
|
||||
}
|
||||
|
||||
TEST_F(MultipleDevicesTest, whenRetrievingNumberOfSubdevicesThenCorrectNumberIsReturned) {
|
||||
L0::Device *device0 = driverHandle->devices[0];
|
||||
|
||||
uint32_t count = 0;
|
||||
auto result = device0->getSubDevices(&count, nullptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(numSubDevices, count);
|
||||
|
||||
std::vector<ze_device_handle_t> subDevices(count);
|
||||
count++;
|
||||
result = device0->getSubDevices(&count, subDevices.data());
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(numSubDevices, count);
|
||||
for (auto subDevice : subDevices) {
|
||||
EXPECT_NE(nullptr, subDevice);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MultipleDevicesTest, givenTheSameDeviceThenCanAccessPeerReturnsTrue) {
|
||||
L0::Device *device0 = driverHandle->devices[0];
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include "level_zero/core/source/driver/driver_handle_imp.h"
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
|
||||
#include <bitset>
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
@@ -126,5 +128,119 @@ TEST_F(DriverTestMultipleFamilyNoSupport, whenInitializingDriverWithArrayOfNotSu
|
||||
EXPECT_EQ(nullptr, driverHandle);
|
||||
}
|
||||
|
||||
struct DriverTestMultipleDeviceWithAffinityMask : public ::testing::WithParamInterface<std::tuple<int, int>>,
|
||||
public ::testing::Test {
|
||||
void SetUp() override {
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
void getNumOfExposedDevices(uint32_t mask, uint32_t &rootDeviceExposed, uint32_t &numOfSubDevicesExposed) {
|
||||
rootDeviceExposed = (((1UL << numSubDevices) - 1) & mask) ? 1 : 0;
|
||||
numOfSubDevicesExposed = static_cast<uint32_t>(static_cast<std::bitset<sizeof(uint32_t) * 8>>(mask).count());
|
||||
}
|
||||
|
||||
DebugManagerStateRestore restorer;
|
||||
std::vector<std::unique_ptr<NEO::Device>> devices;
|
||||
|
||||
const uint32_t numRootDevices = 2u;
|
||||
const uint32_t numSubDevices = 4u;
|
||||
};
|
||||
|
||||
TEST_F(DriverTestMultipleDeviceWithAffinityMask, whenNotSettingAffinityThenAllRootDevicesAndSubDevicesAreExposed) {
|
||||
L0::DriverHandleImp *driverHandle = new DriverHandleImp;
|
||||
|
||||
ze_result_t res = driverHandle->initialize(std::move(devices));
|
||||
uint32_t deviceCount = 0;
|
||||
res = zeDeviceGet(driverHandle->toHandle(), &deviceCount, nullptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
EXPECT_EQ(deviceCount, numRootDevices);
|
||||
|
||||
std::vector<ze_device_handle_t> phDevices(deviceCount);
|
||||
res = zeDeviceGet(driverHandle->toHandle(), &deviceCount, phDevices.data());
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
for (uint32_t i = 0; i < numRootDevices; i++) {
|
||||
ze_device_handle_t hDevice = phDevices[i];
|
||||
EXPECT_NE(nullptr, hDevice);
|
||||
|
||||
uint32_t subDeviceCount = 0;
|
||||
res = zeDeviceGetSubDevices(hDevice, &subDeviceCount, nullptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
EXPECT_EQ(numSubDevices, subDeviceCount);
|
||||
}
|
||||
|
||||
delete driverHandle;
|
||||
}
|
||||
|
||||
TEST_P(DriverTestMultipleDeviceWithAffinityMask, whenSettingAffinityMaskToDifferentValuesThenCorrectNumberOfDevicesIsExposed) {
|
||||
L0::DriverHandleImp *driverHandle = new DriverHandleImp;
|
||||
|
||||
uint32_t device0Mask = std::get<0>(GetParam());
|
||||
uint32_t rootDevice0Exposed = 0;
|
||||
uint32_t numOfSubDevicesExposedInDevice0 = 0;
|
||||
getNumOfExposedDevices(device0Mask, rootDevice0Exposed, numOfSubDevicesExposedInDevice0);
|
||||
uint32_t device1Mask = std::get<1>(GetParam());
|
||||
uint32_t rootDevice1Exposed = 0;
|
||||
uint32_t numOfSubDevicesExposedInDevice1 = 0;
|
||||
getNumOfExposedDevices(device1Mask, rootDevice1Exposed, numOfSubDevicesExposedInDevice1);
|
||||
|
||||
driverHandle->affinityMask = device0Mask | (device1Mask << numSubDevices);
|
||||
|
||||
ze_result_t res = driverHandle->initialize(std::move(devices));
|
||||
uint32_t deviceCount = 0;
|
||||
res = zeDeviceGet(driverHandle->toHandle(), &deviceCount, nullptr);
|
||||
|
||||
uint32_t totalRootDevices = rootDevice0Exposed + rootDevice1Exposed;
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
EXPECT_EQ(deviceCount, totalRootDevices);
|
||||
|
||||
if (deviceCount) {
|
||||
std::vector<ze_device_handle_t> phDevices(deviceCount);
|
||||
res = zeDeviceGet(driverHandle->toHandle(), &deviceCount, phDevices.data());
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
|
||||
for (uint32_t i = 0; i < deviceCount; i++) {
|
||||
ze_device_handle_t hDevice = phDevices[i];
|
||||
EXPECT_NE(nullptr, hDevice);
|
||||
|
||||
uint32_t subDeviceCount = 0;
|
||||
res = zeDeviceGetSubDevices(hDevice, &subDeviceCount, nullptr);
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
|
||||
if (rootDevice0Exposed && !rootDevice1Exposed) {
|
||||
EXPECT_EQ(numOfSubDevicesExposedInDevice0, subDeviceCount);
|
||||
} else if (!rootDevice0Exposed && rootDevice1Exposed) {
|
||||
EXPECT_EQ(numOfSubDevicesExposedInDevice1, subDeviceCount);
|
||||
} else {
|
||||
if (i == 0) {
|
||||
EXPECT_EQ(numOfSubDevicesExposedInDevice0, subDeviceCount);
|
||||
} else {
|
||||
EXPECT_EQ(numOfSubDevicesExposedInDevice1, subDeviceCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete driverHandle;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(DriverTestMultipleDeviceWithAffinityMaskTests,
|
||||
DriverTestMultipleDeviceWithAffinityMask,
|
||||
::testing::Combine(
|
||||
::testing::Range(0, 15), // Masks for 1 root device with 4 sub devices
|
||||
::testing::Range(0, 15)));
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
|
||||
Reference in New Issue
Block a user