Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[GPU] Prefer Intel OpenCL platform when enumerating GPU devices (#37426)

Aleksandr Voronafd4204db8cf
diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/device.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/device.hpp
index 4c4d733e1f7..d88bd233b0f 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/device.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/device.hpp
@@ -38,8 +38,9 @@ public:
// The priority return by this function impacts the order of devices reported by GPU plugin and devices enumeration
// Lower priority value means lower device ID
// Current behavior is: Intel iGPU < Intel dGPU < any other GPU
-// Order of Intel dGPUs is undefined and depends on the OCL impl
-// Order of other vendor GPUs is undefined and depends on the OCL impl
+// Devices with the equal priority keep the order they were enumerated in.
+// The OCL runtime moves the Intel platform to the beginning of the platform list.
+// Order of the devices reported by the same platform is undefined and depends on the OCL impl
inline size_t get_device_priority(const cldnn::device_info& info) {
if (info.vendor_id == cldnn::INTEL_VENDOR_ID && info.dev_type == cldnn::device_type::integrated_gpu) {
return 0;
diff --git a/src/plugins/intel_gpu/src/runtime/ocl/ocl_device_detector.cpp b/src/plugins/intel_gpu/src/runtime/ocl/ocl_device_detector.cpp
index e5f49931302..aee784eef6b 100644
--- a/src/plugins/intel_gpu/src/runtime/ocl/ocl_device_detector.cpp
+++ b/src/plugins/intel_gpu/src/runtime/ocl/ocl_device_detector.cpp
@@ -7,6 +7,8 @@
#include "ocl_device.hpp"
#include "ocl_common.hpp"
+#include <algorithm>
+#include <iterator>
#include <string>
#include <vector>
@@ -188,6 +190,14 @@ std::vector<device::ptr> ocl_device_detector::create_device_list() const {
error_code = clGetPlatformIDs(num_platforms, platform_ids.data(), nullptr);
OPENVINO_ASSERT(error_code == CL_SUCCESS, create_device_error_msg, "[GPU] clGetPlatformIDs error code: ", std::to_string(error_code));
+ // The ICD loader doesn't guarantee platform order. Keep Intel devices first.
+ const auto intel_platform = std::find_if(platform_ids.begin(), platform_ids.end(), [](const cl_platform_id id) {
+ return cl::Platform(id).getInfo<CL_PLATFORM_VENDOR>() == INTEL_PLATFORM_VENDOR;
+ });
+ if (intel_platform != platform_ids.end()) {
+ std::rotate(platform_ids.begin(), intel_platform, std::next(intel_platform));
+ }
+
std::vector<device::ptr> supported_devices;
for (auto& id : platform_ids) {
cl::Platform platform = cl::Platform(id);