vSMC
vSMC: Scalable Monte Carlo
cl_manager.hpp
Go to the documentation of this file.
1 //============================================================================
2 // vSMC/include/vsmc/opencl/cl_manager.hpp
3 //----------------------------------------------------------------------------
4 // vSMC: Scalable Monte Carlo
5 //----------------------------------------------------------------------------
6 // Copyright (c) 2013,2014, Yan Zhou
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // Redistributions of source code must retain the above copyright notice,
13 // this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright notice,
16 // this list of conditions and the following disclaimer in the documentation
17 // and/or other materials provided with the distribution.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 // POSSIBILITY OF SUCH DAMAGE.
30 //============================================================================
31 
32 #ifndef VSMC_OPENCL_CL_MANAGER_HPP
33 #define VSMC_OPENCL_CL_MANAGER_HPP
34 
35 #include <vsmc/internal/common.hpp>
36 #include <vsmc/opencl/cl_setup.hpp>
37 #include <vsmc/opencl/cl_manip.hpp>
38 #include <vsmc/opencl/cl_query.hpp>
41 
42 #define VSMC_RUNTIME_ASSERT_OPENCL_CL_MANAGER_SETUP(func) \
43  VSMC_RUNTIME_ASSERT((setup()), \
44  ("**CLManager::"#func"** CAN ONLY BE CALLED AFTER TRUE " \
45  "**CLManager::setup**"));
46 
47 #define VSMC_RUNTIME_WARNING_OPENCL_CL_MANAGER_SETUP_PLATFORM \
48  VSMC_RUNTIME_WARNING(setup_platform, \
49  ("**CLManager::setup** FAILED TO SETUP A PLATFORM"));
50 
51 #define VSMC_RUNTIME_WARNING_OPENCL_CL_MANAGER_SETUP_CONTEXT \
52  VSMC_RUNTIME_WARNING(setup_context, \
53  ("**CLManager::setup** FAILED TO SETUP A CONTEXT"));
54 
55 #define VSMC_RUNTIME_WARNING_OPENCL_CL_MANAGER_SETUP_DEVICE \
56  VSMC_RUNTIME_WARNING(setup_device, \
57  ("**CLManager::setup** FAILED TO SETUP A DEVICE"));
58 
59 #define VSMC_RUNTIME_WARNING_OPENCL_CL_MANAGER_SETUP_COMMAND_QUEUE \
60  VSMC_RUNTIME_WARNING(setup_command_queue, \
61  ("**CLManager::setup** FAILED TO SETUP A COMMAND_QUEUE"));
62 
63 #define VSMC_RUNTIME_WARNING_OPENCL_CL_MANAGER_BLOCK(func, block, event) \
64  VSMC_RUNTIME_WARNING((block || event != VSMC_NULLPTR), \
65  ("**CLManager::"#func" NOT BLOCKING BUT WITH NULL EVENT"))
66 
67 namespace vsmc {
68 
128 template <typename ID = CLDefault>
130 {
131  public :
132 
133  typedef ID cl_id;
134 
137  {
138  static CLManager<ID> manager;
139 
140  return manager;
141  }
142 
147  int opencl_version () const {return opencl_version_;}
148 
153  int opencl_c_version () const {return opencl_c_version_;}
154 
156  const ::cl::Platform &platform () const {return platform_;}
157 
159  const ::cl::Context &context () const {return context_;}
160 
162  const ::cl::Device &device () const {return device_;}
163 
165  const std::vector< ::cl::Device> &device_vec () const {return device_vec_;}
166 
168  const ::cl::CommandQueue &command_queue () const {return command_queue_;}
169 
172  bool setup () const {return setup_;}
173 
176  bool setup (::cl_device_type dev)
177  {
178  setup_ = false;
179  setup_cl_manager(dev);
180 
181  return setup_;
182  }
183 
189  bool setup (const ::cl::Platform &plat, const ::cl::Context &ctx,
190  const ::cl::Device &dev, const ::cl::CommandQueue &cmd)
191  {
192  setup_ = false;
193  platform_ = plat;
194  context_ = ctx;
195  device_ = dev;
196  device_vec_ = context_.getInfo<CL_CONTEXT_DEVICES>();
197  command_queue_ = cmd;
198  check_opencl_version();
199  setup_ = true;
200 
201  return setup_;
202  }
203 
205  template <typename CLType>
206  ::cl::Buffer create_buffer (std::size_t num,
207  ::cl_mem_flags flag = CL_MEM_READ_WRITE,
208  void *host_ptr = VSMC_NULLPTR) const
209  {
211 
212  if (num == 0)
213  return ::cl::Buffer();
214 
215  return ::cl::Buffer(context_, flag, sizeof(CLType) * num, host_ptr);
216  }
217 
220  template <typename CLType, typename OutputIter>
221  void read_buffer (const ::cl::Buffer &buf, std::size_t num,
222  OutputIter first, std::size_t offset = 0,
223  const std::vector< ::cl::Event> *events = VSMC_NULLPTR,
224  ::cl::Event *event = VSMC_NULLPTR, bool block = true) const
225  {
228  event);
229 
230  std::vector<CLType> buffer(num);
231  command_queue_.enqueueReadBuffer(buf, static_cast< ::cl_bool>(block),
232  sizeof(CLType) * offset, sizeof(CLType) * num,
233  &buffer[0], events, event);
234  std::copy(buffer.begin(), buffer.end(), first);
235  }
236 
239  template <typename CLType>
240  void read_buffer (const ::cl::Buffer &buf, std::size_t num,
241  CLType *first, std::size_t offset = 0,
242  const std::vector< ::cl::Event> *events = VSMC_NULLPTR,
243  ::cl::Event *event = VSMC_NULLPTR, bool block = true) const
244  {
247  event);
248 
249  command_queue_.enqueueReadBuffer(buf, static_cast< ::cl_bool>(block),
250  sizeof(CLType) * offset, sizeof(CLType) * num,
251  first, events, event);
252  }
253 
256  template <typename CLType, typename InputIter>
257  void write_buffer (const ::cl::Buffer &buf, std::size_t num,
258  InputIter first, std::size_t offset = 0,
259  const std::vector< ::cl::Event> *events = VSMC_NULLPTR,
260  ::cl::Event *event = VSMC_NULLPTR, bool block = true) const
261  {
264  event);
265 
266  std::vector<CLType> buffer(num);
267 #if VSMC_HAS_CXX11LIB_ALGORITHM
268  std::copy_n(first, num, &buffer[0]);
269 #else
270  for (std::size_t i = 0; i != num; ++i, ++first)
271  buffer[i] = *first;
272 #endif
273  command_queue_.enqueueWriteBuffer(buf, static_cast< ::cl_bool>(block),
274  sizeof(CLType) * offset, sizeof(CLType) * num,
275  &buffer[0], events, event);
276  }
277 
280  template <typename CLType>
281  void write_buffer (const ::cl::Buffer &buf, std::size_t num,
282  const CLType *first, std::size_t offset = 0,
283  const std::vector< ::cl::Event> *events = VSMC_NULLPTR,
284  ::cl::Event *event = VSMC_NULLPTR, bool block = true) const
285  {
288  event);
289 
290  command_queue_.enqueueWriteBuffer(buf, static_cast< ::cl_bool>(block),
291  sizeof(CLType) * offset, sizeof(CLType) * num,
292  const_cast<CLType *>(first), events, event);
293  }
294 
297  template <typename CLType>
298  void write_buffer (const ::cl::Buffer &buf, std::size_t num,
299  CLType *first, std::size_t offset = 0,
300  const std::vector< ::cl::Event> *events = VSMC_NULLPTR,
301  ::cl::Event *event = VSMC_NULLPTR, bool block = true) const
302  {
305  event);
306 
307  command_queue_.enqueueWriteBuffer(buf, static_cast< ::cl_bool>(block),
308  sizeof(CLType) * offset, sizeof(CLType) * num,
309  first, events, event);
310  }
311 
314  template <typename CLType>
315  void copy_buffer (const ::cl::Buffer &src, const ::cl::Buffer &dst,
316  std::size_t num,
317  std::size_t src_offset = 0, std::size_t dst_offset = 0,
318  const std::vector< ::cl::Event> *events = VSMC_NULLPTR,
319  ::cl::Event *event = VSMC_NULLPTR, bool block = true) const
320  {
323  event);
324 
325  ::cl::Event e;
326  ::cl::Event *eptr = event == VSMC_NULLPTR ? &e : event;
327  command_queue_.enqueueCopyBuffer(src, dst,
328  sizeof(CLType) * src_offset, sizeof(CLType) * dst_offset,
329  sizeof(CLType) * num, events, eptr);
330  if (block)
331  eptr->wait();
332  }
333 
348  void run_kernel (const ::cl::Kernel &kern, std::size_t N,
349  std::size_t local_size = 0,
350  const std::vector< ::cl::Event> *events = VSMC_NULLPTR,
351  ::cl::Event *event = VSMC_NULLPTR, bool block = true) const
352  {
354 
355  ::cl::Event e;
356  ::cl::Event *eptr = event == VSMC_NULLPTR ? &e : event;
357  command_queue_.enqueueNDRangeKernel(kern, ::cl::NullRange,
358  get_global_nd_range(N, local_size),
359  get_local_nd_range(local_size), events, eptr);
360  if (block)
361  eptr->wait();
362  }
363 
385  template <typename Func>
386  typename cxx11::enable_if<
389  profile_kernel (::cl::Kernel &kern, std::size_t N,
390  const Func &func, std::size_t lmin = 0, std::size_t repeat = 10)
391  {
392  cl::size_t<3> reqd_size;
393  try {
394  kern.getWorkGroupInfo(device_,
395  CL_KERNEL_COMPILE_WORK_GROUP_SIZE, &reqd_size);
396  } catch (const ::cl::Error &) {
397  reqd_size[0] = 0;
398  }
399 
400  if (reqd_size[0] != 0)
401  return reqd_size[0];
402 
403  std::size_t factor;
404  std::size_t lmax;
405  std::size_t mmax;
406  cl_minmax_local_size(kern, device_, factor, lmax, mmax);
407  if (lmax == 0)
408  return 0;
409 
410  if (lmin != 0 && lmin <= lmax) {
411  factor = lmin;
412  mmax = lmax / factor;
413  lmax = mmax * factor;
414  }
415 
416  if (mmax < 2)
417  return lmax;
418 
419  double time = std::numeric_limits<double>::max VSMC_MNE ();
420  std::size_t lsize = lmax;
421  vsmc::StopWatch watch;
422  Func f(func);
423  for (std::size_t m = mmax; m >= 1; --m) {
424  std::size_t l = m * factor;
425  f(kern);
426  run_kernel(kern, N, l);
427  watch.reset();
428  watch.start();
429  for (std::size_t r = 0; r != repeat; ++r) {
430  f(kern);
431  run_kernel(kern, N, l);
432  }
433  watch.stop();
434  if (time > watch.milliseconds()) {
435  time = watch.milliseconds();
436  lsize = l;
437  }
438  }
439 
440  return lsize;
441  }
442 
443  std::size_t profile_kernel (::cl::Kernel &kern, std::size_t N,
444  std::size_t lmin = 0, std::size_t repeat = 3)
445  {return profile_kernel(kern, N, profile_kernel_func_(), lmin, repeat);}
446 
448  ::cl::Program create_program (const std::string &source) const
449  {return ::cl::Program(context_, source);}
450 
453  ::cl::Program create_program (const std::vector<std::string> &source) const
454  {
455  std::vector<std::pair<const char *, std::size_t> > src(source.size());
456  for (std::size_t i = 0; i != source.size(); ++i)
457  src[i] = std::make_pair(source[i].data(), source[i].size());
458 
459  return ::cl::Program(context_, src);
460  }
461 
471  ::cl::Program create_program (const std::vector<std::string> &binary,
472  const std::vector< ::cl::Device> *devices,
473  std::vector< ::cl_int> *status = VSMC_NULLPTR) const
474  {
475  std::vector<std::pair<const void *, std::size_t> > bin(binary.size());
476  for (std::size_t i = 0; i != binary.size(); ++i) {
477  bin[i] = std::make_pair(
478  static_cast<const void *>(binary[i].data()),
479  binary[i].size());
480  }
481 
482  return devices == VSMC_NULLPTR ?
483  ::cl::Program(context_, device_vec_, bin, status):
484  ::cl::Program(context_, *devices, bin, status);
485  }
486 
487  private :
488 
489  struct profile_kernel_func_ {void operator() (::cl::Kernel &) const {}};
490 
491  ::cl::Platform platform_;
492  ::cl::Context context_;
493  ::cl::Device device_;
494  std::vector< ::cl::Device> device_vec_;
495  ::cl::CommandQueue command_queue_;
496 
497  bool setup_;
498  CLSetup<ID> &setup_default_;
499  int opencl_version_;
500  int opencl_c_version_;
501 
502  CLManager () : setup_(false), setup_default_(CLSetup<ID>::instance())
503  {setup_cl_manager(setup_default_.device_type());}
504 
505  CLManager (const CLManager<ID> &);
506 
507  CLManager<ID> &operator= (const CLManager<ID> &);
508 
509  void check_opencl_version ()
510  {
511  opencl_version_ = CLQuery::opencl_version(device_);
512  opencl_c_version_ = CLQuery::opencl_c_version(device_);
513  for (std::size_t i = 0; i != device_vec_.size(); ++i) {
514  int ocl = CLQuery::opencl_version(device_vec_[i]);
515  int oclc = CLQuery::opencl_c_version(device_vec_[i]);
516  if (opencl_version_ > ocl)
517  opencl_version_ = ocl;
518  if (opencl_c_version_ > ocl)
519  opencl_c_version_ = oclc;
520  }
521  }
522 
523  void setup_cl_manager (::cl_device_type dev_type)
524  {
525  setup_ = false;
526 
527  bool setup_platform = platform_filter(dev_type);
529  if (!setup_platform) return;
530 
531  bool setup_context = false;
532  bool setup_device = false;
533  try {
534  std::vector< ::cl::Device> dev_pool;
535  std::vector< ::cl::Device> dev_select;
536  platform_.getDevices(dev_type, &dev_pool);
537  device_filter(dev_pool, dev_select);
538  if (dev_select.size() != 0) {
539  ::cl_context_properties context_properties[] = {
540  CL_CONTEXT_PLATFORM,
541  reinterpret_cast< ::cl_context_properties>(platform_()), 0
542  };
543  context_ = ::cl::Context(dev_select, context_properties);
544  setup_context = true;
545  device_vec_ = context_.getInfo<CL_CONTEXT_DEVICES>();
546  device_ = device_vec_[0];
547  setup_device = true;
548  }
549  } catch (const ::cl::Error &) {}
552  if (!setup_context) return;
553  if (!setup_device) return;
554 
555  bool setup_command_queue = false;
556  try {
557  command_queue_ = ::cl::CommandQueue(context_, device_, 0);
558  setup_command_queue = true;
559  } catch (const ::cl::Error &) {}
561  if (!setup_command_queue) return;
562 
563  check_opencl_version();
564 
565  setup_ = true;
566  }
567 
568  bool platform_filter (::cl_device_type dev_type)
569  {
570  std::vector< ::cl::Platform> platform_vec;
571  try {
572  ::cl::Platform::get(&platform_vec);
573  } catch (const ::cl::Error &) {
574  platform_vec.clear();
575  }
576  if (platform_vec.size() == 0)
577  return false;
578 
579  // If not using default platform
580  if (!setup_default_.default_platform()) {
581  for (std::size_t p = 0; p != platform_vec.size(); ++p) {
582  try {
583  std::string name;
584  platform_vec[p].getInfo(CL_PLATFORM_NAME, &name);
585  if (setup_default_.check_platform(name)) {
586  platform_ = platform_vec[p];
587  return true;
588  }
589  } catch (const ::cl::Error &) {}
590  }
591 
592  return false;
593  }
594 
595  // Using default platform: finding the first that has the device type
596  for (std::size_t p = 0; p != platform_vec.size(); ++p) {
597  try {
598  std::vector< ::cl::Device> dev_pool;
599  std::vector< ::cl::Device> dev_select;
600  platform_vec[p].getDevices(dev_type, &dev_pool);
601  device_filter(dev_pool, dev_select);
602  if (dev_select.size() != 0) {
603  platform_ = platform_vec[p];
604  return true;
605  }
606  } catch (const ::cl::Error &) {}
607  }
608 
609  return false;
610  }
611 
612  void device_filter (const std::vector< ::cl::Device> &dev_pool,
613  std::vector< ::cl::Device> &dev_select)
614  {
615  std::vector<bool> dev_select_idx(dev_pool.size(), true);
616 
617  // Not using the default device vendor
618  if (!setup_default_.default_device_vendor()) {
619  for (std::size_t d = 0; d != dev_pool.size(); ++d) {
620  try {
621  std::string str;
622  dev_pool[d].getInfo(CL_DEVICE_VENDOR, &str);
623  if (!setup_default_.check_device_vendor(str))
624  dev_select_idx[d] = false;
625  } catch (const ::cl::Error &) {
626  dev_select_idx[d] = false;
627  }
628  }
629  }
630 
631  // Not using the default device
632  if (!setup_default_.default_device()) {
633  for (std::size_t d = 0; d != dev_pool.size(); ++d) {
634  try {
635  std::string str;
636  dev_pool[d].getInfo(CL_DEVICE_NAME, &str);
637  if (!setup_default_.check_device(str))
638  dev_select_idx[d] = false;
639  } catch (const ::cl::Error &) {
640  dev_select_idx[d] = false;
641  }
642  }
643  }
644 
645  for (std::size_t d = 0; d != dev_pool.size(); ++d) {
646  if (dev_select_idx[d]) {
647  try {
648  dev_select.push_back(dev_pool[d]);
649  } catch (const ::cl::Error &) {}
650  }
651  }
652  }
653 
654  ::cl::NDRange get_global_nd_range (
655  std::size_t N, std::size_t local_size) const
656  {
657  if (local_size == 0)
658  return ::cl::NDRange(N);
659 
660  if (N % local_size == 0)
661  return ::cl::NDRange(N);
662 
663  return ::cl::NDRange((N / local_size + 1) * local_size);
664  }
665 
666  ::cl::NDRange get_local_nd_range (std::size_t local_size) const
667  {return local_size == 0 ? ::cl::NullRange : ::cl::NDRange(local_size);}
668 }; // clss CLManager
669 
670 } // namespace vsmc
671 
672 #endif // VSMC_OPENCL_CL_MANAGER_HPP
::cl::Program create_program(const std::vector< std::string > &source) const
Create a program given a vector of sources within the current context.
Definition: cl_manager.hpp:453
Definition: adapter.hpp:37
const ::cl::Context & context() const
The context currently being used.
Definition: cl_manager.hpp:159
void read_buffer(const ::cl::Buffer &buf, std::size_t num, CLType *first, std::size_t offset=0, const std::vector< ::cl::Event > *events=nullptr,::cl::Event *event=nullptr, bool block=true) const
Read an OpenCL buffer of a given type and number of elements into a pointer.
Definition: cl_manager.hpp:240
void read_buffer(const ::cl::Buffer &buf, std::size_t num, OutputIter first, std::size_t offset=0, const std::vector< ::cl::Event > *events=nullptr,::cl::Event *event=nullptr, bool block=true) const
Read an OpenCL buffer of a given type and number of elements into an iterator.
Definition: cl_manager.hpp:221
bool setup(::cl_device_type dev)
Try to setup the platform, context, device and command queue using the given device type...
Definition: cl_manager.hpp:176
void write_buffer(const ::cl::Buffer &buf, std::size_t num, CLType *first, std::size_t offset=0, const std::vector< ::cl::Event > *events=nullptr,::cl::Event *event=nullptr, bool block=true) const
Write an OpenCL buffer of a given type and number of elements from a pointer.
Definition: cl_manager.hpp:298
#define VSMC_RUNTIME_WARNING_OPENCL_CL_MANAGER_BLOCK(func, block, event)
Definition: cl_manager.hpp:63
void copy_buffer(const ::cl::Buffer &src, const ::cl::Buffer &dst, std::size_t num, std::size_t src_offset=0, std::size_t dst_offset=0, const std::vector< ::cl::Event > *events=nullptr,::cl::Event *event=nullptr, bool block=true) const
Copy an OpenCL buffer into another of a given type and number of elements.
Definition: cl_manager.hpp:315
void write_buffer(const ::cl::Buffer &buf, std::size_t num, InputIter first, std::size_t offset=0, const std::vector< ::cl::Event > *events=nullptr,::cl::Event *event=nullptr, bool block=true) const
Write an OpenCL buffer of a given type and number of elements from an iterator.
Definition: cl_manager.hpp:257
const ::cl::CommandQueue & command_queue() const
The command queue currently being used.
Definition: cl_manager.hpp:168
int opencl_c_version() const
The minimum OpenCL C version supported by all devices in the context of this manager.
Definition: cl_manager.hpp:153
void reset()
Stop and reset the elapsed time to zero.
Definition: stop_watch.hpp:167
T & get(Array< T, N > &ary)
Array ADL of get.
Definition: array.hpp:322
void write_buffer(const ::cl::Buffer &buf, std::size_t num, const CLType *first, std::size_t offset=0, const std::vector< ::cl::Event > *events=nullptr,::cl::Event *event=nullptr, bool block=true) const
Write an OpenCL buffer of a given type and number of elements from a pointer.
Definition: cl_manager.hpp:281
#define VSMC_RUNTIME_WARNING_OPENCL_CL_MANAGER_SETUP_PLATFORM
Definition: cl_manager.hpp:47
void cl_minmax_local_size(const ::cl::Kernel &kern, const ::cl::Device &dev, std::size_t &factor, std::size_t &lmax, std::size_t &mmax)
Query the preferred factor of local size.
Definition: cl_manip.hpp:48
static int opencl_c_version(const ::cl::Device &dev)
Return the OpenCL C version of a device.
Definition: cl_query.hpp:77
::cl::Buffer create_buffer(std::size_t num,::cl_mem_flags flag=CL_MEM_READ_WRITE, void *host_ptr=nullptr) const
Create an OpenCL buffer of a given type and number of elements.
Definition: cl_manager.hpp:206
std::size_t profile_kernel(::cl::Kernel &kern, std::size_t N, std::size_t lmin=0, std::size_t repeat=3)
Definition: cl_manager.hpp:443
#define VSMC_MNE
Avoid MSVC stupid behavior: MNE = Macro No Expansion.
Definition: defines.hpp:38
StopWatch as an adapter of C++11 clock.
Definition: stop_watch.hpp:117
const std::vector< ::cl::Device > & device_vec() const
The vector of all device that is in the context of this manager.
Definition: cl_manager.hpp:165
void run_kernel(const ::cl::Kernel &kern, std::size_t N, std::size_t local_size=0, const std::vector< ::cl::Event > *events=nullptr,::cl::Event *event=nullptr, bool block=true) const
Run a given kernel with one dimensional global size and local size on the current command queue...
Definition: cl_manager.hpp:348
bool stop()
Stop the watch, no effect if already stopped.
Definition: stop_watch.hpp:154
#define VSMC_RUNTIME_WARNING_OPENCL_CL_MANAGER_SETUP_COMMAND_QUEUE
Definition: cl_manager.hpp:59
#define VSMC_NULLPTR
nullptr
Definition: defines.hpp:79
double milliseconds() const
Return the accumulated elapsed time in milliseconds.
Definition: stop_watch.hpp:189
bool setup(const ::cl::Platform &plat, const ::cl::Context &ctx, const ::cl::Device &dev, const ::cl::CommandQueue &cmd)
Set the platform, context, device and command queue manually.
Definition: cl_manager.hpp:189
int opencl_version() const
The minimum OpenCL version supported by all devices in the context of this manager.
Definition: cl_manager.hpp:147
#define VSMC_RUNTIME_WARNING_OPENCL_CL_MANAGER_SETUP_CONTEXT
Definition: cl_manager.hpp:51
const ::cl::Platform & platform() const
The platform currently being used.
Definition: cl_manager.hpp:156
cxx11::enable_if< !cxx11::is_same< Func, std::size_t >::value &&!cxx11::is_convertible< Func, std::size_t >::value, std::size_t >::type profile_kernel(::cl::Kernel &kern, std::size_t N, const Func &func, std::size_t lmin=0, std::size_t repeat=10)
Run the kernel with all local size that are multiples of the preferred factor, return the local size ...
Definition: cl_manager.hpp:389
#define VSMC_RUNTIME_ASSERT_OPENCL_CL_MANAGER_SETUP(func)
Definition: cl_manager.hpp:42
static int opencl_version(const ::cl::Device &dev)
Return the OpenCL version of a device.
Definition: cl_query.hpp:66
bool start()
Start the watch, no effect if already started.
Definition: stop_watch.hpp:138
OpenCL Manager.
Definition: cl_manager.hpp:129
::cl::Program create_program(const std::string &source) const
Create a program given the source within the current context.
Definition: cl_manager.hpp:448
static CLManager< ID > & instance()
Get an instance of the manager singleton.
Definition: cl_manager.hpp:136
#define VSMC_RUNTIME_WARNING_OPENCL_CL_MANAGER_SETUP_DEVICE
Definition: cl_manager.hpp:55
::cl::Program create_program(const std::vector< std::string > &binary, const std::vector< ::cl::Device > *devices, std::vector< ::cl_int > *status=nullptr) const
Create a program given binaries within the current context.
Definition: cl_manager.hpp:471
bool setup() const
Whether the platform, context, device and command queue has been setup correctly. ...
Definition: cl_manager.hpp:172
const ::cl::Device & device() const
The device currently being used.
Definition: cl_manager.hpp:162