407 #if !defined(CL_HPP_USE_DX_INTEROP) && defined(USE_DX_INTEROP)
408 # pragma message("cl2.hpp: USE_DX_INTEROP is deprecated. Define CL_HPP_USE_DX_INTEROP instead")
409 # define CL_HPP_USE_DX_INTEROP
411 #if !defined(CL_HPP_USE_CL_DEVICE_FISSION) && defined(USE_CL_DEVICE_FISSION)
412 # pragma message("cl2.hpp: USE_CL_DEVICE_FISSION is deprecated. Define CL_HPP_USE_CL_DEVICE_FISSION instead")
413 # define CL_HPP_USE_CL_DEVICE_FISSION
415 #if !defined(CL_HPP_ENABLE_EXCEPTIONS) && defined(__CL_ENABLE_EXCEPTIONS)
416 # pragma message("cl2.hpp: __CL_ENABLE_EXCEPTIONS is deprecated. Define CL_HPP_ENABLE_EXCEPTIONS instead")
417 # define CL_HPP_ENABLE_EXCEPTIONS
419 #if !defined(CL_HPP_NO_STD_VECTOR) && defined(__NO_STD_VECTOR)
420 # pragma message("cl2.hpp: __NO_STD_VECTOR is deprecated. Define CL_HPP_NO_STD_VECTOR instead")
421 # define CL_HPP_NO_STD_VECTOR
423 #if !defined(CL_HPP_NO_STD_STRING) && defined(__NO_STD_STRING)
424 # pragma message("cl2.hpp: __NO_STD_STRING is deprecated. Define CL_HPP_NO_STD_STRING instead")
425 # define CL_HPP_NO_STD_STRING
427 #if defined(VECTOR_CLASS)
428 # pragma message("cl2.hpp: VECTOR_CLASS is deprecated. Alias cl::vector instead")
430 #if defined(STRING_CLASS)
431 # pragma message("cl2.hpp: STRING_CLASS is deprecated. Alias cl::string instead.")
433 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) && defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
434 # pragma message("cl2.hpp: __CL_USER_OVERRIDE_ERROR_STRINGS is deprecated. Define CL_HPP_USER_OVERRIDE_ERROR_STRINGS instead")
435 # define CL_HPP_USER_OVERRIDE_ERROR_STRINGS
440 #if defined(__USE_DEV_VECTOR)
441 # pragma message("cl2.hpp: __USE_DEV_VECTOR is no longer supported. Expect compilation errors")
443 #if defined(__USE_DEV_STRING)
444 # pragma message("cl2.hpp: __USE_DEV_STRING is no longer supported. Expect compilation errors")
448 #if !defined(CL_HPP_TARGET_OPENCL_VERSION)
449 # pragma message("cl2.hpp: CL_HPP_TARGET_OPENCL_VERSION is not defined. It will default to 210 (OpenCL 2.1)")
450 # define CL_HPP_TARGET_OPENCL_VERSION 210
452 #if CL_HPP_TARGET_OPENCL_VERSION != 100 && CL_HPP_TARGET_OPENCL_VERSION != 110 && CL_HPP_TARGET_OPENCL_VERSION != 120 && CL_HPP_TARGET_OPENCL_VERSION != 200 && CL_HPP_TARGET_OPENCL_VERSION != 210
453 # pragma message("cl2.hpp: CL_HPP_TARGET_OPENCL_VERSION is not a valid value (100, 110, 120, 200 or 210). It will be set to 210")
454 # undef CL_HPP_TARGET_OPENCL_VERSION
455 # define CL_HPP_TARGET_OPENCL_VERSION 210
459 #if defined(CL_TARGET_OPENCL_VERSION)
462 #if CL_TARGET_OPENCL_VERSION < CL_HPP_TARGET_OPENCL_VERSION
463 # pragma message("CL_TARGET_OPENCL_VERSION is already defined as is lower than CL_HPP_TARGET_OPENCL_VERSION")
466 # define CL_TARGET_OPENCL_VERSION CL_HPP_TARGET_OPENCL_VERSION
469 #if !defined(CL_HPP_MINIMUM_OPENCL_VERSION)
470 # define CL_HPP_MINIMUM_OPENCL_VERSION 200
472 #if CL_HPP_MINIMUM_OPENCL_VERSION != 100 && CL_HPP_MINIMUM_OPENCL_VERSION != 110 && CL_HPP_MINIMUM_OPENCL_VERSION != 120 && CL_HPP_MINIMUM_OPENCL_VERSION != 200 && CL_HPP_MINIMUM_OPENCL_VERSION != 210
473 # pragma message("cl2.hpp: CL_HPP_MINIMUM_OPENCL_VERSION is not a valid value (100, 110, 120, 200 or 210). It will be set to 100")
474 # undef CL_HPP_MINIMUM_OPENCL_VERSION
475 # define CL_HPP_MINIMUM_OPENCL_VERSION 100
477 #if CL_HPP_MINIMUM_OPENCL_VERSION > CL_HPP_TARGET_OPENCL_VERSION
478 # error "CL_HPP_MINIMUM_OPENCL_VERSION must not be greater than CL_HPP_TARGET_OPENCL_VERSION"
481 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 100 && !defined(CL_USE_DEPRECATED_OPENCL_1_0_APIS)
482 # define CL_USE_DEPRECATED_OPENCL_1_0_APIS
484 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 110 && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
485 # define CL_USE_DEPRECATED_OPENCL_1_1_APIS
487 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 120 && !defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
488 # define CL_USE_DEPRECATED_OPENCL_1_2_APIS
490 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 200 && !defined(CL_USE_DEPRECATED_OPENCL_2_0_APIS)
491 # define CL_USE_DEPRECATED_OPENCL_2_0_APIS
493 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 210 && !defined(CL_USE_DEPRECATED_OPENCL_2_1_APIS)
494 # define CL_USE_DEPRECATED_OPENCL_2_1_APIS
501 #if defined(CL_HPP_USE_DX_INTEROP)
502 #include <CL/cl_d3d10.h>
503 #include <CL/cl_dx9_media_sharing.h>
507 #if defined(_MSC_VER)
515 #if (!defined(_MSC_VER) && __cplusplus < 201103L) || (defined(_MSC_VER) && _MSC_VER < 1700)
516 #error Visual studio 2013 or another C++11-supporting compiler required
520 #if defined(CL_HPP_USE_CL_DEVICE_FISSION) || defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)
521 #include <CL/cl_ext.h>
524 #if defined(__APPLE__) || defined(__MACOSX)
525 #include <OpenCL/opencl.h>
527 #include <CL/opencl.h>
530 #if (__cplusplus >= 201103L)
531 #define CL_HPP_NOEXCEPT_ noexcept
533 #define CL_HPP_NOEXCEPT_
536 #if defined(_MSC_VER)
537 # define CL_HPP_DEFINE_STATIC_MEMBER_ __declspec(selectany)
538 #elif defined(__MINGW32__)
539 # define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((selectany))
541 # define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((weak))
546 #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
547 #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
548 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
549 #if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED)
550 #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
551 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
553 #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED)
554 #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED
555 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED)
556 #if !defined(CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED)
557 #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED
558 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED)
560 #if !defined(CL_CALLBACK)
569 #include <functional>
573 #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
575 using size_type = ::size_t;
577 #else // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
579 using size_type = size_t;
581 #endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
584 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
586 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
588 #if !defined(CL_HPP_NO_STD_VECTOR)
591 template <
class T,
class Alloc = std::allocator<T> >
592 using vector = std::vector<T, Alloc>;
594 #endif // #if !defined(CL_HPP_NO_STD_VECTOR)
596 #if !defined(CL_HPP_NO_STD_STRING)
599 using string = std::string;
601 #endif // #if !defined(CL_HPP_NO_STD_STRING)
603 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
605 #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
610 template<
class T,
class D>
611 using pointer = std::unique_ptr<T, D>;
614 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
615 #if !defined(CL_HPP_NO_STD_ARRAY)
618 template <
class T,
size_type N >
619 using array = std::array<T, N>;
621 #endif // #if !defined(CL_HPP_NO_STD_ARRAY)
625 #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
627 namespace compatibility {
642 for (
int i = 0; i < N; ++i) {
647 size_t(
const array<size_type, N> &rhs)
649 for (
int i = 0; i < N; ++i) {
654 size_type& operator[](
int index)
659 const size_type& operator[](
int index)
const
665 operator size_type* () {
return data_; }
668 operator const size_type* ()
const {
return data_; }
670 operator array<size_type, N>()
const
672 array<size_type, N> ret;
674 for (
int i = 0; i < N; ++i) {
683 using size_t = compatibility::size_t<N>;
685 #endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
690 using size_t_array = array<size_type, 3>;
703 #define CL_HPP_INIT_CL_EXT_FCN_PTR_(name) \
705 pfn_##name = (PFN_##name) \
706 clGetExtensionFunctionAddress(#name); \
711 #define CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, name) \
713 pfn_##name = (PFN_##name) \
714 clGetExtensionFunctionAddressForPlatform(platform, #name); \
723 class DeviceCommandQueue;
728 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
733 class Error :
public std::exception
737 const char * errStr_;
748 Error(cl_int err,
const char * errStr = NULL) : err_(err), errStr_(errStr)
757 virtual const char * what()
const throw ()
759 if (errStr_ == NULL) {
771 cl_int err(
void)
const {
return err_; }
773 #define CL_HPP_ERR_STR_(x) #x
775 #define CL_HPP_ERR_STR_(x) NULL
776 #endif // CL_HPP_ENABLE_EXCEPTIONS
781 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
782 static inline cl_int errHandler (
784 const char * errStr = NULL)
786 if (err != CL_SUCCESS) {
787 throw Error(err, errStr);
792 static inline cl_int errHandler (cl_int err,
const char * errStr = NULL)
797 #endif // CL_HPP_ENABLE_EXCEPTIONS
803 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
804 #define __GET_DEVICE_INFO_ERR CL_HPP_ERR_STR_(clGetDeviceInfo)
805 #define __GET_PLATFORM_INFO_ERR CL_HPP_ERR_STR_(clGetPlatformInfo)
806 #define __GET_DEVICE_IDS_ERR CL_HPP_ERR_STR_(clGetDeviceIDs)
807 #define __GET_PLATFORM_IDS_ERR CL_HPP_ERR_STR_(clGetPlatformIDs)
808 #define __GET_CONTEXT_INFO_ERR CL_HPP_ERR_STR_(clGetContextInfo)
809 #define __GET_EVENT_INFO_ERR CL_HPP_ERR_STR_(clGetEventInfo)
810 #define __GET_EVENT_PROFILE_INFO_ERR CL_HPP_ERR_STR_(clGetEventProfileInfo)
811 #define __GET_MEM_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetMemObjectInfo)
812 #define __GET_IMAGE_INFO_ERR CL_HPP_ERR_STR_(clGetImageInfo)
813 #define __GET_SAMPLER_INFO_ERR CL_HPP_ERR_STR_(clGetSamplerInfo)
814 #define __GET_KERNEL_INFO_ERR CL_HPP_ERR_STR_(clGetKernelInfo)
815 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
816 #define __GET_KERNEL_ARG_INFO_ERR CL_HPP_ERR_STR_(clGetKernelArgInfo)
817 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
818 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
819 #define __GET_KERNEL_SUB_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelSubGroupInfo)
820 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
821 #define __GET_KERNEL_WORK_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelWorkGroupInfo)
822 #define __GET_PROGRAM_INFO_ERR CL_HPP_ERR_STR_(clGetProgramInfo)
823 #define __GET_PROGRAM_BUILD_INFO_ERR CL_HPP_ERR_STR_(clGetProgramBuildInfo)
824 #define __GET_COMMAND_QUEUE_INFO_ERR CL_HPP_ERR_STR_(clGetCommandQueueInfo)
826 #define __CREATE_CONTEXT_ERR CL_HPP_ERR_STR_(clCreateContext)
827 #define __CREATE_CONTEXT_FROM_TYPE_ERR CL_HPP_ERR_STR_(clCreateContextFromType)
828 #define __GET_SUPPORTED_IMAGE_FORMATS_ERR CL_HPP_ERR_STR_(clGetSupportedImageFormats)
830 #define __CREATE_BUFFER_ERR CL_HPP_ERR_STR_(clCreateBuffer)
831 #define __COPY_ERR CL_HPP_ERR_STR_(cl::copy)
832 #define __CREATE_SUBBUFFER_ERR CL_HPP_ERR_STR_(clCreateSubBuffer)
833 #define __CREATE_GL_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
834 #define __CREATE_GL_RENDER_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
835 #define __GET_GL_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetGLObjectInfo)
836 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
837 #define __CREATE_IMAGE_ERR CL_HPP_ERR_STR_(clCreateImage)
838 #define __CREATE_GL_TEXTURE_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture)
839 #define __IMAGE_DIMENSION_ERR CL_HPP_ERR_STR_(Incorrect image dimensions)
840 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
841 #define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR CL_HPP_ERR_STR_(clSetMemObjectDestructorCallback)
843 #define __CREATE_USER_EVENT_ERR CL_HPP_ERR_STR_(clCreateUserEvent)
844 #define __SET_USER_EVENT_STATUS_ERR CL_HPP_ERR_STR_(clSetUserEventStatus)
845 #define __SET_EVENT_CALLBACK_ERR CL_HPP_ERR_STR_(clSetEventCallback)
846 #define __WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clWaitForEvents)
848 #define __CREATE_KERNEL_ERR CL_HPP_ERR_STR_(clCreateKernel)
849 #define __SET_KERNEL_ARGS_ERR CL_HPP_ERR_STR_(clSetKernelArg)
850 #define __CREATE_PROGRAM_WITH_SOURCE_ERR CL_HPP_ERR_STR_(clCreateProgramWithSource)
851 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
852 #define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
853 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
854 #define __CREATE_PROGRAM_WITH_BINARY_ERR CL_HPP_ERR_STR_(clCreateProgramWithBinary)
855 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
856 #define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
857 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
858 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
859 #define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR CL_HPP_ERR_STR_(clCreateProgramWithBuiltInKernels)
860 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
861 #define __BUILD_PROGRAM_ERR CL_HPP_ERR_STR_(clBuildProgram)
862 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
863 #define __COMPILE_PROGRAM_ERR CL_HPP_ERR_STR_(clCompileProgram)
864 #define __LINK_PROGRAM_ERR CL_HPP_ERR_STR_(clLinkProgram)
865 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
866 #define __CREATE_KERNELS_IN_PROGRAM_ERR CL_HPP_ERR_STR_(clCreateKernelsInProgram)
868 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
869 #define __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateCommandQueueWithProperties)
870 #define __CREATE_SAMPLER_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateSamplerWithProperties)
871 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
872 #define __SET_COMMAND_QUEUE_PROPERTY_ERR CL_HPP_ERR_STR_(clSetCommandQueueProperty)
873 #define __ENQUEUE_READ_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueReadBuffer)
874 #define __ENQUEUE_READ_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueReadBufferRect)
875 #define __ENQUEUE_WRITE_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueWriteBuffer)
876 #define __ENQUEUE_WRITE_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueWriteBufferRect)
877 #define __ENQEUE_COPY_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyBuffer)
878 #define __ENQEUE_COPY_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferRect)
879 #define __ENQUEUE_FILL_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueFillBuffer)
880 #define __ENQUEUE_READ_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueReadImage)
881 #define __ENQUEUE_WRITE_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueWriteImage)
882 #define __ENQUEUE_COPY_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyImage)
883 #define __ENQUEUE_FILL_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueFillImage)
884 #define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyImageToBuffer)
885 #define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferToImage)
886 #define __ENQUEUE_MAP_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueMapBuffer)
887 #define __ENQUEUE_MAP_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueMapImage)
888 #define __ENQUEUE_UNMAP_MEM_OBJECT_ERR CL_HPP_ERR_STR_(clEnqueueUnMapMemObject)
889 #define __ENQUEUE_NDRANGE_KERNEL_ERR CL_HPP_ERR_STR_(clEnqueueNDRangeKernel)
890 #define __ENQUEUE_NATIVE_KERNEL CL_HPP_ERR_STR_(clEnqueueNativeKernel)
891 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
892 #define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR CL_HPP_ERR_STR_(clEnqueueMigrateMemObjects)
893 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
894 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
895 #define __ENQUEUE_MIGRATE_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMMigrateMem)
896 #define __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clSetDefaultDeviceCommandQueue)
897 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
900 #define __ENQUEUE_ACQUIRE_GL_ERR CL_HPP_ERR_STR_(clEnqueueAcquireGLObjects)
901 #define __ENQUEUE_RELEASE_GL_ERR CL_HPP_ERR_STR_(clEnqueueReleaseGLObjects)
903 #define __CREATE_PIPE_ERR CL_HPP_ERR_STR_(clCreatePipe)
904 #define __GET_PIPE_INFO_ERR CL_HPP_ERR_STR_(clGetPipeInfo)
907 #define __RETAIN_ERR CL_HPP_ERR_STR_(Retain Object)
908 #define __RELEASE_ERR CL_HPP_ERR_STR_(Release Object)
909 #define __FLUSH_ERR CL_HPP_ERR_STR_(clFlush)
910 #define __FINISH_ERR CL_HPP_ERR_STR_(clFinish)
911 #define __VECTOR_CAPACITY_ERR CL_HPP_ERR_STR_(Vector capacity error)
913 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
914 #define __GET_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetHostTimer)
915 #define __GET_DEVICE_AND_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetDeviceAndHostTimer)
922 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
923 #define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevices)
925 #define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevicesEXT)
926 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
931 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
932 #define __ENQUEUE_MARKER_ERR CL_HPP_ERR_STR_(clEnqueueMarker)
933 #define __ENQUEUE_WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clEnqueueWaitForEvents)
934 #define __ENQUEUE_BARRIER_ERR CL_HPP_ERR_STR_(clEnqueueBarrier)
935 #define __UNLOAD_COMPILER_ERR CL_HPP_ERR_STR_(clUnloadCompiler)
936 #define __CREATE_GL_TEXTURE_2D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture2D)
937 #define __CREATE_GL_TEXTURE_3D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture3D)
938 #define __CREATE_IMAGE2D_ERR CL_HPP_ERR_STR_(clCreateImage2D)
939 #define __CREATE_IMAGE3D_ERR CL_HPP_ERR_STR_(clCreateImage3D)
940 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
945 #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
946 #define __CREATE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clCreateCommandQueue)
947 #define __ENQUEUE_TASK_ERR CL_HPP_ERR_STR_(clEnqueueTask)
948 #define __CREATE_SAMPLER_ERR CL_HPP_ERR_STR_(clCreateSampler)
949 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
954 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
955 #define __ENQUEUE_MARKER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueMarkerWithWaitList)
956 #define __ENQUEUE_BARRIER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueBarrierWithWaitList)
957 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
959 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
960 #define __CLONE_KERNEL_ERR CL_HPP_ERR_STR_(clCloneKernel)
961 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
963 #endif // CL_HPP_USER_OVERRIDE_ERROR_STRINGS
973 template<
typename Functor,
typename T>
974 inline cl_int getInfoHelper(Functor f, cl_uint name, T* param,
long)
976 return f(name,
sizeof(T), param, NULL);
981 template <
typename Func>
982 inline cl_int getInfoHelper(Func f, cl_uint name, vector<vector<unsigned char>>* param,
int)
984 if (name != CL_PROGRAM_BINARIES) {
985 return CL_INVALID_VALUE;
989 size_type numBinaries = param->size();
990 vector<unsigned char*> binariesPointers(numBinaries);
992 for (size_type i = 0; i < numBinaries; ++i)
994 binariesPointers[i] = (*param)[i].data();
997 cl_int err = f(name, numBinaries *
sizeof(
unsigned char*), binariesPointers.data(), NULL);
999 if (err != CL_SUCCESS) {
1009 template <
typename Func,
typename T>
1010 inline cl_int getInfoHelper(Func f, cl_uint name, vector<T>* param,
long)
1013 cl_int err = f(name, 0, NULL, &required);
1014 if (err != CL_SUCCESS) {
1017 const size_type elements = required /
sizeof(T);
1020 vector<T> localData(elements);
1021 err = f(name, required, localData.data(), NULL);
1022 if (err != CL_SUCCESS) {
1026 *param = std::move(localData);
1038 template <
typename Func,
typename T>
1039 inline cl_int getInfoHelper(
1040 Func f, cl_uint name, vector<T>* param,
int,
typename T::cl_type = 0)
1043 cl_int err = f(name, 0, NULL, &required);
1044 if (err != CL_SUCCESS) {
1048 const size_type elements = required /
sizeof(
typename T::cl_type);
1050 vector<typename T::cl_type> value(elements);
1051 err = f(name, required, value.data(), NULL);
1052 if (err != CL_SUCCESS) {
1058 param->resize(elements);
1062 for (size_type i = 0; i < elements; i++) {
1063 (*param)[i] = T(value[i],
true);
1070 template <
typename Func>
1071 inline cl_int getInfoHelper(Func f, cl_uint name,
string* param,
long)
1074 cl_int err = f(name, 0, NULL, &required);
1075 if (err != CL_SUCCESS) {
1082 vector<char> value(required);
1083 err = f(name, required, value.data(), NULL);
1084 if (err != CL_SUCCESS) {
1088 param->assign(begin(value), prev(end(value)));
1098 template <
typename Func,
size_type N>
1099 inline cl_int getInfoHelper(Func f, cl_uint name, array<size_type, N>* param,
long)
1102 cl_int err = f(name, 0, NULL, &required);
1103 if (err != CL_SUCCESS) {
1107 size_type elements = required /
sizeof(size_type);
1108 vector<size_type> value(elements, 0);
1110 err = f(name, required, value.data(), NULL);
1111 if (err != CL_SUCCESS) {
1120 for (size_type i = 0; i < elements; ++i) {
1121 (*param)[i] = value[i];
1135 template<
typename Func,
typename T>
1136 inline cl_int getInfoHelper(Func f, cl_uint name, T* param,
int,
typename T::cl_type = 0)
1138 typename T::cl_type value;
1139 cl_int err = f(name,
sizeof(value), &value, NULL);
1140 if (err != CL_SUCCESS) {
1146 err = param->retain();
1147 if (err != CL_SUCCESS) {
1154 #define CL_HPP_PARAM_NAME_INFO_1_0_(F) \
1155 F(cl_platform_info, CL_PLATFORM_PROFILE, string) \
1156 F(cl_platform_info, CL_PLATFORM_VERSION, string) \
1157 F(cl_platform_info, CL_PLATFORM_NAME, string) \
1158 F(cl_platform_info, CL_PLATFORM_VENDOR, string) \
1159 F(cl_platform_info, CL_PLATFORM_EXTENSIONS, string) \
1161 F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
1162 F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
1163 F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
1164 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
1165 F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, size_type) \
1166 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, cl::vector<size_type>) \
1167 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
1168 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
1169 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
1170 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
1171 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
1172 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
1173 F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
1174 F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \
1175 F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
1176 F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
1177 F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
1178 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, size_type) \
1179 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, size_type) \
1180 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, size_type) \
1181 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, size_type) \
1182 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, size_type) \
1183 F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \
1184 F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, size_type) \
1185 F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
1186 F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
1187 F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
1188 F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
1189 F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
1190 F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
1191 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
1192 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
1193 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
1194 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
1195 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
1196 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
1197 F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
1198 F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
1199 F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
1200 F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, size_type) \
1201 F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
1202 F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
1203 F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
1204 F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
1205 F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
1206 F(cl_device_info, CL_DEVICE_NAME, string) \
1207 F(cl_device_info, CL_DEVICE_VENDOR, string) \
1208 F(cl_device_info, CL_DRIVER_VERSION, string) \
1209 F(cl_device_info, CL_DEVICE_PROFILE, string) \
1210 F(cl_device_info, CL_DEVICE_VERSION, string) \
1211 F(cl_device_info, CL_DEVICE_EXTENSIONS, string) \
1213 F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
1214 F(cl_context_info, CL_CONTEXT_DEVICES, cl::vector<Device>) \
1215 F(cl_context_info, CL_CONTEXT_PROPERTIES, cl::vector<cl_context_properties>) \
1217 F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
1218 F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
1219 F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
1220 F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \
1222 F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
1223 F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
1224 F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
1225 F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
1227 F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
1228 F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
1229 F(cl_mem_info, CL_MEM_SIZE, size_type) \
1230 F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
1231 F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
1232 F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
1233 F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
1235 F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
1236 F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, size_type) \
1237 F(cl_image_info, CL_IMAGE_ROW_PITCH, size_type) \
1238 F(cl_image_info, CL_IMAGE_SLICE_PITCH, size_type) \
1239 F(cl_image_info, CL_IMAGE_WIDTH, size_type) \
1240 F(cl_image_info, CL_IMAGE_HEIGHT, size_type) \
1241 F(cl_image_info, CL_IMAGE_DEPTH, size_type) \
1243 F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
1244 F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
1245 F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \
1246 F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \
1247 F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \
1249 F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
1250 F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
1251 F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
1252 F(cl_program_info, CL_PROGRAM_DEVICES, cl::vector<Device>) \
1253 F(cl_program_info, CL_PROGRAM_SOURCE, string) \
1254 F(cl_program_info, CL_PROGRAM_BINARY_SIZES, cl::vector<size_type>) \
1255 F(cl_program_info, CL_PROGRAM_BINARIES, cl::vector<cl::vector<unsigned char>>) \
1257 F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
1258 F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, string) \
1259 F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, string) \
1261 F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, string) \
1262 F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
1263 F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
1264 F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
1265 F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
1267 F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, size_type) \
1268 F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::detail::size_t_array) \
1269 F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
1271 F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
1272 F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
1273 F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
1274 F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
1277 #define CL_HPP_PARAM_NAME_INFO_1_1_(F) \
1278 F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
1279 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
1280 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
1281 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
1282 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
1283 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
1284 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
1285 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
1286 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
1287 F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, string) \
1289 F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
1290 F(cl_mem_info, CL_MEM_OFFSET, size_type) \
1292 F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1293 F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
1295 F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
1297 #define CL_HPP_PARAM_NAME_INFO_1_2_(F) \
1298 F(cl_program_info, CL_PROGRAM_NUM_KERNELS, size_type) \
1299 F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, string) \
1301 F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \
1303 F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, string) \
1305 F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \
1306 F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \
1307 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, string) \
1308 F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, string) \
1309 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \
1311 F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl::Device) \
1312 F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, cl::vector<cl_device_partition_property>) \
1313 F(cl_device_info, CL_DEVICE_PARTITION_TYPE, cl::vector<cl_device_partition_property>) \
1314 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \
1315 F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, size_type) \
1316 F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \
1317 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, string) \
1319 F(cl_image_info, CL_IMAGE_ARRAY_SIZE, size_type) \
1320 F(cl_image_info, CL_IMAGE_NUM_MIP_LEVELS, cl_uint) \
1321 F(cl_image_info, CL_IMAGE_NUM_SAMPLES, cl_uint)
1323 #define CL_HPP_PARAM_NAME_INFO_2_0_(F) \
1324 F(cl_device_info, CL_DEVICE_QUEUE_ON_HOST_PROPERTIES, cl_command_queue_properties) \
1325 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES, cl_command_queue_properties) \
1326 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, cl_uint) \
1327 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, cl_uint) \
1328 F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_QUEUES, cl_uint) \
1329 F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_EVENTS, cl_uint) \
1330 F(cl_device_info, CL_DEVICE_MAX_PIPE_ARGS, cl_uint) \
1331 F(cl_device_info, CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS, cl_uint) \
1332 F(cl_device_info, CL_DEVICE_PIPE_MAX_PACKET_SIZE, cl_uint) \
1333 F(cl_device_info, CL_DEVICE_SVM_CAPABILITIES, cl_device_svm_capabilities) \
1334 F(cl_device_info, CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT, cl_uint) \
1335 F(cl_device_info, CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT, cl_uint) \
1336 F(cl_device_info, CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT, cl_uint) \
1337 F(cl_command_queue_info, CL_QUEUE_SIZE, cl_uint) \
1338 F(cl_mem_info, CL_MEM_USES_SVM_POINTER, cl_bool) \
1339 F(cl_program_build_info, CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, size_type) \
1340 F(cl_pipe_info, CL_PIPE_PACKET_SIZE, cl_uint) \
1341 F(cl_pipe_info, CL_PIPE_MAX_PACKETS, cl_uint)
1343 #define CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(F) \
1344 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR, size_type) \
1345 F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR, size_type)
1347 #define CL_HPP_PARAM_NAME_INFO_IL_KHR_(F) \
1348 F(cl_device_info, CL_DEVICE_IL_VERSION_KHR, string) \
1349 F(cl_program_info, CL_PROGRAM_IL_KHR, cl::vector<unsigned char>)
1351 #define CL_HPP_PARAM_NAME_INFO_2_1_(F) \
1352 F(cl_platform_info, CL_PLATFORM_HOST_TIMER_RESOLUTION, size_type) \
1353 F(cl_program_info, CL_PROGRAM_IL, cl::vector<unsigned char>) \
1354 F(cl_kernel_info, CL_KERNEL_MAX_NUM_SUB_GROUPS, size_type) \
1355 F(cl_kernel_info, CL_KERNEL_COMPILE_NUM_SUB_GROUPS, size_type) \
1356 F(cl_device_info, CL_DEVICE_MAX_NUM_SUB_GROUPS, cl_uint) \
1357 F(cl_device_info, CL_DEVICE_IL_VERSION, string) \
1358 F(cl_device_info, CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS, cl_bool) \
1359 F(cl_command_queue_info, CL_QUEUE_DEVICE_DEFAULT, cl::DeviceCommandQueue) \
1360 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE, size_type) \
1361 F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE, size_type) \
1362 F(cl_kernel_sub_group_info, CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT, cl::detail::size_t_array)
1364 #define CL_HPP_PARAM_NAME_DEVICE_FISSION_(F) \
1365 F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
1366 F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, cl::vector<cl_device_partition_property_ext>) \
1367 F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, cl::vector<cl_device_partition_property_ext>) \
1368 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
1369 F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, cl::vector<cl_device_partition_property_ext>)
1371 template <
typename enum_type, cl_
int Name>
1374 #define CL_HPP_DECLARE_PARAM_TRAITS_(token, param_name, T) \
1377 struct param_traits<detail:: token,param_name> \
1379 enum { value = param_name }; \
1380 typedef T param_type; \
1383 CL_HPP_PARAM_NAME_INFO_1_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1384 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
1385 CL_HPP_PARAM_NAME_INFO_1_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1386 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
1387 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1388 CL_HPP_PARAM_NAME_INFO_1_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1389 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1390 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
1391 CL_HPP_PARAM_NAME_INFO_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1392 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
1393 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
1394 CL_HPP_PARAM_NAME_INFO_2_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1395 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
1397 #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1398 CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1399 #endif // #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1401 #if defined(CL_HPP_USE_IL_KHR)
1402 CL_HPP_PARAM_NAME_INFO_IL_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1403 #endif // #if defined(CL_HPP_USE_IL_KHR)
1407 #define CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(F) \
1408 F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties)
1410 #define CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(F) \
1411 F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool)
1413 #define CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(F) \
1414 F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer)
1418 #if CL_HPP_TARGET_OPENCL_VERSION > 100 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 && CL_HPP_TARGET_OPENCL_VERSION < 200
1419 CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1420 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 110
1421 #if CL_HPP_TARGET_OPENCL_VERSION > 110 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1422 CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1423 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1424 #if CL_HPP_TARGET_OPENCL_VERSION > 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1425 CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1426 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
1428 #if defined(CL_HPP_USE_CL_DEVICE_FISSION)
1429 CL_HPP_PARAM_NAME_DEVICE_FISSION_(CL_HPP_DECLARE_PARAM_TRAITS_);
1430 #endif // CL_HPP_USE_CL_DEVICE_FISSION
1432 #ifdef CL_PLATFORM_ICD_SUFFIX_KHR
1433 CL_HPP_DECLARE_PARAM_TRAITS_(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR,
string)
1436 #ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
1437 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong)
1440 #ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
1441 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, vector<size_type>)
1443 #ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
1444 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint)
1446 #ifdef CL_DEVICE_SIMD_WIDTH_AMD
1447 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint)
1449 #ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD
1450 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint)
1452 #ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD
1453 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint)
1455 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
1456 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint)
1458 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
1459 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint)
1461 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
1462 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint)
1464 #ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
1465 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint)
1467 #ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
1468 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint)
1471 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
1472 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint)
1474 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV
1475 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint)
1477 #ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV
1478 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint)
1480 #ifdef CL_DEVICE_WARP_SIZE_NV
1481 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint)
1483 #ifdef CL_DEVICE_GPU_OVERLAP_NV
1484 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool)
1486 #ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV
1487 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool)
1489 #ifdef CL_DEVICE_INTEGRATED_MEMORY_NV
1490 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool)
1495 template <
typename Func,
typename T>
1497 getInfo(Func f, cl_uint name, T* param)
1499 return getInfoHelper(f, name, param, 0);
1502 template <
typename Func,
typename Arg0>
1505 Func f_;
const Arg0& arg0_;
1507 cl_uint param, size_type size,
void* value, size_type* size_ret)
1508 {
return f_(arg0_, param, size, value, size_ret); }
1511 template <
typename Func,
typename Arg0,
typename Arg1>
1514 Func f_;
const Arg0& arg0_;
const Arg1& arg1_;
1516 cl_uint param, size_type size,
void* value, size_type* size_ret)
1517 {
return f_(arg0_, arg1_, param, size, value, size_ret); }
1520 template <
typename Func,
typename Arg0,
typename T>
1522 getInfo(Func f,
const Arg0& arg0, cl_uint name, T* param)
1525 return getInfoHelper(f0, name, param, 0);
1528 template <
typename Func,
typename Arg0,
typename Arg1,
typename T>
1530 getInfo(Func f,
const Arg0& arg0,
const Arg1& arg1, cl_uint name, T* param)
1532 GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
1533 return getInfoHelper(f0, name, param, 0);
1537 template<
typename T>
1538 struct ReferenceHandler
1541 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1558 { return ::clRetainDevice(device); }
1569 { return ::clReleaseDevice(device); }
1571 #else // CL_HPP_TARGET_OPENCL_VERSION >= 120
1576 struct ReferenceHandler<cl_device_id>
1579 static cl_int retain(cl_device_id)
1580 {
return CL_SUCCESS; }
1582 static cl_int release(cl_device_id)
1583 {
return CL_SUCCESS; }
1585 #endif // ! (CL_HPP_TARGET_OPENCL_VERSION >= 120)
1591 static cl_int retain(cl_platform_id)
1592 {
return CL_SUCCESS; }
1594 static cl_int release(cl_platform_id)
1595 {
return CL_SUCCESS; }
1601 static cl_int retain(cl_context context)
1602 { return ::clRetainContext(context); }
1603 static cl_int release(cl_context context)
1604 { return ::clReleaseContext(context); }
1610 static cl_int retain(cl_command_queue queue)
1611 { return ::clRetainCommandQueue(queue); }
1612 static cl_int release(cl_command_queue queue)
1613 { return ::clReleaseCommandQueue(queue); }
1619 static cl_int retain(cl_mem memory)
1620 { return ::clRetainMemObject(memory); }
1621 static cl_int release(cl_mem memory)
1622 { return ::clReleaseMemObject(memory); }
1628 static cl_int retain(cl_sampler sampler)
1629 { return ::clRetainSampler(sampler); }
1630 static cl_int release(cl_sampler sampler)
1631 { return ::clReleaseSampler(sampler); }
1637 static cl_int retain(cl_program program)
1638 { return ::clRetainProgram(program); }
1639 static cl_int release(cl_program program)
1640 { return ::clReleaseProgram(program); }
1646 static cl_int retain(cl_kernel kernel)
1647 { return ::clRetainKernel(kernel); }
1648 static cl_int release(cl_kernel kernel)
1649 { return ::clReleaseKernel(kernel); }
1655 static cl_int retain(cl_event event)
1656 { return ::clRetainEvent(event); }
1657 static cl_int release(cl_event event)
1658 { return ::clReleaseEvent(event); }
1662 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1664 static cl_uint getVersion(
const vector<char> &versionInfo)
1666 int highVersion = 0;
1669 while(versionInfo[index] !=
'.' ) {
1671 highVersion += versionInfo[index]-
'0';
1675 while(versionInfo[index] !=
' ' && versionInfo[index] !=
'\0') {
1677 lowVersion += versionInfo[index]-
'0';
1680 return (highVersion << 16) | lowVersion;
1683 static cl_uint getPlatformVersion(cl_platform_id platform)
1686 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size);
1688 vector<char> versionInfo(size);
1689 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, versionInfo.data(), &size);
1690 return getVersion(versionInfo);
1693 static cl_uint getDevicePlatformVersion(cl_device_id device)
1695 cl_platform_id platform;
1696 clGetDeviceInfo(device, CL_DEVICE_PLATFORM,
sizeof(platform), &platform, NULL);
1697 return getPlatformVersion(platform);
1700 static cl_uint getContextPlatformVersion(cl_context context)
1705 clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size);
1708 vector<cl_device_id> devices(size/
sizeof(cl_device_id));
1709 clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices.data(), NULL);
1710 return getDevicePlatformVersion(devices[0]);
1712 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1714 template <
typename T>
1726 Wrapper(
const cl_type &obj,
bool retainObject) : object_(obj)
1729 detail::errHandler(retain(), __RETAIN_ERR);
1735 if (object_ != NULL) { release(); }
1740 object_ = rhs.object_;
1741 detail::errHandler(retain(), __RETAIN_ERR);
1746 object_ = rhs.object_;
1753 detail::errHandler(release(), __RELEASE_ERR);
1754 object_ = rhs.object_;
1755 detail::errHandler(retain(), __RETAIN_ERR);
1763 detail::errHandler(release(), __RELEASE_ERR);
1764 object_ = rhs.object_;
1772 detail::errHandler(release(), __RELEASE_ERR);
1777 const cl_type& operator ()()
const {
return object_; }
1779 cl_type& operator ()() {
return object_; }
1781 const cl_type get()
const {
return object_; }
1783 cl_type get() {
return object_; }
1787 template<
typename Func,
typename U>
1788 friend inline cl_int getInfoHelper(Func, cl_uint, U*,
int,
typename U::cl_type);
1790 cl_int retain()
const
1792 if (object_ !=
nullptr) {
1800 cl_int release()
const
1802 if (object_ !=
nullptr) {
1815 typedef cl_device_id cl_type;
1819 bool referenceCountable_;
1821 static bool isReferenceCountable(cl_device_id device)
1823 bool retVal =
false;
1824 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1825 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
1826 if (device != NULL) {
1827 int version = getDevicePlatformVersion(device);
1828 if(version > ((1 << 16) + 1)) {
1832 #else // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1834 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1835 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1840 Wrapper() : object_(NULL), referenceCountable_(
false)
1844 Wrapper(
const cl_type &obj,
bool retainObject) :
1846 referenceCountable_(
false)
1848 referenceCountable_ = isReferenceCountable(obj);
1851 detail::errHandler(retain(), __RETAIN_ERR);
1862 object_ = rhs.object_;
1863 referenceCountable_ = isReferenceCountable(object_);
1864 detail::errHandler(retain(), __RETAIN_ERR);
1869 object_ = rhs.object_;
1870 referenceCountable_ = rhs.referenceCountable_;
1872 rhs.referenceCountable_ =
false;
1878 detail::errHandler(release(), __RELEASE_ERR);
1879 object_ = rhs.object_;
1880 referenceCountable_ = rhs.referenceCountable_;
1881 detail::errHandler(retain(), __RETAIN_ERR);
1889 detail::errHandler(release(), __RELEASE_ERR);
1890 object_ = rhs.object_;
1891 referenceCountable_ = rhs.referenceCountable_;
1893 rhs.referenceCountable_ =
false;
1900 detail::errHandler(release(), __RELEASE_ERR);
1902 referenceCountable_ = isReferenceCountable(object_);
1906 const cl_type& operator ()()
const {
return object_; }
1908 cl_type& operator ()() {
return object_; }
1910 cl_type get()
const {
return object_; }
1913 template<
typename Func,
typename U>
1914 friend inline cl_int getInfoHelper(Func, cl_uint, U*,
int,
typename U::cl_type);
1916 template<
typename Func,
typename U>
1917 friend inline cl_int getInfoHelper(Func, cl_uint, vector<U>*,
int,
typename U::cl_type);
1919 cl_int retain()
const
1921 if( object_ !=
nullptr && referenceCountable_ ) {
1929 cl_int release()
const
1931 if (object_ !=
nullptr && referenceCountable_) {
1940 template <
typename T>
1943 return lhs() == rhs();
1946 template <
typename T>
1947 inline bool operator!=(
const Wrapper<T> &lhs,
const Wrapper<T> &rhs)
1949 return !operator==(lhs, rhs);
1956 using BuildLogType = vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, CL_PROGRAM_BUILD_LOG>::param_type>>;
1957 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
1961 class BuildError :
public Error
1964 BuildLogType buildLogs;
1966 BuildError(cl_int err,
const char * errStr,
const BuildLogType &vec) : Error(err, errStr), buildLogs(vec)
1970 BuildLogType getBuildLog()
const
1976 static inline cl_int buildErrHandler(
1978 const char * errStr,
1979 const BuildLogType &buildLogs)
1981 if (err != CL_SUCCESS) {
1982 throw BuildError(err, errStr, buildLogs);
1990 static inline cl_int buildErrHandler(
1992 const char * errStr,
1993 const BuildLogType &buildLogs)
2000 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2016 image_channel_order = order;
2017 image_channel_data_type = type;
2024 this->image_channel_data_type = rhs.image_channel_data_type;
2025 this->image_channel_order = rhs.image_channel_order;
2041 static std::once_flag default_initialized_;
2043 static cl_int default_error_;
2050 static void makeDefault();
2057 static void makeDefaultProvided(
const Device &p) {
2062 #ifdef CL_HPP_UNIT_TEST_ENABLE
2069 static void unitTestClearDefault() {
2072 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2081 explicit Device(
const cl_device_id &device,
bool retainObject =
false) :
2082 detail::Wrapper<cl_type>(device, retainObject) { }
2089 cl_int *errResult = NULL)
2091 std::call_once(default_initialized_, makeDefault);
2092 detail::errHandler(default_error_);
2093 if (errResult != NULL) {
2094 *errResult = default_error_;
2108 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_device));
2109 detail::errHandler(default_error_);
2152 template <
typename T>
2153 cl_int
getInfo(cl_device_info name, T* param)
const
2155 return detail::errHandler(
2156 detail::getInfo(&::clGetDeviceInfo, object_, name, param),
2157 __GET_DEVICE_INFO_ERR);
2161 template <cl_
int name>
typename
2166 detail::cl_device_info, name>::param_type param;
2167 cl_int result =
getInfo(name, ¶m);
2175 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2184 cl_ulong retVal = 0;
2186 clGetHostTimer(this->get(), &retVal);
2189 __GET_HOST_TIMER_ERR);
2208 std::pair<cl_ulong, cl_ulong> retVal;
2210 clGetDeviceAndHostTimer(this->get(), &(retVal.first), &(retVal.second));
2213 __GET_DEVICE_AND_HOST_TIMER_ERR);
2219 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2224 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
2227 const cl_device_partition_property * properties,
2228 vector<Device>* devices)
2231 cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n);
2232 if (err != CL_SUCCESS) {
2233 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2236 vector<cl_device_id> ids(n);
2237 err = clCreateSubDevices(object_, properties, n, ids.data(), NULL);
2238 if (err != CL_SUCCESS) {
2239 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2245 devices->resize(ids.size());
2249 for (size_type i = 0; i < ids.size(); i++) {
2252 (*devices)[i] =
Device(ids[i],
false);
2258 #elif defined(CL_HPP_USE_CL_DEVICE_FISSION)
2264 const cl_device_partition_property_ext * properties,
2265 vector<Device>* devices)
2267 typedef CL_API_ENTRY cl_int
2268 ( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
2270 const cl_device_partition_property_ext * ,
2273 cl_uint * ) CL_EXT_SUFFIX__VERSION_1_1;
2275 static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
2276 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSubDevicesEXT);
2279 cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
2280 if (err != CL_SUCCESS) {
2281 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2284 vector<cl_device_id> ids(n);
2285 err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids.data(), NULL);
2286 if (err != CL_SUCCESS) {
2287 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2292 devices->resize(ids.size());
2296 for (size_type i = 0; i < ids.size(); i++) {
2299 (*devices)[i] =
Device(ids[i],
false);
2304 #endif // defined(CL_HPP_USE_CL_DEVICE_FISSION)
2307 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Device::default_initialized_;
2308 CL_HPP_DEFINE_STATIC_MEMBER_ Device Device::default_;
2309 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Device::default_error_ = CL_SUCCESS;
2321 static std::once_flag default_initialized_;
2323 static cl_int default_error_;
2330 static void makeDefault() {
2334 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2342 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2343 if (err != CL_SUCCESS) {
2344 default_error_ = err;
2348 default_error_ = CL_INVALID_PLATFORM;
2352 vector<cl_platform_id> ids(n);
2353 err = ::clGetPlatformIDs(n, ids.data(), NULL);
2354 if (err != CL_SUCCESS) {
2355 default_error_ = err;
2361 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2362 catch (cl::Error &e) {
2363 default_error_ = e.err();
2373 static void makeDefaultProvided(
const Platform &p) {
2378 #ifdef CL_HPP_UNIT_TEST_ENABLE
2385 static void unitTestClearDefault() {
2388 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2400 explicit Platform(
const cl_platform_id &platform,
bool retainObject =
false) :
2401 detail::Wrapper<cl_type>(platform, retainObject) { }
2414 cl_int *errResult = NULL)
2416 std::call_once(default_initialized_, makeDefault);
2417 detail::errHandler(default_error_);
2418 if (errResult != NULL) {
2419 *errResult = default_error_;
2433 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_platform));
2434 detail::errHandler(default_error_);
2439 cl_int
getInfo(cl_platform_info name,
string* param)
const
2441 return detail::errHandler(
2442 detail::getInfo(&::clGetPlatformInfo, object_, name, param),
2443 __GET_PLATFORM_INFO_ERR);
2447 template <cl_
int name>
typename
2452 detail::cl_platform_info, name>::param_type param;
2453 cl_int result =
getInfo(name, ¶m);
2465 cl_device_type type,
2466 vector<Device>* devices)
const
2469 if( devices == NULL ) {
2470 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2472 cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
2473 if (err != CL_SUCCESS) {
2474 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2477 vector<cl_device_id> ids(n);
2478 err = ::clGetDeviceIDs(object_, type, n, ids.data(), NULL);
2479 if (err != CL_SUCCESS) {
2480 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2488 devices->resize(ids.size());
2492 for (size_type i = 0; i < ids.size(); i++) {
2493 (*devices)[i] =
Device(ids[i],
true);
2499 #if defined(CL_HPP_USE_DX_INTEROP)
2524 cl_d3d10_device_source_khr d3d_device_source,
2526 cl_d3d10_device_set_khr d3d_device_set,
2527 vector<Device>* devices)
const
2529 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
2530 cl_platform_id platform,
2531 cl_d3d10_device_source_khr d3d_device_source,
2533 cl_d3d10_device_set_khr d3d_device_set,
2534 cl_uint num_entries,
2535 cl_device_id * devices,
2536 cl_uint* num_devices);
2538 if( devices == NULL ) {
2539 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2542 static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
2543 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(object_, clGetDeviceIDsFromD3D10KHR);
2546 cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
2554 if (err != CL_SUCCESS) {
2555 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2558 vector<cl_device_id> ids(n);
2559 err = pfn_clGetDeviceIDsFromD3D10KHR(
2567 if (err != CL_SUCCESS) {
2568 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2576 devices->resize(ids.size());
2580 for (size_type i = 0; i < ids.size(); i++) {
2581 (*devices)[i] = Device(ids[i],
true);
2593 vector<Platform>* platforms)
2597 if( platforms == NULL ) {
2598 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
2601 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2602 if (err != CL_SUCCESS) {
2603 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2606 vector<cl_platform_id> ids(n);
2607 err = ::clGetPlatformIDs(n, ids.data(), NULL);
2608 if (err != CL_SUCCESS) {
2609 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2613 platforms->resize(ids.size());
2616 for (size_type i = 0; i < ids.size(); i++) {
2617 (*platforms)[i] =
Platform(ids[i]);
2631 Platform default_platform = Platform::getDefault(&err);
2633 *platform = default_platform;
2647 cl_int * errResult = NULL)
2650 Platform default_platform = Platform::getDefault(&err);
2654 return default_platform;
2657 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
2662 return ::clUnloadPlatformCompiler(object_);
2664 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
2667 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Platform::default_initialized_;
2668 CL_HPP_DEFINE_STATIC_MEMBER_ Platform Platform::default_;
2669 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Platform::default_error_ = CL_SUCCESS;
2675 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2680 inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int
2685 return ::clUnloadCompiler();
2687 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2701 static std::once_flag default_initialized_;
2703 static cl_int default_error_;
2710 static void makeDefault() {
2714 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2718 #if !defined(__APPLE__) && !defined(__MACOS)
2719 const Platform &p = Platform::getDefault();
2720 cl_platform_id defaultPlatform = p();
2721 cl_context_properties properties[3] = {
2722 CL_CONTEXT_PLATFORM, (cl_context_properties)defaultPlatform, 0
2724 #else // #if !defined(__APPLE__) && !defined(__MACOS)
2725 cl_context_properties *properties =
nullptr;
2726 #endif // #if !defined(__APPLE__) && !defined(__MACOS)
2729 CL_DEVICE_TYPE_DEFAULT,
2735 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2736 catch (cl::Error &e) {
2737 default_error_ = e.err();
2748 static void makeDefaultProvided(
const Context &c) {
2753 #ifdef CL_HPP_UNIT_TEST_ENABLE
2760 static void unitTestClearDefault() {
2763 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2770 const vector<Device>& devices,
2771 cl_context_properties* properties = NULL,
2772 void (CL_CALLBACK * notifyFptr)(
2782 size_type numDevices = devices.size();
2783 vector<cl_device_id> deviceIDs(numDevices);
2785 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
2786 deviceIDs[deviceIndex] = (devices[deviceIndex])();
2789 object_ = ::clCreateContext(
2790 properties, (cl_uint) numDevices,
2792 notifyFptr, data, &error);
2794 detail::errHandler(error, __CREATE_CONTEXT_ERR);
2802 cl_context_properties* properties = NULL,
2803 void (CL_CALLBACK * notifyFptr)(
2813 cl_device_id deviceID = device();
2815 object_ = ::clCreateContext(
2818 notifyFptr, data, &error);
2820 detail::errHandler(error, __CREATE_CONTEXT_ERR);
2831 cl_device_type type,
2832 cl_context_properties* properties = NULL,
2833 void (CL_CALLBACK * notifyFptr)(
2843 #if !defined(__APPLE__) && !defined(__MACOS)
2844 cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 };
2846 if (properties == NULL) {
2848 vector<Platform> platforms;
2849 error = Platform::get(&platforms);
2850 if (error != CL_SUCCESS) {
2851 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2859 cl_context_properties platform_id = 0;
2860 for (
unsigned int i = 0; i < platforms.size(); i++) {
2862 vector<Device> devices;
2864 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2868 error = platforms[i].getDevices(type, &devices);
2870 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2871 }
catch (cl::Error& e) {
2879 if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) {
2880 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2886 if (devices.size() > 0) {
2887 platform_id = (cl_context_properties)platforms[i]();
2892 if (platform_id == 0) {
2893 detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR);
2895 *err = CL_DEVICE_NOT_FOUND;
2900 prop[1] = platform_id;
2901 properties = &prop[0];
2904 object_ = ::clCreateContextFromType(
2905 properties, type, notifyFptr, data, &error);
2907 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2948 std::call_once(default_initialized_, makeDefault);
2949 detail::errHandler(default_error_);
2951 *err = default_error_;
2965 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_context));
2966 detail::errHandler(default_error_);
2978 explicit Context(
const cl_context& context,
bool retainObject =
false) :
2979 detail::Wrapper<cl_type>(context, retainObject) { }
2993 template <
typename T>
2994 cl_int
getInfo(cl_context_info name, T* param)
const
2996 return detail::errHandler(
2997 detail::getInfo(&::clGetContextInfo, object_, name, param),
2998 __GET_CONTEXT_INFO_ERR);
3002 template <cl_
int name>
typename
3007 detail::cl_context_info, name>::param_type param;
3008 cl_int result =
getInfo(name, ¶m);
3021 cl_mem_object_type type,
3022 vector<ImageFormat>* formats)
const
3030 cl_int err = ::clGetSupportedImageFormats(
3037 if (err != CL_SUCCESS) {
3038 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3041 if (numEntries > 0) {
3042 vector<ImageFormat> value(numEntries);
3043 err = ::clGetSupportedImageFormats(
3048 (cl_image_format*)value.data(),
3050 if (err != CL_SUCCESS) {
3051 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3054 formats->assign(begin(value), end(value));
3065 inline void Device::makeDefault()
3070 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3077 detail::errHandler(error, __CREATE_CONTEXT_ERR);
3079 if (error != CL_SUCCESS) {
3080 default_error_ = error;
3083 default_ = context.
getInfo<CL_CONTEXT_DEVICES>()[0];
3084 default_error_ = CL_SUCCESS;
3087 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3088 catch (cl::Error &e) {
3089 default_error_ = e.err();
3094 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Context::default_initialized_;
3095 CL_HPP_DEFINE_STATIC_MEMBER_ Context Context::default_;
3096 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Context::default_error_ = CL_SUCCESS;
3110 Event() : detail::Wrapper<cl_type>() { }
3120 explicit Event(
const cl_event& event,
bool retainObject =
false) :
3121 detail::Wrapper<cl_type>(event, retainObject) { }
3135 template <
typename T>
3136 cl_int
getInfo(cl_event_info name, T* param)
const
3138 return detail::errHandler(
3139 detail::getInfo(&::clGetEventInfo, object_, name, param),
3140 __GET_EVENT_INFO_ERR);
3144 template <cl_
int name>
typename
3149 detail::cl_event_info, name>::param_type param;
3150 cl_int result =
getInfo(name, ¶m);
3158 template <
typename T>
3161 return detail::errHandler(detail::getInfo(
3162 &::clGetEventProfilingInfo, object_, name, param),
3163 __GET_EVENT_PROFILE_INFO_ERR);
3167 template <cl_
int name>
typename
3172 detail::cl_profiling_info, name>::param_type param;
3186 return detail::errHandler(
3187 ::clWaitForEvents(1, &object_),
3188 __WAIT_FOR_EVENTS_ERR);
3191 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3198 void (CL_CALLBACK * pfn_notify)(cl_event, cl_int,
void *),
3199 void * user_data = NULL)
3201 return detail::errHandler(
3202 ::clSetEventCallback(
3207 __SET_EVENT_CALLBACK_ERR);
3209 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3218 return detail::errHandler(
3220 (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3221 __WAIT_FOR_EVENTS_ERR);
3225 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3239 cl_int * err = NULL)
3242 object_ = ::clCreateUserEvent(
3246 detail::errHandler(error, __CREATE_USER_EVENT_ERR);
3261 return detail::errHandler(
3262 ::clSetUserEventStatus(object_,status),
3263 __SET_USER_EVENT_STATUS_ERR);
3266 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3272 inline static cl_int
3273 WaitForEvents(
const vector<Event>& events)
3275 return detail::errHandler(
3277 (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3278 __WAIT_FOR_EVENTS_ERR);
3306 explicit Memory(
const cl_mem& memory,
bool retainObject) :
3307 detail::Wrapper<cl_type>(memory, retainObject) { }
3350 template <
typename T>
3353 return detail::errHandler(
3354 detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
3355 __GET_MEM_OBJECT_INFO_ERR);
3359 template <cl_
int name>
typename
3364 detail::cl_mem_info, name>::param_type param;
3365 cl_int result =
getInfo(name, ¶m);
3372 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3387 void (CL_CALLBACK * pfn_notify)(cl_mem,
void *),
3388 void * user_data = NULL)
3390 return detail::errHandler(
3391 ::clSetMemObjectDestructorCallback(
3395 __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
3397 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3403 template<
typename IteratorType >
3404 cl_int
copy( IteratorType startIterator, IteratorType endIterator,
cl::Buffer &buffer );
3405 template<
typename IteratorType >
3406 cl_int
copy(
const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3407 template<
typename IteratorType >
3408 cl_int
copy(
const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator,
cl::Buffer &buffer );
3409 template<
typename IteratorType >
3410 cl_int
copy(
const CommandQueue &queue,
const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3413 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
3419 static cl_svm_mem_flags getSVMMemFlags()
3426 template<
class Trait = detail::SVMTraitNull>
3430 static cl_svm_mem_flags getSVMMemFlags()
3432 return CL_MEM_READ_WRITE |
3433 Trait::getSVMMemFlags();
3437 template<
class Trait = detail::SVMTraitNull>
3441 static cl_svm_mem_flags getSVMMemFlags()
3443 return CL_MEM_READ_ONLY |
3444 Trait::getSVMMemFlags();
3448 template<
class Trait = detail::SVMTraitNull>
3452 static cl_svm_mem_flags getSVMMemFlags()
3454 return CL_MEM_WRITE_ONLY |
3455 Trait::getSVMMemFlags();
3459 template<
class Trait = SVMTraitReadWrite<>>
3463 static cl_svm_mem_flags getSVMMemFlags()
3465 return Trait::getSVMMemFlags();
3469 template<
class Trait = SVMTraitReadWrite<>>
3473 static cl_svm_mem_flags getSVMMemFlags()
3475 return CL_MEM_SVM_FINE_GRAIN_BUFFER |
3476 Trait::getSVMMemFlags();
3480 template<
class Trait = SVMTraitReadWrite<>>
3484 static cl_svm_mem_flags getSVMMemFlags()
3487 CL_MEM_SVM_FINE_GRAIN_BUFFER |
3488 CL_MEM_SVM_ATOMICS |
3489 Trait::getSVMMemFlags();
3494 template<
typename T>
3500 const vector<Event>* events = NULL,
3501 Event* event = NULL);
3514 template<
typename T,
class SVMTrait>
3520 typedef T value_type;
3521 typedef value_type* pointer;
3522 typedef const value_type* const_pointer;
3523 typedef value_type& reference;
3524 typedef const value_type& const_reference;
3525 typedef std::size_t size_type;
3526 typedef std::ptrdiff_t difference_type;
3528 template<
typename U>
3534 template<
typename U,
typename V>
3538 context_(
Context::getDefault())
3548 SVMAllocator(
const SVMAllocator &other) :
3549 context_(other.context_)
3553 template<
typename U>
3554 SVMAllocator(
const SVMAllocator<U, SVMTrait> &other) :
3555 context_(other.context_)
3563 pointer address(reference r) CL_HPP_NOEXCEPT_
3565 return std::addressof(r);
3568 const_pointer address(const_reference r) CL_HPP_NOEXCEPT_
3570 return std::addressof(r);
3587 SVMTrait::getSVMMemFlags(),
3590 pointer retValue =
reinterpret_cast<pointer
>(
3592 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3594 std::bad_alloc excep;
3597 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3600 if (!(SVMTrait::getSVMMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) {
3601 cl_int err =
enqueueMapSVM(retValue, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, size*
sizeof(T));
3602 if (err != CL_SUCCESS) {
3603 std::bad_alloc excep;
3612 void deallocate(pointer p, size_type)
3614 clSVMFree(context_(), p);
3623 size_type maxSize = std::numeric_limits<size_type>::max() /
sizeof(T);
3625 for (
const Device &d : context_.
getInfo<CL_CONTEXT_DEVICES>()) {
3628 static_cast<size_type
>(d.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>()));
3634 template<
class U,
class... Args >
3635 void construct(U* p, Args&&... args)
3651 return (context_==rhs.context_);
3661 template<
class SVMTrait>
3664 typedef void value_type;
3665 typedef value_type* pointer;
3666 typedef const value_type* const_pointer;
3668 template<
typename U>
3674 template<
typename U,
typename V>
3678 #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3681 template<
class Alloc>
3688 typedef typename std::allocator_traits<Alloc>::pointer pointer;
3690 Deleter(
const Alloc &alloc, size_type copies) : alloc_{ alloc }, copies_{ copies }
3694 void operator()(pointer ptr)
const {
3695 Alloc tmpAlloc{ alloc_ };
3696 std::allocator_traits<Alloc>::destroy(tmpAlloc, std::addressof(*ptr));
3697 std::allocator_traits<Alloc>::deallocate(tmpAlloc, ptr, copies_);
3708 template <
class T,
class Alloc,
class... Args>
3711 Alloc alloc(alloc_);
3712 static const size_type copies = 1;
3717 T* tmp = std::allocator_traits<Alloc>::allocate(alloc, copies);
3719 std::bad_alloc excep;
3723 std::allocator_traits<Alloc>::construct(
3725 std::addressof(*tmp),
3726 std::forward<Args>(args)...);
3730 catch (std::bad_alloc& b)
3732 std::allocator_traits<Alloc>::deallocate(alloc, tmp, copies);
3737 template<
class T,
class SVMTrait,
class... Args >
3738 cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(Args... args)
3740 SVMAllocator<T, SVMTrait> alloc;
3741 return cl::allocate_pointer<T>(alloc, args...);
3744 template<
class T,
class SVMTrait,
class... Args >
3745 cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(
const cl::Context &c, Args... args)
3747 SVMAllocator<T, SVMTrait> alloc(c);
3748 return cl::allocate_pointer<T>(alloc, args...);
3750 #endif // #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3755 template <
class T >
3761 template <
class T >
3767 template <
class T >
3770 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
3794 void* host_ptr = NULL,
3798 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3800 detail::errHandler(error, __CREATE_BUFFER_ERR);
3818 void* host_ptr = NULL,
3825 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3827 detail::errHandler(error, __CREATE_BUFFER_ERR);
3838 template<
typename IteratorType >
3840 IteratorType startIterator,
3841 IteratorType endIterator,
3843 bool useHostPtr =
false,
3846 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
3849 cl_mem_flags flags = 0;
3851 flags |= CL_MEM_READ_ONLY;
3854 flags |= CL_MEM_READ_WRITE;
3857 flags |= CL_MEM_USE_HOST_PTR;
3860 size_type size =
sizeof(DataType)*(endIterator - startIterator);
3865 object_ = ::clCreateBuffer(context(), flags, size,
static_cast<DataType*
>(&*startIterator), &error);
3867 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
3870 detail::errHandler(error, __CREATE_BUFFER_ERR);
3876 error =
cl::copy(startIterator, endIterator, *
this);
3877 detail::errHandler(error, __CREATE_BUFFER_ERR);
3889 template<
typename IteratorType >
3890 Buffer(
const Context &context, IteratorType startIterator, IteratorType endIterator,
3891 bool readOnly,
bool useHostPtr =
false, cl_int* err = NULL);
3897 template<
typename IteratorType >
3898 Buffer(
const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator,
3899 bool readOnly,
bool useHostPtr =
false, cl_int* err = NULL);
3911 explicit Buffer(
const cl_mem& buffer,
bool retainObject =
false) :
3912 Memory(buffer, retainObject) { }
3952 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3959 cl_buffer_create_type buffer_create_type,
3960 const void * buffer_create_info,
3961 cl_int * err = NULL)
3965 result.object_ = ::clCreateSubBuffer(
3972 detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
3979 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3982 #if defined (CL_HPP_USE_DX_INTEROP)
3991 class BufferD3D10 :
public Buffer
4002 const Context& context,
4004 ID3D10Buffer* bufobj,
4005 cl_int * err = NULL) : pfn_clCreateFromD3D10BufferKHR(nullptr)
4007 typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
4008 cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
4009 cl_int* errcode_ret);
4010 PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR;
4011 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4012 vector<cl_context_properties> props = context.getInfo<CL_CONTEXT_PROPERTIES>();
4013 cl_platform platform = -1;
4014 for(
int i = 0; i < props.size(); ++i ) {
4015 if( props[i] == CL_CONTEXT_PLATFORM ) {
4016 platform = props[i+1];
4019 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateFromD3D10BufferKHR);
4020 #elif CL_HPP_TARGET_OPENCL_VERSION >= 110
4021 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateFromD3D10BufferKHR);
4025 object_ = pfn_clCreateFromD3D10BufferKHR(
4031 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4038 BufferD3D10() : Buffer() { }
4047 explicit BufferD3D10(
const cl_mem& buffer,
bool retainObject =
false) :
4048 Buffer(buffer, retainObject) { }
4054 BufferD3D10& operator = (
const cl_mem& rhs)
4063 BufferD3D10(
const BufferD3D10& buf) :
4069 BufferD3D10& operator = (
const BufferD3D10 &buf)
4078 BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4083 BufferD3D10& operator = (BufferD3D10 &&buf)
4111 cl_int * err = NULL)
4114 object_ = ::clCreateFromGLBuffer(
4120 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4136 explicit BufferGL(
const cl_mem& buffer,
bool retainObject =
false) :
4137 Buffer(buffer, retainObject) { }
4179 cl_gl_object_type *type,
4180 cl_GLuint * gl_object_name)
4182 return detail::errHandler(
4183 ::clGetGLObjectInfo(object_,type,gl_object_name),
4184 __GET_GL_OBJECT_INFO_ERR);
4208 cl_int * err = NULL)
4211 object_ = ::clCreateFromGLRenderbuffer(
4217 detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR);
4234 Buffer(buffer, retainObject) { }
4276 cl_gl_object_type *type,
4277 cl_GLuint * gl_object_name)
4279 return detail::errHandler(
4280 ::clGetGLObjectInfo(object_,type,gl_object_name),
4281 __GET_GL_OBJECT_INFO_ERR);
4304 explicit Image(
const cl_mem& image,
bool retainObject =
false) :
4305 Memory(image, retainObject) { }
4348 template <
typename T>
4351 return detail::errHandler(
4352 detail::getInfo(&::clGetImageInfo, object_, name, param),
4353 __GET_IMAGE_INFO_ERR);
4357 template <cl_
int name>
typename
4362 detail::cl_image_info, name>::param_type param;
4371 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4390 void* host_ptr = NULL,
4394 cl_image_desc desc =
4396 CL_MEM_OBJECT_IMAGE1D,
4398 0, 0, 0, 0, 0, 0, 0, 0
4400 object_ = ::clCreateImage(
4408 detail::errHandler(error, __CREATE_IMAGE_ERR);
4424 explicit Image1D(
const cl_mem& image1D,
bool retainObject =
false) :
4425 Image(image1D, retainObject) { }
4482 cl_image_desc desc =
4484 CL_MEM_OBJECT_IMAGE1D_BUFFER,
4486 0, 0, 0, 0, 0, 0, 0,
4489 object_ = ::clCreateImage(
4497 detail::errHandler(error, __CREATE_IMAGE_ERR);
4513 Image(image1D, retainObject) { }
4561 size_type arraySize,
4564 void* host_ptr = NULL,
4568 cl_image_desc desc =
4570 CL_MEM_OBJECT_IMAGE1D_ARRAY,
4577 object_ = ::clCreateImage(
4585 detail::errHandler(error, __CREATE_IMAGE_ERR);
4600 explicit Image1DArray(
const cl_mem& imageArray,
bool retainObject =
false) :
4601 Image(imageArray, retainObject) { }
4639 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4661 size_type row_pitch = 0,
4662 void* host_ptr = NULL,
4666 bool useCreateImage;
4668 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
4671 cl_uint version = detail::getContextPlatformVersion(context());
4672 useCreateImage = (version >= 0x10002);
4674 #elif CL_HPP_TARGET_OPENCL_VERSION >= 120
4675 useCreateImage =
true;
4677 useCreateImage =
false;
4680 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4683 cl_image_desc desc =
4685 CL_MEM_OBJECT_IMAGE2D,
4692 object_ = ::clCreateImage(
4700 detail::errHandler(error, __CREATE_IMAGE_ERR);
4705 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
4706 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
4707 if (!useCreateImage)
4709 object_ = ::clCreateImage2D(
4710 context(), flags,&format, width, height, row_pitch, host_ptr, &error);
4712 detail::errHandler(error, __CREATE_IMAGE2D_ERR);
4717 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
4720 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4729 const Buffer &sourceBuffer,
4732 size_type row_pitch = 0,
4733 cl_int* err =
nullptr)
4737 cl_image_desc desc =
4739 CL_MEM_OBJECT_IMAGE2D,
4748 object_ = ::clCreateImage(
4756 detail::errHandler(error, __CREATE_IMAGE_ERR);
4757 if (err !=
nullptr) {
4761 #endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4763 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
4778 cl_channel_order order,
4779 const Image &sourceImage,
4780 cl_int* err =
nullptr)
4785 size_type sourceWidth =
4787 size_type sourceHeight =
4789 size_type sourceRowPitch =
4791 cl_uint sourceNumMIPLevels =
4793 cl_uint sourceNumSamples =
4795 cl_image_format sourceFormat =
4800 sourceFormat.image_channel_order = order;
4801 cl_image_desc desc =
4803 CL_MEM_OBJECT_IMAGE2D,
4814 object_ = ::clCreateImage(
4822 detail::errHandler(error, __CREATE_IMAGE_ERR);
4823 if (err !=
nullptr) {
4827 #endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200
4839 explicit Image2D(
const cl_mem& image2D,
bool retainObject =
false) :
4840 Image(image2D, retainObject) { }
4883 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
4907 cl_int * err = NULL)
4910 object_ = ::clCreateFromGLTexture2D(
4918 detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR);
4935 explicit Image2DGL(
const cl_mem& image,
bool retainObject =
false) :
4936 Image2D(image, retainObject) { }
4976 } CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
4977 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
4979 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4990 size_type arraySize,
4994 size_type slicePitch,
4995 void* host_ptr = NULL,
4999 cl_image_desc desc =
5001 CL_MEM_OBJECT_IMAGE2D_ARRAY,
5010 object_ = ::clCreateImage(
5018 detail::errHandler(error, __CREATE_IMAGE_ERR);
5033 explicit Image2DArray(
const cl_mem& imageArray,
bool retainObject =
false) :
Image(imageArray, retainObject) { }
5069 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5091 size_type row_pitch = 0,
5092 size_type slice_pitch = 0,
5093 void* host_ptr = NULL,
5097 bool useCreateImage;
5099 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
5102 cl_uint version = detail::getContextPlatformVersion(context());
5103 useCreateImage = (version >= 0x10002);
5105 #elif CL_HPP_TARGET_OPENCL_VERSION >= 120
5106 useCreateImage =
true;
5108 useCreateImage =
false;
5111 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5114 cl_image_desc desc =
5116 CL_MEM_OBJECT_IMAGE3D,
5125 object_ = ::clCreateImage(
5133 detail::errHandler(error, __CREATE_IMAGE_ERR);
5138 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5139 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
5140 if (!useCreateImage)
5142 object_ = ::clCreateImage3D(
5143 context(), flags, &format, width, height, depth, row_pitch,
5144 slice_pitch, host_ptr, &error);
5146 detail::errHandler(error, __CREATE_IMAGE3D_ERR);
5151 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
5164 explicit Image3D(
const cl_mem& image3D,
bool retainObject =
false) :
5165 Image(image3D, retainObject) { }
5206 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
5229 cl_int * err = NULL)
5232 object_ = ::clCreateFromGLTexture3D(
5240 detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR);
5256 explicit Image3DGL(
const cl_mem& image,
bool retainObject =
false) :
5257 Image3D(image, retainObject) { }
5297 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5299 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5315 cl_int * err = NULL)
5318 object_ = ::clCreateFromGLTexture(
5326 detail::errHandler(error, __CREATE_GL_TEXTURE_ERR);
5341 explicit ImageGL(
const cl_mem& image,
bool retainObject =
false) :
5342 Image(image, retainObject) { }
5344 ImageGL& operator = (
const cl_mem& rhs)
5378 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5382 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5404 cl_uint packet_size,
5405 cl_uint max_packets,
5410 cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5411 object_ = ::clCreatePipe(context(), flags, packet_size, max_packets,
nullptr, &error);
5413 detail::errHandler(error, __CREATE_PIPE_ERR);
5428 cl_uint packet_size,
5429 cl_uint max_packets,
5436 cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5437 object_ = ::clCreatePipe(context(), flags, packet_size, max_packets,
nullptr, &error);
5439 detail::errHandler(error, __CREATE_PIPE_ERR);
5455 explicit Pipe(
const cl_mem& pipe,
bool retainObject =
false) :
5456 Memory(pipe, retainObject) { }
5497 template <
typename T>
5500 return detail::errHandler(
5501 detail::getInfo(&::clGetPipeInfo, object_, name, param),
5502 __GET_PIPE_INFO_ERR);
5506 template <cl_
int name>
typename
5511 detail::cl_pipe_info, name>::param_type param;
5512 cl_int result =
getInfo(name, ¶m);
5519 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
5542 cl_bool normalized_coords,
5543 cl_addressing_mode addressing_mode,
5544 cl_filter_mode filter_mode,
5549 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5550 cl_sampler_properties sampler_properties[] = {
5551 CL_SAMPLER_NORMALIZED_COORDS, normalized_coords,
5552 CL_SAMPLER_ADDRESSING_MODE, addressing_mode,
5553 CL_SAMPLER_FILTER_MODE, filter_mode,
5555 object_ = ::clCreateSamplerWithProperties(
5560 detail::errHandler(error, __CREATE_SAMPLER_WITH_PROPERTIES_ERR);
5565 object_ = ::clCreateSampler(
5572 detail::errHandler(error, __CREATE_SAMPLER_ERR);
5587 explicit Sampler(
const cl_sampler& sampler,
bool retainObject =
false) :
5588 detail::Wrapper<cl_type>(sampler, retainObject) { }
5630 template <
typename T>
5631 cl_int
getInfo(cl_sampler_info name, T* param)
const
5633 return detail::errHandler(
5634 detail::getInfo(&::clGetSamplerInfo, object_, name, param),
5635 __GET_SAMPLER_INFO_ERR);
5639 template <cl_
int name>
typename
5644 detail::cl_sampler_info, name>::param_type param;
5645 cl_int result =
getInfo(name, ¶m);
5655 class DeviceCommandQueue;
5662 size_type sizes_[3];
5663 cl_uint dimensions_;
5694 NDRange(size_type size0, size_type size1, size_type size2)
5706 operator const size_type*()
const {
5720 return dimensions_*
sizeof(size_type);
5728 const size_type* get()
const
5735 static const NDRange NullRange;
5745 template <
typename T,
class Enable =
void>
5750 template <
typename T>
5753 static size_type size(
const T&) {
return sizeof(T); }
5754 static const T* ptr(
const T& value) {
return &value; }
5759 template <
typename T>
5762 static size_type size(
const T&) {
return sizeof(cl_mem); }
5763 static const cl_mem* ptr(
const T& value) {
return &(value()); }
5771 static size_type size(
const LocalSpaceArg& value) {
return value.size_; }
5772 static const void* ptr(
const LocalSpaceArg&) {
return NULL; }
5799 inline Kernel(
const Program& program,
const char* name, cl_int* err = NULL);
5812 explicit Kernel(
const cl_kernel& kernel,
bool retainObject =
false) :
5813 detail::Wrapper<cl_type>(kernel, retainObject) { }
5854 template <
typename T>
5855 cl_int getInfo(cl_kernel_info name, T* param)
const
5857 return detail::errHandler(
5858 detail::getInfo(&::clGetKernelInfo, object_, name, param),
5859 __GET_KERNEL_INFO_ERR);
5862 template <cl_
int name>
typename
5863 detail::param_traits<detail::cl_kernel_info, name>::param_type
5864 getInfo(cl_int* err = NULL)
const
5866 typename detail::param_traits<
5867 detail::cl_kernel_info, name>::param_type param;
5868 cl_int result = getInfo(name, ¶m);
5875 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5876 template <
typename T>
5877 cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param)
const
5879 return detail::errHandler(
5880 detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param),
5881 __GET_KERNEL_ARG_INFO_ERR);
5884 template <cl_
int name>
typename
5885 detail::param_traits<detail::cl_kernel_arg_info, name>::param_type
5886 getArgInfo(cl_uint argIndex, cl_int* err = NULL)
const
5888 typename detail::param_traits<
5889 detail::cl_kernel_arg_info, name>::param_type param;
5890 cl_int result = getArgInfo(argIndex, name, ¶m);
5896 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5898 template <
typename T>
5899 cl_int getWorkGroupInfo(
5900 const Device& device, cl_kernel_work_group_info name, T* param)
const
5902 return detail::errHandler(
5904 &::clGetKernelWorkGroupInfo, object_, device(), name, param),
5905 __GET_KERNEL_WORK_GROUP_INFO_ERR);
5908 template <cl_
int name>
typename
5909 detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
5910 getWorkGroupInfo(
const Device& device, cl_int* err = NULL)
const
5912 typename detail::param_traits<
5913 detail::cl_kernel_work_group_info, name>::param_type param;
5914 cl_int result = getWorkGroupInfo(device, name, ¶m);
5921 #if (CL_HPP_TARGET_OPENCL_VERSION >= 200 && defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)) || CL_HPP_TARGET_OPENCL_VERSION >= 210
5922 cl_int getSubGroupInfo(
const cl::Device &dev, cl_kernel_sub_group_info name,
const cl::NDRange &range, size_type* param)
const
5924 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
5926 return detail::errHandler(
5927 clGetKernelSubGroupInfo(object_, dev(), name, range.
size(), range.get(),
sizeof(size_type), param,
nullptr),
5928 __GET_KERNEL_SUB_GROUP_INFO_ERR);
5930 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
5932 typedef clGetKernelSubGroupInfoKHR_fn PFN_clGetKernelSubGroupInfoKHR;
5933 static PFN_clGetKernelSubGroupInfoKHR pfn_clGetKernelSubGroupInfoKHR = NULL;
5934 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetKernelSubGroupInfoKHR);
5936 return detail::errHandler(
5937 pfn_clGetKernelSubGroupInfoKHR(object_, dev(), name, range.
size(), range.get(),
sizeof(size_type), param,
nullptr),
5938 __GET_KERNEL_SUB_GROUP_INFO_ERR);
5940 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
5943 template <cl_
int name>
5944 size_type getSubGroupInfo(
const cl::Device &dev,
const cl::NDRange &range, cl_int* err = NULL)
const
5947 cl_int result = getSubGroupInfo(dev, name, range, ¶m);
5953 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5955 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5958 template<
typename T,
class D>
5959 cl_int
setArg(cl_uint index,
const cl::pointer<T, D> &argPtr)
5961 return detail::errHandler(
5962 ::clSetKernelArgSVMPointer(object_, index, argPtr.get()),
5963 __SET_KERNEL_ARGS_ERR);
5968 template<
typename T,
class Alloc>
5969 cl_int
setArg(cl_uint index,
const cl::vector<T, Alloc> &argPtr)
5971 return detail::errHandler(
5972 ::clSetKernelArgSVMPointer(object_, index, argPtr.data()),
5973 __SET_KERNEL_ARGS_ERR);
5978 template<
typename T>
5979 typename std::enable_if<std::is_pointer<T>::value, cl_int>::type
5982 return detail::errHandler(
5983 ::clSetKernelArgSVMPointer(object_, index, argPtr),
5984 __SET_KERNEL_ARGS_ERR);
5986 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5990 template <
typename T>
5991 typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
5994 return detail::errHandler(
6000 __SET_KERNEL_ARGS_ERR);
6003 cl_int
setArg(cl_uint index, size_type size,
const void* argPtr)
6005 return detail::errHandler(
6006 ::clSetKernelArg(object_, index, size, argPtr),
6007 __SET_KERNEL_ARGS_ERR);
6010 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6017 return detail::errHandler(
6018 ::clSetKernelExecInfo(
6020 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6021 sizeof(
void*)*pointerList.size(),
6022 pointerList.data()));
6029 template<
int ArrayLength>
6032 return detail::errHandler(
6033 ::clSetKernelExecInfo(
6035 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6036 sizeof(
void*)*pointerList.size(),
6037 pointerList.data()));
6053 cl_bool svmEnabled_ = svmEnabled ? CL_TRUE : CL_FALSE;
6054 return detail::errHandler(
6055 ::clSetKernelExecInfo(
6057 CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM,
6064 template<
int index,
int ArrayLength,
class D,
typename T0,
typename T1,
typename... Ts>
6065 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList,
const pointer<T0, D> &t0,
const pointer<T1, D> &t1, Ts & ... ts)
6067 pointerList[index] =
static_cast<void*
>(t0.get());
6068 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6071 template<
int index,
int ArrayLength,
typename T0,
typename T1,
typename... Ts>
6072 typename std::enable_if<std::is_pointer<T0>::value,
void>::type
6073 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0, T1 t1, Ts... ts)
6075 pointerList[index] =
static_cast<void*
>(t0);
6076 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6079 template<
int index,
int ArrayLength,
typename T0,
class D>
6080 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList,
const pointer<T0, D> &t0)
6082 pointerList[index] =
static_cast<void*
>(t0.get());
6086 template<
int index,
int ArrayLength,
typename T0>
6087 typename std::enable_if<std::is_pointer<T0>::value,
void>::type
6088 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0)
6090 pointerList[index] =
static_cast<void*
>(t0);
6093 template<
typename T0,
typename... Ts>
6096 std::array<
void*, 1 +
sizeof...(Ts)> pointerList;
6098 setSVMPointersHelper<0, 1 +
sizeof...(Ts)>(pointerList, t0, ts...);
6099 return detail::errHandler(
6100 ::clSetKernelExecInfo(
6102 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6103 sizeof(
void*)*(1 +
sizeof...(Ts)),
6104 pointerList.data()));
6106 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6108 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6117 Kernel retValue(clCloneKernel(this->get(), &error));
6119 detail::errHandler(error, __CLONE_KERNEL_ERR);
6122 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6131 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6132 typedef vector<vector<unsigned char>> Binaries;
6133 typedef vector<string> Sources;
6134 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6135 typedef vector<std::pair<const void*, size_type> > Binaries;
6136 typedef vector<std::pair<const char*, size_type> > Sources;
6137 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6140 const string& source,
6146 const char * strings = source.c_str();
6147 const size_type length = source.size();
6151 object_ = ::clCreateProgramWithSource(
6152 context(), (cl_uint)1, &strings, &length, &error);
6154 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6156 if (error == CL_SUCCESS && build) {
6158 error = ::clBuildProgram(
6162 #
if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6170 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6180 const string& source,
6186 const char * strings = source.c_str();
6187 const size_type length = source.size();
6189 object_ = ::clCreateProgramWithSource(
6190 context(), (cl_uint)1, &strings, &length, &error);
6192 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6194 if (error == CL_SUCCESS && build) {
6195 error = ::clBuildProgram(
6199 #
if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6207 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6220 const Sources& sources,
6226 const size_type n = (size_type)sources.size();
6228 vector<size_type> lengths(n);
6229 vector<const char*> strings(n);
6231 for (size_type i = 0; i < n; ++i) {
6232 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6233 strings[i] = sources[(int)i].data();
6234 lengths[i] = sources[(int)i].length();
6235 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6236 strings[i] = sources[(int)i].first;
6237 lengths[i] = sources[(int)i].second;
6238 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6241 object_ = ::clCreateProgramWithSource(
6242 context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6244 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6256 const Sources& sources,
6261 const size_type n = (size_type)sources.size();
6263 vector<size_type> lengths(n);
6264 vector<const char*> strings(n);
6266 for (size_type i = 0; i < n; ++i) {
6267 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6268 strings[i] = sources[(int)i].data();
6269 lengths[i] = sources[(int)i].length();
6270 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6271 strings[i] = sources[(int)i].first;
6272 lengths[i] = sources[(int)i].second;
6273 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6276 object_ = ::clCreateProgramWithSource(
6277 context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6279 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6286 #if CL_HPP_TARGET_OPENCL_VERSION >= 210 || (CL_HPP_TARGET_OPENCL_VERSION==200 && defined(CL_HPP_USE_IL_KHR))
6292 const vector<char>& IL,
6300 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6302 object_ = ::clCreateProgramWithIL(
6303 context(),
static_cast<const void*
>(IL.data()), IL.size(), &error);
6305 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6307 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6308 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6309 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6311 return detail::errHandler(
6312 pfn_clCreateProgramWithILKHR(
6313 context(),
static_cast<const void*
>(IL.data()), IL.size(), &error);
6317 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6319 if (error == CL_SUCCESS && build) {
6321 error = ::clBuildProgram(
6325 #
if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6333 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6348 const vector<char>& IL,
6354 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6356 object_ = ::clCreateProgramWithIL(
6357 context(),
static_cast<const void*
>(IL.data()), IL.size(), &error);
6359 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6361 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6362 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6363 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6365 return detail::errHandler(
6366 pfn_clCreateProgramWithILKHR(
6367 context(),
static_cast<const void*
>(IL.data()), IL.size(), &error);
6371 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6373 if (error == CL_SUCCESS && build) {
6374 error = ::clBuildProgram(
6378 #
if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6386 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6393 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6416 const vector<Device>& devices,
6417 const Binaries& binaries,
6418 vector<cl_int>* binaryStatus = NULL,
6423 const size_type numDevices = devices.size();
6426 if(binaries.size() != numDevices) {
6427 error = CL_INVALID_VALUE;
6428 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6436 vector<size_type> lengths(numDevices);
6437 vector<const unsigned char*> images(numDevices);
6438 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6439 for (size_type i = 0; i < numDevices; ++i) {
6440 images[i] = binaries[i].data();
6441 lengths[i] = binaries[(int)i].size();
6443 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6444 for (size_type i = 0; i < numDevices; ++i) {
6445 images[i] = (
const unsigned char*)binaries[i].first;
6446 lengths[i] = binaries[(int)i].second;
6448 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6450 vector<cl_device_id> deviceIDs(numDevices);
6451 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6452 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6456 binaryStatus->resize(numDevices);
6459 object_ = ::clCreateProgramWithBinary(
6460 context(), (cl_uint) devices.size(),
6462 lengths.data(), images.data(), (binaryStatus != NULL && numDevices > 0)
6463 ? &binaryStatus->front()
6466 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6473 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6480 const vector<Device>& devices,
6481 const string& kernelNames,
6487 size_type numDevices = devices.size();
6488 vector<cl_device_id> deviceIDs(numDevices);
6489 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6490 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6493 object_ = ::clCreateProgramWithBuiltInKernels(
6495 (cl_uint) devices.size(),
6497 kernelNames.c_str(),
6500 detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR);
6505 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6516 explicit Program(
const cl_program& program,
bool retainObject =
false) :
6517 detail::Wrapper<cl_type>(program, retainObject) { }
6519 Program& operator = (
const cl_program& rhs)
6554 const vector<Device>& devices,
6555 const char* options = NULL,
6556 void (CL_CALLBACK * notifyFptr)(cl_program,
void *) = NULL,
6557 void* data = NULL)
const
6559 size_type numDevices = devices.size();
6560 vector<cl_device_id> deviceIDs(numDevices);
6562 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6563 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6566 cl_int buildError = ::clBuildProgram(
6575 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6579 const char* options = NULL,
6580 void (CL_CALLBACK * notifyFptr)(cl_program,
void *) = NULL,
6581 void* data = NULL)
const
6583 cl_int buildError = ::clBuildProgram(
6592 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6595 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6597 const char* options = NULL,
6598 void (CL_CALLBACK * notifyFptr)(cl_program,
void *) = NULL,
6599 void* data = NULL)
const
6601 cl_int error = ::clCompileProgram(
6611 return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6613 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6615 template <
typename T>
6616 cl_int getInfo(cl_program_info name, T* param)
const
6618 return detail::errHandler(
6619 detail::getInfo(&::clGetProgramInfo, object_, name, param),
6620 __GET_PROGRAM_INFO_ERR);
6623 template <cl_
int name>
typename
6624 detail::param_traits<detail::cl_program_info, name>::param_type
6625 getInfo(cl_int* err = NULL)
const
6627 typename detail::param_traits<
6628 detail::cl_program_info, name>::param_type param;
6629 cl_int result = getInfo(name, ¶m);
6636 template <
typename T>
6637 cl_int getBuildInfo(
6638 const Device& device, cl_program_build_info name, T* param)
const
6640 return detail::errHandler(
6642 &::clGetProgramBuildInfo, object_, device(), name, param),
6643 __GET_PROGRAM_BUILD_INFO_ERR);
6646 template <cl_
int name>
typename
6647 detail::param_traits<detail::cl_program_build_info, name>::param_type
6648 getBuildInfo(
const Device& device, cl_int* err = NULL)
const
6650 typename detail::param_traits<
6651 detail::cl_program_build_info, name>::param_type param;
6652 cl_int result = getBuildInfo(device, name, ¶m);
6664 template <cl_
int name>
6665 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6668 cl_int result = CL_SUCCESS;
6670 auto devs = getInfo<CL_PROGRAM_DEVICES>(&result);
6671 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6675 if (result != CL_SUCCESS) {
6684 detail::cl_program_build_info, name>::param_type param;
6685 result = getBuildInfo(d, name, ¶m);
6689 if (result != CL_SUCCESS) {
6697 if (result != CL_SUCCESS) {
6703 cl_int createKernels(vector<Kernel>* kernels)
6706 cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
6707 if (err != CL_SUCCESS) {
6708 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6711 vector<cl_kernel> value(numKernels);
6713 err = ::clCreateKernelsInProgram(
6714 object_, numKernels, value.data(), NULL);
6715 if (err != CL_SUCCESS) {
6716 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6720 kernels->resize(value.size());
6724 for (size_type i = 0; i < value.size(); i++) {
6727 (*kernels)[i] = Kernel(value[i],
false);
6734 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6735 inline Program linkProgram(
6738 const char* options = NULL,
6739 void (CL_CALLBACK * notifyFptr)(cl_program,
void *) = NULL,
6743 cl_int error_local = CL_SUCCESS;
6745 cl_program programs[2] = { input1(), input2() };
6747 Context ctx = input1.getInfo<CL_PROGRAM_CONTEXT>(&error_local);
6748 if(error_local!=CL_SUCCESS) {
6749 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
6752 cl_program prog = ::clLinkProgram(
6763 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
6768 return Program(prog);
6771 inline Program linkProgram(
6772 vector<Program> inputPrograms,
6773 const char* options = NULL,
6774 void (CL_CALLBACK * notifyFptr)(cl_program,
void *) = NULL,
6778 cl_int error_local = CL_SUCCESS;
6780 vector<cl_program> programs(inputPrograms.size());
6782 for (
unsigned int i = 0; i < inputPrograms.size(); i++) {
6783 programs[i] = inputPrograms[i]();
6787 if(inputPrograms.size() > 0) {
6788 ctx = inputPrograms[0].getInfo<CL_PROGRAM_CONTEXT>(&error_local);
6789 if(error_local!=CL_SUCCESS) {
6790 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
6793 cl_program prog = ::clLinkProgram(
6798 (cl_uint)inputPrograms.size(),
6804 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
6809 return Program(prog,
false);
6811 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6815 inline cl_int cl::Program::getInfo(cl_program_info name, vector<vector<unsigned char>>* param)
const
6817 if (name != CL_PROGRAM_BINARIES) {
6818 return CL_INVALID_VALUE;
6824 vector<size_type> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>();
6825 size_type numBinaries = sizes.size();
6828 param->resize(numBinaries);
6829 for (size_type i = 0; i < numBinaries; ++i) {
6830 (*param)[i].resize(sizes[i]);
6833 return detail::errHandler(
6834 detail::getInfo(&::clGetProgramInfo, object_, name, param),
6835 __GET_PROGRAM_INFO_ERR);
6842 inline vector<vector<unsigned char>> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err)
const
6844 vector<vector<unsigned char>> binariesVectors;
6846 cl_int result = getInfo(CL_PROGRAM_BINARIES, &binariesVectors);
6850 return binariesVectors;
6853 inline Kernel::Kernel(
const Program& program,
const char* name, cl_int* err)
6857 object_ = ::clCreateKernel(program(), name, &error);
6858 detail::errHandler(error, __CREATE_KERNEL_ERR);
6866 enum class QueueProperties : cl_command_queue_properties
6869 Profiling = CL_QUEUE_PROFILING_ENABLE,
6870 OutOfOrder = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,
6873 inline QueueProperties operator|(QueueProperties lhs, QueueProperties rhs)
6875 return static_cast<QueueProperties
>(
static_cast<cl_command_queue_properties
>(lhs) |
static_cast<cl_command_queue_properties
>(rhs));
6884 static std::once_flag default_initialized_;
6886 static cl_int default_error_;
6893 static void makeDefault()
6898 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
6905 if (error != CL_SUCCESS) {
6906 default_error_ = error;
6910 default_ =
CommandQueue(context, device, 0, &default_error_);
6913 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
6914 catch (cl::Error &e) {
6915 default_error_ = e.err();
6925 static void makeDefaultProvided(
const CommandQueue &c) {
6930 #ifdef CL_HPP_UNIT_TEST_ENABLE
6937 static void unitTestClearDefault() {
6940 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
6948 cl_command_queue_properties properties,
6954 detail::errHandler(error, __CREATE_CONTEXT_ERR);
6956 if (error != CL_SUCCESS) {
6963 bool useWithProperties;
6965 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
6968 cl_uint version = detail::getContextPlatformVersion(context());
6969 useWithProperties = (version >= 0x20000);
6971 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
6972 useWithProperties =
true;
6974 useWithProperties =
false;
6977 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6978 if (useWithProperties) {
6979 cl_queue_properties queue_properties[] = {
6980 CL_QUEUE_PROPERTIES, properties, 0 };
6981 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
6982 object_ = ::clCreateCommandQueueWithProperties(
6983 context(), device(), queue_properties, &error);
6986 error = CL_INVALID_QUEUE_PROPERTIES;
6989 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
6994 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
6995 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
6996 if (!useWithProperties) {
6997 object_ = ::clCreateCommandQueue(
6998 context(), device(), properties, &error);
7000 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7005 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7014 QueueProperties properties,
7020 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7022 if (error != CL_SUCCESS) {
7029 bool useWithProperties;
7031 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7034 cl_uint version = detail::getContextPlatformVersion(context());
7035 useWithProperties = (version >= 0x20000);
7037 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7038 useWithProperties =
true;
7040 useWithProperties =
false;
7043 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7044 if (useWithProperties) {
7045 cl_queue_properties queue_properties[] = {
7046 CL_QUEUE_PROPERTIES,
static_cast<cl_queue_properties
>(properties), 0 };
7048 object_ = ::clCreateCommandQueueWithProperties(
7049 context(), device(), queue_properties, &error);
7051 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7056 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7057 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7058 if (!useWithProperties) {
7059 object_ = ::clCreateCommandQueue(
7060 context(), device(),
static_cast<cl_command_queue_properties
>(properties), &error);
7062 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7067 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7078 cl_command_queue_properties properties = 0,
7082 bool useWithProperties;
7083 vector<cl::Device> devices;
7084 error = context.
getInfo(CL_CONTEXT_DEVICES, &devices);
7086 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7088 if (error != CL_SUCCESS)
7096 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7099 cl_uint version = detail::getContextPlatformVersion(context());
7100 useWithProperties = (version >= 0x20000);
7102 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7103 useWithProperties =
true;
7105 useWithProperties =
false;
7108 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7109 if (useWithProperties) {
7110 cl_queue_properties queue_properties[] = {
7111 CL_QUEUE_PROPERTIES, properties, 0 };
7112 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7113 object_ = ::clCreateCommandQueueWithProperties(
7114 context(), devices[0](), queue_properties, &error);
7117 error = CL_INVALID_QUEUE_PROPERTIES;
7120 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7125 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7126 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7127 if (!useWithProperties) {
7128 object_ = ::clCreateCommandQueue(
7129 context(), devices[0](), properties, &error);
7131 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7136 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7145 QueueProperties properties,
7149 bool useWithProperties;
7150 vector<cl::Device> devices;
7151 error = context.
getInfo(CL_CONTEXT_DEVICES, &devices);
7153 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7155 if (error != CL_SUCCESS)
7163 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7166 cl_uint version = detail::getContextPlatformVersion(context());
7167 useWithProperties = (version >= 0x20000);
7169 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7170 useWithProperties =
true;
7172 useWithProperties =
false;
7175 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7176 if (useWithProperties) {
7177 cl_queue_properties queue_properties[] = {
7178 CL_QUEUE_PROPERTIES,
static_cast<cl_queue_properties
>(properties), 0 };
7179 object_ = ::clCreateCommandQueueWithProperties(
7180 context(), devices[0](), queue_properties, &error);
7182 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7187 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7188 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7189 if (!useWithProperties) {
7190 object_ = ::clCreateCommandQueue(
7191 context(), devices[0](),
static_cast<cl_command_queue_properties
>(properties), &error);
7193 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7198 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7208 cl_command_queue_properties properties = 0,
7212 bool useWithProperties;
7214 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7217 cl_uint version = detail::getContextPlatformVersion(context());
7218 useWithProperties = (version >= 0x20000);
7220 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7221 useWithProperties =
true;
7223 useWithProperties =
false;
7226 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7227 if (useWithProperties) {
7228 cl_queue_properties queue_properties[] = {
7229 CL_QUEUE_PROPERTIES, properties, 0 };
7230 object_ = ::clCreateCommandQueueWithProperties(
7231 context(), device(), queue_properties, &error);
7233 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7238 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7239 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7240 if (!useWithProperties) {
7241 object_ = ::clCreateCommandQueue(
7242 context(), device(), properties, &error);
7244 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7249 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7259 QueueProperties properties,
7263 bool useWithProperties;
7265 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7268 cl_uint version = detail::getContextPlatformVersion(context());
7269 useWithProperties = (version >= 0x20000);
7271 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7272 useWithProperties =
true;
7274 useWithProperties =
false;
7277 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7278 if (useWithProperties) {
7279 cl_queue_properties queue_properties[] = {
7280 CL_QUEUE_PROPERTIES,
static_cast<cl_queue_properties
>(properties), 0 };
7281 object_ = ::clCreateCommandQueueWithProperties(
7282 context(), device(), queue_properties, &error);
7284 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7289 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7290 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7291 if (!useWithProperties) {
7292 object_ = ::clCreateCommandQueue(
7293 context(), device(),
static_cast<cl_command_queue_properties
>(properties), &error);
7295 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7300 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7305 std::call_once(default_initialized_, makeDefault);
7306 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7307 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7308 #else // CL_HPP_TARGET_OPENCL_VERSION >= 200
7309 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_ERR);
7310 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7312 *err = default_error_;
7326 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_queue));
7327 detail::errHandler(default_error_);
7340 explicit CommandQueue(
const cl_command_queue& commandQueue,
bool retainObject =
false) :
7341 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
7377 template <
typename T>
7378 cl_int getInfo(cl_command_queue_info name, T* param)
const
7380 return detail::errHandler(
7382 &::clGetCommandQueueInfo, object_, name, param),
7383 __GET_COMMAND_QUEUE_INFO_ERR);
7386 template <cl_
int name>
typename
7387 detail::param_traits<detail::cl_command_queue_info, name>::param_type
7388 getInfo(cl_int* err = NULL)
const
7390 typename detail::param_traits<
7391 detail::cl_command_queue_info, name>::param_type param;
7392 cl_int result = getInfo(name, ¶m);
7399 cl_int enqueueReadBuffer(
7400 const Buffer& buffer,
7405 const vector<Event>* events = NULL,
7406 Event* event = NULL)
const
7409 cl_int err = detail::errHandler(
7410 ::clEnqueueReadBuffer(
7411 object_, buffer(), blocking, offset, size,
7413 (events != NULL) ? (cl_uint) events->size() : 0,
7414 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7415 (event != NULL) ? &tmp : NULL),
7416 __ENQUEUE_READ_BUFFER_ERR);
7418 if (event != NULL && err == CL_SUCCESS)
7424 cl_int enqueueWriteBuffer(
7425 const Buffer& buffer,
7430 const vector<Event>* events = NULL,
7431 Event* event = NULL)
const
7434 cl_int err = detail::errHandler(
7435 ::clEnqueueWriteBuffer(
7436 object_, buffer(), blocking, offset, size,
7438 (events != NULL) ? (cl_uint) events->size() : 0,
7439 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7440 (event != NULL) ? &tmp : NULL),
7441 __ENQUEUE_WRITE_BUFFER_ERR);
7443 if (event != NULL && err == CL_SUCCESS)
7449 cl_int enqueueCopyBuffer(
7452 size_type src_offset,
7453 size_type dst_offset,
7455 const vector<Event>* events = NULL,
7456 Event* event = NULL)
const
7459 cl_int err = detail::errHandler(
7460 ::clEnqueueCopyBuffer(
7461 object_, src(), dst(), src_offset, dst_offset, size,
7462 (events != NULL) ? (cl_uint) events->size() : 0,
7463 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7464 (event != NULL) ? &tmp : NULL),
7465 __ENQEUE_COPY_BUFFER_ERR);
7467 if (event != NULL && err == CL_SUCCESS)
7472 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
7473 cl_int enqueueReadBufferRect(
7474 const Buffer& buffer,
7476 const array<size_type, 3>& buffer_offset,
7477 const array<size_type, 3>& host_offset,
7478 const array<size_type, 3>& region,
7479 size_type buffer_row_pitch,
7480 size_type buffer_slice_pitch,
7481 size_type host_row_pitch,
7482 size_type host_slice_pitch,
7484 const vector<Event>* events = NULL,
7485 Event* event = NULL)
const
7488 cl_int err = detail::errHandler(
7489 ::clEnqueueReadBufferRect(
7493 buffer_offset.data(),
7501 (events != NULL) ? (cl_uint) events->size() : 0,
7502 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7503 (event != NULL) ? &tmp : NULL),
7504 __ENQUEUE_READ_BUFFER_RECT_ERR);
7506 if (event != NULL && err == CL_SUCCESS)
7512 cl_int enqueueWriteBufferRect(
7513 const Buffer& buffer,
7515 const array<size_type, 3>& buffer_offset,
7516 const array<size_type, 3>& host_offset,
7517 const array<size_type, 3>& region,
7518 size_type buffer_row_pitch,
7519 size_type buffer_slice_pitch,
7520 size_type host_row_pitch,
7521 size_type host_slice_pitch,
7523 const vector<Event>* events = NULL,
7524 Event* event = NULL)
const
7527 cl_int err = detail::errHandler(
7528 ::clEnqueueWriteBufferRect(
7532 buffer_offset.data(),
7540 (events != NULL) ? (cl_uint) events->size() : 0,
7541 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7542 (event != NULL) ? &tmp : NULL),
7543 __ENQUEUE_WRITE_BUFFER_RECT_ERR);
7545 if (event != NULL && err == CL_SUCCESS)
7551 cl_int enqueueCopyBufferRect(
7554 const array<size_type, 3>& src_origin,
7555 const array<size_type, 3>& dst_origin,
7556 const array<size_type, 3>& region,
7557 size_type src_row_pitch,
7558 size_type src_slice_pitch,
7559 size_type dst_row_pitch,
7560 size_type dst_slice_pitch,
7561 const vector<Event>* events = NULL,
7562 Event* event = NULL)
const
7565 cl_int err = detail::errHandler(
7566 ::clEnqueueCopyBufferRect(
7577 (events != NULL) ? (cl_uint) events->size() : 0,
7578 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7579 (event != NULL) ? &tmp : NULL),
7580 __ENQEUE_COPY_BUFFER_RECT_ERR);
7582 if (event != NULL && err == CL_SUCCESS)
7587 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
7588 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
7600 template<
typename PatternType>
7603 PatternType pattern,
7606 const vector<Event>* events = NULL,
7607 Event* event = NULL)
const
7610 cl_int err = detail::errHandler(
7611 ::clEnqueueFillBuffer(
7614 static_cast<void*
>(&pattern),
7615 sizeof(PatternType),
7618 (events != NULL) ? (cl_uint) events->size() : 0,
7619 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7620 (event != NULL) ? &tmp : NULL),
7621 __ENQUEUE_FILL_BUFFER_ERR);
7623 if (event != NULL && err == CL_SUCCESS)
7628 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7630 cl_int enqueueReadImage(
7633 const array<size_type, 3>& origin,
7634 const array<size_type, 3>& region,
7635 size_type row_pitch,
7636 size_type slice_pitch,
7638 const vector<Event>* events = NULL,
7639 Event* event = NULL)
const
7642 cl_int err = detail::errHandler(
7643 ::clEnqueueReadImage(
7652 (events != NULL) ? (cl_uint) events->size() : 0,
7653 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7654 (event != NULL) ? &tmp : NULL),
7655 __ENQUEUE_READ_IMAGE_ERR);
7657 if (event != NULL && err == CL_SUCCESS)
7663 cl_int enqueueWriteImage(
7666 const array<size_type, 3>& origin,
7667 const array<size_type, 3>& region,
7668 size_type row_pitch,
7669 size_type slice_pitch,
7671 const vector<Event>* events = NULL,
7672 Event* event = NULL)
const
7675 cl_int err = detail::errHandler(
7676 ::clEnqueueWriteImage(
7685 (events != NULL) ? (cl_uint) events->size() : 0,
7686 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7687 (event != NULL) ? &tmp : NULL),
7688 __ENQUEUE_WRITE_IMAGE_ERR);
7690 if (event != NULL && err == CL_SUCCESS)
7696 cl_int enqueueCopyImage(
7699 const array<size_type, 3>& src_origin,
7700 const array<size_type, 3>& dst_origin,
7701 const array<size_type, 3>& region,
7702 const vector<Event>* events = NULL,
7703 Event* event = NULL)
const
7706 cl_int err = detail::errHandler(
7707 ::clEnqueueCopyImage(
7714 (events != NULL) ? (cl_uint) events->size() : 0,
7715 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7716 (event != NULL) ? &tmp : NULL),
7717 __ENQUEUE_COPY_IMAGE_ERR);
7719 if (event != NULL && err == CL_SUCCESS)
7725 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
7735 cl_float4 fillColor,
7736 const array<size_type, 3>& origin,
7737 const array<size_type, 3>& region,
7738 const vector<Event>* events = NULL,
7739 Event* event = NULL)
const
7742 cl_int err = detail::errHandler(
7743 ::clEnqueueFillImage(
7746 static_cast<void*
>(&fillColor),
7749 (events != NULL) ? (cl_uint) events->size() : 0,
7750 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7751 (event != NULL) ? &tmp : NULL),
7752 __ENQUEUE_FILL_IMAGE_ERR);
7754 if (event != NULL && err == CL_SUCCESS)
7770 const array<size_type, 3>& origin,
7771 const array<size_type, 3>& region,
7772 const vector<Event>* events = NULL,
7773 Event* event = NULL)
const
7776 cl_int err = detail::errHandler(
7777 ::clEnqueueFillImage(
7780 static_cast<void*
>(&fillColor),
7783 (events != NULL) ? (cl_uint) events->size() : 0,
7784 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7785 (event != NULL) ? &tmp : NULL),
7786 __ENQUEUE_FILL_IMAGE_ERR);
7788 if (event != NULL && err == CL_SUCCESS)
7804 const array<size_type, 3>& origin,
7805 const array<size_type, 3>& region,
7806 const vector<Event>* events = NULL,
7807 Event* event = NULL)
const
7810 cl_int err = detail::errHandler(
7811 ::clEnqueueFillImage(
7814 static_cast<void*
>(&fillColor),
7817 (events != NULL) ? (cl_uint) events->size() : 0,
7818 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7819 (event != NULL) ? &tmp : NULL),
7820 __ENQUEUE_FILL_IMAGE_ERR);
7822 if (event != NULL && err == CL_SUCCESS)
7827 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7829 cl_int enqueueCopyImageToBuffer(
7832 const array<size_type, 3>& src_origin,
7833 const array<size_type, 3>& region,
7834 size_type dst_offset,
7835 const vector<Event>* events = NULL,
7836 Event* event = NULL)
const
7839 cl_int err = detail::errHandler(
7840 ::clEnqueueCopyImageToBuffer(
7847 (events != NULL) ? (cl_uint) events->size() : 0,
7848 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7849 (event != NULL) ? &tmp : NULL),
7850 __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
7852 if (event != NULL && err == CL_SUCCESS)
7858 cl_int enqueueCopyBufferToImage(
7861 size_type src_offset,
7862 const array<size_type, 3>& dst_origin,
7863 const array<size_type, 3>& region,
7864 const vector<Event>* events = NULL,
7865 Event* event = NULL)
const
7868 cl_int err = detail::errHandler(
7869 ::clEnqueueCopyBufferToImage(
7876 (events != NULL) ? (cl_uint) events->size() : 0,
7877 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7878 (event != NULL) ? &tmp : NULL),
7879 __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
7881 if (event != NULL && err == CL_SUCCESS)
7887 void* enqueueMapBuffer(
7888 const Buffer& buffer,
7893 const vector<Event>* events = NULL,
7894 Event* event = NULL,
7895 cl_int* err = NULL)
const
7899 void * result = ::clEnqueueMapBuffer(
7900 object_, buffer(), blocking, flags, offset, size,
7901 (events != NULL) ? (cl_uint) events->size() : 0,
7902 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7903 (event != NULL) ? &tmp : NULL,
7906 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
7910 if (event != NULL && error == CL_SUCCESS)
7916 void* enqueueMapImage(
7917 const Image& buffer,
7920 const array<size_type, 3>& origin,
7921 const array<size_type, 3>& region,
7922 size_type * row_pitch,
7923 size_type * slice_pitch,
7924 const vector<Event>* events = NULL,
7925 Event* event = NULL,
7926 cl_int* err = NULL)
const
7930 void * result = ::clEnqueueMapImage(
7931 object_, buffer(), blocking, flags,
7934 row_pitch, slice_pitch,
7935 (events != NULL) ? (cl_uint) events->size() : 0,
7936 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7937 (event != NULL) ? &tmp : NULL,
7940 detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
7944 if (event != NULL && error == CL_SUCCESS)
7949 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7954 template<
typename T>
7960 const vector<Event>* events = NULL,
7961 Event* event = NULL)
const
7964 cl_int err = detail::errHandler(::clEnqueueSVMMap(
7965 object_, blocking, flags,
static_cast<void*
>(ptr), size,
7966 (events != NULL) ? (cl_uint)events->size() : 0,
7967 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
7968 (event != NULL) ? &tmp : NULL),
7969 __ENQUEUE_MAP_BUFFER_ERR);
7971 if (event != NULL && err == CL_SUCCESS)
7982 template<
typename T,
class D>
7984 cl::pointer<T, D> &ptr,
7988 const vector<Event>* events = NULL,
7989 Event* event = NULL)
const
7992 cl_int err = detail::errHandler(::clEnqueueSVMMap(
7993 object_, blocking, flags,
static_cast<void*
>(ptr.get()), size,
7994 (events != NULL) ? (cl_uint)events->size() : 0,
7995 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
7996 (event != NULL) ? &tmp : NULL),
7997 __ENQUEUE_MAP_BUFFER_ERR);
7999 if (event != NULL && err == CL_SUCCESS)
8009 template<
typename T,
class Alloc>
8011 cl::vector<T, Alloc> &container,
8014 const vector<Event>* events = NULL,
8015 Event* event = NULL)
const
8018 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8019 object_, blocking, flags,
static_cast<void*
>(container.data()), container.size(),
8020 (events != NULL) ? (cl_uint)events->size() : 0,
8021 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8022 (event != NULL) ? &tmp : NULL),
8023 __ENQUEUE_MAP_BUFFER_ERR);
8025 if (event != NULL && err == CL_SUCCESS)
8030 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8032 cl_int enqueueUnmapMemObject(
8035 const vector<Event>* events = NULL,
8036 Event* event = NULL)
const
8039 cl_int err = detail::errHandler(
8040 ::clEnqueueUnmapMemObject(
8041 object_, memory(), mapped_ptr,
8042 (events != NULL) ? (cl_uint) events->size() : 0,
8043 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8044 (event != NULL) ? &tmp : NULL),
8045 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8047 if (event != NULL && err == CL_SUCCESS)
8054 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8059 template<
typename T>
8062 const vector<Event>* events = NULL,
8063 Event* event = NULL)
const
8066 cl_int err = detail::errHandler(
8067 ::clEnqueueSVMUnmap(
8068 object_,
static_cast<void*
>(ptr),
8069 (events != NULL) ? (cl_uint)events->size() : 0,
8070 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8071 (event != NULL) ? &tmp : NULL),
8072 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8074 if (event != NULL && err == CL_SUCCESS)
8084 template<
typename T,
class D>
8086 cl::pointer<T, D> &ptr,
8087 const vector<Event>* events = NULL,
8088 Event* event = NULL)
const
8091 cl_int err = detail::errHandler(
8092 ::clEnqueueSVMUnmap(
8093 object_,
static_cast<void*
>(ptr.get()),
8094 (events != NULL) ? (cl_uint)events->size() : 0,
8095 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8096 (event != NULL) ? &tmp : NULL),
8097 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8099 if (event != NULL && err == CL_SUCCESS)
8109 template<
typename T,
class Alloc>
8111 cl::vector<T, Alloc> &container,
8112 const vector<Event>* events = NULL,
8113 Event* event = NULL)
const
8116 cl_int err = detail::errHandler(
8117 ::clEnqueueSVMUnmap(
8118 object_,
static_cast<void*
>(container.data()),
8119 (events != NULL) ? (cl_uint)events->size() : 0,
8120 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8121 (event != NULL) ? &tmp : NULL),
8122 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8124 if (event != NULL && err == CL_SUCCESS)
8129 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8131 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8144 const vector<Event> *events = 0,
8145 Event *event = 0)
const
8148 cl_int err = detail::errHandler(
8149 ::clEnqueueMarkerWithWaitList(
8151 (events != NULL) ? (cl_uint) events->size() : 0,
8152 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8153 (event != NULL) ? &tmp : NULL),
8154 __ENQUEUE_MARKER_WAIT_LIST_ERR);
8156 if (event != NULL && err == CL_SUCCESS)
8174 const vector<Event> *events = 0,
8175 Event *event = 0)
const
8178 cl_int err = detail::errHandler(
8179 ::clEnqueueBarrierWithWaitList(
8181 (events != NULL) ? (cl_uint) events->size() : 0,
8182 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8183 (event != NULL) ? &tmp : NULL),
8184 __ENQUEUE_BARRIER_WAIT_LIST_ERR);
8186 if (event != NULL && err == CL_SUCCESS)
8197 const vector<Memory> &memObjects,
8198 cl_mem_migration_flags flags,
8199 const vector<Event>* events = NULL,
8205 vector<cl_mem> localMemObjects(memObjects.size());
8207 for(
int i = 0; i < (int)memObjects.size(); ++i ) {
8208 localMemObjects[i] = memObjects[i]();
8211 cl_int err = detail::errHandler(
8212 ::clEnqueueMigrateMemObjects(
8214 (cl_uint)memObjects.size(),
8215 localMemObjects.data(),
8217 (events != NULL) ? (cl_uint) events->size() : 0,
8218 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8219 (event != NULL) ? &tmp : NULL),
8220 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8222 if (event != NULL && err == CL_SUCCESS)
8227 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8230 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8236 template<
typename T>
8238 const cl::vector<T*> &svmRawPointers,
8239 const cl::vector<size_type> &sizes,
8240 cl_mem_migration_flags flags = 0,
8241 const vector<Event>* events = NULL,
8242 Event* event = NULL)
const
8245 cl_int err = detail::errHandler(::clEnqueueSVMMigrateMem(
8247 svmRawPointers.size(),
static_cast<void**
>(svmRawPointers.data()),
8250 (events != NULL) ? (cl_uint)events->size() : 0,
8251 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8252 (event != NULL) ? &tmp : NULL),
8253 __ENQUEUE_MIGRATE_SVM_ERR);
8255 if (event != NULL && err == CL_SUCCESS)
8265 template<
typename T>
8267 const cl::vector<T*> &svmRawPointers,
8268 cl_mem_migration_flags flags = 0,
8269 const vector<Event>* events = NULL,
8270 Event* event = NULL)
const
8272 return enqueueMigrateSVM(svmRawPointers, cl::vector<size_type>(svmRawPointers.size()), flags, events, event);
8281 template<
typename T,
class D>
8283 const cl::vector<cl::pointer<T, D>> &svmPointers,
8284 const cl::vector<size_type> &sizes,
8285 cl_mem_migration_flags flags = 0,
8286 const vector<Event>* events = NULL,
8287 Event* event = NULL)
const
8290 cl::vector<void*> svmRawPointers;
8291 svmRawPointers.reserve(svmPointers.size());
8292 for (
auto p : svmPointers) {
8293 svmRawPointers.push_back(
static_cast<void*
>(p.get()));
8304 template<
typename T,
class D>
8306 const cl::vector<cl::pointer<T, D>> &svmPointers,
8307 cl_mem_migration_flags flags = 0,
8308 const vector<Event>* events = NULL,
8309 Event* event = NULL)
const
8311 return enqueueMigrateSVM(svmPointers, cl::vector<size_type>(svmPointers.size()), flags, events, event);
8319 template<
typename T,
class Alloc>
8321 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8322 const cl::vector<size_type> &sizes,
8323 cl_mem_migration_flags flags = 0,
8324 const vector<Event>* events = NULL,
8325 Event* event = NULL)
const
8328 cl::vector<void*> svmRawPointers;
8329 svmRawPointers.reserve(svmContainers.size());
8330 for (
auto p : svmContainers) {
8331 svmRawPointers.push_back(
static_cast<void*
>(p.data()));
8341 template<
typename T,
class Alloc>
8343 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8344 cl_mem_migration_flags flags = 0,
8345 const vector<Event>* events = NULL,
8346 Event* event = NULL)
const
8348 return enqueueMigrateSVM(svmContainers, cl::vector<size_type>(svmContainers.size()), flags, events, event);
8351 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8353 cl_int enqueueNDRangeKernel(
8357 const NDRange& local = NullRange,
8358 const vector<Event>* events = NULL,
8359 Event* event = NULL)
const
8362 cl_int err = detail::errHandler(
8363 ::clEnqueueNDRangeKernel(
8364 object_, kernel(), (cl_uint) global.
dimensions(),
8365 offset.
dimensions() != 0 ? (
const size_type*) offset : NULL,
8366 (
const size_type*) global,
8367 local.dimensions() != 0 ? (
const size_type*) local : NULL,
8368 (events != NULL) ? (cl_uint) events->size() : 0,
8369 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8370 (event != NULL) ? &tmp : NULL),
8371 __ENQUEUE_NDRANGE_KERNEL_ERR);
8373 if (event != NULL && err == CL_SUCCESS)
8379 #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8380 CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_int enqueueTask(
8381 const Kernel& kernel,
8382 const vector<Event>* events = NULL,
8383 Event* event = NULL)
const CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED
8386 cl_int err = detail::errHandler(
8389 (events != NULL) ? (cl_uint) events->size() : 0,
8390 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8391 (event != NULL) ? &tmp : NULL),
8392 __ENQUEUE_TASK_ERR);
8394 if (event != NULL && err == CL_SUCCESS)
8399 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8401 cl_int enqueueNativeKernel(
8402 void (CL_CALLBACK *userFptr)(
void *),
8403 std::pair<void*, size_type> args,
8404 const vector<Memory>* mem_objects = NULL,
8405 const vector<const void*>* mem_locs = NULL,
8406 const vector<Event>* events = NULL,
8407 Event* event = NULL)
const
8409 size_type elements = 0;
8410 if (mem_objects != NULL) {
8411 elements = mem_objects->size();
8413 vector<cl_mem> mems(elements);
8414 for (
unsigned int i = 0; i < elements; i++) {
8415 mems[i] = ((*mem_objects)[i])();
8419 cl_int err = detail::errHandler(
8420 ::clEnqueueNativeKernel(
8421 object_, userFptr, args.first, args.second,
8422 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8424 (mem_locs != NULL && mem_locs->size() > 0) ? (
const void **) &mem_locs->front() : NULL,
8425 (events != NULL) ? (cl_uint) events->size() : 0,
8426 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8427 (event != NULL) ? &tmp : NULL),
8428 __ENQUEUE_NATIVE_KERNEL);
8430 if (event != NULL && err == CL_SUCCESS)
8439 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8440 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
8444 cl_int err = detail::errHandler(
8447 (event != NULL) ? &tmp : NULL),
8448 __ENQUEUE_MARKER_ERR);
8450 if (event != NULL && err == CL_SUCCESS)
8456 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
8457 cl_int enqueueWaitForEvents(
const vector<Event>& events)
const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
8459 return detail::errHandler(
8460 ::clEnqueueWaitForEvents(
8462 (cl_uint) events.size(),
8463 events.size() > 0 ? (
const cl_event*) &events.front() : NULL),
8464 __ENQUEUE_WAIT_FOR_EVENTS_ERR);
8466 #endif // defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8468 cl_int enqueueAcquireGLObjects(
8469 const vector<Memory>* mem_objects = NULL,
8470 const vector<Event>* events = NULL,
8471 Event* event = NULL)
const
8474 cl_int err = detail::errHandler(
8475 ::clEnqueueAcquireGLObjects(
8477 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8478 (mem_objects != NULL && mem_objects->size() > 0) ? (
const cl_mem *) &mem_objects->front(): NULL,
8479 (events != NULL) ? (cl_uint) events->size() : 0,
8480 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8481 (event != NULL) ? &tmp : NULL),
8482 __ENQUEUE_ACQUIRE_GL_ERR);
8484 if (event != NULL && err == CL_SUCCESS)
8490 cl_int enqueueReleaseGLObjects(
8491 const vector<Memory>* mem_objects = NULL,
8492 const vector<Event>* events = NULL,
8493 Event* event = NULL)
const
8496 cl_int err = detail::errHandler(
8497 ::clEnqueueReleaseGLObjects(
8499 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8500 (mem_objects != NULL && mem_objects->size() > 0) ? (
const cl_mem *) &mem_objects->front(): NULL,
8501 (events != NULL) ? (cl_uint) events->size() : 0,
8502 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8503 (event != NULL) ? &tmp : NULL),
8504 __ENQUEUE_RELEASE_GL_ERR);
8506 if (event != NULL && err == CL_SUCCESS)
8512 #if defined (CL_HPP_USE_DX_INTEROP)
8513 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
8514 cl_command_queue command_queue, cl_uint num_objects,
8515 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8516 const cl_event* event_wait_list, cl_event* event);
8517 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
8518 cl_command_queue command_queue, cl_uint num_objects,
8519 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8520 const cl_event* event_wait_list, cl_event* event);
8522 cl_int enqueueAcquireD3D10Objects(
8523 const vector<Memory>* mem_objects = NULL,
8524 const vector<Event>* events = NULL,
8525 Event* event = NULL)
const
8527 static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
8528 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8529 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8530 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8531 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8532 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireD3D10ObjectsKHR);
8534 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
8535 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueAcquireD3D10ObjectsKHR);
8539 cl_int err = detail::errHandler(
8540 pfn_clEnqueueAcquireD3D10ObjectsKHR(
8542 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8543 (mem_objects != NULL && mem_objects->size() > 0) ? (
const cl_mem *) &mem_objects->front(): NULL,
8544 (events != NULL) ? (cl_uint) events->size() : 0,
8545 (events != NULL) ? (cl_event*) &events->front() : NULL,
8546 (event != NULL) ? &tmp : NULL),
8547 __ENQUEUE_ACQUIRE_GL_ERR);
8549 if (event != NULL && err == CL_SUCCESS)
8555 cl_int enqueueReleaseD3D10Objects(
8556 const vector<Memory>* mem_objects = NULL,
8557 const vector<Event>* events = NULL,
8558 Event* event = NULL)
const
8560 static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL;
8561 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8562 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8563 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8564 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8565 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseD3D10ObjectsKHR);
8566 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8567 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
8568 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueReleaseD3D10ObjectsKHR);
8569 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
8572 cl_int err = detail::errHandler(
8573 pfn_clEnqueueReleaseD3D10ObjectsKHR(
8575 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8576 (mem_objects != NULL && mem_objects->size() > 0) ? (
const cl_mem *) &mem_objects->front(): NULL,
8577 (events != NULL) ? (cl_uint) events->size() : 0,
8578 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8579 (event != NULL) ? &tmp : NULL),
8580 __ENQUEUE_RELEASE_GL_ERR);
8582 if (event != NULL && err == CL_SUCCESS)
8592 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8593 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
8596 return detail::errHandler(
8597 ::clEnqueueBarrier(object_),
8598 __ENQUEUE_BARRIER_ERR);
8600 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
8602 cl_int flush()
const
8604 return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
8607 cl_int finish()
const
8609 return detail::errHandler(::clFinish(object_), __FINISH_ERR);
8613 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::default_initialized_;
8614 CL_HPP_DEFINE_STATIC_MEMBER_ CommandQueue CommandQueue::default_;
8615 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int CommandQueue::default_error_ = CL_SUCCESS;
8618 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8619 enum class DeviceQueueProperties : cl_command_queue_properties
8622 Profiling = CL_QUEUE_PROFILING_ENABLE,
8625 inline DeviceQueueProperties operator|(DeviceQueueProperties lhs, DeviceQueueProperties rhs)
8627 return static_cast<DeviceQueueProperties
>(
static_cast<cl_command_queue_properties
>(lhs) |
static_cast<cl_command_queue_properties
>(rhs));
8651 cl_command_queue_properties mergedProperties =
8652 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE |
static_cast<cl_command_queue_properties
>(properties);
8654 cl_queue_properties queue_properties[] = {
8655 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8656 object_ = ::clCreateCommandQueueWithProperties(
8657 context(), device(), queue_properties, &error);
8659 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8671 DeviceQueueProperties properties = DeviceQueueProperties::None,
8676 cl_command_queue_properties mergedProperties =
8677 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE |
static_cast<cl_command_queue_properties
>(properties);
8678 cl_queue_properties queue_properties[] = {
8679 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8680 object_ = ::clCreateCommandQueueWithProperties(
8681 context(), device(), queue_properties, &error);
8683 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8696 DeviceQueueProperties properties = DeviceQueueProperties::None,
8701 cl_command_queue_properties mergedProperties =
8702 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE |
static_cast<cl_command_queue_properties
>(properties);
8703 cl_queue_properties queue_properties[] = {
8704 CL_QUEUE_PROPERTIES, mergedProperties,
8705 CL_QUEUE_SIZE, queueSize,
8707 object_ = ::clCreateCommandQueueWithProperties(
8708 context(), device(), queue_properties, &error);
8710 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8723 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
8759 template <
typename T>
8760 cl_int getInfo(cl_command_queue_info name, T* param)
const
8762 return detail::errHandler(
8764 &::clGetCommandQueueInfo, object_, name, param),
8765 __GET_COMMAND_QUEUE_INFO_ERR);
8768 template <cl_
int name>
typename
8769 detail::param_traits<detail::cl_command_queue_info, name>::param_type
8770 getInfo(cl_int* err = NULL)
const
8772 typename detail::param_traits<
8773 detail::cl_command_queue_info, name>::param_type param;
8774 cl_int result = getInfo(name, ¶m);
8788 cl_int *err =
nullptr)
8794 cl_command_queue_properties properties =
8795 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
8796 cl_queue_properties queue_properties[] = {
8797 CL_QUEUE_PROPERTIES, properties,
8800 ::clCreateCommandQueueWithProperties(
8801 context(), device(), queue_properties, &error));
8803 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8818 const Context &context,
const Device &device, cl_int *err =
nullptr)
8822 cl_command_queue_properties properties =
8823 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
8824 cl_queue_properties queue_properties[] = {
8825 CL_QUEUE_PROPERTIES, properties,
8828 ::clCreateCommandQueueWithProperties(
8829 context(), device(), queue_properties, &error));
8831 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8846 const Context &context,
const Device &device, cl_uint queueSize, cl_int *err =
nullptr)
8850 cl_command_queue_properties properties =
8851 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
8852 cl_queue_properties queue_properties[] = {
8853 CL_QUEUE_PROPERTIES, properties,
8854 CL_QUEUE_SIZE, queueSize,
8857 ::clCreateCommandQueueWithProperties(
8858 context(), device(), queue_properties, &error));
8860 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8870 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8880 error = clSetDefaultDeviceCommandQueue(context.get(), device.get(), default_queue.get());
8882 detail::errHandler(error, __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR);
8886 return default_queue;
8894 return queue.getInfo<CL_QUEUE_DEVICE_DEFAULT>(err);
8897 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8911 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8914 template<
typename IteratorType >
8917 IteratorType startIterator,
8918 IteratorType endIterator,
8923 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
8926 cl_mem_flags flags = 0;
8928 flags |= CL_MEM_READ_ONLY;
8931 flags |= CL_MEM_READ_WRITE;
8934 flags |= CL_MEM_USE_HOST_PTR;
8937 size_type size =
sizeof(DataType)*(endIterator - startIterator);
8940 object_ = ::clCreateBuffer(context(), flags, size,
static_cast<DataType*
>(&*startIterator), &error);
8942 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
8945 detail::errHandler(error, __CREATE_BUFFER_ERR);
8952 detail::errHandler(error, __CREATE_BUFFER_ERR);
8957 error =
cl::copy(queue, startIterator, endIterator, *
this);
8958 detail::errHandler(error, __CREATE_BUFFER_ERR);
8965 template<
typename IteratorType >
8968 IteratorType startIterator,
8969 IteratorType endIterator,
8974 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
8977 cl_mem_flags flags = 0;
8979 flags |= CL_MEM_READ_ONLY;
8982 flags |= CL_MEM_READ_WRITE;
8985 flags |= CL_MEM_USE_HOST_PTR;
8988 size_type size =
sizeof(DataType)*(endIterator - startIterator);
8990 Context context = queue.getInfo<CL_QUEUE_CONTEXT>();
8993 object_ = ::clCreateBuffer(context(), flags, size,
static_cast<DataType*
>(&*startIterator), &error);
8996 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
8999 detail::errHandler(error, __CREATE_BUFFER_ERR);
9005 error =
cl::copy(queue, startIterator, endIterator, *
this);
9006 detail::errHandler(error, __CREATE_BUFFER_ERR);
9013 inline cl_int enqueueReadBuffer(
9019 const vector<Event>* events = NULL,
9020 Event* event = NULL)
9025 if (error != CL_SUCCESS) {
9029 return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event);
9032 inline cl_int enqueueWriteBuffer(
9033 const Buffer& buffer,
9038 const vector<Event>* events = NULL,
9039 Event* event = NULL)
9042 CommandQueue queue = CommandQueue::getDefault(&error);
9044 if (error != CL_SUCCESS) {
9048 return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event);
9051 inline void* enqueueMapBuffer(
9052 const Buffer& buffer,
9057 const vector<Event>* events = NULL,
9058 Event* event = NULL,
9062 CommandQueue queue = CommandQueue::getDefault(&error);
9063 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9068 void * result = ::clEnqueueMapBuffer(
9069 queue(), buffer(), blocking, flags, offset, size,
9070 (events != NULL) ? (cl_uint) events->size() : 0,
9071 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
9075 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9083 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9089 template<
typename T>
9095 const vector<Event>* events,
9100 if (error != CL_SUCCESS) {
9101 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9105 ptr, blocking, flags, size, events, event);
9113 template<
typename T,
class D>
9115 cl::pointer<T, D> ptr,
9119 const vector<Event>* events = NULL,
9120 Event* event = NULL)
9124 if (error != CL_SUCCESS) {
9125 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9129 ptr, blocking, flags, size, events, event);
9137 template<
typename T,
class Alloc>
9139 cl::vector<T, Alloc> container,
9142 const vector<Event>* events = NULL,
9143 Event* event = NULL)
9147 if (error != CL_SUCCESS) {
9148 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9152 container, blocking, flags, events, event);
9155 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9157 inline cl_int enqueueUnmapMemObject(
9158 const Memory& memory,
9160 const vector<Event>* events = NULL,
9161 Event* event = NULL)
9164 CommandQueue queue = CommandQueue::getDefault(&error);
9165 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9166 if (error != CL_SUCCESS) {
9171 cl_int err = detail::errHandler(
9172 ::clEnqueueUnmapMemObject(
9173 queue(), memory(), mapped_ptr,
9174 (events != NULL) ? (cl_uint)events->size() : 0,
9175 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
9176 (event != NULL) ? &tmp : NULL),
9177 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9179 if (event != NULL && err == CL_SUCCESS)
9185 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9191 template<
typename T>
9194 const vector<Event>* events = NULL,
9195 Event* event = NULL)
9199 if (error != CL_SUCCESS) {
9200 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9204 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9213 template<
typename T,
class D>
9215 cl::pointer<T, D> &ptr,
9216 const vector<Event>* events = NULL,
9217 Event* event = NULL)
9221 if (error != CL_SUCCESS) {
9222 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9226 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9234 template<
typename T,
class Alloc>
9236 cl::vector<T, Alloc> &container,
9237 const vector<Event>* events = NULL,
9238 Event* event = NULL)
9242 if (error != CL_SUCCESS) {
9243 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9246 return detail::errHandler(queue.
enqueueUnmapSVM(container, events, event),
9247 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9250 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9252 inline cl_int enqueueCopyBuffer(
9255 size_type src_offset,
9256 size_type dst_offset,
9258 const vector<Event>* events = NULL,
9259 Event* event = NULL)
9262 CommandQueue queue = CommandQueue::getDefault(&error);
9264 if (error != CL_SUCCESS) {
9268 return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event);
9276 template<
typename IteratorType >
9277 inline cl_int
copy( IteratorType startIterator, IteratorType endIterator,
cl::Buffer &buffer )
9281 if (error != CL_SUCCESS)
9284 return cl::copy(queue, startIterator, endIterator, buffer);
9292 template<
typename IteratorType >
9293 inline cl_int
copy(
const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
9297 if (error != CL_SUCCESS)
9300 return cl::copy(queue, buffer, startIterator, endIterator);
9308 template<
typename IteratorType >
9311 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9314 size_type length = endIterator-startIterator;
9315 size_type byteLength = length*
sizeof(DataType);
9318 static_cast<DataType*
>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error));
9320 if( error != CL_SUCCESS ) {
9323 #if defined(_MSC_VER)
9327 stdext::checked_array_iterator<DataType*>(
9330 std::copy(startIterator, endIterator, pointer);
9333 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9335 if( error != CL_SUCCESS ) {
9347 template<
typename IteratorType >
9350 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9353 size_type length = endIterator-startIterator;
9354 size_type byteLength = length*
sizeof(DataType);
9357 static_cast<DataType*
>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error));
9359 if( error != CL_SUCCESS ) {
9362 std::copy(pointer, pointer + length, startIterator);
9364 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9366 if( error != CL_SUCCESS ) {
9374 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9378 template<
typename T,
class Alloc>
9379 inline cl_int
mapSVM(cl::vector<T, Alloc> &container)
9381 return enqueueMapSVM(container, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE);
9387 template<
typename T,
class Alloc>
9388 inline cl_int
unmapSVM(cl::vector<T, Alloc> &container)
9393 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9395 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
9396 inline cl_int enqueueReadBufferRect(
9397 const Buffer& buffer,
9399 const array<size_type, 3>& buffer_offset,
9400 const array<size_type, 3>& host_offset,
9401 const array<size_type, 3>& region,
9402 size_type buffer_row_pitch,
9403 size_type buffer_slice_pitch,
9404 size_type host_row_pitch,
9405 size_type host_slice_pitch,
9407 const vector<Event>* events = NULL,
9408 Event* event = NULL)
9411 CommandQueue queue = CommandQueue::getDefault(&error);
9413 if (error != CL_SUCCESS) {
9417 return queue.enqueueReadBufferRect(
9432 inline cl_int enqueueWriteBufferRect(
9433 const Buffer& buffer,
9435 const array<size_type, 3>& buffer_offset,
9436 const array<size_type, 3>& host_offset,
9437 const array<size_type, 3>& region,
9438 size_type buffer_row_pitch,
9439 size_type buffer_slice_pitch,
9440 size_type host_row_pitch,
9441 size_type host_slice_pitch,
9443 const vector<Event>* events = NULL,
9444 Event* event = NULL)
9447 CommandQueue queue = CommandQueue::getDefault(&error);
9449 if (error != CL_SUCCESS) {
9453 return queue.enqueueWriteBufferRect(
9468 inline cl_int enqueueCopyBufferRect(
9471 const array<size_type, 3>& src_origin,
9472 const array<size_type, 3>& dst_origin,
9473 const array<size_type, 3>& region,
9474 size_type src_row_pitch,
9475 size_type src_slice_pitch,
9476 size_type dst_row_pitch,
9477 size_type dst_slice_pitch,
9478 const vector<Event>* events = NULL,
9479 Event* event = NULL)
9482 CommandQueue queue = CommandQueue::getDefault(&error);
9484 if (error != CL_SUCCESS) {
9488 return queue.enqueueCopyBufferRect(
9501 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
9503 inline cl_int enqueueReadImage(
9506 const array<size_type, 3>& origin,
9507 const array<size_type, 3>& region,
9508 size_type row_pitch,
9509 size_type slice_pitch,
9511 const vector<Event>* events = NULL,
9512 Event* event = NULL)
9515 CommandQueue queue = CommandQueue::getDefault(&error);
9517 if (error != CL_SUCCESS) {
9521 return queue.enqueueReadImage(
9533 inline cl_int enqueueWriteImage(
9536 const array<size_type, 3>& origin,
9537 const array<size_type, 3>& region,
9538 size_type row_pitch,
9539 size_type slice_pitch,
9541 const vector<Event>* events = NULL,
9542 Event* event = NULL)
9545 CommandQueue queue = CommandQueue::getDefault(&error);
9547 if (error != CL_SUCCESS) {
9551 return queue.enqueueWriteImage(
9563 inline cl_int enqueueCopyImage(
9566 const array<size_type, 3>& src_origin,
9567 const array<size_type, 3>& dst_origin,
9568 const array<size_type, 3>& region,
9569 const vector<Event>* events = NULL,
9570 Event* event = NULL)
9573 CommandQueue queue = CommandQueue::getDefault(&error);
9575 if (error != CL_SUCCESS) {
9579 return queue.enqueueCopyImage(
9589 inline cl_int enqueueCopyImageToBuffer(
9592 const array<size_type, 3>& src_origin,
9593 const array<size_type, 3>& region,
9594 size_type dst_offset,
9595 const vector<Event>* events = NULL,
9596 Event* event = NULL)
9599 CommandQueue queue = CommandQueue::getDefault(&error);
9601 if (error != CL_SUCCESS) {
9605 return queue.enqueueCopyImageToBuffer(
9615 inline cl_int enqueueCopyBufferToImage(
9618 size_type src_offset,
9619 const array<size_type, 3>& dst_origin,
9620 const array<size_type, 3>& region,
9621 const vector<Event>* events = NULL,
9622 Event* event = NULL)
9625 CommandQueue queue = CommandQueue::getDefault(&error);
9627 if (error != CL_SUCCESS) {
9631 return queue.enqueueCopyBufferToImage(
9642 inline cl_int flush(
void)
9645 CommandQueue queue = CommandQueue::getDefault(&error);
9647 if (error != CL_SUCCESS) {
9651 return queue.flush();
9654 inline cl_int finish(
void)
9657 CommandQueue queue = CommandQueue::getDefault(&error);
9659 if (error != CL_SUCCESS) {
9664 return queue.finish();
9674 vector<Event> events_;
9676 template<
typename... Ts>
9681 queue_(CommandQueue::getDefault()),
9690 queue_(CommandQueue::getDefault()),
9699 queue_(CommandQueue::getDefault()),
9708 queue_(CommandQueue::getDefault()),
9713 events_.push_back(e);
9717 queue_(CommandQueue::getDefault()),
9722 events_.push_back(e);
9726 queue_(CommandQueue::getDefault()),
9731 events_.push_back(e);
9735 queue_(CommandQueue::getDefault()),
9745 queue_(CommandQueue::getDefault()),
9755 queue_(CommandQueue::getDefault()),
9797 events_.push_back(e);
9806 events_.push_back(e);
9815 events_.push_back(e);
9857 template<
typename... Ts>
9863 template<
int index,
typename T0,
typename... T1s>
9864 void setArgs(T0&& t0, T1s&&... t1s)
9866 kernel_.
setArg(index, t0);
9867 setArgs<index + 1, T1s...>(std::forward<T1s>(t1s)...);
9870 template<
int index,
typename T0>
9871 void setArgs(T0&& t0)
9873 kernel_.
setArg(index, t0);
9889 cl_int * err = NULL) :
9890 kernel_(program, name.c_str(), err)
9906 setArgs<0>(std::forward<Ts>(ts)...);
9908 args.queue_.enqueueNDRangeKernel(
9931 setArgs<0>(std::forward<Ts>(ts)...);
9933 error = args.queue_.enqueueNDRangeKernel(
9944 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9945 cl_int setSVMPointers(
const vector<void*> &pointerList)
9950 template<
typename T0,
typename... T1s>
9951 cl_int setSVMPointers(
const T0 &t0, T1s &... ts)
9955 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9963 namespace compatibility {
9968 template<
typename... Ts>
9978 cl_int * err = NULL) :
10000 enqueueArgs, args...);
10008 #undef CL_HPP_ERR_STR_
10009 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
10010 #undef __GET_DEVICE_INFO_ERR
10011 #undef __GET_PLATFORM_INFO_ERR
10012 #undef __GET_DEVICE_IDS_ERR
10013 #undef __GET_PLATFORM_IDS_ERR
10014 #undef __GET_CONTEXT_INFO_ERR
10015 #undef __GET_EVENT_INFO_ERR
10016 #undef __GET_EVENT_PROFILE_INFO_ERR
10017 #undef __GET_MEM_OBJECT_INFO_ERR
10018 #undef __GET_IMAGE_INFO_ERR
10019 #undef __GET_SAMPLER_INFO_ERR
10020 #undef __GET_KERNEL_INFO_ERR
10021 #undef __GET_KERNEL_ARG_INFO_ERR
10022 #undef __GET_KERNEL_SUB_GROUP_INFO_ERR
10023 #undef __GET_KERNEL_WORK_GROUP_INFO_ERR
10024 #undef __GET_PROGRAM_INFO_ERR
10025 #undef __GET_PROGRAM_BUILD_INFO_ERR
10026 #undef __GET_COMMAND_QUEUE_INFO_ERR
10027 #undef __CREATE_CONTEXT_ERR
10028 #undef __CREATE_CONTEXT_FROM_TYPE_ERR
10029 #undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
10030 #undef __CREATE_BUFFER_ERR
10032 #undef __CREATE_SUBBUFFER_ERR
10033 #undef __CREATE_GL_BUFFER_ERR
10034 #undef __CREATE_GL_RENDER_BUFFER_ERR
10035 #undef __GET_GL_OBJECT_INFO_ERR
10036 #undef __CREATE_IMAGE_ERR
10037 #undef __CREATE_GL_TEXTURE_ERR
10038 #undef __IMAGE_DIMENSION_ERR
10039 #undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
10040 #undef __CREATE_USER_EVENT_ERR
10041 #undef __SET_USER_EVENT_STATUS_ERR
10042 #undef __SET_EVENT_CALLBACK_ERR
10043 #undef __WAIT_FOR_EVENTS_ERR
10044 #undef __CREATE_KERNEL_ERR
10045 #undef __SET_KERNEL_ARGS_ERR
10046 #undef __CREATE_PROGRAM_WITH_SOURCE_ERR
10047 #undef __CREATE_PROGRAM_WITH_IL_ERR
10048 #undef __CREATE_PROGRAM_WITH_BINARY_ERR
10049 #undef __CREATE_PROGRAM_WITH_IL_ERR
10050 #undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR
10051 #undef __BUILD_PROGRAM_ERR
10052 #undef __COMPILE_PROGRAM_ERR
10053 #undef __LINK_PROGRAM_ERR
10054 #undef __CREATE_KERNELS_IN_PROGRAM_ERR
10055 #undef __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR
10056 #undef __CREATE_SAMPLER_WITH_PROPERTIES_ERR
10057 #undef __SET_COMMAND_QUEUE_PROPERTY_ERR
10058 #undef __ENQUEUE_READ_BUFFER_ERR
10059 #undef __ENQUEUE_READ_BUFFER_RECT_ERR
10060 #undef __ENQUEUE_WRITE_BUFFER_ERR
10061 #undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
10062 #undef __ENQEUE_COPY_BUFFER_ERR
10063 #undef __ENQEUE_COPY_BUFFER_RECT_ERR
10064 #undef __ENQUEUE_FILL_BUFFER_ERR
10065 #undef __ENQUEUE_READ_IMAGE_ERR
10066 #undef __ENQUEUE_WRITE_IMAGE_ERR
10067 #undef __ENQUEUE_COPY_IMAGE_ERR
10068 #undef __ENQUEUE_FILL_IMAGE_ERR
10069 #undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
10070 #undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
10071 #undef __ENQUEUE_MAP_BUFFER_ERR
10072 #undef __ENQUEUE_MAP_IMAGE_ERR
10073 #undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
10074 #undef __ENQUEUE_NDRANGE_KERNEL_ERR
10075 #undef __ENQUEUE_NATIVE_KERNEL
10076 #undef __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR
10077 #undef __ENQUEUE_MIGRATE_SVM_ERR
10078 #undef __ENQUEUE_ACQUIRE_GL_ERR
10079 #undef __ENQUEUE_RELEASE_GL_ERR
10080 #undef __CREATE_PIPE_ERR
10081 #undef __GET_PIPE_INFO_ERR
10082 #undef __RETAIN_ERR
10083 #undef __RELEASE_ERR
10085 #undef __FINISH_ERR
10086 #undef __VECTOR_CAPACITY_ERR
10087 #undef __CREATE_SUB_DEVICES_ERR
10088 #undef __CREATE_SUB_DEVICES_ERR
10089 #undef __ENQUEUE_MARKER_ERR
10090 #undef __ENQUEUE_WAIT_FOR_EVENTS_ERR
10091 #undef __ENQUEUE_BARRIER_ERR
10092 #undef __UNLOAD_COMPILER_ERR
10093 #undef __CREATE_GL_TEXTURE_2D_ERR
10094 #undef __CREATE_GL_TEXTURE_3D_ERR
10095 #undef __CREATE_IMAGE2D_ERR
10096 #undef __CREATE_IMAGE3D_ERR
10097 #undef __CREATE_COMMAND_QUEUE_ERR
10098 #undef __ENQUEUE_TASK_ERR
10099 #undef __CREATE_SAMPLER_ERR
10100 #undef __ENQUEUE_MARKER_WAIT_LIST_ERR
10101 #undef __ENQUEUE_BARRIER_WAIT_LIST_ERR
10102 #undef __CLONE_KERNEL_ERR
10103 #undef __GET_HOST_TIMER_ERR
10104 #undef __GET_DEVICE_AND_HOST_TIMER_ERR
10106 #endif //CL_HPP_USER_OVERRIDE_ERROR_STRINGS
10109 #undef CL_HPP_INIT_CL_EXT_FCN_PTR_
10110 #undef CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_
10112 #if defined(CL_HPP_USE_CL_DEVICE_FISSION)
10113 #undef CL_HPP_PARAM_NAME_DEVICE_FISSION_
10114 #endif // CL_HPP_USE_CL_DEVICE_FISSION
10116 #undef CL_HPP_NOEXCEPT_
10117 #undef CL_HPP_DEFINE_STATIC_MEMBER_