Skip to content

Commit e39575e

Browse files
[SYCL] - Align get_info<info::device::version>() with the SYCL spec
According to the SYCL spec, cl::sycl::info::device::version should be returned in a form: `<major_version>.<minor_version>` This patch trims the string returned from the piDeviceGetInfo call. For example, for the string "OpenCL 2.1 (Build 0)", it will return "2.1".
1 parent a09aed0 commit e39575e

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

sycl/source/detail/device_info.hpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ template <info::device param> struct get_device_info<platform, param> {
122122
}
123123
};
124124

125-
// Specialization for string return type, variable return size
126-
template <info::device param> struct get_device_info<string_class, param> {
125+
// Helper struct to allow using the specialization of get_device_info
126+
// for string return type in other specializations.
127+
template <info::device param> struct get_device_info_string {
127128
static string_class get(RT::PiDevice dev, const plugin &Plugin) {
128129
size_t resultSize;
129130
Plugin.call<PiApiKind::piDeviceGetInfo>(
@@ -140,6 +141,13 @@ template <info::device param> struct get_device_info<string_class, param> {
140141
}
141142
};
142143

144+
// Specialization for string return type, variable return size
145+
template <info::device param> struct get_device_info<string_class, param> {
146+
static string_class get(RT::PiDevice dev, const plugin &Plugin) {
147+
return get_device_info_string<param>::get(dev, Plugin);
148+
}
149+
};
150+
143151
// Specialization for parent device
144152
template <typename T> struct get_device_info<T, info::device::parent_device> {
145153
static T get(RT::PiDevice dev, const plugin &Plugin);
@@ -176,6 +184,30 @@ struct get_device_info<vector_class<info::fp_config>, param> {
176184
}
177185
};
178186

187+
// Specialization for OpenCL version, splits the string returned by OpenCL
188+
template <> struct get_device_info<string_class, info::device::version> {
189+
static string_class get(RT::PiDevice dev, const plugin &Plugin) {
190+
string_class result =
191+
get_device_info_string<info::device::version>::get(dev, Plugin);
192+
193+
// Extract OpenCL version from the returned string.
194+
// For example, for the string "OpenCL 2.1 (Build 0)"
195+
// return '2.1'.
196+
auto dotPos = result.find('.');
197+
if (dotPos == std::string::npos)
198+
return result;
199+
200+
auto leftPos = result.rfind(' ', dotPos);
201+
if (leftPos == std::string::npos)
202+
leftPos = 0;
203+
else
204+
leftPos++;
205+
206+
auto rightPos = result.find(' ', dotPos);
207+
return result.substr(leftPos, rightPos - leftPos);
208+
}
209+
};
210+
179211
// Specialization for single_fp_config, no type support check required
180212
template <>
181213
struct get_device_info<vector_class<info::fp_config>,

sycl/test/plugins/sycl-ls-gpu-opencl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// RUN: env SYCL_BE=PI_OPENCL sycl-ls --verbose >%t.opencl.out
44
// RUN: FileCheck %s --check-prefixes=CHECK-GPU-BUILTIN,CHECK-GPU-CUSTOM --input-file %t.opencl.out
55

6-
// CHECK-GPU-BUILTIN: gpu_selector(){{.*}}GPU : OpenCL
7-
// CHECK-GPU-CUSTOM: custom_selector(gpu){{.*}}GPU : OpenCL
6+
// CHECK-GPU-BUILTIN: gpu_selector(){{.*}}GPU : 2.1
7+
// CHECK-GPU-CUSTOM: custom_selector(gpu){{.*}}GPU : 2.1
88

99
//==-- sycl-ls-gpu-opencl.cpp - SYCL test for discovered/selected devices -===//
1010
//

0 commit comments

Comments
 (0)