OpenCL C++ Bindings
opencl.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2008-2020 The Khronos Group Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
311 
324 
388 #ifndef CL_HPP_
389 #define CL_HPP_
390 
391 /* Handle deprecated preprocessor definitions. In each case, we only check for
392  * the old name if the new name is not defined, so that user code can define
393  * both and hence work with either version of the bindings.
394  */
395 #if !defined(CL_HPP_USE_DX_INTEROP) && defined(USE_DX_INTEROP)
396 # pragma message("opencl.hpp: USE_DX_INTEROP is deprecated. Define CL_HPP_USE_DX_INTEROP instead")
397 # define CL_HPP_USE_DX_INTEROP
398 #endif
399 #if !defined(CL_HPP_USE_CL_DEVICE_FISSION) && defined(USE_CL_DEVICE_FISSION)
400 # pragma message("opencl.hpp: USE_CL_DEVICE_FISSION is deprecated. Define CL_HPP_USE_CL_DEVICE_FISSION instead")
401 # define CL_HPP_USE_CL_DEVICE_FISSION
402 #endif
403 #if !defined(CL_HPP_ENABLE_EXCEPTIONS) && defined(__CL_ENABLE_EXCEPTIONS)
404 # pragma message("opencl.hpp: __CL_ENABLE_EXCEPTIONS is deprecated. Define CL_HPP_ENABLE_EXCEPTIONS instead")
405 # define CL_HPP_ENABLE_EXCEPTIONS
406 #endif
407 #if !defined(CL_HPP_NO_STD_VECTOR) && defined(__NO_STD_VECTOR)
408 # pragma message("opencl.hpp: __NO_STD_VECTOR is deprecated. Define CL_HPP_NO_STD_VECTOR instead")
409 # define CL_HPP_NO_STD_VECTOR
410 #endif
411 #if !defined(CL_HPP_NO_STD_STRING) && defined(__NO_STD_STRING)
412 # pragma message("opencl.hpp: __NO_STD_STRING is deprecated. Define CL_HPP_NO_STD_STRING instead")
413 # define CL_HPP_NO_STD_STRING
414 #endif
415 #if defined(VECTOR_CLASS)
416 # pragma message("opencl.hpp: VECTOR_CLASS is deprecated. Alias cl::vector instead")
417 #endif
418 #if defined(STRING_CLASS)
419 # pragma message("opencl.hpp: STRING_CLASS is deprecated. Alias cl::string instead.")
420 #endif
421 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) && defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
422 # pragma message("opencl.hpp: __CL_USER_OVERRIDE_ERROR_STRINGS is deprecated. Define CL_HPP_USER_OVERRIDE_ERROR_STRINGS instead")
423 # define CL_HPP_USER_OVERRIDE_ERROR_STRINGS
424 #endif
425 
426 /* Warn about features that are no longer supported
427  */
428 #if defined(__USE_DEV_VECTOR)
429 # pragma message("opencl.hpp: __USE_DEV_VECTOR is no longer supported. Expect compilation errors")
430 #endif
431 #if defined(__USE_DEV_STRING)
432 # pragma message("opencl.hpp: __USE_DEV_STRING is no longer supported. Expect compilation errors")
433 #endif
434 
435 /* Detect which version to target */
436 #if !defined(CL_HPP_TARGET_OPENCL_VERSION)
437 # pragma message("opencl.hpp: CL_HPP_TARGET_OPENCL_VERSION is not defined. It will default to 300 (OpenCL 3.0)")
438 # define CL_HPP_TARGET_OPENCL_VERSION 300
439 #endif
440 #if CL_HPP_TARGET_OPENCL_VERSION != 100 && \
441  CL_HPP_TARGET_OPENCL_VERSION != 110 && \
442  CL_HPP_TARGET_OPENCL_VERSION != 120 && \
443  CL_HPP_TARGET_OPENCL_VERSION != 200 && \
444  CL_HPP_TARGET_OPENCL_VERSION != 210 && \
445  CL_HPP_TARGET_OPENCL_VERSION != 220 && \
446  CL_HPP_TARGET_OPENCL_VERSION != 300
447 # pragma message("opencl.hpp: CL_HPP_TARGET_OPENCL_VERSION is not a valid value (100, 110, 120, 200, 210, 220 or 300). It will be set to 300 (OpenCL 3.0).")
448 # undef CL_HPP_TARGET_OPENCL_VERSION
449 # define CL_HPP_TARGET_OPENCL_VERSION 300
450 #endif
451 
452 /* Forward target OpenCL version to C headers if necessary */
453 #if defined(CL_TARGET_OPENCL_VERSION)
454 /* Warn if prior definition of CL_TARGET_OPENCL_VERSION is lower than
455  * requested C++ bindings version */
456 #if CL_TARGET_OPENCL_VERSION < CL_HPP_TARGET_OPENCL_VERSION
457 # pragma message("CL_TARGET_OPENCL_VERSION is already defined as is lower than CL_HPP_TARGET_OPENCL_VERSION")
458 #endif
459 #else
460 # define CL_TARGET_OPENCL_VERSION CL_HPP_TARGET_OPENCL_VERSION
461 #endif
462 
463 #if !defined(CL_HPP_MINIMUM_OPENCL_VERSION)
464 # define CL_HPP_MINIMUM_OPENCL_VERSION 200
465 #endif
466 #if CL_HPP_MINIMUM_OPENCL_VERSION != 100 && \
467  CL_HPP_MINIMUM_OPENCL_VERSION != 110 && \
468  CL_HPP_MINIMUM_OPENCL_VERSION != 120 && \
469  CL_HPP_MINIMUM_OPENCL_VERSION != 200 && \
470  CL_HPP_MINIMUM_OPENCL_VERSION != 210 && \
471  CL_HPP_MINIMUM_OPENCL_VERSION != 220 && \
472  CL_HPP_MINIMUM_OPENCL_VERSION != 300
473 # pragma message("opencl.hpp: CL_HPP_MINIMUM_OPENCL_VERSION is not a valid value (100, 110, 120, 200, 210, 220 or 300). It will be set to 100")
474 # undef CL_HPP_MINIMUM_OPENCL_VERSION
475 # define CL_HPP_MINIMUM_OPENCL_VERSION 100
476 #endif
477 #if CL_HPP_MINIMUM_OPENCL_VERSION > CL_HPP_TARGET_OPENCL_VERSION
478 # error "CL_HPP_MINIMUM_OPENCL_VERSION must not be greater than CL_HPP_TARGET_OPENCL_VERSION"
479 #endif
480 
481 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 100 && !defined(CL_USE_DEPRECATED_OPENCL_1_0_APIS)
482 # define CL_USE_DEPRECATED_OPENCL_1_0_APIS
483 #endif
484 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 110 && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
485 # define CL_USE_DEPRECATED_OPENCL_1_1_APIS
486 #endif
487 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 120 && !defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
488 # define CL_USE_DEPRECATED_OPENCL_1_2_APIS
489 #endif
490 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 200 && !defined(CL_USE_DEPRECATED_OPENCL_2_0_APIS)
491 # define CL_USE_DEPRECATED_OPENCL_2_0_APIS
492 #endif
493 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 210 && !defined(CL_USE_DEPRECATED_OPENCL_2_1_APIS)
494 # define CL_USE_DEPRECATED_OPENCL_2_1_APIS
495 #endif
496 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 220 && !defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
497 # define CL_USE_DEPRECATED_OPENCL_2_2_APIS
498 #endif
499 
500 #ifdef _WIN32
501 
502 #include <malloc.h>
503 
504 #if defined(CL_HPP_USE_DX_INTEROP)
505 #include <CL/cl_d3d10.h>
506 #include <CL/cl_dx9_media_sharing.h>
507 #endif
508 #endif // _WIN32
509 
510 #if defined(_MSC_VER)
511 #include <intrin.h>
512 #endif // _MSC_VER
513 
514  // Check for a valid C++ version
515 
516 // Need to do both tests here because for some reason __cplusplus is not
517 // updated in visual studio
518 #if (!defined(_MSC_VER) && __cplusplus < 201103L) || (defined(_MSC_VER) && _MSC_VER < 1700)
519 #error Visual studio 2013 or another C++11-supporting compiler required
520 #endif
521 
522 //
523 #if defined(CL_HPP_USE_CL_DEVICE_FISSION) || defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)
524 #include <CL/cl_ext.h>
525 #endif
526 
527 #if defined(__APPLE__) || defined(__MACOSX)
528 #include <OpenCL/opencl.h>
529 #else
530 #include <CL/opencl.h>
531 #endif // !__APPLE__
532 
533 #if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L )
534 #define CL_HPP_NOEXCEPT_ noexcept
535 #else
536 #define CL_HPP_NOEXCEPT_
537 #endif
538 
539 #if __cplusplus >= 201703L
540 # define CL_HPP_DEFINE_STATIC_MEMBER_ inline
541 #elif defined(_MSC_VER)
542 # define CL_HPP_DEFINE_STATIC_MEMBER_ __declspec(selectany)
543 #elif defined(__MINGW32__)
544 # define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((selectany))
545 #else
546 # define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((weak))
547 #endif // !_MSC_VER
548 
549 // Define deprecated prefixes and suffixes to ensure compilation
550 // in case they are not pre-defined
551 #if !defined(CL_API_PREFIX__VERSION_1_1_DEPRECATED)
552 #define CL_API_PREFIX__VERSION_1_1_DEPRECATED
553 #endif // #if !defined(CL_API_PREFIX__VERSION_1_1_DEPRECATED)
554 #if !defined(CL_API_SUFFIX__VERSION_1_1_DEPRECATED)
555 #define CL_API_SUFFIX__VERSION_1_1_DEPRECATED
556 #endif // #if !defined(CL_API_PREFIX__VERSION_1_1_DEPRECATED)
557 
558 #if !defined(CL_API_PREFIX__VERSION_1_2_DEPRECATED)
559 #define CL_API_PREFIX__VERSION_1_2_DEPRECATED
560 #endif // #if !defined(CL_API_PREFIX__VERSION_1_2_DEPRECATED)
561 #if !defined(CL_API_SUFFIX__VERSION_1_2_DEPRECATED)
562 #define CL_API_SUFFIX__VERSION_1_2_DEPRECATED
563 #endif // #if !defined(CL_API_PREFIX__VERSION_1_2_DEPRECATED)
564 
565 #if !defined(CL_CALLBACK)
566 #define CL_CALLBACK
567 #endif //CL_CALLBACK
568 
569 #include <utility>
570 #include <limits>
571 #include <iterator>
572 #include <mutex>
573 #include <cstring>
574 #include <functional>
575 
576 
577 // Define a size_type to represent a correctly resolved size_t
578 #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
579 namespace cl {
580  using size_type = ::size_t;
581 } // namespace cl
582 #else // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
583 namespace cl {
584  using size_type = size_t;
585 } // namespace cl
586 #endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
587 
588 
589 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
590 #include <exception>
591 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
592 
593 #if !defined(CL_HPP_NO_STD_VECTOR)
594 #include <vector>
595 namespace cl {
596  template < class T, class Alloc = std::allocator<T> >
597  using vector = std::vector<T, Alloc>;
598 } // namespace cl
599 #endif // #if !defined(CL_HPP_NO_STD_VECTOR)
600 
601 #if !defined(CL_HPP_NO_STD_STRING)
602 #include <string>
603 namespace cl {
604  using string = std::string;
605 } // namespace cl
606 #endif // #if !defined(CL_HPP_NO_STD_STRING)
607 
608 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
609 
610 #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
611 #include <memory>
612 namespace cl {
613  // Replace unique_ptr and allocate_pointer for internal use
614  // to allow user to replace them
615  template<class T, class D>
616  using pointer = std::unique_ptr<T, D>;
617 } // namespace cl
618 #endif
619 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
620 #if !defined(CL_HPP_NO_STD_ARRAY)
621 #include <array>
622 namespace cl {
623  template < class T, size_type N >
624  using array = std::array<T, N>;
625 } // namespace cl
626 #endif // #if !defined(CL_HPP_NO_STD_ARRAY)
627 
628 // Define size_type appropriately to allow backward-compatibility
629 // use of the old size_t interface class
630 #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
631 namespace cl {
632  namespace compatibility {
637  template <int N>
638  class size_t
639  {
640  private:
641  size_type data_[N];
642 
643  public:
645  size_t()
646  {
647  for (int i = 0; i < N; ++i) {
648  data_[i] = 0;
649  }
650  }
651 
652  size_t(const array<size_type, N> &rhs)
653  {
654  for (int i = 0; i < N; ++i) {
655  data_[i] = rhs[i];
656  }
657  }
658 
659  size_type& operator[](int index)
660  {
661  return data_[index];
662  }
663 
664  const size_type& operator[](int index) const
665  {
666  return data_[index];
667  }
668 
670  operator size_type* () { return data_; }
671 
673  operator const size_type* () const { return data_; }
674 
675  operator array<size_type, N>() const
676  {
677  array<size_type, N> ret;
678 
679  for (int i = 0; i < N; ++i) {
680  ret[i] = data_[i];
681  }
682  return ret;
683  }
684  };
685  } // namespace compatibility
686 
687  template<int N>
688  using size_t = compatibility::size_t<N>;
689 } // namespace cl
690 #endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
691 
692 // Helper alias to avoid confusing the macros
693 namespace cl {
694  namespace detail {
695  using size_t_array = array<size_type, 3>;
696  } // namespace detail
697 } // namespace cl
698 
699 
705 namespace cl {
706  class Memory;
707 
708 #define CL_HPP_INIT_CL_EXT_FCN_PTR_(name) \
709  if (!pfn_##name) { \
710  pfn_##name = (PFN_##name) \
711  clGetExtensionFunctionAddress(#name); \
712  if (!pfn_##name) { \
713  } \
714  }
715 
716 #define CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, name) \
717  if (!pfn_##name) { \
718  pfn_##name = (PFN_##name) \
719  clGetExtensionFunctionAddressForPlatform(platform, #name); \
720  if (!pfn_##name) { \
721  } \
722  }
723 
724  class Program;
725  class Device;
726  class Context;
727  class CommandQueue;
728  class DeviceCommandQueue;
729  class Memory;
730  class Buffer;
731  class Pipe;
732 
733 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
738  class Error : public std::exception
739  {
740  private:
741  cl_int err_;
742  const char * errStr_;
743  public:
753  Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr)
754  {}
755 
756  ~Error() throw() {}
757 
762  virtual const char * what() const throw ()
763  {
764  if (errStr_ == NULL) {
765  return "empty";
766  }
767  else {
768  return errStr_;
769  }
770  }
771 
776  cl_int err(void) const { return err_; }
777  };
778 #define CL_HPP_ERR_STR_(x) #x
779 #else
780 #define CL_HPP_ERR_STR_(x) NULL
781 #endif // CL_HPP_ENABLE_EXCEPTIONS
782 
783 
784 namespace detail
785 {
786 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
787 static inline cl_int errHandler (
788  cl_int err,
789  const char * errStr = NULL)
790 {
791  if (err != CL_SUCCESS) {
792  throw Error(err, errStr);
793  }
794  return err;
795 }
796 #else
797 static inline cl_int errHandler (cl_int err, const char * errStr = NULL)
798 {
799  (void) errStr; // suppress unused variable warning
800  return err;
801 }
802 #endif // CL_HPP_ENABLE_EXCEPTIONS
803 }
804 
805 
806 
808 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
809 #define __GET_DEVICE_INFO_ERR CL_HPP_ERR_STR_(clGetDeviceInfo)
810 #define __GET_PLATFORM_INFO_ERR CL_HPP_ERR_STR_(clGetPlatformInfo)
811 #define __GET_DEVICE_IDS_ERR CL_HPP_ERR_STR_(clGetDeviceIDs)
812 #define __GET_PLATFORM_IDS_ERR CL_HPP_ERR_STR_(clGetPlatformIDs)
813 #define __GET_CONTEXT_INFO_ERR CL_HPP_ERR_STR_(clGetContextInfo)
814 #define __GET_EVENT_INFO_ERR CL_HPP_ERR_STR_(clGetEventInfo)
815 #define __GET_EVENT_PROFILE_INFO_ERR CL_HPP_ERR_STR_(clGetEventProfileInfo)
816 #define __GET_MEM_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetMemObjectInfo)
817 #define __GET_IMAGE_INFO_ERR CL_HPP_ERR_STR_(clGetImageInfo)
818 #define __GET_SAMPLER_INFO_ERR CL_HPP_ERR_STR_(clGetSamplerInfo)
819 #define __GET_KERNEL_INFO_ERR CL_HPP_ERR_STR_(clGetKernelInfo)
820 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
821 #define __GET_KERNEL_ARG_INFO_ERR CL_HPP_ERR_STR_(clGetKernelArgInfo)
822 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
823 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
824 #define __GET_KERNEL_SUB_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelSubGroupInfo)
825 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
826 #define __GET_KERNEL_WORK_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelWorkGroupInfo)
827 #define __GET_PROGRAM_INFO_ERR CL_HPP_ERR_STR_(clGetProgramInfo)
828 #define __GET_PROGRAM_BUILD_INFO_ERR CL_HPP_ERR_STR_(clGetProgramBuildInfo)
829 #define __GET_COMMAND_QUEUE_INFO_ERR CL_HPP_ERR_STR_(clGetCommandQueueInfo)
830 
831 #define __CREATE_CONTEXT_ERR CL_HPP_ERR_STR_(clCreateContext)
832 #define __CREATE_CONTEXT_FROM_TYPE_ERR CL_HPP_ERR_STR_(clCreateContextFromType)
833 #define __GET_SUPPORTED_IMAGE_FORMATS_ERR CL_HPP_ERR_STR_(clGetSupportedImageFormats)
834 
835 #define __CREATE_BUFFER_ERR CL_HPP_ERR_STR_(clCreateBuffer)
836 #define __COPY_ERR CL_HPP_ERR_STR_(cl::copy)
837 #define __CREATE_SUBBUFFER_ERR CL_HPP_ERR_STR_(clCreateSubBuffer)
838 #define __CREATE_GL_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
839 #define __CREATE_GL_RENDER_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
840 #define __GET_GL_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetGLObjectInfo)
841 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
842 #define __CREATE_IMAGE_ERR CL_HPP_ERR_STR_(clCreateImage)
843 #define __CREATE_GL_TEXTURE_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture)
844 #define __IMAGE_DIMENSION_ERR CL_HPP_ERR_STR_(Incorrect image dimensions)
845 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
846 #define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR CL_HPP_ERR_STR_(clSetMemObjectDestructorCallback)
847 
848 #define __CREATE_USER_EVENT_ERR CL_HPP_ERR_STR_(clCreateUserEvent)
849 #define __SET_USER_EVENT_STATUS_ERR CL_HPP_ERR_STR_(clSetUserEventStatus)
850 #define __SET_EVENT_CALLBACK_ERR CL_HPP_ERR_STR_(clSetEventCallback)
851 #define __WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clWaitForEvents)
852 
853 #define __CREATE_KERNEL_ERR CL_HPP_ERR_STR_(clCreateKernel)
854 #define __SET_KERNEL_ARGS_ERR CL_HPP_ERR_STR_(clSetKernelArg)
855 #define __CREATE_PROGRAM_WITH_SOURCE_ERR CL_HPP_ERR_STR_(clCreateProgramWithSource)
856 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
857 #define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
858 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
859 #define __CREATE_PROGRAM_WITH_BINARY_ERR CL_HPP_ERR_STR_(clCreateProgramWithBinary)
860 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
861 #define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
862 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
863 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
864 #define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR CL_HPP_ERR_STR_(clCreateProgramWithBuiltInKernels)
865 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
866 #define __BUILD_PROGRAM_ERR CL_HPP_ERR_STR_(clBuildProgram)
867 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
868 #define __COMPILE_PROGRAM_ERR CL_HPP_ERR_STR_(clCompileProgram)
869 #define __LINK_PROGRAM_ERR CL_HPP_ERR_STR_(clLinkProgram)
870 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
871 #define __CREATE_KERNELS_IN_PROGRAM_ERR CL_HPP_ERR_STR_(clCreateKernelsInProgram)
872 
873 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
874 #define __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateCommandQueueWithProperties)
875 #define __CREATE_SAMPLER_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateSamplerWithProperties)
876 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
877 #define __SET_COMMAND_QUEUE_PROPERTY_ERR CL_HPP_ERR_STR_(clSetCommandQueueProperty)
878 #define __ENQUEUE_READ_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueReadBuffer)
879 #define __ENQUEUE_READ_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueReadBufferRect)
880 #define __ENQUEUE_WRITE_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueWriteBuffer)
881 #define __ENQUEUE_WRITE_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueWriteBufferRect)
882 #define __ENQEUE_COPY_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyBuffer)
883 #define __ENQEUE_COPY_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferRect)
884 #define __ENQUEUE_FILL_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueFillBuffer)
885 #define __ENQUEUE_READ_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueReadImage)
886 #define __ENQUEUE_WRITE_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueWriteImage)
887 #define __ENQUEUE_COPY_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyImage)
888 #define __ENQUEUE_FILL_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueFillImage)
889 #define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyImageToBuffer)
890 #define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferToImage)
891 #define __ENQUEUE_MAP_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueMapBuffer)
892 #define __ENQUEUE_MAP_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueMapImage)
893 #define __ENQUEUE_UNMAP_MEM_OBJECT_ERR CL_HPP_ERR_STR_(clEnqueueUnMapMemObject)
894 #define __ENQUEUE_NDRANGE_KERNEL_ERR CL_HPP_ERR_STR_(clEnqueueNDRangeKernel)
895 #define __ENQUEUE_NATIVE_KERNEL CL_HPP_ERR_STR_(clEnqueueNativeKernel)
896 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
897 #define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR CL_HPP_ERR_STR_(clEnqueueMigrateMemObjects)
898 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
899 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
900 #define __ENQUEUE_MIGRATE_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMMigrateMem)
901 #define __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clSetDefaultDeviceCommandQueue)
902 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
903 
904 
905 #define __ENQUEUE_ACQUIRE_GL_ERR CL_HPP_ERR_STR_(clEnqueueAcquireGLObjects)
906 #define __ENQUEUE_RELEASE_GL_ERR CL_HPP_ERR_STR_(clEnqueueReleaseGLObjects)
907 
908 #define __CREATE_PIPE_ERR CL_HPP_ERR_STR_(clCreatePipe)
909 #define __GET_PIPE_INFO_ERR CL_HPP_ERR_STR_(clGetPipeInfo)
910 
911 
912 #define __RETAIN_ERR CL_HPP_ERR_STR_(Retain Object)
913 #define __RELEASE_ERR CL_HPP_ERR_STR_(Release Object)
914 #define __FLUSH_ERR CL_HPP_ERR_STR_(clFlush)
915 #define __FINISH_ERR CL_HPP_ERR_STR_(clFinish)
916 #define __VECTOR_CAPACITY_ERR CL_HPP_ERR_STR_(Vector capacity error)
917 
918 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
919 #define __GET_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetHostTimer)
920 #define __GET_DEVICE_AND_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetDeviceAndHostTimer)
921 #endif
922 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
923 #define __SET_PROGRAM_RELEASE_CALLBACK_ERR CL_HPP_ERR_STR_(clSetProgramReleaseCallback)
924 #define __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR CL_HPP_ERR_STR_(clSetProgramSpecializationConstant)
925 #endif
926 
927 
931 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
932 #define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevices)
933 #else
934 #define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevicesEXT)
935 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
936 
940 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
941 #define __ENQUEUE_MARKER_ERR CL_HPP_ERR_STR_(clEnqueueMarker)
942 #define __ENQUEUE_WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clEnqueueWaitForEvents)
943 #define __ENQUEUE_BARRIER_ERR CL_HPP_ERR_STR_(clEnqueueBarrier)
944 #define __UNLOAD_COMPILER_ERR CL_HPP_ERR_STR_(clUnloadCompiler)
945 #define __CREATE_GL_TEXTURE_2D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture2D)
946 #define __CREATE_GL_TEXTURE_3D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture3D)
947 #define __CREATE_IMAGE2D_ERR CL_HPP_ERR_STR_(clCreateImage2D)
948 #define __CREATE_IMAGE3D_ERR CL_HPP_ERR_STR_(clCreateImage3D)
949 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
950 
954 #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
955 #define __CREATE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clCreateCommandQueue)
956 #define __ENQUEUE_TASK_ERR CL_HPP_ERR_STR_(clEnqueueTask)
957 #define __CREATE_SAMPLER_ERR CL_HPP_ERR_STR_(clCreateSampler)
958 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
959 
963 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
964 #define __ENQUEUE_MARKER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueMarkerWithWaitList)
965 #define __ENQUEUE_BARRIER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueBarrierWithWaitList)
966 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
967 
968 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
969 #define __CLONE_KERNEL_ERR CL_HPP_ERR_STR_(clCloneKernel)
970 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
971 
972 #endif // CL_HPP_USER_OVERRIDE_ERROR_STRINGS
974 
975 
976 namespace detail {
977 
978 // Generic getInfoHelper. The final parameter is used to guide overload
979 // resolution: the actual parameter passed is an int, which makes this
980 // a worse conversion sequence than a specialization that declares the
981 // parameter as an int.
982 template<typename Functor, typename T>
983 inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long)
984 {
985  return f(name, sizeof(T), param, NULL);
986 }
987 
988 // Specialized for getInfo<CL_PROGRAM_BINARIES>
989 // Assumes that the output vector was correctly resized on the way in
990 template <typename Func>
991 inline cl_int getInfoHelper(Func f, cl_uint name, vector<vector<unsigned char>>* param, int)
992 {
993  if (name != CL_PROGRAM_BINARIES) {
994  return CL_INVALID_VALUE;
995  }
996  if (param) {
997  // Create array of pointers, calculate total size and pass pointer array in
998  size_type numBinaries = param->size();
999  vector<unsigned char*> binariesPointers(numBinaries);
1000 
1001  for (size_type i = 0; i < numBinaries; ++i)
1002  {
1003  binariesPointers[i] = (*param)[i].data();
1004  }
1005 
1006  cl_int err = f(name, numBinaries * sizeof(unsigned char*), binariesPointers.data(), NULL);
1007 
1008  if (err != CL_SUCCESS) {
1009  return err;
1010  }
1011  }
1012 
1013 
1014  return CL_SUCCESS;
1015 }
1016 
1017 // Specialized getInfoHelper for vector params
1018 template <typename Func, typename T>
1019 inline cl_int getInfoHelper(Func f, cl_uint name, vector<T>* param, long)
1020 {
1021  size_type required;
1022  cl_int err = f(name, 0, NULL, &required);
1023  if (err != CL_SUCCESS) {
1024  return err;
1025  }
1026  const size_type elements = required / sizeof(T);
1027 
1028  // Temporary to avoid changing param on an error
1029  vector<T> localData(elements);
1030  err = f(name, required, localData.data(), NULL);
1031  if (err != CL_SUCCESS) {
1032  return err;
1033  }
1034  if (param) {
1035  *param = std::move(localData);
1036  }
1037 
1038  return CL_SUCCESS;
1039 }
1040 
1041 /* Specialization for reference-counted types. This depends on the
1042  * existence of Wrapper<T>::cl_type, and none of the other types having the
1043  * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1044  * does not work, because when using a derived type (e.g. Context) the generic
1045  * template will provide a better match.
1046  */
1047 template <typename Func, typename T>
1048 inline cl_int getInfoHelper(
1049  Func f, cl_uint name, vector<T>* param, int, typename T::cl_type = 0)
1050 {
1051  size_type required;
1052  cl_int err = f(name, 0, NULL, &required);
1053  if (err != CL_SUCCESS) {
1054  return err;
1055  }
1056 
1057  const size_type elements = required / sizeof(typename T::cl_type);
1058 
1059  vector<typename T::cl_type> value(elements);
1060  err = f(name, required, value.data(), NULL);
1061  if (err != CL_SUCCESS) {
1062  return err;
1063  }
1064 
1065  if (param) {
1066  // Assign to convert CL type to T for each element
1067  param->resize(elements);
1068 
1069  // Assign to param, constructing with retain behaviour
1070  // to correctly capture each underlying CL object
1071  for (size_type i = 0; i < elements; i++) {
1072  (*param)[i] = T(value[i], true);
1073  }
1074  }
1075  return CL_SUCCESS;
1076 }
1077 
1078 // Specialized GetInfoHelper for string params
1079 template <typename Func>
1080 inline cl_int getInfoHelper(Func f, cl_uint name, string* param, long)
1081 {
1082  size_type required;
1083  cl_int err = f(name, 0, NULL, &required);
1084  if (err != CL_SUCCESS) {
1085  return err;
1086  }
1087 
1088  // std::string has a constant data member
1089  // a char vector does not
1090  if (required > 0) {
1091  vector<char> value(required);
1092  err = f(name, required, value.data(), NULL);
1093  if (err != CL_SUCCESS) {
1094  return err;
1095  }
1096  if (param) {
1097  param->assign(begin(value), prev(end(value)));
1098  }
1099  }
1100  else if (param) {
1101  param->assign("");
1102  }
1103  return CL_SUCCESS;
1104 }
1105 
1106 // Specialized GetInfoHelper for clsize_t params
1107 template <typename Func, size_type N>
1108 inline cl_int getInfoHelper(Func f, cl_uint name, array<size_type, N>* param, long)
1109 {
1110  size_type required;
1111  cl_int err = f(name, 0, NULL, &required);
1112  if (err != CL_SUCCESS) {
1113  return err;
1114  }
1115 
1116  size_type elements = required / sizeof(size_type);
1117  vector<size_type> value(elements, 0);
1118 
1119  err = f(name, required, value.data(), NULL);
1120  if (err != CL_SUCCESS) {
1121  return err;
1122  }
1123 
1124  // Bound the copy with N to prevent overruns
1125  // if passed N > than the amount copied
1126  if (elements > N) {
1127  elements = N;
1128  }
1129  for (size_type i = 0; i < elements; ++i) {
1130  (*param)[i] = value[i];
1131  }
1132 
1133  return CL_SUCCESS;
1134 }
1135 
1136 template<typename T> struct ReferenceHandler;
1137 
1138 /* Specialization for reference-counted types. This depends on the
1139  * existence of Wrapper<T>::cl_type, and none of the other types having the
1140  * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1141  * does not work, because when using a derived type (e.g. Context) the generic
1142  * template will provide a better match.
1143  */
1144 template<typename Func, typename T>
1145 inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0)
1146 {
1147  typename T::cl_type value;
1148  cl_int err = f(name, sizeof(value), &value, NULL);
1149  if (err != CL_SUCCESS) {
1150  return err;
1151  }
1152  *param = value;
1153  if (value != NULL)
1154  {
1155  err = param->retain();
1156  if (err != CL_SUCCESS) {
1157  return err;
1158  }
1159  }
1160  return CL_SUCCESS;
1161 }
1162 
1163 #define CL_HPP_PARAM_NAME_INFO_1_0_(F) \
1164  F(cl_platform_info, CL_PLATFORM_PROFILE, string) \
1165  F(cl_platform_info, CL_PLATFORM_VERSION, string) \
1166  F(cl_platform_info, CL_PLATFORM_NAME, string) \
1167  F(cl_platform_info, CL_PLATFORM_VENDOR, string) \
1168  F(cl_platform_info, CL_PLATFORM_EXTENSIONS, string) \
1169  \
1170  F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
1171  F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
1172  F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
1173  F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
1174  F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, size_type) \
1175  F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, cl::vector<size_type>) \
1176  F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
1177  F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
1178  F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
1179  F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
1180  F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
1181  F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
1182  F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
1183  F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \
1184  F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
1185  F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
1186  F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
1187  F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, size_type) \
1188  F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, size_type) \
1189  F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, size_type) \
1190  F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, size_type) \
1191  F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, size_type) \
1192  F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \
1193  F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, size_type) \
1194  F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
1195  F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
1196  F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
1197  F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
1198  F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
1199  F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
1200  F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
1201  F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
1202  F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
1203  F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
1204  F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
1205  F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
1206  F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
1207  F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
1208  F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
1209  F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, size_type) \
1210  F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
1211  F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
1212  F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
1213  F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
1214  F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
1215  F(cl_device_info, CL_DEVICE_NAME, string) \
1216  F(cl_device_info, CL_DEVICE_VENDOR, string) \
1217  F(cl_device_info, CL_DRIVER_VERSION, string) \
1218  F(cl_device_info, CL_DEVICE_PROFILE, string) \
1219  F(cl_device_info, CL_DEVICE_VERSION, string) \
1220  F(cl_device_info, CL_DEVICE_EXTENSIONS, string) \
1221  \
1222  F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
1223  F(cl_context_info, CL_CONTEXT_DEVICES, cl::vector<Device>) \
1224  F(cl_context_info, CL_CONTEXT_PROPERTIES, cl::vector<cl_context_properties>) \
1225  \
1226  F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
1227  F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
1228  F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
1229  F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \
1230  \
1231  F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
1232  F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
1233  F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
1234  F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
1235  \
1236  F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
1237  F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
1238  F(cl_mem_info, CL_MEM_SIZE, size_type) \
1239  F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
1240  F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
1241  F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
1242  F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
1243  \
1244  F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
1245  F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, size_type) \
1246  F(cl_image_info, CL_IMAGE_ROW_PITCH, size_type) \
1247  F(cl_image_info, CL_IMAGE_SLICE_PITCH, size_type) \
1248  F(cl_image_info, CL_IMAGE_WIDTH, size_type) \
1249  F(cl_image_info, CL_IMAGE_HEIGHT, size_type) \
1250  F(cl_image_info, CL_IMAGE_DEPTH, size_type) \
1251  \
1252  F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
1253  F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
1254  F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \
1255  F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \
1256  F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \
1257  \
1258  F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
1259  F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
1260  F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
1261  F(cl_program_info, CL_PROGRAM_DEVICES, cl::vector<Device>) \
1262  F(cl_program_info, CL_PROGRAM_SOURCE, string) \
1263  F(cl_program_info, CL_PROGRAM_BINARY_SIZES, cl::vector<size_type>) \
1264  F(cl_program_info, CL_PROGRAM_BINARIES, cl::vector<cl::vector<unsigned char>>) \
1265  \
1266  F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
1267  F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, string) \
1268  F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, string) \
1269  \
1270  F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, string) \
1271  F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
1272  F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
1273  F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
1274  F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
1275  \
1276  F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, size_type) \
1277  F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::detail::size_t_array) \
1278  F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
1279  \
1280  F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
1281  F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
1282  F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
1283  F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
1284 
1285 
1286 #define CL_HPP_PARAM_NAME_INFO_1_1_(F) \
1287  F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
1288  F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
1289  F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
1290  F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
1291  F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
1292  F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
1293  F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
1294  F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
1295  F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
1296  F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, string) \
1297  \
1298  F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
1299  F(cl_mem_info, CL_MEM_OFFSET, size_type) \
1300  \
1301  F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1302  F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
1303  \
1304  F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
1305 
1306 #define CL_HPP_PARAM_NAME_INFO_1_2_(F) \
1307  F(cl_program_info, CL_PROGRAM_NUM_KERNELS, size_type) \
1308  F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, string) \
1309  \
1310  F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \
1311  \
1312  F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, string) \
1313  \
1314  F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \
1315  F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \
1316  F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, string) \
1317  F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, string) \
1318  F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \
1319  \
1320  F(cl_kernel_work_group_info, CL_KERNEL_GLOBAL_WORK_SIZE, cl::detail::size_t_array) \
1321  \
1322  F(cl_device_info, CL_DEVICE_LINKER_AVAILABLE, cl_bool) \
1323  F(cl_device_info, CL_DEVICE_IMAGE_MAX_BUFFER_SIZE, size_type) \
1324  F(cl_device_info, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, size_type) \
1325  F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl::Device) \
1326  F(cl_device_info, CL_DEVICE_PARTITION_MAX_SUB_DEVICES, cl_uint) \
1327  F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, cl::vector<cl_device_partition_property>) \
1328  F(cl_device_info, CL_DEVICE_PARTITION_TYPE, cl::vector<cl_device_partition_property>) \
1329  F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \
1330  F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, cl_bool) \
1331  F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \
1332  F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, string) \
1333  F(cl_device_info, CL_DEVICE_PRINTF_BUFFER_SIZE, size_type) \
1334  \
1335  F(cl_image_info, CL_IMAGE_ARRAY_SIZE, size_type) \
1336  F(cl_image_info, CL_IMAGE_NUM_MIP_LEVELS, cl_uint) \
1337  F(cl_image_info, CL_IMAGE_NUM_SAMPLES, cl_uint)
1338 
1339 #define CL_HPP_PARAM_NAME_INFO_2_0_(F) \
1340  F(cl_device_info, CL_DEVICE_QUEUE_ON_HOST_PROPERTIES, cl_command_queue_properties) \
1341  F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES, cl_command_queue_properties) \
1342  F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, cl_uint) \
1343  F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, cl_uint) \
1344  F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_QUEUES, cl_uint) \
1345  F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_EVENTS, cl_uint) \
1346  F(cl_device_info, CL_DEVICE_MAX_PIPE_ARGS, cl_uint) \
1347  F(cl_device_info, CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS, cl_uint) \
1348  F(cl_device_info, CL_DEVICE_PIPE_MAX_PACKET_SIZE, cl_uint) \
1349  F(cl_device_info, CL_DEVICE_SVM_CAPABILITIES, cl_device_svm_capabilities) \
1350  F(cl_device_info, CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT, cl_uint) \
1351  F(cl_device_info, CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT, cl_uint) \
1352  F(cl_device_info, CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT, cl_uint) \
1353  F(cl_device_info, CL_DEVICE_IMAGE_PITCH_ALIGNMENT, cl_uint) \
1354  F(cl_device_info, CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT, cl_uint) \
1355  F(cl_device_info, CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS, cl_uint ) \
1356  F(cl_device_info, CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE, size_type ) \
1357  F(cl_device_info, CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE, size_type ) \
1358  F(cl_profiling_info, CL_PROFILING_COMMAND_COMPLETE, cl_ulong) \
1359  F(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM, cl_bool) \
1360  F(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_SVM_PTRS, void**) \
1361  F(cl_command_queue_info, CL_QUEUE_SIZE, cl_uint) \
1362  F(cl_mem_info, CL_MEM_USES_SVM_POINTER, cl_bool) \
1363  F(cl_program_build_info, CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, size_type) \
1364  F(cl_pipe_info, CL_PIPE_PACKET_SIZE, cl_uint) \
1365  F(cl_pipe_info, CL_PIPE_MAX_PACKETS, cl_uint)
1366 
1367 #define CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(F) \
1368  F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR, size_type) \
1369  F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR, size_type)
1370 
1371 #define CL_HPP_PARAM_NAME_INFO_IL_KHR_(F) \
1372  F(cl_device_info, CL_DEVICE_IL_VERSION_KHR, string) \
1373  F(cl_program_info, CL_PROGRAM_IL_KHR, cl::vector<unsigned char>)
1374 
1375 #define CL_HPP_PARAM_NAME_INFO_2_1_(F) \
1376  F(cl_platform_info, CL_PLATFORM_HOST_TIMER_RESOLUTION, cl_ulong) \
1377  F(cl_program_info, CL_PROGRAM_IL, cl::vector<unsigned char>) \
1378  F(cl_device_info, CL_DEVICE_MAX_NUM_SUB_GROUPS, cl_uint) \
1379  F(cl_device_info, CL_DEVICE_IL_VERSION, string) \
1380  F(cl_device_info, CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS, cl_bool) \
1381  F(cl_command_queue_info, CL_QUEUE_DEVICE_DEFAULT, cl::DeviceCommandQueue) \
1382  F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE, size_type) \
1383  F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE, size_type) \
1384  F(cl_kernel_sub_group_info, CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT, cl::detail::size_t_array) \
1385  F(cl_kernel_sub_group_info, CL_KERNEL_MAX_NUM_SUB_GROUPS, size_type) \
1386  F(cl_kernel_sub_group_info, CL_KERNEL_COMPILE_NUM_SUB_GROUPS, size_type)
1387 
1388 #define CL_HPP_PARAM_NAME_INFO_2_2_(F) \
1389  F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_CTORS_PRESENT, cl_bool) \
1390  F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_DTORS_PRESENT, cl_bool)
1391 
1392 #define CL_HPP_PARAM_NAME_DEVICE_FISSION_(F) \
1393  F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
1394  F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, cl::vector<cl_device_partition_property_ext>) \
1395  F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, cl::vector<cl_device_partition_property_ext>) \
1396  F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
1397  F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, cl::vector<cl_device_partition_property_ext>)
1398 
1399 #define CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_CL3_SHARED_(F) \
1400  F(cl_platform_info, CL_PLATFORM_NUMERIC_VERSION_KHR, cl_version_khr) \
1401  F(cl_platform_info, CL_PLATFORM_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1402  \
1403  F(cl_device_info, CL_DEVICE_NUMERIC_VERSION_KHR, cl_version_khr) \
1404  F(cl_device_info, CL_DEVICE_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1405  F(cl_device_info, CL_DEVICE_ILS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1406  F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>)
1407 
1408 #define CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_KHRONLY_(F) \
1409  F(cl_device_info, CL_DEVICE_OPENCL_C_NUMERIC_VERSION_KHR, cl_version_khr)
1410 
1411 #define CL_HPP_PARAM_NAME_INFO_3_0_(F) \
1412  F(cl_platform_info, CL_PLATFORM_NUMERIC_VERSION, cl_version) \
1413  F(cl_platform_info, CL_PLATFORM_EXTENSIONS_WITH_VERSION, cl::vector<cl_name_version>) \
1414  \
1415  F(cl_device_info, CL_DEVICE_NUMERIC_VERSION, cl_version) \
1416  F(cl_device_info, CL_DEVICE_EXTENSIONS_WITH_VERSION, cl::vector<cl_name_version>) \
1417  F(cl_device_info, CL_DEVICE_ILS_WITH_VERSION, cl::vector<cl_name_version>) \
1418  F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION, cl::vector<cl_name_version>) \
1419  F(cl_device_info, CL_DEVICE_ATOMIC_MEMORY_CAPABILITIES, cl_device_atomic_capabilities) \
1420  F(cl_device_info, CL_DEVICE_ATOMIC_FENCE_CAPABILITIES, cl_device_atomic_capabilities) \
1421  F(cl_device_info, CL_DEVICE_NON_UNIFORM_WORK_GROUP_SUPPORT, cl_bool) \
1422  F(cl_device_info, CL_DEVICE_OPENCL_C_ALL_VERSIONS, cl::vector<cl_name_version>) \
1423  F(cl_device_info, CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1424  F(cl_device_info, CL_DEVICE_WORK_GROUP_COLLECTIVE_FUNCTIONS_SUPPORT, cl_bool) \
1425  F(cl_device_info, CL_DEVICE_GENERIC_ADDRESS_SPACE_SUPPORT, cl_bool) \
1426  F(cl_device_info, CL_DEVICE_OPENCL_C_FEATURES, cl::vector<cl_name_version>) \
1427  F(cl_device_info, CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES, cl_device_device_enqueue_capabilities) \
1428  F(cl_device_info, CL_DEVICE_PIPE_SUPPORT, cl_bool) \
1429  F(cl_device_info, CL_DEVICE_LATEST_CONFORMANCE_VERSION_PASSED, string) \
1430  \
1431  F(cl_command_queue_info, CL_QUEUE_PROPERTIES_ARRAY, cl::vector<cl_queue_properties>) \
1432  F(cl_mem_info, CL_MEM_PROPERTIES, cl::vector<cl_mem_properties>) \
1433  F(cl_pipe_info, CL_PIPE_PROPERTIES, cl::vector<cl_pipe_properties>) \
1434  F(cl_sampler_info, CL_SAMPLER_PROPERTIES, cl::vector<cl_sampler_properties>)
1435 
1436 template <typename enum_type, cl_int Name>
1437 struct param_traits {};
1438 
1439 #define CL_HPP_DECLARE_PARAM_TRAITS_(token, param_name, T) \
1440 struct token; \
1441 template<> \
1442 struct param_traits<detail:: token,param_name> \
1443 { \
1444  enum { value = param_name }; \
1445  typedef T param_type; \
1446 };
1447 
1448 CL_HPP_PARAM_NAME_INFO_1_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1449 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
1450 CL_HPP_PARAM_NAME_INFO_1_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1451 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
1452 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1453 CL_HPP_PARAM_NAME_INFO_1_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1454 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1455 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
1456 CL_HPP_PARAM_NAME_INFO_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1457 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
1458 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
1459 CL_HPP_PARAM_NAME_INFO_2_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1460 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
1461 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
1462 CL_HPP_PARAM_NAME_INFO_2_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1463 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
1464 #if CL_HPP_TARGET_OPENCL_VERSION >= 300
1465 CL_HPP_PARAM_NAME_INFO_3_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1466 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
1467 
1468 #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1469 CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1470 #endif // #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1471 
1472 #if defined(CL_HPP_USE_IL_KHR)
1473 CL_HPP_PARAM_NAME_INFO_IL_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1474 #endif // #if defined(CL_HPP_USE_IL_KHR)
1475 
1476 
1477 // Flags deprecated in OpenCL 2.0
1478 #define CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(F) \
1479  F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties)
1480 
1481 #define CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(F) \
1482  F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool)
1483 
1484 #define CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(F) \
1485  F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer)
1486 
1487 // Include deprecated query flags based on versions
1488 // Only include deprecated 1.0 flags if 2.0 not active as there is an enum clash
1489 #if CL_HPP_TARGET_OPENCL_VERSION > 100 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 && CL_HPP_TARGET_OPENCL_VERSION < 200
1490 CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1491 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 110
1492 #if CL_HPP_TARGET_OPENCL_VERSION > 110 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1493 CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1494 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1495 #if CL_HPP_TARGET_OPENCL_VERSION > 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1496 CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1497 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
1498 
1499 #if defined(CL_HPP_USE_CL_DEVICE_FISSION)
1500 CL_HPP_PARAM_NAME_DEVICE_FISSION_(CL_HPP_DECLARE_PARAM_TRAITS_);
1501 #endif // CL_HPP_USE_CL_DEVICE_FISSION
1502 
1503 #if defined(cl_khr_extended_versioning)
1504 #if CL_HPP_TARGET_OPENCL_VERSION < 300
1505 CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_CL3_SHARED_(CL_HPP_DECLARE_PARAM_TRAITS_)
1506 #endif // CL_HPP_TARGET_OPENCL_VERSION < 300
1507 CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_KHRONLY_(CL_HPP_DECLARE_PARAM_TRAITS_)
1508 #endif // cl_khr_extended_versioning
1509 
1510 #if defined(cl_khr_device_uuid)
1511 using uuid_array = array<cl_uchar, CL_UUID_SIZE_KHR>;
1512 using luid_array = array<cl_uchar, CL_LUID_SIZE_KHR>;
1513 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_UUID_KHR, uuid_array)
1514 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DRIVER_UUID_KHR, uuid_array)
1515 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LUID_VALID_KHR, cl_bool)
1516 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LUID_KHR, luid_array)
1517 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_NODE_MASK_KHR, cl_uint)
1518 #endif
1519 
1520 #if defined(cl_khr_pci_bus_info)
1521 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PCI_BUS_INFO_KHR, cl_device_pci_bus_info_khr)
1522 #endif
1523 
1524 #ifdef CL_PLATFORM_ICD_SUFFIX_KHR
1525 CL_HPP_DECLARE_PARAM_TRAITS_(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, string)
1526 #endif
1527 
1528 #ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
1529 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong)
1530 #endif
1531 #ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
1532 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, vector<size_type>)
1533 #endif
1534 #ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
1535 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint)
1536 #endif
1537 #ifdef CL_DEVICE_SIMD_WIDTH_AMD
1538 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint)
1539 #endif
1540 #ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD
1541 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint)
1542 #endif
1543 #ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD
1544 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint)
1545 #endif
1546 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
1547 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint)
1548 #endif
1549 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
1550 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint)
1551 #endif
1552 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
1553 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint)
1554 #endif
1555 #ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
1556 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint)
1557 #endif
1558 #ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
1559 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint)
1560 #endif
1561 
1562 #ifdef CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM
1563 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM, cl_ulong)
1564 #endif
1565 #ifdef CL_DEVICE_JOB_SLOTS_ARM
1566 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_JOB_SLOTS_ARM, cl_uint)
1567 #endif
1568 #ifdef CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM
1569 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM, cl_bitfield)
1570 #endif
1571 #ifdef CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_ARM
1572 CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_ARM, cl_uint)
1573 #endif
1574 #ifdef CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM
1575 CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM, cl_int)
1576 #endif
1577 
1578 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
1579 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint)
1580 #endif
1581 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV
1582 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint)
1583 #endif
1584 #ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV
1585 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint)
1586 #endif
1587 #ifdef CL_DEVICE_WARP_SIZE_NV
1588 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint)
1589 #endif
1590 #ifdef CL_DEVICE_GPU_OVERLAP_NV
1591 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool)
1592 #endif
1593 #ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV
1594 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool)
1595 #endif
1596 #ifdef CL_DEVICE_INTEGRATED_MEMORY_NV
1597 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool)
1598 #endif
1599 
1600 // Convenience functions
1601 
1602 template <typename Func, typename T>
1603 inline cl_int
1604 getInfo(Func f, cl_uint name, T* param)
1605 {
1606  return getInfoHelper(f, name, param, 0);
1607 }
1608 
1609 template <typename Func, typename Arg0>
1611 {
1612  Func f_; const Arg0& arg0_;
1613  cl_int operator ()(
1614  cl_uint param, size_type size, void* value, size_type* size_ret)
1615  { return f_(arg0_, param, size, value, size_ret); }
1616 };
1617 
1618 template <typename Func, typename Arg0, typename Arg1>
1620 {
1621  Func f_; const Arg0& arg0_; const Arg1& arg1_;
1622  cl_int operator ()(
1623  cl_uint param, size_type size, void* value, size_type* size_ret)
1624  { return f_(arg0_, arg1_, param, size, value, size_ret); }
1625 };
1626 
1627 template <typename Func, typename Arg0, typename T>
1628 inline cl_int
1629 getInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
1630 {
1631  GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
1632  return getInfoHelper(f0, name, param, 0);
1633 }
1634 
1635 template <typename Func, typename Arg0, typename Arg1, typename T>
1636 inline cl_int
1637 getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
1638 {
1639  GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
1640  return getInfoHelper(f0, name, param, 0);
1641 }
1642 
1643 
1644 template<typename T>
1646 { };
1647 
1648 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1652 template <>
1653 struct ReferenceHandler<cl_device_id>
1654 {
1664  static cl_int retain(cl_device_id device)
1665  { return ::clRetainDevice(device); }
1675  static cl_int release(cl_device_id device)
1676  { return ::clReleaseDevice(device); }
1677 };
1678 #else // CL_HPP_TARGET_OPENCL_VERSION >= 120
1682 template <>
1683 struct ReferenceHandler<cl_device_id>
1684 {
1685  // cl_device_id does not have retain().
1686  static cl_int retain(cl_device_id)
1687  { return CL_SUCCESS; }
1688  // cl_device_id does not have release().
1689  static cl_int release(cl_device_id)
1690  { return CL_SUCCESS; }
1691 };
1692 #endif // ! (CL_HPP_TARGET_OPENCL_VERSION >= 120)
1693 
1694 template <>
1695 struct ReferenceHandler<cl_platform_id>
1696 {
1697  // cl_platform_id does not have retain().
1698  static cl_int retain(cl_platform_id)
1699  { return CL_SUCCESS; }
1700  // cl_platform_id does not have release().
1701  static cl_int release(cl_platform_id)
1702  { return CL_SUCCESS; }
1703 };
1704 
1705 template <>
1706 struct ReferenceHandler<cl_context>
1707 {
1708  static cl_int retain(cl_context context)
1709  { return ::clRetainContext(context); }
1710  static cl_int release(cl_context context)
1711  { return ::clReleaseContext(context); }
1712 };
1713 
1714 template <>
1715 struct ReferenceHandler<cl_command_queue>
1716 {
1717  static cl_int retain(cl_command_queue queue)
1718  { return ::clRetainCommandQueue(queue); }
1719  static cl_int release(cl_command_queue queue)
1720  { return ::clReleaseCommandQueue(queue); }
1721 };
1722 
1723 template <>
1724 struct ReferenceHandler<cl_mem>
1725 {
1726  static cl_int retain(cl_mem memory)
1727  { return ::clRetainMemObject(memory); }
1728  static cl_int release(cl_mem memory)
1729  { return ::clReleaseMemObject(memory); }
1730 };
1731 
1732 template <>
1733 struct ReferenceHandler<cl_sampler>
1734 {
1735  static cl_int retain(cl_sampler sampler)
1736  { return ::clRetainSampler(sampler); }
1737  static cl_int release(cl_sampler sampler)
1738  { return ::clReleaseSampler(sampler); }
1739 };
1740 
1741 template <>
1742 struct ReferenceHandler<cl_program>
1743 {
1744  static cl_int retain(cl_program program)
1745  { return ::clRetainProgram(program); }
1746  static cl_int release(cl_program program)
1747  { return ::clReleaseProgram(program); }
1748 };
1749 
1750 template <>
1751 struct ReferenceHandler<cl_kernel>
1752 {
1753  static cl_int retain(cl_kernel kernel)
1754  { return ::clRetainKernel(kernel); }
1755  static cl_int release(cl_kernel kernel)
1756  { return ::clReleaseKernel(kernel); }
1757 };
1758 
1759 template <>
1760 struct ReferenceHandler<cl_event>
1761 {
1762  static cl_int retain(cl_event event)
1763  { return ::clRetainEvent(event); }
1764  static cl_int release(cl_event event)
1765  { return ::clReleaseEvent(event); }
1766 };
1767 
1768 
1769 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1770 // Extracts version number with major in the upper 16 bits, minor in the lower 16
1771 static cl_uint getVersion(const vector<char> &versionInfo)
1772 {
1773  int highVersion = 0;
1774  int lowVersion = 0;
1775  int index = 7;
1776  while(versionInfo[index] != '.' ) {
1777  highVersion *= 10;
1778  highVersion += versionInfo[index]-'0';
1779  ++index;
1780  }
1781  ++index;
1782  while(versionInfo[index] != ' ' && versionInfo[index] != '\0') {
1783  lowVersion *= 10;
1784  lowVersion += versionInfo[index]-'0';
1785  ++index;
1786  }
1787  return (highVersion << 16) | lowVersion;
1788 }
1789 
1790 static cl_uint getPlatformVersion(cl_platform_id platform)
1791 {
1792  size_type size = 0;
1793  clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size);
1794 
1795  vector<char> versionInfo(size);
1796  clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, versionInfo.data(), &size);
1797  return getVersion(versionInfo);
1798 }
1799 
1800 static cl_uint getDevicePlatformVersion(cl_device_id device)
1801 {
1802  cl_platform_id platform;
1803  clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL);
1804  return getPlatformVersion(platform);
1805 }
1806 
1807 static cl_uint getContextPlatformVersion(cl_context context)
1808 {
1809  // The platform cannot be queried directly, so we first have to grab a
1810  // device and obtain its context
1811  size_type size = 0;
1812  clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size);
1813  if (size == 0)
1814  return 0;
1815  vector<cl_device_id> devices(size/sizeof(cl_device_id));
1816  clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices.data(), NULL);
1817  return getDevicePlatformVersion(devices[0]);
1818 }
1819 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1820 
1821 template <typename T>
1822 class Wrapper
1823 {
1824 public:
1825  typedef T cl_type;
1826 
1827 protected:
1828  cl_type object_;
1829 
1830 public:
1831  Wrapper() : object_(NULL) { }
1832 
1833  Wrapper(const cl_type &obj, bool retainObject) : object_(obj)
1834  {
1835  if (retainObject) {
1836  detail::errHandler(retain(), __RETAIN_ERR);
1837  }
1838  }
1839 
1840  ~Wrapper()
1841  {
1842  if (object_ != NULL) { release(); }
1843  }
1844 
1845  Wrapper(const Wrapper<cl_type>& rhs)
1846  {
1847  object_ = rhs.object_;
1848  detail::errHandler(retain(), __RETAIN_ERR);
1849  }
1850 
1851  Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT_
1852  {
1853  object_ = rhs.object_;
1854  rhs.object_ = NULL;
1855  }
1856 
1857  Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
1858  {
1859  if (this != &rhs) {
1860  detail::errHandler(release(), __RELEASE_ERR);
1861  object_ = rhs.object_;
1862  detail::errHandler(retain(), __RETAIN_ERR);
1863  }
1864  return *this;
1865  }
1866 
1867  Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
1868  {
1869  if (this != &rhs) {
1870  detail::errHandler(release(), __RELEASE_ERR);
1871  object_ = rhs.object_;
1872  rhs.object_ = NULL;
1873  }
1874  return *this;
1875  }
1876 
1877  Wrapper<cl_type>& operator = (const cl_type &rhs)
1878  {
1879  detail::errHandler(release(), __RELEASE_ERR);
1880  object_ = rhs;
1881  return *this;
1882  }
1883 
1884  const cl_type& operator ()() const { return object_; }
1885 
1886  cl_type& operator ()() { return object_; }
1887 
1888  cl_type get() const { return object_; }
1889 
1890 protected:
1891  template<typename Func, typename U>
1892  friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
1893 
1894  cl_int retain() const
1895  {
1896  if (object_ != nullptr) {
1897  return ReferenceHandler<cl_type>::retain(object_);
1898  }
1899  else {
1900  return CL_SUCCESS;
1901  }
1902  }
1903 
1904  cl_int release() const
1905  {
1906  if (object_ != nullptr) {
1907  return ReferenceHandler<cl_type>::release(object_);
1908  }
1909  else {
1910  return CL_SUCCESS;
1911  }
1912  }
1913 };
1914 
1915 template <>
1916 class Wrapper<cl_device_id>
1917 {
1918 public:
1919  typedef cl_device_id cl_type;
1920 
1921 protected:
1922  cl_type object_;
1923  bool referenceCountable_;
1924 
1925  static bool isReferenceCountable(cl_device_id device)
1926  {
1927  bool retVal = false;
1928 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1929 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
1930  if (device != NULL) {
1931  int version = getDevicePlatformVersion(device);
1932  if(version > ((1 << 16) + 1)) {
1933  retVal = true;
1934  }
1935  }
1936 #else // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1937  retVal = true;
1938 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1939 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1940  return retVal;
1941  }
1942 
1943 public:
1944  Wrapper() : object_(NULL), referenceCountable_(false)
1945  {
1946  }
1947 
1948  Wrapper(const cl_type &obj, bool retainObject) :
1949  object_(obj),
1950  referenceCountable_(false)
1951  {
1952  referenceCountable_ = isReferenceCountable(obj);
1953 
1954  if (retainObject) {
1955  detail::errHandler(retain(), __RETAIN_ERR);
1956  }
1957  }
1958 
1959  ~Wrapper()
1960  {
1961  release();
1962  }
1963 
1964  Wrapper(const Wrapper<cl_type>& rhs)
1965  {
1966  object_ = rhs.object_;
1967  referenceCountable_ = isReferenceCountable(object_);
1968  detail::errHandler(retain(), __RETAIN_ERR);
1969  }
1970 
1971  Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT_
1972  {
1973  object_ = rhs.object_;
1974  referenceCountable_ = rhs.referenceCountable_;
1975  rhs.object_ = NULL;
1976  rhs.referenceCountable_ = false;
1977  }
1978 
1979  Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
1980  {
1981  if (this != &rhs) {
1982  detail::errHandler(release(), __RELEASE_ERR);
1983  object_ = rhs.object_;
1984  referenceCountable_ = rhs.referenceCountable_;
1985  detail::errHandler(retain(), __RETAIN_ERR);
1986  }
1987  return *this;
1988  }
1989 
1990  Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
1991  {
1992  if (this != &rhs) {
1993  detail::errHandler(release(), __RELEASE_ERR);
1994  object_ = rhs.object_;
1995  referenceCountable_ = rhs.referenceCountable_;
1996  rhs.object_ = NULL;
1997  rhs.referenceCountable_ = false;
1998  }
1999  return *this;
2000  }
2001 
2002  Wrapper<cl_type>& operator = (const cl_type &rhs)
2003  {
2004  detail::errHandler(release(), __RELEASE_ERR);
2005  object_ = rhs;
2006  referenceCountable_ = isReferenceCountable(object_);
2007  return *this;
2008  }
2009 
2010  const cl_type& operator ()() const { return object_; }
2011 
2012  cl_type& operator ()() { return object_; }
2013 
2014  cl_type get() const { return object_; }
2015 
2016 protected:
2017  template<typename Func, typename U>
2018  friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
2019 
2020  template<typename Func, typename U>
2021  friend inline cl_int getInfoHelper(Func, cl_uint, vector<U>*, int, typename U::cl_type);
2022 
2023  cl_int retain() const
2024  {
2025  if( object_ != nullptr && referenceCountable_ ) {
2026  return ReferenceHandler<cl_type>::retain(object_);
2027  }
2028  else {
2029  return CL_SUCCESS;
2030  }
2031  }
2032 
2033  cl_int release() const
2034  {
2035  if (object_ != nullptr && referenceCountable_) {
2036  return ReferenceHandler<cl_type>::release(object_);
2037  }
2038  else {
2039  return CL_SUCCESS;
2040  }
2041  }
2042 };
2043 
2044 template <typename T>
2045 inline bool operator==(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
2046 {
2047  return lhs() == rhs();
2048 }
2049 
2050 template <typename T>
2051 inline bool operator!=(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
2052 {
2053  return !operator==(lhs, rhs);
2054 }
2055 
2056 } // namespace detail
2058 
2059 
2060 using BuildLogType = vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, CL_PROGRAM_BUILD_LOG>::param_type>>;
2061 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2065 class BuildError : public Error
2066 {
2067 private:
2068  BuildLogType buildLogs;
2069 public:
2070  BuildError(cl_int err, const char * errStr, const BuildLogType &vec) : Error(err, errStr), buildLogs(vec)
2071  {
2072  }
2073 
2074  BuildLogType getBuildLog() const
2075  {
2076  return buildLogs;
2077  }
2078 };
2079 namespace detail {
2080  static inline cl_int buildErrHandler(
2081  cl_int err,
2082  const char * errStr,
2083  const BuildLogType &buildLogs)
2084  {
2085  if (err != CL_SUCCESS) {
2086  throw BuildError(err, errStr, buildLogs);
2087  }
2088  return err;
2089  }
2090 } // namespace detail
2091 
2092 #else
2093 namespace detail {
2094  static inline cl_int buildErrHandler(
2095  cl_int err,
2096  const char * errStr,
2097  const BuildLogType &buildLogs)
2098  {
2099  (void)buildLogs; // suppress unused variable warning
2100  (void)errStr;
2101  return err;
2102  }
2103 } // namespace detail
2104 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2105 
2106 
2112 struct ImageFormat : public cl_image_format
2113 {
2116 
2118  ImageFormat(cl_channel_order order, cl_channel_type type)
2119  {
2120  image_channel_order = order;
2121  image_channel_data_type = type;
2122  }
2123 
2125  ImageFormat(const ImageFormat &other) { *this = other; }
2126 
2129  {
2130  if (this != &rhs) {
2131  this->image_channel_data_type = rhs.image_channel_data_type;
2132  this->image_channel_order = rhs.image_channel_order;
2133  }
2134  return *this;
2135  }
2136 };
2137 
2145 class Device : public detail::Wrapper<cl_device_id>
2146 {
2147 private:
2148  static std::once_flag default_initialized_;
2149  static Device default_;
2150  static cl_int default_error_;
2151 
2157  static void makeDefault();
2158 
2164  static void makeDefaultProvided(const Device &p) {
2165  default_ = p;
2166  }
2167 
2168 public:
2169 #ifdef CL_HPP_UNIT_TEST_ENABLE
2176  static void unitTestClearDefault() {
2177  default_ = Device();
2178  }
2179 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2180 
2182  Device() : detail::Wrapper<cl_type>() { }
2183 
2188  explicit Device(const cl_device_id &device, bool retainObject = false) :
2189  detail::Wrapper<cl_type>(device, retainObject) { }
2190 
2196  cl_int *errResult = NULL)
2197  {
2198  std::call_once(default_initialized_, makeDefault);
2199  detail::errHandler(default_error_);
2200  if (errResult != NULL) {
2201  *errResult = default_error_;
2202  }
2203  return default_;
2204  }
2205 
2213  static Device setDefault(const Device &default_device)
2214  {
2215  std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_device));
2216  detail::errHandler(default_error_);
2217  return default_;
2218  }
2219 
2224  Device& operator = (const cl_device_id& rhs)
2225  {
2227  return *this;
2228  }
2229 
2233  Device(const Device& dev) : detail::Wrapper<cl_type>(dev) {}
2234 
2239  {
2241  return *this;
2242  }
2243 
2247  Device(Device&& dev) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(dev)) {}
2248 
2253  {
2254  detail::Wrapper<cl_type>::operator=(std::move(dev));
2255  return *this;
2256  }
2257 
2259  template <typename T>
2260  cl_int getInfo(cl_device_info name, T* param) const
2261  {
2262  return detail::errHandler(
2263  detail::getInfo(&::clGetDeviceInfo, object_, name, param),
2264  __GET_DEVICE_INFO_ERR);
2265  }
2266 
2268  template <cl_device_info name> typename
2270  getInfo(cl_int* err = NULL) const
2271  {
2272  typename detail::param_traits<
2273  detail::cl_device_info, name>::param_type param;
2274  cl_int result = getInfo(name, &param);
2275  if (err != NULL) {
2276  *err = result;
2277  }
2278  return param;
2279  }
2280 
2281 
2282 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2289  cl_ulong getHostTimer(cl_int *error = nullptr)
2290  {
2291  cl_ulong retVal = 0;
2292  cl_int err =
2293  clGetHostTimer(this->get(), &retVal);
2294  detail::errHandler(
2295  err,
2296  __GET_HOST_TIMER_ERR);
2297  if (error) {
2298  *error = err;
2299  }
2300  return retVal;
2301  }
2302 
2313  std::pair<cl_ulong, cl_ulong> getDeviceAndHostTimer(cl_int *error = nullptr)
2314  {
2315  std::pair<cl_ulong, cl_ulong> retVal;
2316  cl_int err =
2317  clGetDeviceAndHostTimer(this->get(), &(retVal.first), &(retVal.second));
2318  detail::errHandler(
2319  err,
2320  __GET_DEVICE_AND_HOST_TIMER_ERR);
2321  if (error) {
2322  *error = err;
2323  }
2324  return retVal;
2325  }
2326 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2327 
2331 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
2334  const cl_device_partition_property * properties,
2335  vector<Device>* devices)
2336  {
2337  cl_uint n = 0;
2338  cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n);
2339  if (err != CL_SUCCESS) {
2340  return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2341  }
2342 
2343  vector<cl_device_id> ids(n);
2344  err = clCreateSubDevices(object_, properties, n, ids.data(), NULL);
2345  if (err != CL_SUCCESS) {
2346  return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2347  }
2348 
2349  // Cannot trivially assign because we need to capture intermediates
2350  // with safe construction
2351  if (devices) {
2352  devices->resize(ids.size());
2353 
2354  // Assign to param, constructing with retain behaviour
2355  // to correctly capture each underlying CL object
2356  for (size_type i = 0; i < ids.size(); i++) {
2357  // We do not need to retain because this device is being created
2358  // by the runtime
2359  (*devices)[i] = Device(ids[i], false);
2360  }
2361  }
2362 
2363  return CL_SUCCESS;
2364  }
2365 #elif defined(CL_HPP_USE_CL_DEVICE_FISSION)
2366 
2370  cl_int createSubDevices(
2371  const cl_device_partition_property_ext * properties,
2372  vector<Device>* devices)
2373  {
2374  typedef CL_API_ENTRY cl_int
2375  ( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
2376  cl_device_id /*in_device*/,
2377  const cl_device_partition_property_ext * /* properties */,
2378  cl_uint /*num_entries*/,
2379  cl_device_id * /*out_devices*/,
2380  cl_uint * /*num_devices*/ ) CL_API_SUFFIX__VERSION_1_1;
2381 
2382  static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
2383  CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSubDevicesEXT);
2384 
2385  cl_uint n = 0;
2386  cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
2387  if (err != CL_SUCCESS) {
2388  return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2389  }
2390 
2391  vector<cl_device_id> ids(n);
2392  err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids.data(), NULL);
2393  if (err != CL_SUCCESS) {
2394  return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2395  }
2396  // Cannot trivially assign because we need to capture intermediates
2397  // with safe construction
2398  if (devices) {
2399  devices->resize(ids.size());
2400 
2401  // Assign to param, constructing with retain behaviour
2402  // to correctly capture each underlying CL object
2403  for (size_type i = 0; i < ids.size(); i++) {
2404  // We do not need to retain because this device is being created
2405  // by the runtime
2406  (*devices)[i] = Device(ids[i], false);
2407  }
2408  }
2409  return CL_SUCCESS;
2410  }
2411 #endif // defined(CL_HPP_USE_CL_DEVICE_FISSION)
2412 };
2413 
2414 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Device::default_initialized_;
2415 CL_HPP_DEFINE_STATIC_MEMBER_ Device Device::default_;
2416 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Device::default_error_ = CL_SUCCESS;
2417 
2425 class Platform : public detail::Wrapper<cl_platform_id>
2426 {
2427 private:
2428  static std::once_flag default_initialized_;
2429  static Platform default_;
2430  static cl_int default_error_;
2431 
2437  static void makeDefault() {
2438  /* Throwing an exception from a call_once invocation does not do
2439  * what we wish, so we catch it and save the error.
2440  */
2441 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2442  try
2443 #endif
2444  {
2445  // If default wasn't passed ,generate one
2446  // Otherwise set it
2447  cl_uint n = 0;
2448 
2449  cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2450  if (err != CL_SUCCESS) {
2451  default_error_ = err;
2452  return;
2453  }
2454  if (n == 0) {
2455  default_error_ = CL_INVALID_PLATFORM;
2456  return;
2457  }
2458 
2459  vector<cl_platform_id> ids(n);
2460  err = ::clGetPlatformIDs(n, ids.data(), NULL);
2461  if (err != CL_SUCCESS) {
2462  default_error_ = err;
2463  return;
2464  }
2465 
2466  default_ = Platform(ids[0]);
2467  }
2468 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2469  catch (cl::Error &e) {
2470  default_error_ = e.err();
2471  }
2472 #endif
2473  }
2474 
2480  static void makeDefaultProvided(const Platform &p) {
2481  default_ = p;
2482  }
2483 
2484 public:
2485 #ifdef CL_HPP_UNIT_TEST_ENABLE
2492  static void unitTestClearDefault() {
2493  default_ = Platform();
2494  }
2495 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2496 
2498  Platform() : detail::Wrapper<cl_type>() { }
2499 
2507  explicit Platform(const cl_platform_id &platform, bool retainObject = false) :
2508  detail::Wrapper<cl_type>(platform, retainObject) { }
2509 
2514  Platform& operator = (const cl_platform_id& rhs)
2515  {
2517  return *this;
2518  }
2519 
2520  static Platform getDefault(
2521  cl_int *errResult = NULL)
2522  {
2523  std::call_once(default_initialized_, makeDefault);
2524  detail::errHandler(default_error_);
2525  if (errResult != NULL) {
2526  *errResult = default_error_;
2527  }
2528  return default_;
2529  }
2530 
2538  static Platform setDefault(const Platform &default_platform)
2539  {
2540  std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_platform));
2541  detail::errHandler(default_error_);
2542  return default_;
2543  }
2544 
2546  template <typename T>
2547  cl_int getInfo(cl_platform_info name, T* param) const
2548  {
2549  return detail::errHandler(
2550  detail::getInfo(&::clGetPlatformInfo, object_, name, param),
2551  __GET_PLATFORM_INFO_ERR);
2552  }
2553 
2555  template <cl_platform_info name> typename
2557  getInfo(cl_int* err = NULL) const
2558  {
2559  typename detail::param_traits<
2560  detail::cl_platform_info, name>::param_type param;
2561  cl_int result = getInfo(name, &param);
2562  if (err != NULL) {
2563  *err = result;
2564  }
2565  return param;
2566  }
2567 
2572  cl_int getDevices(
2573  cl_device_type type,
2574  vector<Device>* devices) const
2575  {
2576  cl_uint n = 0;
2577  if( devices == NULL ) {
2578  return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2579  }
2580  cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
2581  if (err != CL_SUCCESS && err != CL_DEVICE_NOT_FOUND) {
2582  return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2583  }
2584 
2585  vector<cl_device_id> ids(n);
2586  if (n>0) {
2587  err = ::clGetDeviceIDs(object_, type, n, ids.data(), NULL);
2588  if (err != CL_SUCCESS) {
2589  return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2590  }
2591  }
2592 
2593  // Cannot trivially assign because we need to capture intermediates
2594  // with safe construction
2595  // We must retain things we obtain from the API to avoid releasing
2596  // API-owned objects.
2597  if (devices) {
2598  devices->resize(ids.size());
2599 
2600  // Assign to param, constructing with retain behaviour
2601  // to correctly capture each underlying CL object
2602  for (size_type i = 0; i < ids.size(); i++) {
2603  (*devices)[i] = Device(ids[i], true);
2604  }
2605  }
2606  return CL_SUCCESS;
2607  }
2608 
2609 #if defined(CL_HPP_USE_DX_INTEROP)
2633  cl_int getDevices(
2634  cl_d3d10_device_source_khr d3d_device_source,
2635  void * d3d_object,
2636  cl_d3d10_device_set_khr d3d_device_set,
2637  vector<Device>* devices) const
2638  {
2639  typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
2640  cl_platform_id platform,
2641  cl_d3d10_device_source_khr d3d_device_source,
2642  void * d3d_object,
2643  cl_d3d10_device_set_khr d3d_device_set,
2644  cl_uint num_entries,
2645  cl_device_id * devices,
2646  cl_uint* num_devices);
2647 
2648  if( devices == NULL ) {
2649  return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2650  }
2651 
2652  static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
2653  CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(object_, clGetDeviceIDsFromD3D10KHR);
2654 
2655  cl_uint n = 0;
2656  cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
2657  object_,
2658  d3d_device_source,
2659  d3d_object,
2660  d3d_device_set,
2661  0,
2662  NULL,
2663  &n);
2664  if (err != CL_SUCCESS) {
2665  return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2666  }
2667 
2668  vector<cl_device_id> ids(n);
2669  err = pfn_clGetDeviceIDsFromD3D10KHR(
2670  object_,
2671  d3d_device_source,
2672  d3d_object,
2673  d3d_device_set,
2674  n,
2675  ids.data(),
2676  NULL);
2677  if (err != CL_SUCCESS) {
2678  return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2679  }
2680 
2681  // Cannot trivially assign because we need to capture intermediates
2682  // with safe construction
2683  // We must retain things we obtain from the API to avoid releasing
2684  // API-owned objects.
2685  if (devices) {
2686  devices->resize(ids.size());
2687 
2688  // Assign to param, constructing with retain behaviour
2689  // to correctly capture each underlying CL object
2690  for (size_type i = 0; i < ids.size(); i++) {
2691  (*devices)[i] = Device(ids[i], true);
2692  }
2693  }
2694  return CL_SUCCESS;
2695  }
2696 #endif
2697 
2702  static cl_int get(
2703  vector<Platform>* platforms)
2704  {
2705  cl_uint n = 0;
2706 
2707  if( platforms == NULL ) {
2708  return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
2709  }
2710 
2711  cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2712  if (err != CL_SUCCESS) {
2713  return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2714  }
2715 
2716  vector<cl_platform_id> ids(n);
2717  err = ::clGetPlatformIDs(n, ids.data(), NULL);
2718  if (err != CL_SUCCESS) {
2719  return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2720  }
2721 
2722  if (platforms) {
2723  platforms->resize(ids.size());
2724 
2725  // Platforms don't reference count
2726  for (size_type i = 0; i < ids.size(); i++) {
2727  (*platforms)[i] = Platform(ids[i]);
2728  }
2729  }
2730  return CL_SUCCESS;
2731  }
2732 
2737  static cl_int get(
2738  Platform * platform)
2739  {
2740  cl_int err;
2741  Platform default_platform = Platform::getDefault(&err);
2742  if (platform) {
2743  *platform = default_platform;
2744  }
2745  return err;
2746  }
2747 
2756  static Platform get(
2757  cl_int * errResult = NULL)
2758  {
2759  cl_int err;
2760  Platform default_platform = Platform::getDefault(&err);
2761  if (errResult) {
2762  *errResult = err;
2763  }
2764  return default_platform;
2765  }
2766 
2767 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
2769  cl_int
2771  {
2772  return ::clUnloadPlatformCompiler(object_);
2773  }
2774 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
2775 }; // class Platform
2776 
2777 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Platform::default_initialized_;
2778 CL_HPP_DEFINE_STATIC_MEMBER_ Platform Platform::default_;
2779 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Platform::default_error_ = CL_SUCCESS;
2780 
2781 
2785 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2790 inline CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int
2791 UnloadCompiler() CL_API_SUFFIX__VERSION_1_1_DEPRECATED;
2792 inline cl_int
2794 {
2795  return ::clUnloadCompiler();
2796 }
2797 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2798 
2807 class Context
2808  : public detail::Wrapper<cl_context>
2809 {
2810 private:
2811  static std::once_flag default_initialized_;
2812  static Context default_;
2813  static cl_int default_error_;
2814 
2820  static void makeDefault() {
2821  /* Throwing an exception from a call_once invocation does not do
2822  * what we wish, so we catch it and save the error.
2823  */
2824 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2825  try
2826 #endif
2827  {
2828 #if !defined(__APPLE__) && !defined(__MACOS)
2829  const Platform &p = Platform::getDefault();
2830  cl_platform_id defaultPlatform = p();
2831  cl_context_properties properties[3] = {
2832  CL_CONTEXT_PLATFORM, (cl_context_properties)defaultPlatform, 0
2833  };
2834 #else // #if !defined(__APPLE__) && !defined(__MACOS)
2835  cl_context_properties *properties = nullptr;
2836 #endif // #if !defined(__APPLE__) && !defined(__MACOS)
2837 
2838  default_ = Context(
2839  CL_DEVICE_TYPE_DEFAULT,
2840  properties,
2841  NULL,
2842  NULL,
2843  &default_error_);
2844  }
2845 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2846  catch (cl::Error &e) {
2847  default_error_ = e.err();
2848  }
2849 #endif
2850  }
2851 
2852 
2858  static void makeDefaultProvided(const Context &c) {
2859  default_ = c;
2860  }
2861 
2862 public:
2863 #ifdef CL_HPP_UNIT_TEST_ENABLE
2870  static void unitTestClearDefault() {
2871  default_ = Context();
2872  }
2873 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2874 
2880  const vector<Device>& devices,
2881  const cl_context_properties* properties = NULL,
2882  void (CL_CALLBACK * notifyFptr)(
2883  const char *,
2884  const void *,
2885  size_type,
2886  void *) = NULL,
2887  void* data = NULL,
2888  cl_int* err = NULL)
2889  {
2890  cl_int error;
2891 
2892  size_type numDevices = devices.size();
2893  vector<cl_device_id> deviceIDs(numDevices);
2894 
2895  for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
2896  deviceIDs[deviceIndex] = (devices[deviceIndex])();
2897  }
2898 
2899  object_ = ::clCreateContext(
2900  properties, (cl_uint) numDevices,
2901  deviceIDs.data(),
2902  notifyFptr, data, &error);
2903 
2904  detail::errHandler(error, __CREATE_CONTEXT_ERR);
2905  if (err != NULL) {
2906  *err = error;
2907  }
2908  }
2909 
2915  const Device& device,
2916  const cl_context_properties* properties = NULL,
2917  void (CL_CALLBACK * notifyFptr)(
2918  const char *,
2919  const void *,
2920  size_type,
2921  void *) = NULL,
2922  void* data = NULL,
2923  cl_int* err = NULL)
2924  {
2925  cl_int error;
2926 
2927  cl_device_id deviceID = device();
2928 
2929  object_ = ::clCreateContext(
2930  properties, 1,
2931  &deviceID,
2932  notifyFptr, data, &error);
2933 
2934  detail::errHandler(error, __CREATE_CONTEXT_ERR);
2935  if (err != NULL) {
2936  *err = error;
2937  }
2938  }
2939 
2945  cl_device_type type,
2946  const cl_context_properties* properties = NULL,
2947  void (CL_CALLBACK * notifyFptr)(
2948  const char *,
2949  const void *,
2950  size_type,
2951  void *) = NULL,
2952  void* data = NULL,
2953  cl_int* err = NULL)
2954  {
2955  cl_int error;
2956 
2957 #if !defined(__APPLE__) && !defined(__MACOS)
2958  cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 };
2959 
2960  if (properties == NULL) {
2961  // Get a valid platform ID as we cannot send in a blank one
2962  vector<Platform> platforms;
2963  error = Platform::get(&platforms);
2964  if (error != CL_SUCCESS) {
2965  detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2966  if (err != NULL) {
2967  *err = error;
2968  }
2969  return;
2970  }
2971 
2972  // Check the platforms we found for a device of our specified type
2973  cl_context_properties platform_id = 0;
2974  for (unsigned int i = 0; i < platforms.size(); i++) {
2975 
2976  vector<Device> devices;
2977 
2978 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2979  try {
2980 #endif
2981 
2982  error = platforms[i].getDevices(type, &devices);
2983 
2984 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2985  } catch (cl::Error& e) {
2986  error = e.err();
2987  }
2988  // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type
2989  // We do error checking next anyway, and can throw there if needed
2990 #endif
2991 
2992  // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND
2993  if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) {
2994  detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2995  if (err != NULL) {
2996  *err = error;
2997  }
2998  }
2999 
3000  if (devices.size() > 0) {
3001  platform_id = (cl_context_properties)platforms[i]();
3002  break;
3003  }
3004  }
3005 
3006  if (platform_id == 0) {
3007  detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR);
3008  if (err != NULL) {
3009  *err = CL_DEVICE_NOT_FOUND;
3010  }
3011  return;
3012  }
3013 
3014  prop[1] = platform_id;
3015  properties = &prop[0];
3016  }
3017 #endif
3018  object_ = ::clCreateContextFromType(
3019  properties, type, notifyFptr, data, &error);
3020 
3021  detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
3022  if (err != NULL) {
3023  *err = error;
3024  }
3025  }
3026 
3030  Context(const Context& ctx) : detail::Wrapper<cl_type>(ctx) {}
3031 
3036  {
3038  return *this;
3039  }
3040 
3044  Context(Context&& ctx) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(ctx)) {}
3045 
3050  {
3051  detail::Wrapper<cl_type>::operator=(std::move(ctx));
3052  return *this;
3053  }
3054 
3055 
3060  static Context getDefault(cl_int * err = NULL)
3061  {
3062  std::call_once(default_initialized_, makeDefault);
3063  detail::errHandler(default_error_);
3064  if (err != NULL) {
3065  *err = default_error_;
3066  }
3067  return default_;
3068  }
3069 
3077  static Context setDefault(const Context &default_context)
3078  {
3079  std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_context));
3080  detail::errHandler(default_error_);
3081  return default_;
3082  }
3083 
3085  Context() : detail::Wrapper<cl_type>() { }
3086 
3092  explicit Context(const cl_context& context, bool retainObject = false) :
3093  detail::Wrapper<cl_type>(context, retainObject) { }
3094 
3100  Context& operator = (const cl_context& rhs)
3101  {
3103  return *this;
3104  }
3105 
3107  template <typename T>
3108  cl_int getInfo(cl_context_info name, T* param) const
3109  {
3110  return detail::errHandler(
3111  detail::getInfo(&::clGetContextInfo, object_, name, param),
3112  __GET_CONTEXT_INFO_ERR);
3113  }
3114 
3116  template <cl_context_info name> typename
3118  getInfo(cl_int* err = NULL) const
3119  {
3120  typename detail::param_traits<
3121  detail::cl_context_info, name>::param_type param;
3122  cl_int result = getInfo(name, &param);
3123  if (err != NULL) {
3124  *err = result;
3125  }
3126  return param;
3127  }
3128 
3134  cl_mem_flags flags,
3135  cl_mem_object_type type,
3136  vector<ImageFormat>* formats) const
3137  {
3138  cl_uint numEntries;
3139 
3140  if (!formats) {
3141  return CL_SUCCESS;
3142  }
3143 
3144  cl_int err = ::clGetSupportedImageFormats(
3145  object_,
3146  flags,
3147  type,
3148  0,
3149  NULL,
3150  &numEntries);
3151  if (err != CL_SUCCESS) {
3152  return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3153  }
3154 
3155  if (numEntries > 0) {
3156  vector<ImageFormat> value(numEntries);
3157  err = ::clGetSupportedImageFormats(
3158  object_,
3159  flags,
3160  type,
3161  numEntries,
3162  (cl_image_format*)value.data(),
3163  NULL);
3164  if (err != CL_SUCCESS) {
3165  return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3166  }
3167 
3168  formats->assign(begin(value), end(value));
3169  }
3170  else {
3171  // If no values are being returned, ensure an empty vector comes back
3172  formats->clear();
3173  }
3174 
3175  return CL_SUCCESS;
3176  }
3177 };
3178 
3179 inline void Device::makeDefault()
3180 {
3181  /* Throwing an exception from a call_once invocation does not do
3182  * what we wish, so we catch it and save the error.
3183  */
3184 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3185  try
3186 #endif
3187  {
3188  cl_int error = 0;
3189 
3190  Context context = Context::getDefault(&error);
3191  detail::errHandler(error, __CREATE_CONTEXT_ERR);
3192 
3193  if (error != CL_SUCCESS) {
3194  default_error_ = error;
3195  }
3196  else {
3197  default_ = context.getInfo<CL_CONTEXT_DEVICES>()[0];
3198  default_error_ = CL_SUCCESS;
3199  }
3200  }
3201 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3202  catch (cl::Error &e) {
3203  default_error_ = e.err();
3204  }
3205 #endif
3206 }
3207 
3208 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Context::default_initialized_;
3209 CL_HPP_DEFINE_STATIC_MEMBER_ Context Context::default_;
3210 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Context::default_error_ = CL_SUCCESS;
3211 
3220 class Event : public detail::Wrapper<cl_event>
3221 {
3222 public:
3224  Event() : detail::Wrapper<cl_type>() { }
3225 
3234  explicit Event(const cl_event& event, bool retainObject = false) :
3235  detail::Wrapper<cl_type>(event, retainObject) { }
3236 
3242  Event& operator = (const cl_event& rhs)
3243  {
3245  return *this;
3246  }
3247 
3249  template <typename T>
3250  cl_int getInfo(cl_event_info name, T* param) const
3251  {
3252  return detail::errHandler(
3253  detail::getInfo(&::clGetEventInfo, object_, name, param),
3254  __GET_EVENT_INFO_ERR);
3255  }
3256 
3258  template <cl_event_info name> typename
3260  getInfo(cl_int* err = NULL) const
3261  {
3262  typename detail::param_traits<
3263  detail::cl_event_info, name>::param_type param;
3264  cl_int result = getInfo(name, &param);
3265  if (err != NULL) {
3266  *err = result;
3267  }
3268  return param;
3269  }
3270 
3272  template <typename T>
3273  cl_int getProfilingInfo(cl_profiling_info name, T* param) const
3274  {
3275  return detail::errHandler(detail::getInfo(
3276  &::clGetEventProfilingInfo, object_, name, param),
3277  __GET_EVENT_PROFILE_INFO_ERR);
3278  }
3279 
3281  template <cl_profiling_info name> typename
3283  getProfilingInfo(cl_int* err = NULL) const
3284  {
3285  typename detail::param_traits<
3286  detail::cl_profiling_info, name>::param_type param;
3287  cl_int result = getProfilingInfo(name, &param);
3288  if (err != NULL) {
3289  *err = result;
3290  }
3291  return param;
3292  }
3293 
3298  cl_int wait() const
3299  {
3300  return detail::errHandler(
3301  ::clWaitForEvents(1, &object_),
3302  __WAIT_FOR_EVENTS_ERR);
3303  }
3304 
3305 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3310  cl_int setCallback(
3311  cl_int type,
3312  void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
3313  void * user_data = NULL)
3314  {
3315  return detail::errHandler(
3316  ::clSetEventCallback(
3317  object_,
3318  type,
3319  pfn_notify,
3320  user_data),
3321  __SET_EVENT_CALLBACK_ERR);
3322  }
3323 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3324 
3329  static cl_int
3330  waitForEvents(const vector<Event>& events)
3331  {
3332  return detail::errHandler(
3333  ::clWaitForEvents(
3334  (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3335  __WAIT_FOR_EVENTS_ERR);
3336  }
3337 };
3338 
3339 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3344 class UserEvent : public Event
3345 {
3346 public:
3352  const Context& context,
3353  cl_int * err = NULL)
3354  {
3355  cl_int error;
3356  object_ = ::clCreateUserEvent(
3357  context(),
3358  &error);
3359 
3360  detail::errHandler(error, __CREATE_USER_EVENT_ERR);
3361  if (err != NULL) {
3362  *err = error;
3363  }
3364  }
3365 
3367  UserEvent() : Event() { }
3368 
3373  cl_int setStatus(cl_int status)
3374  {
3375  return detail::errHandler(
3376  ::clSetUserEventStatus(object_,status),
3377  __SET_USER_EVENT_STATUS_ERR);
3378  }
3379 };
3380 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3381 
3386 inline static cl_int
3387 WaitForEvents(const vector<Event>& events)
3388 {
3389  return detail::errHandler(
3390  ::clWaitForEvents(
3391  (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3392  __WAIT_FOR_EVENTS_ERR);
3393 }
3394 
3403 class Memory : public detail::Wrapper<cl_mem>
3404 {
3405 public:
3407  Memory() : detail::Wrapper<cl_type>() { }
3408 
3420  explicit Memory(const cl_mem& memory, bool retainObject) :
3421  detail::Wrapper<cl_type>(memory, retainObject) { }
3422 
3428  Memory& operator = (const cl_mem& rhs)
3429  {
3431  return *this;
3432  }
3433 
3437  Memory(const Memory& mem) : detail::Wrapper<cl_type>(mem) {}
3438 
3443  {
3445  return *this;
3446  }
3447 
3451  Memory(Memory&& mem) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(mem)) {}
3452 
3457  {
3458  detail::Wrapper<cl_type>::operator=(std::move(mem));
3459  return *this;
3460  }
3461 
3462 
3464  template <typename T>
3465  cl_int getInfo(cl_mem_info name, T* param) const
3466  {
3467  return detail::errHandler(
3468  detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
3469  __GET_MEM_OBJECT_INFO_ERR);
3470  }
3471 
3473  template <cl_mem_info name> typename
3475  getInfo(cl_int* err = NULL) const
3476  {
3477  typename detail::param_traits<
3478  detail::cl_mem_info, name>::param_type param;
3479  cl_int result = getInfo(name, &param);
3480  if (err != NULL) {
3481  *err = result;
3482  }
3483  return param;
3484  }
3485 
3486 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3501  void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
3502  void * user_data = NULL)
3503  {
3504  return detail::errHandler(
3505  ::clSetMemObjectDestructorCallback(
3506  object_,
3507  pfn_notify,
3508  user_data),
3509  __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
3510  }
3511 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3512 
3513 };
3514 
3515 // Pre-declare copy functions
3516 class Buffer;
3517 template< typename IteratorType >
3518 cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3519 template< typename IteratorType >
3520 cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3521 template< typename IteratorType >
3522 cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3523 template< typename IteratorType >
3524 cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3525 
3526 
3527 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
3528 namespace detail
3529 {
3531  {
3532  public:
3533  static cl_svm_mem_flags getSVMMemFlags()
3534  {
3535  return 0;
3536  }
3537  };
3538 } // namespace detail
3539 
3540 template<class Trait = detail::SVMTraitNull>
3542 {
3543 public:
3544  static cl_svm_mem_flags getSVMMemFlags()
3545  {
3546  return CL_MEM_READ_WRITE |
3547  Trait::getSVMMemFlags();
3548  }
3549 };
3550 
3551 template<class Trait = detail::SVMTraitNull>
3553 {
3554 public:
3555  static cl_svm_mem_flags getSVMMemFlags()
3556  {
3557  return CL_MEM_READ_ONLY |
3558  Trait::getSVMMemFlags();
3559  }
3560 };
3561 
3562 template<class Trait = detail::SVMTraitNull>
3564 {
3565 public:
3566  static cl_svm_mem_flags getSVMMemFlags()
3567  {
3568  return CL_MEM_WRITE_ONLY |
3569  Trait::getSVMMemFlags();
3570  }
3571 };
3572 
3573 template<class Trait = SVMTraitReadWrite<>>
3575 {
3576 public:
3577  static cl_svm_mem_flags getSVMMemFlags()
3578  {
3579  return Trait::getSVMMemFlags();
3580  }
3581 };
3582 
3583 template<class Trait = SVMTraitReadWrite<>>
3585 {
3586 public:
3587  static cl_svm_mem_flags getSVMMemFlags()
3588  {
3589  return CL_MEM_SVM_FINE_GRAIN_BUFFER |
3590  Trait::getSVMMemFlags();
3591  }
3592 };
3593 
3594 template<class Trait = SVMTraitReadWrite<>>
3596 {
3597 public:
3598  static cl_svm_mem_flags getSVMMemFlags()
3599  {
3600  return
3601  CL_MEM_SVM_FINE_GRAIN_BUFFER |
3602  CL_MEM_SVM_ATOMICS |
3603  Trait::getSVMMemFlags();
3604  }
3605 };
3606 
3607 // Pre-declare SVM map function
3608 template<typename T>
3609 inline cl_int enqueueMapSVM(
3610  T* ptr,
3611  cl_bool blocking,
3612  cl_map_flags flags,
3613  size_type size,
3614  const vector<Event>* events = NULL,
3615  Event* event = NULL);
3616 
3628 template<typename T, class SVMTrait>
3630 private:
3631  Context context_;
3632 
3633 public:
3634  typedef T value_type;
3635  typedef value_type* pointer;
3636  typedef const value_type* const_pointer;
3637  typedef value_type& reference;
3638  typedef const value_type& const_reference;
3639  typedef std::size_t size_type;
3640  typedef std::ptrdiff_t difference_type;
3641 
3642  template<typename U>
3643  struct rebind
3644  {
3646  };
3647 
3648  template<typename U, typename V>
3649  friend class SVMAllocator;
3650 
3651  SVMAllocator() :
3652  context_(Context::getDefault())
3653  {
3654  }
3655 
3656  explicit SVMAllocator(cl::Context context) :
3657  context_(context)
3658  {
3659  }
3660 
3661 
3662  SVMAllocator(const SVMAllocator &other) :
3663  context_(other.context_)
3664  {
3665  }
3666 
3667  template<typename U>
3668  SVMAllocator(const SVMAllocator<U, SVMTrait> &other) :
3669  context_(other.context_)
3670  {
3671  }
3672 
3673  ~SVMAllocator()
3674  {
3675  }
3676 
3677  pointer address(reference r) CL_HPP_NOEXCEPT_
3678  {
3679  return std::addressof(r);
3680  }
3681 
3682  const_pointer address(const_reference r) CL_HPP_NOEXCEPT_
3683  {
3684  return std::addressof(r);
3685  }
3686 
3693  pointer allocate(
3694  size_type size,
3696  {
3697  // Allocate memory with default alignment matching the size of the type
3698  void* voidPointer =
3699  clSVMAlloc(
3700  context_(),
3701  SVMTrait::getSVMMemFlags(),
3702  size*sizeof(T),
3703  0);
3704  pointer retValue = reinterpret_cast<pointer>(
3705  voidPointer);
3706 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3707  if (!retValue) {
3708  std::bad_alloc excep;
3709  throw excep;
3710  }
3711 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3712 
3713  // If allocation was coarse-grained then map it
3714  if (!(SVMTrait::getSVMMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) {
3715  cl_int err = enqueueMapSVM(retValue, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, size*sizeof(T));
3716  if (err != CL_SUCCESS) {
3717  std::bad_alloc excep;
3718  throw excep;
3719  }
3720  }
3721 
3722  // If exceptions disabled, return null pointer from allocator
3723  return retValue;
3724  }
3725 
3726  void deallocate(pointer p, size_type)
3727  {
3728  clSVMFree(context_(), p);
3729  }
3730 
3735  size_type max_size() const CL_HPP_NOEXCEPT_
3736  {
3737  size_type maxSize = std::numeric_limits<size_type>::max() / sizeof(T);
3738 
3739  for (const Device &d : context_.getInfo<CL_CONTEXT_DEVICES>()) {
3740  maxSize = std::min(
3741  maxSize,
3742  static_cast<size_type>(d.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>()));
3743  }
3744 
3745  return maxSize;
3746  }
3747 
3748  template< class U, class... Args >
3749  void construct(U* p, Args&&... args)
3750  {
3751  new(p)T(args...);
3752  }
3753 
3754  template< class U >
3755  void destroy(U* p)
3756  {
3757  p->~U();
3758  }
3759 
3763  inline bool operator==(SVMAllocator const& rhs)
3764  {
3765  return (context_==rhs.context_);
3766  }
3767 
3768  inline bool operator!=(SVMAllocator const& a)
3769  {
3770  return !operator==(a);
3771  }
3772 }; // class SVMAllocator return cl::pointer<T>(tmp, detail::Deleter<T, Alloc>{alloc, copies});
3773 
3774 
3775 template<class SVMTrait>
3776 class SVMAllocator<void, SVMTrait> {
3777 public:
3778  typedef void value_type;
3779  typedef value_type* pointer;
3780  typedef const value_type* const_pointer;
3781 
3782  template<typename U>
3783  struct rebind
3784  {
3786  };
3787 
3788  template<typename U, typename V>
3789  friend class SVMAllocator;
3790 };
3791 
3792 #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3793 namespace detail
3794 {
3795  template<class Alloc>
3796  class Deleter {
3797  private:
3798  Alloc alloc_;
3799  size_type copies_;
3800 
3801  public:
3802  typedef typename std::allocator_traits<Alloc>::pointer pointer;
3803 
3804  Deleter(const Alloc &alloc, size_type copies) : alloc_{ alloc }, copies_{ copies }
3805  {
3806  }
3807 
3808  void operator()(pointer ptr) const {
3809  Alloc tmpAlloc{ alloc_ };
3810  std::allocator_traits<Alloc>::destroy(tmpAlloc, std::addressof(*ptr));
3811  std::allocator_traits<Alloc>::deallocate(tmpAlloc, ptr, copies_);
3812  }
3813  };
3814 } // namespace detail
3815 
3822 template <class T, class Alloc, class... Args>
3823 cl::pointer<T, detail::Deleter<Alloc>> allocate_pointer(const Alloc &alloc_, Args&&... args)
3824 {
3825  Alloc alloc(alloc_);
3826  static const size_type copies = 1;
3827 
3828  // Ensure that creation of the management block and the
3829  // object are dealt with separately such that we only provide a deleter
3830 
3831  T* tmp = std::allocator_traits<Alloc>::allocate(alloc, copies);
3832  if (!tmp) {
3833  std::bad_alloc excep;
3834  throw excep;
3835  }
3836  try {
3837  std::allocator_traits<Alloc>::construct(
3838  alloc,
3839  std::addressof(*tmp),
3840  std::forward<Args>(args)...);
3841 
3842  return cl::pointer<T, detail::Deleter<Alloc>>(tmp, detail::Deleter<Alloc>{alloc, copies});
3843  }
3844  catch (std::bad_alloc& b)
3845  {
3846  std::allocator_traits<Alloc>::deallocate(alloc, tmp, copies);
3847  throw;
3848  }
3849 }
3850 
3851 template< class T, class SVMTrait, class... Args >
3852 cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(Args... args)
3853 {
3854  SVMAllocator<T, SVMTrait> alloc;
3855  return cl::allocate_pointer<T>(alloc, args...);
3856 }
3857 
3858 template< class T, class SVMTrait, class... Args >
3859 cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(const cl::Context &c, Args... args)
3860 {
3861  SVMAllocator<T, SVMTrait> alloc(c);
3862  return cl::allocate_pointer<T>(alloc, args...);
3863 }
3864 #endif // #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3865 
3869 template < class T >
3870 using coarse_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>>;
3871 
3875 template < class T >
3876 using fine_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitFine<>>>;
3877 
3881 template < class T >
3882 using atomic_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitAtomic<>>>;
3883 
3884 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
3885 
3886 
3893 class Buffer : public Memory
3894 {
3895 public:
3896 
3905  const Context& context,
3906  cl_mem_flags flags,
3907  size_type size,
3908  void* host_ptr = NULL,
3909  cl_int* err = NULL)
3910  {
3911  cl_int error;
3912  object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3913 
3914  detail::errHandler(error, __CREATE_BUFFER_ERR);
3915  if (err != NULL) {
3916  *err = error;
3917  }
3918  }
3919 
3930  cl_mem_flags flags,
3931  size_type size,
3932  void* host_ptr = NULL,
3933  cl_int* err = NULL)
3934  {
3935  cl_int error;
3936 
3937  Context context = Context::getDefault(err);
3938 
3939  object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3940 
3941  detail::errHandler(error, __CREATE_BUFFER_ERR);
3942  if (err != NULL) {
3943  *err = error;
3944  }
3945  }
3946 
3952  template< typename IteratorType >
3954  IteratorType startIterator,
3955  IteratorType endIterator,
3956  bool readOnly,
3957  bool useHostPtr = false,
3958  cl_int* err = NULL)
3959  {
3960  typedef typename std::iterator_traits<IteratorType>::value_type DataType;
3961  cl_int error;
3962 
3963  cl_mem_flags flags = 0;
3964  if( readOnly ) {
3965  flags |= CL_MEM_READ_ONLY;
3966  }
3967  else {
3968  flags |= CL_MEM_READ_WRITE;
3969  }
3970  if( useHostPtr ) {
3971  flags |= CL_MEM_USE_HOST_PTR;
3972  }
3973 
3974  size_type size = sizeof(DataType)*(endIterator - startIterator);
3975 
3976  Context context = Context::getDefault(err);
3977 
3978  if( useHostPtr ) {
3979  object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
3980  } else {
3981  object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
3982  }
3983 
3984  detail::errHandler(error, __CREATE_BUFFER_ERR);
3985  if (err != NULL) {
3986  *err = error;
3987  }
3988 
3989  if( !useHostPtr ) {
3990  error = cl::copy(startIterator, endIterator, *this);
3991  detail::errHandler(error, __CREATE_BUFFER_ERR);
3992  if (err != NULL) {
3993  *err = error;
3994  }
3995  }
3996  }
3997 
4003  template< typename IteratorType >
4004  Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator,
4005  bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
4006 
4011  template< typename IteratorType >
4012  Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator,
4013  bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
4014 
4016  Buffer() : Memory() { }
4017 
4025  explicit Buffer(const cl_mem& buffer, bool retainObject = false) :
4026  Memory(buffer, retainObject) { }
4027 
4032  Buffer& operator = (const cl_mem& rhs)
4033  {
4034  Memory::operator=(rhs);
4035  return *this;
4036  }
4037 
4041  Buffer(const Buffer& buf) : Memory(buf) {}
4042 
4047  {
4048  Memory::operator=(buf);
4049  return *this;
4050  }
4051 
4055  Buffer(Buffer&& buf) CL_HPP_NOEXCEPT_ : Memory(std::move(buf)) {}
4056 
4061  {
4062  Memory::operator=(std::move(buf));
4063  return *this;
4064  }
4065 
4066 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
4072  cl_mem_flags flags,
4073  cl_buffer_create_type buffer_create_type,
4074  const void * buffer_create_info,
4075  cl_int * err = NULL)
4076  {
4077  Buffer result;
4078  cl_int error;
4079  result.object_ = ::clCreateSubBuffer(
4080  object_,
4081  flags,
4082  buffer_create_type,
4083  buffer_create_info,
4084  &error);
4085 
4086  detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
4087  if (err != NULL) {
4088  *err = error;
4089  }
4090 
4091  return result;
4092  }
4093 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
4094 };
4095 
4096 #if defined (CL_HPP_USE_DX_INTEROP)
4105 class BufferD3D10 : public Buffer
4106 {
4107 public:
4108 
4109 
4115  BufferD3D10(
4116  const Context& context,
4117  cl_mem_flags flags,
4118  ID3D10Buffer* bufobj,
4119  cl_int * err = NULL) : pfn_clCreateFromD3D10BufferKHR(nullptr)
4120  {
4121  typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
4122  cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
4123  cl_int* errcode_ret);
4124  PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR;
4125 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4126  vector<cl_context_properties> props = context.getInfo<CL_CONTEXT_PROPERTIES>();
4127  cl_platform platform = -1;
4128  for( int i = 0; i < props.size(); ++i ) {
4129  if( props[i] == CL_CONTEXT_PLATFORM ) {
4130  platform = props[i+1];
4131  }
4132  }
4133  CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateFromD3D10BufferKHR);
4134 #elif CL_HPP_TARGET_OPENCL_VERSION >= 110
4135  CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateFromD3D10BufferKHR);
4136 #endif
4137 
4138  cl_int error;
4139  object_ = pfn_clCreateFromD3D10BufferKHR(
4140  context(),
4141  flags,
4142  bufobj,
4143  &error);
4144 
4145  detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4146  if (err != NULL) {
4147  *err = error;
4148  }
4149  }
4150 
4152  BufferD3D10() : Buffer() { }
4153 
4161  explicit BufferD3D10(const cl_mem& buffer, bool retainObject = false) :
4162  Buffer(buffer, retainObject) { }
4163 
4168  BufferD3D10& operator = (const cl_mem& rhs)
4169  {
4170  Buffer::operator=(rhs);
4171  return *this;
4172  }
4173 
4177  BufferD3D10(const BufferD3D10& buf) :
4178  Buffer(buf) {}
4179 
4183  BufferD3D10& operator = (const BufferD3D10 &buf)
4184  {
4185  Buffer::operator=(buf);
4186  return *this;
4187  }
4188 
4192  BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4193 
4197  BufferD3D10& operator = (BufferD3D10 &&buf)
4198  {
4199  Buffer::operator=(std::move(buf));
4200  return *this;
4201  }
4202 };
4203 #endif
4204 
4213 class BufferGL : public Buffer
4214 {
4215 public:
4222  const Context& context,
4223  cl_mem_flags flags,
4224  cl_GLuint bufobj,
4225  cl_int * err = NULL)
4226  {
4227  cl_int error;
4228  object_ = ::clCreateFromGLBuffer(
4229  context(),
4230  flags,
4231  bufobj,
4232  &error);
4233 
4234  detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4235  if (err != NULL) {
4236  *err = error;
4237  }
4238  }
4239 
4241  BufferGL() : Buffer() { }
4242 
4250  explicit BufferGL(const cl_mem& buffer, bool retainObject = false) :
4251  Buffer(buffer, retainObject) { }
4252 
4257  BufferGL& operator = (const cl_mem& rhs)
4258  {
4259  Buffer::operator=(rhs);
4260  return *this;
4261  }
4262 
4266  BufferGL(const BufferGL& buf) : Buffer(buf) {}
4267 
4272  {
4273  Buffer::operator=(buf);
4274  return *this;
4275  }
4276 
4280  BufferGL(BufferGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4281 
4286  {
4287  Buffer::operator=(std::move(buf));
4288  return *this;
4289  }
4290 
4293  cl_gl_object_type *type,
4294  cl_GLuint * gl_object_name)
4295  {
4296  return detail::errHandler(
4297  ::clGetGLObjectInfo(object_,type,gl_object_name),
4298  __GET_GL_OBJECT_INFO_ERR);
4299  }
4300 };
4301 
4310 class BufferRenderGL : public Buffer
4311 {
4312 public:
4319  const Context& context,
4320  cl_mem_flags flags,
4321  cl_GLuint bufobj,
4322  cl_int * err = NULL)
4323  {
4324  cl_int error;
4325  object_ = ::clCreateFromGLRenderbuffer(
4326  context(),
4327  flags,
4328  bufobj,
4329  &error);
4330 
4331  detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR);
4332  if (err != NULL) {
4333  *err = error;
4334  }
4335  }
4336 
4339 
4347  explicit BufferRenderGL(const cl_mem& buffer, bool retainObject = false) :
4348  Buffer(buffer, retainObject) { }
4349 
4354  BufferRenderGL& operator = (const cl_mem& rhs)
4355  {
4356  Buffer::operator=(rhs);
4357  return *this;
4358  }
4359 
4363  BufferRenderGL(const BufferRenderGL& buf) : Buffer(buf) {}
4364 
4369  {
4370  Buffer::operator=(buf);
4371  return *this;
4372  }
4373 
4377  BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4378 
4383  {
4384  Buffer::operator=(std::move(buf));
4385  return *this;
4386  }
4387 
4390  cl_gl_object_type *type,
4391  cl_GLuint * gl_object_name)
4392  {
4393  return detail::errHandler(
4394  ::clGetGLObjectInfo(object_,type,gl_object_name),
4395  __GET_GL_OBJECT_INFO_ERR);
4396  }
4397 };
4398 
4405 class Image : public Memory
4406 {
4407 protected:
4409  Image() : Memory() { }
4410 
4418  explicit Image(const cl_mem& image, bool retainObject = false) :
4419  Memory(image, retainObject) { }
4420 
4425  Image& operator = (const cl_mem& rhs)
4426  {
4427  Memory::operator=(rhs);
4428  return *this;
4429  }
4430 
4434  Image(const Image& img) : Memory(img) {}
4435 
4439  Image& operator = (const Image &img)
4440  {
4441  Memory::operator=(img);
4442  return *this;
4443  }
4444 
4448  Image(Image&& img) CL_HPP_NOEXCEPT_ : Memory(std::move(img)) {}
4449 
4454  {
4455  Memory::operator=(std::move(img));
4456  return *this;
4457  }
4458 
4459 
4460 public:
4462  template <typename T>
4463  cl_int getImageInfo(cl_image_info name, T* param) const
4464  {
4465  return detail::errHandler(
4466  detail::getInfo(&::clGetImageInfo, object_, name, param),
4467  __GET_IMAGE_INFO_ERR);
4468  }
4469 
4471  template <cl_image_info name> typename
4473  getImageInfo(cl_int* err = NULL) const
4474  {
4475  typename detail::param_traits<
4476  detail::cl_image_info, name>::param_type param;
4477  cl_int result = getImageInfo(name, &param);
4478  if (err != NULL) {
4479  *err = result;
4480  }
4481  return param;
4482  }
4483 };
4484 
4485 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4492 class Image1D : public Image
4493 {
4494 public:
4500  const Context& context,
4501  cl_mem_flags flags,
4502  ImageFormat format,
4503  size_type width,
4504  void* host_ptr = NULL,
4505  cl_int* err = NULL)
4506  {
4507  cl_int error;
4508 
4509  cl_image_desc desc = {0};
4510  desc.image_type = CL_MEM_OBJECT_IMAGE1D;
4511  desc.image_width = width;
4512 
4513  object_ = ::clCreateImage(
4514  context(),
4515  flags,
4516  &format,
4517  &desc,
4518  host_ptr,
4519  &error);
4520 
4521  detail::errHandler(error, __CREATE_IMAGE_ERR);
4522  if (err != NULL) {
4523  *err = error;
4524  }
4525  }
4526 
4528  Image1D() { }
4529 
4537  explicit Image1D(const cl_mem& image1D, bool retainObject = false) :
4538  Image(image1D, retainObject) { }
4539 
4544  Image1D& operator = (const cl_mem& rhs)
4545  {
4546  Image::operator=(rhs);
4547  return *this;
4548  }
4549 
4553  Image1D(const Image1D& img) : Image(img) {}
4554 
4559  {
4560  Image::operator=(img);
4561  return *this;
4562  }
4563 
4567  Image1D(Image1D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4568 
4573  {
4574  Image::operator=(std::move(img));
4575  return *this;
4576  }
4577 
4578 };
4579 
4583 class Image1DBuffer : public Image
4584 {
4585 public:
4586  Image1DBuffer(
4587  const Context& context,
4588  cl_mem_flags flags,
4589  ImageFormat format,
4590  size_type width,
4591  const Buffer &buffer,
4592  cl_int* err = NULL)
4593  {
4594  cl_int error;
4595 
4596  cl_image_desc desc = {0};
4597  desc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER;
4598  desc.image_width = width;
4599  desc.buffer = buffer();
4600 
4601  object_ = ::clCreateImage(
4602  context(),
4603  flags,
4604  &format,
4605  &desc,
4606  NULL,
4607  &error);
4608 
4609  detail::errHandler(error, __CREATE_IMAGE_ERR);
4610  if (err != NULL) {
4611  *err = error;
4612  }
4613  }
4614 
4615  Image1DBuffer() { }
4616 
4624  explicit Image1DBuffer(const cl_mem& image1D, bool retainObject = false) :
4625  Image(image1D, retainObject) { }
4626 
4627  Image1DBuffer& operator = (const cl_mem& rhs)
4628  {
4629  Image::operator=(rhs);
4630  return *this;
4631  }
4632 
4636  Image1DBuffer(const Image1DBuffer& img) : Image(img) {}
4637 
4641  Image1DBuffer& operator = (const Image1DBuffer &img)
4642  {
4643  Image::operator=(img);
4644  return *this;
4645  }
4646 
4650  Image1DBuffer(Image1DBuffer&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4651 
4655  Image1DBuffer& operator = (Image1DBuffer &&img)
4656  {
4657  Image::operator=(std::move(img));
4658  return *this;
4659  }
4660 
4661 };
4662 
4666 class Image1DArray : public Image
4667 {
4668 public:
4669  Image1DArray(
4670  const Context& context,
4671  cl_mem_flags flags,
4672  ImageFormat format,
4673  size_type arraySize,
4674  size_type width,
4675  size_type rowPitch,
4676  void* host_ptr = NULL,
4677  cl_int* err = NULL)
4678  {
4679  cl_int error;
4680 
4681  cl_image_desc desc = {0};
4682  desc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
4683  desc.image_width = width;
4684  desc.image_array_size = arraySize;
4685  desc.image_row_pitch = rowPitch;
4686 
4687  object_ = ::clCreateImage(
4688  context(),
4689  flags,
4690  &format,
4691  &desc,
4692  host_ptr,
4693  &error);
4694 
4695  detail::errHandler(error, __CREATE_IMAGE_ERR);
4696  if (err != NULL) {
4697  *err = error;
4698  }
4699  }
4700 
4701  Image1DArray() { }
4702 
4710  explicit Image1DArray(const cl_mem& imageArray, bool retainObject = false) :
4711  Image(imageArray, retainObject) { }
4712 
4713 
4714  Image1DArray& operator = (const cl_mem& rhs)
4715  {
4716  Image::operator=(rhs);
4717  return *this;
4718  }
4719 
4723  Image1DArray(const Image1DArray& img) : Image(img) {}
4724 
4728  Image1DArray& operator = (const Image1DArray &img)
4729  {
4730  Image::operator=(img);
4731  return *this;
4732  }
4733 
4737  Image1DArray(Image1DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4738 
4742  Image1DArray& operator = (Image1DArray &&img)
4743  {
4744  Image::operator=(std::move(img));
4745  return *this;
4746  }
4747 
4748 };
4749 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4750 
4751 
4758 class Image2D : public Image
4759 {
4760 public:
4766  const Context& context,
4767  cl_mem_flags flags,
4768  ImageFormat format,
4769  size_type width,
4770  size_type height,
4771  size_type row_pitch = 0,
4772  void* host_ptr = NULL,
4773  cl_int* err = NULL)
4774  {
4775  cl_int error;
4776  bool useCreateImage;
4777 
4778 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
4779  // Run-time decision based on the actual platform
4780  {
4781  cl_uint version = detail::getContextPlatformVersion(context());
4782  useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
4783  }
4784 #elif CL_HPP_TARGET_OPENCL_VERSION >= 120
4785  useCreateImage = true;
4786 #else
4787  useCreateImage = false;
4788 #endif
4789 
4790 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4791  if (useCreateImage)
4792  {
4793  cl_image_desc desc = {0};
4794  desc.image_type = CL_MEM_OBJECT_IMAGE2D;
4795  desc.image_width = width;
4796  desc.image_height = height;
4797  desc.image_row_pitch = row_pitch;
4798 
4799  object_ = ::clCreateImage(
4800  context(),
4801  flags,
4802  &format,
4803  &desc,
4804  host_ptr,
4805  &error);
4806 
4807  detail::errHandler(error, __CREATE_IMAGE_ERR);
4808  if (err != NULL) {
4809  *err = error;
4810  }
4811  }
4812 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
4813 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
4814  if (!useCreateImage)
4815  {
4816  object_ = ::clCreateImage2D(
4817  context(), flags,&format, width, height, row_pitch, host_ptr, &error);
4818 
4819  detail::errHandler(error, __CREATE_IMAGE2D_ERR);
4820  if (err != NULL) {
4821  *err = error;
4822  }
4823  }
4824 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
4825  }
4826 
4827 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4834  const Context& context,
4835  ImageFormat format,
4836  const Buffer &sourceBuffer,
4837  size_type width,
4838  size_type height,
4839  size_type row_pitch = 0,
4840  cl_int* err = nullptr)
4841  {
4842  cl_int error;
4843 
4844  cl_image_desc desc = {0};
4845  desc.image_type = CL_MEM_OBJECT_IMAGE2D;
4846  desc.image_width = width;
4847  desc.image_height = height;
4848  desc.image_row_pitch = row_pitch;
4849  desc.buffer = sourceBuffer();
4850 
4851  object_ = ::clCreateImage(
4852  context(),
4853  0, // flags inherited from buffer
4854  &format,
4855  &desc,
4856  nullptr,
4857  &error);
4858 
4859  detail::errHandler(error, __CREATE_IMAGE_ERR);
4860  if (err != nullptr) {
4861  *err = error;
4862  }
4863  }
4864 #endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4865 
4866 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
4880  const Context& context,
4881  cl_channel_order order,
4882  const Image &sourceImage,
4883  cl_int* err = nullptr)
4884  {
4885  cl_int error;
4886 
4887  // Descriptor fields have to match source image
4888  size_type sourceWidth =
4889  sourceImage.getImageInfo<CL_IMAGE_WIDTH>();
4890  size_type sourceHeight =
4891  sourceImage.getImageInfo<CL_IMAGE_HEIGHT>();
4892  size_type sourceRowPitch =
4893  sourceImage.getImageInfo<CL_IMAGE_ROW_PITCH>();
4894  cl_uint sourceNumMIPLevels =
4895  sourceImage.getImageInfo<CL_IMAGE_NUM_MIP_LEVELS>();
4896  cl_uint sourceNumSamples =
4897  sourceImage.getImageInfo<CL_IMAGE_NUM_SAMPLES>();
4898  cl_image_format sourceFormat =
4899  sourceImage.getImageInfo<CL_IMAGE_FORMAT>();
4900 
4901  // Update only the channel order.
4902  // Channel format inherited from source.
4903  sourceFormat.image_channel_order = order;
4904 
4905  cl_image_desc desc = {0};
4906  desc.image_type = CL_MEM_OBJECT_IMAGE2D;
4907  desc.image_width = sourceWidth;
4908  desc.image_height = sourceHeight;
4909  desc.image_row_pitch = sourceRowPitch;
4910  desc.num_mip_levels = sourceNumMIPLevels;
4911  desc.num_samples = sourceNumSamples;
4912  desc.buffer = sourceImage();
4913 
4914  object_ = ::clCreateImage(
4915  context(),
4916  0, // flags should be inherited from mem_object
4917  &sourceFormat,
4918  &desc,
4919  nullptr,
4920  &error);
4921 
4922  detail::errHandler(error, __CREATE_IMAGE_ERR);
4923  if (err != nullptr) {
4924  *err = error;
4925  }
4926  }
4927 #endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200
4928 
4930  Image2D() { }
4931 
4939  explicit Image2D(const cl_mem& image2D, bool retainObject = false) :
4940  Image(image2D, retainObject) { }
4941 
4946  Image2D& operator = (const cl_mem& rhs)
4947  {
4948  Image::operator=(rhs);
4949  return *this;
4950  }
4951 
4955  Image2D(const Image2D& img) : Image(img) {}
4956 
4961  {
4962  Image::operator=(img);
4963  return *this;
4964  }
4965 
4969  Image2D(Image2D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4970 
4975  {
4976  Image::operator=(std::move(img));
4977  return *this;
4978  }
4979 
4980 };
4981 
4982 
4983 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
4993 class CL_API_PREFIX__VERSION_1_1_DEPRECATED Image2DGL : public Image2D
4994 {
4995 public:
5002  const Context& context,
5003  cl_mem_flags flags,
5004  cl_GLenum target,
5005  cl_GLint miplevel,
5006  cl_GLuint texobj,
5007  cl_int * err = NULL)
5008  {
5009  cl_int error;
5010  object_ = ::clCreateFromGLTexture2D(
5011  context(),
5012  flags,
5013  target,
5014  miplevel,
5015  texobj,
5016  &error);
5017 
5018  detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR);
5019  if (err != NULL) {
5020  *err = error;
5021  }
5022 
5023  }
5024 
5026  Image2DGL() : Image2D() { }
5027 
5035  explicit Image2DGL(const cl_mem& image, bool retainObject = false) :
5036  Image2D(image, retainObject) { }
5037 
5042  Image2DGL& operator = (const cl_mem& rhs)
5043  {
5044  Image2D::operator=(rhs);
5045  return *this;
5046  }
5047 
5051  Image2DGL(const Image2DGL& img) : Image2D(img) {}
5052 
5056  Image2DGL& operator = (const Image2DGL &img)
5057  {
5058  Image2D::operator=(img);
5059  return *this;
5060  }
5061 
5065  Image2DGL(Image2DGL&& img) CL_HPP_NOEXCEPT_ : Image2D(std::move(img)) {}
5066 
5070  Image2DGL& operator = (Image2DGL &&img)
5071  {
5072  Image2D::operator=(std::move(img));
5073  return *this;
5074  }
5075 
5076 } CL_API_SUFFIX__VERSION_1_1_DEPRECATED;
5077 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5078 
5079 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5083 class Image2DArray : public Image
5084 {
5085 public:
5086  Image2DArray(
5087  const Context& context,
5088  cl_mem_flags flags,
5089  ImageFormat format,
5090  size_type arraySize,
5091  size_type width,
5092  size_type height,
5093  size_type rowPitch,
5094  size_type slicePitch,
5095  void* host_ptr = NULL,
5096  cl_int* err = NULL)
5097  {
5098  cl_int error;
5099 
5100  cl_image_desc desc = {0};
5101  desc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
5102  desc.image_width = width;
5103  desc.image_height = height;
5104  desc.image_array_size = arraySize;
5105  desc.image_row_pitch = rowPitch;
5106  desc.image_slice_pitch = slicePitch;
5107 
5108  object_ = ::clCreateImage(
5109  context(),
5110  flags,
5111  &format,
5112  &desc,
5113  host_ptr,
5114  &error);
5115 
5116  detail::errHandler(error, __CREATE_IMAGE_ERR);
5117  if (err != NULL) {
5118  *err = error;
5119  }
5120  }
5121 
5122  Image2DArray() { }
5123 
5131  explicit Image2DArray(const cl_mem& imageArray, bool retainObject = false) : Image(imageArray, retainObject) { }
5132 
5133  Image2DArray& operator = (const cl_mem& rhs)
5134  {
5135  Image::operator=(rhs);
5136  return *this;
5137  }
5138 
5142  Image2DArray(const Image2DArray& img) : Image(img) {}
5143 
5147  Image2DArray& operator = (const Image2DArray &img)
5148  {
5149  Image::operator=(img);
5150  return *this;
5151  }
5152 
5156  Image2DArray(Image2DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5157 
5161  Image2DArray& operator = (Image2DArray &&img)
5162  {
5163  Image::operator=(std::move(img));
5164  return *this;
5165  }
5166 };
5167 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5168 
5175 class Image3D : public Image
5176 {
5177 public:
5183  const Context& context,
5184  cl_mem_flags flags,
5185  ImageFormat format,
5186  size_type width,
5187  size_type height,
5188  size_type depth,
5189  size_type row_pitch = 0,
5190  size_type slice_pitch = 0,
5191  void* host_ptr = NULL,
5192  cl_int* err = NULL)
5193  {
5194  cl_int error;
5195  bool useCreateImage;
5196 
5197 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
5198  // Run-time decision based on the actual platform
5199  {
5200  cl_uint version = detail::getContextPlatformVersion(context());
5201  useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
5202  }
5203 #elif CL_HPP_TARGET_OPENCL_VERSION >= 120
5204  useCreateImage = true;
5205 #else
5206  useCreateImage = false;
5207 #endif
5208 
5209 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5210  if (useCreateImage)
5211  {
5212  cl_image_desc desc = {0};
5213  desc.image_type = CL_MEM_OBJECT_IMAGE3D;
5214  desc.image_width = width;
5215  desc.image_height = height;
5216  desc.image_depth = depth;
5217  desc.image_row_pitch = row_pitch;
5218  desc.image_slice_pitch = slice_pitch;
5219 
5220  object_ = ::clCreateImage(
5221  context(),
5222  flags,
5223  &format,
5224  &desc,
5225  host_ptr,
5226  &error);
5227 
5228  detail::errHandler(error, __CREATE_IMAGE_ERR);
5229  if (err != NULL) {
5230  *err = error;
5231  }
5232  }
5233 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5234 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
5235  if (!useCreateImage)
5236  {
5237  object_ = ::clCreateImage3D(
5238  context(), flags, &format, width, height, depth, row_pitch,
5239  slice_pitch, host_ptr, &error);
5240 
5241  detail::errHandler(error, __CREATE_IMAGE3D_ERR);
5242  if (err != NULL) {
5243  *err = error;
5244  }
5245  }
5246 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
5247  }
5248 
5250  Image3D() : Image() { }
5251 
5259  explicit Image3D(const cl_mem& image3D, bool retainObject = false) :
5260  Image(image3D, retainObject) { }
5261 
5266  Image3D& operator = (const cl_mem& rhs)
5267  {
5268  Image::operator=(rhs);
5269  return *this;
5270  }
5271 
5275  Image3D(const Image3D& img) : Image(img) {}
5276 
5281  {
5282  Image::operator=(img);
5283  return *this;
5284  }
5285 
5289  Image3D(Image3D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5290 
5295  {
5296  Image::operator=(std::move(img));
5297  return *this;
5298  }
5299 };
5300 
5301 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
5310 class Image3DGL : public Image3D
5311 {
5312 public:
5319  const Context& context,
5320  cl_mem_flags flags,
5321  cl_GLenum target,
5322  cl_GLint miplevel,
5323  cl_GLuint texobj,
5324  cl_int * err = NULL)
5325  {
5326  cl_int error;
5327  object_ = ::clCreateFromGLTexture3D(
5328  context(),
5329  flags,
5330  target,
5331  miplevel,
5332  texobj,
5333  &error);
5334 
5335  detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR);
5336  if (err != NULL) {
5337  *err = error;
5338  }
5339  }
5340 
5342  Image3DGL() : Image3D() { }
5343 
5351  explicit Image3DGL(const cl_mem& image, bool retainObject = false) :
5352  Image3D(image, retainObject) { }
5353 
5358  Image3DGL& operator = (const cl_mem& rhs)
5359  {
5360  Image3D::operator=(rhs);
5361  return *this;
5362  }
5363 
5367  Image3DGL(const Image3DGL& img) : Image3D(img) {}
5368 
5373  {
5374  Image3D::operator=(img);
5375  return *this;
5376  }
5377 
5381  Image3DGL(Image3DGL&& img) CL_HPP_NOEXCEPT_ : Image3D(std::move(img)) {}
5382 
5387  {
5388  Image3D::operator=(std::move(img));
5389  return *this;
5390  }
5391 };
5392 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5393 
5394 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5401 class ImageGL : public Image
5402 {
5403 public:
5404  ImageGL(
5405  const Context& context,
5406  cl_mem_flags flags,
5407  cl_GLenum target,
5408  cl_GLint miplevel,
5409  cl_GLuint texobj,
5410  cl_int * err = NULL)
5411  {
5412  cl_int error;
5413  object_ = ::clCreateFromGLTexture(
5414  context(),
5415  flags,
5416  target,
5417  miplevel,
5418  texobj,
5419  &error);
5420 
5421  detail::errHandler(error, __CREATE_GL_TEXTURE_ERR);
5422  if (err != NULL) {
5423  *err = error;
5424  }
5425  }
5426 
5427  ImageGL() : Image() { }
5428 
5436  explicit ImageGL(const cl_mem& image, bool retainObject = false) :
5437  Image(image, retainObject) { }
5438 
5439  ImageGL& operator = (const cl_mem& rhs)
5440  {
5441  Image::operator=(rhs);
5442  return *this;
5443  }
5444 
5448  ImageGL(const ImageGL& img) : Image(img) {}
5449 
5453  ImageGL& operator = (const ImageGL &img)
5454  {
5455  Image::operator=(img);
5456  return *this;
5457  }
5458 
5462  ImageGL(ImageGL&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5463 
5467  ImageGL& operator = (ImageGL &&img)
5468  {
5469  Image::operator=(std::move(img));
5470  return *this;
5471  }
5472 };
5473 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5474 
5475 
5476 
5477 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5484 class Pipe : public Memory
5485 {
5486 public:
5487 
5498  const Context& context,
5499  cl_uint packet_size,
5500  cl_uint max_packets,
5501  cl_int* err = NULL)
5502  {
5503  cl_int error;
5504 
5505  cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5506  object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error);
5507 
5508  detail::errHandler(error, __CREATE_PIPE_ERR);
5509  if (err != NULL) {
5510  *err = error;
5511  }
5512  }
5513 
5523  cl_uint packet_size,
5524  cl_uint max_packets,
5525  cl_int* err = NULL)
5526  {
5527  cl_int error;
5528 
5529  Context context = Context::getDefault(err);
5530 
5531  cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5532  object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error);
5533 
5534  detail::errHandler(error, __CREATE_PIPE_ERR);
5535  if (err != NULL) {
5536  *err = error;
5537  }
5538  }
5539 
5541  Pipe() : Memory() { }
5542 
5550  explicit Pipe(const cl_mem& pipe, bool retainObject = false) :
5551  Memory(pipe, retainObject) { }
5552 
5557  Pipe& operator = (const cl_mem& rhs)
5558  {
5559  Memory::operator=(rhs);
5560  return *this;
5561  }
5562 
5566  Pipe(const Pipe& pipe) : Memory(pipe) {}
5567 
5571  Pipe& operator = (const Pipe &pipe)
5572  {
5573  Memory::operator=(pipe);
5574  return *this;
5575  }
5576 
5580  Pipe(Pipe&& pipe) CL_HPP_NOEXCEPT_ : Memory(std::move(pipe)) {}
5581 
5586  {
5587  Memory::operator=(std::move(pipe));
5588  return *this;
5589  }
5590 
5592  template <typename T>
5593  cl_int getInfo(cl_pipe_info name, T* param) const
5594  {
5595  return detail::errHandler(
5596  detail::getInfo(&::clGetPipeInfo, object_, name, param),
5597  __GET_PIPE_INFO_ERR);
5598  }
5599 
5601  template <cl_pipe_info name> typename
5603  getInfo(cl_int* err = NULL) const
5604  {
5605  typename detail::param_traits<
5606  detail::cl_pipe_info, name>::param_type param;
5607  cl_int result = getInfo(name, &param);
5608  if (err != NULL) {
5609  *err = result;
5610  }
5611  return param;
5612  }
5613 }; // class Pipe
5614 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
5615 
5616 
5625 class Sampler : public detail::Wrapper<cl_sampler>
5626 {
5627 public:
5629  Sampler() { }
5630 
5636  const Context& context,
5637  cl_bool normalized_coords,
5638  cl_addressing_mode addressing_mode,
5639  cl_filter_mode filter_mode,
5640  cl_int* err = NULL)
5641  {
5642  cl_int error;
5643 
5644 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5645  cl_sampler_properties sampler_properties[] = {
5646  CL_SAMPLER_NORMALIZED_COORDS, normalized_coords,
5647  CL_SAMPLER_ADDRESSING_MODE, addressing_mode,
5648  CL_SAMPLER_FILTER_MODE, filter_mode,
5649  0 };
5650  object_ = ::clCreateSamplerWithProperties(
5651  context(),
5652  sampler_properties,
5653  &error);
5654 
5655  detail::errHandler(error, __CREATE_SAMPLER_WITH_PROPERTIES_ERR);
5656  if (err != NULL) {
5657  *err = error;
5658  }
5659 #else
5660  object_ = ::clCreateSampler(
5661  context(),
5662  normalized_coords,
5663  addressing_mode,
5664  filter_mode,
5665  &error);
5666 
5667  detail::errHandler(error, __CREATE_SAMPLER_ERR);
5668  if (err != NULL) {
5669  *err = error;
5670  }
5671 #endif
5672  }
5673 
5682  explicit Sampler(const cl_sampler& sampler, bool retainObject = false) :
5683  detail::Wrapper<cl_type>(sampler, retainObject) { }
5684 
5690  Sampler& operator = (const cl_sampler& rhs)
5691  {
5693  return *this;
5694  }
5695 
5699  Sampler(const Sampler& sam) : detail::Wrapper<cl_type>(sam) {}
5700 
5705  {
5707  return *this;
5708  }
5709 
5713  Sampler(Sampler&& sam) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(sam)) {}
5714 
5719  {
5720  detail::Wrapper<cl_type>::operator=(std::move(sam));
5721  return *this;
5722  }
5723 
5725  template <typename T>
5726  cl_int getInfo(cl_sampler_info name, T* param) const
5727  {
5728  return detail::errHandler(
5729  detail::getInfo(&::clGetSamplerInfo, object_, name, param),
5730  __GET_SAMPLER_INFO_ERR);
5731  }
5732 
5734  template <cl_sampler_info name> typename
5736  getInfo(cl_int* err = NULL) const
5737  {
5738  typename detail::param_traits<
5739  detail::cl_sampler_info, name>::param_type param;
5740  cl_int result = getInfo(name, &param);
5741  if (err != NULL) {
5742  *err = result;
5743  }
5744  return param;
5745  }
5746 };
5747 
5748 class Program;
5749 class CommandQueue;
5750 class DeviceCommandQueue;
5751 class Kernel;
5752 
5754 class NDRange
5755 {
5756 private:
5757  size_type sizes_[3];
5758  cl_uint dimensions_;
5759 
5760 public:
5763  : dimensions_(0)
5764  {
5765  sizes_[0] = 0;
5766  sizes_[1] = 0;
5767  sizes_[2] = 0;
5768  }
5769 
5771  NDRange(size_type size0)
5772  : dimensions_(1)
5773  {
5774  sizes_[0] = size0;
5775  sizes_[1] = 1;
5776  sizes_[2] = 1;
5777  }
5778 
5780  NDRange(size_type size0, size_type size1)
5781  : dimensions_(2)
5782  {
5783  sizes_[0] = size0;
5784  sizes_[1] = size1;
5785  sizes_[2] = 1;
5786  }
5787 
5789  NDRange(size_type size0, size_type size1, size_type size2)
5790  : dimensions_(3)
5791  {
5792  sizes_[0] = size0;
5793  sizes_[1] = size1;
5794  sizes_[2] = size2;
5795  }
5796 
5801  operator const size_type*() const {
5802  return sizes_;
5803  }
5804 
5806  size_type dimensions() const
5807  {
5808  return dimensions_;
5809  }
5810 
5812  // runtime number of dimensions
5813  size_type size() const
5814  {
5815  return dimensions_*sizeof(size_type);
5816  }
5817 
5818  size_type* get()
5819  {
5820  return sizes_;
5821  }
5822 
5823  const size_type* get() const
5824  {
5825  return sizes_;
5826  }
5827 };
5828 
5830 static const NDRange NullRange;
5831 
5834 {
5835  size_type size_;
5836 };
5837 
5838 namespace detail {
5839 
5840 template <typename T, class Enable = void>
5842 
5843 // Enable for objects that are not subclasses of memory
5844 // Pointers, constants etc
5845 template <typename T>
5846 struct KernelArgumentHandler<T, typename std::enable_if<!std::is_base_of<cl::Memory, T>::value>::type>
5847 {
5848  static size_type size(const T&) { return sizeof(T); }
5849  static const T* ptr(const T& value) { return &value; }
5850 };
5851 
5852 // Enable for subclasses of memory where we want to get a reference to the cl_mem out
5853 // and pass that in for safety
5854 template <typename T>
5855 struct KernelArgumentHandler<T, typename std::enable_if<std::is_base_of<cl::Memory, T>::value>::type>
5856 {
5857  static size_type size(const T&) { return sizeof(cl_mem); }
5858  static const cl_mem* ptr(const T& value) { return &(value()); }
5859 };
5860 
5861 // Specialization for DeviceCommandQueue defined later
5862 
5863 template <>
5865 {
5866  static size_type size(const LocalSpaceArg& value) { return value.size_; }
5867  static const void* ptr(const LocalSpaceArg&) { return NULL; }
5868 };
5869 
5870 }
5872 
5876 inline LocalSpaceArg
5877 Local(size_type size)
5878 {
5879  LocalSpaceArg ret = { size };
5880  return ret;
5881 }
5882 
5891 class Kernel : public detail::Wrapper<cl_kernel>
5892 {
5893 public:
5894  inline Kernel(const Program& program, const char* name, cl_int* err = NULL);
5895 
5897  Kernel() { }
5898 
5907  explicit Kernel(const cl_kernel& kernel, bool retainObject = false) :
5908  detail::Wrapper<cl_type>(kernel, retainObject) { }
5909 
5915  Kernel& operator = (const cl_kernel& rhs)
5916  {
5918  return *this;
5919  }
5920 
5924  Kernel(const Kernel& kernel) : detail::Wrapper<cl_type>(kernel) {}
5925 
5929  Kernel& operator = (const Kernel &kernel)
5930  {
5932  return *this;
5933  }
5934 
5938  Kernel(Kernel&& kernel) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(kernel)) {}
5939 
5944  {
5945  detail::Wrapper<cl_type>::operator=(std::move(kernel));
5946  return *this;
5947  }
5948 
5949  template <typename T>
5950  cl_int getInfo(cl_kernel_info name, T* param) const
5951  {
5952  return detail::errHandler(
5953  detail::getInfo(&::clGetKernelInfo, object_, name, param),
5954  __GET_KERNEL_INFO_ERR);
5955  }
5956 
5957  template <cl_kernel_info name> typename
5958  detail::param_traits<detail::cl_kernel_info, name>::param_type
5959  getInfo(cl_int* err = NULL) const
5960  {
5961  typename detail::param_traits<
5962  detail::cl_kernel_info, name>::param_type param;
5963  cl_int result = getInfo(name, &param);
5964  if (err != NULL) {
5965  *err = result;
5966  }
5967  return param;
5968  }
5969 
5970 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5971  template <typename T>
5972  cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const
5973  {
5974  return detail::errHandler(
5975  detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param),
5976  __GET_KERNEL_ARG_INFO_ERR);
5977  }
5978 
5979  template <cl_kernel_arg_info name> typename
5980  detail::param_traits<detail::cl_kernel_arg_info, name>::param_type
5981  getArgInfo(cl_uint argIndex, cl_int* err = NULL) const
5982  {
5983  typename detail::param_traits<
5984  detail::cl_kernel_arg_info, name>::param_type param;
5985  cl_int result = getArgInfo(argIndex, name, &param);
5986  if (err != NULL) {
5987  *err = result;
5988  }
5989  return param;
5990  }
5991 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5992 
5993  template <typename T>
5994  cl_int getWorkGroupInfo(
5995  const Device& device, cl_kernel_work_group_info name, T* param) const
5996  {
5997  return detail::errHandler(
5998  detail::getInfo(
5999  &::clGetKernelWorkGroupInfo, object_, device(), name, param),
6000  __GET_KERNEL_WORK_GROUP_INFO_ERR);
6001  }
6002 
6003  template <cl_kernel_work_group_info name> typename
6004  detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
6005  getWorkGroupInfo(const Device& device, cl_int* err = NULL) const
6006  {
6007  typename detail::param_traits<
6008  detail::cl_kernel_work_group_info, name>::param_type param;
6009  cl_int result = getWorkGroupInfo(device, name, &param);
6010  if (err != NULL) {
6011  *err = result;
6012  }
6013  return param;
6014  }
6015 
6016 #if (CL_HPP_TARGET_OPENCL_VERSION >= 200 && defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)) || CL_HPP_TARGET_OPENCL_VERSION >= 210
6017  cl_int getSubGroupInfo(const cl::Device &dev, cl_kernel_sub_group_info name, const cl::NDRange &range, size_type* param) const
6018  {
6019 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6020 
6021  return detail::errHandler(
6022  clGetKernelSubGroupInfo(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
6023  __GET_KERNEL_SUB_GROUP_INFO_ERR);
6024 
6025 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6026 
6027  typedef clGetKernelSubGroupInfoKHR_fn PFN_clGetKernelSubGroupInfoKHR;
6028  static PFN_clGetKernelSubGroupInfoKHR pfn_clGetKernelSubGroupInfoKHR = NULL;
6029  CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetKernelSubGroupInfoKHR);
6030 
6031  return detail::errHandler(
6032  pfn_clGetKernelSubGroupInfoKHR(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
6033  __GET_KERNEL_SUB_GROUP_INFO_ERR);
6034 
6035 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6036  }
6037 
6038  template <cl_kernel_sub_group_info name>
6039  size_type getSubGroupInfo(const cl::Device &dev, const cl::NDRange &range, cl_int* err = NULL) const
6040  {
6041  size_type param;
6042  cl_int result = getSubGroupInfo(dev, name, range, &param);
6043  if (err != NULL) {
6044  *err = result;
6045  }
6046  return param;
6047  }
6048 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6049 
6050 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6053  template<typename T, class D>
6054  cl_int setArg(cl_uint index, const cl::pointer<T, D> &argPtr)
6055  {
6056  return detail::errHandler(
6057  ::clSetKernelArgSVMPointer(object_, index, argPtr.get()),
6058  __SET_KERNEL_ARGS_ERR);
6059  }
6060 
6063  template<typename T, class Alloc>
6064  cl_int setArg(cl_uint index, const cl::vector<T, Alloc> &argPtr)
6065  {
6066  return detail::errHandler(
6067  ::clSetKernelArgSVMPointer(object_, index, argPtr.data()),
6068  __SET_KERNEL_ARGS_ERR);
6069  }
6070 
6073  template<typename T>
6074  typename std::enable_if<std::is_pointer<T>::value, cl_int>::type
6075  setArg(cl_uint index, const T argPtr)
6076  {
6077  return detail::errHandler(
6078  ::clSetKernelArgSVMPointer(object_, index, argPtr),
6079  __SET_KERNEL_ARGS_ERR);
6080  }
6081 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6082 
6085  template <typename T>
6086  typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6087  setArg(cl_uint index, const T &value)
6088  {
6089  return detail::errHandler(
6090  ::clSetKernelArg(
6091  object_,
6092  index,
6095  __SET_KERNEL_ARGS_ERR);
6096  }
6097 
6098  cl_int setArg(cl_uint index, size_type size, const void* argPtr)
6099  {
6100  return detail::errHandler(
6101  ::clSetKernelArg(object_, index, size, argPtr),
6102  __SET_KERNEL_ARGS_ERR);
6103  }
6104 
6105 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6110  cl_int setSVMPointers(const vector<void*> &pointerList)
6111  {
6112  return detail::errHandler(
6113  ::clSetKernelExecInfo(
6114  object_,
6115  CL_KERNEL_EXEC_INFO_SVM_PTRS,
6116  sizeof(void*)*pointerList.size(),
6117  pointerList.data()));
6118  }
6119 
6124  template<int ArrayLength>
6125  cl_int setSVMPointers(const std::array<void*, ArrayLength> &pointerList)
6126  {
6127  return detail::errHandler(
6128  ::clSetKernelExecInfo(
6129  object_,
6130  CL_KERNEL_EXEC_INFO_SVM_PTRS,
6131  sizeof(void*)*pointerList.size(),
6132  pointerList.data()));
6133  }
6134 
6146  cl_int enableFineGrainedSystemSVM(bool svmEnabled)
6147  {
6148  cl_bool svmEnabled_ = svmEnabled ? CL_TRUE : CL_FALSE;
6149  return detail::errHandler(
6150  ::clSetKernelExecInfo(
6151  object_,
6152  CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM,
6153  sizeof(cl_bool),
6154  &svmEnabled_
6155  )
6156  );
6157  }
6158 
6159  template<int index, int ArrayLength, class D, typename T0, typename T1, typename... Ts>
6160  void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0, const pointer<T1, D> &t1, Ts & ... ts)
6161  {
6162  pointerList[index] = static_cast<void*>(t0.get());
6163  setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6164  }
6165 
6166  template<int index, int ArrayLength, typename T0, typename T1, typename... Ts>
6167  typename std::enable_if<std::is_pointer<T0>::value, void>::type
6168  setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0, T1 t1, Ts... ts)
6169  {
6170  pointerList[index] = static_cast<void*>(t0);
6171  setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6172  }
6173 
6174  template<int index, int ArrayLength, typename T0, class D>
6175  void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0)
6176  {
6177  pointerList[index] = static_cast<void*>(t0.get());
6178  }
6179 
6180 
6181  template<int index, int ArrayLength, typename T0>
6182  typename std::enable_if<std::is_pointer<T0>::value, void>::type
6183  setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0)
6184  {
6185  pointerList[index] = static_cast<void*>(t0);
6186  }
6187 
6188  template<typename T0, typename... Ts>
6189  cl_int setSVMPointers(const T0 &t0, Ts & ... ts)
6190  {
6191  std::array<void*, 1 + sizeof...(Ts)> pointerList;
6192 
6193  setSVMPointersHelper<0, 1 + sizeof...(Ts)>(pointerList, t0, ts...);
6194  return detail::errHandler(
6195  ::clSetKernelExecInfo(
6196  object_,
6197  CL_KERNEL_EXEC_INFO_SVM_PTRS,
6198  sizeof(void*)*(1 + sizeof...(Ts)),
6199  pointerList.data()));
6200  }
6201 
6202  template<typename T>
6203  cl_int setExecInfo(cl_kernel_exec_info param_name, const T& val)
6204  {
6205  return detail::errHandler(
6206  ::clSetKernelExecInfo(
6207  object_,
6208  param_name,
6209  sizeof(T),
6210  &val));
6211  }
6212 
6213  template<cl_kernel_exec_info name>
6214  cl_int setExecInfo(typename detail::param_traits<detail::cl_kernel_exec_info, name>::param_type& val)
6215  {
6216  return setExecInfo(name, val);
6217  }
6218 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6219 
6220 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6227  {
6228  cl_int error;
6229  Kernel retValue(clCloneKernel(this->get(), &error));
6230 
6231  detail::errHandler(error, __CLONE_KERNEL_ERR);
6232  return retValue;
6233  }
6234 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6235 };
6236 
6240 class Program : public detail::Wrapper<cl_program>
6241 {
6242 public:
6243 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6244  typedef vector<vector<unsigned char>> Binaries;
6245  typedef vector<string> Sources;
6246 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6247  typedef vector<std::pair<const void*, size_type> > Binaries;
6248  typedef vector<std::pair<const char*, size_type> > Sources;
6249 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6250 
6251  Program(
6252  const string& source,
6253  bool build = false,
6254  cl_int* err = NULL)
6255  {
6256  cl_int error;
6257 
6258  const char * strings = source.c_str();
6259  const size_type length = source.size();
6260 
6261  Context context = Context::getDefault(err);
6262 
6263  object_ = ::clCreateProgramWithSource(
6264  context(), (cl_uint)1, &strings, &length, &error);
6265 
6266  detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6267 
6268  if (error == CL_SUCCESS && build) {
6269 
6270  error = ::clBuildProgram(
6271  object_,
6272  0,
6273  NULL,
6274 #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6275  "-cl-std=CL2.0",
6276 #else
6277  "",
6278 #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6279  NULL,
6280  NULL);
6281 
6282  detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6283  }
6284 
6285  if (err != NULL) {
6286  *err = error;
6287  }
6288  }
6289 
6290  Program(
6291  const Context& context,
6292  const string& source,
6293  bool build = false,
6294  cl_int* err = NULL)
6295  {
6296  cl_int error;
6297 
6298  const char * strings = source.c_str();
6299  const size_type length = source.size();
6300 
6301  object_ = ::clCreateProgramWithSource(
6302  context(), (cl_uint)1, &strings, &length, &error);
6303 
6304  detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6305 
6306  if (error == CL_SUCCESS && build) {
6307  error = ::clBuildProgram(
6308  object_,
6309  0,
6310  NULL,
6311 #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6312  "-cl-std=CL2.0",
6313 #else
6314  "",
6315 #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6316  NULL,
6317  NULL);
6318 
6319  detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6320  }
6321 
6322  if (err != NULL) {
6323  *err = error;
6324  }
6325  }
6326 
6332  const Sources& sources,
6333  cl_int* err = NULL)
6334  {
6335  cl_int error;
6336  Context context = Context::getDefault(err);
6337 
6338  const size_type n = (size_type)sources.size();
6339 
6340  vector<size_type> lengths(n);
6341  vector<const char*> strings(n);
6342 
6343  for (size_type i = 0; i < n; ++i) {
6344 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6345  strings[i] = sources[(int)i].data();
6346  lengths[i] = sources[(int)i].length();
6347 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6348  strings[i] = sources[(int)i].first;
6349  lengths[i] = sources[(int)i].second;
6350 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6351  }
6352 
6353  object_ = ::clCreateProgramWithSource(
6354  context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6355 
6356  detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6357  if (err != NULL) {
6358  *err = error;
6359  }
6360  }
6361 
6367  const Context& context,
6368  const Sources& sources,
6369  cl_int* err = NULL)
6370  {
6371  cl_int error;
6372 
6373  const size_type n = (size_type)sources.size();
6374 
6375  vector<size_type> lengths(n);
6376  vector<const char*> strings(n);
6377 
6378  for (size_type i = 0; i < n; ++i) {
6379 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6380  strings[i] = sources[(int)i].data();
6381  lengths[i] = sources[(int)i].length();
6382 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6383  strings[i] = sources[(int)i].first;
6384  lengths[i] = sources[(int)i].second;
6385 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6386  }
6387 
6388  object_ = ::clCreateProgramWithSource(
6389  context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6390 
6391  detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6392  if (err != NULL) {
6393  *err = error;
6394  }
6395  }
6396 
6397 
6398 #if CL_HPP_TARGET_OPENCL_VERSION >= 210 || (CL_HPP_TARGET_OPENCL_VERSION==200 && defined(CL_HPP_USE_IL_KHR))
6404  const vector<char>& IL,
6405  bool build = false,
6406  cl_int* err = NULL)
6407  {
6408  cl_int error;
6409 
6410  Context context = Context::getDefault(err);
6411 
6412 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6413 
6414  object_ = ::clCreateProgramWithIL(
6415  context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6416 
6417 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6418 
6419  typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6420  static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6421  CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6422 
6423  return detail::errHandler(
6424  pfn_clCreateProgramWithILKHR(
6425  context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6426 
6427 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6428 
6429  detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6430 
6431  if (error == CL_SUCCESS && build) {
6432 
6433  error = ::clBuildProgram(
6434  object_,
6435  0,
6436  NULL,
6437 #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6438  "-cl-std=CL2.0",
6439 #else
6440  "",
6441 #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6442  NULL,
6443  NULL);
6444 
6445  detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6446  }
6447 
6448  if (err != NULL) {
6449  *err = error;
6450  }
6451  }
6452 
6459  const Context& context,
6460  const vector<char>& IL,
6461  bool build = false,
6462  cl_int* err = NULL)
6463  {
6464  cl_int error;
6465 
6466 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6467 
6468  object_ = ::clCreateProgramWithIL(
6469  context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6470 
6471 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6472 
6473  typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6474  static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6475  CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6476 
6477  return detail::errHandler(
6478  pfn_clCreateProgramWithILKHR(
6479  context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6480 
6481 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6482 
6483  detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6484 
6485  if (error == CL_SUCCESS && build) {
6486  error = ::clBuildProgram(
6487  object_,
6488  0,
6489  NULL,
6490 #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6491  "-cl-std=CL2.0",
6492 #else
6493  "",
6494 #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6495  NULL,
6496  NULL);
6497 
6498  detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6499  }
6500 
6501  if (err != NULL) {
6502  *err = error;
6503  }
6504  }
6505 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6506 
6527  const Context& context,
6528  const vector<Device>& devices,
6529  const Binaries& binaries,
6530  vector<cl_int>* binaryStatus = NULL,
6531  cl_int* err = NULL)
6532  {
6533  cl_int error;
6534 
6535  const size_type numDevices = devices.size();
6536 
6537  // Catch size mismatch early and return
6538  if(binaries.size() != numDevices) {
6539  error = CL_INVALID_VALUE;
6540  detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6541  if (err != NULL) {
6542  *err = error;
6543  }
6544  return;
6545  }
6546 
6547 
6548  vector<size_type> lengths(numDevices);
6549  vector<const unsigned char*> images(numDevices);
6550 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6551  for (size_type i = 0; i < numDevices; ++i) {
6552  images[i] = binaries[i].data();
6553  lengths[i] = binaries[(int)i].size();
6554  }
6555 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6556  for (size_type i = 0; i < numDevices; ++i) {
6557  images[i] = (const unsigned char*)binaries[i].first;
6558  lengths[i] = binaries[(int)i].second;
6559  }
6560 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6561 
6562  vector<cl_device_id> deviceIDs(numDevices);
6563  for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6564  deviceIDs[deviceIndex] = (devices[deviceIndex])();
6565  }
6566 
6567  if(binaryStatus) {
6568  binaryStatus->resize(numDevices);
6569  }
6570 
6571  object_ = ::clCreateProgramWithBinary(
6572  context(), (cl_uint) devices.size(),
6573  deviceIDs.data(),
6574  lengths.data(), images.data(), (binaryStatus != NULL && numDevices > 0)
6575  ? &binaryStatus->front()
6576  : NULL, &error);
6577 
6578  detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6579  if (err != NULL) {
6580  *err = error;
6581  }
6582  }
6583 
6584 
6585 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6591  const Context& context,
6592  const vector<Device>& devices,
6593  const string& kernelNames,
6594  cl_int* err = NULL)
6595  {
6596  cl_int error;
6597 
6598 
6599  size_type numDevices = devices.size();
6600  vector<cl_device_id> deviceIDs(numDevices);
6601  for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6602  deviceIDs[deviceIndex] = (devices[deviceIndex])();
6603  }
6604 
6605  object_ = ::clCreateProgramWithBuiltInKernels(
6606  context(),
6607  (cl_uint) devices.size(),
6608  deviceIDs.data(),
6609  kernelNames.c_str(),
6610  &error);
6611 
6612  detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR);
6613  if (err != NULL) {
6614  *err = error;
6615  }
6616  }
6617 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6618 
6619  Program() { }
6620 
6621 
6628  explicit Program(const cl_program& program, bool retainObject = false) :
6629  detail::Wrapper<cl_type>(program, retainObject) { }
6630 
6631  Program& operator = (const cl_program& rhs)
6632  {
6634  return *this;
6635  }
6636 
6640  Program(const Program& program) : detail::Wrapper<cl_type>(program) {}
6641 
6645  Program& operator = (const Program &program)
6646  {
6648  return *this;
6649  }
6650 
6654  Program(Program&& program) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(program)) {}
6655 
6659  Program& operator = (Program &&program)
6660  {
6661  detail::Wrapper<cl_type>::operator=(std::move(program));
6662  return *this;
6663  }
6664 
6665  cl_int build(
6666  const vector<Device>& devices,
6667  const char* options = NULL,
6668  void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6669  void* data = NULL) const
6670  {
6671  size_type numDevices = devices.size();
6672  vector<cl_device_id> deviceIDs(numDevices);
6673 
6674  for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6675  deviceIDs[deviceIndex] = (devices[deviceIndex])();
6676  }
6677 
6678  cl_int buildError = ::clBuildProgram(
6679  object_,
6680  (cl_uint)
6681  devices.size(),
6682  deviceIDs.data(),
6683  options,
6684  notifyFptr,
6685  data);
6686 
6687  return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6688  }
6689 
6690  cl_int build(
6691  const Device& device,
6692  const char* options = NULL,
6693  void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6694  void* data = NULL) const
6695  {
6696  cl_device_id deviceID = device();
6697 
6698  cl_int buildError = ::clBuildProgram(
6699  object_,
6700  1,
6701  &deviceID,
6702  options,
6703  notifyFptr,
6704  data);
6705 
6706  BuildLogType buildLog(1);
6707  buildLog.push_back(std::make_pair(device, getBuildInfo<CL_PROGRAM_BUILD_LOG>(device)));
6708  return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, buildLog);
6709  }
6710 
6711  cl_int build(
6712  const char* options = NULL,
6713  void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6714  void* data = NULL) const
6715  {
6716  cl_int buildError = ::clBuildProgram(
6717  object_,
6718  0,
6719  NULL,
6720  options,
6721  notifyFptr,
6722  data);
6723 
6724  return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6725  }
6726 
6727 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6728  cl_int compile(
6729  const char* options = NULL,
6730  void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6731  void* data = NULL) const
6732  {
6733  cl_int error = ::clCompileProgram(
6734  object_,
6735  0,
6736  NULL,
6737  options,
6738  0,
6739  NULL,
6740  NULL,
6741  notifyFptr,
6742  data);
6743  return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6744  }
6745 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6746 
6747  template <typename T>
6748  cl_int getInfo(cl_program_info name, T* param) const
6749  {
6750  return detail::errHandler(
6751  detail::getInfo(&::clGetProgramInfo, object_, name, param),
6752  __GET_PROGRAM_INFO_ERR);
6753  }
6754 
6755  template <cl_program_info name> typename
6756  detail::param_traits<detail::cl_program_info, name>::param_type
6757  getInfo(cl_int* err = NULL) const
6758  {
6759  typename detail::param_traits<
6760  detail::cl_program_info, name>::param_type param;
6761  cl_int result = getInfo(name, &param);
6762  if (err != NULL) {
6763  *err = result;
6764  }
6765  return param;
6766  }
6767 
6768  template <typename T>
6769  cl_int getBuildInfo(
6770  const Device& device, cl_program_build_info name, T* param) const
6771  {
6772  return detail::errHandler(
6773  detail::getInfo(
6774  &::clGetProgramBuildInfo, object_, device(), name, param),
6775  __GET_PROGRAM_BUILD_INFO_ERR);
6776  }
6777 
6778  template <cl_program_build_info name> typename
6779  detail::param_traits<detail::cl_program_build_info, name>::param_type
6780  getBuildInfo(const Device& device, cl_int* err = NULL) const
6781  {
6782  typename detail::param_traits<
6783  detail::cl_program_build_info, name>::param_type param;
6784  cl_int result = getBuildInfo(device, name, &param);
6785  if (err != NULL) {
6786  *err = result;
6787  }
6788  return param;
6789  }
6790 
6796  template <cl_program_build_info name>
6797  vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6798  getBuildInfo(cl_int *err = NULL) const
6799  {
6800  cl_int result = CL_SUCCESS;
6801 
6802  auto devs = getInfo<CL_PROGRAM_DEVICES>(&result);
6803  vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6804  devInfo;
6805 
6806  // If there was an initial error from getInfo return the error
6807  if (result != CL_SUCCESS) {
6808  if (err != NULL) {
6809  *err = result;
6810  }
6811  return devInfo;
6812  }
6813 
6814  for (const cl::Device &d : devs) {
6815  typename detail::param_traits<
6816  detail::cl_program_build_info, name>::param_type param;
6817  result = getBuildInfo(d, name, &param);
6818  devInfo.push_back(
6820  (d, param));
6821  if (result != CL_SUCCESS) {
6822  // On error, leave the loop and return the error code
6823  break;
6824  }
6825  }
6826  if (err != NULL) {
6827  *err = result;
6828  }
6829  if (result != CL_SUCCESS) {
6830  devInfo.clear();
6831  }
6832  return devInfo;
6833  }
6834 
6835  cl_int createKernels(vector<Kernel>* kernels)
6836  {
6837  cl_uint numKernels;
6838  cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
6839  if (err != CL_SUCCESS) {
6840  return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6841  }
6842 
6843  vector<cl_kernel> value(numKernels);
6844 
6845  err = ::clCreateKernelsInProgram(
6846  object_, numKernels, value.data(), NULL);
6847  if (err != CL_SUCCESS) {
6848  return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6849  }
6850 
6851  if (kernels) {
6852  kernels->resize(value.size());
6853 
6854  // Assign to param, constructing with retain behaviour
6855  // to correctly capture each underlying CL object
6856  for (size_type i = 0; i < value.size(); i++) {
6857  // We do not need to retain because this kernel is being created
6858  // by the runtime
6859  (*kernels)[i] = Kernel(value[i], false);
6860  }
6861  }
6862  return CL_SUCCESS;
6863  }
6864 
6865 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
6866 #if defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
6877  CL_API_PREFIX__VERSION_2_2_DEPRECATED cl_int setReleaseCallback(
6878  void (CL_CALLBACK * pfn_notify)(cl_program program, void * user_data),
6879  void * user_data = NULL) CL_API_SUFFIX__VERSION_2_2_DEPRECATED
6880  {
6881  return detail::errHandler(
6882  ::clSetProgramReleaseCallback(
6883  object_,
6884  pfn_notify,
6885  user_data),
6886  __SET_PROGRAM_RELEASE_CALLBACK_ERR);
6887  }
6888 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
6889 
6894  template <typename T>
6895  typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6896  setSpecializationConstant(cl_uint index, const T &value)
6897  {
6898  return detail::errHandler(
6899  ::clSetProgramSpecializationConstant(
6900  object_,
6901  index,
6902  sizeof(value),
6903  &value),
6904  __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6905  }
6906 
6911  cl_int setSpecializationConstant(cl_uint index, size_type size, const void* value)
6912  {
6913  return detail::errHandler(
6914  ::clSetProgramSpecializationConstant(
6915  object_,
6916  index,
6917  size,
6918  value),
6919  __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6920  }
6921 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
6922 };
6923 
6924 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6925 inline Program linkProgram(
6926  Program input1,
6927  Program input2,
6928  const char* options = NULL,
6929  void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6930  void* data = NULL,
6931  cl_int* err = NULL)
6932 {
6933  cl_int error_local = CL_SUCCESS;
6934 
6935  cl_program programs[2] = { input1(), input2() };
6936 
6937  Context ctx = input1.getInfo<CL_PROGRAM_CONTEXT>(&error_local);
6938  if(error_local!=CL_SUCCESS) {
6939  detail::errHandler(error_local, __LINK_PROGRAM_ERR);
6940  }
6941 
6942  cl_program prog = ::clLinkProgram(
6943  ctx(),
6944  0,
6945  NULL,
6946  options,
6947  2,
6948  programs,
6949  notifyFptr,
6950  data,
6951  &error_local);
6952 
6953  detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
6954  if (err != NULL) {
6955  *err = error_local;
6956  }
6957 
6958  return Program(prog);
6959 }
6960 
6961 inline Program linkProgram(
6962  vector<Program> inputPrograms,
6963  const char* options = NULL,
6964  void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6965  void* data = NULL,
6966  cl_int* err = NULL)
6967 {
6968  cl_int error_local = CL_SUCCESS;
6969 
6970  vector<cl_program> programs(inputPrograms.size());
6971 
6972  for (unsigned int i = 0; i < inputPrograms.size(); i++) {
6973  programs[i] = inputPrograms[i]();
6974  }
6975 
6976  Context ctx;
6977  if(inputPrograms.size() > 0) {
6978  ctx = inputPrograms[0].getInfo<CL_PROGRAM_CONTEXT>(&error_local);
6979  if(error_local!=CL_SUCCESS) {
6980  detail::errHandler(error_local, __LINK_PROGRAM_ERR);
6981  }
6982  }
6983  cl_program prog = ::clLinkProgram(
6984  ctx(),
6985  0,
6986  NULL,
6987  options,
6988  (cl_uint)inputPrograms.size(),
6989  programs.data(),
6990  notifyFptr,
6991  data,
6992  &error_local);
6993 
6994  detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
6995  if (err != NULL) {
6996  *err = error_local;
6997  }
6998 
6999  return Program(prog, false);
7000 }
7001 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7002 
7003 // Template specialization for CL_PROGRAM_BINARIES
7004 template <>
7005 inline cl_int cl::Program::getInfo(cl_program_info name, vector<vector<unsigned char>>* param) const
7006 {
7007  if (name != CL_PROGRAM_BINARIES) {
7008  return CL_INVALID_VALUE;
7009  }
7010  if (param) {
7011  // Resize the parameter array appropriately for each allocation
7012  // and pass down to the helper
7013 
7014  vector<size_type> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>();
7015  size_type numBinaries = sizes.size();
7016 
7017  // Resize the parameter array and constituent arrays
7018  param->resize(numBinaries);
7019  for (size_type i = 0; i < numBinaries; ++i) {
7020  (*param)[i].resize(sizes[i]);
7021  }
7022 
7023  return detail::errHandler(
7024  detail::getInfo(&::clGetProgramInfo, object_, name, param),
7025  __GET_PROGRAM_INFO_ERR);
7026  }
7027 
7028  return CL_SUCCESS;
7029 }
7030 
7031 template<>
7032 inline vector<vector<unsigned char>> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err) const
7033 {
7034  vector<vector<unsigned char>> binariesVectors;
7035 
7036  cl_int result = getInfo(CL_PROGRAM_BINARIES, &binariesVectors);
7037  if (err != NULL) {
7038  *err = result;
7039  }
7040  return binariesVectors;
7041 }
7042 
7043 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
7044 // Template specialization for clSetProgramSpecializationConstant
7045 template <>
7046 inline cl_int cl::Program::setSpecializationConstant(cl_uint index, const bool &value)
7047 {
7048  cl_uchar ucValue = value ? CL_UCHAR_MAX : 0;
7049  return detail::errHandler(
7050  ::clSetProgramSpecializationConstant(
7051  object_,
7052  index,
7053  sizeof(ucValue),
7054  &ucValue),
7055  __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
7056 }
7057 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
7058 
7059 inline Kernel::Kernel(const Program& program, const char* name, cl_int* err)
7060 {
7061  cl_int error;
7062 
7063  object_ = ::clCreateKernel(program(), name, &error);
7064  detail::errHandler(error, __CREATE_KERNEL_ERR);
7065 
7066  if (err != NULL) {
7067  *err = error;
7068  }
7069 
7070 }
7071 
7072 enum class QueueProperties : cl_command_queue_properties
7073 {
7074  None = 0,
7075  Profiling = CL_QUEUE_PROFILING_ENABLE,
7076  OutOfOrder = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,
7077 };
7078 
7079 inline QueueProperties operator|(QueueProperties lhs, QueueProperties rhs)
7080 {
7081  return static_cast<QueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
7082 }
7083 
7087 class CommandQueue : public detail::Wrapper<cl_command_queue>
7088 {
7089 private:
7090  static std::once_flag default_initialized_;
7091  static CommandQueue default_;
7092  static cl_int default_error_;
7093 
7099  static void makeDefault()
7100  {
7101  /* We don't want to throw an error from this function, so we have to
7102  * catch and set the error flag.
7103  */
7104 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
7105  try
7106 #endif
7107  {
7108  int error;
7109  Context context = Context::getDefault(&error);
7110 
7111  if (error != CL_SUCCESS) {
7112  default_error_ = error;
7113  }
7114  else {
7115  Device device = Device::getDefault();
7116  default_ = CommandQueue(context, device, 0, &default_error_);
7117  }
7118  }
7119 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
7120  catch (cl::Error &e) {
7121  default_error_ = e.err();
7122  }
7123 #endif
7124  }
7125 
7131  static void makeDefaultProvided(const CommandQueue &c) {
7132  default_ = c;
7133  }
7134 
7135 public:
7136 #ifdef CL_HPP_UNIT_TEST_ENABLE
7143  static void unitTestClearDefault() {
7144  default_ = CommandQueue();
7145  }
7146 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
7147 
7148 
7154  cl_command_queue_properties properties,
7155  cl_int* err = NULL)
7156  {
7157  cl_int error;
7158 
7159  Context context = Context::getDefault(&error);
7160  detail::errHandler(error, __CREATE_CONTEXT_ERR);
7161 
7162  if (error != CL_SUCCESS) {
7163  if (err != NULL) {
7164  *err = error;
7165  }
7166  }
7167  else {
7168  Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7169  bool useWithProperties;
7170 
7171 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7172  // Run-time decision based on the actual platform
7173  {
7174  cl_uint version = detail::getContextPlatformVersion(context());
7175  useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7176  }
7177 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7178  useWithProperties = true;
7179 #else
7180  useWithProperties = false;
7181 #endif
7182 
7183 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7184  if (useWithProperties) {
7185  cl_queue_properties queue_properties[] = {
7186  CL_QUEUE_PROPERTIES, properties, 0 };
7187  if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7188  object_ = ::clCreateCommandQueueWithProperties(
7189  context(), device(), queue_properties, &error);
7190  }
7191  else {
7192  error = CL_INVALID_QUEUE_PROPERTIES;
7193  }
7194 
7195  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7196  if (err != NULL) {
7197  *err = error;
7198  }
7199  }
7200 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7201 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7202  if (!useWithProperties) {
7203  object_ = ::clCreateCommandQueue(
7204  context(), device(), properties, &error);
7205 
7206  detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7207  if (err != NULL) {
7208  *err = error;
7209  }
7210  }
7211 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7212  }
7213  }
7214 
7220  QueueProperties properties,
7221  cl_int* err = NULL)
7222  {
7223  cl_int error;
7224 
7225  Context context = Context::getDefault(&error);
7226  detail::errHandler(error, __CREATE_CONTEXT_ERR);
7227 
7228  if (error != CL_SUCCESS) {
7229  if (err != NULL) {
7230  *err = error;
7231  }
7232  }
7233  else {
7234  Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7235  bool useWithProperties;
7236 
7237 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7238  // Run-time decision based on the actual platform
7239  {
7240  cl_uint version = detail::getContextPlatformVersion(context());
7241  useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7242  }
7243 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7244  useWithProperties = true;
7245 #else
7246  useWithProperties = false;
7247 #endif
7248 
7249 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7250  if (useWithProperties) {
7251  cl_queue_properties queue_properties[] = {
7252  CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7253 
7254  object_ = ::clCreateCommandQueueWithProperties(
7255  context(), device(), queue_properties, &error);
7256 
7257  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7258  if (err != NULL) {
7259  *err = error;
7260  }
7261  }
7262 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7263 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7264  if (!useWithProperties) {
7265  object_ = ::clCreateCommandQueue(
7266  context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
7267 
7268  detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7269  if (err != NULL) {
7270  *err = error;
7271  }
7272  }
7273 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7274 
7275  }
7276  }
7277 
7282  explicit CommandQueue(
7283  const Context& context,
7284  cl_command_queue_properties properties = 0,
7285  cl_int* err = NULL)
7286  {
7287  cl_int error;
7288  bool useWithProperties;
7289  vector<cl::Device> devices;
7290  error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7291 
7292  detail::errHandler(error, __CREATE_CONTEXT_ERR);
7293 
7294  if (error != CL_SUCCESS)
7295  {
7296  if (err != NULL) {
7297  *err = error;
7298  }
7299  return;
7300  }
7301 
7302 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7303  // Run-time decision based on the actual platform
7304  {
7305  cl_uint version = detail::getContextPlatformVersion(context());
7306  useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7307  }
7308 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7309  useWithProperties = true;
7310 #else
7311  useWithProperties = false;
7312 #endif
7313 
7314 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7315  if (useWithProperties) {
7316  cl_queue_properties queue_properties[] = {
7317  CL_QUEUE_PROPERTIES, properties, 0 };
7318  if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7319  object_ = ::clCreateCommandQueueWithProperties(
7320  context(), devices[0](), queue_properties, &error);
7321  }
7322  else {
7323  error = CL_INVALID_QUEUE_PROPERTIES;
7324  }
7325 
7326  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7327  if (err != NULL) {
7328  *err = error;
7329  }
7330  }
7331 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7332 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7333  if (!useWithProperties) {
7334  object_ = ::clCreateCommandQueue(
7335  context(), devices[0](), properties, &error);
7336 
7337  detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7338  if (err != NULL) {
7339  *err = error;
7340  }
7341  }
7342 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7343  }
7344 
7349  explicit CommandQueue(
7350  const Context& context,
7351  QueueProperties properties,
7352  cl_int* err = NULL)
7353  {
7354  cl_int error;
7355  bool useWithProperties;
7356  vector<cl::Device> devices;
7357  error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7358 
7359  detail::errHandler(error, __CREATE_CONTEXT_ERR);
7360 
7361  if (error != CL_SUCCESS)
7362  {
7363  if (err != NULL) {
7364  *err = error;
7365  }
7366  return;
7367  }
7368 
7369 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7370  // Run-time decision based on the actual platform
7371  {
7372  cl_uint version = detail::getContextPlatformVersion(context());
7373  useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7374  }
7375 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7376  useWithProperties = true;
7377 #else
7378  useWithProperties = false;
7379 #endif
7380 
7381 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7382  if (useWithProperties) {
7383  cl_queue_properties queue_properties[] = {
7384  CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7385  object_ = ::clCreateCommandQueueWithProperties(
7386  context(), devices[0](), queue_properties, &error);
7387 
7388  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7389  if (err != NULL) {
7390  *err = error;
7391  }
7392  }
7393 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7394 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7395  if (!useWithProperties) {
7396  object_ = ::clCreateCommandQueue(
7397  context(), devices[0](), static_cast<cl_command_queue_properties>(properties), &error);
7398 
7399  detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7400  if (err != NULL) {
7401  *err = error;
7402  }
7403  }
7404 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7405  }
7406 
7412  const Context& context,
7413  const Device& device,
7414  cl_command_queue_properties properties = 0,
7415  cl_int* err = NULL)
7416  {
7417  cl_int error;
7418  bool useWithProperties;
7419 
7420 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7421  // Run-time decision based on the actual platform
7422  {
7423  cl_uint version = detail::getContextPlatformVersion(context());
7424  useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7425  }
7426 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7427  useWithProperties = true;
7428 #else
7429  useWithProperties = false;
7430 #endif
7431 
7432 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7433  if (useWithProperties) {
7434  cl_queue_properties queue_properties[] = {
7435  CL_QUEUE_PROPERTIES, properties, 0 };
7436  object_ = ::clCreateCommandQueueWithProperties(
7437  context(), device(), queue_properties, &error);
7438 
7439  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7440  if (err != NULL) {
7441  *err = error;
7442  }
7443  }
7444 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7445 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7446  if (!useWithProperties) {
7447  object_ = ::clCreateCommandQueue(
7448  context(), device(), properties, &error);
7449 
7450  detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7451  if (err != NULL) {
7452  *err = error;
7453  }
7454  }
7455 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7456  }
7457 
7463  const Context& context,
7464  const Device& device,
7465  QueueProperties properties,
7466  cl_int* err = NULL)
7467  {
7468  cl_int error;
7469  bool useWithProperties;
7470 
7471 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7472  // Run-time decision based on the actual platform
7473  {
7474  cl_uint version = detail::getContextPlatformVersion(context());
7475  useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7476  }
7477 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7478  useWithProperties = true;
7479 #else
7480  useWithProperties = false;
7481 #endif
7482 
7483 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7484  if (useWithProperties) {
7485  cl_queue_properties queue_properties[] = {
7486  CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7487  object_ = ::clCreateCommandQueueWithProperties(
7488  context(), device(), queue_properties, &error);
7489 
7490  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7491  if (err != NULL) {
7492  *err = error;
7493  }
7494  }
7495 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7496 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7497  if (!useWithProperties) {
7498  object_ = ::clCreateCommandQueue(
7499  context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
7500 
7501  detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7502  if (err != NULL) {
7503  *err = error;
7504  }
7505  }
7506 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7507  }
7508 
7509  static CommandQueue getDefault(cl_int * err = NULL)
7510  {
7511  std::call_once(default_initialized_, makeDefault);
7512 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7513  detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7514 #else // CL_HPP_TARGET_OPENCL_VERSION >= 200
7515  detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_ERR);
7516 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7517  if (err != NULL) {
7518  *err = default_error_;
7519  }
7520  return default_;
7521  }
7522 
7530  static CommandQueue setDefault(const CommandQueue &default_queue)
7531  {
7532  std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_queue));
7533  detail::errHandler(default_error_);
7534  return default_;
7535  }
7536 
7537  CommandQueue() { }
7538 
7539 
7546  explicit CommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
7547  detail::Wrapper<cl_type>(commandQueue, retainObject) { }
7548 
7549  CommandQueue& operator = (const cl_command_queue& rhs)
7550  {
7552  return *this;
7553  }
7554 
7558  CommandQueue(const CommandQueue& queue) : detail::Wrapper<cl_type>(queue) {}
7559 
7563  CommandQueue& operator = (const CommandQueue &queue)
7564  {
7566  return *this;
7567  }
7568 
7572  CommandQueue(CommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(queue)) {}
7573 
7577  CommandQueue& operator = (CommandQueue &&queue)
7578  {
7579  detail::Wrapper<cl_type>::operator=(std::move(queue));
7580  return *this;
7581  }
7582 
7583  template <typename T>
7584  cl_int getInfo(cl_command_queue_info name, T* param) const
7585  {
7586  return detail::errHandler(
7587  detail::getInfo(
7588  &::clGetCommandQueueInfo, object_, name, param),
7589  __GET_COMMAND_QUEUE_INFO_ERR);
7590  }
7591 
7592  template <cl_command_queue_info name> typename
7593  detail::param_traits<detail::cl_command_queue_info, name>::param_type
7594  getInfo(cl_int* err = NULL) const
7595  {
7596  typename detail::param_traits<
7597  detail::cl_command_queue_info, name>::param_type param;
7598  cl_int result = getInfo(name, &param);
7599  if (err != NULL) {
7600  *err = result;
7601  }
7602  return param;
7603  }
7604 
7605  cl_int enqueueReadBuffer(
7606  const Buffer& buffer,
7607  cl_bool blocking,
7608  size_type offset,
7609  size_type size,
7610  void* ptr,
7611  const vector<Event>* events = NULL,
7612  Event* event = NULL) const
7613  {
7614  cl_event tmp;
7615  cl_int err = detail::errHandler(
7616  ::clEnqueueReadBuffer(
7617  object_, buffer(), blocking, offset, size,
7618  ptr,
7619  (events != NULL) ? (cl_uint) events->size() : 0,
7620  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7621  (event != NULL) ? &tmp : NULL),
7622  __ENQUEUE_READ_BUFFER_ERR);
7623 
7624  if (event != NULL && err == CL_SUCCESS)
7625  *event = tmp;
7626 
7627  return err;
7628  }
7629 
7630  cl_int enqueueWriteBuffer(
7631  const Buffer& buffer,
7632  cl_bool blocking,
7633  size_type offset,
7634  size_type size,
7635  const void* ptr,
7636  const vector<Event>* events = NULL,
7637  Event* event = NULL) const
7638  {
7639  cl_event tmp;
7640  cl_int err = detail::errHandler(
7641  ::clEnqueueWriteBuffer(
7642  object_, buffer(), blocking, offset, size,
7643  ptr,
7644  (events != NULL) ? (cl_uint) events->size() : 0,
7645  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7646  (event != NULL) ? &tmp : NULL),
7647  __ENQUEUE_WRITE_BUFFER_ERR);
7648 
7649  if (event != NULL && err == CL_SUCCESS)
7650  *event = tmp;
7651 
7652  return err;
7653  }
7654 
7655  cl_int enqueueCopyBuffer(
7656  const Buffer& src,
7657  const Buffer& dst,
7658  size_type src_offset,
7659  size_type dst_offset,
7660  size_type size,
7661  const vector<Event>* events = NULL,
7662  Event* event = NULL) const
7663  {
7664  cl_event tmp;
7665  cl_int err = detail::errHandler(
7666  ::clEnqueueCopyBuffer(
7667  object_, src(), dst(), src_offset, dst_offset, size,
7668  (events != NULL) ? (cl_uint) events->size() : 0,
7669  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7670  (event != NULL) ? &tmp : NULL),
7671  __ENQEUE_COPY_BUFFER_ERR);
7672 
7673  if (event != NULL && err == CL_SUCCESS)
7674  *event = tmp;
7675 
7676  return err;
7677  }
7678 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
7679  cl_int enqueueReadBufferRect(
7680  const Buffer& buffer,
7681  cl_bool blocking,
7682  const array<size_type, 3>& buffer_offset,
7683  const array<size_type, 3>& host_offset,
7684  const array<size_type, 3>& region,
7685  size_type buffer_row_pitch,
7686  size_type buffer_slice_pitch,
7687  size_type host_row_pitch,
7688  size_type host_slice_pitch,
7689  void *ptr,
7690  const vector<Event>* events = NULL,
7691  Event* event = NULL) const
7692  {
7693  cl_event tmp;
7694  cl_int err = detail::errHandler(
7695  ::clEnqueueReadBufferRect(
7696  object_,
7697  buffer(),
7698  blocking,
7699  buffer_offset.data(),
7700  host_offset.data(),
7701  region.data(),
7702  buffer_row_pitch,
7703  buffer_slice_pitch,
7704  host_row_pitch,
7705  host_slice_pitch,
7706  ptr,
7707  (events != NULL) ? (cl_uint) events->size() : 0,
7708  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7709  (event != NULL) ? &tmp : NULL),
7710  __ENQUEUE_READ_BUFFER_RECT_ERR);
7711 
7712  if (event != NULL && err == CL_SUCCESS)
7713  *event = tmp;
7714 
7715  return err;
7716  }
7717 
7718  cl_int enqueueWriteBufferRect(
7719  const Buffer& buffer,
7720  cl_bool blocking,
7721  const array<size_type, 3>& buffer_offset,
7722  const array<size_type, 3>& host_offset,
7723  const array<size_type, 3>& region,
7724  size_type buffer_row_pitch,
7725  size_type buffer_slice_pitch,
7726  size_type host_row_pitch,
7727  size_type host_slice_pitch,
7728  const void *ptr,
7729  const vector<Event>* events = NULL,
7730  Event* event = NULL) const
7731  {
7732  cl_event tmp;
7733  cl_int err = detail::errHandler(
7734  ::clEnqueueWriteBufferRect(
7735  object_,
7736  buffer(),
7737  blocking,
7738  buffer_offset.data(),
7739  host_offset.data(),
7740  region.data(),
7741  buffer_row_pitch,
7742  buffer_slice_pitch,
7743  host_row_pitch,
7744  host_slice_pitch,
7745  ptr,
7746  (events != NULL) ? (cl_uint) events->size() : 0,
7747  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7748  (event != NULL) ? &tmp : NULL),
7749  __ENQUEUE_WRITE_BUFFER_RECT_ERR);
7750 
7751  if (event != NULL && err == CL_SUCCESS)
7752  *event = tmp;
7753 
7754  return err;
7755  }
7756 
7757  cl_int enqueueCopyBufferRect(
7758  const Buffer& src,
7759  const Buffer& dst,
7760  const array<size_type, 3>& src_origin,
7761  const array<size_type, 3>& dst_origin,
7762  const array<size_type, 3>& region,
7763  size_type src_row_pitch,
7764  size_type src_slice_pitch,
7765  size_type dst_row_pitch,
7766  size_type dst_slice_pitch,
7767  const vector<Event>* events = NULL,
7768  Event* event = NULL) const
7769  {
7770  cl_event tmp;
7771  cl_int err = detail::errHandler(
7772  ::clEnqueueCopyBufferRect(
7773  object_,
7774  src(),
7775  dst(),
7776  src_origin.data(),
7777  dst_origin.data(),
7778  region.data(),
7779  src_row_pitch,
7780  src_slice_pitch,
7781  dst_row_pitch,
7782  dst_slice_pitch,
7783  (events != NULL) ? (cl_uint) events->size() : 0,
7784  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7785  (event != NULL) ? &tmp : NULL),
7786  __ENQEUE_COPY_BUFFER_RECT_ERR);
7787 
7788  if (event != NULL && err == CL_SUCCESS)
7789  *event = tmp;
7790 
7791  return err;
7792  }
7793 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
7794 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
7806  template<typename PatternType>
7808  const Buffer& buffer,
7809  PatternType pattern,
7810  size_type offset,
7811  size_type size,
7812  const vector<Event>* events = NULL,
7813  Event* event = NULL) const
7814  {
7815  cl_event tmp;
7816  cl_int err = detail::errHandler(
7817  ::clEnqueueFillBuffer(
7818  object_,
7819  buffer(),
7820  static_cast<void*>(&pattern),
7821  sizeof(PatternType),
7822  offset,
7823  size,
7824  (events != NULL) ? (cl_uint) events->size() : 0,
7825  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7826  (event != NULL) ? &tmp : NULL),
7827  __ENQUEUE_FILL_BUFFER_ERR);
7828 
7829  if (event != NULL && err == CL_SUCCESS)
7830  *event = tmp;
7831 
7832  return err;
7833  }
7834 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7835 
7836  cl_int enqueueReadImage(
7837  const Image& image,
7838  cl_bool blocking,
7839  const array<size_type, 3>& origin,
7840  const array<size_type, 3>& region,
7841  size_type row_pitch,
7842  size_type slice_pitch,
7843  void* ptr,
7844  const vector<Event>* events = NULL,
7845  Event* event = NULL) const
7846  {
7847  cl_event tmp;
7848  cl_int err = detail::errHandler(
7849  ::clEnqueueReadImage(
7850  object_,
7851  image(),
7852  blocking,
7853  origin.data(),
7854  region.data(),
7855  row_pitch,
7856  slice_pitch,
7857  ptr,
7858  (events != NULL) ? (cl_uint) events->size() : 0,
7859  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7860  (event != NULL) ? &tmp : NULL),
7861  __ENQUEUE_READ_IMAGE_ERR);
7862 
7863  if (event != NULL && err == CL_SUCCESS)
7864  *event = tmp;
7865 
7866  return err;
7867  }
7868 
7869  cl_int enqueueWriteImage(
7870  const Image& image,
7871  cl_bool blocking,
7872  const array<size_type, 3>& origin,
7873  const array<size_type, 3>& region,
7874  size_type row_pitch,
7875  size_type slice_pitch,
7876  const void* ptr,
7877  const vector<Event>* events = NULL,
7878  Event* event = NULL) const
7879  {
7880  cl_event tmp;
7881  cl_int err = detail::errHandler(
7882  ::clEnqueueWriteImage(
7883  object_,
7884  image(),
7885  blocking,
7886  origin.data(),
7887  region.data(),
7888  row_pitch,
7889  slice_pitch,
7890  ptr,
7891  (events != NULL) ? (cl_uint) events->size() : 0,
7892  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7893  (event != NULL) ? &tmp : NULL),
7894  __ENQUEUE_WRITE_IMAGE_ERR);
7895 
7896  if (event != NULL && err == CL_SUCCESS)
7897  *event = tmp;
7898 
7899  return err;
7900  }
7901 
7902  cl_int enqueueCopyImage(
7903  const Image& src,
7904  const Image& dst,
7905  const array<size_type, 3>& src_origin,
7906  const array<size_type, 3>& dst_origin,
7907  const array<size_type, 3>& region,
7908  const vector<Event>* events = NULL,
7909  Event* event = NULL) const
7910  {
7911  cl_event tmp;
7912  cl_int err = detail::errHandler(
7913  ::clEnqueueCopyImage(
7914  object_,
7915  src(),
7916  dst(),
7917  src_origin.data(),
7918  dst_origin.data(),
7919  region.data(),
7920  (events != NULL) ? (cl_uint) events->size() : 0,
7921  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7922  (event != NULL) ? &tmp : NULL),
7923  __ENQUEUE_COPY_IMAGE_ERR);
7924 
7925  if (event != NULL && err == CL_SUCCESS)
7926  *event = tmp;
7927 
7928  return err;
7929  }
7930 
7931 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
7940  const Image& image,
7941  cl_float4 fillColor,
7942  const array<size_type, 3>& origin,
7943  const array<size_type, 3>& region,
7944  const vector<Event>* events = NULL,
7945  Event* event = NULL) const
7946  {
7947  cl_event tmp;
7948  cl_int err = detail::errHandler(
7949  ::clEnqueueFillImage(
7950  object_,
7951  image(),
7952  static_cast<void*>(&fillColor),
7953  origin.data(),
7954  region.data(),
7955  (events != NULL) ? (cl_uint) events->size() : 0,
7956  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7957  (event != NULL) ? &tmp : NULL),
7958  __ENQUEUE_FILL_IMAGE_ERR);
7959 
7960  if (event != NULL && err == CL_SUCCESS)
7961  *event = tmp;
7962 
7963  return err;
7964  }
7965 
7974  const Image& image,
7975  cl_int4 fillColor,
7976  const array<size_type, 3>& origin,
7977  const array<size_type, 3>& region,
7978  const vector<Event>* events = NULL,
7979  Event* event = NULL) const
7980  {
7981  cl_event tmp;
7982  cl_int err = detail::errHandler(
7983  ::clEnqueueFillImage(
7984  object_,
7985  image(),
7986  static_cast<void*>(&fillColor),
7987  origin.data(),
7988  region.data(),
7989  (events != NULL) ? (cl_uint) events->size() : 0,
7990  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7991  (event != NULL) ? &tmp : NULL),
7992  __ENQUEUE_FILL_IMAGE_ERR);
7993 
7994  if (event != NULL && err == CL_SUCCESS)
7995  *event = tmp;
7996 
7997  return err;
7998  }
7999 
8008  const Image& image,
8009  cl_uint4 fillColor,
8010  const array<size_type, 3>& origin,
8011  const array<size_type, 3>& region,
8012  const vector<Event>* events = NULL,
8013  Event* event = NULL) const
8014  {
8015  cl_event tmp;
8016  cl_int err = detail::errHandler(
8017  ::clEnqueueFillImage(
8018  object_,
8019  image(),
8020  static_cast<void*>(&fillColor),
8021  origin.data(),
8022  region.data(),
8023  (events != NULL) ? (cl_uint) events->size() : 0,
8024  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8025  (event != NULL) ? &tmp : NULL),
8026  __ENQUEUE_FILL_IMAGE_ERR);
8027 
8028  if (event != NULL && err == CL_SUCCESS)
8029  *event = tmp;
8030 
8031  return err;
8032  }
8033 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8034 
8035  cl_int enqueueCopyImageToBuffer(
8036  const Image& src,
8037  const Buffer& dst,
8038  const array<size_type, 3>& src_origin,
8039  const array<size_type, 3>& region,
8040  size_type dst_offset,
8041  const vector<Event>* events = NULL,
8042  Event* event = NULL) const
8043  {
8044  cl_event tmp;
8045  cl_int err = detail::errHandler(
8046  ::clEnqueueCopyImageToBuffer(
8047  object_,
8048  src(),
8049  dst(),
8050  src_origin.data(),
8051  region.data(),
8052  dst_offset,
8053  (events != NULL) ? (cl_uint) events->size() : 0,
8054  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8055  (event != NULL) ? &tmp : NULL),
8056  __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
8057 
8058  if (event != NULL && err == CL_SUCCESS)
8059  *event = tmp;
8060 
8061  return err;
8062  }
8063 
8064  cl_int enqueueCopyBufferToImage(
8065  const Buffer& src,
8066  const Image& dst,
8067  size_type src_offset,
8068  const array<size_type, 3>& dst_origin,
8069  const array<size_type, 3>& region,
8070  const vector<Event>* events = NULL,
8071  Event* event = NULL) const
8072  {
8073  cl_event tmp;
8074  cl_int err = detail::errHandler(
8075  ::clEnqueueCopyBufferToImage(
8076  object_,
8077  src(),
8078  dst(),
8079  src_offset,
8080  dst_origin.data(),
8081  region.data(),
8082  (events != NULL) ? (cl_uint) events->size() : 0,
8083  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8084  (event != NULL) ? &tmp : NULL),
8085  __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
8086 
8087  if (event != NULL && err == CL_SUCCESS)
8088  *event = tmp;
8089 
8090  return err;
8091  }
8092 
8093  void* enqueueMapBuffer(
8094  const Buffer& buffer,
8095  cl_bool blocking,
8096  cl_map_flags flags,
8097  size_type offset,
8098  size_type size,
8099  const vector<Event>* events = NULL,
8100  Event* event = NULL,
8101  cl_int* err = NULL) const
8102  {
8103  cl_event tmp;
8104  cl_int error;
8105  void * result = ::clEnqueueMapBuffer(
8106  object_, buffer(), blocking, flags, offset, size,
8107  (events != NULL) ? (cl_uint) events->size() : 0,
8108  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8109  (event != NULL) ? &tmp : NULL,
8110  &error);
8111 
8112  detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
8113  if (err != NULL) {
8114  *err = error;
8115  }
8116  if (event != NULL && error == CL_SUCCESS)
8117  *event = tmp;
8118 
8119  return result;
8120  }
8121 
8122  void* enqueueMapImage(
8123  const Image& buffer,
8124  cl_bool blocking,
8125  cl_map_flags flags,
8126  const array<size_type, 3>& origin,
8127  const array<size_type, 3>& region,
8128  size_type * row_pitch,
8129  size_type * slice_pitch,
8130  const vector<Event>* events = NULL,
8131  Event* event = NULL,
8132  cl_int* err = NULL) const
8133  {
8134  cl_event tmp;
8135  cl_int error;
8136  void * result = ::clEnqueueMapImage(
8137  object_, buffer(), blocking, flags,
8138  origin.data(),
8139  region.data(),
8140  row_pitch, slice_pitch,
8141  (events != NULL) ? (cl_uint) events->size() : 0,
8142  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8143  (event != NULL) ? &tmp : NULL,
8144  &error);
8145 
8146  detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
8147  if (err != NULL) {
8148  *err = error;
8149  }
8150  if (event != NULL && error == CL_SUCCESS)
8151  *event = tmp;
8152  return result;
8153  }
8154 
8155 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8160  template<typename T>
8162  T* ptr,
8163  cl_bool blocking,
8164  cl_map_flags flags,
8165  size_type size,
8166  const vector<Event>* events = NULL,
8167  Event* event = NULL) const
8168  {
8169  cl_event tmp;
8170  cl_int err = detail::errHandler(::clEnqueueSVMMap(
8171  object_, blocking, flags, static_cast<void*>(ptr), size,
8172  (events != NULL) ? (cl_uint)events->size() : 0,
8173  (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8174  (event != NULL) ? &tmp : NULL),
8175  __ENQUEUE_MAP_BUFFER_ERR);
8176 
8177  if (event != NULL && err == CL_SUCCESS)
8178  *event = tmp;
8179 
8180  return err;
8181  }
8182 
8183 
8188  template<typename T, class D>
8190  cl::pointer<T, D> &ptr,
8191  cl_bool blocking,
8192  cl_map_flags flags,
8193  size_type size,
8194  const vector<Event>* events = NULL,
8195  Event* event = NULL) const
8196  {
8197  cl_event tmp;
8198  cl_int err = detail::errHandler(::clEnqueueSVMMap(
8199  object_, blocking, flags, static_cast<void*>(ptr.get()), size,
8200  (events != NULL) ? (cl_uint)events->size() : 0,
8201  (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8202  (event != NULL) ? &tmp : NULL),
8203  __ENQUEUE_MAP_BUFFER_ERR);
8204 
8205  if (event != NULL && err == CL_SUCCESS)
8206  *event = tmp;
8207 
8208  return err;
8209  }
8210 
8215  template<typename T, class Alloc>
8217  cl::vector<T, Alloc> &container,
8218  cl_bool blocking,
8219  cl_map_flags flags,
8220  const vector<Event>* events = NULL,
8221  Event* event = NULL) const
8222  {
8223  cl_event tmp;
8224  cl_int err = detail::errHandler(::clEnqueueSVMMap(
8225  object_, blocking, flags, static_cast<void*>(container.data()), container.size()*sizeof(T),
8226  (events != NULL) ? (cl_uint)events->size() : 0,
8227  (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8228  (event != NULL) ? &tmp : NULL),
8229  __ENQUEUE_MAP_BUFFER_ERR);
8230 
8231  if (event != NULL && err == CL_SUCCESS)
8232  *event = tmp;
8233 
8234  return err;
8235  }
8236 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8237 
8238  cl_int enqueueUnmapMemObject(
8239  const Memory& memory,
8240  void* mapped_ptr,
8241  const vector<Event>* events = NULL,
8242  Event* event = NULL) const
8243  {
8244  cl_event tmp;
8245  cl_int err = detail::errHandler(
8246  ::clEnqueueUnmapMemObject(
8247  object_, memory(), mapped_ptr,
8248  (events != NULL) ? (cl_uint) events->size() : 0,
8249  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8250  (event != NULL) ? &tmp : NULL),
8251  __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8252 
8253  if (event != NULL && err == CL_SUCCESS)
8254  *event = tmp;
8255 
8256  return err;
8257  }
8258 
8259 
8260 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8265  template<typename T>
8267  T* ptr,
8268  const vector<Event>* events = NULL,
8269  Event* event = NULL) const
8270  {
8271  cl_event tmp;
8272  cl_int err = detail::errHandler(
8273  ::clEnqueueSVMUnmap(
8274  object_, static_cast<void*>(ptr),
8275  (events != NULL) ? (cl_uint)events->size() : 0,
8276  (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8277  (event != NULL) ? &tmp : NULL),
8278  __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8279 
8280  if (event != NULL && err == CL_SUCCESS)
8281  *event = tmp;
8282 
8283  return err;
8284  }
8285 
8290  template<typename T, class D>
8292  cl::pointer<T, D> &ptr,
8293  const vector<Event>* events = NULL,
8294  Event* event = NULL) const
8295  {
8296  cl_event tmp;
8297  cl_int err = detail::errHandler(
8298  ::clEnqueueSVMUnmap(
8299  object_, static_cast<void*>(ptr.get()),
8300  (events != NULL) ? (cl_uint)events->size() : 0,
8301  (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8302  (event != NULL) ? &tmp : NULL),
8303  __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8304 
8305  if (event != NULL && err == CL_SUCCESS)
8306  *event = tmp;
8307 
8308  return err;
8309  }
8310 
8315  template<typename T, class Alloc>
8317  cl::vector<T, Alloc> &container,
8318  const vector<Event>* events = NULL,
8319  Event* event = NULL) const
8320  {
8321  cl_event tmp;
8322  cl_int err = detail::errHandler(
8323  ::clEnqueueSVMUnmap(
8324  object_, static_cast<void*>(container.data()),
8325  (events != NULL) ? (cl_uint)events->size() : 0,
8326  (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8327  (event != NULL) ? &tmp : NULL),
8328  __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8329 
8330  if (event != NULL && err == CL_SUCCESS)
8331  *event = tmp;
8332 
8333  return err;
8334  }
8335 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8336 
8337 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8350  const vector<Event> *events = 0,
8351  Event *event = 0) const
8352  {
8353  cl_event tmp;
8354  cl_int err = detail::errHandler(
8355  ::clEnqueueMarkerWithWaitList(
8356  object_,
8357  (events != NULL) ? (cl_uint) events->size() : 0,
8358  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8359  (event != NULL) ? &tmp : NULL),
8360  __ENQUEUE_MARKER_WAIT_LIST_ERR);
8361 
8362  if (event != NULL && err == CL_SUCCESS)
8363  *event = tmp;
8364 
8365  return err;
8366  }
8367 
8380  const vector<Event> *events = 0,
8381  Event *event = 0) const
8382  {
8383  cl_event tmp;
8384  cl_int err = detail::errHandler(
8385  ::clEnqueueBarrierWithWaitList(
8386  object_,
8387  (events != NULL) ? (cl_uint) events->size() : 0,
8388  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8389  (event != NULL) ? &tmp : NULL),
8390  __ENQUEUE_BARRIER_WAIT_LIST_ERR);
8391 
8392  if (event != NULL && err == CL_SUCCESS)
8393  *event = tmp;
8394 
8395  return err;
8396  }
8397 
8403  const vector<Memory> &memObjects,
8404  cl_mem_migration_flags flags,
8405  const vector<Event>* events = NULL,
8406  Event* event = NULL
8407  ) const
8408  {
8409  cl_event tmp;
8410 
8411  vector<cl_mem> localMemObjects(memObjects.size());
8412 
8413  for( int i = 0; i < (int)memObjects.size(); ++i ) {
8414  localMemObjects[i] = memObjects[i]();
8415  }
8416 
8417  cl_int err = detail::errHandler(
8418  ::clEnqueueMigrateMemObjects(
8419  object_,
8420  (cl_uint)memObjects.size(),
8421  localMemObjects.data(),
8422  flags,
8423  (events != NULL) ? (cl_uint) events->size() : 0,
8424  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8425  (event != NULL) ? &tmp : NULL),
8426  __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8427 
8428  if (event != NULL && err == CL_SUCCESS)
8429  *event = tmp;
8430 
8431  return err;
8432  }
8433 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8434 
8435 
8436 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8442  template<typename T>
8444  const cl::vector<T*> &svmRawPointers,
8445  const cl::vector<size_type> &sizes,
8446  cl_mem_migration_flags flags = 0,
8447  const vector<Event>* events = NULL,
8448  Event* event = NULL) const
8449  {
8450  cl_event tmp;
8451  cl_int err = detail::errHandler(::clEnqueueSVMMigrateMem(
8452  object_,
8453  svmRawPointers.size(), static_cast<void**>(svmRawPointers.data()),
8454  sizes.data(), // array of sizes not passed
8455  flags,
8456  (events != NULL) ? (cl_uint)events->size() : 0,
8457  (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8458  (event != NULL) ? &tmp : NULL),
8459  __ENQUEUE_MIGRATE_SVM_ERR);
8460 
8461  if (event != NULL && err == CL_SUCCESS)
8462  *event = tmp;
8463 
8464  return err;
8465  }
8466 
8471  template<typename T>
8473  const cl::vector<T*> &svmRawPointers,
8474  cl_mem_migration_flags flags = 0,
8475  const vector<Event>* events = NULL,
8476  Event* event = NULL) const
8477  {
8478  return enqueueMigrateSVM(svmRawPointers, cl::vector<size_type>(svmRawPointers.size()), flags, events, event);
8479  }
8480 
8481 
8487  template<typename T, class D>
8489  const cl::vector<cl::pointer<T, D>> &svmPointers,
8490  const cl::vector<size_type> &sizes,
8491  cl_mem_migration_flags flags = 0,
8492  const vector<Event>* events = NULL,
8493  Event* event = NULL) const
8494  {
8495  cl::vector<void*> svmRawPointers;
8496  svmRawPointers.reserve(svmPointers.size());
8497  for (auto p : svmPointers) {
8498  svmRawPointers.push_back(static_cast<void*>(p.get()));
8499  }
8500 
8501  return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
8502  }
8503 
8504 
8509  template<typename T, class D>
8511  const cl::vector<cl::pointer<T, D>> &svmPointers,
8512  cl_mem_migration_flags flags = 0,
8513  const vector<Event>* events = NULL,
8514  Event* event = NULL) const
8515  {
8516  return enqueueMigrateSVM(svmPointers, cl::vector<size_type>(svmPointers.size()), flags, events, event);
8517  }
8518 
8524  template<typename T, class Alloc>
8526  const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8527  const cl::vector<size_type> &sizes,
8528  cl_mem_migration_flags flags = 0,
8529  const vector<Event>* events = NULL,
8530  Event* event = NULL) const
8531  {
8532  cl::vector<void*> svmRawPointers;
8533  svmRawPointers.reserve(svmContainers.size());
8534  for (auto p : svmContainers) {
8535  svmRawPointers.push_back(static_cast<void*>(p.data()));
8536  }
8537 
8538  return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
8539  }
8540 
8545  template<typename T, class Alloc>
8547  const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8548  cl_mem_migration_flags flags = 0,
8549  const vector<Event>* events = NULL,
8550  Event* event = NULL) const
8551  {
8552  return enqueueMigrateSVM(svmContainers, cl::vector<size_type>(svmContainers.size()), flags, events, event);
8553  }
8554 
8555 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8556 
8557  cl_int enqueueNDRangeKernel(
8558  const Kernel& kernel,
8559  const NDRange& offset,
8560  const NDRange& global,
8561  const NDRange& local = NullRange,
8562  const vector<Event>* events = NULL,
8563  Event* event = NULL) const
8564  {
8565  cl_event tmp;
8566  cl_int err = detail::errHandler(
8567  ::clEnqueueNDRangeKernel(
8568  object_, kernel(), (cl_uint) global.dimensions(),
8569  offset.dimensions() != 0 ? (const size_type*) offset : NULL,
8570  (const size_type*) global,
8571  local.dimensions() != 0 ? (const size_type*) local : NULL,
8572  (events != NULL) ? (cl_uint) events->size() : 0,
8573  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8574  (event != NULL) ? &tmp : NULL),
8575  __ENQUEUE_NDRANGE_KERNEL_ERR);
8576 
8577  if (event != NULL && err == CL_SUCCESS)
8578  *event = tmp;
8579 
8580  return err;
8581  }
8582 
8583 #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8584  CL_API_PREFIX__VERSION_1_2_DEPRECATED cl_int enqueueTask(
8585  const Kernel& kernel,
8586  const vector<Event>* events = NULL,
8587  Event* event = NULL) const CL_API_SUFFIX__VERSION_1_2_DEPRECATED
8588  {
8589  cl_event tmp;
8590  cl_int err = detail::errHandler(
8591  ::clEnqueueTask(
8592  object_, kernel(),
8593  (events != NULL) ? (cl_uint) events->size() : 0,
8594  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8595  (event != NULL) ? &tmp : NULL),
8596  __ENQUEUE_TASK_ERR);
8597 
8598  if (event != NULL && err == CL_SUCCESS)
8599  *event = tmp;
8600 
8601  return err;
8602  }
8603 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8604 
8605  cl_int enqueueNativeKernel(
8606  void (CL_CALLBACK *userFptr)(void *),
8607  std::pair<void*, size_type> args,
8608  const vector<Memory>* mem_objects = NULL,
8609  const vector<const void*>* mem_locs = NULL,
8610  const vector<Event>* events = NULL,
8611  Event* event = NULL) const
8612  {
8613  size_type elements = 0;
8614  if (mem_objects != NULL) {
8615  elements = mem_objects->size();
8616  }
8617  vector<cl_mem> mems(elements);
8618  for (unsigned int i = 0; i < elements; i++) {
8619  mems[i] = ((*mem_objects)[i])();
8620  }
8621 
8622  cl_event tmp;
8623  cl_int err = detail::errHandler(
8624  ::clEnqueueNativeKernel(
8625  object_, userFptr, args.first, args.second,
8626  (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8627  mems.data(),
8628  (mem_locs != NULL && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : NULL,
8629  (events != NULL) ? (cl_uint) events->size() : 0,
8630  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8631  (event != NULL) ? &tmp : NULL),
8632  __ENQUEUE_NATIVE_KERNEL);
8633 
8634  if (event != NULL && err == CL_SUCCESS)
8635  *event = tmp;
8636 
8637  return err;
8638  }
8639 
8643 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8644  CL_API_PREFIX__VERSION_1_1_DEPRECATED
8645  cl_int enqueueMarker(Event* event = NULL) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
8646  {
8647  cl_event tmp;
8648  cl_int err = detail::errHandler(
8649  ::clEnqueueMarker(
8650  object_,
8651  (event != NULL) ? &tmp : NULL),
8652  __ENQUEUE_MARKER_ERR);
8653 
8654  if (event != NULL && err == CL_SUCCESS)
8655  *event = tmp;
8656 
8657  return err;
8658  }
8659 
8660  CL_API_PREFIX__VERSION_1_1_DEPRECATED
8661  cl_int enqueueWaitForEvents(const vector<Event>& events) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
8662  {
8663  return detail::errHandler(
8664  ::clEnqueueWaitForEvents(
8665  object_,
8666  (cl_uint) events.size(),
8667  events.size() > 0 ? (const cl_event*) &events.front() : NULL),
8668  __ENQUEUE_WAIT_FOR_EVENTS_ERR);
8669  }
8670 #endif // defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8671 
8672  cl_int enqueueAcquireGLObjects(
8673  const vector<Memory>* mem_objects = NULL,
8674  const vector<Event>* events = NULL,
8675  Event* event = NULL) const
8676  {
8677  cl_event tmp;
8678  cl_int err = detail::errHandler(
8679  ::clEnqueueAcquireGLObjects(
8680  object_,
8681  (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8682  (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8683  (events != NULL) ? (cl_uint) events->size() : 0,
8684  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8685  (event != NULL) ? &tmp : NULL),
8686  __ENQUEUE_ACQUIRE_GL_ERR);
8687 
8688  if (event != NULL && err == CL_SUCCESS)
8689  *event = tmp;
8690 
8691  return err;
8692  }
8693 
8694  cl_int enqueueReleaseGLObjects(
8695  const vector<Memory>* mem_objects = NULL,
8696  const vector<Event>* events = NULL,
8697  Event* event = NULL) const
8698  {
8699  cl_event tmp;
8700  cl_int err = detail::errHandler(
8701  ::clEnqueueReleaseGLObjects(
8702  object_,
8703  (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8704  (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8705  (events != NULL) ? (cl_uint) events->size() : 0,
8706  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8707  (event != NULL) ? &tmp : NULL),
8708  __ENQUEUE_RELEASE_GL_ERR);
8709 
8710  if (event != NULL && err == CL_SUCCESS)
8711  *event = tmp;
8712 
8713  return err;
8714  }
8715 
8716 #if defined (CL_HPP_USE_DX_INTEROP)
8717 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
8718  cl_command_queue command_queue, cl_uint num_objects,
8719  const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8720  const cl_event* event_wait_list, cl_event* event);
8721 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
8722  cl_command_queue command_queue, cl_uint num_objects,
8723  const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8724  const cl_event* event_wait_list, cl_event* event);
8725 
8726  cl_int enqueueAcquireD3D10Objects(
8727  const vector<Memory>* mem_objects = NULL,
8728  const vector<Event>* events = NULL,
8729  Event* event = NULL) const
8730  {
8731  static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
8732 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8733  cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8734  cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8735  cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8736  CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireD3D10ObjectsKHR);
8737 #endif
8738 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
8739  CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueAcquireD3D10ObjectsKHR);
8740 #endif
8741 
8742  cl_event tmp;
8743  cl_int err = detail::errHandler(
8744  pfn_clEnqueueAcquireD3D10ObjectsKHR(
8745  object_,
8746  (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8747  (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8748  (events != NULL) ? (cl_uint) events->size() : 0,
8749  (events != NULL) ? (cl_event*) &events->front() : NULL,
8750  (event != NULL) ? &tmp : NULL),
8751  __ENQUEUE_ACQUIRE_GL_ERR);
8752 
8753  if (event != NULL && err == CL_SUCCESS)
8754  *event = tmp;
8755 
8756  return err;
8757  }
8758 
8759  cl_int enqueueReleaseD3D10Objects(
8760  const vector<Memory>* mem_objects = NULL,
8761  const vector<Event>* events = NULL,
8762  Event* event = NULL) const
8763  {
8764  static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL;
8765 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8766  cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8767  cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8768  cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8769  CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseD3D10ObjectsKHR);
8770 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8771 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
8772  CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueReleaseD3D10ObjectsKHR);
8773 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
8774 
8775  cl_event tmp;
8776  cl_int err = detail::errHandler(
8777  pfn_clEnqueueReleaseD3D10ObjectsKHR(
8778  object_,
8779  (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8780  (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8781  (events != NULL) ? (cl_uint) events->size() : 0,
8782  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8783  (event != NULL) ? &tmp : NULL),
8784  __ENQUEUE_RELEASE_GL_ERR);
8785 
8786  if (event != NULL && err == CL_SUCCESS)
8787  *event = tmp;
8788 
8789  return err;
8790  }
8791 #endif
8792 
8796 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8797  CL_API_PREFIX__VERSION_1_1_DEPRECATED
8798  cl_int enqueueBarrier() const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
8799  {
8800  return detail::errHandler(
8801  ::clEnqueueBarrier(object_),
8802  __ENQUEUE_BARRIER_ERR);
8803  }
8804 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
8805 
8806  cl_int flush() const
8807  {
8808  return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
8809  }
8810 
8811  cl_int finish() const
8812  {
8813  return detail::errHandler(::clFinish(object_), __FINISH_ERR);
8814  }
8815 }; // CommandQueue
8816 
8817 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::default_initialized_;
8818 CL_HPP_DEFINE_STATIC_MEMBER_ CommandQueue CommandQueue::default_;
8819 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int CommandQueue::default_error_ = CL_SUCCESS;
8820 
8821 
8822 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8823 enum class DeviceQueueProperties : cl_command_queue_properties
8824 {
8825  None = 0,
8826  Profiling = CL_QUEUE_PROFILING_ENABLE,
8827 };
8828 
8829 inline DeviceQueueProperties operator|(DeviceQueueProperties lhs, DeviceQueueProperties rhs)
8830 {
8831  return static_cast<DeviceQueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
8832 }
8833 
8837 class DeviceCommandQueue : public detail::Wrapper<cl_command_queue>
8838 {
8839 public:
8840 
8845 
8849  DeviceCommandQueue(DeviceQueueProperties properties, cl_int* err = NULL)
8850  {
8851  cl_int error;
8854 
8855  cl_command_queue_properties mergedProperties =
8856  CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8857 
8858  cl_queue_properties queue_properties[] = {
8859  CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8860  object_ = ::clCreateCommandQueueWithProperties(
8861  context(), device(), queue_properties, &error);
8862 
8863  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8864  if (err != NULL) {
8865  *err = error;
8866  }
8867  }
8868 
8873  const Context& context,
8874  const Device& device,
8875  DeviceQueueProperties properties = DeviceQueueProperties::None,
8876  cl_int* err = NULL)
8877  {
8878  cl_int error;
8879 
8880  cl_command_queue_properties mergedProperties =
8881  CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8882  cl_queue_properties queue_properties[] = {
8883  CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8884  object_ = ::clCreateCommandQueueWithProperties(
8885  context(), device(), queue_properties, &error);
8886 
8887  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8888  if (err != NULL) {
8889  *err = error;
8890  }
8891  }
8892 
8897  const Context& context,
8898  const Device& device,
8899  cl_uint queueSize,
8900  DeviceQueueProperties properties = DeviceQueueProperties::None,
8901  cl_int* err = NULL)
8902  {
8903  cl_int error;
8904 
8905  cl_command_queue_properties mergedProperties =
8906  CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8907  cl_queue_properties queue_properties[] = {
8908  CL_QUEUE_PROPERTIES, mergedProperties,
8909  CL_QUEUE_SIZE, queueSize,
8910  0 };
8911  object_ = ::clCreateCommandQueueWithProperties(
8912  context(), device(), queue_properties, &error);
8913 
8914  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8915  if (err != NULL) {
8916  *err = error;
8917  }
8918  }
8919 
8926  explicit DeviceCommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
8927  detail::Wrapper<cl_type>(commandQueue, retainObject) { }
8928 
8929  DeviceCommandQueue& operator = (const cl_command_queue& rhs)
8930  {
8932  return *this;
8933  }
8934 
8938  DeviceCommandQueue(const DeviceCommandQueue& queue) : detail::Wrapper<cl_type>(queue) {}
8939 
8943  DeviceCommandQueue& operator = (const DeviceCommandQueue &queue)
8944  {
8946  return *this;
8947  }
8948 
8952  DeviceCommandQueue(DeviceCommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(queue)) {}
8953 
8958  {
8959  detail::Wrapper<cl_type>::operator=(std::move(queue));
8960  return *this;
8961  }
8962 
8963  template <typename T>
8964  cl_int getInfo(cl_command_queue_info name, T* param) const
8965  {
8966  return detail::errHandler(
8967  detail::getInfo(
8968  &::clGetCommandQueueInfo, object_, name, param),
8969  __GET_COMMAND_QUEUE_INFO_ERR);
8970  }
8971 
8972  template <cl_command_queue_info name> typename
8973  detail::param_traits<detail::cl_command_queue_info, name>::param_type
8974  getInfo(cl_int* err = NULL) const
8975  {
8976  typename detail::param_traits<
8977  detail::cl_command_queue_info, name>::param_type param;
8978  cl_int result = getInfo(name, &param);
8979  if (err != NULL) {
8980  *err = result;
8981  }
8982  return param;
8983  }
8984 
8992  cl_int *err = nullptr)
8993  {
8994  cl_int error;
8997 
8998  cl_command_queue_properties properties =
8999  CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9000  cl_queue_properties queue_properties[] = {
9001  CL_QUEUE_PROPERTIES, properties,
9002  0 };
9003  DeviceCommandQueue deviceQueue(
9004  ::clCreateCommandQueueWithProperties(
9005  context(), device(), queue_properties, &error));
9006 
9007  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9008  if (err != NULL) {
9009  *err = error;
9010  }
9011 
9012  return deviceQueue;
9013  }
9014 
9022  const Context &context, const Device &device, cl_int *err = nullptr)
9023  {
9024  cl_int error;
9025 
9026  cl_command_queue_properties properties =
9027  CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9028  cl_queue_properties queue_properties[] = {
9029  CL_QUEUE_PROPERTIES, properties,
9030  0 };
9031  DeviceCommandQueue deviceQueue(
9032  ::clCreateCommandQueueWithProperties(
9033  context(), device(), queue_properties, &error));
9034 
9035  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9036  if (err != NULL) {
9037  *err = error;
9038  }
9039 
9040  return deviceQueue;
9041  }
9042 
9050  const Context &context, const Device &device, cl_uint queueSize, cl_int *err = nullptr)
9051  {
9052  cl_int error;
9053 
9054  cl_command_queue_properties properties =
9055  CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9056  cl_queue_properties queue_properties[] = {
9057  CL_QUEUE_PROPERTIES, properties,
9058  CL_QUEUE_SIZE, queueSize,
9059  0 };
9060  DeviceCommandQueue deviceQueue(
9061  ::clCreateCommandQueueWithProperties(
9062  context(), device(), queue_properties, &error));
9063 
9064  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9065  if (err != NULL) {
9066  *err = error;
9067  }
9068 
9069  return deviceQueue;
9070  }
9071 
9072 
9073 
9074 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
9081  static DeviceCommandQueue updateDefault(const Context &context, const Device &device, const DeviceCommandQueue &default_queue, cl_int *err = nullptr)
9082  {
9083  cl_int error;
9084  error = clSetDefaultDeviceCommandQueue(context.get(), device.get(), default_queue.get());
9085 
9086  detail::errHandler(error, __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR);
9087  if (err != NULL) {
9088  *err = error;
9089  }
9090  return default_queue;
9091  }
9092 
9096  static DeviceCommandQueue getDefault(const CommandQueue &queue, cl_int * err = NULL)
9097  {
9098  return queue.getInfo<CL_QUEUE_DEVICE_DEFAULT>(err);
9099  }
9100 
9101 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
9102 }; // DeviceCommandQueue
9103 
9104 namespace detail
9105 {
9106  // Specialization for device command queue
9107  template <>
9109  {
9110  static size_type size(const cl::DeviceCommandQueue&) { return sizeof(cl_command_queue); }
9111  static const cl_command_queue* ptr(const cl::DeviceCommandQueue& value) { return &(value()); }
9112  };
9113 } // namespace detail
9114 
9115 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9116 
9117 
9118 template< typename IteratorType >
9120  const Context &context,
9121  IteratorType startIterator,
9122  IteratorType endIterator,
9123  bool readOnly,
9124  bool useHostPtr,
9125  cl_int* err)
9126 {
9127  typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9128  cl_int error;
9129 
9130  cl_mem_flags flags = 0;
9131  if( readOnly ) {
9132  flags |= CL_MEM_READ_ONLY;
9133  }
9134  else {
9135  flags |= CL_MEM_READ_WRITE;
9136  }
9137  if( useHostPtr ) {
9138  flags |= CL_MEM_USE_HOST_PTR;
9139  }
9140 
9141  size_type size = sizeof(DataType)*(endIterator - startIterator);
9142 
9143  if( useHostPtr ) {
9144  object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
9145  } else {
9146  object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9147  }
9148 
9149  detail::errHandler(error, __CREATE_BUFFER_ERR);
9150  if (err != NULL) {
9151  *err = error;
9152  }
9153 
9154  if( !useHostPtr ) {
9155  CommandQueue queue(context, 0, &error);
9156  detail::errHandler(error, __CREATE_BUFFER_ERR);
9157  if (err != NULL) {
9158  *err = error;
9159  }
9160 
9161  error = cl::copy(queue, startIterator, endIterator, *this);
9162  detail::errHandler(error, __CREATE_BUFFER_ERR);
9163  if (err != NULL) {
9164  *err = error;
9165  }
9166  }
9167 }
9168 
9169 template< typename IteratorType >
9171  const CommandQueue &queue,
9172  IteratorType startIterator,
9173  IteratorType endIterator,
9174  bool readOnly,
9175  bool useHostPtr,
9176  cl_int* err)
9177 {
9178  typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9179  cl_int error;
9180 
9181  cl_mem_flags flags = 0;
9182  if (readOnly) {
9183  flags |= CL_MEM_READ_ONLY;
9184  }
9185  else {
9186  flags |= CL_MEM_READ_WRITE;
9187  }
9188  if (useHostPtr) {
9189  flags |= CL_MEM_USE_HOST_PTR;
9190  }
9191 
9192  size_type size = sizeof(DataType)*(endIterator - startIterator);
9193 
9194  Context context = queue.getInfo<CL_QUEUE_CONTEXT>();
9195 
9196  if (useHostPtr) {
9197  object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
9198  }
9199  else {
9200  object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9201  }
9202 
9203  detail::errHandler(error, __CREATE_BUFFER_ERR);
9204  if (err != NULL) {
9205  *err = error;
9206  }
9207 
9208  if (!useHostPtr) {
9209  error = cl::copy(queue, startIterator, endIterator, *this);
9210  detail::errHandler(error, __CREATE_BUFFER_ERR);
9211  if (err != NULL) {
9212  *err = error;
9213  }
9214  }
9215 }
9216 
9217 inline cl_int enqueueReadBuffer(
9218  const Buffer& buffer,
9219  cl_bool blocking,
9220  size_type offset,
9221  size_type size,
9222  void* ptr,
9223  const vector<Event>* events = NULL,
9224  Event* event = NULL)
9225 {
9226  cl_int error;
9227  CommandQueue queue = CommandQueue::getDefault(&error);
9228 
9229  if (error != CL_SUCCESS) {
9230  return error;
9231  }
9232 
9233  return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event);
9234 }
9235 
9236 inline cl_int enqueueWriteBuffer(
9237  const Buffer& buffer,
9238  cl_bool blocking,
9239  size_type offset,
9240  size_type size,
9241  const void* ptr,
9242  const vector<Event>* events = NULL,
9243  Event* event = NULL)
9244 {
9245  cl_int error;
9246  CommandQueue queue = CommandQueue::getDefault(&error);
9247 
9248  if (error != CL_SUCCESS) {
9249  return error;
9250  }
9251 
9252  return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event);
9253 }
9254 
9255 inline void* enqueueMapBuffer(
9256  const Buffer& buffer,
9257  cl_bool blocking,
9258  cl_map_flags flags,
9259  size_type offset,
9260  size_type size,
9261  const vector<Event>* events = NULL,
9262  Event* event = NULL,
9263  cl_int* err = NULL)
9264 {
9265  cl_int error;
9266  CommandQueue queue = CommandQueue::getDefault(&error);
9267  detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9268  if (err != NULL) {
9269  *err = error;
9270  }
9271 
9272  void * result = ::clEnqueueMapBuffer(
9273  queue(), buffer(), blocking, flags, offset, size,
9274  (events != NULL) ? (cl_uint) events->size() : 0,
9275  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
9276  (cl_event*) event,
9277  &error);
9278 
9279  detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9280  if (err != NULL) {
9281  *err = error;
9282  }
9283  return result;
9284 }
9285 
9286 
9287 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9293 template<typename T>
9294 inline cl_int enqueueMapSVM(
9295  T* ptr,
9296  cl_bool blocking,
9297  cl_map_flags flags,
9298  size_type size,
9299  const vector<Event>* events,
9300  Event* event)
9301 {
9302  cl_int error;
9303  CommandQueue queue = CommandQueue::getDefault(&error);
9304  if (error != CL_SUCCESS) {
9305  return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9306  }
9307 
9308  return queue.enqueueMapSVM(
9309  ptr, blocking, flags, size, events, event);
9310 }
9311 
9317 template<typename T, class D>
9318 inline cl_int enqueueMapSVM(
9319  cl::pointer<T, D> ptr,
9320  cl_bool blocking,
9321  cl_map_flags flags,
9322  size_type size,
9323  const vector<Event>* events = NULL,
9324  Event* event = NULL)
9325 {
9326  cl_int error;
9327  CommandQueue queue = CommandQueue::getDefault(&error);
9328  if (error != CL_SUCCESS) {
9329  return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9330  }
9331 
9332  return queue.enqueueMapSVM(
9333  ptr, blocking, flags, size, events, event);
9334 }
9335 
9341 template<typename T, class Alloc>
9342 inline cl_int enqueueMapSVM(
9343  cl::vector<T, Alloc> container,
9344  cl_bool blocking,
9345  cl_map_flags flags,
9346  const vector<Event>* events = NULL,
9347  Event* event = NULL)
9348 {
9349  cl_int error;
9350  CommandQueue queue = CommandQueue::getDefault(&error);
9351  if (error != CL_SUCCESS) {
9352  return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9353  }
9354 
9355  return queue.enqueueMapSVM(
9356  container, blocking, flags, events, event);
9357 }
9358 
9359 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9360 
9361 inline cl_int enqueueUnmapMemObject(
9362  const Memory& memory,
9363  void* mapped_ptr,
9364  const vector<Event>* events = NULL,
9365  Event* event = NULL)
9366 {
9367  cl_int error;
9368  CommandQueue queue = CommandQueue::getDefault(&error);
9369  detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9370  if (error != CL_SUCCESS) {
9371  return error;
9372  }
9373 
9374  cl_event tmp;
9375  cl_int err = detail::errHandler(
9376  ::clEnqueueUnmapMemObject(
9377  queue(), memory(), mapped_ptr,
9378  (events != NULL) ? (cl_uint)events->size() : 0,
9379  (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
9380  (event != NULL) ? &tmp : NULL),
9381  __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9382 
9383  if (event != NULL && err == CL_SUCCESS)
9384  *event = tmp;
9385 
9386  return err;
9387 }
9388 
9389 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9395 template<typename T>
9396 inline cl_int enqueueUnmapSVM(
9397  T* ptr,
9398  const vector<Event>* events = NULL,
9399  Event* event = NULL)
9400 {
9401  cl_int error;
9402  CommandQueue queue = CommandQueue::getDefault(&error);
9403  if (error != CL_SUCCESS) {
9404  return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9405  }
9406 
9407  return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
9408  __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9409 
9410 }
9411 
9417 template<typename T, class D>
9418 inline cl_int enqueueUnmapSVM(
9419  cl::pointer<T, D> &ptr,
9420  const vector<Event>* events = NULL,
9421  Event* event = NULL)
9422 {
9423  cl_int error;
9424  CommandQueue queue = CommandQueue::getDefault(&error);
9425  if (error != CL_SUCCESS) {
9426  return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9427  }
9428 
9429  return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
9430  __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9431 }
9432 
9438 template<typename T, class Alloc>
9439 inline cl_int enqueueUnmapSVM(
9440  cl::vector<T, Alloc> &container,
9441  const vector<Event>* events = NULL,
9442  Event* event = NULL)
9443 {
9444  cl_int error;
9445  CommandQueue queue = CommandQueue::getDefault(&error);
9446  if (error != CL_SUCCESS) {
9447  return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9448  }
9449 
9450  return detail::errHandler(queue.enqueueUnmapSVM(container, events, event),
9451  __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9452 }
9453 
9454 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9455 
9456 inline cl_int enqueueCopyBuffer(
9457  const Buffer& src,
9458  const Buffer& dst,
9459  size_type src_offset,
9460  size_type dst_offset,
9461  size_type size,
9462  const vector<Event>* events = NULL,
9463  Event* event = NULL)
9464 {
9465  cl_int error;
9466  CommandQueue queue = CommandQueue::getDefault(&error);
9467 
9468  if (error != CL_SUCCESS) {
9469  return error;
9470  }
9471 
9472  return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event);
9473 }
9474 
9480 template< typename IteratorType >
9481 inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
9482 {
9483  cl_int error;
9484  CommandQueue queue = CommandQueue::getDefault(&error);
9485  if (error != CL_SUCCESS)
9486  return error;
9487 
9488  return cl::copy(queue, startIterator, endIterator, buffer);
9489 }
9490 
9496 template< typename IteratorType >
9497 inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
9498 {
9499  cl_int error;
9500  CommandQueue queue = CommandQueue::getDefault(&error);
9501  if (error != CL_SUCCESS)
9502  return error;
9503 
9504  return cl::copy(queue, buffer, startIterator, endIterator);
9505 }
9506 
9512 template< typename IteratorType >
9513 inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
9514 {
9515  typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9516  cl_int error;
9517 
9518  size_type length = endIterator-startIterator;
9519  size_type byteLength = length*sizeof(DataType);
9520 
9521  DataType *pointer =
9522  static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error));
9523  // if exceptions enabled, enqueueMapBuffer will throw
9524  if( error != CL_SUCCESS ) {
9525  return error;
9526  }
9527 #if defined(_MSC_VER)
9528  std::copy(
9529  startIterator,
9530  endIterator,
9531  stdext::checked_array_iterator<DataType*>(
9532  pointer, length));
9533 #else
9534  std::copy(startIterator, endIterator, pointer);
9535 #endif
9536  Event endEvent;
9537  error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9538  // if exceptions enabled, enqueueUnmapMemObject will throw
9539  if( error != CL_SUCCESS ) {
9540  return error;
9541  }
9542  endEvent.wait();
9543  return CL_SUCCESS;
9544 }
9545 
9551 template< typename IteratorType >
9552 inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
9553 {
9554  typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9555  cl_int error;
9556 
9557  size_type length = endIterator-startIterator;
9558  size_type byteLength = length*sizeof(DataType);
9559 
9560  DataType *pointer =
9561  static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error));
9562  // if exceptions enabled, enqueueMapBuffer will throw
9563  if( error != CL_SUCCESS ) {
9564  return error;
9565  }
9566  std::copy(pointer, pointer + length, startIterator);
9567  Event endEvent;
9568  error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9569  // if exceptions enabled, enqueueUnmapMemObject will throw
9570  if( error != CL_SUCCESS ) {
9571  return error;
9572  }
9573  endEvent.wait();
9574  return CL_SUCCESS;
9575 }
9576 
9577 
9578 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9582 template<typename T, class Alloc>
9583 inline cl_int mapSVM(cl::vector<T, Alloc> &container)
9584 {
9585  return enqueueMapSVM(container, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE);
9586 }
9587 
9591 template<typename T, class Alloc>
9592 inline cl_int unmapSVM(cl::vector<T, Alloc> &container)
9593 {
9594  return enqueueUnmapSVM(container);
9595 }
9596 
9597 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9598 
9599 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
9600 inline cl_int enqueueReadBufferRect(
9601  const Buffer& buffer,
9602  cl_bool blocking,
9603  const array<size_type, 3>& buffer_offset,
9604  const array<size_type, 3>& host_offset,
9605  const array<size_type, 3>& region,
9606  size_type buffer_row_pitch,
9607  size_type buffer_slice_pitch,
9608  size_type host_row_pitch,
9609  size_type host_slice_pitch,
9610  void *ptr,
9611  const vector<Event>* events = NULL,
9612  Event* event = NULL)
9613 {
9614  cl_int error;
9615  CommandQueue queue = CommandQueue::getDefault(&error);
9616 
9617  if (error != CL_SUCCESS) {
9618  return error;
9619  }
9620 
9621  return queue.enqueueReadBufferRect(
9622  buffer,
9623  blocking,
9624  buffer_offset,
9625  host_offset,
9626  region,
9627  buffer_row_pitch,
9628  buffer_slice_pitch,
9629  host_row_pitch,
9630  host_slice_pitch,
9631  ptr,
9632  events,
9633  event);
9634 }
9635 
9636 inline cl_int enqueueWriteBufferRect(
9637  const Buffer& buffer,
9638  cl_bool blocking,
9639  const array<size_type, 3>& buffer_offset,
9640  const array<size_type, 3>& host_offset,
9641  const array<size_type, 3>& region,
9642  size_type buffer_row_pitch,
9643  size_type buffer_slice_pitch,
9644  size_type host_row_pitch,
9645  size_type host_slice_pitch,
9646  const void *ptr,
9647  const vector<Event>* events = NULL,
9648  Event* event = NULL)
9649 {
9650  cl_int error;
9651  CommandQueue queue = CommandQueue::getDefault(&error);
9652 
9653  if (error != CL_SUCCESS) {
9654  return error;
9655  }
9656 
9657  return queue.enqueueWriteBufferRect(
9658  buffer,
9659  blocking,
9660  buffer_offset,
9661  host_offset,
9662  region,
9663  buffer_row_pitch,
9664  buffer_slice_pitch,
9665  host_row_pitch,
9666  host_slice_pitch,
9667  ptr,
9668  events,
9669  event);
9670 }
9671 
9672 inline cl_int enqueueCopyBufferRect(
9673  const Buffer& src,
9674  const Buffer& dst,
9675  const array<size_type, 3>& src_origin,
9676  const array<size_type, 3>& dst_origin,
9677  const array<size_type, 3>& region,
9678  size_type src_row_pitch,
9679  size_type src_slice_pitch,
9680  size_type dst_row_pitch,
9681  size_type dst_slice_pitch,
9682  const vector<Event>* events = NULL,
9683  Event* event = NULL)
9684 {
9685  cl_int error;
9686  CommandQueue queue = CommandQueue::getDefault(&error);
9687 
9688  if (error != CL_SUCCESS) {
9689  return error;
9690  }
9691 
9692  return queue.enqueueCopyBufferRect(
9693  src,
9694  dst,
9695  src_origin,
9696  dst_origin,
9697  region,
9698  src_row_pitch,
9699  src_slice_pitch,
9700  dst_row_pitch,
9701  dst_slice_pitch,
9702  events,
9703  event);
9704 }
9705 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
9706 
9707 inline cl_int enqueueReadImage(
9708  const Image& image,
9709  cl_bool blocking,
9710  const array<size_type, 3>& origin,
9711  const array<size_type, 3>& region,
9712  size_type row_pitch,
9713  size_type slice_pitch,
9714  void* ptr,
9715  const vector<Event>* events = NULL,
9716  Event* event = NULL)
9717 {
9718  cl_int error;
9719  CommandQueue queue = CommandQueue::getDefault(&error);
9720 
9721  if (error != CL_SUCCESS) {
9722  return error;
9723  }
9724 
9725  return queue.enqueueReadImage(
9726  image,
9727  blocking,
9728  origin,
9729  region,
9730  row_pitch,
9731  slice_pitch,
9732  ptr,
9733  events,
9734  event);
9735 }
9736 
9737 inline cl_int enqueueWriteImage(
9738  const Image& image,
9739  cl_bool blocking,
9740  const array<size_type, 3>& origin,
9741  const array<size_type, 3>& region,
9742  size_type row_pitch,
9743  size_type slice_pitch,
9744  const void* ptr,
9745  const vector<Event>* events = NULL,
9746  Event* event = NULL)
9747 {
9748  cl_int error;
9749  CommandQueue queue = CommandQueue::getDefault(&error);
9750 
9751  if (error != CL_SUCCESS) {
9752  return error;
9753  }
9754 
9755  return queue.enqueueWriteImage(
9756  image,
9757  blocking,
9758  origin,
9759  region,
9760  row_pitch,
9761  slice_pitch,
9762  ptr,
9763  events,
9764  event);
9765 }
9766 
9767 inline cl_int enqueueCopyImage(
9768  const Image& src,
9769  const Image& dst,
9770  const array<size_type, 3>& src_origin,
9771  const array<size_type, 3>& dst_origin,
9772  const array<size_type, 3>& region,
9773  const vector<Event>* events = NULL,
9774  Event* event = NULL)
9775 {
9776  cl_int error;
9777  CommandQueue queue = CommandQueue::getDefault(&error);
9778 
9779  if (error != CL_SUCCESS) {
9780  return error;
9781  }
9782 
9783  return queue.enqueueCopyImage(
9784  src,
9785  dst,
9786  src_origin,
9787  dst_origin,
9788  region,
9789  events,
9790  event);
9791 }
9792 
9793 inline cl_int enqueueCopyImageToBuffer(
9794  const Image& src,
9795  const Buffer& dst,
9796  const array<size_type, 3>& src_origin,
9797  const array<size_type, 3>& region,
9798  size_type dst_offset,
9799  const vector<Event>* events = NULL,
9800  Event* event = NULL)
9801 {
9802  cl_int error;
9803  CommandQueue queue = CommandQueue::getDefault(&error);
9804 
9805  if (error != CL_SUCCESS) {
9806  return error;
9807  }
9808 
9809  return queue.enqueueCopyImageToBuffer(
9810  src,
9811  dst,
9812  src_origin,
9813  region,
9814  dst_offset,
9815  events,
9816  event);
9817 }
9818 
9819 inline cl_int enqueueCopyBufferToImage(
9820  const Buffer& src,
9821  const Image& dst,
9822  size_type src_offset,
9823  const array<size_type, 3>& dst_origin,
9824  const array<size_type, 3>& region,
9825  const vector<Event>* events = NULL,
9826  Event* event = NULL)
9827 {
9828  cl_int error;
9829  CommandQueue queue = CommandQueue::getDefault(&error);
9830 
9831  if (error != CL_SUCCESS) {
9832  return error;
9833  }
9834 
9835  return queue.enqueueCopyBufferToImage(
9836  src,
9837  dst,
9838  src_offset,
9839  dst_origin,
9840  region,
9841  events,
9842  event);
9843 }
9844 
9845 
9846 inline cl_int flush(void)
9847 {
9848  cl_int error;
9849  CommandQueue queue = CommandQueue::getDefault(&error);
9850 
9851  if (error != CL_SUCCESS) {
9852  return error;
9853  }
9854 
9855  return queue.flush();
9856 }
9857 
9858 inline cl_int finish(void)
9859 {
9860  cl_int error;
9861  CommandQueue queue = CommandQueue::getDefault(&error);
9862 
9863  if (error != CL_SUCCESS) {
9864  return error;
9865  }
9866 
9867 
9868  return queue.finish();
9869 }
9870 
9872 {
9873 private:
9874  CommandQueue queue_;
9875  const NDRange offset_;
9876  const NDRange global_;
9877  const NDRange local_;
9878  vector<Event> events_;
9879 
9880  template<typename... Ts>
9881  friend class KernelFunctor;
9882 
9883 public:
9884  EnqueueArgs(NDRange global) :
9885  queue_(CommandQueue::getDefault()),
9886  offset_(NullRange),
9887  global_(global),
9888  local_(NullRange)
9889  {
9890 
9891  }
9892 
9893  EnqueueArgs(NDRange global, NDRange local) :
9894  queue_(CommandQueue::getDefault()),
9895  offset_(NullRange),
9896  global_(global),
9897  local_(local)
9898  {
9899 
9900  }
9901 
9902  EnqueueArgs(NDRange offset, NDRange global, NDRange local) :
9903  queue_(CommandQueue::getDefault()),
9904  offset_(offset),
9905  global_(global),
9906  local_(local)
9907  {
9908 
9909  }
9910 
9911  EnqueueArgs(Event e, NDRange global) :
9912  queue_(CommandQueue::getDefault()),
9913  offset_(NullRange),
9914  global_(global),
9915  local_(NullRange)
9916  {
9917  events_.push_back(e);
9918  }
9919 
9920  EnqueueArgs(Event e, NDRange global, NDRange local) :
9921  queue_(CommandQueue::getDefault()),
9922  offset_(NullRange),
9923  global_(global),
9924  local_(local)
9925  {
9926  events_.push_back(e);
9927  }
9928 
9929  EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) :
9930  queue_(CommandQueue::getDefault()),
9931  offset_(offset),
9932  global_(global),
9933  local_(local)
9934  {
9935  events_.push_back(e);
9936  }
9937 
9938  EnqueueArgs(const vector<Event> &events, NDRange global) :
9939  queue_(CommandQueue::getDefault()),
9940  offset_(NullRange),
9941  global_(global),
9942  local_(NullRange),
9943  events_(events)
9944  {
9945 
9946  }
9947 
9948  EnqueueArgs(const vector<Event> &events, NDRange global, NDRange local) :
9949  queue_(CommandQueue::getDefault()),
9950  offset_(NullRange),
9951  global_(global),
9952  local_(local),
9953  events_(events)
9954  {
9955 
9956  }
9957 
9958  EnqueueArgs(const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
9959  queue_(CommandQueue::getDefault()),
9960  offset_(offset),
9961  global_(global),
9962  local_(local),
9963  events_(events)
9964  {
9965 
9966  }
9967 
9968  EnqueueArgs(CommandQueue &queue, NDRange global) :
9969  queue_(queue),
9970  offset_(NullRange),
9971  global_(global),
9972  local_(NullRange)
9973  {
9974 
9975  }
9976 
9977  EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) :
9978  queue_(queue),
9979  offset_(NullRange),
9980  global_(global),
9981  local_(local)
9982  {
9983 
9984  }
9985 
9986  EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) :
9987  queue_(queue),
9988  offset_(offset),
9989  global_(global),
9990  local_(local)
9991  {
9992 
9993  }
9994 
9995  EnqueueArgs(CommandQueue &queue, Event e, NDRange global) :
9996  queue_(queue),
9997  offset_(NullRange),
9998  global_(global),
9999  local_(NullRange)
10000  {
10001  events_.push_back(e);
10002  }
10003 
10004  EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) :
10005  queue_(queue),
10006  offset_(NullRange),
10007  global_(global),
10008  local_(local)
10009  {
10010  events_.push_back(e);
10011  }
10012 
10013  EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) :
10014  queue_(queue),
10015  offset_(offset),
10016  global_(global),
10017  local_(local)
10018  {
10019  events_.push_back(e);
10020  }
10021 
10022  EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global) :
10023  queue_(queue),
10024  offset_(NullRange),
10025  global_(global),
10026  local_(NullRange),
10027  events_(events)
10028  {
10029 
10030  }
10031 
10032  EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global, NDRange local) :
10033  queue_(queue),
10034  offset_(NullRange),
10035  global_(global),
10036  local_(local),
10037  events_(events)
10038  {
10039 
10040  }
10041 
10042  EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
10043  queue_(queue),
10044  offset_(offset),
10045  global_(global),
10046  local_(local),
10047  events_(events)
10048  {
10049 
10050  }
10051 };
10052 
10053 
10054 //----------------------------------------------------------------------------------------------
10055 
10056 
10061 template<typename... Ts>
10063 {
10064 private:
10065  Kernel kernel_;
10066 
10067  template<int index, typename T0, typename... T1s>
10068  void setArgs(T0&& t0, T1s&&... t1s)
10069  {
10070  kernel_.setArg(index, t0);
10071  setArgs<index + 1, T1s...>(std::forward<T1s>(t1s)...);
10072  }
10073 
10074  template<int index, typename T0>
10075  void setArgs(T0&& t0)
10076  {
10077  kernel_.setArg(index, t0);
10078  }
10079 
10080  template<int index>
10081  void setArgs()
10082  {
10083  }
10084 
10085 
10086 public:
10087  KernelFunctor(Kernel kernel) : kernel_(kernel)
10088  {}
10089 
10090  KernelFunctor(
10091  const Program& program,
10092  const string name,
10093  cl_int * err = NULL) :
10094  kernel_(program, name.c_str(), err)
10095  {}
10096 
10099 
10106  const EnqueueArgs& args,
10107  Ts... ts)
10108  {
10109  Event event;
10110  setArgs<0>(std::forward<Ts>(ts)...);
10111 
10112  args.queue_.enqueueNDRangeKernel(
10113  kernel_,
10114  args.offset_,
10115  args.global_,
10116  args.local_,
10117  &args.events_,
10118  &event);
10119 
10120  return event;
10121  }
10122 
10130  const EnqueueArgs& args,
10131  Ts... ts,
10132  cl_int &error)
10133  {
10134  Event event;
10135  setArgs<0>(std::forward<Ts>(ts)...);
10136 
10137  error = args.queue_.enqueueNDRangeKernel(
10138  kernel_,
10139  args.offset_,
10140  args.global_,
10141  args.local_,
10142  &args.events_,
10143  &event);
10144 
10145  return event;
10146  }
10147 
10148 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10149  cl_int setSVMPointers(const vector<void*> &pointerList)
10150  {
10151  return kernel_.setSVMPointers(pointerList);
10152  }
10153 
10154  template<typename T0, typename... T1s>
10155  cl_int setSVMPointers(const T0 &t0, T1s &... ts)
10156  {
10157  return kernel_.setSVMPointers(t0, ts...);
10158  }
10159 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10160 
10161  Kernel getKernel()
10162  {
10163  return kernel_;
10164  }
10165 };
10166 
10167 namespace compatibility {
10172  template<typename... Ts>
10174  {
10175  typedef KernelFunctor<Ts...> FunctorType;
10176 
10177  FunctorType functor_;
10178 
10179  make_kernel(
10180  const Program& program,
10181  const string name,
10182  cl_int * err = NULL) :
10183  functor_(FunctorType(program, name, err))
10184  {}
10185 
10186  make_kernel(
10187  const Kernel kernel) :
10188  functor_(FunctorType(kernel))
10189  {}
10190 
10193 
10195  typedef Event type_(
10196  const EnqueueArgs&,
10197  Ts...);
10198 
10199  Event operator()(
10200  const EnqueueArgs& enqueueArgs,
10201  Ts... args)
10202  {
10203  return functor_(
10204  enqueueArgs, args...);
10205  }
10206  };
10207 } // namespace compatibility
10208 
10209 
10210 //----------------------------------------------------------------------------------------------------------------------
10211 
10212 #undef CL_HPP_ERR_STR_
10213 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
10214 #undef __GET_DEVICE_INFO_ERR
10215 #undef __GET_PLATFORM_INFO_ERR
10216 #undef __GET_DEVICE_IDS_ERR
10217 #undef __GET_PLATFORM_IDS_ERR
10218 #undef __GET_CONTEXT_INFO_ERR
10219 #undef __GET_EVENT_INFO_ERR
10220 #undef __GET_EVENT_PROFILE_INFO_ERR
10221 #undef __GET_MEM_OBJECT_INFO_ERR
10222 #undef __GET_IMAGE_INFO_ERR
10223 #undef __GET_SAMPLER_INFO_ERR
10224 #undef __GET_KERNEL_INFO_ERR
10225 #undef __GET_KERNEL_ARG_INFO_ERR
10226 #undef __GET_KERNEL_SUB_GROUP_INFO_ERR
10227 #undef __GET_KERNEL_WORK_GROUP_INFO_ERR
10228 #undef __GET_PROGRAM_INFO_ERR
10229 #undef __GET_PROGRAM_BUILD_INFO_ERR
10230 #undef __GET_COMMAND_QUEUE_INFO_ERR
10231 #undef __CREATE_CONTEXT_ERR
10232 #undef __CREATE_CONTEXT_FROM_TYPE_ERR
10233 #undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
10234 #undef __CREATE_BUFFER_ERR
10235 #undef __COPY_ERR
10236 #undef __CREATE_SUBBUFFER_ERR
10237 #undef __CREATE_GL_BUFFER_ERR
10238 #undef __CREATE_GL_RENDER_BUFFER_ERR
10239 #undef __GET_GL_OBJECT_INFO_ERR
10240 #undef __CREATE_IMAGE_ERR
10241 #undef __CREATE_GL_TEXTURE_ERR
10242 #undef __IMAGE_DIMENSION_ERR
10243 #undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
10244 #undef __CREATE_USER_EVENT_ERR
10245 #undef __SET_USER_EVENT_STATUS_ERR
10246 #undef __SET_EVENT_CALLBACK_ERR
10247 #undef __WAIT_FOR_EVENTS_ERR
10248 #undef __CREATE_KERNEL_ERR
10249 #undef __SET_KERNEL_ARGS_ERR
10250 #undef __CREATE_PROGRAM_WITH_SOURCE_ERR
10251 #undef __CREATE_PROGRAM_WITH_IL_ERR
10252 #undef __CREATE_PROGRAM_WITH_BINARY_ERR
10253 #undef __CREATE_PROGRAM_WITH_IL_ERR
10254 #undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR
10255 #undef __BUILD_PROGRAM_ERR
10256 #undef __COMPILE_PROGRAM_ERR
10257 #undef __LINK_PROGRAM_ERR
10258 #undef __CREATE_KERNELS_IN_PROGRAM_ERR
10259 #undef __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR
10260 #undef __CREATE_SAMPLER_WITH_PROPERTIES_ERR
10261 #undef __SET_COMMAND_QUEUE_PROPERTY_ERR
10262 #undef __ENQUEUE_READ_BUFFER_ERR
10263 #undef __ENQUEUE_READ_BUFFER_RECT_ERR
10264 #undef __ENQUEUE_WRITE_BUFFER_ERR
10265 #undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
10266 #undef __ENQEUE_COPY_BUFFER_ERR
10267 #undef __ENQEUE_COPY_BUFFER_RECT_ERR
10268 #undef __ENQUEUE_FILL_BUFFER_ERR
10269 #undef __ENQUEUE_READ_IMAGE_ERR
10270 #undef __ENQUEUE_WRITE_IMAGE_ERR
10271 #undef __ENQUEUE_COPY_IMAGE_ERR
10272 #undef __ENQUEUE_FILL_IMAGE_ERR
10273 #undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
10274 #undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
10275 #undef __ENQUEUE_MAP_BUFFER_ERR
10276 #undef __ENQUEUE_MAP_IMAGE_ERR
10277 #undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
10278 #undef __ENQUEUE_NDRANGE_KERNEL_ERR
10279 #undef __ENQUEUE_NATIVE_KERNEL
10280 #undef __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR
10281 #undef __ENQUEUE_MIGRATE_SVM_ERR
10282 #undef __ENQUEUE_ACQUIRE_GL_ERR
10283 #undef __ENQUEUE_RELEASE_GL_ERR
10284 #undef __CREATE_PIPE_ERR
10285 #undef __GET_PIPE_INFO_ERR
10286 #undef __RETAIN_ERR
10287 #undef __RELEASE_ERR
10288 #undef __FLUSH_ERR
10289 #undef __FINISH_ERR
10290 #undef __VECTOR_CAPACITY_ERR
10291 #undef __CREATE_SUB_DEVICES_ERR
10292 #undef __CREATE_SUB_DEVICES_ERR
10293 #undef __ENQUEUE_MARKER_ERR
10294 #undef __ENQUEUE_WAIT_FOR_EVENTS_ERR
10295 #undef __ENQUEUE_BARRIER_ERR
10296 #undef __UNLOAD_COMPILER_ERR
10297 #undef __CREATE_GL_TEXTURE_2D_ERR
10298 #undef __CREATE_GL_TEXTURE_3D_ERR
10299 #undef __CREATE_IMAGE2D_ERR
10300 #undef __CREATE_IMAGE3D_ERR
10301 #undef __CREATE_COMMAND_QUEUE_ERR
10302 #undef __ENQUEUE_TASK_ERR
10303 #undef __CREATE_SAMPLER_ERR
10304 #undef __ENQUEUE_MARKER_WAIT_LIST_ERR
10305 #undef __ENQUEUE_BARRIER_WAIT_LIST_ERR
10306 #undef __CLONE_KERNEL_ERR
10307 #undef __GET_HOST_TIMER_ERR
10308 #undef __GET_DEVICE_AND_HOST_TIMER_ERR
10309 
10310 #endif //CL_HPP_USER_OVERRIDE_ERROR_STRINGS
10311 
10312 // Extensions
10313 #undef CL_HPP_INIT_CL_EXT_FCN_PTR_
10314 #undef CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_
10315 
10316 #if defined(CL_HPP_USE_CL_DEVICE_FISSION)
10317 #undef CL_HPP_PARAM_NAME_DEVICE_FISSION_
10318 #endif // CL_HPP_USE_CL_DEVICE_FISSION
10319 
10320 #undef CL_HPP_NOEXCEPT_
10321 #undef CL_HPP_DEFINE_STATIC_MEMBER_
10322 
10323 } // namespace cl
10324 
10325 #endif // CL_HPP_
Class interface for GL Buffer Memory Objects.
Definition: opencl.hpp:4214
BufferGL(BufferGL &&buf) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4280
BufferGL()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4241
BufferGL(const Context &context, cl_mem_flags flags, cl_GLuint bufobj, cl_int *err=NULL)
Constructs a BufferGL in a specified context, from a given GL buffer.
Definition: opencl.hpp:4221
BufferGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4257
BufferGL(const BufferGL &buf)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4266
cl_int getObjectInfo(cl_gl_object_type *type, cl_GLuint *gl_object_name)
Wrapper for clGetGLObjectInfo().
Definition: opencl.hpp:4292
BufferGL(const cl_mem &buffer, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4250
Class interface for Buffer Memory Objects.
Definition: opencl.hpp:3894
Buffer()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4016
Buffer(const Buffer &buf)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4041
Buffer(Buffer &&buf) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4055
Buffer(const Context &context, cl_mem_flags flags, size_type size, void *host_ptr=NULL, cl_int *err=NULL)
Constructs a Buffer in a specified context.
Definition: opencl.hpp:3904
Buffer(const cl_mem &buffer, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4025
Buffer & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4032
Buffer(IteratorType startIterator, IteratorType endIterator, bool readOnly, bool useHostPtr=false, cl_int *err=NULL)
Construct a Buffer from a host container via iterators. IteratorType must be random access....
Definition: opencl.hpp:3953
Buffer createSubBuffer(cl_mem_flags flags, cl_buffer_create_type buffer_create_type, const void *buffer_create_info, cl_int *err=NULL)
Creates a new buffer object from this.
Definition: opencl.hpp:4071
Buffer(cl_mem_flags flags, size_type size, void *host_ptr=NULL, cl_int *err=NULL)
Constructs a Buffer in the default context.
Definition: opencl.hpp:3929
Class interface for GL Render Buffer Memory Objects.
Definition: opencl.hpp:4311
cl_int getObjectInfo(cl_gl_object_type *type, cl_GLuint *gl_object_name)
Wrapper for clGetGLObjectInfo().
Definition: opencl.hpp:4389
BufferRenderGL(const cl_mem &buffer, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4347
BufferRenderGL(BufferRenderGL &&buf) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4377
BufferRenderGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4354
BufferRenderGL()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4338
BufferRenderGL(const BufferRenderGL &buf)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4363
BufferRenderGL(const Context &context, cl_mem_flags flags, cl_GLuint bufobj, cl_int *err=NULL)
Constructs a BufferRenderGL in a specified context, from a given GL Renderbuffer.
Definition: opencl.hpp:4318
CommandQueue interface for cl_command_queue.
Definition: opencl.hpp:7088
CommandQueue(QueueProperties properties, cl_int *err=NULL)
Constructs a CommandQueue based on passed properties. Will return an CL_INVALID_QUEUE_PROPERTIES erro...
Definition: opencl.hpp:7219
CommandQueue(const cl_command_queue &commandQueue, bool retainObject=false)
Constructor from cl_command_queue - takes ownership.
Definition: opencl.hpp:7546
cl_int enqueueFillBuffer(const Buffer &buffer, PatternType pattern, size_type offset, size_type size, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:7807
CommandQueue(CommandQueue &&queue) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:7572
cl_int enqueueMigrateSVM(const cl::vector< cl::vector< T, Alloc >> &svmContainers, cl_mem_migration_flags flags=0, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8546
cl_int enqueueFillImage(const Image &image, cl_uint4 fillColor, const array< size_type, 3 > &origin, const array< size_type, 3 > &region, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8007
cl_int enqueueMapSVM(cl::vector< T, Alloc > &container, cl_bool blocking, cl_map_flags flags, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8216
cl_int enqueueMigrateMemObjects(const vector< Memory > &memObjects, cl_mem_migration_flags flags, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8402
cl_int enqueueMapSVM(cl::pointer< T, D > &ptr, cl_bool blocking, cl_map_flags flags, size_type size, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8189
cl_int enqueueMigrateSVM(const cl::vector< T * > &svmRawPointers, cl_mem_migration_flags flags=0, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8472
static CommandQueue setDefault(const CommandQueue &default_queue)
Definition: opencl.hpp:7530
cl_int enqueueMarkerWithWaitList(const vector< Event > *events=0, Event *event=0) const
Definition: opencl.hpp:8349
CommandQueue(cl_command_queue_properties properties, cl_int *err=NULL)
Constructs a CommandQueue based on passed properties. Will return an CL_INVALID_QUEUE_PROPERTIES erro...
Definition: opencl.hpp:7153
cl_int enqueueMigrateSVM(const cl::vector< T * > &svmRawPointers, const cl::vector< size_type > &sizes, cl_mem_migration_flags flags=0, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8443
cl_int enqueueUnmapSVM(cl::pointer< T, D > &ptr, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8291
CommandQueue(const Context &context, const Device &device, cl_command_queue_properties properties=0, cl_int *err=NULL)
Constructs a CommandQueue for a passed device and context Will return an CL_INVALID_QUEUE_PROPERTIES ...
Definition: opencl.hpp:7411
cl_int enqueueMigrateSVM(const cl::vector< cl::vector< T, Alloc >> &svmContainers, const cl::vector< size_type > &sizes, cl_mem_migration_flags flags=0, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8525
CommandQueue(const Context &context, const Device &device, QueueProperties properties, cl_int *err=NULL)
Constructs a CommandQueue for a passed device and context Will return an CL_INVALID_QUEUE_PROPERTIES ...
Definition: opencl.hpp:7462
cl_int enqueueMigrateSVM(const cl::vector< cl::pointer< T, D >> &svmPointers, cl_mem_migration_flags flags=0, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8510
CommandQueue(const Context &context, QueueProperties properties, cl_int *err=NULL)
Constructs a CommandQueue for an implementation defined device in the given context Will return an CL...
Definition: opencl.hpp:7349
cl_int enqueueFillImage(const Image &image, cl_float4 fillColor, const array< size_type, 3 > &origin, const array< size_type, 3 > &region, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:7939
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int enqueueMarker(Event *event=NULL) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition: opencl.hpp:8645
cl_int enqueueFillImage(const Image &image, cl_int4 fillColor, const array< size_type, 3 > &origin, const array< size_type, 3 > &region, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:7973
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int enqueueBarrier() const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition: opencl.hpp:8798
cl_int enqueueBarrierWithWaitList(const vector< Event > *events=0, Event *event=0) const
Definition: opencl.hpp:8379
CommandQueue(const Context &context, cl_command_queue_properties properties=0, cl_int *err=NULL)
Constructs a CommandQueue for an implementation defined device in the given context Will return an CL...
Definition: opencl.hpp:7282
CommandQueue(const CommandQueue &queue)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:7558
cl_int enqueueMapSVM(T *ptr, cl_bool blocking, cl_map_flags flags, size_type size, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8161
cl_int enqueueUnmapSVM(cl::vector< T, Alloc > &container, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8316
cl_int enqueueMigrateSVM(const cl::vector< cl::pointer< T, D >> &svmPointers, const cl::vector< size_type > &sizes, cl_mem_migration_flags flags=0, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8488
cl_int enqueueUnmapSVM(T *ptr, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8266
Class interface for cl_context.
Definition: opencl.hpp:2809
Context(const vector< Device > &devices, const cl_context_properties *properties=NULL, void(CL_CALLBACK *notifyFptr)(const char *, const void *, size_type, void *)=NULL, void *data=NULL, cl_int *err=NULL)
Constructs a context including a list of specified devices.
Definition: opencl.hpp:2879
static Context setDefault(const Context &default_context)
Definition: opencl.hpp:3077
Context(const cl_context &context, bool retainObject=false)
Constructor from cl_context - takes ownership.
Definition: opencl.hpp:3092
cl_int getSupportedImageFormats(cl_mem_flags flags, cl_mem_object_type type, vector< ImageFormat > *formats) const
Gets a list of supported image formats.
Definition: opencl.hpp:3133
Context & operator=(const Context &ctx)
Copy assignment to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3035
Context()
Default constructor - initializes to NULL.
Definition: opencl.hpp:3085
cl_int getInfo(cl_context_info name, T *param) const
Wrapper for clGetContextInfo().
Definition: opencl.hpp:3108
Context(cl_device_type type, const cl_context_properties *properties=NULL, void(CL_CALLBACK *notifyFptr)(const char *, const void *, size_type, void *)=NULL, void *data=NULL, cl_int *err=NULL)
Constructs a context including all or a subset of devices of a specified type.
Definition: opencl.hpp:2944
detail::param_traits< detail::cl_context_info, name >::param_type getInfo(cl_int *err=NULL) const
Wrapper for clGetContextInfo() that returns by value.
Definition: opencl.hpp:3118
static Context getDefault(cl_int *err=NULL)
Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT.
Definition: opencl.hpp:3060
Context(const Device &device, const cl_context_properties *properties=NULL, void(CL_CALLBACK *notifyFptr)(const char *, const void *, size_type, void *)=NULL, void *data=NULL, cl_int *err=NULL)
Constructs a context including a specific device.
Definition: opencl.hpp:2914
Context(const Context &ctx)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3030
Context(Context &&ctx) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3044
DeviceCommandQueue interface for device cl_command_queues.
Definition: opencl.hpp:8838
DeviceCommandQueue(const Context &context, const Device &device, DeviceQueueProperties properties=DeviceQueueProperties::None, cl_int *err=NULL)
Definition: opencl.hpp:8872
DeviceCommandQueue(const Context &context, const Device &device, cl_uint queueSize, DeviceQueueProperties properties=DeviceQueueProperties::None, cl_int *err=NULL)
Definition: opencl.hpp:8896
static DeviceCommandQueue makeDefault(const Context &context, const Device &device, cl_int *err=nullptr)
Definition: opencl.hpp:9021
static DeviceCommandQueue updateDefault(const Context &context, const Device &device, const DeviceCommandQueue &default_queue, cl_int *err=nullptr)
Definition: opencl.hpp:9081
static DeviceCommandQueue getDefault(const CommandQueue &queue, cl_int *err=NULL)
Definition: opencl.hpp:9096
static DeviceCommandQueue makeDefault(const Context &context, const Device &device, cl_uint queueSize, cl_int *err=nullptr)
Definition: opencl.hpp:9049
DeviceCommandQueue(DeviceQueueProperties properties, cl_int *err=NULL)
Definition: opencl.hpp:8849
DeviceCommandQueue(const DeviceCommandQueue &queue)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:8938
DeviceCommandQueue(DeviceCommandQueue &&queue) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:8952
DeviceCommandQueue(const cl_command_queue &commandQueue, bool retainObject=false)
Constructor from cl_command_queue - takes ownership.
Definition: opencl.hpp:8926
static DeviceCommandQueue makeDefault(cl_int *err=nullptr)
Definition: opencl.hpp:8991
Class interface for cl_device_id.
Definition: opencl.hpp:2146
detail::param_traits< detail::cl_device_info, name >::param_type getInfo(cl_int *err=NULL) const
Wrapper for clGetDeviceInfo() that returns by value.
Definition: opencl.hpp:2270
Device & operator=(const cl_device_id &rhs)
Assignment operator from cl_device_id.
Definition: opencl.hpp:2224
cl_int getInfo(cl_device_info name, T *param) const
Wrapper for clGetDeviceInfo().
Definition: opencl.hpp:2260
Device()
Default constructor - initializes to NULL.
Definition: opencl.hpp:2182
cl_ulong getHostTimer(cl_int *error=nullptr)
Definition: opencl.hpp:2289
static Device getDefault(cl_int *errResult=NULL)
Returns the first device on the default context.
Definition: opencl.hpp:2195
Device(const Device &dev)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:2233
std::pair< cl_ulong, cl_ulong > getDeviceAndHostTimer(cl_int *error=nullptr)
Definition: opencl.hpp:2313
Device(Device &&dev) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:2247
cl_int createSubDevices(const cl_device_partition_property *properties, vector< Device > *devices)
Wrapper for clCreateSubDevices().
Definition: opencl.hpp:2333
static Device setDefault(const Device &default_device)
Definition: opencl.hpp:2213
Device(const cl_device_id &device, bool retainObject=false)
Constructor from cl_device_id.
Definition: opencl.hpp:2188
Class interface for cl_event.
Definition: opencl.hpp:3221
Event(const cl_event &event, bool retainObject=false)
Constructor from cl_event - takes ownership.
Definition: opencl.hpp:3234
cl_int getProfilingInfo(cl_profiling_info name, T *param) const
Wrapper for clGetEventProfilingInfo().
Definition: opencl.hpp:3273
cl_int setCallback(cl_int type, void(CL_CALLBACK *pfn_notify)(cl_event, cl_int, void *), void *user_data=NULL)
Registers a user callback function for a specific command execution status.
Definition: opencl.hpp:3310
cl_int getInfo(cl_event_info name, T *param) const
Wrapper for clGetEventInfo().
Definition: opencl.hpp:3250
cl_int wait() const
Blocks the calling thread until this event completes.
Definition: opencl.hpp:3298
Event()
Default constructor - initializes to NULL.
Definition: opencl.hpp:3224
Event & operator=(const cl_event &rhs)
Assignment operator from cl_event - takes ownership.
Definition: opencl.hpp:3242
detail::param_traits< detail::cl_profiling_info, name >::param_type getProfilingInfo(cl_int *err=NULL) const
Wrapper for clGetEventProfilingInfo() that returns by value.
Definition: opencl.hpp:3283
detail::param_traits< detail::cl_event_info, name >::param_type getInfo(cl_int *err=NULL) const
Wrapper for clGetEventInfo() that returns by value.
Definition: opencl.hpp:3260
static cl_int waitForEvents(const vector< Event > &events)
Blocks the calling thread until every event specified is complete.
Definition: opencl.hpp:3330
Image interface for arrays of 1D images.
Definition: opencl.hpp:4667
Image1DArray(const Image1DArray &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4723
Image1DArray(Image1DArray &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4737
Image1DArray(const cl_mem &imageArray, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4710
Image interface for 1D buffer images.
Definition: opencl.hpp:4584
Image1DBuffer(const Image1DBuffer &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4636
Image1DBuffer(const cl_mem &image1D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4624
Image1DBuffer(Image1DBuffer &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4650
Class interface for 1D Image Memory objects.
Definition: opencl.hpp:4493
Image1D()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4528
Image1D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4544
Image1D(const cl_mem &image1D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4537
Image1D(const Image1D &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4553
Image1D(const Context &context, cl_mem_flags flags, ImageFormat format, size_type width, void *host_ptr=NULL, cl_int *err=NULL)
Constructs a 1D Image in a specified context.
Definition: opencl.hpp:4499
Image1D(Image1D &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4567
Image interface for arrays of 2D images.
Definition: opencl.hpp:5084
Image2DArray(const Image2DArray &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5142
Image2DArray(const cl_mem &imageArray, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5131
Image2DArray(Image2DArray &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5156
Class interface for GL 2D Image Memory objects.
Definition: opencl.hpp:4994
Image2DGL()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5026
Image2DGL(const Image2DGL &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5051
Image2DGL(Image2DGL &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5065
Image2DGL(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5035
Image2DGL(const Context &context, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texobj, cl_int *err=NULL)
Constructs an Image2DGL in a specified context, from a given GL Texture.
Definition: opencl.hpp:5001
Class interface for 2D Image Memory objects.
Definition: opencl.hpp:4759
Image2D(const Image2D &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4955
Image2D(const cl_mem &image2D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4939
Image2D()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4930
Image2D(Image2D &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4969
Image2D(const Context &context, cl_mem_flags flags, ImageFormat format, size_type width, size_type height, size_type row_pitch=0, void *host_ptr=NULL, cl_int *err=NULL)
Constructs a 2D Image in a specified context.
Definition: opencl.hpp:4765
Image2D(const Context &context, ImageFormat format, const Buffer &sourceBuffer, size_type width, size_type height, size_type row_pitch=0, cl_int *err=nullptr)
Constructs a 2D Image from a buffer.
Definition: opencl.hpp:4833
Image2D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4946
Image2D(const Context &context, cl_channel_order order, const Image &sourceImage, cl_int *err=nullptr)
Constructs a 2D Image from an image.
Definition: opencl.hpp:4879
Class interface for GL 3D Image Memory objects.
Definition: opencl.hpp:5311
Image3DGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:5358
Image3DGL()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5342
Image3DGL(Image3DGL &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5381
Image3DGL(const Image3DGL &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5367
Image3DGL(const Context &context, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texobj, cl_int *err=NULL)
Constructs an Image3DGL in a specified context, from a given GL Texture.
Definition: opencl.hpp:5318
Image3DGL(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5351
Class interface for 3D Image Memory objects.
Definition: opencl.hpp:5176
Image3D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:5266
Image3D(const cl_mem &image3D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5259
Image3D()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5250
Image3D(const Context &context, cl_mem_flags flags, ImageFormat format, size_type width, size_type height, size_type depth, size_type row_pitch=0, size_type slice_pitch=0, void *host_ptr=NULL, cl_int *err=NULL)
Constructs a 3D Image in a specified context.
Definition: opencl.hpp:5182
Image3D(Image3D &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5289
Image3D(const Image3D &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5275
general image interface for GL interop. We abstract the 2D and 3D GL images into a single instance he...
Definition: opencl.hpp:5402
ImageGL(const ImageGL &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5448
ImageGL(ImageGL &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5462
ImageGL(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5436
C++ base class for Image Memory objects.
Definition: opencl.hpp:4406
Image(const Image &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4434
Image(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4418
detail::param_traits< detail::cl_image_info, name >::param_type getImageInfo(cl_int *err=NULL) const
Wrapper for clGetImageInfo() that returns by value.
Definition: opencl.hpp:4473
cl_int getImageInfo(cl_image_info name, T *param) const
Wrapper for clGetImageInfo().
Definition: opencl.hpp:4463
Image()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4409
Image(Image &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4448
Image & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4425
Event operator()(const EnqueueArgs &args, Ts... ts)
Definition: opencl.hpp:10105
Event result_type
Return type of the functor.
Definition: opencl.hpp:10098
Class interface for cl_kernel.
Definition: opencl.hpp:5892
Kernel(Kernel &&kernel) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5938
Kernel(const cl_kernel &kernel, bool retainObject=false)
Constructor from cl_kernel - takes ownership.
Definition: opencl.hpp:5907
Kernel & operator=(const cl_kernel &rhs)
Assignment operator from cl_kernel - takes ownership.
Definition: opencl.hpp:5915
cl_int setSVMPointers(const vector< void * > &pointerList)
Definition: opencl.hpp:6110
cl_int setArg(cl_uint index, const cl::pointer< T, D > &argPtr)
setArg overload taking a shared_ptr type
Definition: opencl.hpp:6054
Kernel()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5897
std::enable_if< std::is_pointer< T >::value, cl_int >::type setArg(cl_uint index, const T argPtr)
setArg overload taking a pointer type
Definition: opencl.hpp:6075
Kernel(const Kernel &kernel)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5924
cl_int setArg(cl_uint index, const cl::vector< T, Alloc > &argPtr)
setArg overload taking a vector type.
Definition: opencl.hpp:6064
std::enable_if<!std::is_pointer< T >::value, cl_int >::type setArg(cl_uint index, const T &value)
setArg overload taking a POD type
Definition: opencl.hpp:6087
cl_int setSVMPointers(const std::array< void *, ArrayLength > &pointerList)
Definition: opencl.hpp:6125
Kernel clone()
Definition: opencl.hpp:6226
cl_int enableFineGrainedSystemSVM(bool svmEnabled)
Enable fine-grained system SVM.
Definition: opencl.hpp:6146
Class interface for cl_mem.
Definition: opencl.hpp:3404
cl_int setDestructorCallback(void(CL_CALLBACK *pfn_notify)(cl_mem, void *), void *user_data=NULL)
Registers a callback function to be called when the memory object is no longer needed.
Definition: opencl.hpp:3500
Memory(const Memory &mem)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3437
Memory(Memory &&mem) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3451
Memory(const cl_mem &memory, bool retainObject)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:3420
detail::param_traits< detail::cl_mem_info, name >::param_type getInfo(cl_int *err=NULL) const
Wrapper for clGetMemObjectInfo() that returns by value.
Definition: opencl.hpp:3475
Memory()
Default constructor - initializes to NULL.
Definition: opencl.hpp:3407
Memory & operator=(const cl_mem &rhs)
Assignment operator from cl_mem - takes ownership.
Definition: opencl.hpp:3428
cl_int getInfo(cl_mem_info name, T *param) const
Wrapper for clGetMemObjectInfo().
Definition: opencl.hpp:3465
Class interface for specifying NDRange values.
Definition: opencl.hpp:5755
size_type dimensions() const
Queries the number of dimensions in the range.
Definition: opencl.hpp:5806
NDRange(size_type size0, size_type size1)
Constructs two-dimensional range.
Definition: opencl.hpp:5780
NDRange(size_type size0, size_type size1, size_type size2)
Constructs three-dimensional range.
Definition: opencl.hpp:5789
size_type size() const
Returns the size of the object in bytes based on the.
Definition: opencl.hpp:5813
NDRange()
Default constructor - resulting range has zero dimensions.
Definition: opencl.hpp:5762
NDRange(size_type size0)
Constructs one-dimensional range.
Definition: opencl.hpp:5771
Class interface for Pipe Memory Objects.
Definition: opencl.hpp:5485
Pipe(Pipe &&pipe) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5580
Pipe(const Context &context, cl_uint packet_size, cl_uint max_packets, cl_int *err=NULL)
Constructs a Pipe in a specified context.
Definition: opencl.hpp:5497
Pipe & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:5557
Pipe()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5541
cl_int getInfo(cl_pipe_info name, T *param) const
Wrapper for clGetMemObjectInfo().
Definition: opencl.hpp:5593
Pipe(cl_uint packet_size, cl_uint max_packets, cl_int *err=NULL)
Constructs a Pipe in a the default context.
Definition: opencl.hpp:5522
Pipe(const Pipe &pipe)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5566
Pipe(const cl_mem &pipe, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5550
detail::param_traits< detail::cl_pipe_info, name >::param_type getInfo(cl_int *err=NULL) const
Wrapper for clGetMemObjectInfo() that returns by value.
Definition: opencl.hpp:5603
Class interface for cl_platform_id.
Definition: opencl.hpp:2426
static cl_int get(Platform *platform)
Gets the first available platform.
Definition: opencl.hpp:2737
Platform(const cl_platform_id &platform, bool retainObject=false)
Constructor from cl_platform_id.
Definition: opencl.hpp:2507
Platform()
Default constructor - initializes to NULL.
Definition: opencl.hpp:2498
cl_int unloadCompiler()
Wrapper for clUnloadCompiler().
Definition: opencl.hpp:2770
cl_int getDevices(cl_device_type type, vector< Device > *devices) const
Gets a list of devices for this platform.
Definition: opencl.hpp:2572
static Platform get(cl_int *errResult=NULL)
Gets the first available platform, returning it by value.
Definition: opencl.hpp:2756
detail::param_traits< detail::cl_platform_info, name >::param_type getInfo(cl_int *err=NULL) const
Wrapper for clGetPlatformInfo() that returns by value.
Definition: opencl.hpp:2557
Platform & operator=(const cl_platform_id &rhs)
Assignment operator from cl_platform_id.
Definition: opencl.hpp:2514
static cl_int get(vector< Platform > *platforms)
Gets a list of available platforms.
Definition: opencl.hpp:2702
cl_int getInfo(cl_platform_info name, T *param) const
Wrapper for clGetPlatformInfo().
Definition: opencl.hpp:2547
static Platform setDefault(const Platform &default_platform)
Definition: opencl.hpp:2538
Program interface that implements cl_program.
Definition: opencl.hpp:6241
Program(const Program &program)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:6640
Program(Program &&program) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:6654
Program(const Sources &sources, cl_int *err=NULL)
Definition: opencl.hpp:6331
Program(const Context &context, const Sources &sources, cl_int *err=NULL)
Definition: opencl.hpp:6366
Program(const vector< char > &IL, bool build=false, cl_int *err=NULL)
Definition: opencl.hpp:6403
CL_API_PREFIX__VERSION_2_2_DEPRECATED cl_int setReleaseCallback(void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data), void *user_data=NULL) CL_API_SUFFIX__VERSION_2_2_DEPRECATED
Registers a callback function to be called when destructors for program scope global variables are co...
Definition: opencl.hpp:6877
vector< std::pair< cl::Device, typename detail::param_traits< detail::cl_program_build_info, name >::param_type > > getBuildInfo(cl_int *err=NULL) const
Definition: opencl.hpp:6798
Program(const Context &context, const vector< Device > &devices, const string &kernelNames, cl_int *err=NULL)
Definition: opencl.hpp:6590
cl_int setSpecializationConstant(cl_uint index, size_type size, const void *value)
Sets a SPIR-V specialization constant.
Definition: opencl.hpp:6911
Program(const cl_program &program, bool retainObject=false)
Constructor from cl_program - takes ownership.
Definition: opencl.hpp:6628
std::enable_if<!std::is_pointer< T >::value, cl_int >::type setSpecializationConstant(cl_uint index, const T &value)
Sets a SPIR-V specialization constant.
Definition: opencl.hpp:6896
Program(const Context &context, const vector< Device > &devices, const Binaries &binaries, vector< cl_int > *binaryStatus=NULL, cl_int *err=NULL)
Definition: opencl.hpp:6526
Program(const Context &context, const vector< char > &IL, bool build=false, cl_int *err=NULL)
Definition: opencl.hpp:6458
pointer allocate(size_type size, typename cl::SVMAllocator< void, SVMTrait >::const_pointer=0)
Definition: opencl.hpp:3693
bool operator==(SVMAllocator const &rhs)
Definition: opencl.hpp:3763
size_type max_size() const CL_HPP_NOEXCEPT_
Definition: opencl.hpp:3735
Class interface for cl_sampler.
Definition: opencl.hpp:5626
Sampler & operator=(const cl_sampler &rhs)
Assignment operator from cl_sampler - takes ownership.
Definition: opencl.hpp:5690
Sampler()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5629
Sampler(const Context &context, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode, cl_int *err=NULL)
Constructs a Sampler in a specified context.
Definition: opencl.hpp:5635
Sampler(Sampler &&sam) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5713
Sampler(const Sampler &sam)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5699
cl_int getInfo(cl_sampler_info name, T *param) const
Wrapper for clGetSamplerInfo().
Definition: opencl.hpp:5726
Sampler(const cl_sampler &sampler, bool retainObject=false)
Constructor from cl_sampler - takes ownership.
Definition: opencl.hpp:5682
detail::param_traits< detail::cl_sampler_info, name >::param_type getInfo(cl_int *err=NULL) const
Wrapper for clGetSamplerInfo() that returns by value.
Definition: opencl.hpp:5736
Class interface for user events (a subset of cl_event's).
Definition: opencl.hpp:3345
UserEvent()
Default constructor - initializes to NULL.
Definition: opencl.hpp:3367
UserEvent(const Context &context, cl_int *err=NULL)
Constructs a user event on a given context.
Definition: opencl.hpp:3351
cl_int setStatus(cl_int status)
Sets the execution status of a user event object.
Definition: opencl.hpp:3373
The OpenCL C++ bindings are defined within this namespace.
Definition: opencl.hpp:583
cl_int copy(const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator)
Definition: opencl.hpp:9552
vector< T, cl::SVMAllocator< int, cl::SVMTraitFine<> >> fine_svm_vector
Vector alias to simplify contruction of fine-grained SVM containers.
Definition: opencl.hpp:3876
cl_int copy(IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer)
Definition: opencl.hpp:9481
LocalSpaceArg Local(size_type size)
Helper function for generating LocalSpaceArg objects.
Definition: opencl.hpp:5877
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int UnloadCompiler() CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition: opencl.hpp:2793
cl_int enqueueUnmapSVM(T *ptr, const vector< Event > *events=NULL, Event *event=NULL)
Definition: opencl.hpp:9396
cl::pointer< T, detail::Deleter< Alloc > > allocate_pointer(const Alloc &alloc_, Args &&... args)
Definition: opencl.hpp:3823
cl_int enqueueMapSVM(T *ptr, cl_bool blocking, cl_map_flags flags, size_type size, const vector< Event > *events=NULL, Event *event=NULL)
Definition: opencl.hpp:9294
vector< T, cl::SVMAllocator< int, cl::SVMTraitCoarse<> >> coarse_svm_vector
Vector alias to simplify contruction of coarse-grained SVM containers.
Definition: opencl.hpp:3870
cl_int mapSVM(cl::vector< T, Alloc > &container)
Definition: opencl.hpp:9583
vector< T, cl::SVMAllocator< int, cl::SVMTraitAtomic<> >> atomic_svm_vector
Vector alias to simplify contruction of fine-grained SVM containers that support platform atomics.
Definition: opencl.hpp:3882
cl_int unmapSVM(cl::vector< T, Alloc > &container)
Definition: opencl.hpp:9592
Adds constructors and member functions for cl_image_format.
Definition: opencl.hpp:2113
ImageFormat(cl_channel_order order, cl_channel_type type)
Initializing constructor.
Definition: opencl.hpp:2118
ImageFormat & operator=(const ImageFormat &rhs)
Assignment operator.
Definition: opencl.hpp:2128
ImageFormat(const ImageFormat &other)
Copy constructor.
Definition: opencl.hpp:2125
ImageFormat()
Default constructor - performs no initialization.
Definition: opencl.hpp:2115
Local address wrapper for use with Kernel::setArg.
Definition: opencl.hpp:5834
Event type_(const EnqueueArgs &, Ts...)
Function signature of kernel functor with no event dependency.
Definition: opencl.hpp:10195
Event result_type
Return type of the functor.
Definition: opencl.hpp:10192
static cl_int release(cl_device_id device)
Definition: opencl.hpp:1675
static cl_int retain(cl_device_id device)
Definition: opencl.hpp:1664