From 6ec92ac082fb071198e2bcfc7b8ef07ba894202c Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Wed, 12 Feb 2025 11:25:57 +0000 Subject: [PATCH] refactor: move groupDevices logic to shared code update platforms used in unit test Related-To: NEO-14062 Signed-off-by: Mateusz Jablonski --- opencl/source/api/api.cpp | 2 +- opencl/source/platform/platform.cpp | 21 +--------- opencl/source/platform/platform.h | 3 +- .../unit_test/platform/platform_tests.cpp | 41 +------------------ shared/source/device/device.cpp | 19 +++++++++ shared/source/device/device.h | 2 + .../unit_test/device/neo_device_tests.cpp | 41 ++++++++++++++++++- 7 files changed, 65 insertions(+), 64 deletions(-) diff --git a/opencl/source/api/api.cpp b/opencl/source/api/api.cpp index 1871e27731..ef59633df7 100644 --- a/opencl/source/api/api.cpp +++ b/opencl/source/api/api.cpp @@ -105,7 +105,7 @@ cl_int CL_API_CALL clGetPlatformIDs(cl_uint numEntries, retVal = CL_OUT_OF_HOST_MEMORY; break; } - auto groupedDevices = Platform::groupDevices(std::move(allDevices)); + auto groupedDevices = Device::groupDevices(std::move(allDevices)); for (auto &deviceVector : groupedDevices) { auto pPlatform = Platform::createFunc(*executionEnvironment); diff --git a/opencl/source/platform/platform.cpp b/opencl/source/platform/platform.cpp index 5e35e4c4d4..92334bd28d 100644 --- a/opencl/source/platform/platform.cpp +++ b/opencl/source/platform/platform.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2024 Intel Corporation + * Copyright (C) 2018-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -243,23 +243,4 @@ std::unique_ptr (*Platform::createFunc)(ExecutionEnvironment &) = [](E return std::make_unique(executionEnvironment); }; -std::vector Platform::groupDevices(DeviceVector devices) { - std::map platformsMap; - std::vector outDevices; - for (auto &device : devices) { - auto productFamily = device->getHardwareInfo().platform.eProductFamily; - auto result = platformsMap.find(productFamily); - if (result == platformsMap.end()) { - platformsMap.insert({productFamily, platformsMap.size()}); - outDevices.push_back(DeviceVector{}); - } - auto platformId = platformsMap[productFamily]; - outDevices[platformId].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) - }); - return outDevices; -} - } // namespace NEO diff --git a/opencl/source/platform/platform.h b/opencl/source/platform/platform.h index b9f026d475..02835d99be 100644 --- a/opencl/source/platform/platform.h +++ b/opencl/source/platform/platform.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -57,7 +57,6 @@ class Platform : public BaseObject<_cl_platform_id> { ExecutionEnvironment *peekExecutionEnvironment() const { return &executionEnvironment; } static std::unique_ptr (*createFunc)(ExecutionEnvironment &executionEnvironment); - static std::vector groupDevices(DeviceVector devices); protected: enum { diff --git a/opencl/test/unit_test/platform/platform_tests.cpp b/opencl/test/unit_test/platform/platform_tests.cpp index 1043c715eb..e1f45cc2a0 100644 --- a/opencl/test/unit_test/platform/platform_tests.cpp +++ b/opencl/test/unit_test/platform/platform_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2024 Intel Corporation + * Copyright (C) 2018-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -438,42 +438,3 @@ TEST(PlatformInitTest, GivenPreferredPlatformNameWhenPlatformIsInitializedThenOv EXPECT_TRUE(status); EXPECT_STREQ("Overridden Platform Name", platform()->getPlatformInfo().name.c_str()); } - -TEST(PlatformGroupDevicesTest, whenMultipleDevicesAreCreatedThenGroupDevicesCreatesVectorPerEachProductFamily) { - DebugManagerStateRestore restorer; - const size_t numRootDevices = 5u; - - debugManager.flags.CreateMultipleRootDevices.set(numRootDevices); - auto executionEnvironment = new ExecutionEnvironment(); - - for (auto i = 0u; i < numRootDevices; i++) { - executionEnvironment->rootDeviceEnvironments.push_back(std::make_unique(*executionEnvironment)); - } - auto inputDevices = DeviceFactory::createDevices(*executionEnvironment); - EXPECT_EQ(numRootDevices, inputDevices.size()); - - auto skl0Device = inputDevices[0].get(); - auto kbl0Device = inputDevices[1].get(); - auto skl1Device = inputDevices[2].get(); - auto skl2Device = inputDevices[3].get(); - auto cfl0Device = inputDevices[4].get(); - - executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_SKYLAKE; - executionEnvironment->rootDeviceEnvironments[1]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_KABYLAKE; - executionEnvironment->rootDeviceEnvironments[2]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_SKYLAKE; - executionEnvironment->rootDeviceEnvironments[3]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_SKYLAKE; - executionEnvironment->rootDeviceEnvironments[4]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_COFFEELAKE; - - auto groupedDevices = Platform::groupDevices(std::move(inputDevices)); - - EXPECT_EQ(3u, groupedDevices.size()); - EXPECT_EQ(1u, groupedDevices[0].size()); - EXPECT_EQ(1u, groupedDevices[1].size()); - EXPECT_EQ(3u, groupedDevices[2].size()); - - EXPECT_EQ(skl0Device, groupedDevices[2][0].get()); - EXPECT_EQ(skl1Device, groupedDevices[2][1].get()); - EXPECT_EQ(skl2Device, groupedDevices[2][2].get()); - EXPECT_EQ(kbl0Device, groupedDevices[1][0].get()); - EXPECT_EQ(cfl0Device, groupedDevices[0][0].get()); -} diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index 1a315509ba..70aa42e36c 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -1259,4 +1259,23 @@ void Device::stopDirectSubmissionForCopyEngine() { } } +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{}); + } + 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) + }); + return outDevices; +} + } // namespace NEO diff --git a/shared/source/device/device.h b/shared/source/device/device.h index ff4be527ca..0b58e550f2 100644 --- a/shared/source/device/device.h +++ b/shared/source/device/device.h @@ -8,6 +8,7 @@ #pragma once #include "shared/source/command_stream/preemption_mode.h" #include "shared/source/device/device_info.h" +#include "shared/source/helpers/common_types.h" #include "shared/source/helpers/engine_control.h" #include "shared/source/helpers/engine_node_helper.h" #include "shared/source/helpers/non_copyable_or_moveable.h" @@ -144,6 +145,7 @@ class Device : public ReferenceTrackedObject { bool isFullRangeSvm() const; static bool isBlitSplitEnabled(); static bool isInitDeviceWithFirstSubmissionEnabled(CommandStreamReceiverType csrType); + static std::vector groupDevices(DeviceVector devices); bool isBcsSplitSupported(); bool isInitDeviceWithFirstSubmissionSupported(CommandStreamReceiverType csrType); bool areSharedSystemAllocationsAllowed() const; diff --git a/shared/test/unit_test/device/neo_device_tests.cpp b/shared/test/unit_test/device/neo_device_tests.cpp index 4d2b271ccc..bc6b29866d 100644 --- a/shared/test/unit_test/device/neo_device_tests.cpp +++ b/shared/test/unit_test/device/neo_device_tests.cpp @@ -2128,4 +2128,43 @@ TEST(Device, givenDeviceWhenGettingMicrosecondResolutionThenCorrectValueReturned uint32_t expectedMicrosecondResolution = 123; device->microsecondResolution = expectedMicrosecondResolution; EXPECT_EQ(device->getMicrosecondResolution(), expectedMicrosecondResolution); -} \ No newline at end of file +} + +TEST(GroupDevicesTest, whenMultipleDevicesAreCreatedThenGroupDevicesCreatesVectorPerEachProductFamily) { + DebugManagerStateRestore restorer; + const size_t numRootDevices = 5u; + + debugManager.flags.CreateMultipleRootDevices.set(numRootDevices); + auto executionEnvironment = new ExecutionEnvironment(); + + for (auto i = 0u; i < numRootDevices; i++) { + executionEnvironment->rootDeviceEnvironments.push_back(std::make_unique(*executionEnvironment)); + } + auto inputDevices = DeviceFactory::createDevices(*executionEnvironment); + EXPECT_EQ(numRootDevices, inputDevices.size()); + + auto lnl0Device = inputDevices[0].get(); + auto bmg0Device = inputDevices[1].get(); + auto lnl1Device = inputDevices[2].get(); + auto lnl2Device = inputDevices[3].get(); + auto ptl0Device = inputDevices[4].get(); + + executionEnvironment->rootDeviceEnvironments[0]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_LUNARLAKE; + executionEnvironment->rootDeviceEnvironments[1]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_BMG; + executionEnvironment->rootDeviceEnvironments[2]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_LUNARLAKE; + executionEnvironment->rootDeviceEnvironments[3]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_LUNARLAKE; + executionEnvironment->rootDeviceEnvironments[4]->getMutableHardwareInfo()->platform.eProductFamily = IGFX_PTL; + + 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(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()); +}