Skip to content

Commit b8c627a

Browse files
authored
[ABI-Break][SYCL] ABI-neutralize device:: and platform::has_extension (#13212)
By passing a `detail::string_view` instead of `std::string`, we can make some APIs ABI-neutral. --------- Signed-off-by: Byoungro So <[email protected]>
1 parent 16e39df commit b8c627a

File tree

7 files changed

+37
-20
lines changed

7 files changed

+37
-20
lines changed

sycl/include/sycl/device.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ class __SYCL_EXPORT device : public detail::OwnerLessBase<device> {
228228
/// \param extension_name is a name of queried extension.
229229
/// \return true if SYCL device supports the extension.
230230
__SYCL2020_DEPRECATED("use device::has() function with aspects APIs instead")
231-
bool has_extension(const std::string &extension_name) const;
231+
bool has_extension(const std::string &extension_name) const {
232+
return has_extension(detail::string_view{extension_name});
233+
}
232234

233235
/// Query available SYCL devices
234236
///
@@ -300,7 +302,9 @@ class __SYCL_EXPORT device : public detail::OwnerLessBase<device> {
300302
/// \param Feature
301303
///
302304
/// \return true if supported
303-
bool ext_oneapi_supports_cl_c_feature(const std::string &Feature);
305+
bool ext_oneapi_supports_cl_c_feature(const std::string &Feature) {
306+
return ext_oneapi_supports_cl_c_feature(detail::string_view{Feature});
307+
}
304308

305309
/// Indicates if the device supports kernel bundles written in a particular
306310
/// OpenCL C version
@@ -320,7 +324,9 @@ class __SYCL_EXPORT device : public detail::OwnerLessBase<device> {
320324
/// extension identified by `name`.
321325
bool ext_oneapi_supports_cl_extension(
322326
const std::string &name,
323-
ext::oneapi::experimental::cl_version *version = nullptr) const;
327+
ext::oneapi::experimental::cl_version *version = nullptr) const {
328+
return ext_oneapi_supports_cl_extension(detail::string_view{name}, version);
329+
}
324330

325331
/// Retrieve the OpenCl Device Profile
326332
///
@@ -361,6 +367,12 @@ class __SYCL_EXPORT device : public detail::OwnerLessBase<device> {
361367
typename detail::ABINeutralT_t<
362368
typename detail::is_device_info_desc<Param>::return_type>
363369
get_info_impl() const;
370+
371+
bool has_extension(detail::string_view extension_name) const;
372+
bool ext_oneapi_supports_cl_c_feature(detail::string_view Feature);
373+
bool ext_oneapi_supports_cl_extension(
374+
detail::string_view name,
375+
ext::oneapi::experimental::cl_version *version = nullptr) const;
364376
};
365377

366378
} // namespace _V1

sycl/include/sycl/platform.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase<platform> {
157157
/// \return true if specified extension is supported by this SYCL platform.
158158
__SYCL2020_DEPRECATED(
159159
"use platform::has() function with aspects APIs instead")
160-
bool has_extension(const std::string &ExtensionName) const;
160+
bool has_extension(const std::string &ExtensionName) const {
161+
return has_extension(detail::string_view{ExtensionName});
162+
}
161163

162164
/// Returns all SYCL devices associated with this platform.
163165
///
@@ -249,6 +251,8 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase<platform> {
249251
typename detail::ABINeutralT_t<
250252
typename detail::is_platform_info_desc<Param>::return_type>
251253
get_info_impl() const;
254+
255+
bool has_extension(detail::string_view ExtensionName) const;
252256
}; // class platform
253257
} // namespace _V1
254258
} // namespace sycl

sycl/source/device.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ std::vector<device> device::create_sub_devices() const {
115115
template __SYCL_EXPORT std::vector<device> device::create_sub_devices<
116116
info::partition_property::ext_intel_partition_by_cslice>() const;
117117

118-
bool device::has_extension(const std::string &extension_name) const {
119-
return impl->has_extension(extension_name);
118+
bool device::has_extension(detail::string_view ext_name) const {
119+
return impl->has_extension(ext_name.data());
120120
}
121121

122122
template <typename Param>
@@ -267,7 +267,8 @@ bool device::ext_oneapi_can_compile(
267267
return impl->extOneapiCanCompile(Language);
268268
}
269269

270-
bool device::ext_oneapi_supports_cl_c_feature(const std::string &Feature) {
270+
bool device::ext_oneapi_supports_cl_c_feature(detail::string_view Feature) {
271+
271272
const detail::pi::PiDevice Device = impl->getHandleRef();
272273
auto Plugin = impl->getPlugin();
273274
uint32_t ipVersion = 0;
@@ -278,7 +279,7 @@ bool device::ext_oneapi_supports_cl_c_feature(const std::string &Feature) {
278279
return false;
279280

280281
return ext::oneapi::experimental::detail::OpenCLC_Feature_Available(
281-
Feature, ipVersion);
282+
Feature.data(), ipVersion);
282283
}
283284

284285
bool device::ext_oneapi_supports_cl_c_version(
@@ -297,7 +298,7 @@ bool device::ext_oneapi_supports_cl_c_version(
297298
}
298299

299300
bool device::ext_oneapi_supports_cl_extension(
300-
const std::string &Name,
301+
detail::string_view Name,
301302
ext::oneapi::experimental::cl_version *VersionPtr) const {
302303
const detail::pi::PiDevice Device = impl->getHandleRef();
303304
auto Plugin = impl->getPlugin();
@@ -309,7 +310,7 @@ bool device::ext_oneapi_supports_cl_extension(
309310
return false;
310311

311312
return ext::oneapi::experimental::detail::OpenCLC_Supports_Extension(
312-
Name, VersionPtr, ipVersion);
313+
Name.data(), VersionPtr, ipVersion);
313314
}
314315

315316
std::string device::ext_oneapi_cl_profile() const {

sycl/source/platform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ platform::platform(const device_selector &dev_selector) {
3636

3737
cl_platform_id platform::get() const { return impl->get(); }
3838

39-
bool platform::has_extension(const std::string &ExtensionName) const {
40-
return impl->has_extension(ExtensionName);
39+
bool platform::has_extension(detail::string_view ExtName) const {
40+
return impl->has_extension(ExtName.data());
4141
}
4242

4343
std::vector<device> platform::get_devices(info::device_type DeviceType) const {

sycl/test/abi/sycl_abi_neutrality_test.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@
2929
// CHECK:_ZN4sycl3_V16detail19kernel_bundle_plain21ext_oneapi_has_kernelERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
3030
// CHECK:_ZN4sycl3_V16detail6OSUtil10getDirNameB5cxx11EPKc
3131
// CHECK:_ZN4sycl3_V16detail6OSUtil16getCurrentDSODirB5cxx11Ev
32-
// CHECK:_ZN4sycl3_V16device32ext_oneapi_supports_cl_c_featureERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
3332
// CHECK:_ZN4sycl3_V16opencl13has_extensionERKNS0_6deviceERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
3433
// CHECK:_ZN4sycl3_V16opencl13has_extensionERKNS0_8platformERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
3534
// CHECK:_ZNK4sycl3_V13ext6oneapi12experimental6detail24modifiable_command_graph11print_graphENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb
36-
// CHECK:_ZNK4sycl3_V16device13has_extensionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
3735
// CHECK:_ZNK4sycl3_V16device21ext_oneapi_cl_profileB5cxx11Ev
38-
// CHECK:_ZNK4sycl3_V16device32ext_oneapi_supports_cl_extensionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPNS0_3ext6oneapi12experimental10cl_versionE
39-
// CHECK:_ZNK4sycl3_V18platform13has_extensionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3337,7 +3337,7 @@ _ZN4sycl3_V16device26ext_oneapi_architecture_isENS0_3ext6oneapi12experimental13a
33373337
_ZN4sycl3_V16device26ext_oneapi_can_access_peerERKS1_NS0_3ext6oneapi11peer_accessE
33383338
_ZN4sycl3_V16device29ext_oneapi_enable_peer_accessERKS1_
33393339
_ZN4sycl3_V16device30ext_oneapi_disable_peer_accessERKS1_
3340-
_ZN4sycl3_V16device32ext_oneapi_supports_cl_c_featureERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
3340+
_ZN4sycl3_V16device32ext_oneapi_supports_cl_c_featureENS0_6detail11string_viewE
33413341
_ZN4sycl3_V16deviceC1EP13_cl_device_id
33423342
_ZN4sycl3_V16deviceC1ERKNS0_15device_selectorE
33433343
_ZN4sycl3_V16deviceC1Ev
@@ -3902,7 +3902,7 @@ _ZNK4sycl3_V16device13get_info_implINS0_4info6device7versionEEENS0_6detail11ABIN
39023902
_ZNK4sycl3_V16device13get_info_implINS0_4info6device8atomic64EEENS0_6detail11ABINeutralTINS6_19is_device_info_descIT_E11return_typeEE4typeEv
39033903
_ZNK4sycl3_V16device13get_info_implINS0_4info6device8platformEEENS0_6detail11ABINeutralTINS6_19is_device_info_descIT_E11return_typeEE4typeEv
39043904
_ZNK4sycl3_V16device13get_info_implINS0_4info6device9vendor_idEEENS0_6detail11ABINeutralTINS6_19is_device_info_descIT_E11return_typeEE4typeEv
3905-
_ZNK4sycl3_V16device13has_extensionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
3905+
_ZNK4sycl3_V16device13has_extensionENS0_6detail11string_viewE
39063906
_ZNK4sycl3_V16device14is_acceleratorEv
39073907
_ZNK4sycl3_V16device16get_backend_infoINS0_4info6device15backend_versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv
39083908
_ZNK4sycl3_V16device16get_backend_infoINS0_4info6device7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv
@@ -3913,7 +3913,7 @@ _ZNK4sycl3_V16device18create_sub_devicesILNS0_4info18partition_propertyE4232EEES
39133913
_ZNK4sycl3_V16device18create_sub_devicesILNS0_4info18partition_propertyE4233EEESt6vectorIS1_SaIS1_EEv
39143914
_ZNK4sycl3_V16device21ext_oneapi_cl_profileB5cxx11Ev
39153915
_ZNK4sycl3_V16device32ext_oneapi_supports_cl_c_versionERKNS0_3ext6oneapi12experimental10cl_versionE
3916-
_ZNK4sycl3_V16device32ext_oneapi_supports_cl_extensionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPNS0_3ext6oneapi12experimental10cl_versionE
3916+
_ZNK4sycl3_V16device32ext_oneapi_supports_cl_extensionENS0_6detail11string_viewEPNS0_3ext6oneapi12experimental10cl_versionE
39173917
_ZNK4sycl3_V16device3getEv
39183918
_ZNK4sycl3_V16device3hasENS0_6aspectE
39193919
_ZNK4sycl3_V16device6is_cpuEv
@@ -3989,7 +3989,7 @@ _ZNK4sycl3_V18platform13get_info_implINS0_4info8platform4nameEEENS0_6detail11ABI
39893989
_ZNK4sycl3_V18platform13get_info_implINS0_4info8platform6vendorEEENS0_6detail11ABINeutralTINS6_21is_platform_info_descIT_E11return_typeEE4typeEv
39903990
_ZNK4sycl3_V18platform13get_info_implINS0_4info8platform7profileEEENS0_6detail11ABINeutralTINS6_21is_platform_info_descIT_E11return_typeEE4typeEv
39913991
_ZNK4sycl3_V18platform13get_info_implINS0_4info8platform7versionEEENS0_6detail11ABINeutralTINS6_21is_platform_info_descIT_E11return_typeEE4typeEv
3992-
_ZNK4sycl3_V18platform13has_extensionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
3992+
_ZNK4sycl3_V18platform13has_extensionENS0_6detail11string_viewE
39933993
_ZNK4sycl3_V18platform16get_backend_infoINS0_4info6device15backend_versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv
39943994
_ZNK4sycl3_V18platform16get_backend_infoINS0_4info6device7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv
39953995
_ZNK4sycl3_V18platform16get_backend_infoINS0_4info8platform7versionEEENS0_6detail20is_backend_info_descIT_E11return_typeEv

sycl/test/abi/sycl_symbols_windows.dump

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3854,8 +3854,10 @@
38543854
?ext_oneapi_signal_external_semaphore@queue@_V1@sycl@@QEAA?AVevent@23@Uinterop_semaphore_handle@experimental@oneapi@ext@23@_KV423@AEBUcode_location@detail@23@@Z
38553855
?ext_oneapi_submit_barrier@queue@_V1@sycl@@QEAA?AVevent@23@AEBUcode_location@detail@23@@Z
38563856
?ext_oneapi_submit_barrier@queue@_V1@sycl@@QEAA?AVevent@23@AEBV?$vector@Vevent@_V1@sycl@@V?$allocator@Vevent@_V1@sycl@@@std@@@std@@AEBUcode_location@detail@23@@Z
3857+
?ext_oneapi_supports_cl_c_feature@device@_V1@sycl@@AEAA_NVstring_view@detail@23@@Z
38573858
?ext_oneapi_supports_cl_c_feature@device@_V1@sycl@@QEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z
38583859
?ext_oneapi_supports_cl_c_version@device@_V1@sycl@@QEBA_NAEBUcl_version@experimental@oneapi@ext@23@@Z
3860+
?ext_oneapi_supports_cl_extension@device@_V1@sycl@@AEBA_NVstring_view@detail@23@PEAUcl_version@experimental@oneapi@ext@23@@Z
38593861
?ext_oneapi_supports_cl_extension@device@_V1@sycl@@QEBA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAUcl_version@experimental@oneapi@ext@23@@Z
38603862
?ext_oneapi_wait_external_semaphore@handler@_V1@sycl@@QEAAXUinterop_semaphore_handle@experimental@oneapi@ext@23@@Z
38613863
?ext_oneapi_wait_external_semaphore@handler@_V1@sycl@@QEAAXUinterop_semaphore_handle@experimental@oneapi@ext@23@_K@Z
@@ -4065,9 +4067,11 @@
40654067
?has@device@_V1@sycl@@QEBA_NW4aspect@23@@Z
40664068
?has@platform@_V1@sycl@@QEBA_NW4aspect@23@@Z
40674069
?has_context@exception@_V1@sycl@@QEBA_NXZ
4070+
?has_extension@device@_V1@sycl@@AEBA_NVstring_view@detail@23@@Z
40684071
?has_extension@device@_V1@sycl@@QEBA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z
40694072
?has_extension@opencl@_V1@sycl@@YA_NAEBVdevice@23@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z
40704073
?has_extension@opencl@_V1@sycl@@YA_NAEBVplatform@23@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z
4074+
?has_extension@platform@_V1@sycl@@AEBA_NVstring_view@detail@23@@Z
40714075
?has_extension@platform@_V1@sycl@@QEBA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z
40724076
?has_kernel@device_image_plain@detail@_V1@sycl@@QEBA_NAEBVkernel_id@34@@Z
40734077
?has_kernel@device_image_plain@detail@_V1@sycl@@QEBA_NAEBVkernel_id@34@AEBVdevice@34@@Z

0 commit comments

Comments
 (0)