From 24a61d096da5e324b7d0cf4cb8ae39ecd15d3090 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Fri, 14 Feb 2025 16:55:44 +0000 Subject: [PATCH] fix: correct logic of groupDevices function discrete devices should be exposed before integrated devices Related-To: NEO-14062 Signed-off-by: Mateusz Jablonski --- shared/source/device/device.cpp | 23 ++++++++---- .../unit_test/device/neo_device_tests.cpp | 37 +++++++++++++++---- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index 10c390ccf9..4c2f8e487f 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -1264,17 +1264,24 @@ std::vector Device::groupDevices(DeviceVector devices) { std::map productsMap; std::vector outDevices; for (auto &device : devices) { - auto productFamily = device->getHardwareInfo().platform.eProductFamily; - auto result = productsMap.find(productFamily); - if (result == productsMap.end()) { - productsMap.insert({productFamily, productsMap.size()}); - outDevices.push_back(DeviceVector{}); + if (device) { + auto productFamily = device->getHardwareInfo().platform.eProductFamily; + auto result = productsMap.find(productFamily); + if (result == productsMap.end()) { + productsMap.insert({productFamily, productsMap.size()}); + outDevices.push_back(DeviceVector{}); + } + auto productId = productsMap[productFamily]; + outDevices[productId].push_back(std::move(device)); } - auto productId = productsMap[productFamily]; - outDevices[productId].push_back(std::move(device)); } std::sort(outDevices.begin(), outDevices.end(), [](DeviceVector &lhs, DeviceVector &rhs) -> bool { - return lhs[0]->getHardwareInfo().platform.eProductFamily > rhs[0]->getHardwareInfo().platform.eProductFamily; // NOLINT(clang-analyzer-cplusplus.Move) + auto &leftHwInfo = lhs[0]->getHardwareInfo(); // NOLINT(clang-analyzer-cplusplus.Move) - MSVC assumes usage of moved vector + auto &rightHwInfo = rhs[0]->getHardwareInfo(); // NOLINT(clang-analyzer-cplusplus.Move) + if (leftHwInfo.capabilityTable.isIntegratedDevice != rightHwInfo.capabilityTable.isIntegratedDevice) { + return rightHwInfo.capabilityTable.isIntegratedDevice; + } + return leftHwInfo.platform.eProductFamily > rightHwInfo.platform.eProductFamily; }); return outDevices; } diff --git a/shared/test/unit_test/device/neo_device_tests.cpp b/shared/test/unit_test/device/neo_device_tests.cpp index bc6b29866d..2c3d51f31c 100644 --- a/shared/test/unit_test/device/neo_device_tests.cpp +++ b/shared/test/unit_test/device/neo_device_tests.cpp @@ -2130,7 +2130,7 @@ TEST(Device, givenDeviceWhenGettingMicrosecondResolutionThenCorrectValueReturned EXPECT_EQ(device->getMicrosecondResolution(), expectedMicrosecondResolution); } -TEST(GroupDevicesTest, whenMultipleDevicesAreCreatedThenGroupDevicesCreatesVectorPerEachProductFamily) { +TEST(GroupDevicesTest, whenMultipleDevicesAreCreatedThenGroupDevicesCreatesVectorPerEachProductFamilySortedOverGpuTypeAndProductFamily) { DebugManagerStateRestore restorer; const size_t numRootDevices = 5u; @@ -2150,21 +2150,42 @@ TEST(GroupDevicesTest, whenMultipleDevicesAreCreatedThenGroupDevicesCreatesVecto auto ptl0Device = inputDevices[4].get(); executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_LUNARLAKE; + executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = true; executionEnvironment->rootDeviceEnvironments[1]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_BMG; + executionEnvironment->rootDeviceEnvironments[1]->getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = false; executionEnvironment->rootDeviceEnvironments[2]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_LUNARLAKE; + executionEnvironment->rootDeviceEnvironments[2]->getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = true; executionEnvironment->rootDeviceEnvironments[3]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_LUNARLAKE; + executionEnvironment->rootDeviceEnvironments[3]->getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = true; executionEnvironment->rootDeviceEnvironments[4]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_PTL; + executionEnvironment->rootDeviceEnvironments[4]->getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = true; auto groupedDevices = Device::groupDevices(std::move(inputDevices)); EXPECT_EQ(3u, groupedDevices.size()); EXPECT_EQ(1u, groupedDevices[0].size()); - EXPECT_EQ(3u, groupedDevices[1].size()); - EXPECT_EQ(1u, groupedDevices[2].size()); + EXPECT_EQ(1u, groupedDevices[1].size()); + EXPECT_EQ(3u, groupedDevices[2].size()); - EXPECT_EQ(bmg0Device, groupedDevices[2][0].get()); - EXPECT_EQ(lnl0Device, groupedDevices[1][0].get()); - EXPECT_EQ(lnl1Device, groupedDevices[1][1].get()); - EXPECT_EQ(lnl2Device, groupedDevices[1][2].get()); - EXPECT_EQ(ptl0Device, groupedDevices[0][0].get()); + EXPECT_EQ(lnl0Device, groupedDevices[2][0].get()); + EXPECT_EQ(lnl1Device, groupedDevices[2][1].get()); + EXPECT_EQ(lnl2Device, groupedDevices[2][2].get()); + EXPECT_EQ(ptl0Device, groupedDevices[1][0].get()); + EXPECT_EQ(bmg0Device, groupedDevices[0][0].get()); +} + +TEST(GroupDevicesTest, givenEmptyDeviceVectorWhenGroupDevicesThenEmptyVectorIsReturned) { + DeviceVector inputDevices{}; + auto groupedDevices = Device::groupDevices(std::move(inputDevices)); + + EXPECT_TRUE(groupedDevices.empty()); +} + +TEST(GroupDevicesTest, givenNullInputInDeviceVectorWhenGroupDevicesThenEmptyVectorIsReturned) { + DeviceVector inputDevices{}; + inputDevices.push_back(nullptr); + inputDevices.push_back(nullptr); + auto groupedDevices = Device::groupDevices(std::move(inputDevices)); + + EXPECT_TRUE(groupedDevices.empty()); }