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 
328 
340 
396 #ifndef CL_HPP_
397 #define CL_HPP_
398 
399 /* Handle deprecated preprocessor definitions. In each case, we only check for
400  * the old name if the new name is not defined, so that user code can define
401  * both and hence work with either version of the bindings.
402  */
403 #if !defined(CL_HPP_USE_DX_INTEROP) && defined(USE_DX_INTEROP)
404 # pragma message("opencl.hpp: USE_DX_INTEROP is deprecated. Define CL_HPP_USE_DX_INTEROP instead")
405 # define CL_HPP_USE_DX_INTEROP
406 #endif
407 #if !defined(CL_HPP_USE_CL_DEVICE_FISSION) && defined(USE_CL_DEVICE_FISSION)
408 # pragma message("opencl.hpp: USE_CL_DEVICE_FISSION is deprecated. Define CL_HPP_USE_CL_DEVICE_FISSION instead")
409 # define CL_HPP_USE_CL_DEVICE_FISSION
410 #endif
411 #if !defined(CL_HPP_ENABLE_EXCEPTIONS) && defined(__CL_ENABLE_EXCEPTIONS)
412 # pragma message("opencl.hpp: __CL_ENABLE_EXCEPTIONS is deprecated. Define CL_HPP_ENABLE_EXCEPTIONS instead")
413 # define CL_HPP_ENABLE_EXCEPTIONS
414 #endif
415 #if !defined(CL_HPP_NO_STD_VECTOR) && defined(__NO_STD_VECTOR)
416 # pragma message("opencl.hpp: __NO_STD_VECTOR is deprecated. Define CL_HPP_NO_STD_VECTOR instead")
417 # define CL_HPP_NO_STD_VECTOR
418 #endif
419 #if !defined(CL_HPP_NO_STD_STRING) && defined(__NO_STD_STRING)
420 # pragma message("opencl.hpp: __NO_STD_STRING is deprecated. Define CL_HPP_NO_STD_STRING instead")
421 # define CL_HPP_NO_STD_STRING
422 #endif
423 #if defined(VECTOR_CLASS)
424 # pragma message("opencl.hpp: VECTOR_CLASS is deprecated. Alias cl::vector instead")
425 #endif
426 #if defined(STRING_CLASS)
427 # pragma message("opencl.hpp: STRING_CLASS is deprecated. Alias cl::string instead.")
428 #endif
429 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) && defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
430 # pragma message("opencl.hpp: __CL_USER_OVERRIDE_ERROR_STRINGS is deprecated. Define CL_HPP_USER_OVERRIDE_ERROR_STRINGS instead")
431 # define CL_HPP_USER_OVERRIDE_ERROR_STRINGS
432 #endif
433 
434 /* Warn about features that are no longer supported
435  */
436 #if defined(__USE_DEV_VECTOR)
437 # pragma message("opencl.hpp: __USE_DEV_VECTOR is no longer supported. Expect compilation errors")
438 #endif
439 #if defined(__USE_DEV_STRING)
440 # pragma message("opencl.hpp: __USE_DEV_STRING is no longer supported. Expect compilation errors")
441 #endif
442 
443 /* Detect which version to target */
444 #if !defined(CL_HPP_TARGET_OPENCL_VERSION)
445 # pragma message("opencl.hpp: CL_HPP_TARGET_OPENCL_VERSION is not defined. It will default to 300 (OpenCL 3.0)")
446 # define CL_HPP_TARGET_OPENCL_VERSION 300
447 #endif
448 #if CL_HPP_TARGET_OPENCL_VERSION != 100 && \
449  CL_HPP_TARGET_OPENCL_VERSION != 110 && \
450  CL_HPP_TARGET_OPENCL_VERSION != 120 && \
451  CL_HPP_TARGET_OPENCL_VERSION != 200 && \
452  CL_HPP_TARGET_OPENCL_VERSION != 210 && \
453  CL_HPP_TARGET_OPENCL_VERSION != 220 && \
454  CL_HPP_TARGET_OPENCL_VERSION != 300
455 # 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).")
456 # undef CL_HPP_TARGET_OPENCL_VERSION
457 # define CL_HPP_TARGET_OPENCL_VERSION 300
458 #endif
459 
460 /* Forward target OpenCL version to C headers if necessary */
461 #if defined(CL_TARGET_OPENCL_VERSION)
462 /* Warn if prior definition of CL_TARGET_OPENCL_VERSION is lower than
463  * requested C++ bindings version */
464 #if CL_TARGET_OPENCL_VERSION < CL_HPP_TARGET_OPENCL_VERSION
465 # pragma message("CL_TARGET_OPENCL_VERSION is already defined as is lower than CL_HPP_TARGET_OPENCL_VERSION")
466 #endif
467 #else
468 # define CL_TARGET_OPENCL_VERSION CL_HPP_TARGET_OPENCL_VERSION
469 #endif
470 
471 #if !defined(CL_HPP_MINIMUM_OPENCL_VERSION)
472 # define CL_HPP_MINIMUM_OPENCL_VERSION 200
473 #endif
474 #if CL_HPP_MINIMUM_OPENCL_VERSION != 100 && \
475  CL_HPP_MINIMUM_OPENCL_VERSION != 110 && \
476  CL_HPP_MINIMUM_OPENCL_VERSION != 120 && \
477  CL_HPP_MINIMUM_OPENCL_VERSION != 200 && \
478  CL_HPP_MINIMUM_OPENCL_VERSION != 210 && \
479  CL_HPP_MINIMUM_OPENCL_VERSION != 220 && \
480  CL_HPP_MINIMUM_OPENCL_VERSION != 300
481 # 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")
482 # undef CL_HPP_MINIMUM_OPENCL_VERSION
483 # define CL_HPP_MINIMUM_OPENCL_VERSION 100
484 #endif
485 #if CL_HPP_MINIMUM_OPENCL_VERSION > CL_HPP_TARGET_OPENCL_VERSION
486 # error "CL_HPP_MINIMUM_OPENCL_VERSION must not be greater than CL_HPP_TARGET_OPENCL_VERSION"
487 #endif
488 
489 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 100 && !defined(CL_USE_DEPRECATED_OPENCL_1_0_APIS)
490 # define CL_USE_DEPRECATED_OPENCL_1_0_APIS
491 #endif
492 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 110 && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
493 # define CL_USE_DEPRECATED_OPENCL_1_1_APIS
494 #endif
495 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 120 && !defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
496 # define CL_USE_DEPRECATED_OPENCL_1_2_APIS
497 #endif
498 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 200 && !defined(CL_USE_DEPRECATED_OPENCL_2_0_APIS)
499 # define CL_USE_DEPRECATED_OPENCL_2_0_APIS
500 #endif
501 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 210 && !defined(CL_USE_DEPRECATED_OPENCL_2_1_APIS)
502 # define CL_USE_DEPRECATED_OPENCL_2_1_APIS
503 #endif
504 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 220 && !defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
505 # define CL_USE_DEPRECATED_OPENCL_2_2_APIS
506 #endif
507 
508 #ifdef _WIN32
509 
510 #include <malloc.h>
511 
512 #if defined(CL_HPP_USE_DX_INTEROP)
513 #include <CL/cl_d3d10.h>
514 #include <CL/cl_dx9_media_sharing.h>
515 #endif
516 #endif // _WIN32
517 
518 #if defined(_MSC_VER)
519 #include <intrin.h>
520 #endif // _MSC_VER
521 
522  // Check for a valid C++ version
523 
524 // Need to do both tests here because for some reason __cplusplus is not
525 // updated in visual studio
526 #if (!defined(_MSC_VER) && __cplusplus < 201103L) || (defined(_MSC_VER) && _MSC_VER < 1700)
527 #error Visual studio 2013 or another C++11-supporting compiler required
528 #endif
529 
530 //
531 #if defined(CL_HPP_USE_CL_DEVICE_FISSION) || defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)
532 #include <CL/cl_ext.h>
533 #endif
534 
535 #if defined(__APPLE__) || defined(__MACOSX)
536 #include <OpenCL/opencl.h>
537 #else
538 #include <CL/opencl.h>
539 #endif // !__APPLE__
540 
541 #if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L )
542 #define CL_HPP_NOEXCEPT_ noexcept
543 #else
544 #define CL_HPP_NOEXCEPT_
545 #endif
546 
547 #if __cplusplus >= 201703L
548 # define CL_HPP_DEFINE_STATIC_MEMBER_ inline
549 #elif defined(_MSC_VER)
550 # define CL_HPP_DEFINE_STATIC_MEMBER_ __declspec(selectany)
551 #elif defined(__MINGW32__)
552 # define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((selectany))
553 #else
554 # define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((weak))
555 #endif // !_MSC_VER
556 
557 // Define deprecated prefixes and suffixes to ensure compilation
558 // in case they are not pre-defined
559 #if !defined(CL_API_PREFIX__VERSION_1_1_DEPRECATED)
560 #define CL_API_PREFIX__VERSION_1_1_DEPRECATED
561 #endif // #if !defined(CL_API_PREFIX__VERSION_1_1_DEPRECATED)
562 #if !defined(CL_API_SUFFIX__VERSION_1_1_DEPRECATED)
563 #define CL_API_SUFFIX__VERSION_1_1_DEPRECATED
564 #endif // #if !defined(CL_API_SUFFIX__VERSION_1_1_DEPRECATED)
565 
566 #if !defined(CL_API_PREFIX__VERSION_1_2_DEPRECATED)
567 #define CL_API_PREFIX__VERSION_1_2_DEPRECATED
568 #endif // #if !defined(CL_API_PREFIX__VERSION_1_2_DEPRECATED)
569 #if !defined(CL_API_SUFFIX__VERSION_1_2_DEPRECATED)
570 #define CL_API_SUFFIX__VERSION_1_2_DEPRECATED
571 #endif // #if !defined(CL_API_SUFFIX__VERSION_1_2_DEPRECATED)
572 
573 #if !defined(CL_API_PREFIX__VERSION_2_2_DEPRECATED)
574 #define CL_API_PREFIX__VERSION_2_2_DEPRECATED
575 #endif // #if !defined(CL_API_PREFIX__VERSION_2_2_DEPRECATED)
576 #if !defined(CL_API_SUFFIX__VERSION_2_2_DEPRECATED)
577 #define CL_API_SUFFIX__VERSION_2_2_DEPRECATED
578 #endif // #if !defined(CL_API_SUFFIX__VERSION_2_2_DEPRECATED)
579 
580 #if !defined(CL_CALLBACK)
581 #define CL_CALLBACK
582 #endif //CL_CALLBACK
583 
584 #include <utility>
585 #include <limits>
586 #include <iterator>
587 #include <mutex>
588 #include <cstring>
589 #include <functional>
590 
591 
592 // Define a size_type to represent a correctly resolved size_t
593 #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
594 namespace cl {
595  using size_type = ::size_t;
596 } // namespace cl
597 #else // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
598 namespace cl {
599  using size_type = size_t;
600 } // namespace cl
601 #endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
602 
603 
604 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
605 #include <exception>
606 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
607 
608 #if !defined(CL_HPP_NO_STD_VECTOR)
609 #include <vector>
610 namespace cl {
611  template < class T, class Alloc = std::allocator<T> >
612  using vector = std::vector<T, Alloc>;
613 } // namespace cl
614 #endif // #if !defined(CL_HPP_NO_STD_VECTOR)
615 
616 #if !defined(CL_HPP_NO_STD_STRING)
617 #include <string>
618 namespace cl {
619  using string = std::string;
620 } // namespace cl
621 #endif // #if !defined(CL_HPP_NO_STD_STRING)
622 
623 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
624 
625 #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
626 #include <memory>
627 namespace cl {
628  // Replace unique_ptr and allocate_pointer for internal use
629  // to allow user to replace them
630  template<class T, class D>
631  using pointer = std::unique_ptr<T, D>;
632 } // namespace cl
633 #endif
634 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
635 #if !defined(CL_HPP_NO_STD_ARRAY)
636 #include <array>
637 namespace cl {
638  template < class T, size_type N >
639  using array = std::array<T, N>;
640 } // namespace cl
641 #endif // #if !defined(CL_HPP_NO_STD_ARRAY)
642 
643 // Define size_type appropriately to allow backward-compatibility
644 // use of the old size_t interface class
645 #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
646 namespace cl {
647  namespace compatibility {
652  template <int N>
653  class size_t
654  {
655  private:
656  size_type data_[N];
657 
658  public:
660  size_t()
661  {
662  for (int i = 0; i < N; ++i) {
663  data_[i] = 0;
664  }
665  }
666 
667  size_t(const array<size_type, N> &rhs)
668  {
669  for (int i = 0; i < N; ++i) {
670  data_[i] = rhs[i];
671  }
672  }
673 
674  size_type& operator[](int index)
675  {
676  return data_[index];
677  }
678 
679  const size_type& operator[](int index) const
680  {
681  return data_[index];
682  }
683 
685  operator size_type* () { return data_; }
686 
688  operator const size_type* () const { return data_; }
689 
690  operator array<size_type, N>() const
691  {
692  array<size_type, N> ret;
693 
694  for (int i = 0; i < N; ++i) {
695  ret[i] = data_[i];
696  }
697  return ret;
698  }
699  };
700  } // namespace compatibility
701 
702  template<int N>
703  using size_t = compatibility::size_t<N>;
704 } // namespace cl
705 #endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
706 
707 // Helper alias to avoid confusing the macros
708 namespace cl {
709  namespace detail {
710  using size_t_array = array<size_type, 3>;
711  } // namespace detail
712 } // namespace cl
713 
714 
720 namespace cl {
721  class Memory;
722 
723 #define CL_HPP_INIT_CL_EXT_FCN_PTR_(name) \
724  if (!pfn_##name) { \
725  pfn_##name = (PFN_##name) \
726  clGetExtensionFunctionAddress(#name); \
727  if (!pfn_##name) { \
728  } \
729  }
730 
731 #define CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, name) \
732  if (!pfn_##name) { \
733  pfn_##name = (PFN_##name) \
734  clGetExtensionFunctionAddressForPlatform(platform, #name); \
735  if (!pfn_##name) { \
736  } \
737  }
738 
739  class Program;
740  class Device;
741  class Context;
742  class CommandQueue;
743  class DeviceCommandQueue;
744  class Memory;
745  class Buffer;
746  class Pipe;
747 
748 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
753  class Error : public std::exception
754  {
755  private:
756  cl_int err_;
757  const char * errStr_;
758  public:
768  Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr)
769  {}
770 
771  ~Error() throw() {}
772 
777  virtual const char * what() const throw ()
778  {
779  if (errStr_ == NULL) {
780  return "empty";
781  }
782  else {
783  return errStr_;
784  }
785  }
786 
791  cl_int err(void) const { return err_; }
792  };
793 #define CL_HPP_ERR_STR_(x) #x
794 #else
795 #define CL_HPP_ERR_STR_(x) NULL
796 #endif // CL_HPP_ENABLE_EXCEPTIONS
797 
798 
799 namespace detail
800 {
801 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
802 static inline cl_int errHandler (
803  cl_int err,
804  const char * errStr = NULL)
805 {
806  if (err != CL_SUCCESS) {
807  throw Error(err, errStr);
808  }
809  return err;
810 }
811 #else
812 static inline cl_int errHandler (cl_int err, const char * errStr = NULL)
813 {
814  (void) errStr; // suppress unused variable warning
815  return err;
816 }
817 #endif // CL_HPP_ENABLE_EXCEPTIONS
818 }
819 
820 
821 
823 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
824 #define __GET_DEVICE_INFO_ERR CL_HPP_ERR_STR_(clGetDeviceInfo)
825 #define __GET_PLATFORM_INFO_ERR CL_HPP_ERR_STR_(clGetPlatformInfo)
826 #define __GET_DEVICE_IDS_ERR CL_HPP_ERR_STR_(clGetDeviceIDs)
827 #define __GET_PLATFORM_IDS_ERR CL_HPP_ERR_STR_(clGetPlatformIDs)
828 #define __GET_CONTEXT_INFO_ERR CL_HPP_ERR_STR_(clGetContextInfo)
829 #define __GET_EVENT_INFO_ERR CL_HPP_ERR_STR_(clGetEventInfo)
830 #define __GET_EVENT_PROFILE_INFO_ERR CL_HPP_ERR_STR_(clGetEventProfileInfo)
831 #define __GET_MEM_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetMemObjectInfo)
832 #define __GET_IMAGE_INFO_ERR CL_HPP_ERR_STR_(clGetImageInfo)
833 #define __GET_SAMPLER_INFO_ERR CL_HPP_ERR_STR_(clGetSamplerInfo)
834 #define __GET_KERNEL_INFO_ERR CL_HPP_ERR_STR_(clGetKernelInfo)
835 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
836 #define __GET_KERNEL_ARG_INFO_ERR CL_HPP_ERR_STR_(clGetKernelArgInfo)
837 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
838 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
839 #define __GET_KERNEL_SUB_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelSubGroupInfo)
840 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
841 #define __GET_KERNEL_WORK_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelWorkGroupInfo)
842 #define __GET_PROGRAM_INFO_ERR CL_HPP_ERR_STR_(clGetProgramInfo)
843 #define __GET_PROGRAM_BUILD_INFO_ERR CL_HPP_ERR_STR_(clGetProgramBuildInfo)
844 #define __GET_COMMAND_QUEUE_INFO_ERR CL_HPP_ERR_STR_(clGetCommandQueueInfo)
845 
846 #define __CREATE_CONTEXT_ERR CL_HPP_ERR_STR_(clCreateContext)
847 #define __CREATE_CONTEXT_FROM_TYPE_ERR CL_HPP_ERR_STR_(clCreateContextFromType)
848 #define __GET_SUPPORTED_IMAGE_FORMATS_ERR CL_HPP_ERR_STR_(clGetSupportedImageFormats)
849 
850 #define __CREATE_BUFFER_ERR CL_HPP_ERR_STR_(clCreateBuffer)
851 #define __COPY_ERR CL_HPP_ERR_STR_(cl::copy)
852 #define __CREATE_SUBBUFFER_ERR CL_HPP_ERR_STR_(clCreateSubBuffer)
853 #define __CREATE_GL_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
854 #define __CREATE_GL_RENDER_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
855 #define __GET_GL_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetGLObjectInfo)
856 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
857 #define __CREATE_IMAGE_ERR CL_HPP_ERR_STR_(clCreateImage)
858 #define __CREATE_GL_TEXTURE_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture)
859 #define __IMAGE_DIMENSION_ERR CL_HPP_ERR_STR_(Incorrect image dimensions)
860 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
861 #define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR CL_HPP_ERR_STR_(clSetMemObjectDestructorCallback)
862 
863 #define __CREATE_USER_EVENT_ERR CL_HPP_ERR_STR_(clCreateUserEvent)
864 #define __SET_USER_EVENT_STATUS_ERR CL_HPP_ERR_STR_(clSetUserEventStatus)
865 #define __SET_EVENT_CALLBACK_ERR CL_HPP_ERR_STR_(clSetEventCallback)
866 #define __WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clWaitForEvents)
867 
868 #define __CREATE_KERNEL_ERR CL_HPP_ERR_STR_(clCreateKernel)
869 #define __SET_KERNEL_ARGS_ERR CL_HPP_ERR_STR_(clSetKernelArg)
870 #define __CREATE_PROGRAM_WITH_SOURCE_ERR CL_HPP_ERR_STR_(clCreateProgramWithSource)
871 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
872 #define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
873 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
874 #define __CREATE_PROGRAM_WITH_BINARY_ERR CL_HPP_ERR_STR_(clCreateProgramWithBinary)
875 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
876 #define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
877 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
878 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
879 #define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR CL_HPP_ERR_STR_(clCreateProgramWithBuiltInKernels)
880 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
881 #define __BUILD_PROGRAM_ERR CL_HPP_ERR_STR_(clBuildProgram)
882 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
883 #define __COMPILE_PROGRAM_ERR CL_HPP_ERR_STR_(clCompileProgram)
884 #define __LINK_PROGRAM_ERR CL_HPP_ERR_STR_(clLinkProgram)
885 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
886 #define __CREATE_KERNELS_IN_PROGRAM_ERR CL_HPP_ERR_STR_(clCreateKernelsInProgram)
887 
888 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
889 #define __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateCommandQueueWithProperties)
890 #define __CREATE_SAMPLER_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateSamplerWithProperties)
891 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
892 #define __SET_COMMAND_QUEUE_PROPERTY_ERR CL_HPP_ERR_STR_(clSetCommandQueueProperty)
893 #define __ENQUEUE_READ_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueReadBuffer)
894 #define __ENQUEUE_READ_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueReadBufferRect)
895 #define __ENQUEUE_WRITE_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueWriteBuffer)
896 #define __ENQUEUE_WRITE_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueWriteBufferRect)
897 #define __ENQEUE_COPY_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyBuffer)
898 #define __ENQEUE_COPY_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferRect)
899 #define __ENQUEUE_FILL_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueFillBuffer)
900 #define __ENQUEUE_READ_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueReadImage)
901 #define __ENQUEUE_WRITE_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueWriteImage)
902 #define __ENQUEUE_COPY_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyImage)
903 #define __ENQUEUE_FILL_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueFillImage)
904 #define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyImageToBuffer)
905 #define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferToImage)
906 #define __ENQUEUE_MAP_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueMapBuffer)
907 #define __ENQUEUE_MAP_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueMapImage)
908 #define __ENQUEUE_UNMAP_MEM_OBJECT_ERR CL_HPP_ERR_STR_(clEnqueueUnMapMemObject)
909 #define __ENQUEUE_NDRANGE_KERNEL_ERR CL_HPP_ERR_STR_(clEnqueueNDRangeKernel)
910 #define __ENQUEUE_NATIVE_KERNEL CL_HPP_ERR_STR_(clEnqueueNativeKernel)
911 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
912 #define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR CL_HPP_ERR_STR_(clEnqueueMigrateMemObjects)
913 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
914 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
915 #define __ENQUEUE_MIGRATE_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMMigrateMem)
916 #define __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clSetDefaultDeviceCommandQueue)
917 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
918 
919 
920 #define __ENQUEUE_ACQUIRE_GL_ERR CL_HPP_ERR_STR_(clEnqueueAcquireGLObjects)
921 #define __ENQUEUE_RELEASE_GL_ERR CL_HPP_ERR_STR_(clEnqueueReleaseGLObjects)
922 
923 #define __CREATE_PIPE_ERR CL_HPP_ERR_STR_(clCreatePipe)
924 #define __GET_PIPE_INFO_ERR CL_HPP_ERR_STR_(clGetPipeInfo)
925 
926 
927 #define __RETAIN_ERR CL_HPP_ERR_STR_(Retain Object)
928 #define __RELEASE_ERR CL_HPP_ERR_STR_(Release Object)
929 #define __FLUSH_ERR CL_HPP_ERR_STR_(clFlush)
930 #define __FINISH_ERR CL_HPP_ERR_STR_(clFinish)
931 #define __VECTOR_CAPACITY_ERR CL_HPP_ERR_STR_(Vector capacity error)
932 
933 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
934 #define __GET_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetHostTimer)
935 #define __GET_DEVICE_AND_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetDeviceAndHostTimer)
936 #endif
937 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
938 #define __SET_PROGRAM_RELEASE_CALLBACK_ERR CL_HPP_ERR_STR_(clSetProgramReleaseCallback)
939 #define __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR CL_HPP_ERR_STR_(clSetProgramSpecializationConstant)
940 #endif
941 
942 
946 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
947 #define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevices)
948 #else
949 #define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevicesEXT)
950 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
951 
955 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
956 #define __ENQUEUE_MARKER_ERR CL_HPP_ERR_STR_(clEnqueueMarker)
957 #define __ENQUEUE_WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clEnqueueWaitForEvents)
958 #define __ENQUEUE_BARRIER_ERR CL_HPP_ERR_STR_(clEnqueueBarrier)
959 #define __UNLOAD_COMPILER_ERR CL_HPP_ERR_STR_(clUnloadCompiler)
960 #define __CREATE_GL_TEXTURE_2D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture2D)
961 #define __CREATE_GL_TEXTURE_3D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture3D)
962 #define __CREATE_IMAGE2D_ERR CL_HPP_ERR_STR_(clCreateImage2D)
963 #define __CREATE_IMAGE3D_ERR CL_HPP_ERR_STR_(clCreateImage3D)
964 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
965 
969 #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
970 #define __CREATE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clCreateCommandQueue)
971 #define __ENQUEUE_TASK_ERR CL_HPP_ERR_STR_(clEnqueueTask)
972 #define __CREATE_SAMPLER_ERR CL_HPP_ERR_STR_(clCreateSampler)
973 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
974 
978 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
979 #define __ENQUEUE_MARKER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueMarkerWithWaitList)
980 #define __ENQUEUE_BARRIER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueBarrierWithWaitList)
981 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
982 
983 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
984 #define __CLONE_KERNEL_ERR CL_HPP_ERR_STR_(clCloneKernel)
985 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
986 
987 #endif // CL_HPP_USER_OVERRIDE_ERROR_STRINGS
989 
990 
991 namespace detail {
992 
993 // Generic getInfoHelper. The final parameter is used to guide overload
994 // resolution: the actual parameter passed is an int, which makes this
995 // a worse conversion sequence than a specialization that declares the
996 // parameter as an int.
997 template<typename Functor, typename T>
998 inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long)
999 {
1000  return f(name, sizeof(T), param, NULL);
1001 }
1002 
1003 // Specialized for getInfo<CL_PROGRAM_BINARIES>
1004 // Assumes that the output vector was correctly resized on the way in
1005 template <typename Func>
1006 inline cl_int getInfoHelper(Func f, cl_uint name, vector<vector<unsigned char>>* param, int)
1007 {
1008  if (name != CL_PROGRAM_BINARIES) {
1009  return CL_INVALID_VALUE;
1010  }
1011  if (param) {
1012  // Create array of pointers, calculate total size and pass pointer array in
1013  size_type numBinaries = param->size();
1014  vector<unsigned char*> binariesPointers(numBinaries);
1015 
1016  for (size_type i = 0; i < numBinaries; ++i)
1017  {
1018  binariesPointers[i] = (*param)[i].data();
1019  }
1020 
1021  cl_int err = f(name, numBinaries * sizeof(unsigned char*), binariesPointers.data(), NULL);
1022 
1023  if (err != CL_SUCCESS) {
1024  return err;
1025  }
1026  }
1027 
1028 
1029  return CL_SUCCESS;
1030 }
1031 
1032 // Specialized getInfoHelper for vector params
1033 template <typename Func, typename T>
1034 inline cl_int getInfoHelper(Func f, cl_uint name, vector<T>* param, long)
1035 {
1036  size_type required;
1037  cl_int err = f(name, 0, NULL, &required);
1038  if (err != CL_SUCCESS) {
1039  return err;
1040  }
1041  const size_type elements = required / sizeof(T);
1042 
1043  // Temporary to avoid changing param on an error
1044  vector<T> localData(elements);
1045  err = f(name, required, localData.data(), NULL);
1046  if (err != CL_SUCCESS) {
1047  return err;
1048  }
1049  if (param) {
1050  *param = std::move(localData);
1051  }
1052 
1053  return CL_SUCCESS;
1054 }
1055 
1056 /* Specialization for reference-counted types. This depends on the
1057  * existence of Wrapper<T>::cl_type, and none of the other types having the
1058  * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1059  * does not work, because when using a derived type (e.g. Context) the generic
1060  * template will provide a better match.
1061  */
1062 template <typename Func, typename T>
1063 inline cl_int getInfoHelper(
1064  Func f, cl_uint name, vector<T>* param, int, typename T::cl_type = 0)
1065 {
1066  size_type required;
1067  cl_int err = f(name, 0, NULL, &required);
1068  if (err != CL_SUCCESS) {
1069  return err;
1070  }
1071 
1072  const size_type elements = required / sizeof(typename T::cl_type);
1073 
1074  vector<typename T::cl_type> value(elements);
1075  err = f(name, required, value.data(), NULL);
1076  if (err != CL_SUCCESS) {
1077  return err;
1078  }
1079 
1080  if (param) {
1081  // Assign to convert CL type to T for each element
1082  param->resize(elements);
1083 
1084  // Assign to param, constructing with retain behaviour
1085  // to correctly capture each underlying CL object
1086  for (size_type i = 0; i < elements; i++) {
1087  (*param)[i] = T(value[i], true);
1088  }
1089  }
1090  return CL_SUCCESS;
1091 }
1092 
1093 // Specialized GetInfoHelper for string params
1094 template <typename Func>
1095 inline cl_int getInfoHelper(Func f, cl_uint name, string* param, long)
1096 {
1097  size_type required;
1098  cl_int err = f(name, 0, NULL, &required);
1099  if (err != CL_SUCCESS) {
1100  return err;
1101  }
1102 
1103  // std::string has a constant data member
1104  // a char vector does not
1105  if (required > 0) {
1106  vector<char> value(required);
1107  err = f(name, required, value.data(), NULL);
1108  if (err != CL_SUCCESS) {
1109  return err;
1110  }
1111  if (param) {
1112  param->assign(begin(value), prev(end(value)));
1113  }
1114  }
1115  else if (param) {
1116  param->assign("");
1117  }
1118  return CL_SUCCESS;
1119 }
1120 
1121 // Specialized GetInfoHelper for clsize_t params
1122 template <typename Func, size_type N>
1123 inline cl_int getInfoHelper(Func f, cl_uint name, array<size_type, N>* param, long)
1124 {
1125  size_type required;
1126  cl_int err = f(name, 0, NULL, &required);
1127  if (err != CL_SUCCESS) {
1128  return err;
1129  }
1130 
1131  size_type elements = required / sizeof(size_type);
1132  vector<size_type> value(elements, 0);
1133 
1134  err = f(name, required, value.data(), NULL);
1135  if (err != CL_SUCCESS) {
1136  return err;
1137  }
1138 
1139  // Bound the copy with N to prevent overruns
1140  // if passed N > than the amount copied
1141  if (elements > N) {
1142  elements = N;
1143  }
1144  for (size_type i = 0; i < elements; ++i) {
1145  (*param)[i] = value[i];
1146  }
1147 
1148  return CL_SUCCESS;
1149 }
1150 
1151 template<typename T> struct ReferenceHandler;
1152 
1153 /* Specialization for reference-counted types. This depends on the
1154  * existence of Wrapper<T>::cl_type, and none of the other types having the
1155  * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1156  * does not work, because when using a derived type (e.g. Context) the generic
1157  * template will provide a better match.
1158  */
1159 template<typename Func, typename T>
1160 inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0)
1161 {
1162  typename T::cl_type value;
1163  cl_int err = f(name, sizeof(value), &value, NULL);
1164  if (err != CL_SUCCESS) {
1165  return err;
1166  }
1167  *param = value;
1168  if (value != NULL)
1169  {
1170  err = param->retain();
1171  if (err != CL_SUCCESS) {
1172  return err;
1173  }
1174  }
1175  return CL_SUCCESS;
1176 }
1177 
1178 #define CL_HPP_PARAM_NAME_INFO_1_0_(F) \
1179  F(cl_platform_info, CL_PLATFORM_PROFILE, string) \
1180  F(cl_platform_info, CL_PLATFORM_VERSION, string) \
1181  F(cl_platform_info, CL_PLATFORM_NAME, string) \
1182  F(cl_platform_info, CL_PLATFORM_VENDOR, string) \
1183  F(cl_platform_info, CL_PLATFORM_EXTENSIONS, string) \
1184  \
1185  F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
1186  F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
1187  F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
1188  F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
1189  F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, size_type) \
1190  F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, cl::vector<size_type>) \
1191  F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
1192  F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
1193  F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
1194  F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
1195  F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
1196  F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
1197  F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
1198  F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \
1199  F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
1200  F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
1201  F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
1202  F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, size_type) \
1203  F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, size_type) \
1204  F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, size_type) \
1205  F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, size_type) \
1206  F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, size_type) \
1207  F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \
1208  F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, size_type) \
1209  F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
1210  F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
1211  F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
1212  F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
1213  F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
1214  F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
1215  F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
1216  F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
1217  F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
1218  F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
1219  F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
1220  F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
1221  F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
1222  F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
1223  F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
1224  F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, size_type) \
1225  F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
1226  F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
1227  F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
1228  F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
1229  F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
1230  F(cl_device_info, CL_DEVICE_NAME, string) \
1231  F(cl_device_info, CL_DEVICE_VENDOR, string) \
1232  F(cl_device_info, CL_DRIVER_VERSION, string) \
1233  F(cl_device_info, CL_DEVICE_PROFILE, string) \
1234  F(cl_device_info, CL_DEVICE_VERSION, string) \
1235  F(cl_device_info, CL_DEVICE_EXTENSIONS, string) \
1236  \
1237  F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
1238  F(cl_context_info, CL_CONTEXT_DEVICES, cl::vector<Device>) \
1239  F(cl_context_info, CL_CONTEXT_PROPERTIES, cl::vector<cl_context_properties>) \
1240  \
1241  F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
1242  F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
1243  F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
1244  F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \
1245  \
1246  F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
1247  F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
1248  F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
1249  F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
1250  \
1251  F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
1252  F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
1253  F(cl_mem_info, CL_MEM_SIZE, size_type) \
1254  F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
1255  F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
1256  F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
1257  F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
1258  \
1259  F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
1260  F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, size_type) \
1261  F(cl_image_info, CL_IMAGE_ROW_PITCH, size_type) \
1262  F(cl_image_info, CL_IMAGE_SLICE_PITCH, size_type) \
1263  F(cl_image_info, CL_IMAGE_WIDTH, size_type) \
1264  F(cl_image_info, CL_IMAGE_HEIGHT, size_type) \
1265  F(cl_image_info, CL_IMAGE_DEPTH, size_type) \
1266  \
1267  F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
1268  F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
1269  F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \
1270  F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \
1271  F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \
1272  \
1273  F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
1274  F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
1275  F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
1276  F(cl_program_info, CL_PROGRAM_DEVICES, cl::vector<Device>) \
1277  F(cl_program_info, CL_PROGRAM_SOURCE, string) \
1278  F(cl_program_info, CL_PROGRAM_BINARY_SIZES, cl::vector<size_type>) \
1279  F(cl_program_info, CL_PROGRAM_BINARIES, cl::vector<cl::vector<unsigned char>>) \
1280  \
1281  F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
1282  F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, string) \
1283  F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, string) \
1284  \
1285  F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, string) \
1286  F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
1287  F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
1288  F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
1289  F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
1290  \
1291  F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, size_type) \
1292  F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::detail::size_t_array) \
1293  F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
1294  \
1295  F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
1296  F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
1297  F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
1298  F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
1299 
1300 
1301 #define CL_HPP_PARAM_NAME_INFO_1_1_(F) \
1302  F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
1303  F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
1304  F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
1305  F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
1306  F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
1307  F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
1308  F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
1309  F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
1310  F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
1311  F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, string) \
1312  \
1313  F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
1314  F(cl_mem_info, CL_MEM_OFFSET, size_type) \
1315  \
1316  F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1317  F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
1318  \
1319  F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
1320 
1321 #define CL_HPP_PARAM_NAME_INFO_1_2_(F) \
1322  F(cl_program_info, CL_PROGRAM_NUM_KERNELS, size_type) \
1323  F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, string) \
1324  \
1325  F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \
1326  \
1327  F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, string) \
1328  \
1329  F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \
1330  F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \
1331  F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, string) \
1332  F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, string) \
1333  F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \
1334  \
1335  F(cl_kernel_work_group_info, CL_KERNEL_GLOBAL_WORK_SIZE, cl::detail::size_t_array) \
1336  \
1337  F(cl_device_info, CL_DEVICE_LINKER_AVAILABLE, cl_bool) \
1338  F(cl_device_info, CL_DEVICE_IMAGE_MAX_BUFFER_SIZE, size_type) \
1339  F(cl_device_info, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, size_type) \
1340  F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl::Device) \
1341  F(cl_device_info, CL_DEVICE_PARTITION_MAX_SUB_DEVICES, cl_uint) \
1342  F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, cl::vector<cl_device_partition_property>) \
1343  F(cl_device_info, CL_DEVICE_PARTITION_TYPE, cl::vector<cl_device_partition_property>) \
1344  F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \
1345  F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, cl_bool) \
1346  F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \
1347  F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, string) \
1348  F(cl_device_info, CL_DEVICE_PRINTF_BUFFER_SIZE, size_type) \
1349  \
1350  F(cl_image_info, CL_IMAGE_ARRAY_SIZE, size_type) \
1351  F(cl_image_info, CL_IMAGE_NUM_MIP_LEVELS, cl_uint) \
1352  F(cl_image_info, CL_IMAGE_NUM_SAMPLES, cl_uint)
1353 
1354 #define CL_HPP_PARAM_NAME_INFO_2_0_(F) \
1355  F(cl_device_info, CL_DEVICE_QUEUE_ON_HOST_PROPERTIES, cl_command_queue_properties) \
1356  F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES, cl_command_queue_properties) \
1357  F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, cl_uint) \
1358  F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, cl_uint) \
1359  F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_QUEUES, cl_uint) \
1360  F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_EVENTS, cl_uint) \
1361  F(cl_device_info, CL_DEVICE_MAX_PIPE_ARGS, cl_uint) \
1362  F(cl_device_info, CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS, cl_uint) \
1363  F(cl_device_info, CL_DEVICE_PIPE_MAX_PACKET_SIZE, cl_uint) \
1364  F(cl_device_info, CL_DEVICE_SVM_CAPABILITIES, cl_device_svm_capabilities) \
1365  F(cl_device_info, CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT, cl_uint) \
1366  F(cl_device_info, CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT, cl_uint) \
1367  F(cl_device_info, CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT, cl_uint) \
1368  F(cl_device_info, CL_DEVICE_IMAGE_PITCH_ALIGNMENT, cl_uint) \
1369  F(cl_device_info, CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT, cl_uint) \
1370  F(cl_device_info, CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS, cl_uint ) \
1371  F(cl_device_info, CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE, size_type ) \
1372  F(cl_device_info, CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE, size_type ) \
1373  F(cl_profiling_info, CL_PROFILING_COMMAND_COMPLETE, cl_ulong) \
1374  F(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM, cl_bool) \
1375  F(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_SVM_PTRS, void**) \
1376  F(cl_command_queue_info, CL_QUEUE_SIZE, cl_uint) \
1377  F(cl_mem_info, CL_MEM_USES_SVM_POINTER, cl_bool) \
1378  F(cl_program_build_info, CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, size_type) \
1379  F(cl_pipe_info, CL_PIPE_PACKET_SIZE, cl_uint) \
1380  F(cl_pipe_info, CL_PIPE_MAX_PACKETS, cl_uint)
1381 
1382 #define CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(F) \
1383  F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR, size_type) \
1384  F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR, size_type)
1385 
1386 #define CL_HPP_PARAM_NAME_INFO_IL_KHR_(F) \
1387  F(cl_device_info, CL_DEVICE_IL_VERSION_KHR, string) \
1388  F(cl_program_info, CL_PROGRAM_IL_KHR, cl::vector<unsigned char>)
1389 
1390 #define CL_HPP_PARAM_NAME_INFO_2_1_(F) \
1391  F(cl_platform_info, CL_PLATFORM_HOST_TIMER_RESOLUTION, cl_ulong) \
1392  F(cl_program_info, CL_PROGRAM_IL, cl::vector<unsigned char>) \
1393  F(cl_device_info, CL_DEVICE_MAX_NUM_SUB_GROUPS, cl_uint) \
1394  F(cl_device_info, CL_DEVICE_IL_VERSION, string) \
1395  F(cl_device_info, CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS, cl_bool) \
1396  F(cl_command_queue_info, CL_QUEUE_DEVICE_DEFAULT, cl::DeviceCommandQueue) \
1397  F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE, size_type) \
1398  F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE, size_type) \
1399  F(cl_kernel_sub_group_info, CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT, cl::detail::size_t_array) \
1400  F(cl_kernel_sub_group_info, CL_KERNEL_MAX_NUM_SUB_GROUPS, size_type) \
1401  F(cl_kernel_sub_group_info, CL_KERNEL_COMPILE_NUM_SUB_GROUPS, size_type)
1402 
1403 #define CL_HPP_PARAM_NAME_INFO_2_2_(F) \
1404  F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_CTORS_PRESENT, cl_bool) \
1405  F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_DTORS_PRESENT, cl_bool)
1406 
1407 #define CL_HPP_PARAM_NAME_DEVICE_FISSION_(F) \
1408  F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
1409  F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, cl::vector<cl_device_partition_property_ext>) \
1410  F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, cl::vector<cl_device_partition_property_ext>) \
1411  F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
1412  F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, cl::vector<cl_device_partition_property_ext>)
1413 
1414 #define CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_CL3_SHARED_(F) \
1415  F(cl_platform_info, CL_PLATFORM_NUMERIC_VERSION_KHR, cl_version_khr) \
1416  F(cl_platform_info, CL_PLATFORM_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1417  \
1418  F(cl_device_info, CL_DEVICE_NUMERIC_VERSION_KHR, cl_version_khr) \
1419  F(cl_device_info, CL_DEVICE_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1420  F(cl_device_info, CL_DEVICE_ILS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1421  F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>)
1422 
1423 #define CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_KHRONLY_(F) \
1424  F(cl_device_info, CL_DEVICE_OPENCL_C_NUMERIC_VERSION_KHR, cl_version_khr)
1425 
1426 #define CL_HPP_PARAM_NAME_INFO_3_0_(F) \
1427  F(cl_platform_info, CL_PLATFORM_NUMERIC_VERSION, cl_version) \
1428  F(cl_platform_info, CL_PLATFORM_EXTENSIONS_WITH_VERSION, cl::vector<cl_name_version>) \
1429  \
1430  F(cl_device_info, CL_DEVICE_NUMERIC_VERSION, cl_version) \
1431  F(cl_device_info, CL_DEVICE_EXTENSIONS_WITH_VERSION, cl::vector<cl_name_version>) \
1432  F(cl_device_info, CL_DEVICE_ILS_WITH_VERSION, cl::vector<cl_name_version>) \
1433  F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION, cl::vector<cl_name_version>) \
1434  F(cl_device_info, CL_DEVICE_ATOMIC_MEMORY_CAPABILITIES, cl_device_atomic_capabilities) \
1435  F(cl_device_info, CL_DEVICE_ATOMIC_FENCE_CAPABILITIES, cl_device_atomic_capabilities) \
1436  F(cl_device_info, CL_DEVICE_NON_UNIFORM_WORK_GROUP_SUPPORT, cl_bool) \
1437  F(cl_device_info, CL_DEVICE_OPENCL_C_ALL_VERSIONS, cl::vector<cl_name_version>) \
1438  F(cl_device_info, CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1439  F(cl_device_info, CL_DEVICE_WORK_GROUP_COLLECTIVE_FUNCTIONS_SUPPORT, cl_bool) \
1440  F(cl_device_info, CL_DEVICE_GENERIC_ADDRESS_SPACE_SUPPORT, cl_bool) \
1441  F(cl_device_info, CL_DEVICE_OPENCL_C_FEATURES, cl::vector<cl_name_version>) \
1442  F(cl_device_info, CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES, cl_device_device_enqueue_capabilities) \
1443  F(cl_device_info, CL_DEVICE_PIPE_SUPPORT, cl_bool) \
1444  F(cl_device_info, CL_DEVICE_LATEST_CONFORMANCE_VERSION_PASSED, string) \
1445  \
1446  F(cl_command_queue_info, CL_QUEUE_PROPERTIES_ARRAY, cl::vector<cl_queue_properties>) \
1447  F(cl_mem_info, CL_MEM_PROPERTIES, cl::vector<cl_mem_properties>) \
1448  F(cl_pipe_info, CL_PIPE_PROPERTIES, cl::vector<cl_pipe_properties>) \
1449  F(cl_sampler_info, CL_SAMPLER_PROPERTIES, cl::vector<cl_sampler_properties>)
1450 
1451 template <typename enum_type, cl_int Name>
1452 struct param_traits {};
1453 
1454 #define CL_HPP_DECLARE_PARAM_TRAITS_(token, param_name, T) \
1455 struct token; \
1456 template<> \
1457 struct param_traits<detail:: token,param_name> \
1458 { \
1459  enum { value = param_name }; \
1460  typedef T param_type; \
1461 };
1462 
1463 CL_HPP_PARAM_NAME_INFO_1_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1464 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
1465 CL_HPP_PARAM_NAME_INFO_1_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1466 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
1467 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1468 CL_HPP_PARAM_NAME_INFO_1_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1469 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1470 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
1471 CL_HPP_PARAM_NAME_INFO_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1472 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
1473 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
1474 CL_HPP_PARAM_NAME_INFO_2_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1475 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
1476 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
1477 CL_HPP_PARAM_NAME_INFO_2_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1478 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
1479 #if CL_HPP_TARGET_OPENCL_VERSION >= 300
1480 CL_HPP_PARAM_NAME_INFO_3_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1481 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
1482 
1483 #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1484 CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1485 #endif // #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1486 
1487 #if defined(CL_HPP_USE_IL_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1488 CL_HPP_PARAM_NAME_INFO_IL_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1489 #endif // #if defined(CL_HPP_USE_IL_KHR)
1490 
1491 
1492 // Flags deprecated in OpenCL 2.0
1493 #define CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(F) \
1494  F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties)
1495 
1496 #define CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(F) \
1497  F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool)
1498 
1499 #define CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(F) \
1500  F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer)
1501 
1502 // Include deprecated query flags based on versions
1503 // Only include deprecated 1.0 flags if 2.0 not active as there is an enum clash
1504 #if CL_HPP_TARGET_OPENCL_VERSION > 100 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 && CL_HPP_TARGET_OPENCL_VERSION < 200
1505 CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1506 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 110
1507 #if CL_HPP_TARGET_OPENCL_VERSION > 110 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1508 CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1509 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1510 #if CL_HPP_TARGET_OPENCL_VERSION > 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1511 CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1512 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
1513 
1514 #if defined(CL_HPP_USE_CL_DEVICE_FISSION)
1515 CL_HPP_PARAM_NAME_DEVICE_FISSION_(CL_HPP_DECLARE_PARAM_TRAITS_);
1516 #endif // CL_HPP_USE_CL_DEVICE_FISSION
1517 
1518 #if defined(cl_khr_extended_versioning)
1519 #if CL_HPP_TARGET_OPENCL_VERSION < 300
1520 CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_CL3_SHARED_(CL_HPP_DECLARE_PARAM_TRAITS_)
1521 #endif // CL_HPP_TARGET_OPENCL_VERSION < 300
1522 CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_KHRONLY_(CL_HPP_DECLARE_PARAM_TRAITS_)
1523 #endif // cl_khr_extended_versioning
1524 
1525 #if defined(cl_khr_device_uuid)
1526 using uuid_array = array<cl_uchar, CL_UUID_SIZE_KHR>;
1527 using luid_array = array<cl_uchar, CL_LUID_SIZE_KHR>;
1528 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_UUID_KHR, uuid_array)
1529 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DRIVER_UUID_KHR, uuid_array)
1530 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LUID_VALID_KHR, cl_bool)
1531 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LUID_KHR, luid_array)
1532 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_NODE_MASK_KHR, cl_uint)
1533 #endif
1534 
1535 #if defined(cl_khr_pci_bus_info)
1536 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PCI_BUS_INFO_KHR, cl_device_pci_bus_info_khr)
1537 #endif
1538 
1539 #if defined(cl_khr_integer_dot_product)
1540 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGER_DOT_PRODUCT_CAPABILITIES_KHR, cl_device_integer_dot_product_capabilities_khr)
1541 #if defined(CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_8BIT_KHR)
1542 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_8BIT_KHR, cl_device_integer_dot_product_acceleration_properties_khr)
1543 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_4x8BIT_PACKED_KHR, cl_device_integer_dot_product_acceleration_properties_khr)
1544 #endif // defined(CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_8BIT_KHR)
1545 #endif // defined(cl_khr_integer_dot_product)
1546 
1547 #ifdef CL_PLATFORM_ICD_SUFFIX_KHR
1548 CL_HPP_DECLARE_PARAM_TRAITS_(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, string)
1549 #endif
1550 
1551 #ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
1552 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong)
1553 #endif
1554 #ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
1555 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, vector<size_type>)
1556 #endif
1557 #ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
1558 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint)
1559 #endif
1560 #ifdef CL_DEVICE_SIMD_WIDTH_AMD
1561 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint)
1562 #endif
1563 #ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD
1564 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint)
1565 #endif
1566 #ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD
1567 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint)
1568 #endif
1569 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
1570 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint)
1571 #endif
1572 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
1573 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint)
1574 #endif
1575 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
1576 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint)
1577 #endif
1578 #ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
1579 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint)
1580 #endif
1581 #ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
1582 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint)
1583 #endif
1584 #ifdef CL_DEVICE_BOARD_NAME_AMD
1585 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_BOARD_NAME_AMD, string)
1586 #endif
1587 
1588 #ifdef CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM
1589 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM, cl_ulong)
1590 #endif
1591 #ifdef CL_DEVICE_JOB_SLOTS_ARM
1592 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_JOB_SLOTS_ARM, cl_uint)
1593 #endif
1594 #ifdef CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM
1595 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM, cl_bitfield)
1596 #endif
1597 #ifdef CL_DEVICE_SUPPORTED_REGISTER_ALLOCATIONS_ARM
1598 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SUPPORTED_REGISTER_ALLOCATIONS_ARM, vector<cl_uint>)
1599 #endif
1600 #ifdef CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_ARM
1601 CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_ARM, cl_uint)
1602 #endif
1603 #ifdef CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM
1604 CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM, cl_int)
1605 #endif
1606 
1607 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
1608 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint)
1609 #endif
1610 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV
1611 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint)
1612 #endif
1613 #ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV
1614 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint)
1615 #endif
1616 #ifdef CL_DEVICE_WARP_SIZE_NV
1617 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint)
1618 #endif
1619 #ifdef CL_DEVICE_GPU_OVERLAP_NV
1620 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool)
1621 #endif
1622 #ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV
1623 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool)
1624 #endif
1625 #ifdef CL_DEVICE_INTEGRATED_MEMORY_NV
1626 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool)
1627 #endif
1628 
1629 // Convenience functions
1630 
1631 template <typename Func, typename T>
1632 inline cl_int
1633 getInfo(Func f, cl_uint name, T* param)
1634 {
1635  return getInfoHelper(f, name, param, 0);
1636 }
1637 
1638 template <typename Func, typename Arg0>
1640 {
1641  Func f_; const Arg0& arg0_;
1642  cl_int operator ()(
1643  cl_uint param, size_type size, void* value, size_type* size_ret)
1644  { return f_(arg0_, param, size, value, size_ret); }
1645 };
1646 
1647 template <typename Func, typename Arg0, typename Arg1>
1649 {
1650  Func f_; const Arg0& arg0_; const Arg1& arg1_;
1651  cl_int operator ()(
1652  cl_uint param, size_type size, void* value, size_type* size_ret)
1653  { return f_(arg0_, arg1_, param, size, value, size_ret); }
1654 };
1655 
1656 template <typename Func, typename Arg0, typename T>
1657 inline cl_int
1658 getInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
1659 {
1660  GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
1661  return getInfoHelper(f0, name, param, 0);
1662 }
1663 
1664 template <typename Func, typename Arg0, typename Arg1, typename T>
1665 inline cl_int
1666 getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
1667 {
1668  GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
1669  return getInfoHelper(f0, name, param, 0);
1670 }
1671 
1672 
1673 template<typename T>
1675 { };
1676 
1677 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1681 template <>
1682 struct ReferenceHandler<cl_device_id>
1683 {
1693  static cl_int retain(cl_device_id device)
1694  { return ::clRetainDevice(device); }
1704  static cl_int release(cl_device_id device)
1705  { return ::clReleaseDevice(device); }
1706 };
1707 #else // CL_HPP_TARGET_OPENCL_VERSION >= 120
1711 template <>
1712 struct ReferenceHandler<cl_device_id>
1713 {
1714  // cl_device_id does not have retain().
1715  static cl_int retain(cl_device_id)
1716  { return CL_SUCCESS; }
1717  // cl_device_id does not have release().
1718  static cl_int release(cl_device_id)
1719  { return CL_SUCCESS; }
1720 };
1721 #endif // ! (CL_HPP_TARGET_OPENCL_VERSION >= 120)
1722 
1723 template <>
1724 struct ReferenceHandler<cl_platform_id>
1725 {
1726  // cl_platform_id does not have retain().
1727  static cl_int retain(cl_platform_id)
1728  { return CL_SUCCESS; }
1729  // cl_platform_id does not have release().
1730  static cl_int release(cl_platform_id)
1731  { return CL_SUCCESS; }
1732 };
1733 
1734 template <>
1735 struct ReferenceHandler<cl_context>
1736 {
1737  static cl_int retain(cl_context context)
1738  { return ::clRetainContext(context); }
1739  static cl_int release(cl_context context)
1740  { return ::clReleaseContext(context); }
1741 };
1742 
1743 template <>
1744 struct ReferenceHandler<cl_command_queue>
1745 {
1746  static cl_int retain(cl_command_queue queue)
1747  { return ::clRetainCommandQueue(queue); }
1748  static cl_int release(cl_command_queue queue)
1749  { return ::clReleaseCommandQueue(queue); }
1750 };
1751 
1752 template <>
1753 struct ReferenceHandler<cl_mem>
1754 {
1755  static cl_int retain(cl_mem memory)
1756  { return ::clRetainMemObject(memory); }
1757  static cl_int release(cl_mem memory)
1758  { return ::clReleaseMemObject(memory); }
1759 };
1760 
1761 template <>
1762 struct ReferenceHandler<cl_sampler>
1763 {
1764  static cl_int retain(cl_sampler sampler)
1765  { return ::clRetainSampler(sampler); }
1766  static cl_int release(cl_sampler sampler)
1767  { return ::clReleaseSampler(sampler); }
1768 };
1769 
1770 template <>
1771 struct ReferenceHandler<cl_program>
1772 {
1773  static cl_int retain(cl_program program)
1774  { return ::clRetainProgram(program); }
1775  static cl_int release(cl_program program)
1776  { return ::clReleaseProgram(program); }
1777 };
1778 
1779 template <>
1780 struct ReferenceHandler<cl_kernel>
1781 {
1782  static cl_int retain(cl_kernel kernel)
1783  { return ::clRetainKernel(kernel); }
1784  static cl_int release(cl_kernel kernel)
1785  { return ::clReleaseKernel(kernel); }
1786 };
1787 
1788 template <>
1789 struct ReferenceHandler<cl_event>
1790 {
1791  static cl_int retain(cl_event event)
1792  { return ::clRetainEvent(event); }
1793  static cl_int release(cl_event event)
1794  { return ::clReleaseEvent(event); }
1795 };
1796 
1797 
1798 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1799 // Extracts version number with major in the upper 16 bits, minor in the lower 16
1800 static cl_uint getVersion(const vector<char> &versionInfo)
1801 {
1802  int highVersion = 0;
1803  int lowVersion = 0;
1804  int index = 7;
1805  while(versionInfo[index] != '.' ) {
1806  highVersion *= 10;
1807  highVersion += versionInfo[index]-'0';
1808  ++index;
1809  }
1810  ++index;
1811  while(versionInfo[index] != ' ' && versionInfo[index] != '\0') {
1812  lowVersion *= 10;
1813  lowVersion += versionInfo[index]-'0';
1814  ++index;
1815  }
1816  return (highVersion << 16) | lowVersion;
1817 }
1818 
1819 static cl_uint getPlatformVersion(cl_platform_id platform)
1820 {
1821  size_type size = 0;
1822  clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size);
1823 
1824  vector<char> versionInfo(size);
1825  clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, versionInfo.data(), &size);
1826  return getVersion(versionInfo);
1827 }
1828 
1829 static cl_uint getDevicePlatformVersion(cl_device_id device)
1830 {
1831  cl_platform_id platform;
1832  clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL);
1833  return getPlatformVersion(platform);
1834 }
1835 
1836 static cl_uint getContextPlatformVersion(cl_context context)
1837 {
1838  // The platform cannot be queried directly, so we first have to grab a
1839  // device and obtain its context
1840  size_type size = 0;
1841  clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size);
1842  if (size == 0)
1843  return 0;
1844  vector<cl_device_id> devices(size/sizeof(cl_device_id));
1845  clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices.data(), NULL);
1846  return getDevicePlatformVersion(devices[0]);
1847 }
1848 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1849 
1850 template <typename T>
1851 class Wrapper
1852 {
1853 public:
1854  typedef T cl_type;
1855 
1856 protected:
1857  cl_type object_;
1858 
1859 public:
1860  Wrapper() : object_(NULL) { }
1861 
1862  Wrapper(const cl_type &obj, bool retainObject) : object_(obj)
1863  {
1864  if (retainObject) {
1865  detail::errHandler(retain(), __RETAIN_ERR);
1866  }
1867  }
1868 
1869  ~Wrapper()
1870  {
1871  if (object_ != NULL) { release(); }
1872  }
1873 
1874  Wrapper(const Wrapper<cl_type>& rhs)
1875  {
1876  object_ = rhs.object_;
1877  detail::errHandler(retain(), __RETAIN_ERR);
1878  }
1879 
1880  Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT_
1881  {
1882  object_ = rhs.object_;
1883  rhs.object_ = NULL;
1884  }
1885 
1886  Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
1887  {
1888  if (this != &rhs) {
1889  detail::errHandler(release(), __RELEASE_ERR);
1890  object_ = rhs.object_;
1891  detail::errHandler(retain(), __RETAIN_ERR);
1892  }
1893  return *this;
1894  }
1895 
1896  Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
1897  {
1898  if (this != &rhs) {
1899  detail::errHandler(release(), __RELEASE_ERR);
1900  object_ = rhs.object_;
1901  rhs.object_ = NULL;
1902  }
1903  return *this;
1904  }
1905 
1906  Wrapper<cl_type>& operator = (const cl_type &rhs)
1907  {
1908  detail::errHandler(release(), __RELEASE_ERR);
1909  object_ = rhs;
1910  return *this;
1911  }
1912 
1913  const cl_type& operator ()() const { return object_; }
1914 
1915  cl_type& operator ()() { return object_; }
1916 
1917  cl_type get() const { return object_; }
1918 
1919 protected:
1920  template<typename Func, typename U>
1921  friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
1922 
1923  cl_int retain() const
1924  {
1925  if (object_ != nullptr) {
1926  return ReferenceHandler<cl_type>::retain(object_);
1927  }
1928  else {
1929  return CL_SUCCESS;
1930  }
1931  }
1932 
1933  cl_int release() const
1934  {
1935  if (object_ != nullptr) {
1936  return ReferenceHandler<cl_type>::release(object_);
1937  }
1938  else {
1939  return CL_SUCCESS;
1940  }
1941  }
1942 };
1943 
1944 template <>
1945 class Wrapper<cl_device_id>
1946 {
1947 public:
1948  typedef cl_device_id cl_type;
1949 
1950 protected:
1951  cl_type object_;
1952  bool referenceCountable_;
1953 
1954  static bool isReferenceCountable(cl_device_id device)
1955  {
1956  bool retVal = false;
1957 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1958 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
1959  if (device != NULL) {
1960  int version = getDevicePlatformVersion(device);
1961  if(version > ((1 << 16) + 1)) {
1962  retVal = true;
1963  }
1964  }
1965 #else // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1966  retVal = true;
1967 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1968 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1969  (void)device;
1970  return retVal;
1971  }
1972 
1973 public:
1974  Wrapper() : object_(NULL), referenceCountable_(false)
1975  {
1976  }
1977 
1978  Wrapper(const cl_type &obj, bool retainObject) :
1979  object_(obj),
1980  referenceCountable_(false)
1981  {
1982  referenceCountable_ = isReferenceCountable(obj);
1983 
1984  if (retainObject) {
1985  detail::errHandler(retain(), __RETAIN_ERR);
1986  }
1987  }
1988 
1989  ~Wrapper()
1990  {
1991  release();
1992  }
1993 
1994  Wrapper(const Wrapper<cl_type>& rhs)
1995  {
1996  object_ = rhs.object_;
1997  referenceCountable_ = isReferenceCountable(object_);
1998  detail::errHandler(retain(), __RETAIN_ERR);
1999  }
2000 
2001  Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT_
2002  {
2003  object_ = rhs.object_;
2004  referenceCountable_ = rhs.referenceCountable_;
2005  rhs.object_ = NULL;
2006  rhs.referenceCountable_ = false;
2007  }
2008 
2009  Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
2010  {
2011  if (this != &rhs) {
2012  detail::errHandler(release(), __RELEASE_ERR);
2013  object_ = rhs.object_;
2014  referenceCountable_ = rhs.referenceCountable_;
2015  detail::errHandler(retain(), __RETAIN_ERR);
2016  }
2017  return *this;
2018  }
2019 
2020  Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
2021  {
2022  if (this != &rhs) {
2023  detail::errHandler(release(), __RELEASE_ERR);
2024  object_ = rhs.object_;
2025  referenceCountable_ = rhs.referenceCountable_;
2026  rhs.object_ = NULL;
2027  rhs.referenceCountable_ = false;
2028  }
2029  return *this;
2030  }
2031 
2032  Wrapper<cl_type>& operator = (const cl_type &rhs)
2033  {
2034  detail::errHandler(release(), __RELEASE_ERR);
2035  object_ = rhs;
2036  referenceCountable_ = isReferenceCountable(object_);
2037  return *this;
2038  }
2039 
2040  const cl_type& operator ()() const { return object_; }
2041 
2042  cl_type& operator ()() { return object_; }
2043 
2044  cl_type get() const { return object_; }
2045 
2046 protected:
2047  template<typename Func, typename U>
2048  friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
2049 
2050  template<typename Func, typename U>
2051  friend inline cl_int getInfoHelper(Func, cl_uint, vector<U>*, int, typename U::cl_type);
2052 
2053  cl_int retain() const
2054  {
2055  if( object_ != nullptr && referenceCountable_ ) {
2056  return ReferenceHandler<cl_type>::retain(object_);
2057  }
2058  else {
2059  return CL_SUCCESS;
2060  }
2061  }
2062 
2063  cl_int release() const
2064  {
2065  if (object_ != nullptr && referenceCountable_) {
2066  return ReferenceHandler<cl_type>::release(object_);
2067  }
2068  else {
2069  return CL_SUCCESS;
2070  }
2071  }
2072 };
2073 
2074 template <typename T>
2075 inline bool operator==(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
2076 {
2077  return lhs() == rhs();
2078 }
2079 
2080 template <typename T>
2081 inline bool operator!=(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
2082 {
2083  return !operator==(lhs, rhs);
2084 }
2085 
2086 } // namespace detail
2088 
2089 
2090 
2091 
2092 
2098 struct ImageFormat : public cl_image_format
2099 {
2102 
2104  ImageFormat(cl_channel_order order, cl_channel_type type)
2105  {
2106  image_channel_order = order;
2107  image_channel_data_type = type;
2108  }
2109 
2111  ImageFormat(const ImageFormat &other) { *this = other; }
2112 
2115  {
2116  if (this != &rhs) {
2117  this->image_channel_data_type = rhs.image_channel_data_type;
2118  this->image_channel_order = rhs.image_channel_order;
2119  }
2120  return *this;
2121  }
2122 };
2123 
2131 class Device : public detail::Wrapper<cl_device_id>
2132 {
2133 private:
2134  static std::once_flag default_initialized_;
2135  static Device default_;
2136  static cl_int default_error_;
2137 
2143  static void makeDefault();
2144 
2150  static void makeDefaultProvided(const Device &p) {
2151  default_ = p;
2152  }
2153 
2154 public:
2155 #ifdef CL_HPP_UNIT_TEST_ENABLE
2162  static void unitTestClearDefault() {
2163  default_ = Device();
2164  }
2165 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2166 
2168  Device() : detail::Wrapper<cl_type>() { }
2169 
2174  explicit Device(const cl_device_id &device, bool retainObject = false) :
2175  detail::Wrapper<cl_type>(device, retainObject) { }
2176 
2182  cl_int *errResult = NULL)
2183  {
2184  std::call_once(default_initialized_, makeDefault);
2185  detail::errHandler(default_error_);
2186  if (errResult != NULL) {
2187  *errResult = default_error_;
2188  }
2189  return default_;
2190  }
2191 
2199  static Device setDefault(const Device &default_device)
2200  {
2201  std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_device));
2202  detail::errHandler(default_error_);
2203  return default_;
2204  }
2205 
2210  Device& operator = (const cl_device_id& rhs)
2211  {
2213  return *this;
2214  }
2215 
2219  Device(const Device& dev) : detail::Wrapper<cl_type>(dev) {}
2220 
2225  {
2227  return *this;
2228  }
2229 
2233  Device(Device&& dev) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(dev)) {}
2234 
2239  {
2240  detail::Wrapper<cl_type>::operator=(std::move(dev));
2241  return *this;
2242  }
2243 
2245  template <typename T>
2246  cl_int getInfo(cl_device_info name, T* param) const
2247  {
2248  return detail::errHandler(
2249  detail::getInfo(&::clGetDeviceInfo, object_, name, param),
2250  __GET_DEVICE_INFO_ERR);
2251  }
2252 
2254  template <cl_device_info name> typename
2256  getInfo(cl_int* err = NULL) const
2257  {
2258  typename detail::param_traits<
2259  detail::cl_device_info, name>::param_type param;
2260  cl_int result = getInfo(name, &param);
2261  if (err != NULL) {
2262  *err = result;
2263  }
2264  return param;
2265  }
2266 
2267 
2268 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2275  cl_ulong getHostTimer(cl_int *error = nullptr)
2276  {
2277  cl_ulong retVal = 0;
2278  cl_int err =
2279  clGetHostTimer(this->get(), &retVal);
2280  detail::errHandler(
2281  err,
2282  __GET_HOST_TIMER_ERR);
2283  if (error) {
2284  *error = err;
2285  }
2286  return retVal;
2287  }
2288 
2299  std::pair<cl_ulong, cl_ulong> getDeviceAndHostTimer(cl_int *error = nullptr)
2300  {
2301  std::pair<cl_ulong, cl_ulong> retVal;
2302  cl_int err =
2303  clGetDeviceAndHostTimer(this->get(), &(retVal.first), &(retVal.second));
2304  detail::errHandler(
2305  err,
2306  __GET_DEVICE_AND_HOST_TIMER_ERR);
2307  if (error) {
2308  *error = err;
2309  }
2310  return retVal;
2311  }
2312 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2313 
2317 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
2320  const cl_device_partition_property * properties,
2321  vector<Device>* devices)
2322  {
2323  cl_uint n = 0;
2324  cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n);
2325  if (err != CL_SUCCESS) {
2326  return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2327  }
2328 
2329  vector<cl_device_id> ids(n);
2330  err = clCreateSubDevices(object_, properties, n, ids.data(), NULL);
2331  if (err != CL_SUCCESS) {
2332  return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2333  }
2334 
2335  // Cannot trivially assign because we need to capture intermediates
2336  // with safe construction
2337  if (devices) {
2338  devices->resize(ids.size());
2339 
2340  // Assign to param, constructing with retain behaviour
2341  // to correctly capture each underlying CL object
2342  for (size_type i = 0; i < ids.size(); i++) {
2343  // We do not need to retain because this device is being created
2344  // by the runtime
2345  (*devices)[i] = Device(ids[i], false);
2346  }
2347  }
2348 
2349  return CL_SUCCESS;
2350  }
2351 #elif defined(CL_HPP_USE_CL_DEVICE_FISSION)
2352 
2356  cl_int createSubDevices(
2357  const cl_device_partition_property_ext * properties,
2358  vector<Device>* devices)
2359  {
2360  typedef CL_API_ENTRY cl_int
2361  ( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
2362  cl_device_id /*in_device*/,
2363  const cl_device_partition_property_ext * /* properties */,
2364  cl_uint /*num_entries*/,
2365  cl_device_id * /*out_devices*/,
2366  cl_uint * /*num_devices*/ ) CL_API_SUFFIX__VERSION_1_1;
2367 
2368  static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
2369  CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSubDevicesEXT);
2370 
2371  cl_uint n = 0;
2372  cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
2373  if (err != CL_SUCCESS) {
2374  return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2375  }
2376 
2377  vector<cl_device_id> ids(n);
2378  err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids.data(), NULL);
2379  if (err != CL_SUCCESS) {
2380  return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2381  }
2382  // Cannot trivially assign because we need to capture intermediates
2383  // with safe construction
2384  if (devices) {
2385  devices->resize(ids.size());
2386 
2387  // Assign to param, constructing with retain behaviour
2388  // to correctly capture each underlying CL object
2389  for (size_type i = 0; i < ids.size(); i++) {
2390  // We do not need to retain because this device is being created
2391  // by the runtime
2392  (*devices)[i] = Device(ids[i], false);
2393  }
2394  }
2395  return CL_SUCCESS;
2396  }
2397 #endif // defined(CL_HPP_USE_CL_DEVICE_FISSION)
2398 };
2399 
2400 using BuildLogType = vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, CL_PROGRAM_BUILD_LOG>::param_type>>;
2401 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2405 class BuildError : public Error
2406 {
2407 private:
2408  BuildLogType buildLogs;
2409 public:
2410  BuildError(cl_int err, const char * errStr, const BuildLogType &vec) : Error(err, errStr), buildLogs(vec)
2411  {
2412  }
2413 
2414  BuildLogType getBuildLog() const
2415  {
2416  return buildLogs;
2417  }
2418 };
2419 namespace detail {
2420  static inline cl_int buildErrHandler(
2421  cl_int err,
2422  const char * errStr,
2423  const BuildLogType &buildLogs)
2424  {
2425  if (err != CL_SUCCESS) {
2426  throw BuildError(err, errStr, buildLogs);
2427  }
2428  return err;
2429  }
2430 } // namespace detail
2431 
2432 #else
2433 namespace detail {
2434  static inline cl_int buildErrHandler(
2435  cl_int err,
2436  const char * errStr,
2437  const BuildLogType &buildLogs)
2438  {
2439  (void)buildLogs; // suppress unused variable warning
2440  (void)errStr;
2441  return err;
2442  }
2443 } // namespace detail
2444 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2445 
2446 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Device::default_initialized_;
2447 CL_HPP_DEFINE_STATIC_MEMBER_ Device Device::default_;
2448 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Device::default_error_ = CL_SUCCESS;
2449 
2457 class Platform : public detail::Wrapper<cl_platform_id>
2458 {
2459 private:
2460  static std::once_flag default_initialized_;
2461  static Platform default_;
2462  static cl_int default_error_;
2463 
2469  static void makeDefault() {
2470  /* Throwing an exception from a call_once invocation does not do
2471  * what we wish, so we catch it and save the error.
2472  */
2473 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2474  try
2475 #endif
2476  {
2477  // If default wasn't passed ,generate one
2478  // Otherwise set it
2479  cl_uint n = 0;
2480 
2481  cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2482  if (err != CL_SUCCESS) {
2483  default_error_ = err;
2484  return;
2485  }
2486  if (n == 0) {
2487  default_error_ = CL_INVALID_PLATFORM;
2488  return;
2489  }
2490 
2491  vector<cl_platform_id> ids(n);
2492  err = ::clGetPlatformIDs(n, ids.data(), NULL);
2493  if (err != CL_SUCCESS) {
2494  default_error_ = err;
2495  return;
2496  }
2497 
2498  default_ = Platform(ids[0]);
2499  }
2500 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2501  catch (cl::Error &e) {
2502  default_error_ = e.err();
2503  }
2504 #endif
2505  }
2506 
2512  static void makeDefaultProvided(const Platform &p) {
2513  default_ = p;
2514  }
2515 
2516 public:
2517 #ifdef CL_HPP_UNIT_TEST_ENABLE
2524  static void unitTestClearDefault() {
2525  default_ = Platform();
2526  }
2527 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2528 
2530  Platform() : detail::Wrapper<cl_type>() { }
2531 
2539  explicit Platform(const cl_platform_id &platform, bool retainObject = false) :
2540  detail::Wrapper<cl_type>(platform, retainObject) { }
2541 
2546  Platform& operator = (const cl_platform_id& rhs)
2547  {
2549  return *this;
2550  }
2551 
2552  static Platform getDefault(
2553  cl_int *errResult = NULL)
2554  {
2555  std::call_once(default_initialized_, makeDefault);
2556  detail::errHandler(default_error_);
2557  if (errResult != NULL) {
2558  *errResult = default_error_;
2559  }
2560  return default_;
2561  }
2562 
2570  static Platform setDefault(const Platform &default_platform)
2571  {
2572  std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_platform));
2573  detail::errHandler(default_error_);
2574  return default_;
2575  }
2576 
2578  template <typename T>
2579  cl_int getInfo(cl_platform_info name, T* param) const
2580  {
2581  return detail::errHandler(
2582  detail::getInfo(&::clGetPlatformInfo, object_, name, param),
2583  __GET_PLATFORM_INFO_ERR);
2584  }
2585 
2587  template <cl_platform_info name> typename
2589  getInfo(cl_int* err = NULL) const
2590  {
2591  typename detail::param_traits<
2592  detail::cl_platform_info, name>::param_type param;
2593  cl_int result = getInfo(name, &param);
2594  if (err != NULL) {
2595  *err = result;
2596  }
2597  return param;
2598  }
2599 
2604  cl_int getDevices(
2605  cl_device_type type,
2606  vector<Device>* devices) const
2607  {
2608  cl_uint n = 0;
2609  if( devices == NULL ) {
2610  return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2611  }
2612  cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
2613  if (err != CL_SUCCESS && err != CL_DEVICE_NOT_FOUND) {
2614  return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2615  }
2616 
2617  vector<cl_device_id> ids(n);
2618  if (n>0) {
2619  err = ::clGetDeviceIDs(object_, type, n, ids.data(), NULL);
2620  if (err != CL_SUCCESS) {
2621  return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2622  }
2623  }
2624 
2625  // Cannot trivially assign because we need to capture intermediates
2626  // with safe construction
2627  // We must retain things we obtain from the API to avoid releasing
2628  // API-owned objects.
2629  if (devices) {
2630  devices->resize(ids.size());
2631 
2632  // Assign to param, constructing with retain behaviour
2633  // to correctly capture each underlying CL object
2634  for (size_type i = 0; i < ids.size(); i++) {
2635  (*devices)[i] = Device(ids[i], true);
2636  }
2637  }
2638  return CL_SUCCESS;
2639  }
2640 
2641 #if defined(CL_HPP_USE_DX_INTEROP)
2665  cl_int getDevices(
2666  cl_d3d10_device_source_khr d3d_device_source,
2667  void * d3d_object,
2668  cl_d3d10_device_set_khr d3d_device_set,
2669  vector<Device>* devices) const
2670  {
2671  typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
2672  cl_platform_id platform,
2673  cl_d3d10_device_source_khr d3d_device_source,
2674  void * d3d_object,
2675  cl_d3d10_device_set_khr d3d_device_set,
2676  cl_uint num_entries,
2677  cl_device_id * devices,
2678  cl_uint* num_devices);
2679 
2680  if( devices == NULL ) {
2681  return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2682  }
2683 
2684  static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
2685  CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(object_, clGetDeviceIDsFromD3D10KHR);
2686 
2687  cl_uint n = 0;
2688  cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
2689  object_,
2690  d3d_device_source,
2691  d3d_object,
2692  d3d_device_set,
2693  0,
2694  NULL,
2695  &n);
2696  if (err != CL_SUCCESS) {
2697  return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2698  }
2699 
2700  vector<cl_device_id> ids(n);
2701  err = pfn_clGetDeviceIDsFromD3D10KHR(
2702  object_,
2703  d3d_device_source,
2704  d3d_object,
2705  d3d_device_set,
2706  n,
2707  ids.data(),
2708  NULL);
2709  if (err != CL_SUCCESS) {
2710  return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2711  }
2712 
2713  // Cannot trivially assign because we need to capture intermediates
2714  // with safe construction
2715  // We must retain things we obtain from the API to avoid releasing
2716  // API-owned objects.
2717  if (devices) {
2718  devices->resize(ids.size());
2719 
2720  // Assign to param, constructing with retain behaviour
2721  // to correctly capture each underlying CL object
2722  for (size_type i = 0; i < ids.size(); i++) {
2723  (*devices)[i] = Device(ids[i], true);
2724  }
2725  }
2726  return CL_SUCCESS;
2727  }
2728 #endif
2729 
2734  static cl_int get(
2735  vector<Platform>* platforms)
2736  {
2737  cl_uint n = 0;
2738 
2739  if( platforms == NULL ) {
2740  return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
2741  }
2742 
2743  cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2744  if (err != CL_SUCCESS) {
2745  return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2746  }
2747 
2748  vector<cl_platform_id> ids(n);
2749  err = ::clGetPlatformIDs(n, ids.data(), NULL);
2750  if (err != CL_SUCCESS) {
2751  return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2752  }
2753 
2754  if (platforms) {
2755  platforms->resize(ids.size());
2756 
2757  // Platforms don't reference count
2758  for (size_type i = 0; i < ids.size(); i++) {
2759  (*platforms)[i] = Platform(ids[i]);
2760  }
2761  }
2762  return CL_SUCCESS;
2763  }
2764 
2769  static cl_int get(
2770  Platform * platform)
2771  {
2772  cl_int err;
2773  Platform default_platform = Platform::getDefault(&err);
2774  if (platform) {
2775  *platform = default_platform;
2776  }
2777  return err;
2778  }
2779 
2788  static Platform get(
2789  cl_int * errResult = NULL)
2790  {
2791  cl_int err;
2792  Platform default_platform = Platform::getDefault(&err);
2793  if (errResult) {
2794  *errResult = err;
2795  }
2796  return default_platform;
2797  }
2798 
2799 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
2801  cl_int
2803  {
2804  return ::clUnloadPlatformCompiler(object_);
2805  }
2806 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
2807 }; // class Platform
2808 
2809 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Platform::default_initialized_;
2810 CL_HPP_DEFINE_STATIC_MEMBER_ Platform Platform::default_;
2811 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Platform::default_error_ = CL_SUCCESS;
2812 
2813 
2817 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2822 inline CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int
2823 UnloadCompiler() CL_API_SUFFIX__VERSION_1_1_DEPRECATED;
2824 inline cl_int
2826 {
2827  return ::clUnloadCompiler();
2828 }
2829 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2830 
2839 class Context
2840  : public detail::Wrapper<cl_context>
2841 {
2842 private:
2843  static std::once_flag default_initialized_;
2844  static Context default_;
2845  static cl_int default_error_;
2846 
2852  static void makeDefault() {
2853  /* Throwing an exception from a call_once invocation does not do
2854  * what we wish, so we catch it and save the error.
2855  */
2856 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2857  try
2858 #endif
2859  {
2860 #if !defined(__APPLE__) && !defined(__MACOS)
2861  const Platform &p = Platform::getDefault();
2862  cl_platform_id defaultPlatform = p();
2863  cl_context_properties properties[3] = {
2864  CL_CONTEXT_PLATFORM, (cl_context_properties)defaultPlatform, 0
2865  };
2866 #else // #if !defined(__APPLE__) && !defined(__MACOS)
2867  cl_context_properties *properties = nullptr;
2868 #endif // #if !defined(__APPLE__) && !defined(__MACOS)
2869 
2870  default_ = Context(
2871  CL_DEVICE_TYPE_DEFAULT,
2872  properties,
2873  NULL,
2874  NULL,
2875  &default_error_);
2876  }
2877 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2878  catch (cl::Error &e) {
2879  default_error_ = e.err();
2880  }
2881 #endif
2882  }
2883 
2884 
2890  static void makeDefaultProvided(const Context &c) {
2891  default_ = c;
2892  }
2893 
2894 public:
2895 #ifdef CL_HPP_UNIT_TEST_ENABLE
2902  static void unitTestClearDefault() {
2903  default_ = Context();
2904  }
2905 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2906 
2912  const vector<Device>& devices,
2913  const cl_context_properties* properties = NULL,
2914  void (CL_CALLBACK * notifyFptr)(
2915  const char *,
2916  const void *,
2917  size_type,
2918  void *) = NULL,
2919  void* data = NULL,
2920  cl_int* err = NULL)
2921  {
2922  cl_int error;
2923 
2924  size_type numDevices = devices.size();
2925  vector<cl_device_id> deviceIDs(numDevices);
2926 
2927  for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
2928  deviceIDs[deviceIndex] = (devices[deviceIndex])();
2929  }
2930 
2931  object_ = ::clCreateContext(
2932  properties, (cl_uint) numDevices,
2933  deviceIDs.data(),
2934  notifyFptr, data, &error);
2935 
2936  detail::errHandler(error, __CREATE_CONTEXT_ERR);
2937  if (err != NULL) {
2938  *err = error;
2939  }
2940  }
2941 
2947  const Device& device,
2948  const cl_context_properties* properties = NULL,
2949  void (CL_CALLBACK * notifyFptr)(
2950  const char *,
2951  const void *,
2952  size_type,
2953  void *) = NULL,
2954  void* data = NULL,
2955  cl_int* err = NULL)
2956  {
2957  cl_int error;
2958 
2959  cl_device_id deviceID = device();
2960 
2961  object_ = ::clCreateContext(
2962  properties, 1,
2963  &deviceID,
2964  notifyFptr, data, &error);
2965 
2966  detail::errHandler(error, __CREATE_CONTEXT_ERR);
2967  if (err != NULL) {
2968  *err = error;
2969  }
2970  }
2971 
2977  cl_device_type type,
2978  const cl_context_properties* properties = NULL,
2979  void (CL_CALLBACK * notifyFptr)(
2980  const char *,
2981  const void *,
2982  size_type,
2983  void *) = NULL,
2984  void* data = NULL,
2985  cl_int* err = NULL)
2986  {
2987  cl_int error;
2988 
2989 #if !defined(__APPLE__) && !defined(__MACOS)
2990  cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 };
2991 
2992  if (properties == NULL) {
2993  // Get a valid platform ID as we cannot send in a blank one
2994  vector<Platform> platforms;
2995  error = Platform::get(&platforms);
2996  if (error != CL_SUCCESS) {
2997  detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2998  if (err != NULL) {
2999  *err = error;
3000  }
3001  return;
3002  }
3003 
3004  // Check the platforms we found for a device of our specified type
3005  cl_context_properties platform_id = 0;
3006  for (unsigned int i = 0; i < platforms.size(); i++) {
3007 
3008  vector<Device> devices;
3009 
3010 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3011  try {
3012 #endif
3013 
3014  error = platforms[i].getDevices(type, &devices);
3015 
3016 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3017  } catch (cl::Error& e) {
3018  error = e.err();
3019  }
3020  // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type
3021  // We do error checking next anyway, and can throw there if needed
3022 #endif
3023 
3024  // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND
3025  if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) {
3026  detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
3027  if (err != NULL) {
3028  *err = error;
3029  }
3030  }
3031 
3032  if (devices.size() > 0) {
3033  platform_id = (cl_context_properties)platforms[i]();
3034  break;
3035  }
3036  }
3037 
3038  if (platform_id == 0) {
3039  detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR);
3040  if (err != NULL) {
3041  *err = CL_DEVICE_NOT_FOUND;
3042  }
3043  return;
3044  }
3045 
3046  prop[1] = platform_id;
3047  properties = &prop[0];
3048  }
3049 #endif
3050  object_ = ::clCreateContextFromType(
3051  properties, type, notifyFptr, data, &error);
3052 
3053  detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
3054  if (err != NULL) {
3055  *err = error;
3056  }
3057  }
3058 
3062  Context(const Context& ctx) : detail::Wrapper<cl_type>(ctx) {}
3063 
3068  {
3070  return *this;
3071  }
3072 
3076  Context(Context&& ctx) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(ctx)) {}
3077 
3082  {
3083  detail::Wrapper<cl_type>::operator=(std::move(ctx));
3084  return *this;
3085  }
3086 
3087 
3092  static Context getDefault(cl_int * err = NULL)
3093  {
3094  std::call_once(default_initialized_, makeDefault);
3095  detail::errHandler(default_error_);
3096  if (err != NULL) {
3097  *err = default_error_;
3098  }
3099  return default_;
3100  }
3101 
3109  static Context setDefault(const Context &default_context)
3110  {
3111  std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_context));
3112  detail::errHandler(default_error_);
3113  return default_;
3114  }
3115 
3117  Context() : detail::Wrapper<cl_type>() { }
3118 
3124  explicit Context(const cl_context& context, bool retainObject = false) :
3125  detail::Wrapper<cl_type>(context, retainObject) { }
3126 
3132  Context& operator = (const cl_context& rhs)
3133  {
3135  return *this;
3136  }
3137 
3139  template <typename T>
3140  cl_int getInfo(cl_context_info name, T* param) const
3141  {
3142  return detail::errHandler(
3143  detail::getInfo(&::clGetContextInfo, object_, name, param),
3144  __GET_CONTEXT_INFO_ERR);
3145  }
3146 
3148  template <cl_context_info name> typename
3150  getInfo(cl_int* err = NULL) const
3151  {
3152  typename detail::param_traits<
3153  detail::cl_context_info, name>::param_type param;
3154  cl_int result = getInfo(name, &param);
3155  if (err != NULL) {
3156  *err = result;
3157  }
3158  return param;
3159  }
3160 
3166  cl_mem_flags flags,
3167  cl_mem_object_type type,
3168  vector<ImageFormat>* formats) const
3169  {
3170  cl_uint numEntries;
3171 
3172  if (!formats) {
3173  return CL_SUCCESS;
3174  }
3175 
3176  cl_int err = ::clGetSupportedImageFormats(
3177  object_,
3178  flags,
3179  type,
3180  0,
3181  NULL,
3182  &numEntries);
3183  if (err != CL_SUCCESS) {
3184  return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3185  }
3186 
3187  if (numEntries > 0) {
3188  vector<ImageFormat> value(numEntries);
3189  err = ::clGetSupportedImageFormats(
3190  object_,
3191  flags,
3192  type,
3193  numEntries,
3194  (cl_image_format*)value.data(),
3195  NULL);
3196  if (err != CL_SUCCESS) {
3197  return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3198  }
3199 
3200  formats->assign(begin(value), end(value));
3201  }
3202  else {
3203  // If no values are being returned, ensure an empty vector comes back
3204  formats->clear();
3205  }
3206 
3207  return CL_SUCCESS;
3208  }
3209 };
3210 
3211 inline void Device::makeDefault()
3212 {
3213  /* Throwing an exception from a call_once invocation does not do
3214  * what we wish, so we catch it and save the error.
3215  */
3216 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3217  try
3218 #endif
3219  {
3220  cl_int error = 0;
3221 
3222  Context context = Context::getDefault(&error);
3223  detail::errHandler(error, __CREATE_CONTEXT_ERR);
3224 
3225  if (error != CL_SUCCESS) {
3226  default_error_ = error;
3227  }
3228  else {
3229  default_ = context.getInfo<CL_CONTEXT_DEVICES>()[0];
3230  default_error_ = CL_SUCCESS;
3231  }
3232  }
3233 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3234  catch (cl::Error &e) {
3235  default_error_ = e.err();
3236  }
3237 #endif
3238 }
3239 
3240 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Context::default_initialized_;
3241 CL_HPP_DEFINE_STATIC_MEMBER_ Context Context::default_;
3242 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Context::default_error_ = CL_SUCCESS;
3243 
3252 class Event : public detail::Wrapper<cl_event>
3253 {
3254 public:
3256  Event() : detail::Wrapper<cl_type>() { }
3257 
3266  explicit Event(const cl_event& event, bool retainObject = false) :
3267  detail::Wrapper<cl_type>(event, retainObject) { }
3268 
3274  Event& operator = (const cl_event& rhs)
3275  {
3277  return *this;
3278  }
3279 
3281  template <typename T>
3282  cl_int getInfo(cl_event_info name, T* param) const
3283  {
3284  return detail::errHandler(
3285  detail::getInfo(&::clGetEventInfo, object_, name, param),
3286  __GET_EVENT_INFO_ERR);
3287  }
3288 
3290  template <cl_event_info name> typename
3292  getInfo(cl_int* err = NULL) const
3293  {
3294  typename detail::param_traits<
3295  detail::cl_event_info, name>::param_type param;
3296  cl_int result = getInfo(name, &param);
3297  if (err != NULL) {
3298  *err = result;
3299  }
3300  return param;
3301  }
3302 
3304  template <typename T>
3305  cl_int getProfilingInfo(cl_profiling_info name, T* param) const
3306  {
3307  return detail::errHandler(detail::getInfo(
3308  &::clGetEventProfilingInfo, object_, name, param),
3309  __GET_EVENT_PROFILE_INFO_ERR);
3310  }
3311 
3313  template <cl_profiling_info name> typename
3315  getProfilingInfo(cl_int* err = NULL) const
3316  {
3317  typename detail::param_traits<
3318  detail::cl_profiling_info, name>::param_type param;
3319  cl_int result = getProfilingInfo(name, &param);
3320  if (err != NULL) {
3321  *err = result;
3322  }
3323  return param;
3324  }
3325 
3330  cl_int wait() const
3331  {
3332  return detail::errHandler(
3333  ::clWaitForEvents(1, &object_),
3334  __WAIT_FOR_EVENTS_ERR);
3335  }
3336 
3337 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3342  cl_int setCallback(
3343  cl_int type,
3344  void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
3345  void * user_data = NULL)
3346  {
3347  return detail::errHandler(
3348  ::clSetEventCallback(
3349  object_,
3350  type,
3351  pfn_notify,
3352  user_data),
3353  __SET_EVENT_CALLBACK_ERR);
3354  }
3355 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3356 
3361  static cl_int
3362  waitForEvents(const vector<Event>& events)
3363  {
3364  return detail::errHandler(
3365  ::clWaitForEvents(
3366  (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3367  __WAIT_FOR_EVENTS_ERR);
3368  }
3369 };
3370 
3371 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3376 class UserEvent : public Event
3377 {
3378 public:
3384  const Context& context,
3385  cl_int * err = NULL)
3386  {
3387  cl_int error;
3388  object_ = ::clCreateUserEvent(
3389  context(),
3390  &error);
3391 
3392  detail::errHandler(error, __CREATE_USER_EVENT_ERR);
3393  if (err != NULL) {
3394  *err = error;
3395  }
3396  }
3397 
3399  UserEvent() : Event() { }
3400 
3405  cl_int setStatus(cl_int status)
3406  {
3407  return detail::errHandler(
3408  ::clSetUserEventStatus(object_,status),
3409  __SET_USER_EVENT_STATUS_ERR);
3410  }
3411 };
3412 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3413 
3418 inline static cl_int
3419 WaitForEvents(const vector<Event>& events)
3420 {
3421  return detail::errHandler(
3422  ::clWaitForEvents(
3423  (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3424  __WAIT_FOR_EVENTS_ERR);
3425 }
3426 
3435 class Memory : public detail::Wrapper<cl_mem>
3436 {
3437 public:
3439  Memory() : detail::Wrapper<cl_type>() { }
3440 
3452  explicit Memory(const cl_mem& memory, bool retainObject) :
3453  detail::Wrapper<cl_type>(memory, retainObject) { }
3454 
3460  Memory& operator = (const cl_mem& rhs)
3461  {
3463  return *this;
3464  }
3465 
3469  Memory(const Memory& mem) : detail::Wrapper<cl_type>(mem) {}
3470 
3475  {
3477  return *this;
3478  }
3479 
3483  Memory(Memory&& mem) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(mem)) {}
3484 
3489  {
3490  detail::Wrapper<cl_type>::operator=(std::move(mem));
3491  return *this;
3492  }
3493 
3494 
3496  template <typename T>
3497  cl_int getInfo(cl_mem_info name, T* param) const
3498  {
3499  return detail::errHandler(
3500  detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
3501  __GET_MEM_OBJECT_INFO_ERR);
3502  }
3503 
3505  template <cl_mem_info name> typename
3507  getInfo(cl_int* err = NULL) const
3508  {
3509  typename detail::param_traits<
3510  detail::cl_mem_info, name>::param_type param;
3511  cl_int result = getInfo(name, &param);
3512  if (err != NULL) {
3513  *err = result;
3514  }
3515  return param;
3516  }
3517 
3518 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3533  void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
3534  void * user_data = NULL)
3535  {
3536  return detail::errHandler(
3537  ::clSetMemObjectDestructorCallback(
3538  object_,
3539  pfn_notify,
3540  user_data),
3541  __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
3542  }
3543 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3544 
3545 };
3546 
3547 // Pre-declare copy functions
3548 class Buffer;
3549 template< typename IteratorType >
3550 cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3551 template< typename IteratorType >
3552 cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3553 template< typename IteratorType >
3554 cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3555 template< typename IteratorType >
3556 cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3557 
3558 
3559 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
3560 namespace detail
3561 {
3563  {
3564  public:
3565  static cl_svm_mem_flags getSVMMemFlags()
3566  {
3567  return 0;
3568  }
3569  };
3570 } // namespace detail
3571 
3572 template<class Trait = detail::SVMTraitNull>
3574 {
3575 public:
3576  static cl_svm_mem_flags getSVMMemFlags()
3577  {
3578  return CL_MEM_READ_WRITE |
3579  Trait::getSVMMemFlags();
3580  }
3581 };
3582 
3583 template<class Trait = detail::SVMTraitNull>
3585 {
3586 public:
3587  static cl_svm_mem_flags getSVMMemFlags()
3588  {
3589  return CL_MEM_READ_ONLY |
3590  Trait::getSVMMemFlags();
3591  }
3592 };
3593 
3594 template<class Trait = detail::SVMTraitNull>
3596 {
3597 public:
3598  static cl_svm_mem_flags getSVMMemFlags()
3599  {
3600  return CL_MEM_WRITE_ONLY |
3601  Trait::getSVMMemFlags();
3602  }
3603 };
3604 
3605 template<class Trait = SVMTraitReadWrite<>>
3607 {
3608 public:
3609  static cl_svm_mem_flags getSVMMemFlags()
3610  {
3611  return Trait::getSVMMemFlags();
3612  }
3613 };
3614 
3615 template<class Trait = SVMTraitReadWrite<>>
3617 {
3618 public:
3619  static cl_svm_mem_flags getSVMMemFlags()
3620  {
3621  return CL_MEM_SVM_FINE_GRAIN_BUFFER |
3622  Trait::getSVMMemFlags();
3623  }
3624 };
3625 
3626 template<class Trait = SVMTraitReadWrite<>>
3628 {
3629 public:
3630  static cl_svm_mem_flags getSVMMemFlags()
3631  {
3632  return
3633  CL_MEM_SVM_FINE_GRAIN_BUFFER |
3634  CL_MEM_SVM_ATOMICS |
3635  Trait::getSVMMemFlags();
3636  }
3637 };
3638 
3639 // Pre-declare SVM map function
3640 template<typename T>
3641 inline cl_int enqueueMapSVM(
3642  T* ptr,
3643  cl_bool blocking,
3644  cl_map_flags flags,
3645  size_type size,
3646  const vector<Event>* events = NULL,
3647  Event* event = NULL);
3648 
3660 template<typename T, class SVMTrait>
3662 private:
3663  Context context_;
3664 
3665 public:
3666  typedef T value_type;
3667  typedef value_type* pointer;
3668  typedef const value_type* const_pointer;
3669  typedef value_type& reference;
3670  typedef const value_type& const_reference;
3671  typedef std::size_t size_type;
3672  typedef std::ptrdiff_t difference_type;
3673 
3674  template<typename U>
3675  struct rebind
3676  {
3678  };
3679 
3680  template<typename U, typename V>
3681  friend class SVMAllocator;
3682 
3683  SVMAllocator() :
3684  context_(Context::getDefault())
3685  {
3686  }
3687 
3688  explicit SVMAllocator(cl::Context context) :
3689  context_(context)
3690  {
3691  }
3692 
3693 
3694  SVMAllocator(const SVMAllocator &other) :
3695  context_(other.context_)
3696  {
3697  }
3698 
3699  template<typename U>
3700  SVMAllocator(const SVMAllocator<U, SVMTrait> &other) :
3701  context_(other.context_)
3702  {
3703  }
3704 
3705  ~SVMAllocator()
3706  {
3707  }
3708 
3709  pointer address(reference r) CL_HPP_NOEXCEPT_
3710  {
3711  return std::addressof(r);
3712  }
3713 
3714  const_pointer address(const_reference r) CL_HPP_NOEXCEPT_
3715  {
3716  return std::addressof(r);
3717  }
3718 
3725  pointer allocate(
3726  size_type size,
3728  {
3729  // Allocate memory with default alignment matching the size of the type
3730  void* voidPointer =
3731  clSVMAlloc(
3732  context_(),
3733  SVMTrait::getSVMMemFlags(),
3734  size*sizeof(T),
3735  0);
3736  pointer retValue = reinterpret_cast<pointer>(
3737  voidPointer);
3738 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3739  if (!retValue) {
3740  std::bad_alloc excep;
3741  throw excep;
3742  }
3743 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3744 
3745  // If allocation was coarse-grained then map it
3746  if (!(SVMTrait::getSVMMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) {
3747  cl_int err = enqueueMapSVM(retValue, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, size*sizeof(T));
3748  if (err != CL_SUCCESS) {
3749  std::bad_alloc excep;
3750  throw excep;
3751  }
3752  }
3753 
3754  // If exceptions disabled, return null pointer from allocator
3755  return retValue;
3756  }
3757 
3758  void deallocate(pointer p, size_type)
3759  {
3760  clSVMFree(context_(), p);
3761  }
3762 
3767  size_type max_size() const CL_HPP_NOEXCEPT_
3768  {
3769  size_type maxSize = std::numeric_limits<size_type>::max() / sizeof(T);
3770 
3771  for (const Device &d : context_.getInfo<CL_CONTEXT_DEVICES>()) {
3772  maxSize = std::min(
3773  maxSize,
3774  static_cast<size_type>(d.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>()));
3775  }
3776 
3777  return maxSize;
3778  }
3779 
3780  template< class U, class... Args >
3781  void construct(U* p, Args&&... args)
3782  {
3783  new(p)T(args...);
3784  }
3785 
3786  template< class U >
3787  void destroy(U* p)
3788  {
3789  p->~U();
3790  }
3791 
3795  inline bool operator==(SVMAllocator const& rhs)
3796  {
3797  return (context_==rhs.context_);
3798  }
3799 
3800  inline bool operator!=(SVMAllocator const& a)
3801  {
3802  return !operator==(a);
3803  }
3804 }; // class SVMAllocator return cl::pointer<T>(tmp, detail::Deleter<T, Alloc>{alloc, copies});
3805 
3806 
3807 template<class SVMTrait>
3808 class SVMAllocator<void, SVMTrait> {
3809 public:
3810  typedef void value_type;
3811  typedef value_type* pointer;
3812  typedef const value_type* const_pointer;
3813 
3814  template<typename U>
3815  struct rebind
3816  {
3818  };
3819 
3820  template<typename U, typename V>
3821  friend class SVMAllocator;
3822 };
3823 
3824 #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3825 namespace detail
3826 {
3827  template<class Alloc>
3828  class Deleter {
3829  private:
3830  Alloc alloc_;
3831  size_type copies_;
3832 
3833  public:
3834  typedef typename std::allocator_traits<Alloc>::pointer pointer;
3835 
3836  Deleter(const Alloc &alloc, size_type copies) : alloc_{ alloc }, copies_{ copies }
3837  {
3838  }
3839 
3840  void operator()(pointer ptr) const {
3841  Alloc tmpAlloc{ alloc_ };
3842  std::allocator_traits<Alloc>::destroy(tmpAlloc, std::addressof(*ptr));
3843  std::allocator_traits<Alloc>::deallocate(tmpAlloc, ptr, copies_);
3844  }
3845  };
3846 } // namespace detail
3847 
3854 template <class T, class Alloc, class... Args>
3855 cl::pointer<T, detail::Deleter<Alloc>> allocate_pointer(const Alloc &alloc_, Args&&... args)
3856 {
3857  Alloc alloc(alloc_);
3858  static const size_type copies = 1;
3859 
3860  // Ensure that creation of the management block and the
3861  // object are dealt with separately such that we only provide a deleter
3862 
3863  T* tmp = std::allocator_traits<Alloc>::allocate(alloc, copies);
3864  if (!tmp) {
3865  std::bad_alloc excep;
3866  throw excep;
3867  }
3868  try {
3869  std::allocator_traits<Alloc>::construct(
3870  alloc,
3871  std::addressof(*tmp),
3872  std::forward<Args>(args)...);
3873 
3874  return cl::pointer<T, detail::Deleter<Alloc>>(tmp, detail::Deleter<Alloc>{alloc, copies});
3875  }
3876  catch (std::bad_alloc& b)
3877  {
3878  std::allocator_traits<Alloc>::deallocate(alloc, tmp, copies);
3879  throw;
3880  }
3881 }
3882 
3883 template< class T, class SVMTrait, class... Args >
3884 cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(Args... args)
3885 {
3886  SVMAllocator<T, SVMTrait> alloc;
3887  return cl::allocate_pointer<T>(alloc, args...);
3888 }
3889 
3890 template< class T, class SVMTrait, class... Args >
3891 cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(const cl::Context &c, Args... args)
3892 {
3893  SVMAllocator<T, SVMTrait> alloc(c);
3894  return cl::allocate_pointer<T>(alloc, args...);
3895 }
3896 #endif // #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3897 
3901 template < class T >
3902 using coarse_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>>;
3903 
3907 template < class T >
3908 using fine_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitFine<>>>;
3909 
3913 template < class T >
3914 using atomic_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitAtomic<>>>;
3915 
3916 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
3917 
3918 
3925 class Buffer : public Memory
3926 {
3927 public:
3928 
3937  const Context& context,
3938  cl_mem_flags flags,
3939  size_type size,
3940  void* host_ptr = NULL,
3941  cl_int* err = NULL)
3942  {
3943  cl_int error;
3944  object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3945 
3946  detail::errHandler(error, __CREATE_BUFFER_ERR);
3947  if (err != NULL) {
3948  *err = error;
3949  }
3950  }
3951 
3962  cl_mem_flags flags,
3963  size_type size,
3964  void* host_ptr = NULL,
3965  cl_int* err = NULL)
3966  {
3967  cl_int error;
3968 
3969  Context context = Context::getDefault(err);
3970 
3971  object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3972 
3973  detail::errHandler(error, __CREATE_BUFFER_ERR);
3974  if (err != NULL) {
3975  *err = error;
3976  }
3977  }
3978 
3984  template< typename IteratorType >
3986  IteratorType startIterator,
3987  IteratorType endIterator,
3988  bool readOnly,
3989  bool useHostPtr = false,
3990  cl_int* err = NULL)
3991  {
3992  typedef typename std::iterator_traits<IteratorType>::value_type DataType;
3993  cl_int error;
3994 
3995  cl_mem_flags flags = 0;
3996  if( readOnly ) {
3997  flags |= CL_MEM_READ_ONLY;
3998  }
3999  else {
4000  flags |= CL_MEM_READ_WRITE;
4001  }
4002  if( useHostPtr ) {
4003  flags |= CL_MEM_USE_HOST_PTR;
4004  }
4005 
4006  size_type size = sizeof(DataType)*(endIterator - startIterator);
4007 
4008  Context context = Context::getDefault(err);
4009 
4010  if( useHostPtr ) {
4011  object_ = ::clCreateBuffer(context(), flags, size, const_cast<DataType*>(&*startIterator), &error);
4012  } else {
4013  object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
4014  }
4015 
4016  detail::errHandler(error, __CREATE_BUFFER_ERR);
4017  if (err != NULL) {
4018  *err = error;
4019  }
4020 
4021  if( !useHostPtr ) {
4022  error = cl::copy(startIterator, endIterator, *this);
4023  detail::errHandler(error, __CREATE_BUFFER_ERR);
4024  if (err != NULL) {
4025  *err = error;
4026  }
4027  }
4028  }
4029 
4035  template< typename IteratorType >
4036  Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator,
4037  bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
4038 
4043  template< typename IteratorType >
4044  Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator,
4045  bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
4046 
4048  Buffer() : Memory() { }
4049 
4057  explicit Buffer(const cl_mem& buffer, bool retainObject = false) :
4058  Memory(buffer, retainObject) { }
4059 
4064  Buffer& operator = (const cl_mem& rhs)
4065  {
4066  Memory::operator=(rhs);
4067  return *this;
4068  }
4069 
4073  Buffer(const Buffer& buf) : Memory(buf) {}
4074 
4079  {
4080  Memory::operator=(buf);
4081  return *this;
4082  }
4083 
4087  Buffer(Buffer&& buf) CL_HPP_NOEXCEPT_ : Memory(std::move(buf)) {}
4088 
4093  {
4094  Memory::operator=(std::move(buf));
4095  return *this;
4096  }
4097 
4098 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
4104  cl_mem_flags flags,
4105  cl_buffer_create_type buffer_create_type,
4106  const void * buffer_create_info,
4107  cl_int * err = NULL)
4108  {
4109  Buffer result;
4110  cl_int error;
4111  result.object_ = ::clCreateSubBuffer(
4112  object_,
4113  flags,
4114  buffer_create_type,
4115  buffer_create_info,
4116  &error);
4117 
4118  detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
4119  if (err != NULL) {
4120  *err = error;
4121  }
4122 
4123  return result;
4124  }
4125 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
4126 };
4127 
4128 #if defined (CL_HPP_USE_DX_INTEROP)
4137 class BufferD3D10 : public Buffer
4138 {
4139 public:
4140 
4141 
4147  BufferD3D10(
4148  const Context& context,
4149  cl_mem_flags flags,
4150  ID3D10Buffer* bufobj,
4151  cl_int * err = NULL) : pfn_clCreateFromD3D10BufferKHR(nullptr)
4152  {
4153  typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
4154  cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
4155  cl_int* errcode_ret);
4156  PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR;
4157 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4158  vector<cl_context_properties> props = context.getInfo<CL_CONTEXT_PROPERTIES>();
4159  cl_platform platform = -1;
4160  for( int i = 0; i < props.size(); ++i ) {
4161  if( props[i] == CL_CONTEXT_PLATFORM ) {
4162  platform = props[i+1];
4163  }
4164  }
4165  CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateFromD3D10BufferKHR);
4166 #elif CL_HPP_TARGET_OPENCL_VERSION >= 110
4167  CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateFromD3D10BufferKHR);
4168 #endif
4169 
4170  cl_int error;
4171  object_ = pfn_clCreateFromD3D10BufferKHR(
4172  context(),
4173  flags,
4174  bufobj,
4175  &error);
4176 
4177  detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4178  if (err != NULL) {
4179  *err = error;
4180  }
4181  }
4182 
4184  BufferD3D10() : Buffer() { }
4185 
4193  explicit BufferD3D10(const cl_mem& buffer, bool retainObject = false) :
4194  Buffer(buffer, retainObject) { }
4195 
4200  BufferD3D10& operator = (const cl_mem& rhs)
4201  {
4202  Buffer::operator=(rhs);
4203  return *this;
4204  }
4205 
4209  BufferD3D10(const BufferD3D10& buf) :
4210  Buffer(buf) {}
4211 
4215  BufferD3D10& operator = (const BufferD3D10 &buf)
4216  {
4217  Buffer::operator=(buf);
4218  return *this;
4219  }
4220 
4224  BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4225 
4229  BufferD3D10& operator = (BufferD3D10 &&buf)
4230  {
4231  Buffer::operator=(std::move(buf));
4232  return *this;
4233  }
4234 };
4235 #endif
4236 
4245 class BufferGL : public Buffer
4246 {
4247 public:
4254  const Context& context,
4255  cl_mem_flags flags,
4256  cl_GLuint bufobj,
4257  cl_int * err = NULL)
4258  {
4259  cl_int error;
4260  object_ = ::clCreateFromGLBuffer(
4261  context(),
4262  flags,
4263  bufobj,
4264  &error);
4265 
4266  detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4267  if (err != NULL) {
4268  *err = error;
4269  }
4270  }
4271 
4273  BufferGL() : Buffer() { }
4274 
4282  explicit BufferGL(const cl_mem& buffer, bool retainObject = false) :
4283  Buffer(buffer, retainObject) { }
4284 
4289  BufferGL& operator = (const cl_mem& rhs)
4290  {
4291  Buffer::operator=(rhs);
4292  return *this;
4293  }
4294 
4298  BufferGL(const BufferGL& buf) : Buffer(buf) {}
4299 
4304  {
4305  Buffer::operator=(buf);
4306  return *this;
4307  }
4308 
4312  BufferGL(BufferGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4313 
4318  {
4319  Buffer::operator=(std::move(buf));
4320  return *this;
4321  }
4322 
4325  cl_gl_object_type *type,
4326  cl_GLuint * gl_object_name)
4327  {
4328  return detail::errHandler(
4329  ::clGetGLObjectInfo(object_,type,gl_object_name),
4330  __GET_GL_OBJECT_INFO_ERR);
4331  }
4332 };
4333 
4342 class BufferRenderGL : public Buffer
4343 {
4344 public:
4351  const Context& context,
4352  cl_mem_flags flags,
4353  cl_GLuint bufobj,
4354  cl_int * err = NULL)
4355  {
4356  cl_int error;
4357  object_ = ::clCreateFromGLRenderbuffer(
4358  context(),
4359  flags,
4360  bufobj,
4361  &error);
4362 
4363  detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR);
4364  if (err != NULL) {
4365  *err = error;
4366  }
4367  }
4368 
4371 
4379  explicit BufferRenderGL(const cl_mem& buffer, bool retainObject = false) :
4380  Buffer(buffer, retainObject) { }
4381 
4386  BufferRenderGL& operator = (const cl_mem& rhs)
4387  {
4388  Buffer::operator=(rhs);
4389  return *this;
4390  }
4391 
4395  BufferRenderGL(const BufferRenderGL& buf) : Buffer(buf) {}
4396 
4401  {
4402  Buffer::operator=(buf);
4403  return *this;
4404  }
4405 
4409  BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4410 
4415  {
4416  Buffer::operator=(std::move(buf));
4417  return *this;
4418  }
4419 
4422  cl_gl_object_type *type,
4423  cl_GLuint * gl_object_name)
4424  {
4425  return detail::errHandler(
4426  ::clGetGLObjectInfo(object_,type,gl_object_name),
4427  __GET_GL_OBJECT_INFO_ERR);
4428  }
4429 };
4430 
4437 class Image : public Memory
4438 {
4439 protected:
4441  Image() : Memory() { }
4442 
4450  explicit Image(const cl_mem& image, bool retainObject = false) :
4451  Memory(image, retainObject) { }
4452 
4457  Image& operator = (const cl_mem& rhs)
4458  {
4459  Memory::operator=(rhs);
4460  return *this;
4461  }
4462 
4466  Image(const Image& img) : Memory(img) {}
4467 
4471  Image& operator = (const Image &img)
4472  {
4473  Memory::operator=(img);
4474  return *this;
4475  }
4476 
4480  Image(Image&& img) CL_HPP_NOEXCEPT_ : Memory(std::move(img)) {}
4481 
4486  {
4487  Memory::operator=(std::move(img));
4488  return *this;
4489  }
4490 
4491 
4492 public:
4494  template <typename T>
4495  cl_int getImageInfo(cl_image_info name, T* param) const
4496  {
4497  return detail::errHandler(
4498  detail::getInfo(&::clGetImageInfo, object_, name, param),
4499  __GET_IMAGE_INFO_ERR);
4500  }
4501 
4503  template <cl_image_info name> typename
4505  getImageInfo(cl_int* err = NULL) const
4506  {
4507  typename detail::param_traits<
4508  detail::cl_image_info, name>::param_type param;
4509  cl_int result = getImageInfo(name, &param);
4510  if (err != NULL) {
4511  *err = result;
4512  }
4513  return param;
4514  }
4515 };
4516 
4517 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4524 class Image1D : public Image
4525 {
4526 public:
4532  const Context& context,
4533  cl_mem_flags flags,
4534  ImageFormat format,
4535  size_type width,
4536  void* host_ptr = NULL,
4537  cl_int* err = NULL)
4538  {
4539  cl_int error;
4540 
4541  cl_image_desc desc = {0};
4542  desc.image_type = CL_MEM_OBJECT_IMAGE1D;
4543  desc.image_width = width;
4544 
4545  object_ = ::clCreateImage(
4546  context(),
4547  flags,
4548  &format,
4549  &desc,
4550  host_ptr,
4551  &error);
4552 
4553  detail::errHandler(error, __CREATE_IMAGE_ERR);
4554  if (err != NULL) {
4555  *err = error;
4556  }
4557  }
4558 
4560  Image1D() { }
4561 
4569  explicit Image1D(const cl_mem& image1D, bool retainObject = false) :
4570  Image(image1D, retainObject) { }
4571 
4576  Image1D& operator = (const cl_mem& rhs)
4577  {
4578  Image::operator=(rhs);
4579  return *this;
4580  }
4581 
4585  Image1D(const Image1D& img) : Image(img) {}
4586 
4591  {
4592  Image::operator=(img);
4593  return *this;
4594  }
4595 
4599  Image1D(Image1D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4600 
4605  {
4606  Image::operator=(std::move(img));
4607  return *this;
4608  }
4609 
4610 };
4611 
4615 class Image1DBuffer : public Image
4616 {
4617 public:
4618  Image1DBuffer(
4619  const Context& context,
4620  cl_mem_flags flags,
4621  ImageFormat format,
4622  size_type width,
4623  const Buffer &buffer,
4624  cl_int* err = NULL)
4625  {
4626  cl_int error;
4627 
4628  cl_image_desc desc = {0};
4629  desc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER;
4630  desc.image_width = width;
4631  desc.buffer = buffer();
4632 
4633  object_ = ::clCreateImage(
4634  context(),
4635  flags,
4636  &format,
4637  &desc,
4638  NULL,
4639  &error);
4640 
4641  detail::errHandler(error, __CREATE_IMAGE_ERR);
4642  if (err != NULL) {
4643  *err = error;
4644  }
4645  }
4646 
4647  Image1DBuffer() { }
4648 
4656  explicit Image1DBuffer(const cl_mem& image1D, bool retainObject = false) :
4657  Image(image1D, retainObject) { }
4658 
4659  Image1DBuffer& operator = (const cl_mem& rhs)
4660  {
4661  Image::operator=(rhs);
4662  return *this;
4663  }
4664 
4668  Image1DBuffer(const Image1DBuffer& img) : Image(img) {}
4669 
4673  Image1DBuffer& operator = (const Image1DBuffer &img)
4674  {
4675  Image::operator=(img);
4676  return *this;
4677  }
4678 
4682  Image1DBuffer(Image1DBuffer&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4683 
4687  Image1DBuffer& operator = (Image1DBuffer &&img)
4688  {
4689  Image::operator=(std::move(img));
4690  return *this;
4691  }
4692 
4693 };
4694 
4698 class Image1DArray : public Image
4699 {
4700 public:
4701  Image1DArray(
4702  const Context& context,
4703  cl_mem_flags flags,
4704  ImageFormat format,
4705  size_type arraySize,
4706  size_type width,
4707  size_type rowPitch,
4708  void* host_ptr = NULL,
4709  cl_int* err = NULL)
4710  {
4711  cl_int error;
4712 
4713  cl_image_desc desc = {0};
4714  desc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
4715  desc.image_width = width;
4716  desc.image_array_size = arraySize;
4717  desc.image_row_pitch = rowPitch;
4718 
4719  object_ = ::clCreateImage(
4720  context(),
4721  flags,
4722  &format,
4723  &desc,
4724  host_ptr,
4725  &error);
4726 
4727  detail::errHandler(error, __CREATE_IMAGE_ERR);
4728  if (err != NULL) {
4729  *err = error;
4730  }
4731  }
4732 
4733  Image1DArray() { }
4734 
4742  explicit Image1DArray(const cl_mem& imageArray, bool retainObject = false) :
4743  Image(imageArray, retainObject) { }
4744 
4745 
4746  Image1DArray& operator = (const cl_mem& rhs)
4747  {
4748  Image::operator=(rhs);
4749  return *this;
4750  }
4751 
4755  Image1DArray(const Image1DArray& img) : Image(img) {}
4756 
4760  Image1DArray& operator = (const Image1DArray &img)
4761  {
4762  Image::operator=(img);
4763  return *this;
4764  }
4765 
4769  Image1DArray(Image1DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4770 
4774  Image1DArray& operator = (Image1DArray &&img)
4775  {
4776  Image::operator=(std::move(img));
4777  return *this;
4778  }
4779 
4780 };
4781 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4782 
4783 
4790 class Image2D : public Image
4791 {
4792 public:
4798  const Context& context,
4799  cl_mem_flags flags,
4800  ImageFormat format,
4801  size_type width,
4802  size_type height,
4803  size_type row_pitch = 0,
4804  void* host_ptr = NULL,
4805  cl_int* err = NULL)
4806  {
4807  cl_int error;
4808  bool useCreateImage;
4809 
4810 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
4811  // Run-time decision based on the actual platform
4812  {
4813  cl_uint version = detail::getContextPlatformVersion(context());
4814  useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
4815  }
4816 #elif CL_HPP_TARGET_OPENCL_VERSION >= 120
4817  useCreateImage = true;
4818 #else
4819  useCreateImage = false;
4820 #endif
4821 
4822 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4823  if (useCreateImage)
4824  {
4825  cl_image_desc desc = {0};
4826  desc.image_type = CL_MEM_OBJECT_IMAGE2D;
4827  desc.image_width = width;
4828  desc.image_height = height;
4829  desc.image_row_pitch = row_pitch;
4830 
4831  object_ = ::clCreateImage(
4832  context(),
4833  flags,
4834  &format,
4835  &desc,
4836  host_ptr,
4837  &error);
4838 
4839  detail::errHandler(error, __CREATE_IMAGE_ERR);
4840  if (err != NULL) {
4841  *err = error;
4842  }
4843  }
4844 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
4845 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
4846  if (!useCreateImage)
4847  {
4848  object_ = ::clCreateImage2D(
4849  context(), flags,&format, width, height, row_pitch, host_ptr, &error);
4850 
4851  detail::errHandler(error, __CREATE_IMAGE2D_ERR);
4852  if (err != NULL) {
4853  *err = error;
4854  }
4855  }
4856 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
4857  }
4858 
4859 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4866  const Context& context,
4867  ImageFormat format,
4868  const Buffer &sourceBuffer,
4869  size_type width,
4870  size_type height,
4871  size_type row_pitch = 0,
4872  cl_int* err = nullptr)
4873  {
4874  cl_int error;
4875 
4876  cl_image_desc desc = {0};
4877  desc.image_type = CL_MEM_OBJECT_IMAGE2D;
4878  desc.image_width = width;
4879  desc.image_height = height;
4880  desc.image_row_pitch = row_pitch;
4881  desc.buffer = sourceBuffer();
4882 
4883  object_ = ::clCreateImage(
4884  context(),
4885  0, // flags inherited from buffer
4886  &format,
4887  &desc,
4888  nullptr,
4889  &error);
4890 
4891  detail::errHandler(error, __CREATE_IMAGE_ERR);
4892  if (err != nullptr) {
4893  *err = error;
4894  }
4895  }
4896 #endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4897 
4898 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
4912  const Context& context,
4913  cl_channel_order order,
4914  const Image &sourceImage,
4915  cl_int* err = nullptr)
4916  {
4917  cl_int error;
4918 
4919  // Descriptor fields have to match source image
4920  size_type sourceWidth =
4921  sourceImage.getImageInfo<CL_IMAGE_WIDTH>();
4922  size_type sourceHeight =
4923  sourceImage.getImageInfo<CL_IMAGE_HEIGHT>();
4924  size_type sourceRowPitch =
4925  sourceImage.getImageInfo<CL_IMAGE_ROW_PITCH>();
4926  cl_uint sourceNumMIPLevels =
4927  sourceImage.getImageInfo<CL_IMAGE_NUM_MIP_LEVELS>();
4928  cl_uint sourceNumSamples =
4929  sourceImage.getImageInfo<CL_IMAGE_NUM_SAMPLES>();
4930  cl_image_format sourceFormat =
4931  sourceImage.getImageInfo<CL_IMAGE_FORMAT>();
4932 
4933  // Update only the channel order.
4934  // Channel format inherited from source.
4935  sourceFormat.image_channel_order = order;
4936 
4937  cl_image_desc desc = {0};
4938  desc.image_type = CL_MEM_OBJECT_IMAGE2D;
4939  desc.image_width = sourceWidth;
4940  desc.image_height = sourceHeight;
4941  desc.image_row_pitch = sourceRowPitch;
4942  desc.num_mip_levels = sourceNumMIPLevels;
4943  desc.num_samples = sourceNumSamples;
4944  desc.buffer = sourceImage();
4945 
4946  object_ = ::clCreateImage(
4947  context(),
4948  0, // flags should be inherited from mem_object
4949  &sourceFormat,
4950  &desc,
4951  nullptr,
4952  &error);
4953 
4954  detail::errHandler(error, __CREATE_IMAGE_ERR);
4955  if (err != nullptr) {
4956  *err = error;
4957  }
4958  }
4959 #endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200
4960 
4962  Image2D() { }
4963 
4971  explicit Image2D(const cl_mem& image2D, bool retainObject = false) :
4972  Image(image2D, retainObject) { }
4973 
4978  Image2D& operator = (const cl_mem& rhs)
4979  {
4980  Image::operator=(rhs);
4981  return *this;
4982  }
4983 
4987  Image2D(const Image2D& img) : Image(img) {}
4988 
4993  {
4994  Image::operator=(img);
4995  return *this;
4996  }
4997 
5001  Image2D(Image2D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5002 
5007  {
5008  Image::operator=(std::move(img));
5009  return *this;
5010  }
5011 
5012 };
5013 
5014 
5015 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
5025 class CL_API_PREFIX__VERSION_1_1_DEPRECATED Image2DGL : public Image2D
5026 {
5027 public:
5034  const Context& context,
5035  cl_mem_flags flags,
5036  cl_GLenum target,
5037  cl_GLint miplevel,
5038  cl_GLuint texobj,
5039  cl_int * err = NULL)
5040  {
5041  cl_int error;
5042  object_ = ::clCreateFromGLTexture2D(
5043  context(),
5044  flags,
5045  target,
5046  miplevel,
5047  texobj,
5048  &error);
5049 
5050  detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR);
5051  if (err != NULL) {
5052  *err = error;
5053  }
5054 
5055  }
5056 
5058  Image2DGL() : Image2D() { }
5059 
5067  explicit Image2DGL(const cl_mem& image, bool retainObject = false) :
5068  Image2D(image, retainObject) { }
5069 
5074  Image2DGL& operator = (const cl_mem& rhs)
5075  {
5076  Image2D::operator=(rhs);
5077  return *this;
5078  }
5079 
5083  Image2DGL(const Image2DGL& img) : Image2D(img) {}
5084 
5088  Image2DGL& operator = (const Image2DGL &img)
5089  {
5090  Image2D::operator=(img);
5091  return *this;
5092  }
5093 
5097  Image2DGL(Image2DGL&& img) CL_HPP_NOEXCEPT_ : Image2D(std::move(img)) {}
5098 
5102  Image2DGL& operator = (Image2DGL &&img)
5103  {
5104  Image2D::operator=(std::move(img));
5105  return *this;
5106  }
5107 
5108 } CL_API_SUFFIX__VERSION_1_1_DEPRECATED;
5109 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5110 
5111 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5115 class Image2DArray : public Image
5116 {
5117 public:
5118  Image2DArray(
5119  const Context& context,
5120  cl_mem_flags flags,
5121  ImageFormat format,
5122  size_type arraySize,
5123  size_type width,
5124  size_type height,
5125  size_type rowPitch,
5126  size_type slicePitch,
5127  void* host_ptr = NULL,
5128  cl_int* err = NULL)
5129  {
5130  cl_int error;
5131 
5132  cl_image_desc desc = {0};
5133  desc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
5134  desc.image_width = width;
5135  desc.image_height = height;
5136  desc.image_array_size = arraySize;
5137  desc.image_row_pitch = rowPitch;
5138  desc.image_slice_pitch = slicePitch;
5139 
5140  object_ = ::clCreateImage(
5141  context(),
5142  flags,
5143  &format,
5144  &desc,
5145  host_ptr,
5146  &error);
5147 
5148  detail::errHandler(error, __CREATE_IMAGE_ERR);
5149  if (err != NULL) {
5150  *err = error;
5151  }
5152  }
5153 
5154  Image2DArray() { }
5155 
5163  explicit Image2DArray(const cl_mem& imageArray, bool retainObject = false) : Image(imageArray, retainObject) { }
5164 
5165  Image2DArray& operator = (const cl_mem& rhs)
5166  {
5167  Image::operator=(rhs);
5168  return *this;
5169  }
5170 
5174  Image2DArray(const Image2DArray& img) : Image(img) {}
5175 
5179  Image2DArray& operator = (const Image2DArray &img)
5180  {
5181  Image::operator=(img);
5182  return *this;
5183  }
5184 
5188  Image2DArray(Image2DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5189 
5193  Image2DArray& operator = (Image2DArray &&img)
5194  {
5195  Image::operator=(std::move(img));
5196  return *this;
5197  }
5198 };
5199 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5200 
5207 class Image3D : public Image
5208 {
5209 public:
5215  const Context& context,
5216  cl_mem_flags flags,
5217  ImageFormat format,
5218  size_type width,
5219  size_type height,
5220  size_type depth,
5221  size_type row_pitch = 0,
5222  size_type slice_pitch = 0,
5223  void* host_ptr = NULL,
5224  cl_int* err = NULL)
5225  {
5226  cl_int error;
5227  bool useCreateImage;
5228 
5229 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
5230  // Run-time decision based on the actual platform
5231  {
5232  cl_uint version = detail::getContextPlatformVersion(context());
5233  useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
5234  }
5235 #elif CL_HPP_TARGET_OPENCL_VERSION >= 120
5236  useCreateImage = true;
5237 #else
5238  useCreateImage = false;
5239 #endif
5240 
5241 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5242  if (useCreateImage)
5243  {
5244  cl_image_desc desc = {0};
5245  desc.image_type = CL_MEM_OBJECT_IMAGE3D;
5246  desc.image_width = width;
5247  desc.image_height = height;
5248  desc.image_depth = depth;
5249  desc.image_row_pitch = row_pitch;
5250  desc.image_slice_pitch = slice_pitch;
5251 
5252  object_ = ::clCreateImage(
5253  context(),
5254  flags,
5255  &format,
5256  &desc,
5257  host_ptr,
5258  &error);
5259 
5260  detail::errHandler(error, __CREATE_IMAGE_ERR);
5261  if (err != NULL) {
5262  *err = error;
5263  }
5264  }
5265 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5266 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
5267  if (!useCreateImage)
5268  {
5269  object_ = ::clCreateImage3D(
5270  context(), flags, &format, width, height, depth, row_pitch,
5271  slice_pitch, host_ptr, &error);
5272 
5273  detail::errHandler(error, __CREATE_IMAGE3D_ERR);
5274  if (err != NULL) {
5275  *err = error;
5276  }
5277  }
5278 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
5279  }
5280 
5282  Image3D() : Image() { }
5283 
5291  explicit Image3D(const cl_mem& image3D, bool retainObject = false) :
5292  Image(image3D, retainObject) { }
5293 
5298  Image3D& operator = (const cl_mem& rhs)
5299  {
5300  Image::operator=(rhs);
5301  return *this;
5302  }
5303 
5307  Image3D(const Image3D& img) : Image(img) {}
5308 
5313  {
5314  Image::operator=(img);
5315  return *this;
5316  }
5317 
5321  Image3D(Image3D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5322 
5327  {
5328  Image::operator=(std::move(img));
5329  return *this;
5330  }
5331 };
5332 
5333 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
5342 class Image3DGL : public Image3D
5343 {
5344 public:
5351  const Context& context,
5352  cl_mem_flags flags,
5353  cl_GLenum target,
5354  cl_GLint miplevel,
5355  cl_GLuint texobj,
5356  cl_int * err = NULL)
5357  {
5358  cl_int error;
5359  object_ = ::clCreateFromGLTexture3D(
5360  context(),
5361  flags,
5362  target,
5363  miplevel,
5364  texobj,
5365  &error);
5366 
5367  detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR);
5368  if (err != NULL) {
5369  *err = error;
5370  }
5371  }
5372 
5374  Image3DGL() : Image3D() { }
5375 
5383  explicit Image3DGL(const cl_mem& image, bool retainObject = false) :
5384  Image3D(image, retainObject) { }
5385 
5390  Image3DGL& operator = (const cl_mem& rhs)
5391  {
5392  Image3D::operator=(rhs);
5393  return *this;
5394  }
5395 
5399  Image3DGL(const Image3DGL& img) : Image3D(img) {}
5400 
5405  {
5406  Image3D::operator=(img);
5407  return *this;
5408  }
5409 
5413  Image3DGL(Image3DGL&& img) CL_HPP_NOEXCEPT_ : Image3D(std::move(img)) {}
5414 
5419  {
5420  Image3D::operator=(std::move(img));
5421  return *this;
5422  }
5423 };
5424 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5425 
5426 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5433 class ImageGL : public Image
5434 {
5435 public:
5436  ImageGL(
5437  const Context& context,
5438  cl_mem_flags flags,
5439  cl_GLenum target,
5440  cl_GLint miplevel,
5441  cl_GLuint texobj,
5442  cl_int * err = NULL)
5443  {
5444  cl_int error;
5445  object_ = ::clCreateFromGLTexture(
5446  context(),
5447  flags,
5448  target,
5449  miplevel,
5450  texobj,
5451  &error);
5452 
5453  detail::errHandler(error, __CREATE_GL_TEXTURE_ERR);
5454  if (err != NULL) {
5455  *err = error;
5456  }
5457  }
5458 
5459  ImageGL() : Image() { }
5460 
5468  explicit ImageGL(const cl_mem& image, bool retainObject = false) :
5469  Image(image, retainObject) { }
5470 
5471  ImageGL& operator = (const cl_mem& rhs)
5472  {
5473  Image::operator=(rhs);
5474  return *this;
5475  }
5476 
5480  ImageGL(const ImageGL& img) : Image(img) {}
5481 
5485  ImageGL& operator = (const ImageGL &img)
5486  {
5487  Image::operator=(img);
5488  return *this;
5489  }
5490 
5494  ImageGL(ImageGL&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5495 
5499  ImageGL& operator = (ImageGL &&img)
5500  {
5501  Image::operator=(std::move(img));
5502  return *this;
5503  }
5504 };
5505 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5506 
5507 
5508 
5509 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5516 class Pipe : public Memory
5517 {
5518 public:
5519 
5530  const Context& context,
5531  cl_uint packet_size,
5532  cl_uint max_packets,
5533  cl_int* err = NULL)
5534  {
5535  cl_int error;
5536 
5537  cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5538  object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error);
5539 
5540  detail::errHandler(error, __CREATE_PIPE_ERR);
5541  if (err != NULL) {
5542  *err = error;
5543  }
5544  }
5545 
5555  cl_uint packet_size,
5556  cl_uint max_packets,
5557  cl_int* err = NULL)
5558  {
5559  cl_int error;
5560 
5561  Context context = Context::getDefault(err);
5562 
5563  cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5564  object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error);
5565 
5566  detail::errHandler(error, __CREATE_PIPE_ERR);
5567  if (err != NULL) {
5568  *err = error;
5569  }
5570  }
5571 
5573  Pipe() : Memory() { }
5574 
5582  explicit Pipe(const cl_mem& pipe, bool retainObject = false) :
5583  Memory(pipe, retainObject) { }
5584 
5589  Pipe& operator = (const cl_mem& rhs)
5590  {
5591  Memory::operator=(rhs);
5592  return *this;
5593  }
5594 
5598  Pipe(const Pipe& pipe) : Memory(pipe) {}
5599 
5603  Pipe& operator = (const Pipe &pipe)
5604  {
5605  Memory::operator=(pipe);
5606  return *this;
5607  }
5608 
5612  Pipe(Pipe&& pipe) CL_HPP_NOEXCEPT_ : Memory(std::move(pipe)) {}
5613 
5618  {
5619  Memory::operator=(std::move(pipe));
5620  return *this;
5621  }
5622 
5624  template <typename T>
5625  cl_int getInfo(cl_pipe_info name, T* param) const
5626  {
5627  return detail::errHandler(
5628  detail::getInfo(&::clGetPipeInfo, object_, name, param),
5629  __GET_PIPE_INFO_ERR);
5630  }
5631 
5633  template <cl_pipe_info name> typename
5635  getInfo(cl_int* err = NULL) const
5636  {
5637  typename detail::param_traits<
5638  detail::cl_pipe_info, name>::param_type param;
5639  cl_int result = getInfo(name, &param);
5640  if (err != NULL) {
5641  *err = result;
5642  }
5643  return param;
5644  }
5645 }; // class Pipe
5646 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
5647 
5648 
5657 class Sampler : public detail::Wrapper<cl_sampler>
5658 {
5659 public:
5661  Sampler() { }
5662 
5668  const Context& context,
5669  cl_bool normalized_coords,
5670  cl_addressing_mode addressing_mode,
5671  cl_filter_mode filter_mode,
5672  cl_int* err = NULL)
5673  {
5674  cl_int error;
5675 
5676 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5677  cl_sampler_properties sampler_properties[] = {
5678  CL_SAMPLER_NORMALIZED_COORDS, normalized_coords,
5679  CL_SAMPLER_ADDRESSING_MODE, addressing_mode,
5680  CL_SAMPLER_FILTER_MODE, filter_mode,
5681  0 };
5682  object_ = ::clCreateSamplerWithProperties(
5683  context(),
5684  sampler_properties,
5685  &error);
5686 
5687  detail::errHandler(error, __CREATE_SAMPLER_WITH_PROPERTIES_ERR);
5688  if (err != NULL) {
5689  *err = error;
5690  }
5691 #else
5692  object_ = ::clCreateSampler(
5693  context(),
5694  normalized_coords,
5695  addressing_mode,
5696  filter_mode,
5697  &error);
5698 
5699  detail::errHandler(error, __CREATE_SAMPLER_ERR);
5700  if (err != NULL) {
5701  *err = error;
5702  }
5703 #endif
5704  }
5705 
5714  explicit Sampler(const cl_sampler& sampler, bool retainObject = false) :
5715  detail::Wrapper<cl_type>(sampler, retainObject) { }
5716 
5722  Sampler& operator = (const cl_sampler& rhs)
5723  {
5725  return *this;
5726  }
5727 
5731  Sampler(const Sampler& sam) : detail::Wrapper<cl_type>(sam) {}
5732 
5737  {
5739  return *this;
5740  }
5741 
5745  Sampler(Sampler&& sam) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(sam)) {}
5746 
5751  {
5752  detail::Wrapper<cl_type>::operator=(std::move(sam));
5753  return *this;
5754  }
5755 
5757  template <typename T>
5758  cl_int getInfo(cl_sampler_info name, T* param) const
5759  {
5760  return detail::errHandler(
5761  detail::getInfo(&::clGetSamplerInfo, object_, name, param),
5762  __GET_SAMPLER_INFO_ERR);
5763  }
5764 
5766  template <cl_sampler_info name> typename
5768  getInfo(cl_int* err = NULL) const
5769  {
5770  typename detail::param_traits<
5771  detail::cl_sampler_info, name>::param_type param;
5772  cl_int result = getInfo(name, &param);
5773  if (err != NULL) {
5774  *err = result;
5775  }
5776  return param;
5777  }
5778 };
5779 
5780 class Program;
5781 class CommandQueue;
5782 class DeviceCommandQueue;
5783 class Kernel;
5784 
5786 class NDRange
5787 {
5788 private:
5789  size_type sizes_[3];
5790  cl_uint dimensions_;
5791 
5792 public:
5795  : dimensions_(0)
5796  {
5797  sizes_[0] = 0;
5798  sizes_[1] = 0;
5799  sizes_[2] = 0;
5800  }
5801 
5803  NDRange(size_type size0)
5804  : dimensions_(1)
5805  {
5806  sizes_[0] = size0;
5807  sizes_[1] = 1;
5808  sizes_[2] = 1;
5809  }
5810 
5812  NDRange(size_type size0, size_type size1)
5813  : dimensions_(2)
5814  {
5815  sizes_[0] = size0;
5816  sizes_[1] = size1;
5817  sizes_[2] = 1;
5818  }
5819 
5821  NDRange(size_type size0, size_type size1, size_type size2)
5822  : dimensions_(3)
5823  {
5824  sizes_[0] = size0;
5825  sizes_[1] = size1;
5826  sizes_[2] = size2;
5827  }
5828 
5833  operator const size_type*() const {
5834  return sizes_;
5835  }
5836 
5838  size_type dimensions() const
5839  {
5840  return dimensions_;
5841  }
5842 
5844  // runtime number of dimensions
5845  size_type size() const
5846  {
5847  return dimensions_*sizeof(size_type);
5848  }
5849 
5850  size_type* get()
5851  {
5852  return sizes_;
5853  }
5854 
5855  const size_type* get() const
5856  {
5857  return sizes_;
5858  }
5859 };
5860 
5862 static const NDRange NullRange;
5863 
5866 {
5867  size_type size_;
5868 };
5869 
5870 namespace detail {
5871 
5872 template <typename T, class Enable = void>
5874 
5875 // Enable for objects that are not subclasses of memory
5876 // Pointers, constants etc
5877 template <typename T>
5878 struct KernelArgumentHandler<T, typename std::enable_if<!std::is_base_of<cl::Memory, T>::value>::type>
5879 {
5880  static size_type size(const T&) { return sizeof(T); }
5881  static const T* ptr(const T& value) { return &value; }
5882 };
5883 
5884 // Enable for subclasses of memory where we want to get a reference to the cl_mem out
5885 // and pass that in for safety
5886 template <typename T>
5887 struct KernelArgumentHandler<T, typename std::enable_if<std::is_base_of<cl::Memory, T>::value>::type>
5888 {
5889  static size_type size(const T&) { return sizeof(cl_mem); }
5890  static const cl_mem* ptr(const T& value) { return &(value()); }
5891 };
5892 
5893 // Specialization for DeviceCommandQueue defined later
5894 
5895 template <>
5897 {
5898  static size_type size(const LocalSpaceArg& value) { return value.size_; }
5899  static const void* ptr(const LocalSpaceArg&) { return NULL; }
5900 };
5901 
5902 }
5904 
5908 inline LocalSpaceArg
5909 Local(size_type size)
5910 {
5911  LocalSpaceArg ret = { size };
5912  return ret;
5913 }
5914 
5923 class Kernel : public detail::Wrapper<cl_kernel>
5924 {
5925 public:
5926  inline Kernel(const Program& program, const char* name, cl_int* err = NULL);
5927 
5929  Kernel() { }
5930 
5939  explicit Kernel(const cl_kernel& kernel, bool retainObject = false) :
5940  detail::Wrapper<cl_type>(kernel, retainObject) { }
5941 
5947  Kernel& operator = (const cl_kernel& rhs)
5948  {
5950  return *this;
5951  }
5952 
5956  Kernel(const Kernel& kernel) : detail::Wrapper<cl_type>(kernel) {}
5957 
5961  Kernel& operator = (const Kernel &kernel)
5962  {
5964  return *this;
5965  }
5966 
5970  Kernel(Kernel&& kernel) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(kernel)) {}
5971 
5976  {
5977  detail::Wrapper<cl_type>::operator=(std::move(kernel));
5978  return *this;
5979  }
5980 
5981  template <typename T>
5982  cl_int getInfo(cl_kernel_info name, T* param) const
5983  {
5984  return detail::errHandler(
5985  detail::getInfo(&::clGetKernelInfo, object_, name, param),
5986  __GET_KERNEL_INFO_ERR);
5987  }
5988 
5989  template <cl_kernel_info name> typename
5990  detail::param_traits<detail::cl_kernel_info, name>::param_type
5991  getInfo(cl_int* err = NULL) const
5992  {
5993  typename detail::param_traits<
5994  detail::cl_kernel_info, name>::param_type param;
5995  cl_int result = getInfo(name, &param);
5996  if (err != NULL) {
5997  *err = result;
5998  }
5999  return param;
6000  }
6001 
6002 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6003  template <typename T>
6004  cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const
6005  {
6006  return detail::errHandler(
6007  detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param),
6008  __GET_KERNEL_ARG_INFO_ERR);
6009  }
6010 
6011  template <cl_kernel_arg_info name> typename
6012  detail::param_traits<detail::cl_kernel_arg_info, name>::param_type
6013  getArgInfo(cl_uint argIndex, cl_int* err = NULL) const
6014  {
6015  typename detail::param_traits<
6016  detail::cl_kernel_arg_info, name>::param_type param;
6017  cl_int result = getArgInfo(argIndex, name, &param);
6018  if (err != NULL) {
6019  *err = result;
6020  }
6021  return param;
6022  }
6023 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6024 
6025  template <typename T>
6026  cl_int getWorkGroupInfo(
6027  const Device& device, cl_kernel_work_group_info name, T* param) const
6028  {
6029  return detail::errHandler(
6030  detail::getInfo(
6031  &::clGetKernelWorkGroupInfo, object_, device(), name, param),
6032  __GET_KERNEL_WORK_GROUP_INFO_ERR);
6033  }
6034 
6035  template <cl_kernel_work_group_info name> typename
6036  detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
6037  getWorkGroupInfo(const Device& device, cl_int* err = NULL) const
6038  {
6039  typename detail::param_traits<
6040  detail::cl_kernel_work_group_info, name>::param_type param;
6041  cl_int result = getWorkGroupInfo(device, name, &param);
6042  if (err != NULL) {
6043  *err = result;
6044  }
6045  return param;
6046  }
6047 
6048 #if (CL_HPP_TARGET_OPENCL_VERSION >= 200 && defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)) || CL_HPP_TARGET_OPENCL_VERSION >= 210
6049  cl_int getSubGroupInfo(const cl::Device &dev, cl_kernel_sub_group_info name, const cl::NDRange &range, size_type* param) const
6050  {
6051 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6052 
6053  return detail::errHandler(
6054  clGetKernelSubGroupInfo(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
6055  __GET_KERNEL_SUB_GROUP_INFO_ERR);
6056 
6057 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6058 
6059  typedef clGetKernelSubGroupInfoKHR_fn PFN_clGetKernelSubGroupInfoKHR;
6060  static PFN_clGetKernelSubGroupInfoKHR pfn_clGetKernelSubGroupInfoKHR = NULL;
6061  CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetKernelSubGroupInfoKHR);
6062 
6063  return detail::errHandler(
6064  pfn_clGetKernelSubGroupInfoKHR(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
6065  __GET_KERNEL_SUB_GROUP_INFO_ERR);
6066 
6067 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6068  }
6069 
6070  template <cl_kernel_sub_group_info name>
6071  size_type getSubGroupInfo(const cl::Device &dev, const cl::NDRange &range, cl_int* err = NULL) const
6072  {
6073  size_type param;
6074  cl_int result = getSubGroupInfo(dev, name, range, &param);
6075  if (err != NULL) {
6076  *err = result;
6077  }
6078  return param;
6079  }
6080 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6081 
6082 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6085  template<typename T, class D>
6086  cl_int setArg(cl_uint index, const cl::pointer<T, D> &argPtr)
6087  {
6088  return detail::errHandler(
6089  ::clSetKernelArgSVMPointer(object_, index, argPtr.get()),
6090  __SET_KERNEL_ARGS_ERR);
6091  }
6092 
6095  template<typename T, class Alloc>
6096  cl_int setArg(cl_uint index, const cl::vector<T, Alloc> &argPtr)
6097  {
6098  return detail::errHandler(
6099  ::clSetKernelArgSVMPointer(object_, index, argPtr.data()),
6100  __SET_KERNEL_ARGS_ERR);
6101  }
6102 
6105  template<typename T>
6106  typename std::enable_if<std::is_pointer<T>::value, cl_int>::type
6107  setArg(cl_uint index, const T argPtr)
6108  {
6109  return detail::errHandler(
6110  ::clSetKernelArgSVMPointer(object_, index, argPtr),
6111  __SET_KERNEL_ARGS_ERR);
6112  }
6113 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6114 
6117  template <typename T>
6118  typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6119  setArg(cl_uint index, const T &value)
6120  {
6121  return detail::errHandler(
6122  ::clSetKernelArg(
6123  object_,
6124  index,
6127  __SET_KERNEL_ARGS_ERR);
6128  }
6129 
6130  cl_int setArg(cl_uint index, size_type size, const void* argPtr)
6131  {
6132  return detail::errHandler(
6133  ::clSetKernelArg(object_, index, size, argPtr),
6134  __SET_KERNEL_ARGS_ERR);
6135  }
6136 
6137 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6142  cl_int setSVMPointers(const vector<void*> &pointerList)
6143  {
6144  return detail::errHandler(
6145  ::clSetKernelExecInfo(
6146  object_,
6147  CL_KERNEL_EXEC_INFO_SVM_PTRS,
6148  sizeof(void*)*pointerList.size(),
6149  pointerList.data()));
6150  }
6151 
6156  template<int ArrayLength>
6157  cl_int setSVMPointers(const std::array<void*, ArrayLength> &pointerList)
6158  {
6159  return detail::errHandler(
6160  ::clSetKernelExecInfo(
6161  object_,
6162  CL_KERNEL_EXEC_INFO_SVM_PTRS,
6163  sizeof(void*)*pointerList.size(),
6164  pointerList.data()));
6165  }
6166 
6178  cl_int enableFineGrainedSystemSVM(bool svmEnabled)
6179  {
6180  cl_bool svmEnabled_ = svmEnabled ? CL_TRUE : CL_FALSE;
6181  return detail::errHandler(
6182  ::clSetKernelExecInfo(
6183  object_,
6184  CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM,
6185  sizeof(cl_bool),
6186  &svmEnabled_
6187  )
6188  );
6189  }
6190 
6191  template<int index, int ArrayLength, class D, typename T0, typename T1, typename... Ts>
6192  void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0, const pointer<T1, D> &t1, Ts & ... ts)
6193  {
6194  pointerList[index] = static_cast<void*>(t0.get());
6195  setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6196  }
6197 
6198  template<int index, int ArrayLength, typename T0, typename T1, typename... Ts>
6199  typename std::enable_if<std::is_pointer<T0>::value, void>::type
6200  setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0, T1 t1, Ts... ts)
6201  {
6202  pointerList[index] = static_cast<void*>(t0);
6203  setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6204  }
6205 
6206  template<int index, int ArrayLength, typename T0, class D>
6207  void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0)
6208  {
6209  pointerList[index] = static_cast<void*>(t0.get());
6210  }
6211 
6212 
6213  template<int index, int ArrayLength, typename T0>
6214  typename std::enable_if<std::is_pointer<T0>::value, void>::type
6215  setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0)
6216  {
6217  pointerList[index] = static_cast<void*>(t0);
6218  }
6219 
6220  template<typename T0, typename... Ts>
6221  cl_int setSVMPointers(const T0 &t0, Ts & ... ts)
6222  {
6223  std::array<void*, 1 + sizeof...(Ts)> pointerList;
6224 
6225  setSVMPointersHelper<0, 1 + sizeof...(Ts)>(pointerList, t0, ts...);
6226  return detail::errHandler(
6227  ::clSetKernelExecInfo(
6228  object_,
6229  CL_KERNEL_EXEC_INFO_SVM_PTRS,
6230  sizeof(void*)*(1 + sizeof...(Ts)),
6231  pointerList.data()));
6232  }
6233 
6234  template<typename T>
6235  cl_int setExecInfo(cl_kernel_exec_info param_name, const T& val)
6236  {
6237  return detail::errHandler(
6238  ::clSetKernelExecInfo(
6239  object_,
6240  param_name,
6241  sizeof(T),
6242  &val));
6243  }
6244 
6245  template<cl_kernel_exec_info name>
6246  cl_int setExecInfo(typename detail::param_traits<detail::cl_kernel_exec_info, name>::param_type& val)
6247  {
6248  return setExecInfo(name, val);
6249  }
6250 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6251 
6252 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6259  {
6260  cl_int error;
6261  Kernel retValue(clCloneKernel(this->get(), &error));
6262 
6263  detail::errHandler(error, __CLONE_KERNEL_ERR);
6264  return retValue;
6265  }
6266 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6267 };
6268 
6272 class Program : public detail::Wrapper<cl_program>
6273 {
6274 public:
6275 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6276  typedef vector<vector<unsigned char>> Binaries;
6277  typedef vector<string> Sources;
6278 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6279  typedef vector<std::pair<const void*, size_type> > Binaries;
6280  typedef vector<std::pair<const char*, size_type> > Sources;
6281 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6282 
6283  Program(
6284  const string& source,
6285  bool build = false,
6286  cl_int* err = NULL)
6287  {
6288  cl_int error;
6289 
6290  const char * strings = source.c_str();
6291  const size_type length = source.size();
6292 
6293  Context context = Context::getDefault(err);
6294 
6295  object_ = ::clCreateProgramWithSource(
6296  context(), (cl_uint)1, &strings, &length, &error);
6297 
6298  detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6299 
6300  if (error == CL_SUCCESS && build) {
6301 
6302  error = ::clBuildProgram(
6303  object_,
6304  0,
6305  NULL,
6306 #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6307  "-cl-std=CL2.0",
6308 #else
6309  "",
6310 #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6311  NULL,
6312  NULL);
6313 
6314  detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6315  }
6316 
6317  if (err != NULL) {
6318  *err = error;
6319  }
6320  }
6321 
6322  Program(
6323  const Context& context,
6324  const string& source,
6325  bool build = false,
6326  cl_int* err = NULL)
6327  {
6328  cl_int error;
6329 
6330  const char * strings = source.c_str();
6331  const size_type length = source.size();
6332 
6333  object_ = ::clCreateProgramWithSource(
6334  context(), (cl_uint)1, &strings, &length, &error);
6335 
6336  detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6337 
6338  if (error == CL_SUCCESS && build) {
6339  error = ::clBuildProgram(
6340  object_,
6341  0,
6342  NULL,
6343 #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6344  "-cl-std=CL2.0",
6345 #else
6346  "",
6347 #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6348  NULL,
6349  NULL);
6350 
6351  detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6352  }
6353 
6354  if (err != NULL) {
6355  *err = error;
6356  }
6357  }
6358 
6364  const Sources& sources,
6365  cl_int* err = NULL)
6366  {
6367  cl_int error;
6368  Context context = Context::getDefault(err);
6369 
6370  const size_type n = (size_type)sources.size();
6371 
6372  vector<size_type> lengths(n);
6373  vector<const char*> strings(n);
6374 
6375  for (size_type i = 0; i < n; ++i) {
6376 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6377  strings[i] = sources[(int)i].data();
6378  lengths[i] = sources[(int)i].length();
6379 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6380  strings[i] = sources[(int)i].first;
6381  lengths[i] = sources[(int)i].second;
6382 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6383  }
6384 
6385  object_ = ::clCreateProgramWithSource(
6386  context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6387 
6388  detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6389  if (err != NULL) {
6390  *err = error;
6391  }
6392  }
6393 
6399  const Context& context,
6400  const Sources& sources,
6401  cl_int* err = NULL)
6402  {
6403  cl_int error;
6404 
6405  const size_type n = (size_type)sources.size();
6406 
6407  vector<size_type> lengths(n);
6408  vector<const char*> strings(n);
6409 
6410  for (size_type i = 0; i < n; ++i) {
6411 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6412  strings[i] = sources[(int)i].data();
6413  lengths[i] = sources[(int)i].length();
6414 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6415  strings[i] = sources[(int)i].first;
6416  lengths[i] = sources[(int)i].second;
6417 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6418  }
6419 
6420  object_ = ::clCreateProgramWithSource(
6421  context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6422 
6423  detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6424  if (err != NULL) {
6425  *err = error;
6426  }
6427  }
6428 
6429 
6430 #if CL_HPP_TARGET_OPENCL_VERSION >= 210 || (CL_HPP_TARGET_OPENCL_VERSION==200 && defined(CL_HPP_USE_IL_KHR))
6436  const vector<char>& IL,
6437  bool build = false,
6438  cl_int* err = NULL)
6439  {
6440  cl_int error;
6441 
6442  Context context = Context::getDefault(err);
6443 
6444 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6445 
6446  object_ = ::clCreateProgramWithIL(
6447  context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6448 
6449 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6450 
6451  typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6452  static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6453  CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6454 
6455  object_ = pfn_clCreateProgramWithILKHR(
6456  context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6457 
6458 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6459 
6460  detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6461 
6462  if (error == CL_SUCCESS && build) {
6463 
6464  error = ::clBuildProgram(
6465  object_,
6466  0,
6467  NULL,
6468 #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6469  "-cl-std=CL2.0",
6470 #else
6471  "",
6472 #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6473  NULL,
6474  NULL);
6475 
6476  detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6477  }
6478 
6479  if (err != NULL) {
6480  *err = error;
6481  }
6482  }
6483 
6490  const Context& context,
6491  const vector<char>& IL,
6492  bool build = false,
6493  cl_int* err = NULL)
6494  {
6495  cl_int error;
6496 
6497 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6498 
6499  object_ = ::clCreateProgramWithIL(
6500  context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6501 
6502 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6503 
6504  typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6505  static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6506  CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6507 
6508  object_ = pfn_clCreateProgramWithILKHR(
6509  context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6510 
6511 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6512 
6513  detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6514 
6515  if (error == CL_SUCCESS && build) {
6516  error = ::clBuildProgram(
6517  object_,
6518  0,
6519  NULL,
6520 #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6521  "-cl-std=CL2.0",
6522 #else
6523  "",
6524 #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6525  NULL,
6526  NULL);
6527 
6528  detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6529  }
6530 
6531  if (err != NULL) {
6532  *err = error;
6533  }
6534  }
6535 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6536 
6557  const Context& context,
6558  const vector<Device>& devices,
6559  const Binaries& binaries,
6560  vector<cl_int>* binaryStatus = NULL,
6561  cl_int* err = NULL)
6562  {
6563  cl_int error;
6564 
6565  const size_type numDevices = devices.size();
6566 
6567  // Catch size mismatch early and return
6568  if(binaries.size() != numDevices) {
6569  error = CL_INVALID_VALUE;
6570  detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6571  if (err != NULL) {
6572  *err = error;
6573  }
6574  return;
6575  }
6576 
6577 
6578  vector<size_type> lengths(numDevices);
6579  vector<const unsigned char*> images(numDevices);
6580 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6581  for (size_type i = 0; i < numDevices; ++i) {
6582  images[i] = binaries[i].data();
6583  lengths[i] = binaries[(int)i].size();
6584  }
6585 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6586  for (size_type i = 0; i < numDevices; ++i) {
6587  images[i] = (const unsigned char*)binaries[i].first;
6588  lengths[i] = binaries[(int)i].second;
6589  }
6590 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6591 
6592  vector<cl_device_id> deviceIDs(numDevices);
6593  for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6594  deviceIDs[deviceIndex] = (devices[deviceIndex])();
6595  }
6596 
6597  if(binaryStatus) {
6598  binaryStatus->resize(numDevices);
6599  }
6600 
6601  object_ = ::clCreateProgramWithBinary(
6602  context(), (cl_uint) devices.size(),
6603  deviceIDs.data(),
6604  lengths.data(), images.data(), (binaryStatus != NULL && numDevices > 0)
6605  ? &binaryStatus->front()
6606  : NULL, &error);
6607 
6608  detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6609  if (err != NULL) {
6610  *err = error;
6611  }
6612  }
6613 
6614 
6615 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6621  const Context& context,
6622  const vector<Device>& devices,
6623  const string& kernelNames,
6624  cl_int* err = NULL)
6625  {
6626  cl_int error;
6627 
6628 
6629  size_type numDevices = devices.size();
6630  vector<cl_device_id> deviceIDs(numDevices);
6631  for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6632  deviceIDs[deviceIndex] = (devices[deviceIndex])();
6633  }
6634 
6635  object_ = ::clCreateProgramWithBuiltInKernels(
6636  context(),
6637  (cl_uint) devices.size(),
6638  deviceIDs.data(),
6639  kernelNames.c_str(),
6640  &error);
6641 
6642  detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR);
6643  if (err != NULL) {
6644  *err = error;
6645  }
6646  }
6647 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6648 
6649  Program() { }
6650 
6651 
6658  explicit Program(const cl_program& program, bool retainObject = false) :
6659  detail::Wrapper<cl_type>(program, retainObject) { }
6660 
6661  Program& operator = (const cl_program& rhs)
6662  {
6664  return *this;
6665  }
6666 
6670  Program(const Program& program) : detail::Wrapper<cl_type>(program) {}
6671 
6675  Program& operator = (const Program &program)
6676  {
6678  return *this;
6679  }
6680 
6684  Program(Program&& program) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(program)) {}
6685 
6689  Program& operator = (Program &&program)
6690  {
6691  detail::Wrapper<cl_type>::operator=(std::move(program));
6692  return *this;
6693  }
6694 
6695  cl_int build(
6696  const vector<Device>& devices,
6697  const char* options = NULL,
6698  void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6699  void* data = NULL) const
6700  {
6701  size_type numDevices = devices.size();
6702  vector<cl_device_id> deviceIDs(numDevices);
6703 
6704  for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6705  deviceIDs[deviceIndex] = (devices[deviceIndex])();
6706  }
6707 
6708  cl_int buildError = ::clBuildProgram(
6709  object_,
6710  (cl_uint)
6711  devices.size(),
6712  deviceIDs.data(),
6713  options,
6714  notifyFptr,
6715  data);
6716 
6717  return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6718  }
6719 
6720  cl_int build(
6721  const Device& device,
6722  const char* options = NULL,
6723  void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6724  void* data = NULL) const
6725  {
6726  cl_device_id deviceID = device();
6727 
6728  cl_int buildError = ::clBuildProgram(
6729  object_,
6730  1,
6731  &deviceID,
6732  options,
6733  notifyFptr,
6734  data);
6735 
6736  BuildLogType buildLog(0);
6737  buildLog.push_back(std::make_pair(device, getBuildInfo<CL_PROGRAM_BUILD_LOG>(device)));
6738  return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, buildLog);
6739  }
6740 
6741  cl_int build(
6742  const char* options = NULL,
6743  void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6744  void* data = NULL) const
6745  {
6746  cl_int buildError = ::clBuildProgram(
6747  object_,
6748  0,
6749  NULL,
6750  options,
6751  notifyFptr,
6752  data);
6753 
6754  return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6755  }
6756 
6757 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6758  cl_int compile(
6759  const char* options = NULL,
6760  void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6761  void* data = NULL) const
6762  {
6763  cl_int error = ::clCompileProgram(
6764  object_,
6765  0,
6766  NULL,
6767  options,
6768  0,
6769  NULL,
6770  NULL,
6771  notifyFptr,
6772  data);
6773  return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6774  }
6775 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6776 
6777  template <typename T>
6778  cl_int getInfo(cl_program_info name, T* param) const
6779  {
6780  return detail::errHandler(
6781  detail::getInfo(&::clGetProgramInfo, object_, name, param),
6782  __GET_PROGRAM_INFO_ERR);
6783  }
6784 
6785  template <cl_program_info name> typename
6786  detail::param_traits<detail::cl_program_info, name>::param_type
6787  getInfo(cl_int* err = NULL) const
6788  {
6789  typename detail::param_traits<
6790  detail::cl_program_info, name>::param_type param;
6791  cl_int result = getInfo(name, &param);
6792  if (err != NULL) {
6793  *err = result;
6794  }
6795  return param;
6796  }
6797 
6798  template <typename T>
6799  cl_int getBuildInfo(
6800  const Device& device, cl_program_build_info name, T* param) const
6801  {
6802  return detail::errHandler(
6803  detail::getInfo(
6804  &::clGetProgramBuildInfo, object_, device(), name, param),
6805  __GET_PROGRAM_BUILD_INFO_ERR);
6806  }
6807 
6808  template <cl_program_build_info name> typename
6809  detail::param_traits<detail::cl_program_build_info, name>::param_type
6810  getBuildInfo(const Device& device, cl_int* err = NULL) const
6811  {
6812  typename detail::param_traits<
6813  detail::cl_program_build_info, name>::param_type param;
6814  cl_int result = getBuildInfo(device, name, &param);
6815  if (err != NULL) {
6816  *err = result;
6817  }
6818  return param;
6819  }
6820 
6826  template <cl_program_build_info name>
6827  vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6828  getBuildInfo(cl_int *err = NULL) const
6829  {
6830  cl_int result = CL_SUCCESS;
6831 
6832  auto devs = getInfo<CL_PROGRAM_DEVICES>(&result);
6833  vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6834  devInfo;
6835 
6836  // If there was an initial error from getInfo return the error
6837  if (result != CL_SUCCESS) {
6838  if (err != NULL) {
6839  *err = result;
6840  }
6841  return devInfo;
6842  }
6843 
6844  for (const cl::Device &d : devs) {
6845  typename detail::param_traits<
6846  detail::cl_program_build_info, name>::param_type param;
6847  result = getBuildInfo(d, name, &param);
6848  devInfo.push_back(
6850  (d, param));
6851  if (result != CL_SUCCESS) {
6852  // On error, leave the loop and return the error code
6853  break;
6854  }
6855  }
6856  if (err != NULL) {
6857  *err = result;
6858  }
6859  if (result != CL_SUCCESS) {
6860  devInfo.clear();
6861  }
6862  return devInfo;
6863  }
6864 
6865  cl_int createKernels(vector<Kernel>* kernels)
6866  {
6867  cl_uint numKernels;
6868  cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
6869  if (err != CL_SUCCESS) {
6870  return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6871  }
6872 
6873  vector<cl_kernel> value(numKernels);
6874 
6875  err = ::clCreateKernelsInProgram(
6876  object_, numKernels, value.data(), NULL);
6877  if (err != CL_SUCCESS) {
6878  return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6879  }
6880 
6881  if (kernels) {
6882  kernels->resize(value.size());
6883 
6884  // Assign to param, constructing with retain behaviour
6885  // to correctly capture each underlying CL object
6886  for (size_type i = 0; i < value.size(); i++) {
6887  // We do not need to retain because this kernel is being created
6888  // by the runtime
6889  (*kernels)[i] = Kernel(value[i], false);
6890  }
6891  }
6892  return CL_SUCCESS;
6893  }
6894 
6895 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
6896 #if defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
6907  CL_API_PREFIX__VERSION_2_2_DEPRECATED cl_int setReleaseCallback(
6908  void (CL_CALLBACK * pfn_notify)(cl_program program, void * user_data),
6909  void * user_data = NULL) CL_API_SUFFIX__VERSION_2_2_DEPRECATED
6910  {
6911  return detail::errHandler(
6912  ::clSetProgramReleaseCallback(
6913  object_,
6914  pfn_notify,
6915  user_data),
6916  __SET_PROGRAM_RELEASE_CALLBACK_ERR);
6917  }
6918 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
6919 
6924  template <typename T>
6925  typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6926  setSpecializationConstant(cl_uint index, const T &value)
6927  {
6928  return detail::errHandler(
6929  ::clSetProgramSpecializationConstant(
6930  object_,
6931  index,
6932  sizeof(value),
6933  &value),
6934  __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6935  }
6936 
6941  cl_int setSpecializationConstant(cl_uint index, size_type size, const void* value)
6942  {
6943  return detail::errHandler(
6944  ::clSetProgramSpecializationConstant(
6945  object_,
6946  index,
6947  size,
6948  value),
6949  __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6950  }
6951 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
6952 };
6953 
6954 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6955 inline Program linkProgram(
6956  Program input1,
6957  Program input2,
6958  const char* options = NULL,
6959  void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6960  void* data = NULL,
6961  cl_int* err = NULL)
6962 {
6963  cl_int error_local = CL_SUCCESS;
6964 
6965  cl_program programs[2] = { input1(), input2() };
6966 
6967  Context ctx = input1.getInfo<CL_PROGRAM_CONTEXT>(&error_local);
6968  if(error_local!=CL_SUCCESS) {
6969  detail::errHandler(error_local, __LINK_PROGRAM_ERR);
6970  }
6971 
6972  cl_program prog = ::clLinkProgram(
6973  ctx(),
6974  0,
6975  NULL,
6976  options,
6977  2,
6978  programs,
6979  notifyFptr,
6980  data,
6981  &error_local);
6982 
6983  detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
6984  if (err != NULL) {
6985  *err = error_local;
6986  }
6987 
6988  return Program(prog);
6989 }
6990 
6991 inline Program linkProgram(
6992  vector<Program> inputPrograms,
6993  const char* options = NULL,
6994  void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6995  void* data = NULL,
6996  cl_int* err = NULL)
6997 {
6998  cl_int error_local = CL_SUCCESS;
6999 
7000  vector<cl_program> programs(inputPrograms.size());
7001 
7002  for (unsigned int i = 0; i < inputPrograms.size(); i++) {
7003  programs[i] = inputPrograms[i]();
7004  }
7005 
7006  Context ctx;
7007  if(inputPrograms.size() > 0) {
7008  ctx = inputPrograms[0].getInfo<CL_PROGRAM_CONTEXT>(&error_local);
7009  if(error_local!=CL_SUCCESS) {
7010  detail::errHandler(error_local, __LINK_PROGRAM_ERR);
7011  }
7012  }
7013  cl_program prog = ::clLinkProgram(
7014  ctx(),
7015  0,
7016  NULL,
7017  options,
7018  (cl_uint)inputPrograms.size(),
7019  programs.data(),
7020  notifyFptr,
7021  data,
7022  &error_local);
7023 
7024  detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
7025  if (err != NULL) {
7026  *err = error_local;
7027  }
7028 
7029  return Program(prog, false);
7030 }
7031 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7032 
7033 // Template specialization for CL_PROGRAM_BINARIES
7034 template <>
7035 inline cl_int cl::Program::getInfo(cl_program_info name, vector<vector<unsigned char>>* param) const
7036 {
7037  if (name != CL_PROGRAM_BINARIES) {
7038  return CL_INVALID_VALUE;
7039  }
7040  if (param) {
7041  // Resize the parameter array appropriately for each allocation
7042  // and pass down to the helper
7043 
7044  vector<size_type> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>();
7045  size_type numBinaries = sizes.size();
7046 
7047  // Resize the parameter array and constituent arrays
7048  param->resize(numBinaries);
7049  for (size_type i = 0; i < numBinaries; ++i) {
7050  (*param)[i].resize(sizes[i]);
7051  }
7052 
7053  return detail::errHandler(
7054  detail::getInfo(&::clGetProgramInfo, object_, name, param),
7055  __GET_PROGRAM_INFO_ERR);
7056  }
7057 
7058  return CL_SUCCESS;
7059 }
7060 
7061 template<>
7062 inline vector<vector<unsigned char>> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err) const
7063 {
7064  vector<vector<unsigned char>> binariesVectors;
7065 
7066  cl_int result = getInfo(CL_PROGRAM_BINARIES, &binariesVectors);
7067  if (err != NULL) {
7068  *err = result;
7069  }
7070  return binariesVectors;
7071 }
7072 
7073 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
7074 // Template specialization for clSetProgramSpecializationConstant
7075 template <>
7076 inline cl_int cl::Program::setSpecializationConstant(cl_uint index, const bool &value)
7077 {
7078  cl_uchar ucValue = value ? CL_UCHAR_MAX : 0;
7079  return detail::errHandler(
7080  ::clSetProgramSpecializationConstant(
7081  object_,
7082  index,
7083  sizeof(ucValue),
7084  &ucValue),
7085  __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
7086 }
7087 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
7088 
7089 inline Kernel::Kernel(const Program& program, const char* name, cl_int* err)
7090 {
7091  cl_int error;
7092 
7093  object_ = ::clCreateKernel(program(), name, &error);
7094  detail::errHandler(error, __CREATE_KERNEL_ERR);
7095 
7096  if (err != NULL) {
7097  *err = error;
7098  }
7099 
7100 }
7101 
7102 enum class QueueProperties : cl_command_queue_properties
7103 {
7104  None = 0,
7105  Profiling = CL_QUEUE_PROFILING_ENABLE,
7106  OutOfOrder = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,
7107 };
7108 
7109 inline QueueProperties operator|(QueueProperties lhs, QueueProperties rhs)
7110 {
7111  return static_cast<QueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
7112 }
7113 
7114 inline QueueProperties operator&(QueueProperties lhs, QueueProperties rhs)
7115 {
7116  return static_cast<QueueProperties>(static_cast<cl_command_queue_properties>(lhs) & static_cast<cl_command_queue_properties>(rhs));
7117 }
7118 
7122 class CommandQueue : public detail::Wrapper<cl_command_queue>
7123 {
7124 private:
7125  static std::once_flag default_initialized_;
7126  static CommandQueue default_;
7127  static cl_int default_error_;
7128 
7134  static void makeDefault()
7135  {
7136  /* We don't want to throw an error from this function, so we have to
7137  * catch and set the error flag.
7138  */
7139 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
7140  try
7141 #endif
7142  {
7143  int error;
7144  Context context = Context::getDefault(&error);
7145 
7146  if (error != CL_SUCCESS) {
7147  default_error_ = error;
7148  }
7149  else {
7150  Device device = Device::getDefault();
7151  default_ = CommandQueue(context, device, 0, &default_error_);
7152  }
7153  }
7154 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
7155  catch (cl::Error &e) {
7156  default_error_ = e.err();
7157  }
7158 #endif
7159  }
7160 
7166  static void makeDefaultProvided(const CommandQueue &c) {
7167  default_ = c;
7168  }
7169 
7170 public:
7171 #ifdef CL_HPP_UNIT_TEST_ENABLE
7178  static void unitTestClearDefault() {
7179  default_ = CommandQueue();
7180  }
7181 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
7182 
7183 
7189  cl_command_queue_properties properties,
7190  cl_int* err = NULL)
7191  {
7192  cl_int error;
7193 
7194  Context context = Context::getDefault(&error);
7195  detail::errHandler(error, __CREATE_CONTEXT_ERR);
7196 
7197  if (error != CL_SUCCESS) {
7198  if (err != NULL) {
7199  *err = error;
7200  }
7201  }
7202  else {
7203  Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7204  bool useWithProperties;
7205 
7206 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7207  // Run-time decision based on the actual platform
7208  {
7209  cl_uint version = detail::getContextPlatformVersion(context());
7210  useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7211  }
7212 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7213  useWithProperties = true;
7214 #else
7215  useWithProperties = false;
7216 #endif
7217 
7218 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7219  if (useWithProperties) {
7220  cl_queue_properties queue_properties[] = {
7221  CL_QUEUE_PROPERTIES, properties, 0 };
7222  if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7223  object_ = ::clCreateCommandQueueWithProperties(
7224  context(), device(), queue_properties, &error);
7225  }
7226  else {
7227  error = CL_INVALID_QUEUE_PROPERTIES;
7228  }
7229 
7230  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7231  if (err != NULL) {
7232  *err = error;
7233  }
7234  }
7235 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7236 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7237  if (!useWithProperties) {
7238  object_ = ::clCreateCommandQueue(
7239  context(), device(), properties, &error);
7240 
7241  detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7242  if (err != NULL) {
7243  *err = error;
7244  }
7245  }
7246 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7247  }
7248  }
7249 
7255  QueueProperties properties,
7256  cl_int* err = NULL)
7257  {
7258  cl_int error;
7259 
7260  Context context = Context::getDefault(&error);
7261  detail::errHandler(error, __CREATE_CONTEXT_ERR);
7262 
7263  if (error != CL_SUCCESS) {
7264  if (err != NULL) {
7265  *err = error;
7266  }
7267  }
7268  else {
7269  Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7270  bool useWithProperties;
7271 
7272 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7273  // Run-time decision based on the actual platform
7274  {
7275  cl_uint version = detail::getContextPlatformVersion(context());
7276  useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7277  }
7278 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7279  useWithProperties = true;
7280 #else
7281  useWithProperties = false;
7282 #endif
7283 
7284 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7285  if (useWithProperties) {
7286  cl_queue_properties queue_properties[] = {
7287  CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7288 
7289  object_ = ::clCreateCommandQueueWithProperties(
7290  context(), device(), queue_properties, &error);
7291 
7292  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7293  if (err != NULL) {
7294  *err = error;
7295  }
7296  }
7297 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7298 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7299  if (!useWithProperties) {
7300  object_ = ::clCreateCommandQueue(
7301  context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
7302 
7303  detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7304  if (err != NULL) {
7305  *err = error;
7306  }
7307  }
7308 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7309 
7310  }
7311  }
7312 
7317  explicit CommandQueue(
7318  const Context& context,
7319  cl_command_queue_properties properties = 0,
7320  cl_int* err = NULL)
7321  {
7322  cl_int error;
7323  bool useWithProperties;
7324  vector<cl::Device> devices;
7325  error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7326 
7327  detail::errHandler(error, __CREATE_CONTEXT_ERR);
7328 
7329  if (error != CL_SUCCESS)
7330  {
7331  if (err != NULL) {
7332  *err = error;
7333  }
7334  return;
7335  }
7336 
7337 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7338  // Run-time decision based on the actual platform
7339  {
7340  cl_uint version = detail::getContextPlatformVersion(context());
7341  useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7342  }
7343 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7344  useWithProperties = true;
7345 #else
7346  useWithProperties = false;
7347 #endif
7348 
7349 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7350  if (useWithProperties) {
7351  cl_queue_properties queue_properties[] = {
7352  CL_QUEUE_PROPERTIES, properties, 0 };
7353  if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7354  object_ = ::clCreateCommandQueueWithProperties(
7355  context(), devices[0](), queue_properties, &error);
7356  }
7357  else {
7358  error = CL_INVALID_QUEUE_PROPERTIES;
7359  }
7360 
7361  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7362  if (err != NULL) {
7363  *err = error;
7364  }
7365  }
7366 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7367 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7368  if (!useWithProperties) {
7369  object_ = ::clCreateCommandQueue(
7370  context(), devices[0](), properties, &error);
7371 
7372  detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7373  if (err != NULL) {
7374  *err = error;
7375  }
7376  }
7377 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7378  }
7379 
7384  explicit CommandQueue(
7385  const Context& context,
7386  QueueProperties properties,
7387  cl_int* err = NULL)
7388  {
7389  cl_int error;
7390  bool useWithProperties;
7391  vector<cl::Device> devices;
7392  error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7393 
7394  detail::errHandler(error, __CREATE_CONTEXT_ERR);
7395 
7396  if (error != CL_SUCCESS)
7397  {
7398  if (err != NULL) {
7399  *err = error;
7400  }
7401  return;
7402  }
7403 
7404 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7405  // Run-time decision based on the actual platform
7406  {
7407  cl_uint version = detail::getContextPlatformVersion(context());
7408  useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7409  }
7410 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7411  useWithProperties = true;
7412 #else
7413  useWithProperties = false;
7414 #endif
7415 
7416 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7417  if (useWithProperties) {
7418  cl_queue_properties queue_properties[] = {
7419  CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7420  object_ = ::clCreateCommandQueueWithProperties(
7421  context(), devices[0](), queue_properties, &error);
7422 
7423  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7424  if (err != NULL) {
7425  *err = error;
7426  }
7427  }
7428 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7429 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7430  if (!useWithProperties) {
7431  object_ = ::clCreateCommandQueue(
7432  context(), devices[0](), static_cast<cl_command_queue_properties>(properties), &error);
7433 
7434  detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7435  if (err != NULL) {
7436  *err = error;
7437  }
7438  }
7439 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7440  }
7441 
7447  const Context& context,
7448  const Device& device,
7449  cl_command_queue_properties properties = 0,
7450  cl_int* err = NULL)
7451  {
7452  cl_int error;
7453  bool useWithProperties;
7454 
7455 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7456  // Run-time decision based on the actual platform
7457  {
7458  cl_uint version = detail::getContextPlatformVersion(context());
7459  useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7460  }
7461 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7462  useWithProperties = true;
7463 #else
7464  useWithProperties = false;
7465 #endif
7466 
7467 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7468  if (useWithProperties) {
7469  cl_queue_properties queue_properties[] = {
7470  CL_QUEUE_PROPERTIES, properties, 0 };
7471  object_ = ::clCreateCommandQueueWithProperties(
7472  context(), device(), queue_properties, &error);
7473 
7474  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7475  if (err != NULL) {
7476  *err = error;
7477  }
7478  }
7479 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7480 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7481  if (!useWithProperties) {
7482  object_ = ::clCreateCommandQueue(
7483  context(), device(), properties, &error);
7484 
7485  detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7486  if (err != NULL) {
7487  *err = error;
7488  }
7489  }
7490 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7491  }
7492 
7498  const Context& context,
7499  const Device& device,
7500  QueueProperties properties,
7501  cl_int* err = NULL)
7502  {
7503  cl_int error;
7504  bool useWithProperties;
7505 
7506 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7507  // Run-time decision based on the actual platform
7508  {
7509  cl_uint version = detail::getContextPlatformVersion(context());
7510  useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7511  }
7512 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7513  useWithProperties = true;
7514 #else
7515  useWithProperties = false;
7516 #endif
7517 
7518 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7519  if (useWithProperties) {
7520  cl_queue_properties queue_properties[] = {
7521  CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7522  object_ = ::clCreateCommandQueueWithProperties(
7523  context(), device(), queue_properties, &error);
7524 
7525  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7526  if (err != NULL) {
7527  *err = error;
7528  }
7529  }
7530 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7531 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7532  if (!useWithProperties) {
7533  object_ = ::clCreateCommandQueue(
7534  context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
7535 
7536  detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7537  if (err != NULL) {
7538  *err = error;
7539  }
7540  }
7541 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7542  }
7543 
7544  static CommandQueue getDefault(cl_int * err = NULL)
7545  {
7546  std::call_once(default_initialized_, makeDefault);
7547 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7548  detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7549 #else // CL_HPP_TARGET_OPENCL_VERSION >= 200
7550  detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_ERR);
7551 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7552  if (err != NULL) {
7553  *err = default_error_;
7554  }
7555  return default_;
7556  }
7557 
7565  static CommandQueue setDefault(const CommandQueue &default_queue)
7566  {
7567  std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_queue));
7568  detail::errHandler(default_error_);
7569  return default_;
7570  }
7571 
7572  CommandQueue() { }
7573 
7574 
7581  explicit CommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
7582  detail::Wrapper<cl_type>(commandQueue, retainObject) { }
7583 
7584  CommandQueue& operator = (const cl_command_queue& rhs)
7585  {
7587  return *this;
7588  }
7589 
7593  CommandQueue(const CommandQueue& queue) : detail::Wrapper<cl_type>(queue) {}
7594 
7598  CommandQueue& operator = (const CommandQueue &queue)
7599  {
7601  return *this;
7602  }
7603 
7607  CommandQueue(CommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(queue)) {}
7608 
7612  CommandQueue& operator = (CommandQueue &&queue)
7613  {
7614  detail::Wrapper<cl_type>::operator=(std::move(queue));
7615  return *this;
7616  }
7617 
7618  template <typename T>
7619  cl_int getInfo(cl_command_queue_info name, T* param) const
7620  {
7621  return detail::errHandler(
7622  detail::getInfo(
7623  &::clGetCommandQueueInfo, object_, name, param),
7624  __GET_COMMAND_QUEUE_INFO_ERR);
7625  }
7626 
7627  template <cl_command_queue_info name> typename
7628  detail::param_traits<detail::cl_command_queue_info, name>::param_type
7629  getInfo(cl_int* err = NULL) const
7630  {
7631  typename detail::param_traits<
7632  detail::cl_command_queue_info, name>::param_type param;
7633  cl_int result = getInfo(name, &param);
7634  if (err != NULL) {
7635  *err = result;
7636  }
7637  return param;
7638  }
7639 
7640  cl_int enqueueReadBuffer(
7641  const Buffer& buffer,
7642  cl_bool blocking,
7643  size_type offset,
7644  size_type size,
7645  void* ptr,
7646  const vector<Event>* events = NULL,
7647  Event* event = NULL) const
7648  {
7649  cl_event tmp;
7650  cl_int err = detail::errHandler(
7651  ::clEnqueueReadBuffer(
7652  object_, buffer(), blocking, offset, size,
7653  ptr,
7654  (events != NULL) ? (cl_uint) events->size() : 0,
7655  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7656  (event != NULL) ? &tmp : NULL),
7657  __ENQUEUE_READ_BUFFER_ERR);
7658 
7659  if (event != NULL && err == CL_SUCCESS)
7660  *event = tmp;
7661 
7662  return err;
7663  }
7664 
7665  cl_int enqueueWriteBuffer(
7666  const Buffer& buffer,
7667  cl_bool blocking,
7668  size_type offset,
7669  size_type size,
7670  const void* ptr,
7671  const vector<Event>* events = NULL,
7672  Event* event = NULL) const
7673  {
7674  cl_event tmp;
7675  cl_int err = detail::errHandler(
7676  ::clEnqueueWriteBuffer(
7677  object_, buffer(), blocking, offset, size,
7678  ptr,
7679  (events != NULL) ? (cl_uint) events->size() : 0,
7680  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7681  (event != NULL) ? &tmp : NULL),
7682  __ENQUEUE_WRITE_BUFFER_ERR);
7683 
7684  if (event != NULL && err == CL_SUCCESS)
7685  *event = tmp;
7686 
7687  return err;
7688  }
7689 
7690  cl_int enqueueCopyBuffer(
7691  const Buffer& src,
7692  const Buffer& dst,
7693  size_type src_offset,
7694  size_type dst_offset,
7695  size_type size,
7696  const vector<Event>* events = NULL,
7697  Event* event = NULL) const
7698  {
7699  cl_event tmp;
7700  cl_int err = detail::errHandler(
7701  ::clEnqueueCopyBuffer(
7702  object_, src(), dst(), src_offset, dst_offset, size,
7703  (events != NULL) ? (cl_uint) events->size() : 0,
7704  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7705  (event != NULL) ? &tmp : NULL),
7706  __ENQEUE_COPY_BUFFER_ERR);
7707 
7708  if (event != NULL && err == CL_SUCCESS)
7709  *event = tmp;
7710 
7711  return err;
7712  }
7713 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
7714  cl_int enqueueReadBufferRect(
7715  const Buffer& buffer,
7716  cl_bool blocking,
7717  const array<size_type, 3>& buffer_offset,
7718  const array<size_type, 3>& host_offset,
7719  const array<size_type, 3>& region,
7720  size_type buffer_row_pitch,
7721  size_type buffer_slice_pitch,
7722  size_type host_row_pitch,
7723  size_type host_slice_pitch,
7724  void *ptr,
7725  const vector<Event>* events = NULL,
7726  Event* event = NULL) const
7727  {
7728  cl_event tmp;
7729  cl_int err = detail::errHandler(
7730  ::clEnqueueReadBufferRect(
7731  object_,
7732  buffer(),
7733  blocking,
7734  buffer_offset.data(),
7735  host_offset.data(),
7736  region.data(),
7737  buffer_row_pitch,
7738  buffer_slice_pitch,
7739  host_row_pitch,
7740  host_slice_pitch,
7741  ptr,
7742  (events != NULL) ? (cl_uint) events->size() : 0,
7743  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7744  (event != NULL) ? &tmp : NULL),
7745  __ENQUEUE_READ_BUFFER_RECT_ERR);
7746 
7747  if (event != NULL && err == CL_SUCCESS)
7748  *event = tmp;
7749 
7750  return err;
7751  }
7752 
7753  cl_int enqueueWriteBufferRect(
7754  const Buffer& buffer,
7755  cl_bool blocking,
7756  const array<size_type, 3>& buffer_offset,
7757  const array<size_type, 3>& host_offset,
7758  const array<size_type, 3>& region,
7759  size_type buffer_row_pitch,
7760  size_type buffer_slice_pitch,
7761  size_type host_row_pitch,
7762  size_type host_slice_pitch,
7763  const void *ptr,
7764  const vector<Event>* events = NULL,
7765  Event* event = NULL) const
7766  {
7767  cl_event tmp;
7768  cl_int err = detail::errHandler(
7769  ::clEnqueueWriteBufferRect(
7770  object_,
7771  buffer(),
7772  blocking,
7773  buffer_offset.data(),
7774  host_offset.data(),
7775  region.data(),
7776  buffer_row_pitch,
7777  buffer_slice_pitch,
7778  host_row_pitch,
7779  host_slice_pitch,
7780  ptr,
7781  (events != NULL) ? (cl_uint) events->size() : 0,
7782  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7783  (event != NULL) ? &tmp : NULL),
7784  __ENQUEUE_WRITE_BUFFER_RECT_ERR);
7785 
7786  if (event != NULL && err == CL_SUCCESS)
7787  *event = tmp;
7788 
7789  return err;
7790  }
7791 
7792  cl_int enqueueCopyBufferRect(
7793  const Buffer& src,
7794  const Buffer& dst,
7795  const array<size_type, 3>& src_origin,
7796  const array<size_type, 3>& dst_origin,
7797  const array<size_type, 3>& region,
7798  size_type src_row_pitch,
7799  size_type src_slice_pitch,
7800  size_type dst_row_pitch,
7801  size_type dst_slice_pitch,
7802  const vector<Event>* events = NULL,
7803  Event* event = NULL) const
7804  {
7805  cl_event tmp;
7806  cl_int err = detail::errHandler(
7807  ::clEnqueueCopyBufferRect(
7808  object_,
7809  src(),
7810  dst(),
7811  src_origin.data(),
7812  dst_origin.data(),
7813  region.data(),
7814  src_row_pitch,
7815  src_slice_pitch,
7816  dst_row_pitch,
7817  dst_slice_pitch,
7818  (events != NULL) ? (cl_uint) events->size() : 0,
7819  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7820  (event != NULL) ? &tmp : NULL),
7821  __ENQEUE_COPY_BUFFER_RECT_ERR);
7822 
7823  if (event != NULL && err == CL_SUCCESS)
7824  *event = tmp;
7825 
7826  return err;
7827  }
7828 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
7829 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
7841  template<typename PatternType>
7843  const Buffer& buffer,
7844  PatternType pattern,
7845  size_type offset,
7846  size_type size,
7847  const vector<Event>* events = NULL,
7848  Event* event = NULL) const
7849  {
7850  cl_event tmp;
7851  cl_int err = detail::errHandler(
7852  ::clEnqueueFillBuffer(
7853  object_,
7854  buffer(),
7855  static_cast<void*>(&pattern),
7856  sizeof(PatternType),
7857  offset,
7858  size,
7859  (events != NULL) ? (cl_uint) events->size() : 0,
7860  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7861  (event != NULL) ? &tmp : NULL),
7862  __ENQUEUE_FILL_BUFFER_ERR);
7863 
7864  if (event != NULL && err == CL_SUCCESS)
7865  *event = tmp;
7866 
7867  return err;
7868  }
7869 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7870 
7871  cl_int enqueueReadImage(
7872  const Image& image,
7873  cl_bool blocking,
7874  const array<size_type, 3>& origin,
7875  const array<size_type, 3>& region,
7876  size_type row_pitch,
7877  size_type slice_pitch,
7878  void* ptr,
7879  const vector<Event>* events = NULL,
7880  Event* event = NULL) const
7881  {
7882  cl_event tmp;
7883  cl_int err = detail::errHandler(
7884  ::clEnqueueReadImage(
7885  object_,
7886  image(),
7887  blocking,
7888  origin.data(),
7889  region.data(),
7890  row_pitch,
7891  slice_pitch,
7892  ptr,
7893  (events != NULL) ? (cl_uint) events->size() : 0,
7894  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7895  (event != NULL) ? &tmp : NULL),
7896  __ENQUEUE_READ_IMAGE_ERR);
7897 
7898  if (event != NULL && err == CL_SUCCESS)
7899  *event = tmp;
7900 
7901  return err;
7902  }
7903 
7904  cl_int enqueueWriteImage(
7905  const Image& image,
7906  cl_bool blocking,
7907  const array<size_type, 3>& origin,
7908  const array<size_type, 3>& region,
7909  size_type row_pitch,
7910  size_type slice_pitch,
7911  const void* ptr,
7912  const vector<Event>* events = NULL,
7913  Event* event = NULL) const
7914  {
7915  cl_event tmp;
7916  cl_int err = detail::errHandler(
7917  ::clEnqueueWriteImage(
7918  object_,
7919  image(),
7920  blocking,
7921  origin.data(),
7922  region.data(),
7923  row_pitch,
7924  slice_pitch,
7925  ptr,
7926  (events != NULL) ? (cl_uint) events->size() : 0,
7927  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7928  (event != NULL) ? &tmp : NULL),
7929  __ENQUEUE_WRITE_IMAGE_ERR);
7930 
7931  if (event != NULL && err == CL_SUCCESS)
7932  *event = tmp;
7933 
7934  return err;
7935  }
7936 
7937  cl_int enqueueCopyImage(
7938  const Image& src,
7939  const Image& dst,
7940  const array<size_type, 3>& src_origin,
7941  const array<size_type, 3>& dst_origin,
7942  const array<size_type, 3>& region,
7943  const vector<Event>* events = NULL,
7944  Event* event = NULL) const
7945  {
7946  cl_event tmp;
7947  cl_int err = detail::errHandler(
7948  ::clEnqueueCopyImage(
7949  object_,
7950  src(),
7951  dst(),
7952  src_origin.data(),
7953  dst_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_COPY_IMAGE_ERR);
7959 
7960  if (event != NULL && err == CL_SUCCESS)
7961  *event = tmp;
7962 
7963  return err;
7964  }
7965 
7966 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
7975  const Image& image,
7976  cl_float4 fillColor,
7977  const array<size_type, 3>& origin,
7978  const array<size_type, 3>& region,
7979  const vector<Event>* events = NULL,
7980  Event* event = NULL) const
7981  {
7982  cl_event tmp;
7983  cl_int err = detail::errHandler(
7984  ::clEnqueueFillImage(
7985  object_,
7986  image(),
7987  static_cast<void*>(&fillColor),
7988  origin.data(),
7989  region.data(),
7990  (events != NULL) ? (cl_uint) events->size() : 0,
7991  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7992  (event != NULL) ? &tmp : NULL),
7993  __ENQUEUE_FILL_IMAGE_ERR);
7994 
7995  if (event != NULL && err == CL_SUCCESS)
7996  *event = tmp;
7997 
7998  return err;
7999  }
8000 
8009  const Image& image,
8010  cl_int4 fillColor,
8011  const array<size_type, 3>& origin,
8012  const array<size_type, 3>& region,
8013  const vector<Event>* events = NULL,
8014  Event* event = NULL) const
8015  {
8016  cl_event tmp;
8017  cl_int err = detail::errHandler(
8018  ::clEnqueueFillImage(
8019  object_,
8020  image(),
8021  static_cast<void*>(&fillColor),
8022  origin.data(),
8023  region.data(),
8024  (events != NULL) ? (cl_uint) events->size() : 0,
8025  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8026  (event != NULL) ? &tmp : NULL),
8027  __ENQUEUE_FILL_IMAGE_ERR);
8028 
8029  if (event != NULL && err == CL_SUCCESS)
8030  *event = tmp;
8031 
8032  return err;
8033  }
8034 
8043  const Image& image,
8044  cl_uint4 fillColor,
8045  const array<size_type, 3>& origin,
8046  const array<size_type, 3>& region,
8047  const vector<Event>* events = NULL,
8048  Event* event = NULL) const
8049  {
8050  cl_event tmp;
8051  cl_int err = detail::errHandler(
8052  ::clEnqueueFillImage(
8053  object_,
8054  image(),
8055  static_cast<void*>(&fillColor),
8056  origin.data(),
8057  region.data(),
8058  (events != NULL) ? (cl_uint) events->size() : 0,
8059  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8060  (event != NULL) ? &tmp : NULL),
8061  __ENQUEUE_FILL_IMAGE_ERR);
8062 
8063  if (event != NULL && err == CL_SUCCESS)
8064  *event = tmp;
8065 
8066  return err;
8067  }
8068 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8069 
8070  cl_int enqueueCopyImageToBuffer(
8071  const Image& src,
8072  const Buffer& dst,
8073  const array<size_type, 3>& src_origin,
8074  const array<size_type, 3>& region,
8075  size_type dst_offset,
8076  const vector<Event>* events = NULL,
8077  Event* event = NULL) const
8078  {
8079  cl_event tmp;
8080  cl_int err = detail::errHandler(
8081  ::clEnqueueCopyImageToBuffer(
8082  object_,
8083  src(),
8084  dst(),
8085  src_origin.data(),
8086  region.data(),
8087  dst_offset,
8088  (events != NULL) ? (cl_uint) events->size() : 0,
8089  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8090  (event != NULL) ? &tmp : NULL),
8091  __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
8092 
8093  if (event != NULL && err == CL_SUCCESS)
8094  *event = tmp;
8095 
8096  return err;
8097  }
8098 
8099  cl_int enqueueCopyBufferToImage(
8100  const Buffer& src,
8101  const Image& dst,
8102  size_type src_offset,
8103  const array<size_type, 3>& dst_origin,
8104  const array<size_type, 3>& region,
8105  const vector<Event>* events = NULL,
8106  Event* event = NULL) const
8107  {
8108  cl_event tmp;
8109  cl_int err = detail::errHandler(
8110  ::clEnqueueCopyBufferToImage(
8111  object_,
8112  src(),
8113  dst(),
8114  src_offset,
8115  dst_origin.data(),
8116  region.data(),
8117  (events != NULL) ? (cl_uint) events->size() : 0,
8118  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8119  (event != NULL) ? &tmp : NULL),
8120  __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
8121 
8122  if (event != NULL && err == CL_SUCCESS)
8123  *event = tmp;
8124 
8125  return err;
8126  }
8127 
8128  void* enqueueMapBuffer(
8129  const Buffer& buffer,
8130  cl_bool blocking,
8131  cl_map_flags flags,
8132  size_type offset,
8133  size_type size,
8134  const vector<Event>* events = NULL,
8135  Event* event = NULL,
8136  cl_int* err = NULL) const
8137  {
8138  cl_event tmp;
8139  cl_int error;
8140  void * result = ::clEnqueueMapBuffer(
8141  object_, buffer(), blocking, flags, offset, size,
8142  (events != NULL) ? (cl_uint) events->size() : 0,
8143  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8144  (event != NULL) ? &tmp : NULL,
8145  &error);
8146 
8147  detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
8148  if (err != NULL) {
8149  *err = error;
8150  }
8151  if (event != NULL && error == CL_SUCCESS)
8152  *event = tmp;
8153 
8154  return result;
8155  }
8156 
8157  void* enqueueMapImage(
8158  const Image& buffer,
8159  cl_bool blocking,
8160  cl_map_flags flags,
8161  const array<size_type, 3>& origin,
8162  const array<size_type, 3>& region,
8163  size_type * row_pitch,
8164  size_type * slice_pitch,
8165  const vector<Event>* events = NULL,
8166  Event* event = NULL,
8167  cl_int* err = NULL) const
8168  {
8169  cl_event tmp;
8170  cl_int error;
8171  void * result = ::clEnqueueMapImage(
8172  object_, buffer(), blocking, flags,
8173  origin.data(),
8174  region.data(),
8175  row_pitch, slice_pitch,
8176  (events != NULL) ? (cl_uint) events->size() : 0,
8177  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8178  (event != NULL) ? &tmp : NULL,
8179  &error);
8180 
8181  detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
8182  if (err != NULL) {
8183  *err = error;
8184  }
8185  if (event != NULL && error == CL_SUCCESS)
8186  *event = tmp;
8187  return result;
8188  }
8189 
8190 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8195  template<typename T>
8197  T* ptr,
8198  cl_bool blocking,
8199  cl_map_flags flags,
8200  size_type size,
8201  const vector<Event>* events = NULL,
8202  Event* event = NULL) const
8203  {
8204  cl_event tmp;
8205  cl_int err = detail::errHandler(::clEnqueueSVMMap(
8206  object_, blocking, flags, static_cast<void*>(ptr), size,
8207  (events != NULL) ? (cl_uint)events->size() : 0,
8208  (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8209  (event != NULL) ? &tmp : NULL),
8210  __ENQUEUE_MAP_BUFFER_ERR);
8211 
8212  if (event != NULL && err == CL_SUCCESS)
8213  *event = tmp;
8214 
8215  return err;
8216  }
8217 
8218 
8223  template<typename T, class D>
8225  cl::pointer<T, D> &ptr,
8226  cl_bool blocking,
8227  cl_map_flags flags,
8228  size_type size,
8229  const vector<Event>* events = NULL,
8230  Event* event = NULL) const
8231  {
8232  cl_event tmp;
8233  cl_int err = detail::errHandler(::clEnqueueSVMMap(
8234  object_, blocking, flags, static_cast<void*>(ptr.get()), size,
8235  (events != NULL) ? (cl_uint)events->size() : 0,
8236  (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8237  (event != NULL) ? &tmp : NULL),
8238  __ENQUEUE_MAP_BUFFER_ERR);
8239 
8240  if (event != NULL && err == CL_SUCCESS)
8241  *event = tmp;
8242 
8243  return err;
8244  }
8245 
8250  template<typename T, class Alloc>
8252  cl::vector<T, Alloc> &container,
8253  cl_bool blocking,
8254  cl_map_flags flags,
8255  const vector<Event>* events = NULL,
8256  Event* event = NULL) const
8257  {
8258  cl_event tmp;
8259  cl_int err = detail::errHandler(::clEnqueueSVMMap(
8260  object_, blocking, flags, static_cast<void*>(container.data()), container.size()*sizeof(T),
8261  (events != NULL) ? (cl_uint)events->size() : 0,
8262  (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8263  (event != NULL) ? &tmp : NULL),
8264  __ENQUEUE_MAP_BUFFER_ERR);
8265 
8266  if (event != NULL && err == CL_SUCCESS)
8267  *event = tmp;
8268 
8269  return err;
8270  }
8271 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8272 
8273  cl_int enqueueUnmapMemObject(
8274  const Memory& memory,
8275  void* mapped_ptr,
8276  const vector<Event>* events = NULL,
8277  Event* event = NULL) const
8278  {
8279  cl_event tmp;
8280  cl_int err = detail::errHandler(
8281  ::clEnqueueUnmapMemObject(
8282  object_, memory(), mapped_ptr,
8283  (events != NULL) ? (cl_uint) events->size() : 0,
8284  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8285  (event != NULL) ? &tmp : NULL),
8286  __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8287 
8288  if (event != NULL && err == CL_SUCCESS)
8289  *event = tmp;
8290 
8291  return err;
8292  }
8293 
8294 
8295 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8300  template<typename T>
8302  T* ptr,
8303  const vector<Event>* events = NULL,
8304  Event* event = NULL) const
8305  {
8306  cl_event tmp;
8307  cl_int err = detail::errHandler(
8308  ::clEnqueueSVMUnmap(
8309  object_, static_cast<void*>(ptr),
8310  (events != NULL) ? (cl_uint)events->size() : 0,
8311  (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8312  (event != NULL) ? &tmp : NULL),
8313  __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8314 
8315  if (event != NULL && err == CL_SUCCESS)
8316  *event = tmp;
8317 
8318  return err;
8319  }
8320 
8325  template<typename T, class D>
8327  cl::pointer<T, D> &ptr,
8328  const vector<Event>* events = NULL,
8329  Event* event = NULL) const
8330  {
8331  cl_event tmp;
8332  cl_int err = detail::errHandler(
8333  ::clEnqueueSVMUnmap(
8334  object_, static_cast<void*>(ptr.get()),
8335  (events != NULL) ? (cl_uint)events->size() : 0,
8336  (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8337  (event != NULL) ? &tmp : NULL),
8338  __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8339 
8340  if (event != NULL && err == CL_SUCCESS)
8341  *event = tmp;
8342 
8343  return err;
8344  }
8345 
8350  template<typename T, class Alloc>
8352  cl::vector<T, Alloc> &container,
8353  const vector<Event>* events = NULL,
8354  Event* event = NULL) const
8355  {
8356  cl_event tmp;
8357  cl_int err = detail::errHandler(
8358  ::clEnqueueSVMUnmap(
8359  object_, static_cast<void*>(container.data()),
8360  (events != NULL) ? (cl_uint)events->size() : 0,
8361  (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8362  (event != NULL) ? &tmp : NULL),
8363  __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8364 
8365  if (event != NULL && err == CL_SUCCESS)
8366  *event = tmp;
8367 
8368  return err;
8369  }
8370 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8371 
8372 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8385  const vector<Event> *events = 0,
8386  Event *event = 0) const
8387  {
8388  cl_event tmp;
8389  cl_int err = detail::errHandler(
8390  ::clEnqueueMarkerWithWaitList(
8391  object_,
8392  (events != NULL) ? (cl_uint) events->size() : 0,
8393  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8394  (event != NULL) ? &tmp : NULL),
8395  __ENQUEUE_MARKER_WAIT_LIST_ERR);
8396 
8397  if (event != NULL && err == CL_SUCCESS)
8398  *event = tmp;
8399 
8400  return err;
8401  }
8402 
8415  const vector<Event> *events = 0,
8416  Event *event = 0) const
8417  {
8418  cl_event tmp;
8419  cl_int err = detail::errHandler(
8420  ::clEnqueueBarrierWithWaitList(
8421  object_,
8422  (events != NULL) ? (cl_uint) events->size() : 0,
8423  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8424  (event != NULL) ? &tmp : NULL),
8425  __ENQUEUE_BARRIER_WAIT_LIST_ERR);
8426 
8427  if (event != NULL && err == CL_SUCCESS)
8428  *event = tmp;
8429 
8430  return err;
8431  }
8432 
8438  const vector<Memory> &memObjects,
8439  cl_mem_migration_flags flags,
8440  const vector<Event>* events = NULL,
8441  Event* event = NULL
8442  ) const
8443  {
8444  cl_event tmp;
8445 
8446  vector<cl_mem> localMemObjects(memObjects.size());
8447 
8448  for( int i = 0; i < (int)memObjects.size(); ++i ) {
8449  localMemObjects[i] = memObjects[i]();
8450  }
8451 
8452  cl_int err = detail::errHandler(
8453  ::clEnqueueMigrateMemObjects(
8454  object_,
8455  (cl_uint)memObjects.size(),
8456  localMemObjects.data(),
8457  flags,
8458  (events != NULL) ? (cl_uint) events->size() : 0,
8459  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8460  (event != NULL) ? &tmp : NULL),
8461  __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8462 
8463  if (event != NULL && err == CL_SUCCESS)
8464  *event = tmp;
8465 
8466  return err;
8467  }
8468 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8469 
8470 
8471 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8477  template<typename T>
8479  const cl::vector<T*> &svmRawPointers,
8480  const cl::vector<size_type> &sizes,
8481  cl_mem_migration_flags flags = 0,
8482  const vector<Event>* events = NULL,
8483  Event* event = NULL) const
8484  {
8485  cl_event tmp;
8486  cl_int err = detail::errHandler(::clEnqueueSVMMigrateMem(
8487  object_,
8488  svmRawPointers.size(), static_cast<void**>(svmRawPointers.data()),
8489  sizes.data(), // array of sizes not passed
8490  flags,
8491  (events != NULL) ? (cl_uint)events->size() : 0,
8492  (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8493  (event != NULL) ? &tmp : NULL),
8494  __ENQUEUE_MIGRATE_SVM_ERR);
8495 
8496  if (event != NULL && err == CL_SUCCESS)
8497  *event = tmp;
8498 
8499  return err;
8500  }
8501 
8506  template<typename T>
8508  const cl::vector<T*> &svmRawPointers,
8509  cl_mem_migration_flags flags = 0,
8510  const vector<Event>* events = NULL,
8511  Event* event = NULL) const
8512  {
8513  return enqueueMigrateSVM(svmRawPointers, cl::vector<size_type>(svmRawPointers.size()), flags, events, event);
8514  }
8515 
8516 
8522  template<typename T, class D>
8524  const cl::vector<cl::pointer<T, D>> &svmPointers,
8525  const cl::vector<size_type> &sizes,
8526  cl_mem_migration_flags flags = 0,
8527  const vector<Event>* events = NULL,
8528  Event* event = NULL) const
8529  {
8530  cl::vector<void*> svmRawPointers;
8531  svmRawPointers.reserve(svmPointers.size());
8532  for (auto p : svmPointers) {
8533  svmRawPointers.push_back(static_cast<void*>(p.get()));
8534  }
8535 
8536  return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
8537  }
8538 
8539 
8544  template<typename T, class D>
8546  const cl::vector<cl::pointer<T, D>> &svmPointers,
8547  cl_mem_migration_flags flags = 0,
8548  const vector<Event>* events = NULL,
8549  Event* event = NULL) const
8550  {
8551  return enqueueMigrateSVM(svmPointers, cl::vector<size_type>(svmPointers.size()), flags, events, event);
8552  }
8553 
8559  template<typename T, class Alloc>
8561  const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8562  const cl::vector<size_type> &sizes,
8563  cl_mem_migration_flags flags = 0,
8564  const vector<Event>* events = NULL,
8565  Event* event = NULL) const
8566  {
8567  cl::vector<void*> svmRawPointers;
8568  svmRawPointers.reserve(svmContainers.size());
8569  for (auto p : svmContainers) {
8570  svmRawPointers.push_back(static_cast<void*>(p.data()));
8571  }
8572 
8573  return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
8574  }
8575 
8580  template<typename T, class Alloc>
8582  const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8583  cl_mem_migration_flags flags = 0,
8584  const vector<Event>* events = NULL,
8585  Event* event = NULL) const
8586  {
8587  return enqueueMigrateSVM(svmContainers, cl::vector<size_type>(svmContainers.size()), flags, events, event);
8588  }
8589 
8590 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8591 
8592  cl_int enqueueNDRangeKernel(
8593  const Kernel& kernel,
8594  const NDRange& offset,
8595  const NDRange& global,
8596  const NDRange& local = NullRange,
8597  const vector<Event>* events = NULL,
8598  Event* event = NULL) const
8599  {
8600  cl_event tmp;
8601  cl_int err = detail::errHandler(
8602  ::clEnqueueNDRangeKernel(
8603  object_, kernel(), (cl_uint) global.dimensions(),
8604  offset.dimensions() != 0 ? (const size_type*) offset : NULL,
8605  (const size_type*) global,
8606  local.dimensions() != 0 ? (const size_type*) local : NULL,
8607  (events != NULL) ? (cl_uint) events->size() : 0,
8608  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8609  (event != NULL) ? &tmp : NULL),
8610  __ENQUEUE_NDRANGE_KERNEL_ERR);
8611 
8612  if (event != NULL && err == CL_SUCCESS)
8613  *event = tmp;
8614 
8615  return err;
8616  }
8617 
8618 #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8619  CL_API_PREFIX__VERSION_1_2_DEPRECATED cl_int enqueueTask(
8620  const Kernel& kernel,
8621  const vector<Event>* events = NULL,
8622  Event* event = NULL) const CL_API_SUFFIX__VERSION_1_2_DEPRECATED
8623  {
8624  cl_event tmp;
8625  cl_int err = detail::errHandler(
8626  ::clEnqueueTask(
8627  object_, kernel(),
8628  (events != NULL) ? (cl_uint) events->size() : 0,
8629  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8630  (event != NULL) ? &tmp : NULL),
8631  __ENQUEUE_TASK_ERR);
8632 
8633  if (event != NULL && err == CL_SUCCESS)
8634  *event = tmp;
8635 
8636  return err;
8637  }
8638 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8639 
8640  cl_int enqueueNativeKernel(
8641  void (CL_CALLBACK *userFptr)(void *),
8642  std::pair<void*, size_type> args,
8643  const vector<Memory>* mem_objects = NULL,
8644  const vector<const void*>* mem_locs = NULL,
8645  const vector<Event>* events = NULL,
8646  Event* event = NULL) const
8647  {
8648  size_type elements = 0;
8649  if (mem_objects != NULL) {
8650  elements = mem_objects->size();
8651  }
8652  vector<cl_mem> mems(elements);
8653  for (unsigned int i = 0; i < elements; i++) {
8654  mems[i] = ((*mem_objects)[i])();
8655  }
8656 
8657  cl_event tmp;
8658  cl_int err = detail::errHandler(
8659  ::clEnqueueNativeKernel(
8660  object_, userFptr, args.first, args.second,
8661  (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8662  mems.data(),
8663  (mem_locs != NULL && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : NULL,
8664  (events != NULL) ? (cl_uint) events->size() : 0,
8665  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8666  (event != NULL) ? &tmp : NULL),
8667  __ENQUEUE_NATIVE_KERNEL);
8668 
8669  if (event != NULL && err == CL_SUCCESS)
8670  *event = tmp;
8671 
8672  return err;
8673  }
8674 
8678 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8679  CL_API_PREFIX__VERSION_1_1_DEPRECATED
8680  cl_int enqueueMarker(Event* event = NULL) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
8681  {
8682  cl_event tmp;
8683  cl_int err = detail::errHandler(
8684  ::clEnqueueMarker(
8685  object_,
8686  (event != NULL) ? &tmp : NULL),
8687  __ENQUEUE_MARKER_ERR);
8688 
8689  if (event != NULL && err == CL_SUCCESS)
8690  *event = tmp;
8691 
8692  return err;
8693  }
8694 
8695  CL_API_PREFIX__VERSION_1_1_DEPRECATED
8696  cl_int enqueueWaitForEvents(const vector<Event>& events) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
8697  {
8698  return detail::errHandler(
8699  ::clEnqueueWaitForEvents(
8700  object_,
8701  (cl_uint) events.size(),
8702  events.size() > 0 ? (const cl_event*) &events.front() : NULL),
8703  __ENQUEUE_WAIT_FOR_EVENTS_ERR);
8704  }
8705 #endif // defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8706 
8707  cl_int enqueueAcquireGLObjects(
8708  const vector<Memory>* mem_objects = NULL,
8709  const vector<Event>* events = NULL,
8710  Event* event = NULL) const
8711  {
8712  cl_event tmp;
8713  cl_int err = detail::errHandler(
8714  ::clEnqueueAcquireGLObjects(
8715  object_,
8716  (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8717  (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8718  (events != NULL) ? (cl_uint) events->size() : 0,
8719  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8720  (event != NULL) ? &tmp : NULL),
8721  __ENQUEUE_ACQUIRE_GL_ERR);
8722 
8723  if (event != NULL && err == CL_SUCCESS)
8724  *event = tmp;
8725 
8726  return err;
8727  }
8728 
8729  cl_int enqueueReleaseGLObjects(
8730  const vector<Memory>* mem_objects = NULL,
8731  const vector<Event>* events = NULL,
8732  Event* event = NULL) const
8733  {
8734  cl_event tmp;
8735  cl_int err = detail::errHandler(
8736  ::clEnqueueReleaseGLObjects(
8737  object_,
8738  (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8739  (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8740  (events != NULL) ? (cl_uint) events->size() : 0,
8741  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8742  (event != NULL) ? &tmp : NULL),
8743  __ENQUEUE_RELEASE_GL_ERR);
8744 
8745  if (event != NULL && err == CL_SUCCESS)
8746  *event = tmp;
8747 
8748  return err;
8749  }
8750 
8751 #if defined (CL_HPP_USE_DX_INTEROP)
8752 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
8753  cl_command_queue command_queue, cl_uint num_objects,
8754  const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8755  const cl_event* event_wait_list, cl_event* event);
8756 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
8757  cl_command_queue command_queue, cl_uint num_objects,
8758  const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8759  const cl_event* event_wait_list, cl_event* event);
8760 
8761  cl_int enqueueAcquireD3D10Objects(
8762  const vector<Memory>* mem_objects = NULL,
8763  const vector<Event>* events = NULL,
8764  Event* event = NULL) const
8765  {
8766  static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
8767 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8768  cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8769  cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8770  cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8771  CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireD3D10ObjectsKHR);
8772 #endif
8773 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
8774  CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueAcquireD3D10ObjectsKHR);
8775 #endif
8776 
8777  cl_event tmp;
8778  cl_int err = detail::errHandler(
8779  pfn_clEnqueueAcquireD3D10ObjectsKHR(
8780  object_,
8781  (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8782  (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8783  (events != NULL) ? (cl_uint) events->size() : 0,
8784  (events != NULL) ? (cl_event*) &events->front() : NULL,
8785  (event != NULL) ? &tmp : NULL),
8786  __ENQUEUE_ACQUIRE_GL_ERR);
8787 
8788  if (event != NULL && err == CL_SUCCESS)
8789  *event = tmp;
8790 
8791  return err;
8792  }
8793 
8794  cl_int enqueueReleaseD3D10Objects(
8795  const vector<Memory>* mem_objects = NULL,
8796  const vector<Event>* events = NULL,
8797  Event* event = NULL) const
8798  {
8799  static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL;
8800 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8801  cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8802  cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8803  cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8804  CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseD3D10ObjectsKHR);
8805 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8806 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
8807  CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueReleaseD3D10ObjectsKHR);
8808 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
8809 
8810  cl_event tmp;
8811  cl_int err = detail::errHandler(
8812  pfn_clEnqueueReleaseD3D10ObjectsKHR(
8813  object_,
8814  (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8815  (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8816  (events != NULL) ? (cl_uint) events->size() : 0,
8817  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8818  (event != NULL) ? &tmp : NULL),
8819  __ENQUEUE_RELEASE_GL_ERR);
8820 
8821  if (event != NULL && err == CL_SUCCESS)
8822  *event = tmp;
8823 
8824  return err;
8825  }
8826 #endif
8827 
8831 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8832  CL_API_PREFIX__VERSION_1_1_DEPRECATED
8833  cl_int enqueueBarrier() const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
8834  {
8835  return detail::errHandler(
8836  ::clEnqueueBarrier(object_),
8837  __ENQUEUE_BARRIER_ERR);
8838  }
8839 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
8840 
8841  cl_int flush() const
8842  {
8843  return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
8844  }
8845 
8846  cl_int finish() const
8847  {
8848  return detail::errHandler(::clFinish(object_), __FINISH_ERR);
8849  }
8850 }; // CommandQueue
8851 
8852 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::default_initialized_;
8853 CL_HPP_DEFINE_STATIC_MEMBER_ CommandQueue CommandQueue::default_;
8854 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int CommandQueue::default_error_ = CL_SUCCESS;
8855 
8856 
8857 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8858 enum class DeviceQueueProperties : cl_command_queue_properties
8859 {
8860  None = 0,
8861  Profiling = CL_QUEUE_PROFILING_ENABLE,
8862 };
8863 
8864 inline DeviceQueueProperties operator|(DeviceQueueProperties lhs, DeviceQueueProperties rhs)
8865 {
8866  return static_cast<DeviceQueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
8867 }
8868 
8872 class DeviceCommandQueue : public detail::Wrapper<cl_command_queue>
8873 {
8874 public:
8875 
8880 
8884  DeviceCommandQueue(DeviceQueueProperties properties, cl_int* err = NULL)
8885  {
8886  cl_int error;
8889 
8890  cl_command_queue_properties mergedProperties =
8891  CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8892 
8893  cl_queue_properties queue_properties[] = {
8894  CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8895  object_ = ::clCreateCommandQueueWithProperties(
8896  context(), device(), queue_properties, &error);
8897 
8898  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8899  if (err != NULL) {
8900  *err = error;
8901  }
8902  }
8903 
8908  const Context& context,
8909  const Device& device,
8910  DeviceQueueProperties properties = DeviceQueueProperties::None,
8911  cl_int* err = NULL)
8912  {
8913  cl_int error;
8914 
8915  cl_command_queue_properties mergedProperties =
8916  CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8917  cl_queue_properties queue_properties[] = {
8918  CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8919  object_ = ::clCreateCommandQueueWithProperties(
8920  context(), device(), queue_properties, &error);
8921 
8922  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8923  if (err != NULL) {
8924  *err = error;
8925  }
8926  }
8927 
8932  const Context& context,
8933  const Device& device,
8934  cl_uint queueSize,
8935  DeviceQueueProperties properties = DeviceQueueProperties::None,
8936  cl_int* err = NULL)
8937  {
8938  cl_int error;
8939 
8940  cl_command_queue_properties mergedProperties =
8941  CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8942  cl_queue_properties queue_properties[] = {
8943  CL_QUEUE_PROPERTIES, mergedProperties,
8944  CL_QUEUE_SIZE, queueSize,
8945  0 };
8946  object_ = ::clCreateCommandQueueWithProperties(
8947  context(), device(), queue_properties, &error);
8948 
8949  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8950  if (err != NULL) {
8951  *err = error;
8952  }
8953  }
8954 
8961  explicit DeviceCommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
8962  detail::Wrapper<cl_type>(commandQueue, retainObject) { }
8963 
8964  DeviceCommandQueue& operator = (const cl_command_queue& rhs)
8965  {
8967  return *this;
8968  }
8969 
8973  DeviceCommandQueue(const DeviceCommandQueue& queue) : detail::Wrapper<cl_type>(queue) {}
8974 
8978  DeviceCommandQueue& operator = (const DeviceCommandQueue &queue)
8979  {
8981  return *this;
8982  }
8983 
8987  DeviceCommandQueue(DeviceCommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(queue)) {}
8988 
8993  {
8994  detail::Wrapper<cl_type>::operator=(std::move(queue));
8995  return *this;
8996  }
8997 
8998  template <typename T>
8999  cl_int getInfo(cl_command_queue_info name, T* param) const
9000  {
9001  return detail::errHandler(
9002  detail::getInfo(
9003  &::clGetCommandQueueInfo, object_, name, param),
9004  __GET_COMMAND_QUEUE_INFO_ERR);
9005  }
9006 
9007  template <cl_command_queue_info name> typename
9008  detail::param_traits<detail::cl_command_queue_info, name>::param_type
9009  getInfo(cl_int* err = NULL) const
9010  {
9011  typename detail::param_traits<
9012  detail::cl_command_queue_info, name>::param_type param;
9013  cl_int result = getInfo(name, &param);
9014  if (err != NULL) {
9015  *err = result;
9016  }
9017  return param;
9018  }
9019 
9027  cl_int *err = nullptr)
9028  {
9029  cl_int error;
9032 
9033  cl_command_queue_properties properties =
9034  CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9035  cl_queue_properties queue_properties[] = {
9036  CL_QUEUE_PROPERTIES, properties,
9037  0 };
9038  DeviceCommandQueue deviceQueue(
9039  ::clCreateCommandQueueWithProperties(
9040  context(), device(), queue_properties, &error));
9041 
9042  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9043  if (err != NULL) {
9044  *err = error;
9045  }
9046 
9047  return deviceQueue;
9048  }
9049 
9057  const Context &context, const Device &device, cl_int *err = nullptr)
9058  {
9059  cl_int error;
9060 
9061  cl_command_queue_properties properties =
9062  CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9063  cl_queue_properties queue_properties[] = {
9064  CL_QUEUE_PROPERTIES, properties,
9065  0 };
9066  DeviceCommandQueue deviceQueue(
9067  ::clCreateCommandQueueWithProperties(
9068  context(), device(), queue_properties, &error));
9069 
9070  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9071  if (err != NULL) {
9072  *err = error;
9073  }
9074 
9075  return deviceQueue;
9076  }
9077 
9085  const Context &context, const Device &device, cl_uint queueSize, cl_int *err = nullptr)
9086  {
9087  cl_int error;
9088 
9089  cl_command_queue_properties properties =
9090  CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9091  cl_queue_properties queue_properties[] = {
9092  CL_QUEUE_PROPERTIES, properties,
9093  CL_QUEUE_SIZE, queueSize,
9094  0 };
9095  DeviceCommandQueue deviceQueue(
9096  ::clCreateCommandQueueWithProperties(
9097  context(), device(), queue_properties, &error));
9098 
9099  detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9100  if (err != NULL) {
9101  *err = error;
9102  }
9103 
9104  return deviceQueue;
9105  }
9106 
9107 
9108 
9109 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
9116  static DeviceCommandQueue updateDefault(const Context &context, const Device &device, const DeviceCommandQueue &default_queue, cl_int *err = nullptr)
9117  {
9118  cl_int error;
9119  error = clSetDefaultDeviceCommandQueue(context.get(), device.get(), default_queue.get());
9120 
9121  detail::errHandler(error, __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR);
9122  if (err != NULL) {
9123  *err = error;
9124  }
9125  return default_queue;
9126  }
9127 
9131  static DeviceCommandQueue getDefault(const CommandQueue &queue, cl_int * err = NULL)
9132  {
9133  return queue.getInfo<CL_QUEUE_DEVICE_DEFAULT>(err);
9134  }
9135 
9136 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
9137 }; // DeviceCommandQueue
9138 
9139 namespace detail
9140 {
9141  // Specialization for device command queue
9142  template <>
9144  {
9145  static size_type size(const cl::DeviceCommandQueue&) { return sizeof(cl_command_queue); }
9146  static const cl_command_queue* ptr(const cl::DeviceCommandQueue& value) { return &(value()); }
9147  };
9148 } // namespace detail
9149 
9150 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9151 
9152 
9153 template< typename IteratorType >
9155  const Context &context,
9156  IteratorType startIterator,
9157  IteratorType endIterator,
9158  bool readOnly,
9159  bool useHostPtr,
9160  cl_int* err)
9161 {
9162  typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9163  cl_int error;
9164 
9165  cl_mem_flags flags = 0;
9166  if( readOnly ) {
9167  flags |= CL_MEM_READ_ONLY;
9168  }
9169  else {
9170  flags |= CL_MEM_READ_WRITE;
9171  }
9172  if( useHostPtr ) {
9173  flags |= CL_MEM_USE_HOST_PTR;
9174  }
9175 
9176  size_type size = sizeof(DataType)*(endIterator - startIterator);
9177 
9178  if( useHostPtr ) {
9179  object_ = ::clCreateBuffer(context(), flags, size, const_cast<DataType*>(&*startIterator), &error);
9180  } else {
9181  object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9182  }
9183 
9184  detail::errHandler(error, __CREATE_BUFFER_ERR);
9185  if (err != NULL) {
9186  *err = error;
9187  }
9188 
9189  if( !useHostPtr ) {
9190  CommandQueue queue(context, 0, &error);
9191  detail::errHandler(error, __CREATE_BUFFER_ERR);
9192  if (err != NULL) {
9193  *err = error;
9194  }
9195 
9196  error = cl::copy(queue, startIterator, endIterator, *this);
9197  detail::errHandler(error, __CREATE_BUFFER_ERR);
9198  if (err != NULL) {
9199  *err = error;
9200  }
9201  }
9202 }
9203 
9204 template< typename IteratorType >
9206  const CommandQueue &queue,
9207  IteratorType startIterator,
9208  IteratorType endIterator,
9209  bool readOnly,
9210  bool useHostPtr,
9211  cl_int* err)
9212 {
9213  typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9214  cl_int error;
9215 
9216  cl_mem_flags flags = 0;
9217  if (readOnly) {
9218  flags |= CL_MEM_READ_ONLY;
9219  }
9220  else {
9221  flags |= CL_MEM_READ_WRITE;
9222  }
9223  if (useHostPtr) {
9224  flags |= CL_MEM_USE_HOST_PTR;
9225  }
9226 
9227  size_type size = sizeof(DataType)*(endIterator - startIterator);
9228 
9229  Context context = queue.getInfo<CL_QUEUE_CONTEXT>();
9230 
9231  if (useHostPtr) {
9232  object_ = ::clCreateBuffer(context(), flags, size, const_cast<DataType*>(&*startIterator), &error);
9233  }
9234  else {
9235  object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9236  }
9237 
9238  detail::errHandler(error, __CREATE_BUFFER_ERR);
9239  if (err != NULL) {
9240  *err = error;
9241  }
9242 
9243  if (!useHostPtr) {
9244  error = cl::copy(queue, startIterator, endIterator, *this);
9245  detail::errHandler(error, __CREATE_BUFFER_ERR);
9246  if (err != NULL) {
9247  *err = error;
9248  }
9249  }
9250 }
9251 
9252 inline cl_int enqueueReadBuffer(
9253  const Buffer& buffer,
9254  cl_bool blocking,
9255  size_type offset,
9256  size_type size,
9257  void* ptr,
9258  const vector<Event>* events = NULL,
9259  Event* event = NULL)
9260 {
9261  cl_int error;
9262  CommandQueue queue = CommandQueue::getDefault(&error);
9263 
9264  if (error != CL_SUCCESS) {
9265  return error;
9266  }
9267 
9268  return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event);
9269 }
9270 
9271 inline cl_int enqueueWriteBuffer(
9272  const Buffer& buffer,
9273  cl_bool blocking,
9274  size_type offset,
9275  size_type size,
9276  const void* ptr,
9277  const vector<Event>* events = NULL,
9278  Event* event = NULL)
9279 {
9280  cl_int error;
9281  CommandQueue queue = CommandQueue::getDefault(&error);
9282 
9283  if (error != CL_SUCCESS) {
9284  return error;
9285  }
9286 
9287  return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event);
9288 }
9289 
9290 inline void* enqueueMapBuffer(
9291  const Buffer& buffer,
9292  cl_bool blocking,
9293  cl_map_flags flags,
9294  size_type offset,
9295  size_type size,
9296  const vector<Event>* events = NULL,
9297  Event* event = NULL,
9298  cl_int* err = NULL)
9299 {
9300  cl_int error;
9301  CommandQueue queue = CommandQueue::getDefault(&error);
9302  detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9303  if (err != NULL) {
9304  *err = error;
9305  }
9306 
9307  void * result = ::clEnqueueMapBuffer(
9308  queue(), buffer(), blocking, flags, offset, size,
9309  (events != NULL) ? (cl_uint) events->size() : 0,
9310  (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
9311  (cl_event*) event,
9312  &error);
9313 
9314  detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9315  if (err != NULL) {
9316  *err = error;
9317  }
9318  return result;
9319 }
9320 
9321 
9322 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9328 template<typename T>
9329 inline cl_int enqueueMapSVM(
9330  T* ptr,
9331  cl_bool blocking,
9332  cl_map_flags flags,
9333  size_type size,
9334  const vector<Event>* events,
9335  Event* event)
9336 {
9337  cl_int error;
9338  CommandQueue queue = CommandQueue::getDefault(&error);
9339  if (error != CL_SUCCESS) {
9340  return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9341  }
9342 
9343  return queue.enqueueMapSVM(
9344  ptr, blocking, flags, size, events, event);
9345 }
9346 
9352 template<typename T, class D>
9353 inline cl_int enqueueMapSVM(
9354  cl::pointer<T, D> &ptr,
9355  cl_bool blocking,
9356  cl_map_flags flags,
9357  size_type size,
9358  const vector<Event>* events = NULL,
9359  Event* event = NULL)
9360 {
9361  cl_int error;
9362  CommandQueue queue = CommandQueue::getDefault(&error);
9363  if (error != CL_SUCCESS) {
9364  return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9365  }
9366 
9367  return queue.enqueueMapSVM(
9368  ptr, blocking, flags, size, events, event);
9369 }
9370 
9376 template<typename T, class Alloc>
9377 inline cl_int enqueueMapSVM(
9378  cl::vector<T, Alloc> &container,
9379  cl_bool blocking,
9380  cl_map_flags flags,
9381  const vector<Event>* events = NULL,
9382  Event* event = NULL)
9383 {
9384  cl_int error;
9385  CommandQueue queue = CommandQueue::getDefault(&error);
9386  if (error != CL_SUCCESS) {
9387  return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9388  }
9389 
9390  return queue.enqueueMapSVM(
9391  container, blocking, flags, events, event);
9392 }
9393 
9394 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9395 
9396 inline cl_int enqueueUnmapMemObject(
9397  const Memory& memory,
9398  void* mapped_ptr,
9399  const vector<Event>* events = NULL,
9400  Event* event = NULL)
9401 {
9402  cl_int error;
9403  CommandQueue queue = CommandQueue::getDefault(&error);
9404  detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9405  if (error != CL_SUCCESS) {
9406  return error;
9407  }
9408 
9409  cl_event tmp;
9410  cl_int err = detail::errHandler(
9411  ::clEnqueueUnmapMemObject(
9412  queue(), memory(), mapped_ptr,
9413  (events != NULL) ? (cl_uint)events->size() : 0,
9414  (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
9415  (event != NULL) ? &tmp : NULL),
9416  __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9417 
9418  if (event != NULL && err == CL_SUCCESS)
9419  *event = tmp;
9420 
9421  return err;
9422 }
9423 
9424 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9430 template<typename T>
9431 inline cl_int enqueueUnmapSVM(
9432  T* ptr,
9433  const vector<Event>* events = NULL,
9434  Event* event = NULL)
9435 {
9436  cl_int error;
9437  CommandQueue queue = CommandQueue::getDefault(&error);
9438  if (error != CL_SUCCESS) {
9439  return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9440  }
9441 
9442  return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
9443  __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9444 
9445 }
9446 
9452 template<typename T, class D>
9453 inline cl_int enqueueUnmapSVM(
9454  cl::pointer<T, D> &ptr,
9455  const vector<Event>* events = NULL,
9456  Event* event = NULL)
9457 {
9458  cl_int error;
9459  CommandQueue queue = CommandQueue::getDefault(&error);
9460  if (error != CL_SUCCESS) {
9461  return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9462  }
9463 
9464  return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
9465  __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9466 }
9467 
9473 template<typename T, class Alloc>
9474 inline cl_int enqueueUnmapSVM(
9475  cl::vector<T, Alloc> &container,
9476  const vector<Event>* events = NULL,
9477  Event* event = NULL)
9478 {
9479  cl_int error;
9480  CommandQueue queue = CommandQueue::getDefault(&error);
9481  if (error != CL_SUCCESS) {
9482  return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9483  }
9484 
9485  return detail::errHandler(queue.enqueueUnmapSVM(container, events, event),
9486  __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9487 }
9488 
9489 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9490 
9491 inline cl_int enqueueCopyBuffer(
9492  const Buffer& src,
9493  const Buffer& dst,
9494  size_type src_offset,
9495  size_type dst_offset,
9496  size_type size,
9497  const vector<Event>* events = NULL,
9498  Event* event = NULL)
9499 {
9500  cl_int error;
9501  CommandQueue queue = CommandQueue::getDefault(&error);
9502 
9503  if (error != CL_SUCCESS) {
9504  return error;
9505  }
9506 
9507  return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event);
9508 }
9509 
9515 template< typename IteratorType >
9516 inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
9517 {
9518  cl_int error;
9519  CommandQueue queue = CommandQueue::getDefault(&error);
9520  if (error != CL_SUCCESS)
9521  return error;
9522 
9523  return cl::copy(queue, startIterator, endIterator, buffer);
9524 }
9525 
9531 template< typename IteratorType >
9532 inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
9533 {
9534  cl_int error;
9535  CommandQueue queue = CommandQueue::getDefault(&error);
9536  if (error != CL_SUCCESS)
9537  return error;
9538 
9539  return cl::copy(queue, buffer, startIterator, endIterator);
9540 }
9541 
9547 template< typename IteratorType >
9548 inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
9549 {
9550  typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9551  cl_int error;
9552 
9553  size_type length = endIterator-startIterator;
9554  size_type byteLength = length*sizeof(DataType);
9555 
9556  DataType *pointer =
9557  static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error));
9558  // if exceptions enabled, enqueueMapBuffer will throw
9559  if( error != CL_SUCCESS ) {
9560  return error;
9561  }
9562 #if defined(_MSC_VER)
9563  std::copy(
9564  startIterator,
9565  endIterator,
9566  stdext::checked_array_iterator<DataType*>(
9567  pointer, length));
9568 #else
9569  std::copy(startIterator, endIterator, pointer);
9570 #endif
9571  Event endEvent;
9572  error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9573  // if exceptions enabled, enqueueUnmapMemObject will throw
9574  if( error != CL_SUCCESS ) {
9575  return error;
9576  }
9577  endEvent.wait();
9578  return CL_SUCCESS;
9579 }
9580 
9586 template< typename IteratorType >
9587 inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
9588 {
9589  typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9590  cl_int error;
9591 
9592  size_type length = endIterator-startIterator;
9593  size_type byteLength = length*sizeof(DataType);
9594 
9595  DataType *pointer =
9596  static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error));
9597  // if exceptions enabled, enqueueMapBuffer will throw
9598  if( error != CL_SUCCESS ) {
9599  return error;
9600  }
9601  std::copy(pointer, pointer + length, startIterator);
9602  Event endEvent;
9603  error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9604  // if exceptions enabled, enqueueUnmapMemObject will throw
9605  if( error != CL_SUCCESS ) {
9606  return error;
9607  }
9608  endEvent.wait();
9609  return CL_SUCCESS;
9610 }
9611 
9612 
9613 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9617 template<typename T, class Alloc>
9618 inline cl_int mapSVM(cl::vector<T, Alloc> &container)
9619 {
9620  return enqueueMapSVM(container, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE);
9621 }
9622 
9626 template<typename T, class Alloc>
9627 inline cl_int unmapSVM(cl::vector<T, Alloc> &container)
9628 {
9629  return enqueueUnmapSVM(container);
9630 }
9631 
9632 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9633 
9634 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
9635 inline cl_int enqueueReadBufferRect(
9636  const Buffer& buffer,
9637  cl_bool blocking,
9638  const array<size_type, 3>& buffer_offset,
9639  const array<size_type, 3>& host_offset,
9640  const array<size_type, 3>& region,
9641  size_type buffer_row_pitch,
9642  size_type buffer_slice_pitch,
9643  size_type host_row_pitch,
9644  size_type host_slice_pitch,
9645  void *ptr,
9646  const vector<Event>* events = NULL,
9647  Event* event = NULL)
9648 {
9649  cl_int error;
9650  CommandQueue queue = CommandQueue::getDefault(&error);
9651 
9652  if (error != CL_SUCCESS) {
9653  return error;
9654  }
9655 
9656  return queue.enqueueReadBufferRect(
9657  buffer,
9658  blocking,
9659  buffer_offset,
9660  host_offset,
9661  region,
9662  buffer_row_pitch,
9663  buffer_slice_pitch,
9664  host_row_pitch,
9665  host_slice_pitch,
9666  ptr,
9667  events,
9668  event);
9669 }
9670 
9671 inline cl_int enqueueWriteBufferRect(
9672  const Buffer& buffer,
9673  cl_bool blocking,
9674  const array<size_type, 3>& buffer_offset,
9675  const array<size_type, 3>& host_offset,
9676  const array<size_type, 3>& region,
9677  size_type buffer_row_pitch,
9678  size_type buffer_slice_pitch,
9679  size_type host_row_pitch,
9680  size_type host_slice_pitch,
9681  const void *ptr,
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.enqueueWriteBufferRect(
9693  buffer,
9694  blocking,
9695  buffer_offset,
9696  host_offset,
9697  region,
9698  buffer_row_pitch,
9699  buffer_slice_pitch,
9700  host_row_pitch,
9701  host_slice_pitch,
9702  ptr,
9703  events,
9704  event);
9705 }
9706 
9707 inline cl_int enqueueCopyBufferRect(
9708  const Buffer& src,
9709  const Buffer& dst,
9710  const array<size_type, 3>& src_origin,
9711  const array<size_type, 3>& dst_origin,
9712  const array<size_type, 3>& region,
9713  size_type src_row_pitch,
9714  size_type src_slice_pitch,
9715  size_type dst_row_pitch,
9716  size_type dst_slice_pitch,
9717  const vector<Event>* events = NULL,
9718  Event* event = NULL)
9719 {
9720  cl_int error;
9721  CommandQueue queue = CommandQueue::getDefault(&error);
9722 
9723  if (error != CL_SUCCESS) {
9724  return error;
9725  }
9726 
9727  return queue.enqueueCopyBufferRect(
9728  src,
9729  dst,
9730  src_origin,
9731  dst_origin,
9732  region,
9733  src_row_pitch,
9734  src_slice_pitch,
9735  dst_row_pitch,
9736  dst_slice_pitch,
9737  events,
9738  event);
9739 }
9740 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
9741 
9742 inline cl_int enqueueReadImage(
9743  const Image& image,
9744  cl_bool blocking,
9745  const array<size_type, 3>& origin,
9746  const array<size_type, 3>& region,
9747  size_type row_pitch,
9748  size_type slice_pitch,
9749  void* ptr,
9750  const vector<Event>* events = NULL,
9751  Event* event = NULL)
9752 {
9753  cl_int error;
9754  CommandQueue queue = CommandQueue::getDefault(&error);
9755 
9756  if (error != CL_SUCCESS) {
9757  return error;
9758  }
9759 
9760  return queue.enqueueReadImage(
9761  image,
9762  blocking,
9763  origin,
9764  region,
9765  row_pitch,
9766  slice_pitch,
9767  ptr,
9768  events,
9769  event);
9770 }
9771 
9772 inline cl_int enqueueWriteImage(
9773  const Image& image,
9774  cl_bool blocking,
9775  const array<size_type, 3>& origin,
9776  const array<size_type, 3>& region,
9777  size_type row_pitch,
9778  size_type slice_pitch,
9779  const void* ptr,
9780  const vector<Event>* events = NULL,
9781  Event* event = NULL)
9782 {
9783  cl_int error;
9784  CommandQueue queue = CommandQueue::getDefault(&error);
9785 
9786  if (error != CL_SUCCESS) {
9787  return error;
9788  }
9789 
9790  return queue.enqueueWriteImage(
9791  image,
9792  blocking,
9793  origin,
9794  region,
9795  row_pitch,
9796  slice_pitch,
9797  ptr,
9798  events,
9799  event);
9800 }
9801 
9802 inline cl_int enqueueCopyImage(
9803  const Image& src,
9804  const Image& dst,
9805  const array<size_type, 3>& src_origin,
9806  const array<size_type, 3>& dst_origin,
9807  const array<size_type, 3>& region,
9808  const vector<Event>* events = NULL,
9809  Event* event = NULL)
9810 {
9811  cl_int error;
9812  CommandQueue queue = CommandQueue::getDefault(&error);
9813 
9814  if (error != CL_SUCCESS) {
9815  return error;
9816  }
9817 
9818  return queue.enqueueCopyImage(
9819  src,
9820  dst,
9821  src_origin,
9822  dst_origin,
9823  region,
9824  events,
9825  event);
9826 }
9827 
9828 inline cl_int enqueueCopyImageToBuffer(
9829  const Image& src,
9830  const Buffer& dst,
9831  const array<size_type, 3>& src_origin,
9832  const array<size_type, 3>& region,
9833  size_type dst_offset,
9834  const vector<Event>* events = NULL,
9835  Event* event = NULL)
9836 {
9837  cl_int error;
9838  CommandQueue queue = CommandQueue::getDefault(&error);
9839 
9840  if (error != CL_SUCCESS) {
9841  return error;
9842  }
9843 
9844  return queue.enqueueCopyImageToBuffer(
9845  src,
9846  dst,
9847  src_origin,
9848  region,
9849  dst_offset,
9850  events,
9851  event);
9852 }
9853 
9854 inline cl_int enqueueCopyBufferToImage(
9855  const Buffer& src,
9856  const Image& dst,
9857  size_type src_offset,
9858  const array<size_type, 3>& dst_origin,
9859  const array<size_type, 3>& region,
9860  const vector<Event>* events = NULL,
9861  Event* event = NULL)
9862 {
9863  cl_int error;
9864  CommandQueue queue = CommandQueue::getDefault(&error);
9865 
9866  if (error != CL_SUCCESS) {
9867  return error;
9868  }
9869 
9870  return queue.enqueueCopyBufferToImage(
9871  src,
9872  dst,
9873  src_offset,
9874  dst_origin,
9875  region,
9876  events,
9877  event);
9878 }
9879 
9880 
9881 inline cl_int flush(void)
9882 {
9883  cl_int error;
9884  CommandQueue queue = CommandQueue::getDefault(&error);
9885 
9886  if (error != CL_SUCCESS) {
9887  return error;
9888  }
9889 
9890  return queue.flush();
9891 }
9892 
9893 inline cl_int finish(void)
9894 {
9895  cl_int error;
9896  CommandQueue queue = CommandQueue::getDefault(&error);
9897 
9898  if (error != CL_SUCCESS) {
9899  return error;
9900  }
9901 
9902 
9903  return queue.finish();
9904 }
9905 
9907 {
9908 private:
9909  CommandQueue queue_;
9910  const NDRange offset_;
9911  const NDRange global_;
9912  const NDRange local_;
9913  vector<Event> events_;
9914 
9915  template<typename... Ts>
9916  friend class KernelFunctor;
9917 
9918 public:
9919  EnqueueArgs(NDRange global) :
9920  queue_(CommandQueue::getDefault()),
9921  offset_(NullRange),
9922  global_(global),
9923  local_(NullRange)
9924  {
9925 
9926  }
9927 
9928  EnqueueArgs(NDRange global, NDRange local) :
9929  queue_(CommandQueue::getDefault()),
9930  offset_(NullRange),
9931  global_(global),
9932  local_(local)
9933  {
9934 
9935  }
9936 
9937  EnqueueArgs(NDRange offset, NDRange global, NDRange local) :
9938  queue_(CommandQueue::getDefault()),
9939  offset_(offset),
9940  global_(global),
9941  local_(local)
9942  {
9943 
9944  }
9945 
9946  EnqueueArgs(Event e, NDRange global) :
9947  queue_(CommandQueue::getDefault()),
9948  offset_(NullRange),
9949  global_(global),
9950  local_(NullRange)
9951  {
9952  events_.push_back(e);
9953  }
9954 
9955  EnqueueArgs(Event e, NDRange global, NDRange local) :
9956  queue_(CommandQueue::getDefault()),
9957  offset_(NullRange),
9958  global_(global),
9959  local_(local)
9960  {
9961  events_.push_back(e);
9962  }
9963 
9964  EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) :
9965  queue_(CommandQueue::getDefault()),
9966  offset_(offset),
9967  global_(global),
9968  local_(local)
9969  {
9970  events_.push_back(e);
9971  }
9972 
9973  EnqueueArgs(const vector<Event> &events, NDRange global) :
9974  queue_(CommandQueue::getDefault()),
9975  offset_(NullRange),
9976  global_(global),
9977  local_(NullRange),
9978  events_(events)
9979  {
9980 
9981  }
9982 
9983  EnqueueArgs(const vector<Event> &events, NDRange global, NDRange local) :
9984  queue_(CommandQueue::getDefault()),
9985  offset_(NullRange),
9986  global_(global),
9987  local_(local),
9988  events_(events)
9989  {
9990 
9991  }
9992 
9993  EnqueueArgs(const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
9994  queue_(CommandQueue::getDefault()),
9995  offset_(offset),
9996  global_(global),
9997  local_(local),
9998  events_(events)
9999  {
10000 
10001  }
10002 
10003  EnqueueArgs(CommandQueue &queue, NDRange global) :
10004  queue_(queue),
10005  offset_(NullRange),
10006  global_(global),
10007  local_(NullRange)
10008  {
10009 
10010  }
10011 
10012  EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) :
10013  queue_(queue),
10014  offset_(NullRange),
10015  global_(global),
10016  local_(local)
10017  {
10018 
10019  }
10020 
10021  EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) :
10022  queue_(queue),
10023  offset_(offset),
10024  global_(global),
10025  local_(local)
10026  {
10027 
10028  }
10029 
10030  EnqueueArgs(CommandQueue &queue, Event e, NDRange global) :
10031  queue_(queue),
10032  offset_(NullRange),
10033  global_(global),
10034  local_(NullRange)
10035  {
10036  events_.push_back(e);
10037  }
10038 
10039  EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) :
10040  queue_(queue),
10041  offset_(NullRange),
10042  global_(global),
10043  local_(local)
10044  {
10045  events_.push_back(e);
10046  }
10047 
10048  EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) :
10049  queue_(queue),
10050  offset_(offset),
10051  global_(global),
10052  local_(local)
10053  {
10054  events_.push_back(e);
10055  }
10056 
10057  EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global) :
10058  queue_(queue),
10059  offset_(NullRange),
10060  global_(global),
10061  local_(NullRange),
10062  events_(events)
10063  {
10064 
10065  }
10066 
10067  EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global, NDRange local) :
10068  queue_(queue),
10069  offset_(NullRange),
10070  global_(global),
10071  local_(local),
10072  events_(events)
10073  {
10074 
10075  }
10076 
10077  EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
10078  queue_(queue),
10079  offset_(offset),
10080  global_(global),
10081  local_(local),
10082  events_(events)
10083  {
10084 
10085  }
10086 };
10087 
10088 
10089 //----------------------------------------------------------------------------------------------
10090 
10091 
10096 template<typename... Ts>
10098 {
10099 private:
10100  Kernel kernel_;
10101 
10102  template<int index, typename T0, typename... T1s>
10103  void setArgs(T0&& t0, T1s&&... t1s)
10104  {
10105  kernel_.setArg(index, t0);
10106  setArgs<index + 1, T1s...>(std::forward<T1s>(t1s)...);
10107  }
10108 
10109  template<int index, typename T0>
10110  void setArgs(T0&& t0)
10111  {
10112  kernel_.setArg(index, t0);
10113  }
10114 
10115  template<int index>
10116  void setArgs()
10117  {
10118  }
10119 
10120 
10121 public:
10122  KernelFunctor(Kernel kernel) : kernel_(kernel)
10123  {}
10124 
10125  KernelFunctor(
10126  const Program& program,
10127  const string name,
10128  cl_int * err = NULL) :
10129  kernel_(program, name.c_str(), err)
10130  {}
10131 
10134 
10141  const EnqueueArgs& args,
10142  Ts... ts)
10143  {
10144  Event event;
10145  setArgs<0>(std::forward<Ts>(ts)...);
10146 
10147  args.queue_.enqueueNDRangeKernel(
10148  kernel_,
10149  args.offset_,
10150  args.global_,
10151  args.local_,
10152  &args.events_,
10153  &event);
10154 
10155  return event;
10156  }
10157 
10165  const EnqueueArgs& args,
10166  Ts... ts,
10167  cl_int &error)
10168  {
10169  Event event;
10170  setArgs<0>(std::forward<Ts>(ts)...);
10171 
10172  error = args.queue_.enqueueNDRangeKernel(
10173  kernel_,
10174  args.offset_,
10175  args.global_,
10176  args.local_,
10177  &args.events_,
10178  &event);
10179 
10180  return event;
10181  }
10182 
10183 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10184  cl_int setSVMPointers(const vector<void*> &pointerList)
10185  {
10186  return kernel_.setSVMPointers(pointerList);
10187  }
10188 
10189  template<typename T0, typename... T1s>
10190  cl_int setSVMPointers(const T0 &t0, T1s &... ts)
10191  {
10192  return kernel_.setSVMPointers(t0, ts...);
10193  }
10194 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10195 
10196  Kernel getKernel()
10197  {
10198  return kernel_;
10199  }
10200 };
10201 
10202 namespace compatibility {
10207  template<typename... Ts>
10209  {
10210  typedef KernelFunctor<Ts...> FunctorType;
10211 
10212  FunctorType functor_;
10213 
10214  make_kernel(
10215  const Program& program,
10216  const string name,
10217  cl_int * err = NULL) :
10218  functor_(FunctorType(program, name, err))
10219  {}
10220 
10221  make_kernel(
10222  const Kernel kernel) :
10223  functor_(FunctorType(kernel))
10224  {}
10225 
10228 
10230  typedef Event type_(
10231  const EnqueueArgs&,
10232  Ts...);
10233 
10234  Event operator()(
10235  const EnqueueArgs& enqueueArgs,
10236  Ts... args)
10237  {
10238  return functor_(
10239  enqueueArgs, args...);
10240  }
10241  };
10242 } // namespace compatibility
10243 
10244 
10245 //----------------------------------------------------------------------------------------------------------------------
10246 
10247 #undef CL_HPP_ERR_STR_
10248 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
10249 #undef __GET_DEVICE_INFO_ERR
10250 #undef __GET_PLATFORM_INFO_ERR
10251 #undef __GET_DEVICE_IDS_ERR
10252 #undef __GET_PLATFORM_IDS_ERR
10253 #undef __GET_CONTEXT_INFO_ERR
10254 #undef __GET_EVENT_INFO_ERR
10255 #undef __GET_EVENT_PROFILE_INFO_ERR
10256 #undef __GET_MEM_OBJECT_INFO_ERR
10257 #undef __GET_IMAGE_INFO_ERR
10258 #undef __GET_SAMPLER_INFO_ERR
10259 #undef __GET_KERNEL_INFO_ERR
10260 #undef __GET_KERNEL_ARG_INFO_ERR
10261 #undef __GET_KERNEL_SUB_GROUP_INFO_ERR
10262 #undef __GET_KERNEL_WORK_GROUP_INFO_ERR
10263 #undef __GET_PROGRAM_INFO_ERR
10264 #undef __GET_PROGRAM_BUILD_INFO_ERR
10265 #undef __GET_COMMAND_QUEUE_INFO_ERR
10266 #undef __CREATE_CONTEXT_ERR
10267 #undef __CREATE_CONTEXT_FROM_TYPE_ERR
10268 #undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
10269 #undef __CREATE_BUFFER_ERR
10270 #undef __COPY_ERR
10271 #undef __CREATE_SUBBUFFER_ERR
10272 #undef __CREATE_GL_BUFFER_ERR
10273 #undef __CREATE_GL_RENDER_BUFFER_ERR
10274 #undef __GET_GL_OBJECT_INFO_ERR
10275 #undef __CREATE_IMAGE_ERR
10276 #undef __CREATE_GL_TEXTURE_ERR
10277 #undef __IMAGE_DIMENSION_ERR
10278 #undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
10279 #undef __CREATE_USER_EVENT_ERR
10280 #undef __SET_USER_EVENT_STATUS_ERR
10281 #undef __SET_EVENT_CALLBACK_ERR
10282 #undef __WAIT_FOR_EVENTS_ERR
10283 #undef __CREATE_KERNEL_ERR
10284 #undef __SET_KERNEL_ARGS_ERR
10285 #undef __CREATE_PROGRAM_WITH_SOURCE_ERR
10286 #undef __CREATE_PROGRAM_WITH_IL_ERR
10287 #undef __CREATE_PROGRAM_WITH_BINARY_ERR
10288 #undef __CREATE_PROGRAM_WITH_IL_ERR
10289 #undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR
10290 #undef __BUILD_PROGRAM_ERR
10291 #undef __COMPILE_PROGRAM_ERR
10292 #undef __LINK_PROGRAM_ERR
10293 #undef __CREATE_KERNELS_IN_PROGRAM_ERR
10294 #undef __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR
10295 #undef __CREATE_SAMPLER_WITH_PROPERTIES_ERR
10296 #undef __SET_COMMAND_QUEUE_PROPERTY_ERR
10297 #undef __ENQUEUE_READ_BUFFER_ERR
10298 #undef __ENQUEUE_READ_BUFFER_RECT_ERR
10299 #undef __ENQUEUE_WRITE_BUFFER_ERR
10300 #undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
10301 #undef __ENQEUE_COPY_BUFFER_ERR
10302 #undef __ENQEUE_COPY_BUFFER_RECT_ERR
10303 #undef __ENQUEUE_FILL_BUFFER_ERR
10304 #undef __ENQUEUE_READ_IMAGE_ERR
10305 #undef __ENQUEUE_WRITE_IMAGE_ERR
10306 #undef __ENQUEUE_COPY_IMAGE_ERR
10307 #undef __ENQUEUE_FILL_IMAGE_ERR
10308 #undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
10309 #undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
10310 #undef __ENQUEUE_MAP_BUFFER_ERR
10311 #undef __ENQUEUE_MAP_IMAGE_ERR
10312 #undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
10313 #undef __ENQUEUE_NDRANGE_KERNEL_ERR
10314 #undef __ENQUEUE_NATIVE_KERNEL
10315 #undef __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR
10316 #undef __ENQUEUE_MIGRATE_SVM_ERR
10317 #undef __ENQUEUE_ACQUIRE_GL_ERR
10318 #undef __ENQUEUE_RELEASE_GL_ERR
10319 #undef __CREATE_PIPE_ERR
10320 #undef __GET_PIPE_INFO_ERR
10321 #undef __RETAIN_ERR
10322 #undef __RELEASE_ERR
10323 #undef __FLUSH_ERR
10324 #undef __FINISH_ERR
10325 #undef __VECTOR_CAPACITY_ERR
10326 #undef __CREATE_SUB_DEVICES_ERR
10327 #undef __CREATE_SUB_DEVICES_ERR
10328 #undef __ENQUEUE_MARKER_ERR
10329 #undef __ENQUEUE_WAIT_FOR_EVENTS_ERR
10330 #undef __ENQUEUE_BARRIER_ERR
10331 #undef __UNLOAD_COMPILER_ERR
10332 #undef __CREATE_GL_TEXTURE_2D_ERR
10333 #undef __CREATE_GL_TEXTURE_3D_ERR
10334 #undef __CREATE_IMAGE2D_ERR
10335 #undef __CREATE_IMAGE3D_ERR
10336 #undef __CREATE_COMMAND_QUEUE_ERR
10337 #undef __ENQUEUE_TASK_ERR
10338 #undef __CREATE_SAMPLER_ERR
10339 #undef __ENQUEUE_MARKER_WAIT_LIST_ERR
10340 #undef __ENQUEUE_BARRIER_WAIT_LIST_ERR
10341 #undef __CLONE_KERNEL_ERR
10342 #undef __GET_HOST_TIMER_ERR
10343 #undef __GET_DEVICE_AND_HOST_TIMER_ERR
10344 
10345 #endif //CL_HPP_USER_OVERRIDE_ERROR_STRINGS
10346 
10347 // Extensions
10348 #undef CL_HPP_INIT_CL_EXT_FCN_PTR_
10349 #undef CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_
10350 
10351 #if defined(CL_HPP_USE_CL_DEVICE_FISSION)
10352 #undef CL_HPP_PARAM_NAME_DEVICE_FISSION_
10353 #endif // CL_HPP_USE_CL_DEVICE_FISSION
10354 
10355 #undef CL_HPP_NOEXCEPT_
10356 #undef CL_HPP_DEFINE_STATIC_MEMBER_
10357 
10358 } // namespace cl
10359 
10360 #endif // CL_HPP_
Class interface for GL Buffer Memory Objects.
Definition: opencl.hpp:4246
BufferGL(BufferGL &&buf) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4312
BufferGL()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4273
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:4253
BufferGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4289
BufferGL(const BufferGL &buf)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4298
cl_int getObjectInfo(cl_gl_object_type *type, cl_GLuint *gl_object_name)
Wrapper for clGetGLObjectInfo().
Definition: opencl.hpp:4324
BufferGL(const cl_mem &buffer, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4282
Class interface for Buffer Memory Objects.
Definition: opencl.hpp:3926
Buffer()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4048
Buffer(const Buffer &buf)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4073
Buffer(Buffer &&buf) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4087
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:3936
Buffer(const cl_mem &buffer, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4057
Buffer & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4064
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:3985
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:4103
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:3961
Class interface for GL Render Buffer Memory Objects.
Definition: opencl.hpp:4343
cl_int getObjectInfo(cl_gl_object_type *type, cl_GLuint *gl_object_name)
Wrapper for clGetGLObjectInfo().
Definition: opencl.hpp:4421
BufferRenderGL(const cl_mem &buffer, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4379
BufferRenderGL(BufferRenderGL &&buf) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4409
BufferRenderGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4386
BufferRenderGL()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4370
BufferRenderGL(const BufferRenderGL &buf)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4395
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:4350
CommandQueue interface for cl_command_queue.
Definition: opencl.hpp:7123
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:7254
CommandQueue(const cl_command_queue &commandQueue, bool retainObject=false)
Constructor from cl_command_queue - takes ownership.
Definition: opencl.hpp:7581
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:7842
CommandQueue(CommandQueue &&queue) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:7607
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:8581
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:8042
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:8251
cl_int enqueueMigrateMemObjects(const vector< Memory > &memObjects, cl_mem_migration_flags flags, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8437
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:8224
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:8507
static CommandQueue setDefault(const CommandQueue &default_queue)
Definition: opencl.hpp:7565
cl_int enqueueMarkerWithWaitList(const vector< Event > *events=0, Event *event=0) const
Definition: opencl.hpp:8384
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:7188
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:8478
cl_int enqueueUnmapSVM(cl::pointer< T, D > &ptr, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8326
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:7446
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:8560
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:7497
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:8545
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:7384
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:7974
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int enqueueMarker(Event *event=NULL) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition: opencl.hpp:8680
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:8008
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int enqueueBarrier() const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition: opencl.hpp:8833
cl_int enqueueBarrierWithWaitList(const vector< Event > *events=0, Event *event=0) const
Definition: opencl.hpp:8414
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:7317
CommandQueue(const CommandQueue &queue)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:7593
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:8196
cl_int enqueueUnmapSVM(cl::vector< T, Alloc > &container, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8351
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:8523
cl_int enqueueUnmapSVM(T *ptr, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8301
Class interface for cl_context.
Definition: opencl.hpp:2841
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:2911
static Context setDefault(const Context &default_context)
Definition: opencl.hpp:3109
Context(const cl_context &context, bool retainObject=false)
Constructor from cl_context - takes ownership.
Definition: opencl.hpp:3124
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:3165
Context & operator=(const Context &ctx)
Copy assignment to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3067
Context()
Default constructor - initializes to NULL.
Definition: opencl.hpp:3117
cl_int getInfo(cl_context_info name, T *param) const
Wrapper for clGetContextInfo().
Definition: opencl.hpp:3140
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:2976
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:3150
static Context getDefault(cl_int *err=NULL)
Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT.
Definition: opencl.hpp:3092
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:2946
Context(const Context &ctx)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3062
Context(Context &&ctx) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3076
DeviceCommandQueue interface for device cl_command_queues.
Definition: opencl.hpp:8873
DeviceCommandQueue(const Context &context, const Device &device, DeviceQueueProperties properties=DeviceQueueProperties::None, cl_int *err=NULL)
Definition: opencl.hpp:8907
DeviceCommandQueue(const Context &context, const Device &device, cl_uint queueSize, DeviceQueueProperties properties=DeviceQueueProperties::None, cl_int *err=NULL)
Definition: opencl.hpp:8931
static DeviceCommandQueue makeDefault(const Context &context, const Device &device, cl_int *err=nullptr)
Definition: opencl.hpp:9056
static DeviceCommandQueue updateDefault(const Context &context, const Device &device, const DeviceCommandQueue &default_queue, cl_int *err=nullptr)
Definition: opencl.hpp:9116
static DeviceCommandQueue getDefault(const CommandQueue &queue, cl_int *err=NULL)
Definition: opencl.hpp:9131
static DeviceCommandQueue makeDefault(const Context &context, const Device &device, cl_uint queueSize, cl_int *err=nullptr)
Definition: opencl.hpp:9084
DeviceCommandQueue(DeviceQueueProperties properties, cl_int *err=NULL)
Definition: opencl.hpp:8884
DeviceCommandQueue(const DeviceCommandQueue &queue)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:8973
DeviceCommandQueue(DeviceCommandQueue &&queue) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:8987
DeviceCommandQueue(const cl_command_queue &commandQueue, bool retainObject=false)
Constructor from cl_command_queue - takes ownership.
Definition: opencl.hpp:8961
static DeviceCommandQueue makeDefault(cl_int *err=nullptr)
Definition: opencl.hpp:9026
Class interface for cl_device_id.
Definition: opencl.hpp:2132
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:2256
Device & operator=(const cl_device_id &rhs)
Assignment operator from cl_device_id.
Definition: opencl.hpp:2210
cl_int getInfo(cl_device_info name, T *param) const
Wrapper for clGetDeviceInfo().
Definition: opencl.hpp:2246
Device()
Default constructor - initializes to NULL.
Definition: opencl.hpp:2168
cl_ulong getHostTimer(cl_int *error=nullptr)
Definition: opencl.hpp:2275
static Device getDefault(cl_int *errResult=NULL)
Returns the first device on the default context.
Definition: opencl.hpp:2181
Device(const Device &dev)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:2219
std::pair< cl_ulong, cl_ulong > getDeviceAndHostTimer(cl_int *error=nullptr)
Definition: opencl.hpp:2299
Device(Device &&dev) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:2233
cl_int createSubDevices(const cl_device_partition_property *properties, vector< Device > *devices)
Wrapper for clCreateSubDevices().
Definition: opencl.hpp:2319
static Device setDefault(const Device &default_device)
Definition: opencl.hpp:2199
Device(const cl_device_id &device, bool retainObject=false)
Constructor from cl_device_id.
Definition: opencl.hpp:2174
Class interface for cl_event.
Definition: opencl.hpp:3253
Event(const cl_event &event, bool retainObject=false)
Constructor from cl_event - takes ownership.
Definition: opencl.hpp:3266
cl_int getProfilingInfo(cl_profiling_info name, T *param) const
Wrapper for clGetEventProfilingInfo().
Definition: opencl.hpp:3305
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:3342
cl_int getInfo(cl_event_info name, T *param) const
Wrapper for clGetEventInfo().
Definition: opencl.hpp:3282
cl_int wait() const
Blocks the calling thread until this event completes.
Definition: opencl.hpp:3330
Event()
Default constructor - initializes to NULL.
Definition: opencl.hpp:3256
Event & operator=(const cl_event &rhs)
Assignment operator from cl_event - takes ownership.
Definition: opencl.hpp:3274
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:3315
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:3292
static cl_int waitForEvents(const vector< Event > &events)
Blocks the calling thread until every event specified is complete.
Definition: opencl.hpp:3362
Image interface for arrays of 1D images.
Definition: opencl.hpp:4699
Image1DArray(const Image1DArray &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4755
Image1DArray(Image1DArray &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4769
Image1DArray(const cl_mem &imageArray, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4742
Image interface for 1D buffer images.
Definition: opencl.hpp:4616
Image1DBuffer(const Image1DBuffer &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4668
Image1DBuffer(const cl_mem &image1D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4656
Image1DBuffer(Image1DBuffer &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4682
Class interface for 1D Image Memory objects.
Definition: opencl.hpp:4525
Image1D()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4560
Image1D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4576
Image1D(const cl_mem &image1D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4569
Image1D(const Image1D &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4585
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:4531
Image1D(Image1D &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4599
Image interface for arrays of 2D images.
Definition: opencl.hpp:5116
Image2DArray(const Image2DArray &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5174
Image2DArray(const cl_mem &imageArray, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5163
Image2DArray(Image2DArray &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5188
Class interface for GL 2D Image Memory objects.
Definition: opencl.hpp:5026
Image2DGL()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5058
Image2DGL(const Image2DGL &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5083
Image2DGL(Image2DGL &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5097
Image2DGL(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5067
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:5033
Class interface for 2D Image Memory objects.
Definition: opencl.hpp:4791
Image2D(const Image2D &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4987
Image2D(const cl_mem &image2D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4971
Image2D()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4962
Image2D(Image2D &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5001
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:4797
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:4865
Image2D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4978
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:4911
Class interface for GL 3D Image Memory objects.
Definition: opencl.hpp:5343
Image3DGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:5390
Image3DGL()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5374
Image3DGL(Image3DGL &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5413
Image3DGL(const Image3DGL &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5399
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:5350
Image3DGL(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5383
Class interface for 3D Image Memory objects.
Definition: opencl.hpp:5208
Image3D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:5298
Image3D(const cl_mem &image3D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5291
Image3D()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5282
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:5214
Image3D(Image3D &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5321
Image3D(const Image3D &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5307
general image interface for GL interop. We abstract the 2D and 3D GL images into a single instance he...
Definition: opencl.hpp:5434
ImageGL(const ImageGL &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5480
ImageGL(ImageGL &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5494
ImageGL(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5468
C++ base class for Image Memory objects.
Definition: opencl.hpp:4438
Image(const Image &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4466
Image(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4450
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:4505
cl_int getImageInfo(cl_image_info name, T *param) const
Wrapper for clGetImageInfo().
Definition: opencl.hpp:4495
Image()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4441
Image(Image &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4480
Image & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4457
Event operator()(const EnqueueArgs &args, Ts... ts)
Definition: opencl.hpp:10140
Event result_type
Return type of the functor.
Definition: opencl.hpp:10133
Class interface for cl_kernel.
Definition: opencl.hpp:5924
Kernel(Kernel &&kernel) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5970
Kernel(const cl_kernel &kernel, bool retainObject=false)
Constructor from cl_kernel - takes ownership.
Definition: opencl.hpp:5939
Kernel & operator=(const cl_kernel &rhs)
Assignment operator from cl_kernel - takes ownership.
Definition: opencl.hpp:5947
cl_int setSVMPointers(const vector< void * > &pointerList)
Definition: opencl.hpp:6142
cl_int setArg(cl_uint index, const cl::pointer< T, D > &argPtr)
setArg overload taking a shared_ptr type
Definition: opencl.hpp:6086
Kernel()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5929
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:6107
Kernel(const Kernel &kernel)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5956
cl_int setArg(cl_uint index, const cl::vector< T, Alloc > &argPtr)
setArg overload taking a vector type.
Definition: opencl.hpp:6096
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:6119
cl_int setSVMPointers(const std::array< void *, ArrayLength > &pointerList)
Definition: opencl.hpp:6157
Kernel clone()
Definition: opencl.hpp:6258
cl_int enableFineGrainedSystemSVM(bool svmEnabled)
Enable fine-grained system SVM.
Definition: opencl.hpp:6178
Class interface for cl_mem.
Definition: opencl.hpp:3436
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:3532
Memory(const Memory &mem)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3469
Memory(Memory &&mem) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3483
Memory(const cl_mem &memory, bool retainObject)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:3452
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:3507
Memory()
Default constructor - initializes to NULL.
Definition: opencl.hpp:3439
Memory & operator=(const cl_mem &rhs)
Assignment operator from cl_mem - takes ownership.
Definition: opencl.hpp:3460
cl_int getInfo(cl_mem_info name, T *param) const
Wrapper for clGetMemObjectInfo().
Definition: opencl.hpp:3497
Class interface for specifying NDRange values.
Definition: opencl.hpp:5787
size_type dimensions() const
Queries the number of dimensions in the range.
Definition: opencl.hpp:5838
NDRange(size_type size0, size_type size1)
Constructs two-dimensional range.
Definition: opencl.hpp:5812
NDRange(size_type size0, size_type size1, size_type size2)
Constructs three-dimensional range.
Definition: opencl.hpp:5821
size_type size() const
Returns the size of the object in bytes based on the.
Definition: opencl.hpp:5845
NDRange()
Default constructor - resulting range has zero dimensions.
Definition: opencl.hpp:5794
NDRange(size_type size0)
Constructs one-dimensional range.
Definition: opencl.hpp:5803
Class interface for Pipe Memory Objects.
Definition: opencl.hpp:5517
Pipe(Pipe &&pipe) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5612
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:5529
Pipe & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:5589
Pipe()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5573
cl_int getInfo(cl_pipe_info name, T *param) const
Wrapper for clGetMemObjectInfo().
Definition: opencl.hpp:5625
Pipe(cl_uint packet_size, cl_uint max_packets, cl_int *err=NULL)
Constructs a Pipe in a the default context.
Definition: opencl.hpp:5554
Pipe(const Pipe &pipe)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5598
Pipe(const cl_mem &pipe, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5582
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:5635
Class interface for cl_platform_id.
Definition: opencl.hpp:2458
static cl_int get(Platform *platform)
Gets the first available platform.
Definition: opencl.hpp:2769
Platform(const cl_platform_id &platform, bool retainObject=false)
Constructor from cl_platform_id.
Definition: opencl.hpp:2539
Platform()
Default constructor - initializes to NULL.
Definition: opencl.hpp:2530
cl_int unloadCompiler()
Wrapper for clUnloadCompiler().
Definition: opencl.hpp:2802
cl_int getDevices(cl_device_type type, vector< Device > *devices) const
Gets a list of devices for this platform.
Definition: opencl.hpp:2604
static Platform get(cl_int *errResult=NULL)
Gets the first available platform, returning it by value.
Definition: opencl.hpp:2788
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:2589
Platform & operator=(const cl_platform_id &rhs)
Assignment operator from cl_platform_id.
Definition: opencl.hpp:2546
static cl_int get(vector< Platform > *platforms)
Gets a list of available platforms.
Definition: opencl.hpp:2734
cl_int getInfo(cl_platform_info name, T *param) const
Wrapper for clGetPlatformInfo().
Definition: opencl.hpp:2579
static Platform setDefault(const Platform &default_platform)
Definition: opencl.hpp:2570
Program interface that implements cl_program.
Definition: opencl.hpp:6273
Program(const Program &program)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:6670
Program(Program &&program) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:6684
Program(const Sources &sources, cl_int *err=NULL)
Definition: opencl.hpp:6363
Program(const Context &context, const Sources &sources, cl_int *err=NULL)
Definition: opencl.hpp:6398
Program(const vector< char > &IL, bool build=false, cl_int *err=NULL)
Definition: opencl.hpp:6435
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:6907
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:6828
Program(const Context &context, const vector< Device > &devices, const string &kernelNames, cl_int *err=NULL)
Definition: opencl.hpp:6620
cl_int setSpecializationConstant(cl_uint index, size_type size, const void *value)
Sets a SPIR-V specialization constant.
Definition: opencl.hpp:6941
Program(const cl_program &program, bool retainObject=false)
Constructor from cl_program - takes ownership.
Definition: opencl.hpp:6658
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:6926
Program(const Context &context, const vector< Device > &devices, const Binaries &binaries, vector< cl_int > *binaryStatus=NULL, cl_int *err=NULL)
Definition: opencl.hpp:6556
Program(const Context &context, const vector< char > &IL, bool build=false, cl_int *err=NULL)
Definition: opencl.hpp:6489
pointer allocate(size_type size, typename cl::SVMAllocator< void, SVMTrait >::const_pointer=0)
Definition: opencl.hpp:3725
bool operator==(SVMAllocator const &rhs)
Definition: opencl.hpp:3795
size_type max_size() const CL_HPP_NOEXCEPT_
Definition: opencl.hpp:3767
Class interface for cl_sampler.
Definition: opencl.hpp:5658
Sampler & operator=(const cl_sampler &rhs)
Assignment operator from cl_sampler - takes ownership.
Definition: opencl.hpp:5722
Sampler()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5661
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:5667
Sampler(Sampler &&sam) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5745
Sampler(const Sampler &sam)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5731
cl_int getInfo(cl_sampler_info name, T *param) const
Wrapper for clGetSamplerInfo().
Definition: opencl.hpp:5758
Sampler(const cl_sampler &sampler, bool retainObject=false)
Constructor from cl_sampler - takes ownership.
Definition: opencl.hpp:5714
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:5768
Class interface for user events (a subset of cl_event's).
Definition: opencl.hpp:3377
UserEvent()
Default constructor - initializes to NULL.
Definition: opencl.hpp:3399
UserEvent(const Context &context, cl_int *err=NULL)
Constructs a user event on a given context.
Definition: opencl.hpp:3383
cl_int setStatus(cl_int status)
Sets the execution status of a user event object.
Definition: opencl.hpp:3405
The OpenCL C++ bindings are defined within this namespace.
Definition: opencl.hpp:598
cl_int copy(const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator)
Definition: opencl.hpp:9587
vector< T, cl::SVMAllocator< int, cl::SVMTraitFine<> >> fine_svm_vector
Vector alias to simplify contruction of fine-grained SVM containers.
Definition: opencl.hpp:3908
cl_int copy(IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer)
Definition: opencl.hpp:9516
LocalSpaceArg Local(size_type size)
Helper function for generating LocalSpaceArg objects.
Definition: opencl.hpp:5909
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int UnloadCompiler() CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition: opencl.hpp:2825
cl_int enqueueUnmapSVM(T *ptr, const vector< Event > *events=NULL, Event *event=NULL)
Definition: opencl.hpp:9431
cl::pointer< T, detail::Deleter< Alloc > > allocate_pointer(const Alloc &alloc_, Args &&... args)
Definition: opencl.hpp:3855
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:9329
vector< T, cl::SVMAllocator< int, cl::SVMTraitCoarse<> >> coarse_svm_vector
Vector alias to simplify contruction of coarse-grained SVM containers.
Definition: opencl.hpp:3902
cl_int mapSVM(cl::vector< T, Alloc > &container)
Definition: opencl.hpp:9618
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:3914
cl_int unmapSVM(cl::vector< T, Alloc > &container)
Definition: opencl.hpp:9627
Adds constructors and member functions for cl_image_format.
Definition: opencl.hpp:2099
ImageFormat(cl_channel_order order, cl_channel_type type)
Initializing constructor.
Definition: opencl.hpp:2104
ImageFormat & operator=(const ImageFormat &rhs)
Assignment operator.
Definition: opencl.hpp:2114
ImageFormat(const ImageFormat &other)
Copy constructor.
Definition: opencl.hpp:2111
ImageFormat()
Default constructor - performs no initialization.
Definition: opencl.hpp:2101
Local address wrapper for use with Kernel::setArg.
Definition: opencl.hpp:5866
Event type_(const EnqueueArgs &, Ts...)
Function signature of kernel functor with no event dependency.
Definition: opencl.hpp:10230
Event result_type
Return type of the functor.
Definition: opencl.hpp:10227
static cl_int release(cl_device_id device)
Definition: opencl.hpp:1704
static cl_int retain(cl_device_id device)
Definition: opencl.hpp:1693