DPC++ Runtime
Runtime libraries for oneAPI DPC++
backend_traits_opencl.hpp
Go to the documentation of this file.
1 //===---- backend_traits_opencl.hpp - Backend traits for OpenCL --*- C++-*-===//
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 // This file defines the specializations of the sycl::detail::interop,
10 // sycl::detail::BackendInput, sycl::detail::BackendReturn and
11 // sycl::detail::InteropFeatureSupportMap class templates for the OpenCL
12 // backend.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #pragma once
17 
18 #include <sycl/accessor.hpp>
19 #include <sycl/context.hpp>
21 #include <sycl/detail/defines.hpp>
22 #include <sycl/detail/pi.hpp>
23 #include <sycl/device.hpp>
24 #include <sycl/event.hpp>
25 #include <sycl/kernel_bundle.hpp>
26 #include <sycl/queue.hpp>
27 
28 namespace sycl {
30 namespace detail {
31 
32 // TODO the interops for context, device, event, platform and program
33 // may be removed after removing the deprecated 'get_native()' methods
34 // from the corresponding classes. The interop<backend, queue> specialization
35 // is also used in the get_queue() method of the deprecated class
36 // interop_handler and also can be removed after API cleanup.
37 template <> struct interop<backend::opencl, context> {
38  using type = cl_context;
39 };
40 
41 template <> struct interop<backend::opencl, device> {
42  using type = cl_device_id;
43 };
44 
45 template <> struct interop<backend::opencl, queue> {
46  using type = cl_command_queue;
47 };
48 
49 template <> struct interop<backend::opencl, platform> {
50  using type = cl_platform_id;
51 };
52 
53 // TODO the interops for accessor is used in the already deprecated class
54 // interop_handler and can be removed after API cleanup.
55 template <typename DataT, int Dimensions, access::mode AccessMode>
57  accessor<DataT, Dimensions, AccessMode, access::target::device,
58  access::placeholder::false_t>> {
59  using type = cl_mem;
60 };
61 
62 template <typename DataT, int Dimensions, access::mode AccessMode>
63 struct interop<backend::opencl, accessor<DataT, Dimensions, AccessMode,
64  access::target::constant_buffer,
65  access::placeholder::false_t>> {
66  using type = cl_mem;
67 };
68 
69 template <typename DataT, int Dimensions, access::mode AccessMode>
71  accessor<DataT, Dimensions, AccessMode, access::target::image,
72  access::placeholder::false_t>> {
73  using type = cl_mem;
74 };
75 
76 template <typename DataT, int Dimensions, typename AllocatorT>
77 struct BackendInput<backend::opencl, buffer<DataT, Dimensions, AllocatorT>> {
78  using type = cl_mem;
79 };
80 
81 template <typename DataT, int Dimensions, typename AllocatorT>
82 struct BackendReturn<backend::opencl, buffer<DataT, Dimensions, AllocatorT>> {
83  using type = std::vector<cl_mem>;
84 };
85 
86 template <> struct BackendInput<backend::opencl, context> {
87  using type = cl_context;
88 };
89 
90 template <> struct BackendReturn<backend::opencl, context> {
91  using type = cl_context;
92 };
93 
94 template <> struct BackendInput<backend::opencl, device> {
95  using type = cl_device_id;
96 };
97 
98 template <> struct BackendReturn<backend::opencl, device> {
99  using type = cl_device_id;
100 };
101 
102 template <> struct interop<backend::opencl, event> {
103  using type = std::vector<cl_event>;
104  using value_type = cl_event;
105 };
106 template <> struct BackendInput<backend::opencl, event> {
107  using type = std::vector<cl_event>;
108  using value_type = cl_event;
109 };
110 template <> struct BackendReturn<backend::opencl, event> {
111  using type = std::vector<cl_event>;
112  using value_type = cl_event;
113 };
114 
115 template <> struct BackendInput<backend::opencl, queue> {
116  using type = cl_command_queue;
117 };
118 
119 template <> struct BackendReturn<backend::opencl, queue> {
120  using type = cl_command_queue;
121 };
122 
123 template <> struct BackendInput<backend::opencl, platform> {
124  using type = cl_platform_id;
125 };
126 
127 template <> struct BackendReturn<backend::opencl, platform> {
128  using type = cl_platform_id;
129 };
130 
131 template <bundle_state State>
133  using type = cl_program;
134 };
135 
136 template <bundle_state State>
138  using type = std::vector<cl_program>;
139 };
140 
141 template <> struct BackendInput<backend::opencl, kernel> {
142  using type = cl_kernel;
143 };
144 
145 template <> struct BackendReturn<backend::opencl, kernel> {
146  using type = cl_kernel;
147 };
148 
150  static constexpr bool MakePlatform = true;
151  static constexpr bool MakeDevice = true;
152  static constexpr bool MakeContext = true;
153  static constexpr bool MakeQueue = true;
154  static constexpr bool MakeEvent = true;
155  static constexpr bool MakeBuffer = true;
156  static constexpr bool MakeKernel = true;
157  static constexpr bool MakeKernelBundle = true;
158 };
159 
160 namespace pi {
161 // Cast for std::vector<cl_event>, according to the spec, make_event
162 // should create one(?) event from a vector of cl_event
163 template <class To> inline To cast(std::vector<cl_event> value) {
164  RT::assertion(value.size() == 1,
165  "Temporary workaround requires that the "
166  "size of the input vector for make_event be equal to one.");
167  return cast<To>(value[0]);
168 }
169 
170 // These conversions should use PI interop API.
171 template <>
172 inline PiProgram
173  cast(cl_program) = delete; // Use piextCreateProgramWithNativeHandle
174 
175 template <>
176 inline PiDevice
177  cast(cl_device_id) = delete; // Use piextCreateDeviceWithNativeHandle
178 } // namespace pi
179 } // namespace detail
180 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
181 } // namespace sycl
sycl::_V1::detail::BackendInput< backend::opencl, device >::type
cl_device_id type
Definition: backend_traits_opencl.hpp:95
sycl::_V1::detail::BackendReturn< backend::opencl, context >::type
cl_context type
Definition: backend_traits_opencl.hpp:91
sycl::_V1::backend
backend
Definition: backend_types.hpp:21
sycl::_V1::detail::BackendReturn< backend::opencl, kernel >::type
cl_kernel type
Definition: backend_traits_opencl.hpp:146
sycl::_V1::detail::BackendReturn< backend::opencl, event >::type
std::vector< cl_event > type
Definition: backend_traits_opencl.hpp:111
sycl::_V1::detail::interop< backend::opencl, accessor< DataT, Dimensions, AccessMode, access::target::device, access::placeholder::false_t > >::type
cl_mem type
Definition: backend_traits_opencl.hpp:59
device.hpp
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:13
sycl::_V1::buffer
Defines a shared array that can be used by kernels in queues.
Definition: buffer.hpp:35
sycl::_V1::detail::interop< backend::opencl, context >::type
cl_context type
Definition: backend_traits_opencl.hpp:38
sycl::_V1::detail::interop< backend::opencl, platform >::type
cl_platform_id type
Definition: backend_traits_opencl.hpp:50
sycl::_V1::detail::pi::PiDevice
::pi_device PiDevice
Definition: pi.hpp:110
context.hpp
sycl::_V1::detail::interop< backend::opencl, event >::value_type
cl_event value_type
Definition: backend_traits_opencl.hpp:104
event.hpp
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:13
sycl::_V1::event
An event object can be used to synchronize memory transfers, enqueues of kernels and signaling barrie...
Definition: event.hpp:38
pi.hpp
sycl::_V1::detail::interop< backend::opencl, event >::type
std::vector< cl_event > type
Definition: backend_traits_opencl.hpp:103
cast
To cast(From value)
Definition: pi_opencl.cpp:42
backend_traits.hpp
sycl::_V1::detail::BackendInput
Definition: backend_traits.hpp:20
sycl::_V1::detail::InteropFeatureSupportMap
Definition: backend_traits.hpp:24
sycl::_V1::detail::BackendInput< backend::opencl, kernel_bundle< State > >::type
cl_program type
Definition: backend_traits_opencl.hpp:133
sycl::_V1::kernel
Provides an abstraction of a SYCL kernel.
Definition: kernel.hpp:69
sycl::_V1::detail::BackendReturn< backend::opencl, buffer< DataT, Dimensions, AllocatorT > >::type
std::vector< cl_mem > type
Definition: backend_traits_opencl.hpp:83
sycl::_V1::detail::interop
Definition: backend_traits.hpp:18
sycl::_V1::detail::BackendReturn< backend::opencl, platform >::type
cl_platform_id type
Definition: backend_traits_opencl.hpp:128
kernel_bundle.hpp
sycl::_V1::queue
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:86
sycl::_V1::detail::interop< backend::opencl, accessor< DataT, Dimensions, AccessMode, access::target::constant_buffer, access::placeholder::false_t > >::type
cl_mem type
Definition: backend_traits_opencl.hpp:66
sycl::_V1::detail::BackendReturn< backend::opencl, kernel_bundle< State > >::type
std::vector< cl_program > type
Definition: backend_traits_opencl.hpp:138
sycl::_V1::detail::interop< backend::opencl, accessor< DataT, Dimensions, AccessMode, access::target::image, access::placeholder::false_t > >::type
cl_mem type
Definition: backend_traits_opencl.hpp:73
defines.hpp
sycl::_V1::detail::pi::PiProgram
::pi_program PiProgram
Definition: pi.hpp:115
sycl::_V1::kernel_bundle
The kernel_bundle class represents collection of device images in a particular state.
Definition: kernel.hpp:27
sycl::_V1::detail::interop< backend::opencl, queue >::type
cl_command_queue type
Definition: backend_traits_opencl.hpp:46
sycl::_V1::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:47
queue.hpp
sycl::_V1::detail::interop< backend::opencl, device >::type
cl_device_id type
Definition: backend_traits_opencl.hpp:42
sycl::_V1::detail::BackendInput< backend::opencl, event >::type
std::vector< cl_event > type
Definition: backend_traits_opencl.hpp:107
sycl::_V1::accessor
Definition: accessor.hpp:227
accessor.hpp
sycl::_V1::detail::BackendReturn
Definition: backend_traits.hpp:22
sycl::_V1::detail::BackendReturn< backend::opencl, device >::type
cl_device_id type
Definition: backend_traits_opencl.hpp:99
sycl::_V1::backend::opencl
@ opencl
sycl::_V1::detail::BackendReturn< backend::opencl, event >::value_type
cl_event value_type
Definition: backend_traits_opencl.hpp:112
sycl::_V1::detail::BackendInput< backend::opencl, platform >::type
cl_platform_id type
Definition: backend_traits_opencl.hpp:124
sycl::_V1::detail::pi::assertion
void assertion(bool Condition, const char *Message=nullptr)
Definition: pi.cpp:547
sycl::_V1::platform
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:45
sycl::_V1::detail::BackendInput< backend::opencl, event >::value_type
cl_event value_type
Definition: backend_traits_opencl.hpp:108
sycl::_V1::detail::BackendInput< backend::opencl, buffer< DataT, Dimensions, AllocatorT > >::type
cl_mem type
Definition: backend_traits_opencl.hpp:78
sycl::_V1::detail::BackendInput< backend::opencl, queue >::type
cl_command_queue type
Definition: backend_traits_opencl.hpp:116
sycl::_V1::detail::BackendInput< backend::opencl, context >::type
cl_context type
Definition: backend_traits_opencl.hpp:87
sycl::_V1::detail::BackendReturn< backend::opencl, queue >::type
cl_command_queue type
Definition: backend_traits_opencl.hpp:120
sycl::_V1::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:39
sycl::_V1::detail::BackendInput< backend::opencl, kernel >::type
cl_kernel type
Definition: backend_traits_opencl.hpp:142