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/backend_types.hpp> // for backend
19 #include <sycl/context.hpp> // for context
20 #include <sycl/detail/backend_traits.hpp> // for BackendInput, BackendReturn
21 #include <sycl/detail/cl.h> // for _cl_event, cl_event, cl_de...
22 #include <sycl/detail/pi.hpp> // for assertion, PiDevice, PiPro...
23 #include <sycl/device.hpp> // for device
24 #include <sycl/event.hpp> // for event
25 #include <sycl/handler.hpp> // for buffer
26 #include <sycl/kernel.hpp> // for kernel
27 #include <sycl/kernel_bundle.hpp> // for kernel_bundle
28 #include <sycl/kernel_bundle_enums.hpp> // for bundle_state
29 #include <sycl/platform.hpp> // for platform
30 #include <sycl/queue.hpp> // for queue
31 
32 #include <vector> // for vector
33 
34 namespace sycl {
35 inline namespace _V1 {
36 namespace detail {
37 
38 // TODO the interops for context, device, event, platform and program
39 // may be removed after removing the deprecated 'get_native()' methods
40 // from the corresponding classes.
41 template <> struct interop<backend::opencl, context> {
42  using type = cl_context;
43 };
44 
45 template <> struct interop<backend::opencl, device> {
46  using type = cl_device_id;
47 };
48 
49 template <> struct interop<backend::opencl, queue> {
50  using type = cl_command_queue;
51 };
52 
53 template <> struct interop<backend::opencl, platform> {
54  using type = cl_platform_id;
55 };
56 
57 template <typename DataT, int Dimensions, typename AllocatorT>
58 struct BackendInput<backend::opencl, buffer<DataT, Dimensions, AllocatorT>> {
59  using type = cl_mem;
60 };
61 
62 template <typename DataT, int Dimensions, typename AllocatorT>
63 struct BackendReturn<backend::opencl, buffer<DataT, Dimensions, AllocatorT>> {
64  using type = std::vector<cl_mem>;
65 };
66 
67 template <> struct BackendInput<backend::opencl, context> {
68  using type = cl_context;
69 };
70 
71 template <> struct BackendReturn<backend::opencl, context> {
72  using type = cl_context;
73 };
74 
75 template <> struct BackendInput<backend::opencl, device> {
76  using type = cl_device_id;
77 };
78 
79 template <> struct BackendReturn<backend::opencl, device> {
80  using type = cl_device_id;
81 };
82 
83 template <> struct interop<backend::opencl, event> {
84  using type = std::vector<cl_event>;
85  using value_type = cl_event;
86 };
87 template <> struct BackendInput<backend::opencl, event> {
88  using type = std::vector<cl_event>;
89  using value_type = cl_event;
90 };
91 template <> struct BackendReturn<backend::opencl, event> {
92  using type = std::vector<cl_event>;
93  using value_type = cl_event;
94 };
95 
96 template <> struct BackendInput<backend::opencl, queue> {
97  using type = cl_command_queue;
98 };
99 
100 template <> struct BackendReturn<backend::opencl, queue> {
101  using type = cl_command_queue;
102 };
103 
104 template <> struct BackendInput<backend::opencl, platform> {
105  using type = cl_platform_id;
106 };
107 
108 template <> struct BackendReturn<backend::opencl, platform> {
109  using type = cl_platform_id;
110 };
111 
112 template <bundle_state State>
114  using type = cl_program;
115 };
116 
117 template <bundle_state State>
119  using type = std::vector<cl_program>;
120 };
121 
122 template <> struct BackendInput<backend::opencl, kernel> {
123  using type = cl_kernel;
124 };
125 
126 template <> struct BackendReturn<backend::opencl, kernel> {
127  using type = cl_kernel;
128 };
129 
131  static constexpr bool MakePlatform = true;
132  static constexpr bool MakeDevice = true;
133  static constexpr bool MakeContext = true;
134  static constexpr bool MakeQueue = true;
135  static constexpr bool MakeEvent = true;
136  static constexpr bool MakeBuffer = true;
137  static constexpr bool MakeKernel = true;
138  static constexpr bool MakeKernelBundle = true;
139  static constexpr bool MakeImage = false;
140 };
141 
142 namespace pi {
143 // Cast for std::vector<cl_event>, according to the spec, make_event
144 // should create one(?) event from a vector of cl_event
145 template <class To> inline To cast(std::vector<cl_event> value) {
147  value.size() == 1,
148  "Temporary workaround requires that the "
149  "size of the input vector for make_event be equal to one.");
150  return cast<To>(value[0]);
151 }
152 
153 // These conversions should use PI interop API.
154 template <>
155 inline PiProgram
156  cast(cl_program) = delete; // Use piextCreateProgramWithNativeHandle
157 
158 template <>
159 inline PiDevice
160  cast(cl_device_id) = delete; // Use piextCreateDeviceWithNativeHandle
161 } // namespace pi
162 } // namespace detail
163 } // namespace _V1
164 } // namespace sycl
sycl::_V1::detail::BackendInput< backend::opencl, device >::type
cl_device_id type
Definition: backend_traits_opencl.hpp:76
sycl::_V1::detail::BackendReturn< backend::opencl, context >::type
cl_context type
Definition: backend_traits_opencl.hpp:72
queue.hpp
sycl::_V1::backend
backend
Definition: backend_types.hpp:18
sycl::_V1::detail::BackendReturn< backend::opencl, kernel >::type
cl_kernel type
Definition: backend_traits_opencl.hpp:127
sycl::_V1::detail::BackendReturn< backend::opencl, event >::type
std::vector< cl_event > type
Definition: backend_traits_opencl.hpp:92
sycl::_V1::buffer
Defines a shared array that can be used by kernels in queues.
Definition: buffer.hpp:60
sycl::_V1::detail::interop< backend::opencl, context >::type
cl_context type
Definition: backend_traits_opencl.hpp:42
event.hpp
sycl::_V1::detail::interop< backend::opencl, platform >::type
cl_platform_id type
Definition: backend_traits_opencl.hpp:54
sycl::_V1::detail::InteropFeatureSupportMap::MakeEvent
static constexpr bool MakeEvent
Definition: backend_traits.hpp:28
sycl::_V1::detail::pi::PiDevice
::pi_device PiDevice
Definition: pi.hpp:131
sycl::_V1::detail::interop< backend::opencl, event >::value_type
cl_event value_type
Definition: backend_traits_opencl.hpp:85
detail
---— Error handling, matching OpenCL plugin semantics.
Definition: common.hpp:44
sycl
Definition: access.hpp:18
sycl::_V1::event
An event object can be used to synchronize memory transfers, enqueues of kernels and signaling barrie...
Definition: event.hpp:44
sycl::_V1::detail::InteropFeatureSupportMap::MakeQueue
static constexpr bool MakeQueue
Definition: backend_traits.hpp:27
pi.hpp
sycl::_V1::detail::interop< backend::opencl, event >::type
std::vector< cl_event > type
Definition: backend_traits_opencl.hpp:84
backend_traits.hpp
sycl::_V1::detail::BackendInput
Definition: backend_traits.hpp:19
sycl::_V1::detail::InteropFeatureSupportMap
Definition: backend_traits.hpp:23
sycl::_V1::detail::BackendInput< backend::opencl, kernel_bundle< State > >::type
cl_program type
Definition: backend_traits_opencl.hpp:114
sycl::_V1::kernel
Provides an abstraction of a SYCL kernel.
Definition: kernel.hpp:74
sycl::_V1::detail::BackendReturn< backend::opencl, buffer< DataT, Dimensions, AllocatorT > >::type
std::vector< cl_mem > type
Definition: backend_traits_opencl.hpp:64
sycl::_V1::detail::InteropFeatureSupportMap::MakeImage
static constexpr bool MakeImage
Definition: backend_traits.hpp:32
sycl::_V1::detail::InteropFeatureSupportMap::MakeBuffer
static constexpr bool MakeBuffer
Definition: backend_traits.hpp:29
sycl::_V1::detail::interop
Definition: backend_traits.hpp:17
sycl::_V1::detail::BackendReturn< backend::opencl, platform >::type
cl_platform_id type
Definition: backend_traits_opencl.hpp:109
kernel_bundle.hpp
cl.h
sycl::_V1::queue
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:119
kernel_bundle_enums.hpp
sycl::_V1::detail::BackendReturn< backend::opencl, kernel_bundle< State > >::type
std::vector< cl_program > type
Definition: backend_traits_opencl.hpp:119
sycl::_V1::detail::InteropFeatureSupportMap::MakeContext
static constexpr bool MakeContext
Definition: backend_traits.hpp:26
sycl::_V1::detail::pi::PiProgram
::pi_program PiProgram
Definition: pi.hpp:137
sycl::_V1::kernel_bundle
The kernel_bundle class represents collection of device images in a particular state.
Definition: kernel.hpp:32
sycl::_V1::detail::interop< backend::opencl, queue >::type
cl_command_queue type
Definition: backend_traits_opencl.hpp:50
sycl::_V1::detail::InteropFeatureSupportMap::MakeDevice
static constexpr bool MakeDevice
Definition: backend_traits.hpp:25
sycl::_V1::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:59
sycl::_V1::detail::interop< backend::opencl, device >::type
cl_device_id type
Definition: backend_traits_opencl.hpp:46
device.hpp
sycl::_V1::detail::BackendInput< backend::opencl, event >::type
std::vector< cl_event > type
Definition: backend_traits_opencl.hpp:88
sycl::_V1::detail::InteropFeatureSupportMap::MakePlatform
static constexpr bool MakePlatform
Definition: backend_traits.hpp:24
sycl::_V1::detail::InteropFeatureSupportMap::MakeKernelBundle
static constexpr bool MakeKernelBundle
Definition: backend_traits.hpp:31
sycl::_V1::detail::pi::cast
PiProgram cast(cl_program)=delete
sycl::_V1::detail::BackendReturn
Definition: backend_traits.hpp:21
sycl::_V1::detail::BackendReturn< backend::opencl, device >::type
cl_device_id type
Definition: backend_traits_opencl.hpp:80
sycl::_V1::backend::opencl
@ opencl
sycl::_V1::detail::InteropFeatureSupportMap::MakeKernel
static constexpr bool MakeKernel
Definition: backend_traits.hpp:30
backend_types.hpp
handler.hpp
sycl::_V1::detail::BackendReturn< backend::opencl, event >::value_type
cl_event value_type
Definition: backend_traits_opencl.hpp:93
sycl::_V1::detail::BackendInput< backend::opencl, platform >::type
cl_platform_id type
Definition: backend_traits_opencl.hpp:105
sycl::_V1::detail::pi::assertion
void assertion(bool Condition, const char *Message=nullptr)
Definition: pi.cpp:579
context.hpp
platform.hpp
sycl::_V1::platform
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:63
sycl::_V1::detail::BackendInput< backend::opencl, event >::value_type
cl_event value_type
Definition: backend_traits_opencl.hpp:89
sycl::_V1::detail::BackendInput< backend::opencl, buffer< DataT, Dimensions, AllocatorT > >::type
cl_mem type
Definition: backend_traits_opencl.hpp:59
kernel.hpp
sycl::_V1::detail::BackendInput< backend::opencl, queue >::type
cl_command_queue type
Definition: backend_traits_opencl.hpp:97
sycl::_V1::detail::BackendInput< backend::opencl, context >::type
cl_context type
Definition: backend_traits_opencl.hpp:68
sycl::_V1::detail::BackendReturn< backend::opencl, queue >::type
cl_command_queue type
Definition: backend_traits_opencl.hpp:101
sycl::_V1::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:51
sycl::_V1::detail::BackendInput< backend::opencl, kernel >::type
cl_kernel type
Definition: backend_traits_opencl.hpp:123