refactor: unify device hierarchy mode

Related-To: GSD-9560
Signed-off-by: Jaroslaw Warchulski <jaroslaw.warchulski@intel.com>
This commit is contained in:
Jaroslaw Warchulski 2025-01-14 16:36:45 +00:00 committed by Compute-Runtime-Automation
parent 84b8622c16
commit 6a7bee67e9
30 changed files with 216 additions and 382 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2024 Intel Corporation
* Copyright (C) 2020-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -663,9 +663,8 @@ ze_result_t DeviceImp::getP2PProperties(ze_device_handle_t hPeerDevice,
}
ze_result_t DeviceImp::getRootDevice(ze_device_handle_t *phRootDevice) {
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(driverHandle);
// Given FLAT device Hierarchy mode, then nullptr is returned for the root device since no traversal is allowed.
if (driverHandleImp->deviceHierarchyMode == L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_FLAT) {
if (this->neoDevice->getExecutionEnvironment()->getDeviceHierarchyMode() == NEO::DeviceHierarchyMode::FLAT) {
*phRootDevice = nullptr;
return ZE_RESULT_SUCCESS;
}
@ -1006,12 +1005,9 @@ ze_result_t DeviceImp::getProperties(ze_device_properties_t *pDeviceProperties)
pDeviceProperties->flags |= ZE_DEVICE_PROPERTY_FLAG_INTEGRATED;
}
if (isSubdevice) {
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(driverHandle);
if (driverHandleImp->deviceHierarchyMode != L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_FLAT) {
if (isSubdevice && this->neoDevice->getExecutionEnvironment()->getDeviceHierarchyMode() != NEO::DeviceHierarchyMode::FLAT) {
pDeviceProperties->flags |= ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE;
}
}
if (this->neoDevice->getDeviceInfo().errorCorrectionSupport) {
pDeviceProperties->flags |= ZE_DEVICE_PROPERTY_FLAG_ECC;
@ -1198,9 +1194,8 @@ ze_result_t DeviceImp::getGlobalTimestampsUsingOsInterface(uint64_t *hostTimesta
}
ze_result_t DeviceImp::getSubDevices(uint32_t *pCount, ze_device_handle_t *phSubdevices) {
DriverHandleImp *driverHandleImp = static_cast<DriverHandleImp *>(driverHandle);
// Given FLAT device Hierarchy mode, then a count of 0 is returned since no traversal is allowed.
if (driverHandleImp->deviceHierarchyMode == L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_FLAT) {
if (this->neoDevice->getExecutionEnvironment()->getDeviceHierarchyMode() == NEO::DeviceHierarchyMode::FLAT) {
*pCount = 0;
return ZE_RESULT_SUCCESS;
}

View File

@ -53,8 +53,6 @@ void DriverImp::initialize(ze_result_t *result) {
envReader.getSetting("ZE_ENABLE_PCI_ID_DEVICE_ORDER", false);
envVariables.fp64Emulation =
envReader.getSetting("NEO_FP64_EMULATION", false);
envVariables.deviceHierarchyMode =
envReader.getSetting("ZE_FLAT_DEVICE_HIERARCHY", std::string(NEO::deviceHierarchyUnk));
auto executionEnvironment = new NEO::ExecutionEnvironment();
UNRECOVERABLE_IF(nullptr == executionEnvironment);

View File

@ -298,17 +298,7 @@ DriverHandle *DriverHandle::create(std::vector<std::unique_ptr<NEO::Device>> dev
driverHandle->enableProgramDebugging = static_cast<NEO::DebuggingMode>(envVariables.programDebugging);
driverHandle->enableSysman = envVariables.sysman;
driverHandle->enablePciIdDeviceOrder = envVariables.pciIdDeviceOrder;
char const *preferredDeviceHierarchy = envVariables.deviceHierarchyMode.c_str();
if ((strcmp(preferredDeviceHierarchy, NEO::deviceHierarchyUnk) == 0) || ((strcmp(preferredDeviceHierarchy, NEO::deviceHierarchyComposite) != 0) && (strcmp(preferredDeviceHierarchy, NEO::deviceHierarchyFlat) != 0) && (strcmp(preferredDeviceHierarchy, NEO::deviceHierarchyCombined) != 0))) {
preferredDeviceHierarchy = devices[0]->getGfxCoreHelper().getDefaultDeviceHierarchy();
}
if (strcmp(preferredDeviceHierarchy, NEO::deviceHierarchyComposite) == 0) {
driverHandle->deviceHierarchyMode = L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_COMPOSITE;
} else if (strcmp(preferredDeviceHierarchy, NEO::deviceHierarchyFlat) == 0) {
driverHandle->deviceHierarchyMode = L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_FLAT;
} else if (strcmp(preferredDeviceHierarchy, NEO::deviceHierarchyCombined) == 0) {
driverHandle->deviceHierarchyMode = L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_COMBINED;
}
ze_result_t res = driverHandle->initialize(std::move(devices));
if (res != ZE_RESULT_SUCCESS) {
delete driverHandle;
@ -338,12 +328,9 @@ void DriverHandleImp::initHostUsmAllocPool() {
}
ze_result_t DriverHandleImp::getDevice(uint32_t *pCount, ze_device_handle_t *phDevices) {
bool exposeSubDevices = false;
// If the user has requested FLAT or COMBINED device hierarchy model, then report all the sub devices as devices.
if (this->deviceHierarchyMode != L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_COMPOSITE) {
exposeSubDevices = true;
}
bool exposeSubDevices = (this->devices.size() && this->devices[0]->getNEODevice()->getExecutionEnvironment()->getDeviceHierarchyMode() != NEO::DeviceHierarchyMode::COMPOSITE);
uint32_t numDevices = 0;
if (exposeSubDevices) {
@ -871,10 +858,7 @@ ze_result_t DriverHandleImp::fabricVertexGetExp(uint32_t *pCount, ze_fabric_vert
this->initializeVertexes();
}
bool exposeSubDevices = false;
if (deviceHierarchyMode == L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_FLAT) {
exposeSubDevices = true;
}
bool exposeSubDevices = this->devices[0]->getNEODevice()->getExecutionEnvironment()->getDeviceHierarchyMode() != NEO::DeviceHierarchyMode::COMPOSITE;
if (*pCount == 0) {
if (exposeSubDevices) {

View File

@ -27,11 +27,6 @@ struct FabricEdge;
struct Image;
class ExternalSemaphoreController;
enum L0DeviceHierarchyMode {
L0_DEVICE_HIERARCHY_COMPOSITE,
L0_DEVICE_HIERARCHY_FLAT,
L0_DEVICE_HIERARCHY_COMBINED
};
#pragma pack(1)
struct IpcMemoryData {
uint64_t handle = 0;
@ -172,7 +167,6 @@ struct DriverHandleImp : public DriverHandle {
bool enableSysman = false;
bool enablePciIdDeviceOrder = false;
uint8_t powerHint = 0;
L0DeviceHierarchyMode deviceHierarchyMode = L0_DEVICE_HIERARCHY_COMPOSITE;
// Error messages per thread, variable initialized / destoryed per thread,
// not based on the lifetime of the object of a class.

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2024 Intel Corporation
* Copyright (C) 2020-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -42,7 +42,6 @@ struct L0EnvVariables {
bool sysman;
bool pciIdDeviceOrder;
bool fp64Emulation;
std::string deviceHierarchyMode;
};
} // namespace L0

View File

@ -131,11 +131,7 @@ void MultiDeviceFixtureHierarchy::setUp() {
executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = std::make_unique<MockMemoryOperations>();
}
if (driverHandle->deviceHierarchyMode == L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_FLAT) {
executionEnvironment->setExposeSubDevicesAsDevices(true);
} else if (driverHandle->deviceHierarchyMode == L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_COMBINED) {
executionEnvironment->setCombinedDeviceHierarchy(true);
}
executionEnvironment->setDeviceHierarchyMode(deviceHierarchyMode);
auto devices = NEO::DeviceFactory::createDevices(*executionEnvironment);
if (devices.size()) {

View File

@ -130,6 +130,7 @@ struct MultiDeviceFixture {
uint32_t numRootDevices = 4u;
uint32_t numSubDevices = 2u;
L0::ContextImp *context = nullptr;
NEO::DeviceHierarchyMode deviceHierarchyMode = NEO::DeviceHierarchyMode::COMPOSITE;
VariableBackup<_ze_driver_handle_t *> globalDriverHandleBackup{&globalDriverHandle};
VariableBackup<uint32_t> driverCountBackup{&driverCount};
@ -139,23 +140,18 @@ struct MultiDeviceFixtureHierarchy : public MultiDeviceFixture {
void setUp();
};
struct MultiDeviceFixtureCompositeHierarchy : public MultiDeviceFixtureHierarchy {
void setUp() {
this->driverHandle->deviceHierarchyMode = L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_COMPOSITE;
MultiDeviceFixtureHierarchy::setUp();
}
};
struct MultiDeviceFixtureCompositeHierarchy : public MultiDeviceFixtureHierarchy {};
struct MultiDeviceFixtureFlatHierarchy : public MultiDeviceFixtureHierarchy {
void setUp() {
this->driverHandle->deviceHierarchyMode = L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_FLAT;
this->deviceHierarchyMode = NEO::DeviceHierarchyMode::FLAT;
MultiDeviceFixtureHierarchy::setUp();
}
};
struct MultiDeviceFixtureCombinedHierarchy : public MultiDeviceFixtureHierarchy {
void setUp() {
this->driverHandle->deviceHierarchyMode = L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_COMBINED;
this->deviceHierarchyMode = NEO::DeviceHierarchyMode::COMBINED;
MultiDeviceFixtureHierarchy::setUp();
}
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 Intel Corporation
* Copyright (C) 2024-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -62,7 +62,7 @@ TEST_F(PciBusInfoTest, givenSuccessfulReadingOfBusValuesThenCorrectValuesAreRetu
}
}
TEST_P(PciBusOrderingTest, givenMultipleDevicesAndZePcieIdOrderingSetThenDevicesAndVerticesAreInCorrectOrder) {
TEST_P(PciBusOrderingTest, givenMultipleDevicesWithCompositeHierarchyAndZePcieIdOrderingSetThenDevicesAndVerticesAreInCorrectOrder) {
constexpr uint32_t numRootDevices = 6u;
constexpr uint32_t numSubDevices = 2u;
const NEO::PhysicalDevicePciBusInfo busInfos[numRootDevices] = {{2, 0, 3, 0}, {2, 0, 1, 9}, {0, 0, 0, 1}, {0, 3, 5, 0}, {1, 3, 5, 0}, {0, 4, 1, 0}};
@ -76,6 +76,7 @@ TEST_P(PciBusOrderingTest, givenMultipleDevicesAndZePcieIdOrderingSetThenDevices
debugManager.flags.EnableChipsetUniqueUUID.set(0);
auto executionEnvironment = NEO::MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u);
executionEnvironment->setDeviceHierarchyMode(COMPOSITE);
auto memoryManager = new MockMemoryManagerOsAgnosticContext(*executionEnvironment);
executionEnvironment->memoryManager.reset(memoryManager);
auto neoDevices = NEO::DeviceFactory::createDevices(*executionEnvironment);

View File

@ -558,107 +558,6 @@ TEST_F(DriverImpTest, givenEnabledProgramDebuggingWhenCreatingExecutionEnvironme
L0::globalDriver = nullptr;
}
TEST_F(DriverImpTest, whenCreatingExecutionEnvironmentThenDefaultHierarchyIsEnabled) {
ze_result_t result = ZE_RESULT_ERROR_UNINITIALIZED;
DriverImp driverImp;
driverImp.initialize(&result);
L0::DriverHandleImp *driverHandleImp = reinterpret_cast<L0::DriverHandleImp *>(L0::globalDriverHandle);
auto &gfxCoreHelper = driverHandleImp->memoryManager->peekExecutionEnvironment().rootDeviceEnvironments[0]->getHelper<NEO::GfxCoreHelper>();
if (strcmp(gfxCoreHelper.getDefaultDeviceHierarchy(), "COMPOSITE") == 0) {
EXPECT_EQ(driverHandleImp->deviceHierarchyMode, L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_COMPOSITE);
} else {
EXPECT_EQ(driverHandleImp->deviceHierarchyMode, L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_FLAT);
}
ASSERT_NE(nullptr, L0::globalDriver);
ASSERT_NE(0u, L0::globalDriver->numDevices);
delete L0::globalDriver;
L0::globalDriverHandle = nullptr;
L0::globalDriver = nullptr;
}
TEST_F(DriverImpTest, givenFlatDeviceHierarchyWhenCreatingExecutionEnvironmentThenFlatHierarchyIsEnabled) {
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
std::unordered_map<std::string, std::string> mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "FLAT"}};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
ze_result_t result = ZE_RESULT_ERROR_UNINITIALIZED;
DriverImp driverImp;
driverImp.initialize(&result);
L0::DriverHandleImp *driverHandleImp = reinterpret_cast<L0::DriverHandleImp *>(L0::globalDriverHandle);
EXPECT_EQ(driverHandleImp->deviceHierarchyMode, L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_FLAT);
ASSERT_NE(nullptr, L0::globalDriver);
ASSERT_NE(0u, L0::globalDriver->numDevices);
delete L0::globalDriver;
L0::globalDriverHandle = nullptr;
L0::globalDriver = nullptr;
}
TEST_F(DriverImpTest, givenCompositeDeviceHierarchyWhenCreatingExecutionEnvironmentThenCompositeHierarchyIsEnabled) {
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
std::unordered_map<std::string, std::string> mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMPOSITE"}};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
ze_result_t result = ZE_RESULT_ERROR_UNINITIALIZED;
DriverImp driverImp;
driverImp.initialize(&result);
L0::DriverHandleImp *driverHandleImp = reinterpret_cast<L0::DriverHandleImp *>(L0::globalDriverHandle);
EXPECT_EQ(driverHandleImp->deviceHierarchyMode, L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_COMPOSITE);
ASSERT_NE(nullptr, L0::globalDriver);
ASSERT_NE(0u, L0::globalDriver->numDevices);
delete L0::globalDriver;
L0::globalDriverHandle = nullptr;
L0::globalDriver = nullptr;
}
TEST_F(DriverImpTest, givenCombinedDeviceHierarchyWhenCreatingExecutionEnvironmentThenCombinedHierarchyIsEnabled) {
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
std::unordered_map<std::string, std::string> mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMBINED"}};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
ze_result_t result = ZE_RESULT_ERROR_UNINITIALIZED;
DriverImp driverImp;
driverImp.initialize(&result);
L0::DriverHandleImp *driverHandleImp = reinterpret_cast<L0::DriverHandleImp *>(L0::globalDriverHandle);
EXPECT_EQ(driverHandleImp->deviceHierarchyMode, L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_COMBINED);
ASSERT_NE(nullptr, L0::globalDriver);
ASSERT_NE(0u, L0::globalDriver->numDevices);
delete L0::globalDriver;
L0::globalDriverHandle = nullptr;
L0::globalDriver = nullptr;
}
TEST_F(DriverImpTest, givenErrantDeviceHierarchyWhenCreatingExecutionEnvironmentThenDefaultHierarchyIsEnabled) {
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
std::unordered_map<std::string, std::string> mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "Flat"}};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
ze_result_t result = ZE_RESULT_ERROR_UNINITIALIZED;
DriverImp driverImp;
driverImp.initialize(&result);
L0::DriverHandleImp *driverHandleImp = reinterpret_cast<L0::DriverHandleImp *>(L0::globalDriverHandle);
auto &gfxCoreHelper = driverHandleImp->memoryManager->peekExecutionEnvironment().rootDeviceEnvironments[0]->getHelper<NEO::GfxCoreHelper>();
if (strcmp(gfxCoreHelper.getDefaultDeviceHierarchy(), "COMPOSITE") == 0) {
EXPECT_EQ(driverHandleImp->deviceHierarchyMode, L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_COMPOSITE);
} else {
EXPECT_EQ(driverHandleImp->deviceHierarchyMode, L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_FLAT);
}
ASSERT_NE(nullptr, L0::globalDriver);
ASSERT_NE(0u, L0::globalDriver->numDevices);
delete L0::globalDriver;
L0::globalDriverHandle = nullptr;
L0::globalDriver = nullptr;
}
TEST_F(DriverImpTest, givenEnableProgramDebuggingWithValue2WhenCreatingExecutionEnvironmentThenDebuggingEnabledIsTrue) {
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2024 Intel Corporation
* Copyright (C) 2020-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -2810,9 +2810,9 @@ TEST_F(TimestampEventCreate, givenEventWhenQueryKernelTimestampThenNotReadyRetur
EXPECT_EQ(0u, resultTimestamp.global.kernelEnd);
}
TEST_F(EventPoolCreateMultiDevice, givenFlatHierarchyWhenCallZeGetDevicesThenSubDevicesAreReturnedAsSeparateDevices) {
this->driverHandle->deviceHierarchyMode = L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_FLAT;
using EventPoolCreateMultiDeviceFlatHierarchy = Test<MultiDeviceFixtureFlatHierarchy>;
TEST_F(EventPoolCreateMultiDeviceFlatHierarchy, givenFlatHierarchyWhenCallZeGetDevicesThenSubDevicesAreReturnedAsSeparateDevices) {
uint32_t deviceCount = 0;
ze_result_t result = zeDeviceGet(driverHandle.get(), &deviceCount, nullptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
@ -4311,6 +4311,8 @@ struct EventDynamicPacketUseFixture : public DeviceFixture {
void testSingleDevice() {
ze_result_t result = ZE_RESULT_SUCCESS;
device->getNEODevice()->getExecutionEnvironment()->setDeviceHierarchyMode(COMPOSITE);
auto &hwInfo = device->getHwInfo();
auto &l0GfxCoreHelper = device->getNEODevice()->getRootDeviceEnvironment().getHelper<L0GfxCoreHelper>();
auto &gfxCoreHelper = device->getGfxCoreHelper();

View File

@ -37,7 +37,7 @@ class MockFabricDeviceInterface {
using FabricVertexFixture = Test<MultiDeviceFixture>;
TEST_F(FabricVertexFixture, WhenDevicesAreCreatedThenVerifyFabricVerticesAreCreated) {
TEST_F(FabricVertexFixture, whenDevicesAreCreatedThenVerifyFabricVerticesAreCreated) {
uint32_t count = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, L0::zeFabricVertexGetExp(driverHandle->toHandle(), &count, nullptr));
@ -156,7 +156,7 @@ TEST_F(FabricVertexFixture, givenFabricVerticesAreCreatedWhenzeFabricVertexGetPr
}
}
TEST(FabricEngineInstanceTest, GivenSubDeviceWhenFabricVerticesAreCreatedThenSkipCreationForSubDevice) {
TEST(FabricEngineInstanceTest, givenSubDeviceWhenFabricVerticesAreCreatedThenSkipCreationForSubDevice) {
auto hwInfo = *NEO::defaultHwInfo.get();
auto executionEnvironment = NEO::MockDevice::prepareExecutionEnvironment(&hwInfo, 0u);
@ -182,7 +182,7 @@ TEST(FabricEngineInstanceTest, GivenSubDeviceWhenFabricVerticesAreCreatedThenSki
EXPECT_EQ(count, 0u);
}
TEST_F(FabricVertexFixture, GivenDevicesAreCreatedWhenZeDeviceGetFabricVertexExpIsCalledThenExpectValidVertices) {
TEST_F(FabricVertexFixture, givenDevicesAreCreatedWhenZeDeviceGetFabricVertexExpIsCalledThenExpectValidVertices) {
for (auto l0Device : driverHandle->devices) {
ze_fabric_vertex_handle_t hVertex = nullptr;
@ -197,7 +197,7 @@ TEST_F(FabricVertexFixture, GivenDevicesAreCreatedWhenZeDeviceGetFabricVertexExp
}
}
TEST_F(FabricVertexFixture, GivenDevicesAreCreatedWhenFabricVertexIsNotSetToDeviceThenZeDeviceGetFabricVertexExpReturnsError) {
TEST_F(FabricVertexFixture, givenDevicesAreCreatedWhenFabricVertexIsNotSetToDeviceThenZeDeviceGetFabricVertexExpReturnsError) {
auto l0Device = driverHandle->devices[0];
ze_fabric_vertex_handle_t hVertex = nullptr;
@ -212,67 +212,20 @@ TEST_F(FabricVertexFixture, GivenDevicesAreCreatedWhenFabricVertexIsNotSetToDevi
EXPECT_EQ(hVertex, nullptr);
}
class FabricVertexFlatDeviceTestFixture : public MultiDeviceFixtureFlatHierarchy,
public ::testing::Test {
void SetUp() override {
NEO::debugManager.flags.ZE_AFFINITY_MASK.set("0,1.1,2");
MultiDeviceFixtureFlatHierarchy::setUp();
}
void TearDown() override {
MultiDeviceFixtureFlatHierarchy::tearDown();
}
TEST(FabricVertexTestFixture, givenCompositeHierarchyWhenFabricVerticesGetExpIsCalledCorrectVerticesAreReturned) {
DebugManagerStateRestore restorer;
};
NEO::debugManager.flags.ZE_AFFINITY_MASK.set("0,1.1,2");
MultiDeviceFixtureCompositeHierarchy multiDeviceFixture{};
multiDeviceFixture.setUp();
TEST_F(FabricVertexFlatDeviceTestFixture, GivenFlatHierarchyWhenFabricVerticesGetExpIsCalledCorrectVerticesAreReturned) {
uint32_t count = 0;
std::vector<ze_fabric_vertex_handle_t> phVertices;
EXPECT_EQ(driverHandle->fabricVertexGetExp(&count, nullptr), ZE_RESULT_SUCCESS);
// only 2 vertexes for mask "0,1.1,2":
// 0 and 2
// 1.1 is ignored in FlatHierarchy
uint32_t expectedVertexes = 2u;
EXPECT_EQ(count, expectedVertexes);
// Requesting for a reduced count
phVertices.resize(count);
EXPECT_EQ(driverHandle->fabricVertexGetExp(&count, phVertices.data()), ZE_RESULT_SUCCESS);
ze_device_handle_t hDevice{};
// Device 0 associated with value 0 in mask
EXPECT_EQ(L0::zeFabricVertexGetDeviceExp(phVertices[0], &hDevice), ZE_RESULT_SUCCESS);
DeviceImp *deviceImp = static_cast<DeviceImp *>(hDevice);
EXPECT_FALSE(deviceImp->isSubdevice);
// Device 1 associated with value 2 in mask
EXPECT_EQ(L0::zeFabricVertexGetDeviceExp(phVertices[1], &hDevice), ZE_RESULT_SUCCESS);
deviceImp = static_cast<DeviceImp *>(hDevice);
EXPECT_FALSE(deviceImp->isSubdevice);
}
class FabricVertexTestFixture : public MultiDeviceFixture,
public ::testing::Test {
void SetUp() override {
NEO::debugManager.flags.ZE_AFFINITY_MASK.set("0,1.1,2");
MultiDeviceFixture::setUp();
}
void TearDown() override {
MultiDeviceFixture::tearDown();
}
DebugManagerStateRestore restorer;
};
TEST_F(FabricVertexTestFixture, GivenCompositeHierarchyWhenFabricVerticesGetExpIsCalledCorrectVerticesAreReturned) {
uint32_t count = 0;
std::vector<ze_fabric_vertex_handle_t> phVertices;
EXPECT_EQ(driverHandle->fabricVertexGetExp(&count, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(multiDeviceFixture.driverHandle->fabricVertexGetExp(&count, nullptr), ZE_RESULT_SUCCESS);
uint32_t expectedVertexes = 3u;
EXPECT_EQ(count, expectedVertexes);
phVertices.resize(count);
EXPECT_EQ(driverHandle->fabricVertexGetExp(&count, phVertices.data()), ZE_RESULT_SUCCESS);
EXPECT_EQ(multiDeviceFixture.driverHandle->fabricVertexGetExp(&count, phVertices.data()), ZE_RESULT_SUCCESS);
// Device 0 associated with value 0 in mask
ze_device_handle_t hDevice{};
@ -282,7 +235,7 @@ TEST_F(FabricVertexTestFixture, GivenCompositeHierarchyWhenFabricVerticesGetExpI
uint32_t countSubDevices = 0;
EXPECT_EQ(L0::zeFabricVertexGetSubVerticesExp(phVertices[0], &countSubDevices, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(countSubDevices, numSubDevices);
EXPECT_EQ(countSubDevices, multiDeviceFixture.numSubDevices);
std::vector<ze_fabric_vertex_handle_t> phSubvertices(countSubDevices);
EXPECT_EQ(L0::zeFabricVertexGetSubVerticesExp(phVertices[0], &countSubDevices, phSubvertices.data()), ZE_RESULT_SUCCESS);
@ -311,24 +264,65 @@ TEST_F(FabricVertexTestFixture, GivenCompositeHierarchyWhenFabricVerticesGetExpI
phSubvertices.clear();
countSubDevices = 0;
EXPECT_EQ(L0::zeFabricVertexGetSubVerticesExp(phVertices[2], &countSubDevices, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(countSubDevices, numSubDevices);
EXPECT_EQ(countSubDevices, multiDeviceFixture.numSubDevices);
multiDeviceFixture.tearDown();
}
TEST_F(FabricVertexTestFixture, GivenFlatHierarchyWhenFabricVerticesGetExpIsCalledCorrectVerticesAreReturned) {
TEST(FabricVertexTestFixture, givenFlatHierarchyWhenFabricVerticesGetExpIsCalledCorrectVerticesAreReturned) {
DebugManagerStateRestore restorer;
NEO::debugManager.flags.ZE_AFFINITY_MASK.set("0,1.1,2");
MultiDeviceFixtureFlatHierarchy multiDeviceFixture{};
multiDeviceFixture.setUp();
uint32_t count = 0;
std::vector<ze_fabric_vertex_handle_t> phVertices;
this->driverHandle->deviceHierarchyMode = L0::L0DeviceHierarchyMode::L0_DEVICE_HIERARCHY_FLAT;
EXPECT_EQ(driverHandle->fabricVertexGetExp(&count, nullptr), ZE_RESULT_SUCCESS);
uint32_t expectedVertexes = 5u;
EXPECT_EQ(multiDeviceFixture.driverHandle->fabricVertexGetExp(&count, nullptr), ZE_RESULT_SUCCESS);
// only 2 vertexes for mask "0,1.1,2":
// 0 and 2
// 1.1 is ignored in FlatHierarchy
uint32_t expectedVertexes = 2u;
EXPECT_EQ(count, expectedVertexes);
// Requesting for a reduced count
phVertices.resize(count);
EXPECT_EQ(multiDeviceFixture.driverHandle->fabricVertexGetExp(&count, phVertices.data()), ZE_RESULT_SUCCESS);
ze_device_handle_t hDevice{};
// Device 0 associated with value 0 in mask
EXPECT_EQ(L0::zeFabricVertexGetDeviceExp(phVertices[0], &hDevice), ZE_RESULT_SUCCESS);
DeviceImp *deviceImp = static_cast<DeviceImp *>(hDevice);
EXPECT_FALSE(deviceImp->isSubdevice);
// Device 1 associated with value 2 in mask
EXPECT_EQ(L0::zeFabricVertexGetDeviceExp(phVertices[1], &hDevice), ZE_RESULT_SUCCESS);
deviceImp = static_cast<DeviceImp *>(hDevice);
EXPECT_FALSE(deviceImp->isSubdevice);
multiDeviceFixture.tearDown();
}
TEST(FabricVertexTestFixture, givenCombinedHierarchyWhenFabricVerticesGetExpIsCalledCorrectVerticesAreReturned2) {
DebugManagerStateRestore restorer;
NEO::debugManager.flags.ZE_AFFINITY_MASK.set("0,1.1,2");
MultiDeviceFixtureCombinedHierarchy multiDeviceFixture{};
multiDeviceFixture.setUp();
uint32_t count = 0;
std::vector<ze_fabric_vertex_handle_t> phVertices;
EXPECT_EQ(multiDeviceFixture.driverHandle->fabricVertexGetExp(&count, nullptr), ZE_RESULT_SUCCESS);
uint32_t expectedVertexes = 2u;
EXPECT_EQ(count, expectedVertexes);
phVertices.resize(count);
EXPECT_EQ(driverHandle->fabricVertexGetExp(&count, phVertices.data()), ZE_RESULT_SUCCESS);
EXPECT_EQ(multiDeviceFixture.driverHandle->fabricVertexGetExp(&count, phVertices.data()), ZE_RESULT_SUCCESS);
multiDeviceFixture.tearDown();
}
using FabricEdgeFixture = Test<MultiDeviceFixture>;
TEST_F(FabricEdgeFixture, GivenFabricVerticesAreCreatedWhenZeFabricEdgeGetExpIsCalledThenReturnSuccess) {
TEST_F(FabricEdgeFixture, givenFabricVerticesAreCreatedWhenZeFabricEdgeGetExpIsCalledThenReturnSuccess) {
// initialize
uint32_t count = 0;
@ -364,7 +358,7 @@ TEST_F(FabricEdgeFixture, GivenFabricVerticesAreCreatedWhenZeFabricEdgeGetExpIsC
edgeHandles.data()));
}
TEST_F(FabricEdgeFixture, GivenFabricVerticesAreCreatedForIndirectEdgesWhenZeFabricEdgeGetExpIsCalledThenReturnSuccess) {
TEST_F(FabricEdgeFixture, givenFabricVerticesAreCreatedForIndirectEdgesWhenZeFabricEdgeGetExpIsCalledThenReturnSuccess) {
// initialize
uint32_t count = 0;
std::vector<ze_fabric_vertex_handle_t> phVertices;
@ -417,7 +411,7 @@ TEST_F(FabricEdgeFixture, GivenFabricVerticesAreCreatedForIndirectEdgesWhenZeFab
driverHandle->fabricIndirectEdges.clear();
}
TEST_F(FabricEdgeFixture, GivenFabricEdgesAreCreatedWhenZeFabricEdgeGetVerticesExpIsCalledThenReturnCorrectVertices) {
TEST_F(FabricEdgeFixture, givenFabricEdgesAreCreatedWhenZeFabricEdgeGetVerticesExpIsCalledThenReturnCorrectVertices) {
// initialize
uint32_t count = 0;
std::vector<ze_fabric_vertex_handle_t> phVertices;
@ -449,7 +443,7 @@ TEST_F(FabricEdgeFixture, GivenFabricEdgesAreCreatedWhenZeFabricEdgeGetVerticesE
EXPECT_EQ(hVertexB, driverHandle->fabricVertices[1]);
}
TEST_F(FabricEdgeFixture, GivenFabricEdgesAreCreatedWhenZeFabricEdgeGetPropertiesExpIsCalledThenReturnCorrectProperties) {
TEST_F(FabricEdgeFixture, givenFabricEdgesAreCreatedWhenZeFabricEdgeGetPropertiesExpIsCalledThenReturnCorrectProperties) {
// initialize
uint32_t count = 0;
std::vector<ze_fabric_vertex_handle_t> phVertices;
@ -482,7 +476,7 @@ TEST_F(FabricEdgeFixture, GivenFabricEdgesAreCreatedWhenZeFabricEdgeGetPropertie
EXPECT_EQ(getProperties.latency, 20u);
}
TEST_F(FabricEdgeFixture, GivenMdfiLinksAreAvailableWhenEdgesAreCreatedThenVerifyThatBiDirectionalEdgesAreNotCreated) {
TEST_F(FabricEdgeFixture, givenMdfiLinksAreAvailableWhenEdgesAreCreatedThenVerifyThatBiDirectionalEdgesAreNotCreated) {
// initialize
uint32_t count = 0;
std::vector<ze_fabric_vertex_handle_t> phVertices;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2023 Intel Corporation
* Copyright (C) 2022-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -14,7 +14,7 @@
namespace L0 {
namespace ult {
TEST_F(SysmanMultiDeviceInfoFixture, GivenDeviceWithMultipleTilesWhenOnlyTileOneIsEnabledThenGetSysmanDeviceInfoReturnsExpectedValues) {
TEST_F(SysmanMultiDeviceInfoFixture, givenDeviceWithMultipleTilesWhenOnlyTileOneIsEnabledThenGetSysmanDeviceInfoReturnsExpectedValues) {
neoDevice->deviceBitfield.reset();
neoDevice->deviceBitfield.set(1);
uint32_t subdeviceId = 0;
@ -24,7 +24,7 @@ TEST_F(SysmanMultiDeviceInfoFixture, GivenDeviceWithMultipleTilesWhenOnlyTileOne
EXPECT_TRUE(onSubdevice);
}
TEST_F(SysmanMultiDeviceInfoFixture, GivenDeviceWithMultipleTilesWhenOnlyTileOneIsEnabledAndMultiArchIsDisabledThenGetSysmanDeviceInfoReturnsExpectedValues) {
TEST_F(SysmanMultiDeviceInfoFixture, givenDeviceWithMultipleTilesWhenOnlyTileOneIsEnabledAndMultiArchIsDisabledThenGetSysmanDeviceInfoReturnsExpectedValues) {
neoDevice->deviceBitfield.reset();
neoDevice->deviceBitfield.set(1);
uint32_t subdeviceId = 0;
@ -34,7 +34,8 @@ TEST_F(SysmanMultiDeviceInfoFixture, GivenDeviceWithMultipleTilesWhenOnlyTileOne
EXPECT_FALSE(onSubdevice);
}
TEST_F(SysmanMultiDeviceInfoFixture, GivenDeviceWithMultipleTilesEnabledThenGetSysmanDeviceInfoReturnsExpectedValues) {
TEST_F(SysmanMultiDeviceInfoFixture, givenDeviceWithMultipleTilesEnabledAndCompositeHierarchyThenGetSysmanDeviceInfoReturnsExpectedValues) {
neoDevice->getExecutionEnvironment()->setDeviceHierarchyMode(NEO::DeviceHierarchyMode::COMPOSITE);
uint32_t subDeviceCount = 0;
std::vector<ze_device_handle_t> deviceHandles;
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, nullptr);

View File

@ -259,7 +259,7 @@ cl_int CL_API_CALL clGetDeviceIDs(cl_platform_id platform,
cl_uint retNum = 0;
for (auto platformDeviceIndex = 0u; platformDeviceIndex < numDev; platformDeviceIndex++) {
bool exposeSubDevices = pPlatform->peekExecutionEnvironment()->isExposingSubDevicesAsDevices();
bool exposeSubDevices = pPlatform->peekExecutionEnvironment()->getDeviceHierarchyMode() != COMPOSITE;
ClDevice *device = pPlatform->getClDevice(platformDeviceIndex);
UNRECOVERABLE_IF(device == nullptr);

View File

@ -51,7 +51,7 @@ ClDevice::ClDevice(Device &device, ClDevice &rootClDevice, Platform *platform) :
pClSubDevice->decRefApi();
pClSubDevice->internalParentDevice = this;
if (!device.getExecutionEnvironment()->isExposingSubDevicesAsDevices()) {
if (device.getExecutionEnvironment()->getDeviceHierarchyMode() == COMPOSITE) {
auto &deviceInfo = pClSubDevice->deviceInfo;
deviceInfo.parentDevice = this;
deviceInfo.partitionType[0] = CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2024 Intel Corporation
* Copyright (C) 2019-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -104,14 +104,16 @@ TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceApiRefCountsAreChange
EXPECT_EQ(baseDefaultDeviceInternalRefCount, defaultDevice->getRefInternalCount());
}
TEST(SubDevicesTest, givenDeviceWithSubDevicesAndSubDevicesAsDevicesIsSetWhenSubDeviceApiRefCountsAreChangedThenChangeIsNotPropagatedToRootDevice) {
TEST(SubDevicesTest, givenDeviceWithFlatOrCombinedHierarchyWhenSubDeviceApiRefCountsAreChangedThenChangeIsNotPropagatedToRootDevice) {
DebugManagerStateRestore restorer;
debugManager.flags.CreateMultipleSubDevices.set(2);
UnitTestSetter::disableHeaplessStateInit(restorer);
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
DeviceHierarchyMode deviceHierarchyModes[] = {FLAT, COMBINED};
for (auto deviceHierarchyMode : deviceHierarchyModes) {
initPlatform();
platform()->peekExecutionEnvironment()->setExposeSubDevicesAsDevices(1);
platform()->peekExecutionEnvironment()->setDeviceHierarchyMode(deviceHierarchyMode);
auto nonDefaultPlatform = std::make_unique<MockPlatform>(*platform()->peekExecutionEnvironment());
nonDefaultPlatform->initializeWithNewDevices();
auto device = nonDefaultPlatform->getClDevice(0);
@ -141,6 +143,7 @@ TEST(SubDevicesTest, givenDeviceWithSubDevicesAndSubDevicesAsDevicesIsSetWhenSub
EXPECT_EQ(baseDefaultDeviceApiRefCount, defaultDevice->getRefApiCount());
EXPECT_EQ(baseDefaultDeviceInternalRefCount, defaultDevice->getRefInternalCount());
}
}
TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceInternalRefCountsAreChangedThenChangeIsPropagatedToRootDevice) {
DebugManagerStateRestore restorer;
@ -176,7 +179,6 @@ TEST(SubDevicesTest, givenClDeviceWithSubDevicesWhenSubDeviceInternalRefCountsAr
debugManager.flags.CreateMultipleSubDevices.set(2);
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
device->getExecutionEnvironment()->setExposeSubDevicesAsDevices(false);
device->incRefInternal();
auto &subDevice = device->subDevices[0];

View File

@ -93,7 +93,7 @@ bool Device::genericSubDevicesAllowed() {
deviceBitfield = maxNBitValue(subDeviceCount);
deviceBitfield &= deviceMask;
numSubDevices = static_cast<uint32_t>(deviceBitfield.count());
if (numSubDevices == 1 && (!executionEnvironment->isCombinedDeviceHierarchy() || subDeviceCount == 1)) {
if (numSubDevices == 1 && (executionEnvironment->getDeviceHierarchyMode() != COMBINED || subDeviceCount == 1)) {
numSubDevices = 0;
}

View File

@ -220,7 +220,7 @@ void ExecutionEnvironment::parseAffinityMask() {
}
// If the user has requested FLAT or COMBINED device hierarchy models, then report all the sub devices as devices.
bool exposeSubDevicesAsApiDevices = isExposingSubDevicesAsDevices();
bool exposeSubDevices = this->deviceHierarchyMode != COMPOSITE;
// Reserve at least for a size equal to rootDeviceEnvironments.size() times four,
// which is enough for typical configurations
@ -231,7 +231,7 @@ void ExecutionEnvironment::parseAffinityMask() {
mapOfIndices.reserve(reservedSizeForIndices);
uint32_t hwSubDevicesCount = 0u;
if (exposeSubDevicesAsApiDevices) {
if (exposeSubDevices) {
for (uint32_t currentRootDevice = 0u; currentRootDevice < numRootDevices; currentRootDevice++) {
auto hwInfo = rootDeviceEnvironments[currentRootDevice]->getHardwareInfo();
@ -258,7 +258,7 @@ void ExecutionEnvironment::parseAffinityMask() {
if (entryIndex >= numDevices) {
continue;
} else if (exposeSubDevicesAsApiDevices) {
} else if (exposeSubDevices) {
// tiles as devices
// so ignore X.Y
if (subEntries.size() > 1) {
@ -312,17 +312,17 @@ void ExecutionEnvironment::sortNeoDevices() {
std::sort(rootDeviceEnvironments.begin(), rootDeviceEnvironments.end(), comparePciIdBusNumber);
}
void ExecutionEnvironment::setDeviceHierarchy(const GfxCoreHelper &gfxCoreHelper) {
void ExecutionEnvironment::setDeviceHierarchyMode(const GfxCoreHelper &gfxCoreHelper) {
NEO::EnvironmentVariableReader envReader;
std::string hierarchyModel = envReader.getSetting("ZE_FLAT_DEVICE_HIERARCHY", std::string(gfxCoreHelper.getDefaultDeviceHierarchy()));
if (strcmp(hierarchyModel.c_str(), "COMPOSITE") == 0) {
setExposeSubDevicesAsDevices(false);
}
if (strcmp(hierarchyModel.c_str(), "FLAT") == 0) {
setExposeSubDevicesAsDevices(true);
}
if (strcmp(hierarchyModel.c_str(), "COMBINED") == 0) {
setCombinedDeviceHierarchy(true);
std::string deviceHierarchyMode = envReader.getSetting("ZE_FLAT_DEVICE_HIERARCHY", std::string(""));
if (strcmp(deviceHierarchyMode.c_str(), "COMPOSITE") == 0) {
this->deviceHierarchyMode = COMPOSITE;
} else if (strcmp(deviceHierarchyMode.c_str(), "FLAT") == 0) {
this->deviceHierarchyMode = FLAT;
} else if (strcmp(deviceHierarchyMode.c_str(), "COMBINED") == 0) {
this->deviceHierarchyMode = COMBINED;
} else {
this->deviceHierarchyMode = gfxCoreHelper.getDefaultDeviceHierarchy();
}
}

View File

@ -7,6 +7,7 @@
#pragma once
#include "shared/source/debugger/debugger.h"
#include "shared/source/helpers/device_hierarchy_mode.h"
#include "shared/source/utilities/reference_tracked_object.h"
#include <mutex>
@ -38,7 +39,11 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
void adjustCcsCount();
void adjustCcsCount(const uint32_t rootDeviceIndex) const;
void sortNeoDevices();
void setDeviceHierarchy(const GfxCoreHelper &gfxCoreHelper);
void setDeviceHierarchyMode(const GfxCoreHelper &gfxCoreHelper);
void setDeviceHierarchyMode(const DeviceHierarchyMode deviceHierarchyMode) {
this->deviceHierarchyMode = deviceHierarchyMode;
}
DeviceHierarchyMode getDeviceHierarchyMode() const { return deviceHierarchyMode; }
void adjustRootDeviceEnvironments();
void prepareForCleanup() const;
void configureCcsMode();
@ -50,15 +55,6 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
void setMetricsEnabled(bool value) {
this->metricsEnabled = value;
}
void setExposeSubDevicesAsDevices(bool value) {
this->subDevicesAsDevices = value;
}
void setCombinedDeviceHierarchy(bool value) {
this->subDevicesAsDevices = value;
this->combinedDeviceHierarchy = value;
}
bool isExposingSubDevicesAsDevices() const { return this->subDevicesAsDevices; }
bool isCombinedDeviceHierarchy() const { return this->combinedDeviceHierarchy; }
void getErrorDescription(const char **ppString);
bool getSubDeviceHierarchy(uint32_t index, std::tuple<uint32_t, uint32_t, uint32_t> *subDeviceMap);
bool areMetricsEnabled() { return this->metricsEnabled; }
@ -90,9 +86,8 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
void restoreCcsMode();
bool metricsEnabled = false;
bool fp64EmulationEnabled = false;
bool subDevicesAsDevices = false;
bool combinedDeviceHierarchy = false;
DeviceHierarchyMode deviceHierarchyMode = COMPOSITE;
DebuggingMode debuggingEnabledMode = DebuggingMode::disabled;
std::unordered_map<uint32_t, uint32_t> rootDeviceNumCcsMap;
std::mutex initializeDirectSubmissionControllerMutex;

View File

@ -58,6 +58,7 @@ set(NEO_CORE_HELPERS
${CMAKE_CURRENT_SOURCE_DIR}/debug_helpers.h
${CMAKE_CURRENT_SOURCE_DIR}/deferred_deleter_helper.h
${CMAKE_CURRENT_SOURCE_DIR}/device_bitfield.h
${CMAKE_CURRENT_SOURCE_DIR}/device_hierarchy_mode.h
${CMAKE_CURRENT_SOURCE_DIR}/driver_model_type.h
${CMAKE_CURRENT_SOURCE_DIR}/dirty_state_helpers.cpp
${CMAKE_CURRENT_SOURCE_DIR}/dirty_state_helpers.h

View File

@ -0,0 +1,16 @@
/*
* Copyright (C) 2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
namespace NEO {
enum DeviceHierarchyMode {
COMPOSITE,
FLAT,
COMBINED
};
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2024 Intel Corporation
* Copyright (C) 2018-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -18,11 +18,6 @@ namespace NEO {
GfxCoreHelperCreateFunctionType gfxCoreHelperFactory[IGFX_MAX_CORE] = {};
const char *deviceHierarchyComposite = "COMPOSITE";
const char *deviceHierarchyFlat = "FLAT";
const char *deviceHierarchyCombined = "COMBINED";
const char *deviceHierarchyUnk = "UNK";
std::unique_ptr<GfxCoreHelper> GfxCoreHelper::create(const GFXCORE_FAMILY gfxCoreFamily) {
auto createFunction = gfxCoreHelperFactory[gfxCoreFamily];

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2024 Intel Corporation
* Copyright (C) 2018-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -8,6 +8,7 @@
#pragma once
#include "shared/source/built_ins/sip_kernel_type.h"
#include "shared/source/helpers/definitions/engine_group_types.h"
#include "shared/source/helpers/device_hierarchy_mode.h"
#include "shared/source/helpers/engine_node_helper.h"
#include "shared/source/helpers/options.h"
#include "shared/source/utilities/stackvec.h"
@ -49,11 +50,6 @@ class AILConfiguration;
using EngineInstancesContainer = StackVec<EngineTypeUsage, 32>;
using GfxCoreHelperCreateFunctionType = std::unique_ptr<GfxCoreHelper> (*)();
extern const char *deviceHierarchyComposite;
extern const char *deviceHierarchyFlat;
extern const char *deviceHierarchyCombined;
extern const char *deviceHierarchyUnk;
class GfxCoreHelper {
public:
static std::unique_ptr<GfxCoreHelper> create(const GFXCORE_FAMILY gfxCoreFamily);
@ -171,7 +167,7 @@ class GfxCoreHelper {
virtual bool isRelaxedOrderingSupported() const = 0;
virtual uint32_t calculateNumThreadsPerThreadGroup(uint32_t simd, uint32_t totalWorkItems, uint32_t grfCount, bool isHwLocalIdGeneration, const RootDeviceEnvironment &rootDeviceEnvironment) const = 0;
virtual uint32_t overrideMaxWorkGroupSize(uint32_t maxWG) const = 0;
virtual char const *getDefaultDeviceHierarchy() const = 0;
virtual DeviceHierarchyMode getDefaultDeviceHierarchy() const = 0;
static bool isWorkaroundRequired(uint32_t lowestSteppingWithBug, uint32_t steppingWithFix, const HardwareInfo &hwInfo, const ProductHelper &productHelper);
virtual bool areSecondaryContextsSupported() const = 0;
@ -408,7 +404,7 @@ class GfxCoreHelperHw : public GfxCoreHelper {
bool isRelaxedOrderingSupported() const override;
uint32_t calculateNumThreadsPerThreadGroup(uint32_t simd, uint32_t totalWorkItems, uint32_t grfCount, bool isHwLocalIdGeneration, const RootDeviceEnvironment &rootDeviceEnvironment) const override;
uint32_t overrideMaxWorkGroupSize(uint32_t maxWG) const override;
char const *getDefaultDeviceHierarchy() const override;
DeviceHierarchyMode getDefaultDeviceHierarchy() const override;
bool areSecondaryContextsSupported() const override;
uint32_t getContextGroupContextsCount() const override;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2024 Intel Corporation
* Copyright (C) 2019-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -681,8 +681,8 @@ uint32_t GfxCoreHelperHw<GfxFamily>::calculateNumThreadsPerThreadGroup(uint32_t
}
template <typename GfxFamily>
char const *GfxCoreHelperHw<GfxFamily>::getDefaultDeviceHierarchy() const {
return deviceHierarchyComposite;
DeviceHierarchyMode GfxCoreHelperHw<GfxFamily>::getDefaultDeviceHierarchy() const {
return COMPOSITE;
}
template <typename GfxFamily>

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2024 Intel Corporation
* Copyright (C) 2018-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -137,7 +137,7 @@ bool DeviceFactory::prepareDeviceEnvironmentsForProductFamilyOverride(ExecutionE
}
}
executionEnvironment.setDeviceHierarchy(executionEnvironment.rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>());
executionEnvironment.setDeviceHierarchyMode(executionEnvironment.rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>());
executionEnvironment.parseAffinityMask();
executionEnvironment.adjustCcsCount();
executionEnvironment.calculateMaxOsContextCount();
@ -214,7 +214,7 @@ bool DeviceFactory::prepareDeviceEnvironments(ExecutionEnvironment &executionEnv
return false;
}
executionEnvironment.setDeviceHierarchy(executionEnvironment.rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>());
executionEnvironment.setDeviceHierarchyMode(executionEnvironment.rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>());
executionEnvironment.sortNeoDevices();
executionEnvironment.parseAffinityMask();
executionEnvironment.adjustRootDeviceEnvironments();

View File

@ -299,8 +299,8 @@ bool GfxCoreHelperHw<Family>::isRelaxedOrderingSupported() const {
}
template <>
char const *GfxCoreHelperHw<Family>::getDefaultDeviceHierarchy() const {
return deviceHierarchyFlat;
DeviceHierarchyMode GfxCoreHelperHw<Family>::getDefaultDeviceHierarchy() const {
return FLAT;
}
} // namespace NEO

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2024 Intel Corporation
* Copyright (C) 2018-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -121,7 +121,7 @@ ExecutionEnvironment *MockDevice::prepareExecutionEnvironment(const HardwareInfo
UnitTestSetter::setCcsExposure(*executionEnvironment->rootDeviceEnvironments[i]);
executionEnvironment->rootDeviceEnvironments[i]->initGmm();
}
executionEnvironment->setDeviceHierarchy(executionEnvironment->rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>());
executionEnvironment->setDeviceHierarchyMode(executionEnvironment->rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>());
executionEnvironment->calculateMaxOsContextCount();
return executionEnvironment;
}
@ -160,7 +160,7 @@ ExecutionEnvironment *MockDevice::prepareExecutionEnvironment(const HardwareInfo
UnitTestSetter::setRcsExposure(*executionEnvironment->rootDeviceEnvironments[0]);
UnitTestSetter::setCcsExposure(*executionEnvironment->rootDeviceEnvironments[0]);
executionEnvironment->setDeviceHierarchy(executionEnvironment->rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>());
executionEnvironment->setDeviceHierarchyMode(executionEnvironment->rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>());
MockAubCenterFixture::setMockAubCenter(*executionEnvironment->rootDeviceEnvironments[0]);
executionEnvironment->initializeMemoryManager();

View File

@ -171,7 +171,7 @@ TEST(Device, WhenCreatingDeviceThenCapsInitilizedBeforeEnginesAreCreated) {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfoAndInitHelpers(&hwInfo);
executionEnvironment->rootDeviceEnvironments[i]->initGmm();
}
executionEnvironment->setDeviceHierarchy(executionEnvironment->rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>());
executionEnvironment->setDeviceHierarchyMode(executionEnvironment->rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>());
executionEnvironment->calculateMaxOsContextCount();
executionEnvironment->initializeMemoryManager();

View File

@ -361,19 +361,21 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerI
executionEnvironment.initializeMemoryManager();
EXPECT_NE(nullptr, executionEnvironment.memoryManager);
}
static_assert(sizeof(ExecutionEnvironment) == sizeof(std::unique_ptr<HardwareInfo>) +
sizeof(std::vector<RootDeviceEnvironment>) +
sizeof(std::unique_ptr<OsEnvironment>) +
static_assert(sizeof(ExecutionEnvironment) == sizeof(std::unique_ptr<MemoryManager>) +
sizeof(std::unique_ptr<DirectSubmissionController>) +
sizeof(std::unordered_map<uint32_t, uint32_t>) +
2 * sizeof(bool) +
sizeof(NEO::DebuggingMode) +
(is64bit ? 18 : 14) +
sizeof(std::mutex) +
sizeof(std::unique_ptr<OsEnvironment>) +
sizeof(std::vector<std::unique_ptr<RootDeviceEnvironment>>) +
sizeof(std::unordered_map<uint32_t, std::tuple<uint32_t, uint32_t, uint32_t>>) +
sizeof(std::vector<std::tuple<std::string, uint32_t>>) +
sizeof(std::unordered_map<std::thread::id, std::string>) +
sizeof(std::mutex),
sizeof(std::mutex) +
2 * sizeof(bool) +
sizeof(DeviceHierarchyMode) +
sizeof(DebuggingMode) +
sizeof(std::unordered_map<uint32_t, uint32_t>) +
sizeof(std::mutex) +
sizeof(std::vector<std::tuple<std::string, uint32_t>>) +
(is64bit ? 22 : 14),
"New members detected in ExecutionEnvironment, please ensure that destruction sequence of objects is correct");
TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDestroyedThenDeleteSequenceIsSpecified) {
@ -547,7 +549,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenSettingFP64EmulationEnab
EXPECT_TRUE(executionEnvironment.isFP64EmulationEnabled());
}
TEST(ExecutionEnvironment, givenCorrectZeAffinityMaskWhenExposeSubDevicesAsApiDevicesIsSetThenMapOfSubDeviceIndicesIsSet) {
TEST(ExecutionEnvironment, givenCorrectZeAffinityMaskWithFlatOrCombinedHierarchyThenMapOfSubDeviceIndicesIsSet) {
DebugManagerStateRestore restore;
debugManager.flags.CreateMultipleSubDevices.set(4);
@ -555,16 +557,20 @@ TEST(ExecutionEnvironment, givenCorrectZeAffinityMaskWhenExposeSubDevicesAsApiDe
debugManager.flags.SetCommandStreamReceiver.set(1);
auto hwInfo = *defaultHwInfo;
DeviceHierarchyMode deviceHierarchyModes[] = {FLAT, COMBINED};
for (auto deviceHierarchyMode : deviceHierarchyModes) {
MockExecutionEnvironment executionEnvironment(&hwInfo);
executionEnvironment.incRefInternal();
executionEnvironment.setExposeSubDevicesAsDevices(true);
executionEnvironment.setDeviceHierarchyMode(deviceHierarchyMode);
DeviceFactory::createDevices(executionEnvironment);
EXPECT_FALSE(executionEnvironment.mapOfSubDeviceIndices.empty());
}
}
TEST(ExecutionEnvironment, givenIncorrectZeAffinityMaskWhenExposeSubDevicesAsApiDevicesIsSetThenMapOfSubDeviceIndicesIsEmpty) {
TEST(ExecutionEnvironment, givenIncorrectZeAffinityMaskWithFlatOrCombinedHierarchyThenMapOfSubDeviceIndicesIsEmpty) {
DebugManagerStateRestore restore;
debugManager.flags.CreateMultipleSubDevices.set(4);
@ -572,14 +578,18 @@ TEST(ExecutionEnvironment, givenIncorrectZeAffinityMaskWhenExposeSubDevicesAsApi
debugManager.flags.SetCommandStreamReceiver.set(1);
auto hwInfo = *defaultHwInfo;
DeviceHierarchyMode deviceHierarchyModes[] = {FLAT, COMBINED};
for (auto deviceHierarchyMode : deviceHierarchyModes) {
MockExecutionEnvironment executionEnvironment(&hwInfo);
executionEnvironment.incRefInternal();
executionEnvironment.setExposeSubDevicesAsDevices(true);
executionEnvironment.setDeviceHierarchyMode(deviceHierarchyMode);
DeviceFactory::createDevices(executionEnvironment);
EXPECT_TRUE(executionEnvironment.mapOfSubDeviceIndices.empty());
}
}
TEST(ExecutionEnvironment, givenBuiltinsSetWhenRootDeviceEnvironmentIsReleasedThenBuiltinsIsReset) {
auto hwInfo = *defaultHwInfo;
@ -627,46 +637,6 @@ TEST(ExecutionEnvironmentWithAILTests, whenAILConfigurationFailsOnInitProcessExe
EXPECT_FALSE(rootDeviceEnvironment->initAilConfiguration());
}
TEST(ExecutionEnvironmentDeviceHierarchy, givenExecutionEnvironmentWithDefaultDeviceHierarchyThenExecutionEnvironmentIsInitializedCorrectly) {
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
MockExecutionEnvironment executionEnvironment;
executionEnvironment.rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(defaultHwInfo.get());
auto &gfxCoreHelper = executionEnvironment.rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>();
executionEnvironment.setDeviceHierarchy(gfxCoreHelper);
EXPECT_EQ((strcmp(gfxCoreHelper.getDefaultDeviceHierarchy(), "COMPOSITE") != 0),
executionEnvironment.isExposingSubDevicesAsDevices());
}
TEST(ExecutionEnvironmentDeviceHierarchy, givenExecutionEnvironmentWithCompositeDeviceHierarchyThenExposeSubDevicesAsDevicesIsFalse) {
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
std::unordered_map<std::string, std::string> mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMPOSITE"}};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
MockExecutionEnvironment executionEnvironment;
executionEnvironment.rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(defaultHwInfo.get());
executionEnvironment.setDeviceHierarchy(executionEnvironment.rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>());
EXPECT_FALSE(executionEnvironment.isExposingSubDevicesAsDevices());
}
TEST(ExecutionEnvironmentDeviceHierarchy, givenExecutionEnvironmentWithFlatDeviceHierarchyThenExposeSubDevicesAsDevicesIsTrue) {
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
std::unordered_map<std::string, std::string> mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "FLAT"}};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
MockExecutionEnvironment executionEnvironment;
executionEnvironment.rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(defaultHwInfo.get());
executionEnvironment.setDeviceHierarchy(executionEnvironment.rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>());
EXPECT_TRUE(executionEnvironment.isExposingSubDevicesAsDevices());
}
TEST(ExecutionEnvironmentDeviceHierarchy, givenExecutionEnvironmentWithCombinedDeviceHierarchyThenExposeSubDevicesAsDevicesIsTrue) {
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
std::unordered_map<std::string, std::string> mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMBINED"}};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
MockExecutionEnvironment executionEnvironment;
executionEnvironment.rootDeviceEnvironments[0]->setHwInfoAndInitHelpers(defaultHwInfo.get());
executionEnvironment.setDeviceHierarchy(executionEnvironment.rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>());
EXPECT_TRUE(executionEnvironment.isExposingSubDevicesAsDevices());
}
TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenSetErrorDescriptionIsCalledThenGetErrorDescriptionGetsStringCorrectly) {
std::string errorString = "we manually created error";
std::string errorString2 = "here's the next string to pass with arguments: ";

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2024 Intel Corporation
* Copyright (C) 2022-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -1693,10 +1693,10 @@ HWTEST_F(GfxCoreHelperTest, givenFlagRemoveRestrictionsOnNumberOfThreadsInGpgpuT
}
}
HWTEST2_F(GfxCoreHelperTest, whenGetDefaultDeviceHierarchyThenReturnFlatHierarchy, IsNotXeHpcCore) {
HWTEST2_F(GfxCoreHelperTest, whenGetDefaultDeviceHierarchyThenReturnCompositeHierarchy, IsNotXeHpcCore) {
const auto &gfxCoreHelper = getHelper<GfxCoreHelper>();
auto defaultDeviceHierarchy = gfxCoreHelper.getDefaultDeviceHierarchy();
EXPECT_STREQ("COMPOSITE", defaultDeviceHierarchy);
EXPECT_EQ(COMPOSITE, defaultDeviceHierarchy);
}
HWTEST_F(GfxCoreHelperTest, givenContextGroupDisabledWhenContextGroupContextsCountAndSecondaryContextsSupportQueriedThenZeroCountAndFalseIsReturned) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2024 Intel Corporation
* Copyright (C) 2021-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -113,5 +113,5 @@ XE_HPC_CORETEST_F(GfxCoreHelperXeHpcCoreTest, whenGetDefaultDeviceHierarchyThenR
auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper<GfxCoreHelper>();
auto defaultDeviceHierarchy = gfxCoreHelper.getDefaultDeviceHierarchy();
EXPECT_STREQ("FLAT", defaultDeviceHierarchy);
EXPECT_EQ(FLAT, defaultDeviceHierarchy);
}