fix: correct handling ZE_ENABLE_PCI_ID_DEVICE_ORDER flag

- by default ZE_ENABLE_PCI_ID_DEVICE_ORDER is disabled
- by default devices are sorted by type (discrete first), then by pci order
- when ZE_ENABLE_PCI_ID_DEVICE_ORDER is enabled, devices are sorted by pci id

Related-To: LOCI-4520

Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski 2023-06-13 15:19:02 +00:00 committed by Compute-Runtime-Automation
parent 13b0fb59f7
commit 3b981331c9
27 changed files with 278 additions and 674 deletions

View File

@ -13,7 +13,6 @@
#include "shared/source/os_interface/os_interface.h"
#include "shared/test/common/libult/linux/drm_mock.h"
#include "shared/test/common/mocks/mock_compilers.h"
#include "shared/test/common/mocks/mock_driver_model.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/mocks/ult_device_factory.h"
#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h"
@ -31,437 +30,6 @@ extern std::map<std::string, std::vector<std::string>> directoryFilesMap;
namespace L0 {
namespace ult {
constexpr int mockFd = 0;
class TestDriverMockDrm : public Drm {
public:
TestDriverMockDrm(std::string &bdf, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceIdDrm>(mockFd, bdf.c_str()), rootDeviceEnvironment) {}
};
class DriverLinuxFixture : public ::testing::Test {
public:
void SetUp() override {
auto executionEnvironment = new NEO::ExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfoAndInitHelpers(&hwInfo);
}
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = std::make_unique<NEO::DrmMemoryOperationsHandlerBind>(*executionEnvironment->rootDeviceEnvironments[i], i);
}
deviceFactory = std::make_unique<UltDeviceFactory>(numRootDevices, numSubDevices, *executionEnvironment);
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
devices.push_back(std::unique_ptr<NEO::Device>(deviceFactory->rootDevices[i]));
}
for (auto i = 0u; i < devices.size(); i++) {
devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface = std::make_unique<NEO::OSInterface>();
auto osInterface = devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface.get();
osInterface->setDriverModel(std::make_unique<TestDriverMockDrm>(bdf[i], const_cast<NEO::RootDeviceEnvironment &>(devices[i]->getRootDeviceEnvironment())));
}
executionEnvironment->sortNeoDevices();
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
NEO::DrmMemoryOperationsHandlerBind *drm = static_cast<DrmMemoryOperationsHandlerBind *>(executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface.get());
EXPECT_EQ(drm->getRootDeviceIndex(), i);
}
}
void TearDown() override {}
static constexpr uint32_t numRootDevices = 5u;
static constexpr uint32_t numSubDevices = 2u;
std::vector<std::unique_ptr<NEO::Device>> devices;
std::string bdf[numRootDevices] = {"0000:03:04.0", "0000:08:02.0", "0000:08:03.1", "0000:10:03.0", "0000:02:01.0"};
std::string sortedBdf[numRootDevices] = {"0000:02:01.0", "0000:03:04.0", "0000:08:02.0", "0000:08:03.1", "0000:10:03.0"};
std::unique_ptr<UltDeviceFactory> deviceFactory;
};
class DriverLinuxWithPciOrderTests : public DriverLinuxFixture {
public:
void SetUp() override {
DebugManagerStateRestore restorer;
DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(1);
DriverLinuxFixture::SetUp();
}
void TearDown() override {
DriverLinuxFixture::TearDown();
}
};
TEST_F(DriverLinuxWithPciOrderTests, GivenEnvironmentVariableForDeviceOrderAccordingToPciSetWhenRetrievingNeoDevicesThenNeoDevicesAccordingToBusOrderRetrieved) {
DriverHandleImp *driverHandle = new DriverHandleImp;
EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices)));
for (uint32_t i = 0; i < numRootDevices; i++) {
auto l0Device = driverHandle->devices[i];
if (l0Device != nullptr) {
auto pDrm = l0Device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[l0Device->getRootDeviceIndex()]->osInterface->getDriverModel()->as<Drm>();
EXPECT_NE(pDrm, nullptr);
EXPECT_TRUE(!pDrm->getPciPath().compare(sortedBdf[i]));
}
}
delete driverHandle;
}
class DriverLinuxWithouthPciOrderTests : public DriverLinuxFixture {
public:
void SetUp() override {
DebugManagerStateRestore restorer;
DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(0);
DriverLinuxFixture::SetUp();
}
void TearDown() override {
DriverLinuxFixture::TearDown();
}
};
TEST_F(DriverLinuxWithouthPciOrderTests, GivenNoEnvironmentVariableForDeviceOrderAccordingToPciSetWhenRetrievingNeoDevicesThenNeoDevicesAreNotSorted) {
DriverHandleImp *driverHandle = new DriverHandleImp;
EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices)));
for (uint32_t i = 0; i < numRootDevices; i++) {
auto l0Device = driverHandle->devices[i];
if (l0Device != nullptr) {
auto pDrm = l0Device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[l0Device->getRootDeviceIndex()]->osInterface->getDriverModel()->as<Drm>();
EXPECT_NE(pDrm, nullptr);
EXPECT_FALSE(!pDrm->getPciPath().compare(sortedBdf[i]));
}
}
delete driverHandle;
}
class DriverPciOrderWithSimilarBusLinuxFixture : public ::testing::Test {
public:
void SetUp() override {
DebugManagerStateRestore restorer;
DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(1);
auto executionEnvironment = new NEO::ExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfoAndInitHelpers(&hwInfo);
}
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = std::make_unique<NEO::DrmMemoryOperationsHandlerBind>(*executionEnvironment->rootDeviceEnvironments[i], i);
}
deviceFactory = std::make_unique<UltDeviceFactory>(numRootDevices, numSubDevices, *executionEnvironment);
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
devices.push_back(std::unique_ptr<NEO::Device>(deviceFactory->rootDevices[i]));
}
for (auto i = 0u; i < devices.size(); i++) {
devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface = std::make_unique<NEO::OSInterface>();
auto osInterface = devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface.get();
osInterface->setDriverModel(std::make_unique<TestDriverMockDrm>(bdf[i], const_cast<NEO::RootDeviceEnvironment &>(devices[i]->getRootDeviceEnvironment())));
}
executionEnvironment->sortNeoDevices();
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
NEO::DrmMemoryOperationsHandlerBind *drm = static_cast<DrmMemoryOperationsHandlerBind *>(executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface.get());
EXPECT_EQ(drm->getRootDeviceIndex(), i);
}
}
void TearDown() override {}
static constexpr uint32_t numRootDevices = 4u;
static constexpr uint32_t numSubDevices = 2u;
std::vector<std::unique_ptr<NEO::Device>> devices;
std::string bdf[numRootDevices] = {"0000:03:04.0", "0000:03:05.0", "0000:03:06.0", "0000:03:01.0"};
std::string sortedBdf[numRootDevices] = {"0000:03:01.0", "0000:03:04.0", "0000:03:05.0", "0000:03:06.0"};
std::unique_ptr<UltDeviceFactory> deviceFactory;
};
TEST_F(DriverPciOrderWithSimilarBusLinuxFixture, GivenEnvironmentVariableForDeviceOrderAccordingToPciSetWhenRetrievingNeoDevicesThenNeoDevicesAccordingToBusOrderRetrieved) {
DriverHandleImp *driverHandle = new DriverHandleImp;
EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices)));
for (uint32_t i = 0; i < numRootDevices; i++) {
auto l0Device = driverHandle->devices[i];
if (l0Device != nullptr) {
auto pDrm = l0Device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[l0Device->getRootDeviceIndex()]->osInterface->getDriverModel()->as<Drm>();
EXPECT_NE(pDrm, nullptr);
EXPECT_TRUE(!pDrm->getPciPath().compare(sortedBdf[i]));
}
}
delete driverHandle;
}
TEST_F(DriverPciOrderWithSimilarBusLinuxFixture,
GivenEnvironmentVariableForDeviceOrderAccordingToPciSetWhenRetrievingNeoDevicesAndThenInitializingVertexesThenNeoDevicesAccordingToBusOrderRetrieved) {
DriverHandleImp *driverHandle = new DriverHandleImp;
EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices)));
driverHandle->initializeVertexes();
for (uint32_t i = 0; i < numRootDevices; i++) {
auto l0Device = driverHandle->devices[i];
if (l0Device != nullptr) {
auto pDrm = l0Device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[l0Device->getRootDeviceIndex()]->osInterface->getDriverModel()->as<Drm>();
EXPECT_NE(pDrm, nullptr);
EXPECT_TRUE(!pDrm->getPciPath().compare(sortedBdf[i]));
}
}
delete driverHandle;
}
class DriverPciOrderWithDifferentDeviceLinuxFixture : public ::testing::Test {
public:
void SetUp() override {
DebugManagerStateRestore restorer;
DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(1);
auto executionEnvironment = new NEO::ExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfoAndInitHelpers(&hwInfo);
}
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = std::make_unique<NEO::DrmMemoryOperationsHandlerBind>(*executionEnvironment->rootDeviceEnvironments[i], i);
}
deviceFactory = std::make_unique<UltDeviceFactory>(numRootDevices, numSubDevices, *executionEnvironment);
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
devices.push_back(std::unique_ptr<NEO::Device>(deviceFactory->rootDevices[i]));
}
for (auto i = 0u; i < devices.size(); i++) {
devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface = std::make_unique<NEO::OSInterface>();
auto osInterface = devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface.get();
osInterface->setDriverModel(std::make_unique<TestDriverMockDrm>(bdf[i], const_cast<NEO::RootDeviceEnvironment &>(devices[i]->getRootDeviceEnvironment())));
}
executionEnvironment->sortNeoDevices();
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
NEO::DrmMemoryOperationsHandlerBind *drm = static_cast<DrmMemoryOperationsHandlerBind *>(executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface.get());
EXPECT_EQ(drm->getRootDeviceIndex(), i);
}
}
void TearDown() override {}
static constexpr uint32_t numRootDevices = 2u;
static constexpr uint32_t numSubDevices = 2u;
std::vector<std::unique_ptr<NEO::Device>> devices;
std::string bdf[numRootDevices] = {"0000:03:05.0", "0000:03:04.0"};
std::string sortedBdf[numRootDevices] = {"0000:03:04.0", "0000:03:05.0"};
std::unique_ptr<UltDeviceFactory> deviceFactory;
};
TEST_F(DriverPciOrderWithDifferentDeviceLinuxFixture, GivenEnvironmentVariableForDeviceOrderAccordingToPciSetWhenRetrievingNeoDevicesThenNeoDevicesAccordingToBusOrderRetrieved) {
DriverHandleImp *driverHandle = new DriverHandleImp;
EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices)));
for (uint32_t i = 0; i < numRootDevices; i++) {
auto l0Device = driverHandle->devices[i];
if (l0Device != nullptr) {
auto pDrm = l0Device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[l0Device->getRootDeviceIndex()]->osInterface->getDriverModel()->as<Drm>();
EXPECT_NE(pDrm, nullptr);
EXPECT_TRUE(!pDrm->getPciPath().compare(sortedBdf[i]));
}
}
delete driverHandle;
}
TEST_F(DriverPciOrderWithDifferentDeviceLinuxFixture,
GivenEnvironmentVariableForDeviceOrderAccordingToPciSetWhenRetrievingNeoDevicesAndThenInitializingVertexesThenNeoDevicesAccordingToBusOrderRetrieved) {
DriverHandleImp *driverHandle = new DriverHandleImp;
EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices)));
driverHandle->initializeVertexes();
for (uint32_t i = 0; i < numRootDevices; i++) {
auto l0Device = driverHandle->devices[i];
if (l0Device != nullptr) {
auto pDrm = l0Device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[l0Device->getRootDeviceIndex()]->osInterface->getDriverModel()->as<Drm>();
EXPECT_NE(pDrm, nullptr);
EXPECT_TRUE(!pDrm->getPciPath().compare(sortedBdf[i]));
}
}
delete driverHandle;
}
class DriverPciOrderWithSimilarBusAndDeviceLinuxFixture : public ::testing::Test {
public:
void SetUp() override {
DebugManagerStateRestore restorer;
DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(1);
auto executionEnvironment = new NEO::ExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfoAndInitHelpers(&hwInfo);
}
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = std::make_unique<NEO::DrmMemoryOperationsHandlerBind>(*executionEnvironment->rootDeviceEnvironments[i], i);
}
deviceFactory = std::make_unique<UltDeviceFactory>(numRootDevices, numSubDevices, *executionEnvironment);
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
devices.push_back(std::unique_ptr<NEO::Device>(deviceFactory->rootDevices[i]));
}
for (auto i = 0u; i < devices.size(); i++) {
devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface = std::make_unique<NEO::OSInterface>();
auto osInterface = devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface.get();
osInterface->setDriverModel(std::make_unique<TestDriverMockDrm>(bdf[i], const_cast<NEO::RootDeviceEnvironment &>(devices[i]->getRootDeviceEnvironment())));
}
executionEnvironment->sortNeoDevices();
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
NEO::DrmMemoryOperationsHandlerBind *drm = static_cast<DrmMemoryOperationsHandlerBind *>(executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface.get());
EXPECT_EQ(drm->getRootDeviceIndex(), i);
}
}
void TearDown() override {}
static constexpr uint32_t numRootDevices = 2u;
static constexpr uint32_t numSubDevices = 2u;
std::vector<std::unique_ptr<NEO::Device>> devices;
std::string bdf[numRootDevices] = {"0000:03:04.1", "0000:03:04.0"};
std::string sortedBdf[numRootDevices] = {"0000:03:04.0", "0000:03:04.1"};
std::unique_ptr<UltDeviceFactory> deviceFactory;
};
TEST_F(DriverPciOrderWithSimilarBusAndDeviceLinuxFixture, GivenEnvironmentVariableForDeviceOrderAccordingToPciSetWhenRetrievingNeoDevicesThenNeoDevicesAccordingToBusOrderRetrieved) {
DriverHandleImp *driverHandle = new DriverHandleImp;
EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices)));
for (uint32_t i = 0; i < numRootDevices; i++) {
auto l0Device = driverHandle->devices[i];
if (l0Device != nullptr) {
auto pDrm = l0Device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[l0Device->getRootDeviceIndex()]->osInterface->getDriverModel()->as<Drm>();
EXPECT_NE(pDrm, nullptr);
EXPECT_TRUE(!pDrm->getPciPath().compare(sortedBdf[i]));
}
}
delete driverHandle;
}
class DriverPciOrderWitSimilarBDFLinuxFixture : public ::testing::Test {
public:
void SetUp() override {
DebugManagerStateRestore restorer;
DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(1);
auto executionEnvironment = new NEO::MockExecutionEnvironment(NEO::defaultHwInfo.get(), true, numRootDevices);
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = std::make_unique<NEO::DrmMemoryOperationsHandlerBind>(*executionEnvironment->rootDeviceEnvironments[i], i);
}
deviceFactory = std::make_unique<UltDeviceFactory>(numRootDevices, numSubDevices, *executionEnvironment);
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
devices.push_back(std::unique_ptr<NEO::Device>(deviceFactory->rootDevices[i]));
}
for (auto i = 0u; i < devices.size(); i++) {
devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface = std::make_unique<NEO::OSInterface>();
auto osInterface = devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface.get();
osInterface->setDriverModel(std::make_unique<TestDriverMockDrm>(bdf[i], const_cast<NEO::RootDeviceEnvironment &>(devices[i]->getRootDeviceEnvironment())));
}
executionEnvironment->sortNeoDevices();
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
NEO::DrmMemoryOperationsHandlerBind *drm = static_cast<DrmMemoryOperationsHandlerBind *>(executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface.get());
EXPECT_EQ(drm->getRootDeviceIndex(), i);
}
}
void TearDown() override {}
static constexpr uint32_t numRootDevices = 2u;
static constexpr uint32_t numSubDevices = 2u;
std::vector<std::unique_ptr<NEO::Device>> devices;
std::string bdf[numRootDevices] = {"0001:03:04.0", "0000:03:04.0"};
std::string sortedBdf[numRootDevices] = {"0000:03:04.0", "0001:03:04.0"};
std::unique_ptr<UltDeviceFactory> deviceFactory;
};
TEST_F(DriverPciOrderWitSimilarBDFLinuxFixture, GivenEnvironmentVariableForDeviceOrderAccordingToPciSetWhenRetrievingNeoDevicesThenNeoDevicesAccordingToDomainOrderRetrieved) {
DriverHandleImp *driverHandle = new DriverHandleImp;
EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices)));
for (uint32_t i = 0; i < numRootDevices; i++) {
auto l0Device = driverHandle->devices[i];
if (l0Device != nullptr) {
auto pDrm = l0Device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[l0Device->getRootDeviceIndex()]->osInterface->getDriverModel()->as<Drm>();
EXPECT_NE(pDrm, nullptr);
EXPECT_TRUE(!pDrm->getPciPath().compare(sortedBdf[i]));
}
}
delete driverHandle;
}
class DriverPciOrderSortDoesNothing : public ::testing::Test {
public:
void SetUp() override {
DebugManagerStateRestore restorer;
DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(1);
auto executionEnvironment = new NEO::ExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfoAndInitHelpers(&hwInfo);
}
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = std::make_unique<NEO::DrmMemoryOperationsHandlerBind>(*executionEnvironment->rootDeviceEnvironments[i], i);
}
deviceFactory = std::make_unique<UltDeviceFactory>(numRootDevices, numSubDevices, *executionEnvironment);
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
devices.push_back(std::unique_ptr<NEO::Device>(deviceFactory->rootDevices[i]));
}
for (auto i = 0u; i < devices.size(); i++) {
devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface = std::make_unique<NEO::OSInterface>();
auto osInterface = devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface.get();
osInterface->setDriverModel(std::make_unique<TestDriverMockDrm>(bdf[i], const_cast<NEO::RootDeviceEnvironment &>(devices[i]->getRootDeviceEnvironment())));
}
executionEnvironment->sortNeoDevices();
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
NEO::DrmMemoryOperationsHandlerBind *drm = static_cast<DrmMemoryOperationsHandlerBind *>(executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface.get());
EXPECT_EQ(drm->getRootDeviceIndex(), i);
}
}
void TearDown() override {}
static constexpr uint32_t numRootDevices = 2u;
static constexpr uint32_t numSubDevices = 2u;
std::vector<std::unique_ptr<NEO::Device>> devices;
std::string bdf[numRootDevices] = {"0000:03:04.0", "0001:03:04.0"};
std::string sortedBdf[numRootDevices] = {"0000:03:04.0", "0001:03:04.0"};
std::unique_ptr<UltDeviceFactory> deviceFactory;
};
TEST_F(DriverPciOrderSortDoesNothing, GivenEnvironmentVariableForDeviceOrderAccordingToPciSetThenVerifyCaseSortDoesNothing) {
DriverHandleImp *driverHandle = new DriverHandleImp;
EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices)));
for (uint32_t i = 0; i < numRootDevices; i++) {
auto l0Device = driverHandle->devices[i];
if (l0Device != nullptr) {
auto pDrm = l0Device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[l0Device->getRootDeviceIndex()]->osInterface->getDriverModel()->as<Drm>();
EXPECT_NE(pDrm, nullptr);
EXPECT_TRUE(!pDrm->getPciPath().compare(sortedBdf[i]));
}
}
delete driverHandle;
}
class MockIoctlQueryFabricStats : public NEO::IoctlHelperPrelim20 {
public:
using IoctlHelperPrelim20::IoctlHelperPrelim20;
@ -875,59 +443,5 @@ TEST_F(DriverQueryPeerTestFail, whenQueryingPeerStatsWithFabricAndIoctlFailsThen
NEO::directoryFilesMap.clear();
}
class DriverWDDMLinuxFixture : public ::testing::Test {
public:
void SetUp() override {
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfoAndInitHelpers(&hwInfo);
}
deviceFactory = std::make_unique<UltDeviceFactory>(numRootDevices, numSubDevices, *executionEnvironment);
for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) {
devices.push_back(std::unique_ptr<NEO::Device>(deviceFactory->rootDevices[i]));
}
for (auto i = 0u; i < devices.size(); i++) {
devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface.reset(new NEO::OSInterface());
devices[i]->getExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface->setDriverModel(std::make_unique<NEO::MockDriverModelWDDM>());
}
}
void TearDown() override {}
NEO::ExecutionEnvironment *executionEnvironment = new NEO::ExecutionEnvironment();
static constexpr uint32_t numRootDevices = 5u;
static constexpr uint32_t numSubDevices = 2u;
std::vector<std::unique_ptr<NEO::Device>> devices;
std::unique_ptr<UltDeviceFactory> deviceFactory;
};
TEST_F(DriverWDDMLinuxFixture, ClearPciSortFlagToVerifyCodeCoverageOnly) {
DriverHandleImp *driverHandle = new DriverHandleImp;
EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices)));
DebugManagerStateRestore restorer;
DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(0);
executionEnvironment->sortNeoDevices();
delete driverHandle;
}
TEST_F(DriverWDDMLinuxFixture, ClearPciSortFlagWithFabricEnumerationToVerifyCodeCoverageOnly) {
DriverHandleImp *driverHandle = new DriverHandleImp;
EXPECT_EQ(ZE_RESULT_SUCCESS, driverHandle->initialize(std::move(devices)));
driverHandle->initializeVertexes();
DebugManagerStateRestore restorer;
DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(0);
executionEnvironment->sortNeoDevices();
delete driverHandle;
}
} // namespace ult
} // namespace L0

View File

@ -326,7 +326,7 @@ TEST_F(DeviceFactoryTest, givenPrepareDeviceEnvironmentsCallWhenItIsDoneThenOsIn
EXPECT_NE(nullptr, executionEnvironment->rootDeviceEnvironments[0]->osInterface);
}
TEST(DeviceFactory, givenCreateMultipleRootDevicesWhenCreateDevicesIsCalledThenVectorReturnedWouldContainFirstDiscreteDevicesThenIntegratedDevices) {
TEST(DeviceFactory, givenCreateMultipleRootDevicesWhenCreateDevicesIsCalledThenVectorReturnedWouldContainDevicesInTheSameOrder) {
uint32_t numRootDevices = 8u;
NEO::HardwareInfo hwInfo[8];
auto executionEnvironment = new NEO::ExecutionEnvironment();
@ -345,11 +345,8 @@ TEST(DeviceFactory, givenCreateMultipleRootDevicesWhenCreateDevicesIsCalledThenV
executionEnvironment->rootDeviceEnvironments[6]->getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = true;
executionEnvironment->rootDeviceEnvironments[7]->getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = false;
auto devices = DeviceFactory::createDevices(*executionEnvironment);
for (auto iterator = 0u; iterator < 3; iterator++) {
EXPECT_FALSE(devices[iterator]->getHardwareInfo().capabilityTable.isIntegratedDevice); // Initial entries would be for discrete devices
}
for (auto iterator = 3u; iterator < 8u; iterator++) {
EXPECT_TRUE(devices[iterator]->getHardwareInfo().capabilityTable.isIntegratedDevice); // Later entries would be for integrated
for (auto iterator = 0u; iterator < 8; iterator++) {
EXPECT_EQ(iterator, devices[iterator]->getRootDeviceIndex());
}
}

View File

@ -36,18 +36,13 @@ TEST(osInterfaceTests, whenOsInterfaceSetupGmmInputArgsThenArgsAreSet) {
uint32_t function = 0x56;
adapterBDF.Function = function;
auto adapterBDFretrieved = wddm->getAdapterBDF();
EXPECT_EQ(bus, adapterBDFretrieved.Bus);
EXPECT_EQ(device, adapterBDFretrieved.Device);
EXPECT_EQ(function, adapterBDFretrieved.Function);
GMM_INIT_IN_ARGS gmmInputArgs = {};
EXPECT_NE(0, memcmp(&wddm->getAdapterBDF(), &gmmInputArgs.stAdapterBDF, sizeof(ADAPTER_BDF)));
EXPECT_NE(0, memcmp(&wddm->adapterBDF, &gmmInputArgs.stAdapterBDF, sizeof(ADAPTER_BDF)));
EXPECT_STRNE(expectedRegistryPath, gmmInputArgs.DeviceRegistryPath);
rootDeviceEnvironment.osInterface->getDriverModel()->setGmmInputArgs(&gmmInputArgs);
EXPECT_EQ(0, memcmp(&wddm->getAdapterBDF(), &gmmInputArgs.stAdapterBDF, sizeof(ADAPTER_BDF)));
EXPECT_EQ(0, memcmp(&wddm->adapterBDF, &gmmInputArgs.stAdapterBDF, sizeof(ADAPTER_BDF)));
EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, gmmInputArgs.ClientType);
EXPECT_STREQ(expectedRegistryPath, gmmInputArgs.DeviceRegistryPath);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2022 Intel Corporation
* Copyright (C) 2020-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -14,4 +14,4 @@ DECLARE_DEBUG_VARIABLE(int32_t, OverrideDefaultFP64Settings, -1, "-1: dont overr
DECLARE_DEBUG_VARIABLE(bool, NEO_CAL_ENABLED, false, "Set by the Compute Aggregation Layer.")
DECLARE_DEBUG_VARIABLE(std::string, ZE_AFFINITY_MASK, std::string("default"), "Refer to the Level Zero Specification for a description")
DECLARE_DEBUG_VARIABLE(std::string, ZEX_NUMBER_OF_CCS, std::string("default"), "Define number of CCS engines per root device, e.g. setting Root Device Index 0 to 4 CCS, and Root Device Index 1 To 1 CCS: ZEX_NUMBER_OF_CCS=0:4,1:1")
DECLARE_DEBUG_VARIABLE(bool, ZE_ENABLE_PCI_ID_DEVICE_ORDER, true, "Refer to the Level Zero Specification for a description")
DECLARE_DEBUG_VARIABLE(bool, ZE_ENABLE_PCI_ID_DEVICE_ORDER, false, "Refer to the Level Zero Specification for a description")

View File

@ -1,12 +1,12 @@
#
# Copyright (C) 2022 Intel Corporation
# Copyright (C) 2022-2023 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
set(NEO_CORE_EXECUTION_ENVIRONMENT_DRM
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/execution_environment_drm.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sort_devices_drm.cpp
)
set_property(GLOBAL PROPERTY NEO_CORE_EXECUTION_ENVIRONMENT_DRM ${NEO_CORE_EXECUTION_ENVIRONMENT_DRM})

View File

@ -1,64 +0,0 @@
/*
* Copyright (C) 2021-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/os_interface/linux/drm_memory_operations_handler_bind.h"
#include "shared/source/os_interface/linux/drm_neo.h"
#include "shared/source/os_interface/os_interface.h"
#include <sstream>
namespace NEO {
bool comparePciIdBusNumberDRM(std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment1, std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment2) {
// BDF sample format is : 00:02.0
rootDeviceEnvironment1->osInterface->getDriverModel()->as<NEO::Drm>()->queryAdapterBDF();
auto bdfDevice1 = rootDeviceEnvironment1->osInterface->getDriverModel()->as<NEO::Drm>()->getAdapterBDF();
auto domain1 = rootDeviceEnvironment1->osInterface->getDriverModel()->as<NEO::Drm>()->getPciDomain();
rootDeviceEnvironment2->osInterface->getDriverModel()->as<NEO::Drm>()->queryAdapterBDF();
auto bdfDevice2 = rootDeviceEnvironment2->osInterface->getDriverModel()->as<NEO::Drm>()->getAdapterBDF();
auto domain2 = rootDeviceEnvironment2->osInterface->getDriverModel()->as<NEO::Drm>()->getPciDomain();
if (domain1 != domain2) {
return (domain1 < domain2);
}
if (bdfDevice1.Bus != bdfDevice2.Bus) {
return (bdfDevice1.Bus < bdfDevice2.Bus);
}
if (bdfDevice1.Device != bdfDevice2.Device) {
return (bdfDevice1.Device < bdfDevice2.Device);
}
return bdfDevice1.Function < bdfDevice2.Function;
}
void ExecutionEnvironment::sortNeoDevicesDRM() {
const auto pciOrderVar = DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.get();
if (pciOrderVar) {
std::vector<uint32_t> presortIndex;
for (uint32_t i = 0; i < rootDeviceEnvironments.size(); i++) {
NEO::DrmMemoryOperationsHandler *drm = static_cast<DrmMemoryOperationsHandler *>(rootDeviceEnvironments[i]->memoryOperationsInterface.get());
presortIndex.push_back(drm->getRootDeviceIndex());
}
std::sort(rootDeviceEnvironments.begin(), rootDeviceEnvironments.end(), comparePciIdBusNumberDRM);
for (uint32_t i = 0; i < rootDeviceEnvironments.size(); i++) {
NEO::DrmMemoryOperationsHandler *drm = static_cast<DrmMemoryOperationsHandler *>(rootDeviceEnvironments[i]->memoryOperationsInterface.get());
if (drm->getRootDeviceIndex() != presortIndex[i]) {
drm->setRootDeviceIndex(presortIndex[i]);
}
}
}
}
} // namespace NEO

View File

@ -0,0 +1,33 @@
/*
* Copyright (C) 2021-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/os_interface/linux/drm_memory_operations_handler_bind.h"
#include <algorithm>
namespace NEO {
void ExecutionEnvironment::sortNeoDevicesDRM() {
std::vector<uint32_t> presortIndex;
for (uint32_t i = 0; i < rootDeviceEnvironments.size(); i++) {
NEO::DrmMemoryOperationsHandler *drm = static_cast<DrmMemoryOperationsHandler *>(rootDeviceEnvironments[i]->memoryOperationsInterface.get());
presortIndex.push_back(drm->getRootDeviceIndex());
}
std::sort(rootDeviceEnvironments.begin(), rootDeviceEnvironments.end(), comparePciIdBusNumber);
for (uint32_t i = 0; i < rootDeviceEnvironments.size(); i++) {
NEO::DrmMemoryOperationsHandler *drm = static_cast<DrmMemoryOperationsHandler *>(rootDeviceEnvironments[i]->memoryOperationsInterface.get());
if (drm->getRootDeviceIndex() != presortIndex[i]) {
drm->setRootDeviceIndex(presortIndex[i]);
}
}
}
} // namespace NEO

View File

@ -19,6 +19,7 @@
#include "shared/source/helpers/string_helpers.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "shared/source/memory_manager/os_agnostic_memory_manager.h"
#include "shared/source/os_interface/driver_info.h"
#include "shared/source/os_interface/os_environment.h"
#include "shared/source/os_interface/os_interface.h"
#include "shared/source/os_interface/product_helper.h"
@ -312,4 +313,34 @@ void ExecutionEnvironment::configureNeoEnvironment() {
DebugManager.flags.SplitBcsSize.setIfDefault(256);
}
}
bool ExecutionEnvironment::comparePciIdBusNumber(std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment1, std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment2) {
const auto pciOrderVar = DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.get();
if (!pciOrderVar) {
auto isIntegrated1 = rootDeviceEnvironment1->getHardwareInfo()->capabilityTable.isIntegratedDevice;
auto isIntegrated2 = rootDeviceEnvironment2->getHardwareInfo()->capabilityTable.isIntegratedDevice;
if (isIntegrated1 != isIntegrated2) {
return isIntegrated2;
}
}
// BDF sample format is : 00:02.0
auto pciBusInfo1 = rootDeviceEnvironment1->osInterface->getDriverModel()->getPciBusInfo();
auto pciBusInfo2 = rootDeviceEnvironment2->osInterface->getDriverModel()->getPciBusInfo();
if (pciBusInfo1.pciDomain != pciBusInfo2.pciDomain) {
return (pciBusInfo1.pciDomain < pciBusInfo2.pciDomain);
}
if (pciBusInfo1.pciBus != pciBusInfo2.pciBus) {
return (pciBusInfo1.pciBus < pciBusInfo2.pciBus);
}
if (pciBusInfo1.pciDevice != pciBusInfo2.pciDevice) {
return (pciBusInfo1.pciDevice < pciBusInfo2.pciDevice);
}
return (pciBusInfo1.pciFunction < pciBusInfo2.pciFunction);
}
} // namespace NEO

View File

@ -58,6 +58,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
void releaseRootDeviceEnvironmentResources(RootDeviceEnvironment *rootDeviceEnvironment);
protected:
static bool comparePciIdBusNumber(std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment1, std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment2);
void parseCcsCountLimitations();
void adjustCcsCountImpl(RootDeviceEnvironment *rootDeviceEnvironment) const;
void configureNeoEnvironment();

View File

@ -1,12 +1,12 @@
#
# Copyright (C) 2021-2022 Intel Corporation
# Copyright (C) 2021-2023 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
set(NEO_CORE_EXECUTION_ENVIRONMENT_WDDM
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/execution_environment_wddm.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sort_devices_wddm.cpp
)
set_property(GLOBAL PROPERTY NEO_CORE_EXECUTION_ENVIRONMENT_WDDM ${NEO_CORE_EXECUTION_ENVIRONMENT_WDDM})

View File

@ -1,43 +0,0 @@
/*
* Copyright (C) 2021-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/os_interface/os_interface.h"
#include "shared/source/os_interface/windows/wddm/wddm.h"
#include <algorithm>
#include <sstream>
namespace NEO {
bool comparePciIdBusNumberWDDM(std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment1, std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment2) {
// BDF sample format is : 00:02.0
auto bdfDevice1 = rootDeviceEnvironment1->osInterface->getDriverModel()->as<NEO::Wddm>()->getAdapterBDF();
auto bdfDevice2 = rootDeviceEnvironment2->osInterface->getDriverModel()->as<NEO::Wddm>()->getAdapterBDF();
if (bdfDevice1.Bus != bdfDevice2.Bus) {
return (bdfDevice1.Bus < bdfDevice2.Bus);
}
if (bdfDevice1.Device != bdfDevice2.Device) {
return (bdfDevice1.Device < bdfDevice2.Device);
}
return bdfDevice1.Function < bdfDevice2.Function;
}
void ExecutionEnvironment::sortNeoDevicesWDDM() {
const auto pciOrderVar = DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.get();
if (pciOrderVar) {
std::sort(rootDeviceEnvironments.begin(), rootDeviceEnvironments.end(), comparePciIdBusNumberWDDM);
}
}
} // namespace NEO

View File

@ -0,0 +1,19 @@
/*
* Copyright (C) 2021-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include <algorithm>
namespace NEO {
void ExecutionEnvironment::sortNeoDevicesWDDM() {
std::sort(rootDeviceEnvironments.begin(), rootDeviceEnvironments.end(), comparePciIdBusNumber);
}
} // namespace NEO

View File

@ -229,18 +229,9 @@ std::vector<std::unique_ptr<Device>> DeviceFactory::createDevices(ExecutionEnvir
return devices;
}
auto discreteDeviceIndex = 0u;
for (uint32_t rootDeviceIndex = 0u; rootDeviceIndex < executionEnvironment.rootDeviceEnvironments.size(); rootDeviceIndex++) {
auto device = createRootDeviceFunc(executionEnvironment, rootDeviceIndex);
if (device) {
if (device->getHardwareInfo().capabilityTable.isIntegratedDevice == false) {
// If we are here, it means we are processing entry for discrete device.
// And lets first insert discrete device's entry in devices vector.
devices.insert(devices.begin() + discreteDeviceIndex, std::move(device));
discreteDeviceIndex++;
continue;
}
// Ensure to push integrated device's entry at the end of devices vector
devices.push_back(std::move(device));
}
}

View File

@ -786,7 +786,6 @@ int Drm::queryAdapterBDF() {
void Drm::setGmmInputArgs(void *args) {
auto gmmInArgs = reinterpret_cast<GMM_INIT_IN_ARGS *>(args);
auto adapterBDF = this->getAdapterBDF();
#if defined(__linux__)
gmmInArgs->FileDescriptor = adapterBDF.Data;
#endif

View File

@ -103,9 +103,6 @@ class Drm : public DriverModel {
MOCKABLE_VIRTUAL void checkPreemptionSupport();
inline int getFileDescriptor() const { return hwDeviceId->getFileDescriptor(); }
ADAPTER_BDF getAdapterBDF() const {
return adapterBDF;
}
int queryAdapterBDF();
MOCKABLE_VIRTUAL int createDrmVirtualMemory(uint32_t &drmVmId);
void destroyDrmVirtualMemory(uint32_t drmVmId);
@ -247,9 +244,6 @@ class Drm : public DriverModel {
pciDomain = domain;
}
uint32_t getPciDomain() {
return pciDomain;
}
MOCKABLE_VIRTUAL std::vector<uint8_t> getMemoryRegions();
MOCKABLE_VIRTUAL bool completionFenceSupport();

View File

@ -193,10 +193,6 @@ class Wddm : public DriverModel {
static std::vector<std::unique_ptr<HwDeviceId>> discoverDevices(ExecutionEnvironment &executionEnvironment);
ADAPTER_BDF getAdapterBDF() const {
return adapterBDF;
}
PhysicalDevicePciSpeedInfo getPciSpeedInfo() const override;
bool buildTopologyMapping();

View File

@ -24,6 +24,7 @@ using namespace NEO;
class DrmMock : public Drm {
public:
using Drm::adapterBDF;
using Drm::bindAvailable;
using Drm::cacheInfo;
using Drm::checkQueueSliceSupport;

View File

@ -18,7 +18,8 @@ namespace NEO {
class MockDriverModel : public NEO::DriverModel {
public:
MockDriverModel() : NEO::DriverModel(NEO::DriverModelType::UNKNOWN) {}
MockDriverModel() : MockDriverModel(NEO::DriverModelType::UNKNOWN) {}
MockDriverModel(DriverModelType driverModelType) : DriverModel(driverModelType) {}
void setGmmInputArgs(void *args) override {}

View File

@ -11,7 +11,7 @@ OverrideGdiPath = unk
AubDumpAddMmioRegistersList = unk
ZE_AFFINITY_MASK = default
ZEX_NUMBER_OF_CCS = default
ZE_ENABLE_PCI_ID_DEVICE_ORDER = 1
ZE_ENABLE_PCI_ID_DEVICE_ORDER = 0
NEO_CAL_ENABLED = 0
AUBDumpFilterNamedKernelStartIdx = 0
AUBDumpFilterNamedKernelEndIdx = -1

View File

@ -7,4 +7,6 @@
target_sources(neo_shared_tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/execution_environment_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/execution_environment_tests.h
${CMAKE_CURRENT_SOURCE_DIR}/execution_environment_tests_helper_${DRIVER_MODEL}.cpp
)

View File

@ -5,6 +5,8 @@
*
*/
#include "shared/test/unit_test/execution_environment/execution_environment_tests.h"
#include "shared/source/aub/aub_center.h"
#include "shared/source/built_ins/built_ins.h"
#include "shared/source/compiler_interface/compiler_interface.h"
@ -23,6 +25,7 @@
#include "shared/source/source_level_debugger/source_level_debugger.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/mock_driver_model.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/mocks/mock_memory_manager.h"
#include "shared/test/common/mocks/mock_memory_operations_handler.h"
@ -324,11 +327,11 @@ TEST(ExecutionEnvironment, givenMultipleRootDevicesWhenTheyAreCreatedThenReuseMe
EXPECT_EQ(memoryManager, device2->getMemoryManager());
}
uint64_t isDriverAvailableCounter = 0u;
uint32_t isDriverAvailableCounter = 0u;
class DriverModelMock : public DriverModel {
class DefaultDriverModelMock : public MockDriverModel {
public:
DriverModelMock(DriverModelType driverModelType) : DriverModel(driverModelType) {
DefaultDriverModelMock(DriverModelType driverModelType) : MockDriverModel(driverModelType) {
}
bool isDriverAvailable() override {
@ -358,43 +361,12 @@ class DriverModelMock : public DriverModel {
}
};
class DefaultDriverModelMock : public DriverModel {
public:
DefaultDriverModelMock(DriverModelType driverModelType) : DriverModel(driverModelType) {
}
bool isDriverAvailable() override {
return true;
}
void setGmmInputArgs(void *args) override {
}
uint32_t getDeviceHandle() const override {
return 0;
}
PhysicalDevicePciBusInfo getPciBusInfo() const override {
return {};
}
PhysicalDevicePciSpeedInfo getPciSpeedInfo() const override {
return {};
}
bool skipResourceCleanup() const {
return skipResourceCleanupVar;
}
bool isGpuHangDetected(OsContext &osContext) override {
return false;
}
};
TEST(ExecutionEnvironment, givenRootDeviceWhenPrepareForCleanupThenIsDriverAvailableIsCalled) {
VariableBackup<uint64_t> varBackup = &isDriverAvailableCounter;
VariableBackup<uint32_t> varBackup{&isDriverAvailableCounter, 0u};
ExecutionEnvironment executionEnvironment{};
std::unique_ptr<OSInterface> osInterface = std::make_unique<OSInterface>();
osInterface->setDriverModel(std::make_unique<DriverModelMock>(DriverModelType::UNKNOWN));
osInterface->setDriverModel(std::make_unique<DefaultDriverModelMock>(DriverModelType::UNKNOWN));
executionEnvironment.prepareRootDeviceEnvironments(1);
executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::move(osInterface);
@ -463,3 +435,43 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenSettingFP64EmulationEnab
executionEnvironment.setFP64EmulationEnabled();
EXPECT_TRUE(executionEnvironment.isFP64EmulationEnabled());
}
void ExecutionEnvironmentSortTests::SetUp() {
executionEnvironment.prepareRootDeviceEnvironments(numRootDevices);
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < numRootDevices; rootDeviceIndex++) {
setupOsSpecifcEnvironment(rootDeviceIndex);
executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = false;
}
executionEnvironment.rootDeviceEnvironments[1]->getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = true; // {0,0,2,0}
executionEnvironment.rootDeviceEnvironments[3]->getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = true; // {0,1,2,1}
}
TEST_F(ExecutionEnvironmentSortTests, givenEnabledPciIdDeviceOrderFlagWhenSortingDevicesThenRootDeviceEnvironmentsAreSortedByPciId) {
DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(1);
NEO::PhysicalDevicePciBusInfo expectedBusInfos[numRootDevices] = {{0, 0, 2, 0}, {0, 0, 2, 1}, {0, 1, 2, 1}, {0, 1, 3, 0}, {3, 1, 2, 0}, {3, 1, 2, 1}};
executionEnvironment.sortNeoDevices();
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < numRootDevices; rootDeviceIndex++) {
auto pciBusInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->getDriverModel()->getPciBusInfo();
EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciDomain, pciBusInfo.pciDomain);
EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciBus, pciBusInfo.pciBus);
EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciDevice, pciBusInfo.pciDevice);
EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciFunction, pciBusInfo.pciFunction);
}
}
TEST_F(ExecutionEnvironmentSortTests, givenDisabledPciIdDeviceOrderFlagWhenSortingDevicesThenRootDeviceEnvironmentsAreSortedByTypeThenByPciOrder) {
DebugManager.flags.ZE_ENABLE_PCI_ID_DEVICE_ORDER.set(0);
NEO::PhysicalDevicePciBusInfo expectedBusInfos[numRootDevices] = {{0, 0, 2, 1}, {0, 1, 3, 0}, {3, 1, 2, 0}, {3, 1, 2, 1}, {0, 0, 2, 0}, {0, 1, 2, 1}};
executionEnvironment.sortNeoDevices();
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < numRootDevices; rootDeviceIndex++) {
auto pciBusInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->getDriverModel()->getPciBusInfo();
EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciDomain, pciBusInfo.pciDomain);
EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciBus, pciBusInfo.pciBus);
EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciDevice, pciBusInfo.pciDevice);
EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciFunction, pciBusInfo.pciFunction);
}
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/os_interface/driver_info.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/test_macros/test.h"
namespace NEO {
class ExecutionEnvironmentSortTests : public ::testing::Test {
public:
void SetUp() override;
void setupOsSpecifcEnvironment(uint32_t rootDeviceIndex);
DebugManagerStateRestore restorer;
ExecutionEnvironment executionEnvironment{};
static const auto numRootDevices = 6;
NEO::PhysicalDevicePciBusInfo inputBusInfos[numRootDevices] = {{3, 1, 2, 1}, {0, 0, 2, 0}, {0, 1, 3, 0}, {0, 1, 2, 1}, {0, 0, 2, 1}, {3, 1, 2, 0}};
};
} // namespace NEO

View File

@ -0,0 +1,23 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/os_interface/linux/drm_memory_operations_handler_bind.h"
#include "shared/test/common/mocks/mock_driver_model.h"
#include "shared/test/unit_test/execution_environment/execution_environment_tests.h"
using namespace NEO;
void ExecutionEnvironmentSortTests::setupOsSpecifcEnvironment(uint32_t rootDeviceIndex) {
auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex];
auto osInterface = std::make_unique<OSInterface>();
auto driverModel = std::make_unique<MockDriverModel>(DriverModelType::DRM);
driverModel->pciBusInfo = inputBusInfos[rootDeviceIndex];
osInterface->setDriverModel(std::move(driverModel));
rootDeviceEnvironment.osInterface = std::move(osInterface);
rootDeviceEnvironment.memoryOperationsInterface = std::make_unique<DrmMemoryOperationsHandlerBind>(rootDeviceEnvironment, rootDeviceIndex);
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/test/common/mocks/mock_driver_model.h"
#include "shared/test/unit_test/execution_environment/execution_environment_tests.h"
using namespace NEO;
void ExecutionEnvironmentSortTests::setupOsSpecifcEnvironment(uint32_t rootDeviceIndex) {
auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex];
auto osInterface = std::make_unique<OSInterface>();
auto driverModel = std::make_unique<MockDriverModel>(DriverModelType::WDDM);
driverModel->pciBusInfo = inputBusInfos[rootDeviceIndex];
osInterface->setDriverModel(std::move(driverModel));
rootDeviceEnvironment.osInterface = std::move(osInterface);
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/test/common/mocks/mock_driver_model.h"
#include "shared/test/unit_test/execution_environment/execution_environment_tests.h"
using namespace NEO;
void ExecutionEnvironmentSortTests::setupOsSpecifcEnvironment(uint32_t rootDeviceIndex) {
auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex];
auto osInterface = std::make_unique<OSInterface>();
auto driverModel = std::make_unique<MockDriverModel>(DriverModelType::WDDM);
driverModel->pciBusInfo = inputBusInfos[rootDeviceIndex];
osInterface->setDriverModel(std::move(driverModel));
rootDeviceEnvironment.osInterface = std::move(osInterface);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2022 Intel Corporation
* Copyright (C) 2018-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -9,8 +9,11 @@
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/os_interface/device_factory.h"
#include "shared/source/os_interface/driver_info.h"
#include "shared/source/os_interface/linux/drm_memory_operations_handler_bind.h"
#include "shared/source/os_interface/os_interface.h"
#include "shared/test/common/helpers/default_hw_info.h"
#include "shared/test/common/mocks/mock_driver_model.h"
TEST_F(DeviceFactoryLinuxTest, WhenPreparingDeviceEnvironmentsThenInitializedCorrectly) {
const HardwareInfo *refHwinfo = defaultHwInfo.get();
@ -64,3 +67,32 @@ TEST_F(DeviceFactoryLinuxTest, whenDrmIsNotCretedThenPrepareDeviceEnvironmentsFa
bool success = DeviceFactory::prepareDeviceEnvironments(executionEnvironment);
EXPECT_FALSE(success);
}
TEST(SortDevicesDrmTest, whenSortingDevicesThenMemoryOperationHandlersHaveProperIndices) {
ExecutionEnvironment executionEnvironment{};
static const auto numRootDevices = 6;
NEO::PhysicalDevicePciBusInfo inputBusInfos[numRootDevices] = {{3, 1, 2, 1}, {0, 0, 2, 0}, {0, 1, 3, 0}, {0, 1, 2, 1}, {0, 0, 2, 1}, {3, 1, 2, 0}};
NEO::PhysicalDevicePciBusInfo expectedBusInfos[numRootDevices] = {{0, 0, 2, 0}, {0, 0, 2, 1}, {0, 1, 2, 1}, {0, 1, 3, 0}, {3, 1, 2, 0}, {3, 1, 2, 1}};
executionEnvironment.prepareRootDeviceEnvironments(numRootDevices);
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < numRootDevices; rootDeviceIndex++) {
auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[rootDeviceIndex];
auto osInterface = std::make_unique<OSInterface>();
auto driverModel = std::make_unique<MockDriverModel>(DriverModelType::DRM);
driverModel->pciBusInfo = inputBusInfos[rootDeviceIndex];
osInterface->setDriverModel(std::move(driverModel));
rootDeviceEnvironment.osInterface = std::move(osInterface);
rootDeviceEnvironment.memoryOperationsInterface = std::make_unique<DrmMemoryOperationsHandlerBind>(rootDeviceEnvironment, rootDeviceIndex);
}
executionEnvironment.sortNeoDevices();
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < numRootDevices; rootDeviceIndex++) {
auto pciBusInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->osInterface->getDriverModel()->getPciBusInfo();
EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciDomain, pciBusInfo.pciDomain);
EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciBus, pciBusInfo.pciBus);
EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciDevice, pciBusInfo.pciDevice);
EXPECT_EQ(expectedBusInfos[rootDeviceIndex].pciFunction, pciBusInfo.pciFunction);
EXPECT_EQ(rootDeviceIndex, static_cast<DrmMemoryOperationsHandlerBind &>(*executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface).getRootDeviceIndex());
}
}

View File

@ -60,7 +60,7 @@ TEST(DrmTest, GivenValidPciPathWhenGettingAdapterBdfThenCorrectValuesAreReturned
{
drm.setPciPath("0000:ab:cd.e");
EXPECT_EQ(0, drm.queryAdapterBDF());
auto adapterBdf = drm.getAdapterBDF();
auto adapterBdf = drm.adapterBDF;
EXPECT_EQ(0xabu, adapterBdf.Bus);
EXPECT_EQ(0xcdu, adapterBdf.Device);
EXPECT_EQ(0xeu, adapterBdf.Function);
@ -75,7 +75,7 @@ TEST(DrmTest, GivenValidPciPathWhenGettingAdapterBdfThenCorrectValuesAreReturned
{
drm.setPciPath("0000:01:23.4");
EXPECT_EQ(0, drm.queryAdapterBDF());
auto adapterBdf = drm.getAdapterBDF();
auto adapterBdf = drm.adapterBDF;
EXPECT_EQ(0x1u, adapterBdf.Bus);
EXPECT_EQ(0x23u, adapterBdf.Device);
EXPECT_EQ(0x4u, adapterBdf.Function);
@ -94,7 +94,7 @@ TEST(DrmTest, GivenInvalidPciPathWhenGettingAdapterBdfThenInvalidPciInfoIsReturn
drm.setPciPath("invalidPci");
EXPECT_EQ(1, drm.queryAdapterBDF());
auto adapterBdf = drm.getAdapterBDF();
auto adapterBdf = drm.adapterBDF;
EXPECT_EQ(std::numeric_limits<uint32_t>::max(), adapterBdf.Data);
auto pciInfo = drm.getPciBusInfo();