triSYCL implementation of OpenCL SYCL
handler.hpp
Go to the documentation of this file.
1 #ifndef TRISYCL_SYCL_HANDLER_HPP
2 #define TRISYCL_SYCL_HANDLER_HPP
3 
4 /** \file The OpenCL SYCL command group handler
5 
6  Ronan at Keryell point FR
7 
8  This file is distributed under the University of Illinois Open Source
9  License. See LICENSE.TXT for details.
10 */
11 
12 #include "CL/sycl/accessor.hpp"
16 #include "CL/sycl/exception.hpp"
17 
18 namespace cl {
19 namespace sycl {
20 
21 /** \addtogroup execution Platforms, contexts, devices and queues
22  @{
23 */
24 
25 /** Kernel
26 
27  \todo To be implemented
28 */
29 class kernel {
30 };
31 
32 
33 /** Command group handler class
34 
35  A command group handler object can only be constructed by the SYCL runtime.
36 
37  All of the accessors defined in the command group scope take as a
38  parameter an instance of the command group handler and all the kernel
39  invocation functions are methods of this class.
40 */
41 class handler {
42 
43 public:
44 
45  /** Attach the task and accessors to it.
46  */
47  std::shared_ptr<detail::task> current_task;
48 
49 
50  handler() {
51  // Create a new task for this command_group
52  current_task = std::make_shared<detail::task>();
53  }
54 
55 
56  /** Set kernel args for an OpenCL kernel which is used through the
57  SYCL/OpenCL interop interface
58 
59  The index value specifies which parameter of the OpenCL kernel is
60  being set and the accessor object, which OpenCL buffer or image is
61  going to be given as kernel argument.
62 
63  \todo To be implemented
64  */
65  template <typename DataType,
66  std::size_t Dimensions,
67  access::mode Mode,
69  void set_arg(int arg_index,
72  }
73 
74 
75  /** Set kernel args for an OpenCL kernel which is used through the
76  SYCL/OpenCL interoperability interface
77 
78  The index value specifies which parameter of the OpenCL kernel is
79  being set and the accessor object, which OpenCL buffer or image is
80  going to be given as kernel argument.
81 
82  \todo To be implemented
83  */
84  template <typename T>
85  void set_arg(int arg_index, T scalar_value) {
87  }
88 
89 
90  /** Kernel invocation method of a kernel defined as a lambda or
91  functor. If it is a lambda function or the functor type is globally
92  visible there is no need for the developer to provide a kernel name type
93  (typename KernelName) for it, as described in 3.5.3
94 
95  SYCL single_task launches a computation without parallelism at
96  launch time.
97 
98  \param F specify the kernel to be launched as a single_task
99 
100  \param KernelName is a class type that defines the name to be used for
101  the underlying kernel
102  */
103  template <typename KernelName = std::nullptr_t>
104  void single_task(std::function<void(void)> F) {
105  current_task->schedule(F);
106  }
107 
108 
109  /** SYCL parallel_for launches a data parallel computation with
110  parallelism specified at launch time by a range<>
111 
112  Kernel invocation method of a kernel defined as a lambda or functor,
113  for the specified range and given an id or item for indexing in the
114  indexing space defined by range.
115 
116  If it is a lambda function or the if the functor type is globally
117  visible there is no need for the developer to provide a kernel name
118  type (typename KernelName) for it, as described in detail in 3.5.3
119 
120  \param global_size is the full size of the range<>
121 
122  \param N dimensionality of the iteration space
123 
124  \param f is the kernel functor to execute
125 
126  \param KernelName is a class type that defines the name to be used
127  for the underlying kernel
128 
129  Unfortunately, to have implicit conversion to work on the range, the
130  function can not be templated, so instantiate it for all the
131  dimensions
132  */
133 #define TRISYCL_parallel_for_functor_GLOBAL(N) \
134  template <typename KernelName = std::nullptr_t, \
135  typename ParallelForFunctor> \
136  void parallel_for(range<N> global_size, \
137  ParallelForFunctor f) { \
138  current_task->schedule([=] { detail::parallel_for(global_size, f); }); \
139  }
140 
144 
145 
146  /** Kernel invocation method of a kernel defined as a lambda or functor,
147  for the specified range and offset and given an id or item for
148  indexing in the indexing space defined by range
149 
150  If it is a lambda function or the if the functor type is globally
151  visible there is no need for the developer to provide a kernel name
152  type (typename KernelName) for it, as described in detail in 3.5.3
153 
154  \param global_size is the global size of the range<>
155 
156  \param offset is the offset to be add to the id<> during iteration
157 
158  \param f is the kernel functor to execute
159 
160  \param ParallelForFunctor is the kernel functor type
161 
162  \param KernelName is a class type that defines the name to be used for
163  the underlying kernel
164 
165  Unfortunately, to have implicit conversion to work on the range, the
166  function can not be templated, so instantiate it for all the
167  dimensions
168  */
169 #define TRISYCL_ParallelForFunctor_GLOBAL_OFFSET(N) \
170  template <typename KernelName = std::nullptr_t, \
171  typename ParallelForFunctor> \
172  void parallel_for(range<N> global_size, \
173  id<N> offset, \
174  ParallelForFunctor f) { \
175  current_task->schedule([=] { \
176  detail::parallel_for_global_offset(global_size, \
177  offset, \
178  f); }); \
179  }
180 
184 
185 
186  /** Kernel invocation method of a kernel defined as a lambda or functor,
187  for the specified nd_range and given an nd_item for indexing in the
188  indexing space defined by the nd_range
189 
190  If it is a lambda function or the if the functor type is globally
191  visible there is no need for the developer to provide a kernel name
192  type (typename KernelName) for it, as described in detail in 3.5.3
193 
194  \param r defines the iteration space with the work-group layout and
195  offset
196 
197  \param Dimensions dimensionality of the iteration space
198 
199  \param f is the kernel functor to execute
200 
201  \param ParallelForFunctor is the kernel functor type
202 
203  \param KernelName is a class type that defines the name to be used for
204  the underlying kernel
205  */
206  template <typename KernelName,
207  std::size_t Dimensions,
208  typename ParallelForFunctor>
209  void parallel_for(nd_range<Dimensions> r, ParallelForFunctor f) {
210  current_task->schedule([=] { detail::parallel_for(r, f); });
211  }
212 
213 
214  /** Hierarchical kernel invocation method of a kernel defined as a
215  lambda encoding the body of each work-group to launch
216 
217  May contain multiple kernel built-in parallel_for_work_item
218  functions representing the execution on each work-item.
219 
220  Launch num_work_groups work-groups of runtime-defined
221  size. Described in detail in 3.5.3.
222 
223  \param r defines the iteration space with the work-group layout and
224  offset
225 
226  \param Dimensions dimensionality of the iteration space
227 
228  \param f is the kernel functor to execute
229 
230  \param ParallelForFunctor is the kernel functor type
231 
232  \param KernelName is a class type that defines the name to be used for
233  the underlying kernel
234  */
235  template <typename KernelName = std::nullptr_t,
236  std::size_t Dimensions = 1,
237  typename ParallelForFunctor>
239  ParallelForFunctor f) {
240  current_task->schedule([=] { detail::parallel_for_workgroup(r, f); });
241  }
242 
243 
244  /** Kernel invocation method of a kernel defined as pointer to a kernel
245  object, described in detail in 3.5.3
246 
247  \todo To be implemented
248  */
249  void single_task(kernel syclKernel) {
251  }
252 
253 
254  /** Kernel invocation method of a kernel defined as pointer to a kernel
255  object, for the specified range and given an id or item for indexing
256  in the indexing space defined by range, described in detail in 3.5.3
257 
258  \todo To be implemented
259  */
260  template <std::size_t Dimensions = 1>
261  void parallel_for(range<Dimensions> numWorkItems,
262  kernel sycl_kernel) {
264  }
265 
266 
267  /** Kernel invocation method of a kernel defined as pointer to a kernel
268  object, for the specified nd_range and given an nd_item for indexing
269  in the indexing space defined by the nd_range, described in detail
270  in 3.5.3
271 
272  \todo To be implemented
273  */
274  template <std::size_t Dimensions = 1>
277  }
278 
279 };
280 
281 /// @} End the error_handling Doxygen group
282 
283 }
284 }
285 
286 /*
287  # Some Emacs stuff:
288  ### Local Variables:
289  ### ispell-local-dictionary: "american"
290  ### eval: (flyspell-prog-mode)
291  ### End:
292 */
293 
294 #endif // TRISYCL_SYCL_HANDLER_HPP
void single_task(kernel syclKernel)
Kernel invocation method of a kernel defined as pointer to a kernel object, described in detail in 3...
Definition: handler.hpp:249
The vector type to be used as SYCL vector.
Definition: access.hpp:13
std::shared_ptr< detail::task > current_task
Attach the task and accessors to it.
Definition: handler.hpp:47
#define TRISYCL_ParallelForFunctor_GLOBAL_OFFSET(N)
void set_arg(int arg_index, accessor< DataType, Dimensions, Mode, Target > acc_obj)
Set kernel args for an OpenCL kernel which is used through the SYCL/OpenCL interop interface...
Definition: handler.hpp:69
void unimplemented()
Display an "unimplemented" message.
The accessor abstracts the way buffer data are accessed inside a kernel in a multidimensional variabl...
Definition: accessor.hpp:38
A ND-range, made by a global and local range, to specify work-group and work-item organization...
Definition: nd_range.hpp:33
void parallel_for_work_group(nd_range< Dimensions > r, ParallelForFunctor f)
Hierarchical kernel invocation method of a kernel defined as a lambda encoding the body of each work-...
Definition: handler.hpp:238
Kernel.
Definition: handler.hpp:29
Implement the detail of the parallel constructions to launch kernels.
A SYCL range defines a multi-dimensional index range that can be used to define launch parallel compu...
Definition: range.hpp:31
Command group handler class.
Definition: handler.hpp:41
TRISYCL_parallel_for_functor_GLOBAL(1) TRISYCL_parallel_for_functor_GLOBAL(2) TRISYCL_parallel_for_functor_GLOBAL(3) TRISYCL_ParallelForFunctor_GLOBAL_OFFSET(1) TRISYCL_ParallelForFunctor_GLOBAL_OFFSET(2) TRISYCL_ParallelForFunctor_GLOBAL_OFFSET(3) template< typename KernelName
Kernel invocation method of a kernel defined as a lambda or functor, for the specified range and offs...
std::size_t Dimensions
Definition: handler.hpp:207
void set_arg(int arg_index, T scalar_value)
Set kernel args for an OpenCL kernel which is used through the SYCL/OpenCL interoperability interface...
Definition: handler.hpp:85
std::size_t ParallelForFunctor void parallel_for(nd_range< Dimensions > r, ParallelForFunctor f)
Definition: handler.hpp:209
target
The target enumeration describes the type of object to be accessed via the accessor.
Definition: access.hpp:46
void parallel_for(range< Dimensions > numWorkItems, kernel sycl_kernel)
Kernel invocation method of a kernel defined as pointer to a kernel object, for the specified range a...
Definition: handler.hpp:261
void parallel_for_workgroup(nd_range< Dimensions > r, ParallelForFunctor f)
Implement the loop on the work-groups.
mode
This describes the type of the access mode to be used via accessor.
Definition: access.hpp:33
void parallel_for(nd_range< Dimensions >, kernel syclKernel)
Kernel invocation method of a kernel defined as pointer to a kernel object, for the specified nd_rang...
Definition: handler.hpp:275
void single_task(std::function< void(void)> F)
Kernel invocation method of a kernel defined as a lambda or functor.
Definition: handler.hpp:104
void parallel_for(range< Dimensions > r, ParallelForFunctor f)
Implementation of a data parallel computation with parallelism specified at launch time by a range<>...