From cedbd91f7559d16fa3dff43fb2f34171b34d8382 Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Wed, 4 Sep 2024 12:43:04 -0400 Subject: [PATCH 1/4] xpu: fix engine_factory_t::count() If status != success then it is a non-zero value, but in that case we have zero devices. Return zero instead so we don't index off the end of anything. --- src/xpu/ocl/engine_factory.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xpu/ocl/engine_factory.hpp b/src/xpu/ocl/engine_factory.hpp index f2b6ed1292b..37862dd01aa 100644 --- a/src/xpu/ocl/engine_factory.hpp +++ b/src/xpu/ocl/engine_factory.hpp @@ -46,7 +46,7 @@ class engine_factory_t : public impl::engine_factory_t { std::vector ocl_devices; status_t status = xpu::ocl::get_devices(&ocl_devices, CL_DEVICE_TYPE_GPU); - if (status != status::success) return status; + if (status != status::success) return 0; return ocl_devices.size(); } From c65af5129395f73d6d7e3998df79721e352e7b9c Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Wed, 4 Sep 2024 12:51:54 -0400 Subject: [PATCH 2/4] xpu/ocl: Always consider 0 devices to be a runtime error --- src/xpu/ocl/utils.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/xpu/ocl/utils.cpp b/src/xpu/ocl/utils.cpp index abe8c8ed726..9957b9c157d 100644 --- a/src/xpu/ocl/utils.cpp +++ b/src/xpu/ocl/utils.cpp @@ -194,8 +194,7 @@ status_t get_devices(std::vector *devices, cl_uint num_platforms = 0; cl_int err = clGetPlatformIDs(0, nullptr, &num_platforms); - // No platforms - a valid scenario - if (err == CL_PLATFORM_NOT_FOUND_KHR) return status::success; + if (err == CL_PLATFORM_NOT_FOUND_KHR) return status::runtime_error; OCL_CHECK(err); @@ -228,8 +227,11 @@ status_t get_devices(std::vector *devices, } } } - // No devices found but still return success - return status::success; + + if (devices->size() != 0) + return status::success; + + return status::runtime_error; } status_t get_devices(std::vector *devices, From 36f25abcb04a7da3a4365d548d9edaa76f1ce856 Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Wed, 4 Sep 2024 12:57:18 -0400 Subject: [PATCH 3/4] xpu/ocl: Don't filter by vendor ID We can't do that at this level because it means device indices change based on how we were called. --- src/xpu/ocl/utils.cpp | 8 ++------ src/xpu/ocl/utils.hpp | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/xpu/ocl/utils.cpp b/src/xpu/ocl/utils.cpp index 9957b9c157d..23519c2fee9 100644 --- a/src/xpu/ocl/utils.cpp +++ b/src/xpu/ocl/utils.cpp @@ -190,7 +190,7 @@ static bool is_intel_platform(cl_platform_id platform) { } status_t get_devices(std::vector *devices, - cl_device_type device_type, cl_uint vendor_id /* = 0x8086 */) { + cl_device_type device_type) { cl_uint num_platforms = 0; cl_int err = clGetPlatformIDs(0, nullptr, &num_platforms); @@ -218,12 +218,8 @@ status_t get_devices(std::vector *devices, OCL_CHECK(clGetDeviceIDs(platforms[i], device_type, num_devices, &plat_devices[0], nullptr)); - // Use the devices for the requested vendor only. for (size_t j = 0; j < plat_devices.size(); ++j) { - cl_uint v_id; - OCL_CHECK(clGetDeviceInfo(plat_devices[j], CL_DEVICE_VENDOR_ID, - sizeof(cl_uint), &v_id, nullptr)); - if (v_id == vendor_id) { devices->push_back(plat_devices[j]); } + devices->push_back(plat_devices[j]); } } } diff --git a/src/xpu/ocl/utils.hpp b/src/xpu/ocl/utils.hpp index 65364e59e4d..8b9609c0fa0 100644 --- a/src/xpu/ocl/utils.hpp +++ b/src/xpu/ocl/utils.hpp @@ -273,7 +273,7 @@ struct ext_func_t { std::string get_kernel_name(cl_kernel kernel); status_t get_devices(std::vector *devices, - cl_device_type device_type, cl_uint vendor_id = 0x8086); + cl_device_type device_type); status_t get_devices(std::vector *devices, std::vector> *sub_devices, From ae7ee949108b4f52365cc4aeea345b4d5ca2394d Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Fri, 30 Aug 2024 11:55:04 -0400 Subject: [PATCH 4/4] xpu/ocl: Permit initialization on any capable OpenCL platform This isn't the place for it, this is generic code and doesn't rely on Intel's OpenCL platform. There's another check later, conditional on DNNL_VENDOR_INTEL at build time, that has the same effect. On a CometLake system, with recent Mesa using rusticl and iris: [----------] 2 tests from AllEngineKinds/engine_test_t [ RUN ] AllEngineKinds/engine_test_t.TestMultithreading/0 onednn_verbose,v1,info,oneDNN v3.6.0 (commit d36af6e408cd77b84531b5bbe4b6f3874df625a3) onednn_verbose,v1,info,cpu,runtime:OpenMP,nthr:20 onednn_verbose,v1,info,cpu,isa:Intel AVX2 onednn_verbose,v1,info,gpu,runtime:OpenCL WARNING: OpenCL support via iris driver is incomplete. For a complete and conformant OpenCL implementation, use https://github.com/intel/compute-runtime instead onednn_verbose,v1,common,error,runtime,unsupported ocl platform (expected intel got rusticl) --- src/xpu/ocl/utils.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/xpu/ocl/utils.cpp b/src/xpu/ocl/utils.cpp index 23519c2fee9..59a8d28da85 100644 --- a/src/xpu/ocl/utils.cpp +++ b/src/xpu/ocl/utils.cpp @@ -202,8 +202,6 @@ status_t get_devices(std::vector *devices, OCL_CHECK(clGetPlatformIDs(num_platforms, &platforms[0], nullptr)); for (size_t i = 0; i < platforms.size(); ++i) { - if (!is_intel_platform(platforms[i])) continue; - cl_uint num_devices = 0; cl_int err = clGetDeviceIDs( platforms[i], device_type, 0, nullptr, &num_devices);