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 <CL/sycl/accessor.hpp>
19 #include <CL/sycl/context.hpp>
22 #include <CL/sycl/device.hpp>
23 #include <CL/sycl/event.hpp>
25 #include <CL/sycl/queue.hpp>
26 
28 namespace sycl {
29 namespace detail {
30 
31 // TODO the interops for context, device, event, platform and program
32 // may be removed after removing the deprecated 'get_native()' methods
33 // from the corresponding classes. The interop<backend, queue> specialization
34 // is also used in the get_queue() method of the deprecated class
35 // interop_handler and also can be removed after API cleanup.
36 template <> struct interop<backend::opencl, context> {
37  using type = cl_context;
38 };
39 
40 template <> struct interop<backend::opencl, device> {
41  using type = cl_device_id;
42 };
43 
44 template <> struct interop<backend::opencl, queue> {
45  using type = cl_command_queue;
46 };
47 
48 template <> struct interop<backend::opencl, platform> {
49  using type = cl_platform_id;
50 };
51 
52 #ifdef __SYCL_INTERNAL_API
53 template <> struct interop<backend::opencl, program> {
54  using type = cl_program;
55 };
56 #endif
57 
58 // TODO the interops for accessor is used in the already deprecated class
59 // interop_handler and can be removed after API cleanup.
60 template <typename DataT, int Dimensions, access::mode AccessMode>
62  accessor<DataT, Dimensions, AccessMode, access::target::device,
63  access::placeholder::false_t>> {
64  using type = cl_mem;
65 };
66 
67 template <typename DataT, int Dimensions, access::mode AccessMode>
68 struct interop<backend::opencl, accessor<DataT, Dimensions, AccessMode,
69  access::target::constant_buffer,
70  access::placeholder::false_t>> {
71  using type = cl_mem;
72 };
73 
74 template <typename DataT, int Dimensions, access::mode AccessMode>
76  accessor<DataT, Dimensions, AccessMode, access::target::image,
77  access::placeholder::false_t>> {
78  using type = cl_mem;
79 };
80 
81 template <typename DataT, int Dimensions, typename AllocatorT>
82 struct BackendInput<backend::opencl, buffer<DataT, Dimensions, AllocatorT>> {
83  using type = cl_mem;
84 };
85 
86 #ifdef SYCL2020_CONFORMANT_APIS
87 template <typename DataT, int Dimensions, typename AllocatorT>
88 struct BackendReturn<backend::opencl, buffer<DataT, Dimensions, AllocatorT>> {
89  using type = std::vector<cl_mem>;
90 };
91 #else
92 template <typename DataT, int Dimensions, typename AllocatorT>
93 struct BackendReturn<backend::opencl, buffer<DataT, Dimensions, AllocatorT>> {
94  using type = cl_mem;
95 };
96 #endif
97 
98 template <> struct BackendInput<backend::opencl, context> {
99  using type = cl_context;
100 };
101 
102 template <> struct BackendReturn<backend::opencl, context> {
103  using type = cl_context;
104 };
105 
106 template <> struct BackendInput<backend::opencl, device> {
107  using type = cl_device_id;
108 };
109 
110 template <> struct BackendReturn<backend::opencl, device> {
111  using type = cl_device_id;
112 };
113 
114 #ifdef SYCL2020_CONFORMANT_APIS
115 template <> struct interop<backend::opencl, event> {
116  using type = std::vector<cl_event>;
117  using value_type = cl_event;
118 };
119 template <> struct BackendInput<backend::opencl, event> {
120  using type = std::vector<cl_event>;
121  using value_type = cl_event;
122 };
123 template <> struct BackendReturn<backend::opencl, event> {
124  using type = std::vector<cl_event>;
125  using value_type = cl_event;
126 };
127 #else
128 template <> struct interop<backend::opencl, event> { using type = cl_event; };
129 template <> struct BackendInput<backend::opencl, event> {
130  using type = cl_event;
131 };
132 template <> struct BackendReturn<backend::opencl, event> {
133  using type = cl_event;
134 };
135 #endif
136 
137 template <> struct BackendInput<backend::opencl, queue> {
138  using type = cl_command_queue;
139 };
140 
141 template <> struct BackendReturn<backend::opencl, queue> {
142  using type = cl_command_queue;
143 };
144 
145 template <> struct BackendInput<backend::opencl, platform> {
146  using type = cl_platform_id;
147 };
148 
149 template <> struct BackendReturn<backend::opencl, platform> {
150  using type = cl_platform_id;
151 };
152 
153 #ifdef __SYCL_INTERNAL_API
154 template <> struct BackendInput<backend::opencl, program> {
155  using type = cl_program;
156 };
157 
158 template <> struct BackendReturn<backend::opencl, program> {
159  using type = cl_program;
160 };
161 #endif
162 
163 template <bundle_state State>
165  using type = cl_program;
166 };
167 
168 template <bundle_state State>
170  using type = std::vector<cl_program>;
171 };
172 
173 template <> struct BackendInput<backend::opencl, kernel> {
174  using type = cl_kernel;
175 };
176 
177 template <> struct BackendReturn<backend::opencl, kernel> {
178  using type = cl_kernel;
179 };
180 
182  static constexpr bool MakePlatform = true;
183  static constexpr bool MakeDevice = true;
184  static constexpr bool MakeContext = true;
185  static constexpr bool MakeQueue = true;
186  static constexpr bool MakeEvent = true;
187  static constexpr bool MakeBuffer = true;
188  static constexpr bool MakeKernel = true;
189  static constexpr bool MakeKernelBundle = true;
190 };
191 } // namespace detail
192 } // namespace sycl
193 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::backend
backend
Definition: backend_types.hpp:21
cl::sycl::detail::BackendReturn< backend::opencl, buffer< DataT, Dimensions, AllocatorT > >::type
cl_mem type
Definition: backend_traits_opencl.hpp:94
cl::sycl::detail::BackendInput< backend::opencl, buffer< DataT, Dimensions, AllocatorT > >::type
cl_mem type
Definition: backend_traits_opencl.hpp:83
cl::sycl::kernel_bundle
The kernel_bundle class represents collection of device images in a particular state.
Definition: kernel.hpp:28
cl::sycl::event
An event object can be used to synchronize memory transfers, enqueues of kernels and signaling barrie...
Definition: event.hpp:31
cl::sycl::detail::BackendInput< backend::opencl, event >::type
cl_event type
Definition: backend_traits_opencl.hpp:130
cl::sycl::detail::BackendReturn< backend::opencl, kernel >::type
cl_kernel type
Definition: backend_traits_opencl.hpp:178
cl::sycl::backend::opencl
@ opencl
device.hpp
context.hpp
cl::sycl::detail::BackendInput< backend::opencl, kernel >::type
cl_kernel type
Definition: backend_traits_opencl.hpp:174
event.hpp
cl::sycl::detail::BackendInput< backend::opencl, queue >::type
cl_command_queue type
Definition: backend_traits_opencl.hpp:138
cl::sycl::detail::interop< backend::opencl, event >::type
cl_event type
Definition: backend_traits_opencl.hpp:128
sycl
Definition: invoke_simd.hpp:68
cl::sycl::detail::BackendReturn< backend::opencl, platform >::type
cl_platform_id type
Definition: backend_traits_opencl.hpp:150
cl::sycl::detail::interop< backend::opencl, accessor< DataT, Dimensions, AccessMode, access::target::device, access::placeholder::false_t > >::type
cl_mem type
Definition: backend_traits_opencl.hpp:64
cl::sycl::queue
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:103
cl::sycl::buffer
Defines a shared array that can be used by kernels in queues.
Definition: buffer.hpp:58
backend_traits.hpp
cl::sycl::detail::BackendReturn< backend::opencl, queue >::type
cl_command_queue type
Definition: backend_traits_opencl.hpp:142
cl::sycl::detail::interop< backend::opencl, device >::type
cl_device_id type
Definition: backend_traits_opencl.hpp:41
cl::sycl::detail::BackendInput< backend::opencl, kernel_bundle< State > >::type
cl_program type
Definition: backend_traits_opencl.hpp:165
cl::sycl::detail::BackendReturn< backend::opencl, context >::type
cl_context type
Definition: backend_traits_opencl.hpp:103
cl::sycl::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:35
kernel_bundle.hpp
cl::sycl::detail::InteropFeatureSupportMap
Definition: backend_traits.hpp:24
cl::sycl::detail::interop< backend::opencl, platform >::type
cl_platform_id type
Definition: backend_traits_opencl.hpp:49
cl::sycl::detail::BackendInput< backend::opencl, platform >::type
cl_platform_id type
Definition: backend_traits_opencl.hpp:146
cl::sycl::detail::interop< backend::opencl, context >::type
cl_context type
Definition: backend_traits_opencl.hpp:37
cl::sycl::detail::BackendReturn< backend::opencl, device >::type
cl_device_id type
Definition: backend_traits_opencl.hpp:111
cl::sycl::accessor
Buffer accessor.
Definition: accessor.hpp:223
defines.hpp
cl::sycl::detail::interop< backend::opencl, accessor< DataT, Dimensions, AccessMode, access::target::image, access::placeholder::false_t > >::type
cl_mem type
Definition: backend_traits_opencl.hpp:78
cl::sycl::detail::BackendInput< backend::opencl, context >::type
cl_context type
Definition: backend_traits_opencl.hpp:99
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::detail::interop< backend::opencl, queue >::type
cl_command_queue type
Definition: backend_traits_opencl.hpp:45
queue.hpp
cl::sycl::detail::interop
Definition: backend_traits.hpp:18
accessor.hpp
cl::sycl::detail::BackendInput< backend::opencl, device >::type
cl_device_id type
Definition: backend_traits_opencl.hpp:107
cl::sycl::detail::BackendReturn< backend::opencl, kernel_bundle< State > >::type
std::vector< cl_program > type
Definition: backend_traits_opencl.hpp:170
cl::sycl::info::event
event
Definition: info_desc.hpp:289
cl::sycl::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:71
cl::sycl::platform
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:34
cl::sycl::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:35
cl::sycl::kernel
Provides an abstraction of a SYCL kernel.
Definition: kernel.hpp:67
cl::sycl::detail::BackendReturn< backend::opencl, event >::type
cl_event type
Definition: backend_traits_opencl.hpp:133
cl::sycl::detail::BackendReturn
Definition: backend_traits.hpp:22
cl::sycl::detail::BackendInput
Definition: backend_traits.hpp:20
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12