CLOGS
C++ library for sorting and searching in OpenCL applications
scan.h
Go to the documentation of this file.
1 /* Copyright (c) 2012, 2014 University of Cape Town
2  * Copyright (c) 2014, 2015 Bruce Merry
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22 
29 #ifndef CLOGS_SCAN_H
30 #define CLOGS_SCAN_H
31 
32 #include <clogs/visibility_push.h>
33 #include <CL/cl.hpp>
34 #include <cstddef>
35 #include <clogs/visibility_pop.h>
36 
37 #include <clogs/core.h>
38 #include <clogs/platform.h>
39 #include <clogs/tune.h>
40 
41 namespace clogs
42 {
43 
44 class ScanProblem;
45 
46 namespace detail
47 {
48  class ScanProblem;
49  class Scan;
50 
51  const ScanProblem &getDetail(const clogs::ScanProblem &);
52 } // namespace detail
53 
58 class CLOGS_API ScanProblem
59 {
60 private:
61  detail::ScanProblem *detail_;
62  friend const detail::ScanProblem &detail::getDetail(const clogs::ScanProblem &);
63 
64 public:
65  ScanProblem();
66  ~ScanProblem();
67  ScanProblem(const ScanProblem &);
68  ScanProblem &operator=(const ScanProblem &);
69 
76  void setType(const Type &type);
77 
81  void setTunePolicy(const TunePolicy &tunePolicy);
82 };
83 
98 class CLOGS_API Scan : public Algorithm
99 {
100 private:
101  detail::Scan *getDetail() const;
102  detail::Scan *getDetailNonNull() const;
103  void construct(cl_context context, cl_device_id device, const ScanProblem &problem,
104  cl_int &err, const char *&errStr);
105  friend void swap(Scan &, Scan &);
106 
107 protected:
108  void enqueue(cl_command_queue commandQueue,
109  cl_mem inBuffer,
110  cl_mem outBuffer,
111  ::size_t elements,
112  const void *offset,
113  cl_uint numEvents,
114  const cl_event *events,
115  cl_event *event,
116  cl_int &err,
117  const char *&errStr);
118 
119 
120  void enqueue(cl_command_queue commandQueue,
121  cl_mem inBuffer,
122  cl_mem outBuffer,
123  ::size_t elements,
124  cl_mem offsetBuffer,
125  cl_uint offsetIndex,
126  cl_uint numEvents,
127  const cl_event *events,
128  cl_event *event,
129  cl_int &err,
130  const char *&errStr);
131 
132  void moveAssign(Scan &other);
133 
134 public:
138  Scan();
139 
140 #ifdef CLOGS_HAVE_RVALUE_REFERENCES
141  Scan(Scan &&other) CLOGS_NOEXCEPT
142  {
143  moveConstruct(other);
144  }
145 
146  Scan &operator=(Scan &&other) CLOGS_NOEXCEPT
147  {
148  moveAssign(other);
149  return *this;
150  }
151 #endif
152 
166  Scan(const cl::Context &context, const cl::Device &device, const Type &type)
167  {
168  cl_int err;
169  const char *errStr;
170  ScanProblem problem;
171  problem.setType(type);
172  construct(context(), device(), problem, err, errStr);
173  detail::handleError(err, errStr);
174  }
175 
186  Scan(const cl::Context &context, const cl::Device &device, const ScanProblem &problem)
187  {
188  cl_int err;
189  const char *errStr;
190  construct(context(), device(), problem, err, errStr);
191  detail::handleError(err, errStr);
192  }
193 
194  ~Scan();
195 
202  void enqueue(const cl::CommandQueue &commandQueue,
203  const cl::Buffer &buffer,
204  ::size_t elements,
205  const void *offset = NULL,
206  const VECTOR_CLASS<cl::Event> *events = NULL,
207  cl::Event *event = NULL)
208  {
209  enqueue(commandQueue, buffer, buffer, elements, offset, events, event);
210  }
211 
240  void enqueue(const cl::CommandQueue &commandQueue,
241  const cl::Buffer &inBuffer,
242  const cl::Buffer &outBuffer,
243  ::size_t elements,
244  const void *offset = NULL,
245  const VECTOR_CLASS<cl::Event> *events = NULL,
246  cl::Event *event = NULL)
247  {
248  cl_event outEvent;
249  cl_int err;
250  const char *errStr;
251  detail::UnwrapArray<cl::Event> events_(events);
252  enqueue(commandQueue(), inBuffer(), outBuffer(), elements, offset,
253  events_.size(), events_.data(),
254  event != NULL ? &outEvent : NULL,
255  err, errStr);
256  detail::handleError(err, errStr);
257  if (event != NULL)
258  *event = outEvent; // steals reference
259  }
260 
262  void enqueue(cl_command_queue commandQueue,
263  cl_mem inBuffer,
264  cl_mem outBuffer,
265  ::size_t elements,
266  const void *offset = NULL,
267  cl_uint numEvents = 0,
268  const cl_event *events = NULL,
269  cl_event *event = NULL)
270  {
271  cl_int err;
272  const char *errStr;
273  enqueue(commandQueue, inBuffer, outBuffer, elements, offset, numEvents, events, event,
274  err, errStr);
275  detail::handleError(err, errStr);
276  }
277 
284  void enqueue(const cl::CommandQueue &commandQueue,
285  const cl::Buffer &buffer,
286  ::size_t elements,
287  const cl::Buffer &offsetBuffer,
288  cl_uint offsetIndex,
289  const VECTOR_CLASS<cl::Event> *events = NULL,
290  cl::Event *event = NULL)
291  {
292  enqueue(commandQueue, buffer, buffer, elements, offsetBuffer, offsetIndex, events, event);
293  }
294 
330  void enqueue(const cl::CommandQueue &commandQueue,
331  const cl::Buffer &inBuffer,
332  const cl::Buffer &outBuffer,
333  ::size_t elements,
334  const cl::Buffer &offsetBuffer,
335  cl_uint offsetIndex,
336  const VECTOR_CLASS<cl::Event> *events = NULL,
337  cl::Event *event = NULL)
338  {
339  cl_event outEvent;
340  cl_int err;
341  const char *errStr;
342  detail::UnwrapArray<cl::Event> events_(events);
343  enqueue(commandQueue(), inBuffer(), outBuffer(), elements,
344  offsetBuffer(), offsetIndex,
345  events_.size(), events_.data(),
346  event != NULL ? &outEvent : NULL,
347  err, errStr);
348  detail::handleError(err, errStr);
349  if (event != NULL)
350  *event = outEvent; // steals reference
351  }
352 
354  void enqueue(cl_command_queue commandQueue,
355  cl_mem inBuffer,
356  cl_mem outBuffer,
357  ::size_t elements,
358  cl_mem offsetBuffer,
359  cl_uint offsetIndex,
360  cl_uint numEvents = 0,
361  const cl_event *events = NULL,
362  cl_event *event = NULL)
363  {
364  cl_int err;
365  const char *errStr;
366  enqueue(commandQueue, inBuffer, outBuffer, elements, offsetBuffer, offsetIndex,
367  numEvents, events, event, err, errStr);
368  detail::handleError(err, errStr);
369  }
370 };
371 
372 void swap(Scan &a, Scan &b);
373 
374 } // namespace clogs
375 
376 #endif /* !CLOGS_SCAN_H */
void setType(const Type &type)
Set the element type for the scan.
Scan(const cl::Context &context, const cl::Device &device, const ScanProblem &problem)
Constructor.
Definition: scan.h:186
Pops default visibility if appropriate.
void enqueue(const cl::CommandQueue &commandQueue, const cl::Buffer &buffer,::size_t elements, const void *offset=NULL, const VECTOR_CLASS< cl::Event > *events=NULL, cl::Event *event=NULL)
Enqueue a scan operation on a command queue (in-place).
Definition: scan.h:202
Pushes default visibility if appropriate.
Encapsulation of an OpenCL built-in type that can be stored in a buffer.
Definition: core.h:134
void enqueue(const cl::CommandQueue &commandQueue, const cl::Buffer &buffer,::size_t elements, const cl::Buffer &offsetBuffer, cl_uint offsetIndex, const VECTOR_CLASS< cl::Event > *events=NULL, cl::Event *event=NULL)
Enqueue a scan operation on a command queue, with an offset in a buffer (in-place).
Definition: scan.h:284
Basic types shared by several primitives.
Creates an array of handles from a vector of wrappers.
Definition: core.h:198
Detects compiler properties.
Scan(const cl::Context &context, const cl::Device &device, const Type &type)
Constructor.
Definition: scan.h:166
Encapsulates the specifics of a scan problem.
Definition: scan.h:58
void enqueue(cl_command_queue commandQueue, cl_mem inBuffer, cl_mem outBuffer,::size_t elements, cl_mem offsetBuffer, cl_uint offsetIndex, cl_uint numEvents=0, const cl_event *events=NULL, cl_event *event=NULL)
Definition: scan.h:354
Exclusive scan (prefix sum) primitive.
Definition: scan.h:98
void enqueue(cl_command_queue commandQueue, cl_mem inBuffer, cl_mem outBuffer,::size_t elements, const void *offset=NULL, cl_uint numEvents=0, const cl_event *events=NULL, cl_event *event=NULL)
Definition: scan.h:262
Definition: tune.h:55
void enqueue(const cl::CommandQueue &commandQueue, const cl::Buffer &inBuffer, const cl::Buffer &outBuffer,::size_t elements, const cl::Buffer &offsetBuffer, cl_uint offsetIndex, const VECTOR_CLASS< cl::Event > *events=NULL, cl::Event *event=NULL)
Enqueue a scan operation on a command queue, with an offset in a buffer.
Definition: scan.h:330
Base class for all algorithm classes.
Definition: core.h:305
OpenCL primitives.
Definition: clogs.h:56
Control over tuning policy.
void enqueue(const cl::CommandQueue &commandQueue, const cl::Buffer &inBuffer, const cl::Buffer &outBuffer,::size_t elements, const void *offset=NULL, const VECTOR_CLASS< cl::Event > *events=NULL, cl::Event *event=NULL)
Enqueue a scan operation on a command queue.
Definition: scan.h:240