DPC++ Runtime
Runtime libraries for oneAPI DPC++
opencl.cpp
Go to the documentation of this file.
1 //==------- opencl.cpp - SYCL OpenCL backend -------------------------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include <detail/kernel_impl.hpp>
10 #include <detail/platform_impl.hpp>
11 #include <detail/plugin.hpp>
12 #include <detail/queue_impl.hpp>
13 #include <sycl/sycl.hpp>
14 
15 #include <memory>
16 #include <string_view>
17 
18 namespace sycl {
19 inline namespace _V1 {
20 namespace opencl {
21 using namespace detail;
22 
23 //----------------------------------------------------------------------------
24 // Free functions to query OpenCL backend extensions
25 __SYCL_EXPORT bool has_extension(const sycl::platform &SyclPlatform,
26  const std::string &Extension) {
27  if (SyclPlatform.get_backend() != sycl::backend::opencl) {
28  throw sycl::exception(
30  "has_extension can only be used with an OpenCL backend");
31  }
32 
33  std::shared_ptr<sycl::detail::platform_impl> PlatformImpl =
34  getSyclObjImpl(SyclPlatform);
35  ur_platform_handle_t PluginPlatform = PlatformImpl->getHandleRef();
36  const PluginPtr &Plugin = PlatformImpl->getPlugin();
37 
38  // Manual invocation of plugin API to avoid using deprecated
39  // info::platform::extensions call.
40  size_t ResultSize = 0;
41  Plugin->call(urPlatformGetInfo, PluginPlatform, UR_PLATFORM_INFO_EXTENSIONS,
42  /*propSize=*/0,
43  /*pPropValue=*/nullptr, &ResultSize);
44  if (ResultSize == 0)
45  return false;
46 
47  std::unique_ptr<char[]> Result(new char[ResultSize]);
48  Plugin->call(urPlatformGetInfo, PluginPlatform, UR_PLATFORM_INFO_EXTENSIONS,
49  ResultSize, Result.get(), nullptr);
50 
51  std::string_view ExtensionsString(Result.get());
52  return ExtensionsString.find(Extension) != std::string::npos;
53 }
54 
55 __SYCL_EXPORT bool has_extension(const sycl::device &SyclDevice,
56  const std::string &Extension) {
57  if (SyclDevice.get_backend() != sycl::backend::opencl) {
58  throw sycl::exception(
60  "has_extension can only be used with an OpenCL backend");
61  }
62 
63  std::shared_ptr<sycl::detail::device_impl> DeviceImpl =
64  getSyclObjImpl(SyclDevice);
65  ur_device_handle_t PluginDevice = DeviceImpl->getHandleRef();
66  const PluginPtr &Plugin = DeviceImpl->getPlugin();
67 
68  // Manual invocation of plugin API to avoid using deprecated
69  // info::device::extensions call.
70  size_t ResultSize = 0;
71  Plugin->call(urDeviceGetInfo, PluginDevice, UR_DEVICE_INFO_EXTENSIONS,
72  /*propSize=*/0,
73  /*pPropValue=*/nullptr, &ResultSize);
74  if (ResultSize == 0)
75  return false;
76 
77  std::unique_ptr<char[]> Result(new char[ResultSize]);
78  Plugin->call(urDeviceGetInfo, PluginDevice, UR_DEVICE_INFO_EXTENSIONS,
79  ResultSize, Result.get(), nullptr);
80 
81  std::string_view ExtensionsString(Result.get());
82  return ExtensionsString.find(Extension) != std::string::npos;
83 }
84 } // namespace opencl
85 } // namespace _V1
86 } // namespace sycl
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:64
backend get_backend() const noexcept
Returns the backend associated with this device.
Definition: device.cpp:203
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:99
backend get_backend() const noexcept
Returns the backend associated with this platform.
Definition: platform.cpp:55
decltype(Obj::impl) const & getSyclObjImpl(const Obj &SyclObject)
Definition: impl_utils.hpp:31
std::shared_ptr< plugin > PluginPtr
Definition: ur.hpp:60
bool has_extension(const sycl::platform &SyclPlatform, const std::string &Extension)
Definition: opencl.cpp:25
Definition: access.hpp:18