DPC++ Runtime
Runtime libraries for oneAPI DPC++
opencl.hpp
Go to the documentation of this file.
1 //==---------------- opencl.hpp - 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 #pragma once
10 
11 #include <sycl/backend_types.hpp> // for backend
12 #include <sycl/context.hpp> // for context
13 #include <sycl/detail/backend_traits.hpp> // for interop
14 #include <sycl/detail/defines_elementary.hpp> // for __SYCL_DEPRECATED
15 #include <sycl/detail/export.hpp> // for __SYCL_EXPORT
16 #include <sycl/detail/pi.h> // for pi_native_handle
17 #include <sycl/device.hpp> // for device
18 #include <sycl/platform.hpp> // for platform
19 #include <sycl/queue.hpp> // for queue
20 
21 #include <string> // for string
22 #include <type_traits> // for enable_if_t
23 
24 namespace sycl {
25 inline namespace _V1 {
26 namespace opencl {
27 // Implementation of various "make" functions resides in SYCL RT because
28 // creating SYCL objects requires knowing details not accessible here.
29 // Note that they take opaque pi_native_handle that real OpenCL handles
30 // are casted to.
31 //
32 __SYCL_EXPORT platform make_platform(pi_native_handle NativeHandle);
33 __SYCL_EXPORT device make_device(pi_native_handle NativeHandle);
34 __SYCL_EXPORT context make_context(pi_native_handle NativeHandle);
35 __SYCL_EXPORT queue make_queue(const context &Context,
36  pi_native_handle InteropHandle);
37 
38 __SYCL_EXPORT bool has_extension(const sycl::platform &SyclPlatform,
39  const std::string &Extension);
40 __SYCL_EXPORT bool has_extension(const sycl::device &SyclDevice,
41  const std::string &Extension);
42 
43 // Construction of SYCL platform.
44 template <typename T,
45  typename std::enable_if_t<std::is_same_v<T, platform>> * = nullptr>
46 __SYCL_DEPRECATED("Use SYCL 2020 sycl::make_platform free function")
47 T make(typename detail::interop<backend::opencl, T>::type Interop) {
48  return make_platform(detail::pi::cast<pi_native_handle>(Interop));
49 }
50 
51 // Construction of SYCL device.
52 template <typename T,
53  typename std::enable_if_t<std::is_same_v<T, device>> * = nullptr>
54 __SYCL_DEPRECATED("Use SYCL 2020 sycl::make_device free function")
55 T make(typename detail::interop<backend::opencl, T>::type Interop) {
56  return make_device(detail::pi::cast<pi_native_handle>(Interop));
57 }
58 
59 // Construction of SYCL context.
60 template <typename T,
61  typename std::enable_if_t<std::is_same_v<T, context>> * = nullptr>
62 __SYCL_DEPRECATED("Use SYCL 2020 sycl::make_context free function")
63 T make(typename detail::interop<backend::opencl, T>::type Interop) {
64  return make_context(detail::pi::cast<pi_native_handle>(Interop));
65 }
66 
67 // Construction of SYCL queue.
68 template <typename T,
69  typename std::enable_if_t<std::is_same_v<T, queue>> * = nullptr>
70 __SYCL_DEPRECATED("Use SYCL 2020 sycl::make_queue free function")
71 T make(const context &Context,
72  typename detail::interop<backend::opencl, T>::type Interop) {
73  return make_queue(Context, detail::pi::cast<pi_native_handle>(Interop));
74 }
75 } // namespace opencl
76 } // namespace _V1
77 } // namespace sycl
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:51
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:64
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:99
#define __SYCL_DEPRECATED(message)
device make_device(pi_native_handle NativeHandle)
Definition: opencl.cpp:32
platform make_platform(pi_native_handle NativeHandle)
Definition: opencl.cpp:26
bool has_extension(const sycl::platform &SyclPlatform, const std::string &Extension)
Definition: opencl.cpp:54
context make_context(pi_native_handle NativeHandle)
Definition: opencl.cpp:38
T make(typename detail::interop< backend::opencl, T >::type Interop)
Definition: opencl.hpp:47
queue make_queue(const context &Context, pi_native_handle InteropHandle)
Definition: opencl.cpp:45
Definition: access.hpp:18
uintptr_t pi_native_handle
Definition: pi.h:217