396 #if !defined(CL_HPP_USE_DX_INTEROP) && defined(USE_DX_INTEROP)
397 # pragma message("cl2.hpp: USE_DX_INTEROP is deprecated. Define CL_HPP_USE_DX_INTEROP instead")
398 # define CL_HPP_USE_DX_INTEROP
400 #if !defined(CL_HPP_USE_CL_DEVICE_FISSION) && defined(USE_CL_DEVICE_FISSION)
401 # pragma message("cl2.hpp: USE_CL_DEVICE_FISSION is deprecated. Define CL_HPP_USE_CL_DEVICE_FISSION instead")
402 # define CL_HPP_USE_CL_DEVICE_FISSION
404 #if !defined(CL_HPP_ENABLE_EXCEPTIONS) && defined(__CL_ENABLE_EXCEPTIONS)
405 # pragma message("cl2.hpp: __CL_ENABLE_EXCEPTIONS is deprecated. Define CL_HPP_ENABLE_EXCEPTIONS instead")
406 # define CL_HPP_ENABLE_EXCEPTIONS
408 #if !defined(CL_HPP_NO_STD_VECTOR) && defined(__NO_STD_VECTOR)
409 # pragma message("cl2.hpp: __NO_STD_VECTOR is deprecated. Define CL_HPP_NO_STD_VECTOR instead")
410 # define CL_HPP_NO_STD_VECTOR
412 #if !defined(CL_HPP_NO_STD_STRING) && defined(__NO_STD_STRING)
413 # pragma message("cl2.hpp: __NO_STD_STRING is deprecated. Define CL_HPP_NO_STD_STRING instead")
414 # define CL_HPP_NO_STD_STRING
416 #if defined(VECTOR_CLASS)
417 # pragma message("cl2.hpp: VECTOR_CLASS is deprecated. Alias cl::vector instead")
419 #if defined(STRING_CLASS)
420 # pragma message("cl2.hpp: STRING_CLASS is deprecated. Alias cl::string instead.")
422 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) && defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
423 # pragma message("cl2.hpp: __CL_USER_OVERRIDE_ERROR_STRINGS is deprecated. Define CL_HPP_USER_OVERRIDE_ERROR_STRINGS instead")
424 # define CL_HPP_USER_OVERRIDE_ERROR_STRINGS
429 #if defined(__USE_DEV_VECTOR)
430 # pragma message("cl2.hpp: __USE_DEV_VECTOR is no longer supported. Expect compilation errors")
432 #if defined(__USE_DEV_STRING)
433 # pragma message("cl2.hpp: __USE_DEV_STRING is no longer supported. Expect compilation errors")
437 #if !defined(CL_HPP_TARGET_OPENCL_VERSION)
438 # pragma message("cl2.hpp: CL_HPP_TARGET_OPENCL_VERSION is not defined. It will default to 220 (OpenCL 2.2)")
439 # define CL_HPP_TARGET_OPENCL_VERSION 220
441 #if CL_HPP_TARGET_OPENCL_VERSION != 100 && \
442 CL_HPP_TARGET_OPENCL_VERSION != 110 && \
443 CL_HPP_TARGET_OPENCL_VERSION != 120 && \
444 CL_HPP_TARGET_OPENCL_VERSION != 200 && \
445 CL_HPP_TARGET_OPENCL_VERSION != 210 && \
446 CL_HPP_TARGET_OPENCL_VERSION != 220 && \
447 CL_HPP_TARGET_OPENCL_VERSION != 300
448 # pragma message("cl2.hpp: CL_HPP_TARGET_OPENCL_VERSION is not a valid value (100, 110, 120, 200, 210, 220 or 300). It will be set to 220")
449 # undef CL_HPP_TARGET_OPENCL_VERSION
450 # define CL_HPP_TARGET_OPENCL_VERSION 220
454 #if defined(CL_TARGET_OPENCL_VERSION)
457 #if CL_TARGET_OPENCL_VERSION < CL_HPP_TARGET_OPENCL_VERSION
458 # pragma message("CL_TARGET_OPENCL_VERSION is already defined as is lower than CL_HPP_TARGET_OPENCL_VERSION")
461 # define CL_TARGET_OPENCL_VERSION CL_HPP_TARGET_OPENCL_VERSION
464 #if !defined(CL_HPP_MINIMUM_OPENCL_VERSION)
465 # define CL_HPP_MINIMUM_OPENCL_VERSION 200
467 #if CL_HPP_MINIMUM_OPENCL_VERSION != 100 && \
468 CL_HPP_MINIMUM_OPENCL_VERSION != 110 && \
469 CL_HPP_MINIMUM_OPENCL_VERSION != 120 && \
470 CL_HPP_MINIMUM_OPENCL_VERSION != 200 && \
471 CL_HPP_MINIMUM_OPENCL_VERSION != 210 && \
472 CL_HPP_MINIMUM_OPENCL_VERSION != 220 && \
473 CL_HPP_MINIMUM_OPENCL_VERSION != 300
474 # pragma message("cl2.hpp: CL_HPP_MINIMUM_OPENCL_VERSION is not a valid value (100, 110, 120, 200, 210, 220 or 300). It will be set to 100")
475 # undef CL_HPP_MINIMUM_OPENCL_VERSION
476 # define CL_HPP_MINIMUM_OPENCL_VERSION 100
478 #if CL_HPP_MINIMUM_OPENCL_VERSION > CL_HPP_TARGET_OPENCL_VERSION
479 # error "CL_HPP_MINIMUM_OPENCL_VERSION must not be greater than CL_HPP_TARGET_OPENCL_VERSION"
482 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 100 && !defined(CL_USE_DEPRECATED_OPENCL_1_0_APIS)
483 # define CL_USE_DEPRECATED_OPENCL_1_0_APIS
485 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 110 && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
486 # define CL_USE_DEPRECATED_OPENCL_1_1_APIS
488 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 120 && !defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
489 # define CL_USE_DEPRECATED_OPENCL_1_2_APIS
491 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 200 && !defined(CL_USE_DEPRECATED_OPENCL_2_0_APIS)
492 # define CL_USE_DEPRECATED_OPENCL_2_0_APIS
494 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 210 && !defined(CL_USE_DEPRECATED_OPENCL_2_1_APIS)
495 # define CL_USE_DEPRECATED_OPENCL_2_1_APIS
497 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 220 && !defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
498 # define CL_USE_DEPRECATED_OPENCL_2_2_APIS
505 #if defined(CL_HPP_USE_DX_INTEROP)
506 #include <CL/cl_d3d10.h>
507 #include <CL/cl_dx9_media_sharing.h>
511 #if defined(_MSC_VER)
519 #if (!defined(_MSC_VER) && __cplusplus < 201103L) || (defined(_MSC_VER) && _MSC_VER < 1700)
520 #error Visual studio 2013 or another C++11-supporting compiler required
524 #if defined(CL_HPP_USE_CL_DEVICE_FISSION) || defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)
525 #include <CL/cl_ext.h>
528 #if defined(__APPLE__) || defined(__MACOSX)
529 #include <OpenCL/opencl.h>
531 #include <CL/opencl.h>
534 #if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L )
535 #define CL_HPP_NOEXCEPT_ noexcept
537 #define CL_HPP_NOEXCEPT_
540 #if __cplusplus >= 201703L
541 # define CL_HPP_DEFINE_STATIC_MEMBER_ inline
542 #elif defined(_MSC_VER)
543 # define CL_HPP_DEFINE_STATIC_MEMBER_ __declspec(selectany)
544 #elif defined(__MINGW32__)
545 # define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((selectany))
547 # define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((weak))
552 #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
553 #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
554 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
555 #if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED)
556 #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
557 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
559 #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED)
560 #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED
561 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED)
562 #if !defined(CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED)
563 #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED
564 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED)
566 #if !defined(CL_CALLBACK)
575 #include <functional>
579 #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
581 using size_type = ::size_t;
583 #else // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
585 using size_type = size_t;
587 #endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
590 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
592 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
594 #if !defined(CL_HPP_NO_STD_VECTOR)
597 template <
class T,
class Alloc = std::allocator<T> >
598 using vector = std::vector<T, Alloc>;
600 #endif // #if !defined(CL_HPP_NO_STD_VECTOR)
602 #if !defined(CL_HPP_NO_STD_STRING)
605 using string = std::string;
607 #endif // #if !defined(CL_HPP_NO_STD_STRING)
609 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
611 #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
616 template<
class T,
class D>
617 using pointer = std::unique_ptr<T, D>;
620 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
621 #if !defined(CL_HPP_NO_STD_ARRAY)
624 template <
class T,
size_type N >
625 using array = std::array<T, N>;
627 #endif // #if !defined(CL_HPP_NO_STD_ARRAY)
631 #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
633 namespace compatibility {
648 for (
int i = 0; i < N; ++i) {
653 size_t(
const array<size_type, N> &rhs)
655 for (
int i = 0; i < N; ++i) {
660 size_type& operator[](
int index)
665 const size_type& operator[](
int index)
const
671 operator size_type* () {
return data_; }
674 operator const size_type* ()
const {
return data_; }
676 operator array<size_type, N>()
const
678 array<size_type, N> ret;
680 for (
int i = 0; i < N; ++i) {
689 using size_t = compatibility::size_t<N>;
691 #endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
696 using size_t_array = array<size_type, 3>;
709 #define CL_HPP_INIT_CL_EXT_FCN_PTR_(name) \
711 pfn_##name = (PFN_##name) \
712 clGetExtensionFunctionAddress(#name); \
717 #define CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, name) \
719 pfn_##name = (PFN_##name) \
720 clGetExtensionFunctionAddressForPlatform(platform, #name); \
729 class DeviceCommandQueue;
734 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
739 class Error :
public std::exception
743 const char * errStr_;
754 Error(cl_int err,
const char * errStr = NULL) : err_(err), errStr_(errStr)
763 virtual const char * what()
const throw ()
765 if (errStr_ == NULL) {
777 cl_int err(
void)
const {
return err_; }
779 #define CL_HPP_ERR_STR_(x) #x
781 #define CL_HPP_ERR_STR_(x) NULL
782 #endif // CL_HPP_ENABLE_EXCEPTIONS
787 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
788 static inline cl_int errHandler (
790 const char * errStr = NULL)
792 if (err != CL_SUCCESS) {
793 throw Error(err, errStr);
798 static inline cl_int errHandler (cl_int err,
const char * errStr = NULL)
803 #endif // CL_HPP_ENABLE_EXCEPTIONS
809 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
810 #define __GET_DEVICE_INFO_ERR CL_HPP_ERR_STR_(clGetDeviceInfo)
811 #define __GET_PLATFORM_INFO_ERR CL_HPP_ERR_STR_(clGetPlatformInfo)
812 #define __GET_DEVICE_IDS_ERR CL_HPP_ERR_STR_(clGetDeviceIDs)
813 #define __GET_PLATFORM_IDS_ERR CL_HPP_ERR_STR_(clGetPlatformIDs)
814 #define __GET_CONTEXT_INFO_ERR CL_HPP_ERR_STR_(clGetContextInfo)
815 #define __GET_EVENT_INFO_ERR CL_HPP_ERR_STR_(clGetEventInfo)
816 #define __GET_EVENT_PROFILE_INFO_ERR CL_HPP_ERR_STR_(clGetEventProfileInfo)
817 #define __GET_MEM_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetMemObjectInfo)
818 #define __GET_IMAGE_INFO_ERR CL_HPP_ERR_STR_(clGetImageInfo)
819 #define __GET_SAMPLER_INFO_ERR CL_HPP_ERR_STR_(clGetSamplerInfo)
820 #define __GET_KERNEL_INFO_ERR CL_HPP_ERR_STR_(clGetKernelInfo)
821 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
822 #define __GET_KERNEL_ARG_INFO_ERR CL_HPP_ERR_STR_(clGetKernelArgInfo)
823 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
824 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
825 #define __GET_KERNEL_SUB_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelSubGroupInfo)
826 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
827 #define __GET_KERNEL_WORK_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelWorkGroupInfo)
828 #define __GET_PROGRAM_INFO_ERR CL_HPP_ERR_STR_(clGetProgramInfo)
829 #define __GET_PROGRAM_BUILD_INFO_ERR CL_HPP_ERR_STR_(clGetProgramBuildInfo)
830 #define __GET_COMMAND_QUEUE_INFO_ERR CL_HPP_ERR_STR_(clGetCommandQueueInfo)
832 #define __CREATE_CONTEXT_ERR CL_HPP_ERR_STR_(clCreateContext)
833 #define __CREATE_CONTEXT_FROM_TYPE_ERR CL_HPP_ERR_STR_(clCreateContextFromType)
834 #define __GET_SUPPORTED_IMAGE_FORMATS_ERR CL_HPP_ERR_STR_(clGetSupportedImageFormats)
836 #define __CREATE_BUFFER_ERR CL_HPP_ERR_STR_(clCreateBuffer)
837 #define __COPY_ERR CL_HPP_ERR_STR_(cl::copy)
838 #define __CREATE_SUBBUFFER_ERR CL_HPP_ERR_STR_(clCreateSubBuffer)
839 #define __CREATE_GL_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
840 #define __CREATE_GL_RENDER_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
841 #define __GET_GL_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetGLObjectInfo)
842 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
843 #define __CREATE_IMAGE_ERR CL_HPP_ERR_STR_(clCreateImage)
844 #define __CREATE_GL_TEXTURE_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture)
845 #define __IMAGE_DIMENSION_ERR CL_HPP_ERR_STR_(Incorrect image dimensions)
846 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
847 #define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR CL_HPP_ERR_STR_(clSetMemObjectDestructorCallback)
849 #define __CREATE_USER_EVENT_ERR CL_HPP_ERR_STR_(clCreateUserEvent)
850 #define __SET_USER_EVENT_STATUS_ERR CL_HPP_ERR_STR_(clSetUserEventStatus)
851 #define __SET_EVENT_CALLBACK_ERR CL_HPP_ERR_STR_(clSetEventCallback)
852 #define __WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clWaitForEvents)
854 #define __CREATE_KERNEL_ERR CL_HPP_ERR_STR_(clCreateKernel)
855 #define __SET_KERNEL_ARGS_ERR CL_HPP_ERR_STR_(clSetKernelArg)
856 #define __CREATE_PROGRAM_WITH_SOURCE_ERR CL_HPP_ERR_STR_(clCreateProgramWithSource)
857 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
858 #define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
859 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
860 #define __CREATE_PROGRAM_WITH_BINARY_ERR CL_HPP_ERR_STR_(clCreateProgramWithBinary)
861 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
862 #define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
863 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
864 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
865 #define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR CL_HPP_ERR_STR_(clCreateProgramWithBuiltInKernels)
866 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
867 #define __BUILD_PROGRAM_ERR CL_HPP_ERR_STR_(clBuildProgram)
868 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
869 #define __COMPILE_PROGRAM_ERR CL_HPP_ERR_STR_(clCompileProgram)
870 #define __LINK_PROGRAM_ERR CL_HPP_ERR_STR_(clLinkProgram)
871 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
872 #define __CREATE_KERNELS_IN_PROGRAM_ERR CL_HPP_ERR_STR_(clCreateKernelsInProgram)
874 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
875 #define __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateCommandQueueWithProperties)
876 #define __CREATE_SAMPLER_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateSamplerWithProperties)
877 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
878 #define __SET_COMMAND_QUEUE_PROPERTY_ERR CL_HPP_ERR_STR_(clSetCommandQueueProperty)
879 #define __ENQUEUE_READ_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueReadBuffer)
880 #define __ENQUEUE_READ_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueReadBufferRect)
881 #define __ENQUEUE_WRITE_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueWriteBuffer)
882 #define __ENQUEUE_WRITE_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueWriteBufferRect)
883 #define __ENQEUE_COPY_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyBuffer)
884 #define __ENQEUE_COPY_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferRect)
885 #define __ENQUEUE_FILL_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueFillBuffer)
886 #define __ENQUEUE_READ_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueReadImage)
887 #define __ENQUEUE_WRITE_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueWriteImage)
888 #define __ENQUEUE_COPY_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyImage)
889 #define __ENQUEUE_FILL_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueFillImage)
890 #define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyImageToBuffer)
891 #define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferToImage)
892 #define __ENQUEUE_MAP_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueMapBuffer)
893 #define __ENQUEUE_MAP_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueMapImage)
894 #define __ENQUEUE_UNMAP_MEM_OBJECT_ERR CL_HPP_ERR_STR_(clEnqueueUnMapMemObject)
895 #define __ENQUEUE_NDRANGE_KERNEL_ERR CL_HPP_ERR_STR_(clEnqueueNDRangeKernel)
896 #define __ENQUEUE_NATIVE_KERNEL CL_HPP_ERR_STR_(clEnqueueNativeKernel)
897 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
898 #define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR CL_HPP_ERR_STR_(clEnqueueMigrateMemObjects)
899 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
900 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
901 #define __ENQUEUE_MIGRATE_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMMigrateMem)
902 #define __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clSetDefaultDeviceCommandQueue)
903 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
906 #define __ENQUEUE_ACQUIRE_GL_ERR CL_HPP_ERR_STR_(clEnqueueAcquireGLObjects)
907 #define __ENQUEUE_RELEASE_GL_ERR CL_HPP_ERR_STR_(clEnqueueReleaseGLObjects)
909 #define __CREATE_PIPE_ERR CL_HPP_ERR_STR_(clCreatePipe)
910 #define __GET_PIPE_INFO_ERR CL_HPP_ERR_STR_(clGetPipeInfo)
913 #define __RETAIN_ERR CL_HPP_ERR_STR_(Retain Object)
914 #define __RELEASE_ERR CL_HPP_ERR_STR_(Release Object)
915 #define __FLUSH_ERR CL_HPP_ERR_STR_(clFlush)
916 #define __FINISH_ERR CL_HPP_ERR_STR_(clFinish)
917 #define __VECTOR_CAPACITY_ERR CL_HPP_ERR_STR_(Vector capacity error)
919 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
920 #define __GET_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetHostTimer)
921 #define __GET_DEVICE_AND_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetDeviceAndHostTimer)
923 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
924 #define __SET_PROGRAM_RELEASE_CALLBACK_ERR CL_HPP_ERR_STR_(clSetProgramReleaseCallback)
925 #define __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR CL_HPP_ERR_STR_(clSetProgramSpecializationConstant)
932 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
933 #define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevices)
935 #define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevicesEXT)
936 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
941 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
942 #define __ENQUEUE_MARKER_ERR CL_HPP_ERR_STR_(clEnqueueMarker)
943 #define __ENQUEUE_WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clEnqueueWaitForEvents)
944 #define __ENQUEUE_BARRIER_ERR CL_HPP_ERR_STR_(clEnqueueBarrier)
945 #define __UNLOAD_COMPILER_ERR CL_HPP_ERR_STR_(clUnloadCompiler)
946 #define __CREATE_GL_TEXTURE_2D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture2D)
947 #define __CREATE_GL_TEXTURE_3D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture3D)
948 #define __CREATE_IMAGE2D_ERR CL_HPP_ERR_STR_(clCreateImage2D)
949 #define __CREATE_IMAGE3D_ERR CL_HPP_ERR_STR_(clCreateImage3D)
950 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
955 #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
956 #define __CREATE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clCreateCommandQueue)
957 #define __ENQUEUE_TASK_ERR CL_HPP_ERR_STR_(clEnqueueTask)
958 #define __CREATE_SAMPLER_ERR CL_HPP_ERR_STR_(clCreateSampler)
959 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
964 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
965 #define __ENQUEUE_MARKER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueMarkerWithWaitList)
966 #define __ENQUEUE_BARRIER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueBarrierWithWaitList)
967 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
969 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
970 #define __CLONE_KERNEL_ERR CL_HPP_ERR_STR_(clCloneKernel)
971 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
973 #endif // CL_HPP_USER_OVERRIDE_ERROR_STRINGS
983 template<
typename Functor,
typename T>
984 inline cl_int getInfoHelper(Functor f, cl_uint name, T* param,
long)
986 return f(name,
sizeof(T), param, NULL);
991 template <
typename Func>
992 inline cl_int getInfoHelper(Func f, cl_uint name, vector<vector<unsigned char>>* param,
int)
994 if (name != CL_PROGRAM_BINARIES) {
995 return CL_INVALID_VALUE;
999 size_type numBinaries = param->size();
1000 vector<unsigned char*> binariesPointers(numBinaries);
1002 for (size_type i = 0; i < numBinaries; ++i)
1004 binariesPointers[i] = (*param)[i].data();
1007 cl_int err = f(name, numBinaries *
sizeof(
unsigned char*), binariesPointers.data(), NULL);
1009 if (err != CL_SUCCESS) {
1019 template <
typename Func,
typename T>
1020 inline cl_int getInfoHelper(Func f, cl_uint name, vector<T>* param,
long)
1023 cl_int err = f(name, 0, NULL, &required);
1024 if (err != CL_SUCCESS) {
1027 const size_type elements = required /
sizeof(T);
1030 vector<T> localData(elements);
1031 err = f(name, required, localData.data(), NULL);
1032 if (err != CL_SUCCESS) {
1036 *param = std::move(localData);
1048 template <
typename Func,
typename T>
1049 inline cl_int getInfoHelper(
1050 Func f, cl_uint name, vector<T>* param,
int,
typename T::cl_type = 0)
1053 cl_int err = f(name, 0, NULL, &required);
1054 if (err != CL_SUCCESS) {
1058 const size_type elements = required /
sizeof(
typename T::cl_type);
1060 vector<typename T::cl_type> value(elements);
1061 err = f(name, required, value.data(), NULL);
1062 if (err != CL_SUCCESS) {
1068 param->resize(elements);
1072 for (size_type i = 0; i < elements; i++) {
1073 (*param)[i] = T(value[i],
true);
1080 template <
typename Func>
1081 inline cl_int getInfoHelper(Func f, cl_uint name,
string* param,
long)
1084 cl_int err = f(name, 0, NULL, &required);
1085 if (err != CL_SUCCESS) {
1092 vector<char> value(required);
1093 err = f(name, required, value.data(), NULL);
1094 if (err != CL_SUCCESS) {
1098 param->assign(begin(value), prev(end(value)));
1108 template <
typename Func,
size_type N>
1109 inline cl_int getInfoHelper(Func f, cl_uint name, array<size_type, N>* param,
long)
1112 cl_int err = f(name, 0, NULL, &required);
1113 if (err != CL_SUCCESS) {
1117 size_type elements = required /
sizeof(size_type);
1118 vector<size_type> value(elements, 0);
1120 err = f(name, required, value.data(), NULL);
1121 if (err != CL_SUCCESS) {
1130 for (size_type i = 0; i < elements; ++i) {
1131 (*param)[i] = value[i];
1137 template<
typename T>
struct ReferenceHandler;
1145 template<
typename Func,
typename T>
1146 inline cl_int getInfoHelper(Func f, cl_uint name, T* param,
int,
typename T::cl_type = 0)
1148 typename T::cl_type value;
1149 cl_int err = f(name,
sizeof(value), &value, NULL);
1150 if (err != CL_SUCCESS) {
1156 err = param->retain();
1157 if (err != CL_SUCCESS) {
1164 #define CL_HPP_PARAM_NAME_INFO_1_0_(F) \
1165 F(cl_platform_info, CL_PLATFORM_PROFILE, string) \
1166 F(cl_platform_info, CL_PLATFORM_VERSION, string) \
1167 F(cl_platform_info, CL_PLATFORM_NAME, string) \
1168 F(cl_platform_info, CL_PLATFORM_VENDOR, string) \
1169 F(cl_platform_info, CL_PLATFORM_EXTENSIONS, string) \
1171 F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
1172 F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
1173 F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
1174 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
1175 F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, size_type) \
1176 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, cl::vector<size_type>) \
1177 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
1178 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
1179 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
1180 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
1181 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
1182 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
1183 F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
1184 F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \
1185 F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
1186 F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
1187 F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
1188 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, size_type) \
1189 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, size_type) \
1190 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, size_type) \
1191 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, size_type) \
1192 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, size_type) \
1193 F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \
1194 F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, size_type) \
1195 F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
1196 F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
1197 F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
1198 F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
1199 F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
1200 F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
1201 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
1202 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
1203 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
1204 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
1205 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
1206 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
1207 F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
1208 F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
1209 F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
1210 F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, size_type) \
1211 F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
1212 F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
1213 F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
1214 F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
1215 F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
1216 F(cl_device_info, CL_DEVICE_NAME, string) \
1217 F(cl_device_info, CL_DEVICE_VENDOR, string) \
1218 F(cl_device_info, CL_DRIVER_VERSION, string) \
1219 F(cl_device_info, CL_DEVICE_PROFILE, string) \
1220 F(cl_device_info, CL_DEVICE_VERSION, string) \
1221 F(cl_device_info, CL_DEVICE_EXTENSIONS, string) \
1223 F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
1224 F(cl_context_info, CL_CONTEXT_DEVICES, cl::vector<Device>) \
1225 F(cl_context_info, CL_CONTEXT_PROPERTIES, cl::vector<cl_context_properties>) \
1227 F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
1228 F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
1229 F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
1230 F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \
1232 F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
1233 F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
1234 F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
1235 F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
1237 F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
1238 F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
1239 F(cl_mem_info, CL_MEM_SIZE, size_type) \
1240 F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
1241 F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
1242 F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
1243 F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
1245 F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
1246 F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, size_type) \
1247 F(cl_image_info, CL_IMAGE_ROW_PITCH, size_type) \
1248 F(cl_image_info, CL_IMAGE_SLICE_PITCH, size_type) \
1249 F(cl_image_info, CL_IMAGE_WIDTH, size_type) \
1250 F(cl_image_info, CL_IMAGE_HEIGHT, size_type) \
1251 F(cl_image_info, CL_IMAGE_DEPTH, size_type) \
1253 F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
1254 F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
1255 F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \
1256 F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \
1257 F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \
1259 F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
1260 F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
1261 F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
1262 F(cl_program_info, CL_PROGRAM_DEVICES, cl::vector<Device>) \
1263 F(cl_program_info, CL_PROGRAM_SOURCE, string) \
1264 F(cl_program_info, CL_PROGRAM_BINARY_SIZES, cl::vector<size_type>) \
1265 F(cl_program_info, CL_PROGRAM_BINARIES, cl::vector<cl::vector<unsigned char>>) \
1267 F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
1268 F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, string) \
1269 F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, string) \
1271 F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, string) \
1272 F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
1273 F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
1274 F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
1275 F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
1277 F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, size_type) \
1278 F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::detail::size_t_array) \
1279 F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
1281 F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
1282 F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
1283 F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
1284 F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
1287 #define CL_HPP_PARAM_NAME_INFO_1_1_(F) \
1288 F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
1289 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
1290 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
1291 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
1292 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
1293 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
1294 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
1295 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
1296 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
1297 F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, string) \
1299 F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
1300 F(cl_mem_info, CL_MEM_OFFSET, size_type) \
1302 F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1303 F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
1305 F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
1307 #define CL_HPP_PARAM_NAME_INFO_1_2_(F) \
1308 F(cl_program_info, CL_PROGRAM_NUM_KERNELS, size_type) \
1309 F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, string) \
1311 F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \
1313 F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, string) \
1315 F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \
1316 F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \
1317 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, string) \
1318 F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, string) \
1319 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \
1321 F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl::Device) \
1322 F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, cl::vector<cl_device_partition_property>) \
1323 F(cl_device_info, CL_DEVICE_PARTITION_TYPE, cl::vector<cl_device_partition_property>) \
1324 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \
1325 F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, size_type) \
1326 F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \
1327 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, string) \
1329 F(cl_image_info, CL_IMAGE_ARRAY_SIZE, size_type) \
1330 F(cl_image_info, CL_IMAGE_NUM_MIP_LEVELS, cl_uint) \
1331 F(cl_image_info, CL_IMAGE_NUM_SAMPLES, cl_uint)
1333 #define CL_HPP_PARAM_NAME_INFO_2_0_(F) \
1334 F(cl_device_info, CL_DEVICE_QUEUE_ON_HOST_PROPERTIES, cl_command_queue_properties) \
1335 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES, cl_command_queue_properties) \
1336 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, cl_uint) \
1337 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, cl_uint) \
1338 F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_QUEUES, cl_uint) \
1339 F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_EVENTS, cl_uint) \
1340 F(cl_device_info, CL_DEVICE_MAX_PIPE_ARGS, cl_uint) \
1341 F(cl_device_info, CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS, cl_uint) \
1342 F(cl_device_info, CL_DEVICE_PIPE_MAX_PACKET_SIZE, cl_uint) \
1343 F(cl_device_info, CL_DEVICE_SVM_CAPABILITIES, cl_device_svm_capabilities) \
1344 F(cl_device_info, CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT, cl_uint) \
1345 F(cl_device_info, CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT, cl_uint) \
1346 F(cl_device_info, CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT, cl_uint) \
1347 F(cl_command_queue_info, CL_QUEUE_SIZE, cl_uint) \
1348 F(cl_mem_info, CL_MEM_USES_SVM_POINTER, cl_bool) \
1349 F(cl_program_build_info, CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, size_type) \
1350 F(cl_pipe_info, CL_PIPE_PACKET_SIZE, cl_uint) \
1351 F(cl_pipe_info, CL_PIPE_MAX_PACKETS, cl_uint)
1353 #define CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(F) \
1354 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR, size_type) \
1355 F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR, size_type)
1357 #define CL_HPP_PARAM_NAME_INFO_IL_KHR_(F) \
1358 F(cl_device_info, CL_DEVICE_IL_VERSION_KHR, string) \
1359 F(cl_program_info, CL_PROGRAM_IL_KHR, cl::vector<unsigned char>)
1361 #define CL_HPP_PARAM_NAME_INFO_2_1_(F) \
1362 F(cl_platform_info, CL_PLATFORM_HOST_TIMER_RESOLUTION, size_type) \
1363 F(cl_program_info, CL_PROGRAM_IL, cl::vector<unsigned char>) \
1364 F(cl_kernel_info, CL_KERNEL_MAX_NUM_SUB_GROUPS, size_type) \
1365 F(cl_kernel_info, CL_KERNEL_COMPILE_NUM_SUB_GROUPS, size_type) \
1366 F(cl_device_info, CL_DEVICE_MAX_NUM_SUB_GROUPS, cl_uint) \
1367 F(cl_device_info, CL_DEVICE_IL_VERSION, string) \
1368 F(cl_device_info, CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS, cl_bool) \
1369 F(cl_command_queue_info, CL_QUEUE_DEVICE_DEFAULT, cl::DeviceCommandQueue) \
1370 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE, size_type) \
1371 F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE, size_type) \
1372 F(cl_kernel_sub_group_info, CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT, cl::detail::size_t_array)
1374 #define CL_HPP_PARAM_NAME_INFO_2_2_(F) \
1375 F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_CTORS_PRESENT, cl_bool) \
1376 F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_DTORS_PRESENT, cl_bool)
1378 #define CL_HPP_PARAM_NAME_DEVICE_FISSION_(F) \
1379 F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
1380 F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, cl::vector<cl_device_partition_property_ext>) \
1381 F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, cl::vector<cl_device_partition_property_ext>) \
1382 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
1383 F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, cl::vector<cl_device_partition_property_ext>)
1385 #define CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_(F) \
1386 F(cl_platform_info, CL_PLATFORM_NUMERIC_VERSION_KHR, cl_version_khr) \
1387 F(cl_platform_info, CL_PLATFORM_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1389 F(cl_device_info, CL_DEVICE_NUMERIC_VERSION_KHR, cl_version_khr) \
1390 F(cl_device_info, CL_DEVICE_OPENCL_C_NUMERIC_VERSION_KHR, cl_version_khr) \
1391 F(cl_device_info, CL_DEVICE_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1392 F(cl_device_info, CL_DEVICE_ILS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1393 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>)
1395 template <
typename enum_type, cl_
int Name>
1398 #define CL_HPP_DECLARE_PARAM_TRAITS_(token, param_name, T) \
1401 struct param_traits<detail:: token,param_name> \
1403 enum { value = param_name }; \
1404 typedef T param_type; \
1407 CL_HPP_PARAM_NAME_INFO_1_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1408 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
1409 CL_HPP_PARAM_NAME_INFO_1_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1410 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
1411 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1412 CL_HPP_PARAM_NAME_INFO_1_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1413 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1414 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
1415 CL_HPP_PARAM_NAME_INFO_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1416 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
1417 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
1418 CL_HPP_PARAM_NAME_INFO_2_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1419 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
1420 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
1421 CL_HPP_PARAM_NAME_INFO_2_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1422 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
1424 #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1425 CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1426 #endif // #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1428 #if defined(CL_HPP_USE_IL_KHR)
1429 CL_HPP_PARAM_NAME_INFO_IL_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1430 #endif // #if defined(CL_HPP_USE_IL_KHR)
1434 #define CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(F) \
1435 F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties)
1437 #define CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(F) \
1438 F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool)
1440 #define CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(F) \
1441 F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer)
1445 #if CL_HPP_TARGET_OPENCL_VERSION > 100 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 && CL_HPP_TARGET_OPENCL_VERSION < 200
1446 CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1447 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 110
1448 #if CL_HPP_TARGET_OPENCL_VERSION > 110 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1449 CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1450 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1451 #if CL_HPP_TARGET_OPENCL_VERSION > 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1452 CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1453 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
1455 #if defined(CL_HPP_USE_CL_DEVICE_FISSION)
1456 CL_HPP_PARAM_NAME_DEVICE_FISSION_(CL_HPP_DECLARE_PARAM_TRAITS_);
1457 #endif // CL_HPP_USE_CL_DEVICE_FISSION
1459 #if defined(cl_khr_extended_versioning)
1460 CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_(CL_HPP_DECLARE_PARAM_TRAITS_);
1461 #endif // cl_khr_extended_versioning
1463 #ifdef CL_PLATFORM_ICD_SUFFIX_KHR
1464 CL_HPP_DECLARE_PARAM_TRAITS_(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR,
string)
1467 #ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
1468 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong)
1471 #ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
1472 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, vector<size_type>)
1474 #ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
1475 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint)
1477 #ifdef CL_DEVICE_SIMD_WIDTH_AMD
1478 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint)
1480 #ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD
1481 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint)
1483 #ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD
1484 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint)
1486 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
1487 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint)
1489 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
1490 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint)
1492 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
1493 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint)
1495 #ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
1496 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint)
1498 #ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
1499 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint)
1502 #ifdef CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM
1503 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM, cl_ulong)
1505 #ifdef CL_DEVICE_JOB_SLOTS_ARM
1506 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_JOB_SLOTS_ARM, cl_uint)
1509 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
1510 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint)
1512 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV
1513 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint)
1515 #ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV
1516 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint)
1518 #ifdef CL_DEVICE_WARP_SIZE_NV
1519 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint)
1521 #ifdef CL_DEVICE_GPU_OVERLAP_NV
1522 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool)
1524 #ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV
1525 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool)
1527 #ifdef CL_DEVICE_INTEGRATED_MEMORY_NV
1528 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool)
1533 template <
typename Func,
typename T>
1535 getInfo(Func f, cl_uint name, T* param)
1537 return getInfoHelper(f, name, param, 0);
1540 template <
typename Func,
typename Arg0>
1543 Func f_;
const Arg0& arg0_;
1545 cl_uint param, size_type size,
void* value, size_type* size_ret)
1546 {
return f_(arg0_, param, size, value, size_ret); }
1549 template <
typename Func,
typename Arg0,
typename Arg1>
1552 Func f_;
const Arg0& arg0_;
const Arg1& arg1_;
1554 cl_uint param, size_type size,
void* value, size_type* size_ret)
1555 {
return f_(arg0_, arg1_, param, size, value, size_ret); }
1558 template <
typename Func,
typename Arg0,
typename T>
1560 getInfo(Func f,
const Arg0& arg0, cl_uint name, T* param)
1563 return getInfoHelper(f0, name, param, 0);
1566 template <
typename Func,
typename Arg0,
typename Arg1,
typename T>
1568 getInfo(Func f,
const Arg0& arg0,
const Arg1& arg1, cl_uint name, T* param)
1570 GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
1571 return getInfoHelper(f0, name, param, 0);
1575 template<
typename T>
1579 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1596 { return ::clRetainDevice(device); }
1607 { return ::clReleaseDevice(device); }
1609 #else // CL_HPP_TARGET_OPENCL_VERSION >= 120
1614 struct ReferenceHandler<cl_device_id>
1617 static cl_int retain(cl_device_id)
1618 {
return CL_SUCCESS; }
1620 static cl_int release(cl_device_id)
1621 {
return CL_SUCCESS; }
1623 #endif // ! (CL_HPP_TARGET_OPENCL_VERSION >= 120)
1629 static cl_int retain(cl_platform_id)
1630 {
return CL_SUCCESS; }
1632 static cl_int release(cl_platform_id)
1633 {
return CL_SUCCESS; }
1639 static cl_int retain(cl_context context)
1640 { return ::clRetainContext(context); }
1641 static cl_int release(cl_context context)
1642 { return ::clReleaseContext(context); }
1648 static cl_int retain(cl_command_queue queue)
1649 { return ::clRetainCommandQueue(queue); }
1650 static cl_int release(cl_command_queue queue)
1651 { return ::clReleaseCommandQueue(queue); }
1657 static cl_int retain(cl_mem memory)
1658 { return ::clRetainMemObject(memory); }
1659 static cl_int release(cl_mem memory)
1660 { return ::clReleaseMemObject(memory); }
1666 static cl_int retain(cl_sampler sampler)
1667 { return ::clRetainSampler(sampler); }
1668 static cl_int release(cl_sampler sampler)
1669 { return ::clReleaseSampler(sampler); }
1675 static cl_int retain(cl_program program)
1676 { return ::clRetainProgram(program); }
1677 static cl_int release(cl_program program)
1678 { return ::clReleaseProgram(program); }
1684 static cl_int retain(cl_kernel kernel)
1685 { return ::clRetainKernel(kernel); }
1686 static cl_int release(cl_kernel kernel)
1687 { return ::clReleaseKernel(kernel); }
1693 static cl_int retain(cl_event event)
1694 { return ::clRetainEvent(event); }
1695 static cl_int release(cl_event event)
1696 { return ::clReleaseEvent(event); }
1700 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1702 static cl_uint getVersion(
const vector<char> &versionInfo)
1704 int highVersion = 0;
1707 while(versionInfo[index] !=
'.' ) {
1709 highVersion += versionInfo[index]-
'0';
1713 while(versionInfo[index] !=
' ' && versionInfo[index] !=
'\0') {
1715 lowVersion += versionInfo[index]-
'0';
1718 return (highVersion << 16) | lowVersion;
1721 static cl_uint getPlatformVersion(cl_platform_id platform)
1724 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size);
1726 vector<char> versionInfo(size);
1727 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, versionInfo.data(), &size);
1728 return getVersion(versionInfo);
1731 static cl_uint getDevicePlatformVersion(cl_device_id device)
1733 cl_platform_id platform;
1734 clGetDeviceInfo(device, CL_DEVICE_PLATFORM,
sizeof(platform), &platform, NULL);
1735 return getPlatformVersion(platform);
1738 static cl_uint getContextPlatformVersion(cl_context context)
1743 clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size);
1746 vector<cl_device_id> devices(size/
sizeof(cl_device_id));
1747 clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices.data(), NULL);
1748 return getDevicePlatformVersion(devices[0]);
1750 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1752 template <
typename T>
1764 Wrapper(
const cl_type &obj,
bool retainObject) : object_(obj)
1767 detail::errHandler(retain(), __RETAIN_ERR);
1773 if (object_ != NULL) { release(); }
1778 object_ = rhs.object_;
1779 detail::errHandler(retain(), __RETAIN_ERR);
1784 object_ = rhs.object_;
1791 detail::errHandler(release(), __RELEASE_ERR);
1792 object_ = rhs.object_;
1793 detail::errHandler(retain(), __RETAIN_ERR);
1801 detail::errHandler(release(), __RELEASE_ERR);
1802 object_ = rhs.object_;
1810 detail::errHandler(release(), __RELEASE_ERR);
1815 const cl_type& operator ()()
const {
return object_; }
1817 cl_type& operator ()() {
return object_; }
1819 cl_type get()
const {
return object_; }
1822 template<
typename Func,
typename U>
1823 friend inline cl_int getInfoHelper(Func, cl_uint, U*,
int,
typename U::cl_type);
1825 cl_int retain()
const
1827 if (object_ !=
nullptr) {
1835 cl_int release()
const
1837 if (object_ !=
nullptr) {
1850 typedef cl_device_id cl_type;
1854 bool referenceCountable_;
1856 static bool isReferenceCountable(cl_device_id device)
1858 bool retVal =
false;
1859 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1860 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
1861 if (device != NULL) {
1862 int version = getDevicePlatformVersion(device);
1863 if(version > ((1 << 16) + 1)) {
1867 #else // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1869 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1870 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1875 Wrapper() : object_(NULL), referenceCountable_(
false)
1879 Wrapper(
const cl_type &obj,
bool retainObject) :
1881 referenceCountable_(
false)
1883 referenceCountable_ = isReferenceCountable(obj);
1886 detail::errHandler(retain(), __RETAIN_ERR);
1897 object_ = rhs.object_;
1898 referenceCountable_ = isReferenceCountable(object_);
1899 detail::errHandler(retain(), __RETAIN_ERR);
1904 object_ = rhs.object_;
1905 referenceCountable_ = rhs.referenceCountable_;
1907 rhs.referenceCountable_ =
false;
1913 detail::errHandler(release(), __RELEASE_ERR);
1914 object_ = rhs.object_;
1915 referenceCountable_ = rhs.referenceCountable_;
1916 detail::errHandler(retain(), __RETAIN_ERR);
1924 detail::errHandler(release(), __RELEASE_ERR);
1925 object_ = rhs.object_;
1926 referenceCountable_ = rhs.referenceCountable_;
1928 rhs.referenceCountable_ =
false;
1935 detail::errHandler(release(), __RELEASE_ERR);
1937 referenceCountable_ = isReferenceCountable(object_);
1941 const cl_type& operator ()()
const {
return object_; }
1943 cl_type& operator ()() {
return object_; }
1945 cl_type get()
const {
return object_; }
1948 template<
typename Func,
typename U>
1949 friend inline cl_int getInfoHelper(Func, cl_uint, U*,
int,
typename U::cl_type);
1951 template<
typename Func,
typename U>
1952 friend inline cl_int getInfoHelper(Func, cl_uint, vector<U>*,
int,
typename U::cl_type);
1954 cl_int retain()
const
1956 if( object_ !=
nullptr && referenceCountable_ ) {
1964 cl_int release()
const
1966 if (object_ !=
nullptr && referenceCountable_) {
1975 template <
typename T>
1978 return lhs() == rhs();
1981 template <
typename T>
1982 inline bool operator!=(
const Wrapper<T> &lhs,
const Wrapper<T> &rhs)
1984 return !operator==(lhs, rhs);
1991 using BuildLogType = vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, CL_PROGRAM_BUILD_LOG>::param_type>>;
1992 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
1996 class BuildError :
public Error
1999 BuildLogType buildLogs;
2001 BuildError(cl_int err,
const char * errStr,
const BuildLogType &vec) : Error(err, errStr), buildLogs(vec)
2005 BuildLogType getBuildLog()
const
2011 static inline cl_int buildErrHandler(
2013 const char * errStr,
2014 const BuildLogType &buildLogs)
2016 if (err != CL_SUCCESS) {
2017 throw BuildError(err, errStr, buildLogs);
2025 static inline cl_int buildErrHandler(
2027 const char * errStr,
2028 const BuildLogType &buildLogs)
2035 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2051 image_channel_order = order;
2052 image_channel_data_type = type;
2059 this->image_channel_data_type = rhs.image_channel_data_type;
2060 this->image_channel_order = rhs.image_channel_order;
2076 static std::once_flag default_initialized_;
2078 static cl_int default_error_;
2085 static void makeDefault();
2092 static void makeDefaultProvided(
const Device &p) {
2097 #ifdef CL_HPP_UNIT_TEST_ENABLE
2104 static void unitTestClearDefault() {
2107 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2116 explicit Device(
const cl_device_id &device,
bool retainObject =
false) :
2117 detail::Wrapper<cl_type>(device, retainObject) { }
2124 cl_int *errResult = NULL)
2126 std::call_once(default_initialized_, makeDefault);
2127 detail::errHandler(default_error_);
2128 if (errResult != NULL) {
2129 *errResult = default_error_;
2143 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_device));
2144 detail::errHandler(default_error_);
2187 template <
typename T>
2188 cl_int
getInfo(cl_device_info name, T* param)
const
2190 return detail::errHandler(
2191 detail::getInfo(&::clGetDeviceInfo, object_, name, param),
2192 __GET_DEVICE_INFO_ERR);
2196 template <cl_device_info name>
typename
2201 detail::cl_device_info, name>::param_type param;
2202 cl_int result =
getInfo(name, ¶m);
2210 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2219 cl_ulong retVal = 0;
2221 clGetHostTimer(this->get(), &retVal);
2224 __GET_HOST_TIMER_ERR);
2243 std::pair<cl_ulong, cl_ulong> retVal;
2245 clGetDeviceAndHostTimer(this->get(), &(retVal.first), &(retVal.second));
2248 __GET_DEVICE_AND_HOST_TIMER_ERR);
2254 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2259 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
2262 const cl_device_partition_property * properties,
2263 vector<Device>* devices)
2266 cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n);
2267 if (err != CL_SUCCESS) {
2268 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2271 vector<cl_device_id> ids(n);
2272 err = clCreateSubDevices(object_, properties, n, ids.data(), NULL);
2273 if (err != CL_SUCCESS) {
2274 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2280 devices->resize(ids.size());
2284 for (size_type i = 0; i < ids.size(); i++) {
2287 (*devices)[i] =
Device(ids[i],
false);
2293 #elif defined(CL_HPP_USE_CL_DEVICE_FISSION)
2299 const cl_device_partition_property_ext * properties,
2300 vector<Device>* devices)
2302 typedef CL_API_ENTRY cl_int
2303 ( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
2305 const cl_device_partition_property_ext * ,
2308 cl_uint * ) CL_EXT_SUFFIX__VERSION_1_1;
2310 static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
2311 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSubDevicesEXT);
2314 cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
2315 if (err != CL_SUCCESS) {
2316 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2319 vector<cl_device_id> ids(n);
2320 err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids.data(), NULL);
2321 if (err != CL_SUCCESS) {
2322 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2327 devices->resize(ids.size());
2331 for (size_type i = 0; i < ids.size(); i++) {
2334 (*devices)[i] =
Device(ids[i],
false);
2339 #endif // defined(CL_HPP_USE_CL_DEVICE_FISSION)
2342 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Device::default_initialized_;
2343 CL_HPP_DEFINE_STATIC_MEMBER_ Device Device::default_;
2344 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Device::default_error_ = CL_SUCCESS;
2356 static std::once_flag default_initialized_;
2358 static cl_int default_error_;
2365 static void makeDefault() {
2369 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2377 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2378 if (err != CL_SUCCESS) {
2379 default_error_ = err;
2383 default_error_ = CL_INVALID_PLATFORM;
2387 vector<cl_platform_id> ids(n);
2388 err = ::clGetPlatformIDs(n, ids.data(), NULL);
2389 if (err != CL_SUCCESS) {
2390 default_error_ = err;
2396 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2397 catch (cl::Error &e) {
2398 default_error_ = e.err();
2408 static void makeDefaultProvided(
const Platform &p) {
2413 #ifdef CL_HPP_UNIT_TEST_ENABLE
2420 static void unitTestClearDefault() {
2423 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2435 explicit Platform(
const cl_platform_id &platform,
bool retainObject =
false) :
2436 detail::Wrapper<cl_type>(platform, retainObject) { }
2449 cl_int *errResult = NULL)
2451 std::call_once(default_initialized_, makeDefault);
2452 detail::errHandler(default_error_);
2453 if (errResult != NULL) {
2454 *errResult = default_error_;
2468 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_platform));
2469 detail::errHandler(default_error_);
2474 template <
typename T>
2475 cl_int
getInfo(cl_platform_info name, T* param)
const
2477 return detail::errHandler(
2478 detail::getInfo(&::clGetPlatformInfo, object_, name, param),
2479 __GET_PLATFORM_INFO_ERR);
2483 template <cl_platform_info name>
typename
2488 detail::cl_platform_info, name>::param_type param;
2489 cl_int result =
getInfo(name, ¶m);
2501 cl_device_type type,
2502 vector<Device>* devices)
const
2505 if( devices == NULL ) {
2506 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2508 cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
2509 if (err != CL_SUCCESS && err != CL_DEVICE_NOT_FOUND) {
2510 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2513 vector<cl_device_id> ids(n);
2515 err = ::clGetDeviceIDs(object_, type, n, ids.data(), NULL);
2516 if (err != CL_SUCCESS) {
2517 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2526 devices->resize(ids.size());
2530 for (size_type i = 0; i < ids.size(); i++) {
2531 (*devices)[i] =
Device(ids[i],
true);
2537 #if defined(CL_HPP_USE_DX_INTEROP)
2562 cl_d3d10_device_source_khr d3d_device_source,
2564 cl_d3d10_device_set_khr d3d_device_set,
2565 vector<Device>* devices)
const
2567 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
2568 cl_platform_id platform,
2569 cl_d3d10_device_source_khr d3d_device_source,
2571 cl_d3d10_device_set_khr d3d_device_set,
2572 cl_uint num_entries,
2573 cl_device_id * devices,
2574 cl_uint* num_devices);
2576 if( devices == NULL ) {
2577 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2580 static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
2581 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(object_, clGetDeviceIDsFromD3D10KHR);
2584 cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
2592 if (err != CL_SUCCESS) {
2593 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2596 vector<cl_device_id> ids(n);
2597 err = pfn_clGetDeviceIDsFromD3D10KHR(
2605 if (err != CL_SUCCESS) {
2606 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2614 devices->resize(ids.size());
2618 for (size_type i = 0; i < ids.size(); i++) {
2619 (*devices)[i] = Device(ids[i],
true);
2631 vector<Platform>* platforms)
2635 if( platforms == NULL ) {
2636 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
2639 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2640 if (err != CL_SUCCESS) {
2641 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2644 vector<cl_platform_id> ids(n);
2645 err = ::clGetPlatformIDs(n, ids.data(), NULL);
2646 if (err != CL_SUCCESS) {
2647 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2651 platforms->resize(ids.size());
2654 for (size_type i = 0; i < ids.size(); i++) {
2655 (*platforms)[i] =
Platform(ids[i]);
2669 Platform default_platform = Platform::getDefault(&err);
2671 *platform = default_platform;
2685 cl_int * errResult = NULL)
2688 Platform default_platform = Platform::getDefault(&err);
2692 return default_platform;
2695 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
2700 return ::clUnloadPlatformCompiler(object_);
2702 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
2705 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Platform::default_initialized_;
2706 CL_HPP_DEFINE_STATIC_MEMBER_ Platform Platform::default_;
2707 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Platform::default_error_ = CL_SUCCESS;
2713 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2718 inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int
2723 return ::clUnloadCompiler();
2725 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2739 static std::once_flag default_initialized_;
2741 static cl_int default_error_;
2748 static void makeDefault() {
2752 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2756 #if !defined(__APPLE__) && !defined(__MACOS)
2757 const Platform &p = Platform::getDefault();
2758 cl_platform_id defaultPlatform = p();
2759 cl_context_properties properties[3] = {
2760 CL_CONTEXT_PLATFORM, (cl_context_properties)defaultPlatform, 0
2762 #else // #if !defined(__APPLE__) && !defined(__MACOS)
2763 cl_context_properties *properties =
nullptr;
2764 #endif // #if !defined(__APPLE__) && !defined(__MACOS)
2767 CL_DEVICE_TYPE_DEFAULT,
2773 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2774 catch (cl::Error &e) {
2775 default_error_ = e.err();
2786 static void makeDefaultProvided(
const Context &c) {
2791 #ifdef CL_HPP_UNIT_TEST_ENABLE
2798 static void unitTestClearDefault() {
2801 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2808 const vector<Device>& devices,
2809 cl_context_properties* properties = NULL,
2810 void (CL_CALLBACK * notifyFptr)(
2820 size_type numDevices = devices.size();
2821 vector<cl_device_id> deviceIDs(numDevices);
2823 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
2824 deviceIDs[deviceIndex] = (devices[deviceIndex])();
2827 object_ = ::clCreateContext(
2828 properties, (cl_uint) numDevices,
2830 notifyFptr, data, &error);
2832 detail::errHandler(error, __CREATE_CONTEXT_ERR);
2840 cl_context_properties* properties = NULL,
2841 void (CL_CALLBACK * notifyFptr)(
2851 cl_device_id deviceID = device();
2853 object_ = ::clCreateContext(
2856 notifyFptr, data, &error);
2858 detail::errHandler(error, __CREATE_CONTEXT_ERR);
2869 cl_device_type type,
2870 cl_context_properties* properties = NULL,
2871 void (CL_CALLBACK * notifyFptr)(
2881 #if !defined(__APPLE__) && !defined(__MACOS)
2882 cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 };
2884 if (properties == NULL) {
2886 vector<Platform> platforms;
2887 error = Platform::get(&platforms);
2888 if (error != CL_SUCCESS) {
2889 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2897 cl_context_properties platform_id = 0;
2898 for (
unsigned int i = 0; i < platforms.size(); i++) {
2900 vector<Device> devices;
2902 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2906 error = platforms[i].getDevices(type, &devices);
2908 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2909 }
catch (cl::Error& e) {
2917 if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) {
2918 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2924 if (devices.size() > 0) {
2925 platform_id = (cl_context_properties)platforms[i]();
2930 if (platform_id == 0) {
2931 detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR);
2933 *err = CL_DEVICE_NOT_FOUND;
2938 prop[1] = platform_id;
2939 properties = &prop[0];
2942 object_ = ::clCreateContextFromType(
2943 properties, type, notifyFptr, data, &error);
2945 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2986 std::call_once(default_initialized_, makeDefault);
2987 detail::errHandler(default_error_);
2989 *err = default_error_;
3003 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_context));
3004 detail::errHandler(default_error_);
3016 explicit Context(
const cl_context& context,
bool retainObject =
false) :
3017 detail::Wrapper<cl_type>(context, retainObject) { }
3031 template <
typename T>
3032 cl_int
getInfo(cl_context_info name, T* param)
const
3034 return detail::errHandler(
3035 detail::getInfo(&::clGetContextInfo, object_, name, param),
3036 __GET_CONTEXT_INFO_ERR);
3040 template <cl_context_info name>
typename
3045 detail::cl_context_info, name>::param_type param;
3046 cl_int result =
getInfo(name, ¶m);
3059 cl_mem_object_type type,
3060 vector<ImageFormat>* formats)
const
3068 cl_int err = ::clGetSupportedImageFormats(
3075 if (err != CL_SUCCESS) {
3076 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3079 if (numEntries > 0) {
3080 vector<ImageFormat> value(numEntries);
3081 err = ::clGetSupportedImageFormats(
3086 (cl_image_format*)value.data(),
3088 if (err != CL_SUCCESS) {
3089 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3092 formats->assign(begin(value), end(value));
3103 inline void Device::makeDefault()
3108 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3115 detail::errHandler(error, __CREATE_CONTEXT_ERR);
3117 if (error != CL_SUCCESS) {
3118 default_error_ = error;
3121 default_ = context.
getInfo<CL_CONTEXT_DEVICES>()[0];
3122 default_error_ = CL_SUCCESS;
3125 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3126 catch (cl::Error &e) {
3127 default_error_ = e.err();
3132 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Context::default_initialized_;
3133 CL_HPP_DEFINE_STATIC_MEMBER_ Context Context::default_;
3134 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Context::default_error_ = CL_SUCCESS;
3148 Event() : detail::Wrapper<cl_type>() { }
3158 explicit Event(
const cl_event& event,
bool retainObject =
false) :
3159 detail::Wrapper<cl_type>(event, retainObject) { }
3173 template <
typename T>
3174 cl_int
getInfo(cl_event_info name, T* param)
const
3176 return detail::errHandler(
3177 detail::getInfo(&::clGetEventInfo, object_, name, param),
3178 __GET_EVENT_INFO_ERR);
3182 template <cl_event_info name>
typename
3187 detail::cl_event_info, name>::param_type param;
3188 cl_int result =
getInfo(name, ¶m);
3196 template <
typename T>
3199 return detail::errHandler(detail::getInfo(
3200 &::clGetEventProfilingInfo, object_, name, param),
3201 __GET_EVENT_PROFILE_INFO_ERR);
3205 template <cl_profiling_info name>
typename
3210 detail::cl_profiling_info, name>::param_type param;
3224 return detail::errHandler(
3225 ::clWaitForEvents(1, &object_),
3226 __WAIT_FOR_EVENTS_ERR);
3229 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3236 void (CL_CALLBACK * pfn_notify)(cl_event, cl_int,
void *),
3237 void * user_data = NULL)
3239 return detail::errHandler(
3240 ::clSetEventCallback(
3245 __SET_EVENT_CALLBACK_ERR);
3247 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3256 return detail::errHandler(
3258 (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3259 __WAIT_FOR_EVENTS_ERR);
3263 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3277 cl_int * err = NULL)
3280 object_ = ::clCreateUserEvent(
3284 detail::errHandler(error, __CREATE_USER_EVENT_ERR);
3299 return detail::errHandler(
3300 ::clSetUserEventStatus(object_,status),
3301 __SET_USER_EVENT_STATUS_ERR);
3304 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3310 inline static cl_int
3311 WaitForEvents(
const vector<Event>& events)
3313 return detail::errHandler(
3315 (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3316 __WAIT_FOR_EVENTS_ERR);
3344 explicit Memory(
const cl_mem& memory,
bool retainObject) :
3345 detail::Wrapper<cl_type>(memory, retainObject) { }
3388 template <
typename T>
3391 return detail::errHandler(
3392 detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
3393 __GET_MEM_OBJECT_INFO_ERR);
3397 template <cl_mem_info name>
typename
3402 detail::cl_mem_info, name>::param_type param;
3403 cl_int result =
getInfo(name, ¶m);
3410 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3425 void (CL_CALLBACK * pfn_notify)(cl_mem,
void *),
3426 void * user_data = NULL)
3428 return detail::errHandler(
3429 ::clSetMemObjectDestructorCallback(
3433 __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
3435 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3441 template<
typename IteratorType >
3442 cl_int
copy( IteratorType startIterator, IteratorType endIterator,
cl::Buffer &buffer );
3443 template<
typename IteratorType >
3444 cl_int
copy(
const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3445 template<
typename IteratorType >
3446 cl_int
copy(
const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator,
cl::Buffer &buffer );
3447 template<
typename IteratorType >
3448 cl_int
copy(
const CommandQueue &queue,
const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3451 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
3457 static cl_svm_mem_flags getSVMMemFlags()
3464 template<
class Trait = detail::SVMTraitNull>
3468 static cl_svm_mem_flags getSVMMemFlags()
3470 return CL_MEM_READ_WRITE |
3471 Trait::getSVMMemFlags();
3475 template<
class Trait = detail::SVMTraitNull>
3479 static cl_svm_mem_flags getSVMMemFlags()
3481 return CL_MEM_READ_ONLY |
3482 Trait::getSVMMemFlags();
3486 template<
class Trait = detail::SVMTraitNull>
3490 static cl_svm_mem_flags getSVMMemFlags()
3492 return CL_MEM_WRITE_ONLY |
3493 Trait::getSVMMemFlags();
3497 template<
class Trait = SVMTraitReadWrite<>>
3501 static cl_svm_mem_flags getSVMMemFlags()
3503 return Trait::getSVMMemFlags();
3507 template<
class Trait = SVMTraitReadWrite<>>
3511 static cl_svm_mem_flags getSVMMemFlags()
3513 return CL_MEM_SVM_FINE_GRAIN_BUFFER |
3514 Trait::getSVMMemFlags();
3518 template<
class Trait = SVMTraitReadWrite<>>
3522 static cl_svm_mem_flags getSVMMemFlags()
3525 CL_MEM_SVM_FINE_GRAIN_BUFFER |
3526 CL_MEM_SVM_ATOMICS |
3527 Trait::getSVMMemFlags();
3532 template<
typename T>
3538 const vector<Event>* events = NULL,
3539 Event* event = NULL);
3552 template<
typename T,
class SVMTrait>
3558 typedef T value_type;
3559 typedef value_type* pointer;
3560 typedef const value_type* const_pointer;
3561 typedef value_type& reference;
3562 typedef const value_type& const_reference;
3563 typedef std::size_t size_type;
3564 typedef std::ptrdiff_t difference_type;
3566 template<
typename U>
3572 template<
typename U,
typename V>
3576 context_(
Context::getDefault())
3586 SVMAllocator(
const SVMAllocator &other) :
3587 context_(other.context_)
3591 template<
typename U>
3592 SVMAllocator(
const SVMAllocator<U, SVMTrait> &other) :
3593 context_(other.context_)
3601 pointer address(reference r) CL_HPP_NOEXCEPT_
3603 return std::addressof(r);
3606 const_pointer address(const_reference r) CL_HPP_NOEXCEPT_
3608 return std::addressof(r);
3625 SVMTrait::getSVMMemFlags(),
3628 pointer retValue =
reinterpret_cast<pointer
>(
3630 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3632 std::bad_alloc excep;
3635 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3638 if (!(SVMTrait::getSVMMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) {
3639 cl_int err =
enqueueMapSVM(retValue, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, size*
sizeof(T));
3640 if (err != CL_SUCCESS) {
3641 std::bad_alloc excep;
3650 void deallocate(pointer p, size_type)
3652 clSVMFree(context_(), p);
3661 size_type maxSize = std::numeric_limits<size_type>::max() /
sizeof(T);
3663 for (
const Device &d : context_.
getInfo<CL_CONTEXT_DEVICES>()) {
3666 static_cast<size_type
>(d.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>()));
3672 template<
class U,
class... Args >
3673 void construct(U* p, Args&&... args)
3689 return (context_==rhs.context_);
3699 template<
class SVMTrait>
3702 typedef void value_type;
3703 typedef value_type* pointer;
3704 typedef const value_type* const_pointer;
3706 template<
typename U>
3712 template<
typename U,
typename V>
3716 #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3719 template<
class Alloc>
3726 typedef typename std::allocator_traits<Alloc>::pointer pointer;
3728 Deleter(
const Alloc &alloc, size_type copies) : alloc_{ alloc }, copies_{ copies }
3732 void operator()(pointer ptr)
const {
3733 Alloc tmpAlloc{ alloc_ };
3734 std::allocator_traits<Alloc>::destroy(tmpAlloc, std::addressof(*ptr));
3735 std::allocator_traits<Alloc>::deallocate(tmpAlloc, ptr, copies_);
3746 template <
class T,
class Alloc,
class... Args>
3749 Alloc alloc(alloc_);
3750 static const size_type copies = 1;
3755 T* tmp = std::allocator_traits<Alloc>::allocate(alloc, copies);
3757 std::bad_alloc excep;
3761 std::allocator_traits<Alloc>::construct(
3763 std::addressof(*tmp),
3764 std::forward<Args>(args)...);
3768 catch (std::bad_alloc& b)
3770 std::allocator_traits<Alloc>::deallocate(alloc, tmp, copies);
3775 template<
class T,
class SVMTrait,
class... Args >
3776 cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(Args... args)
3778 SVMAllocator<T, SVMTrait> alloc;
3779 return cl::allocate_pointer<T>(alloc, args...);
3782 template<
class T,
class SVMTrait,
class... Args >
3783 cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(
const cl::Context &c, Args... args)
3785 SVMAllocator<T, SVMTrait> alloc(c);
3786 return cl::allocate_pointer<T>(alloc, args...);
3788 #endif // #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3793 template <
class T >
3799 template <
class T >
3805 template <
class T >
3808 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
3832 void* host_ptr = NULL,
3836 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3838 detail::errHandler(error, __CREATE_BUFFER_ERR);
3856 void* host_ptr = NULL,
3863 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3865 detail::errHandler(error, __CREATE_BUFFER_ERR);
3876 template<
typename IteratorType >
3878 IteratorType startIterator,
3879 IteratorType endIterator,
3881 bool useHostPtr =
false,
3884 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
3887 cl_mem_flags flags = 0;
3889 flags |= CL_MEM_READ_ONLY;
3892 flags |= CL_MEM_READ_WRITE;
3895 flags |= CL_MEM_USE_HOST_PTR;
3898 size_type size =
sizeof(DataType)*(endIterator - startIterator);
3903 object_ = ::clCreateBuffer(context(), flags, size,
static_cast<DataType*
>(&*startIterator), &error);
3905 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
3908 detail::errHandler(error, __CREATE_BUFFER_ERR);
3914 error =
cl::copy(startIterator, endIterator, *
this);
3915 detail::errHandler(error, __CREATE_BUFFER_ERR);
3927 template<
typename IteratorType >
3928 Buffer(
const Context &context, IteratorType startIterator, IteratorType endIterator,
3929 bool readOnly,
bool useHostPtr =
false, cl_int* err = NULL);
3935 template<
typename IteratorType >
3936 Buffer(
const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator,
3937 bool readOnly,
bool useHostPtr =
false, cl_int* err = NULL);
3949 explicit Buffer(
const cl_mem& buffer,
bool retainObject =
false) :
3950 Memory(buffer, retainObject) { }
3990 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3997 cl_buffer_create_type buffer_create_type,
3998 const void * buffer_create_info,
3999 cl_int * err = NULL)
4003 result.object_ = ::clCreateSubBuffer(
4010 detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
4017 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
4020 #if defined (CL_HPP_USE_DX_INTEROP)
4029 class BufferD3D10 :
public Buffer
4040 const Context& context,
4042 ID3D10Buffer* bufobj,
4043 cl_int * err = NULL) : pfn_clCreateFromD3D10BufferKHR(nullptr)
4045 typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
4046 cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
4047 cl_int* errcode_ret);
4048 PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR;
4049 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4050 vector<cl_context_properties> props = context.getInfo<CL_CONTEXT_PROPERTIES>();
4051 cl_platform platform = -1;
4052 for(
int i = 0; i < props.size(); ++i ) {
4053 if( props[i] == CL_CONTEXT_PLATFORM ) {
4054 platform = props[i+1];
4057 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateFromD3D10BufferKHR);
4058 #elif CL_HPP_TARGET_OPENCL_VERSION >= 110
4059 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateFromD3D10BufferKHR);
4063 object_ = pfn_clCreateFromD3D10BufferKHR(
4069 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4076 BufferD3D10() : Buffer() { }
4085 explicit BufferD3D10(
const cl_mem& buffer,
bool retainObject =
false) :
4086 Buffer(buffer, retainObject) { }
4092 BufferD3D10& operator = (
const cl_mem& rhs)
4101 BufferD3D10(
const BufferD3D10& buf) :
4107 BufferD3D10& operator = (
const BufferD3D10 &buf)
4116 BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4121 BufferD3D10& operator = (BufferD3D10 &&buf)
4149 cl_int * err = NULL)
4152 object_ = ::clCreateFromGLBuffer(
4158 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4174 explicit BufferGL(
const cl_mem& buffer,
bool retainObject =
false) :
4175 Buffer(buffer, retainObject) { }
4217 cl_gl_object_type *type,
4218 cl_GLuint * gl_object_name)
4220 return detail::errHandler(
4221 ::clGetGLObjectInfo(object_,type,gl_object_name),
4222 __GET_GL_OBJECT_INFO_ERR);
4246 cl_int * err = NULL)
4249 object_ = ::clCreateFromGLRenderbuffer(
4255 detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR);
4272 Buffer(buffer, retainObject) { }
4314 cl_gl_object_type *type,
4315 cl_GLuint * gl_object_name)
4317 return detail::errHandler(
4318 ::clGetGLObjectInfo(object_,type,gl_object_name),
4319 __GET_GL_OBJECT_INFO_ERR);
4342 explicit Image(
const cl_mem& image,
bool retainObject =
false) :
4343 Memory(image, retainObject) { }
4386 template <
typename T>
4389 return detail::errHandler(
4390 detail::getInfo(&::clGetImageInfo, object_, name, param),
4391 __GET_IMAGE_INFO_ERR);
4395 template <cl_image_info name>
typename
4400 detail::cl_image_info, name>::param_type param;
4409 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4428 void* host_ptr = NULL,
4432 cl_image_desc desc =
4434 CL_MEM_OBJECT_IMAGE1D,
4436 0, 0, 0, 0, 0, 0, 0, 0
4438 object_ = ::clCreateImage(
4446 detail::errHandler(error, __CREATE_IMAGE_ERR);
4462 explicit Image1D(
const cl_mem& image1D,
bool retainObject =
false) :
4463 Image(image1D, retainObject) { }
4520 cl_image_desc desc =
4522 CL_MEM_OBJECT_IMAGE1D_BUFFER,
4524 0, 0, 0, 0, 0, 0, 0,
4527 object_ = ::clCreateImage(
4535 detail::errHandler(error, __CREATE_IMAGE_ERR);
4551 Image(image1D, retainObject) { }
4599 size_type arraySize,
4602 void* host_ptr = NULL,
4606 cl_image_desc desc =
4608 CL_MEM_OBJECT_IMAGE1D_ARRAY,
4615 object_ = ::clCreateImage(
4623 detail::errHandler(error, __CREATE_IMAGE_ERR);
4638 explicit Image1DArray(
const cl_mem& imageArray,
bool retainObject =
false) :
4639 Image(imageArray, retainObject) { }
4677 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4699 size_type row_pitch = 0,
4700 void* host_ptr = NULL,
4704 bool useCreateImage;
4706 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
4709 cl_uint version = detail::getContextPlatformVersion(context());
4710 useCreateImage = (version >= 0x10002);
4712 #elif CL_HPP_TARGET_OPENCL_VERSION >= 120
4713 useCreateImage =
true;
4715 useCreateImage =
false;
4718 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4721 cl_image_desc desc =
4723 CL_MEM_OBJECT_IMAGE2D,
4730 object_ = ::clCreateImage(
4738 detail::errHandler(error, __CREATE_IMAGE_ERR);
4743 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
4744 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
4745 if (!useCreateImage)
4747 object_ = ::clCreateImage2D(
4748 context(), flags,&format, width, height, row_pitch, host_ptr, &error);
4750 detail::errHandler(error, __CREATE_IMAGE2D_ERR);
4755 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
4758 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4767 const Buffer &sourceBuffer,
4770 size_type row_pitch = 0,
4771 cl_int* err =
nullptr)
4775 cl_image_desc desc =
4777 CL_MEM_OBJECT_IMAGE2D,
4786 object_ = ::clCreateImage(
4794 detail::errHandler(error, __CREATE_IMAGE_ERR);
4795 if (err !=
nullptr) {
4799 #endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4801 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
4816 cl_channel_order order,
4817 const Image &sourceImage,
4818 cl_int* err =
nullptr)
4823 size_type sourceWidth =
4825 size_type sourceHeight =
4827 size_type sourceRowPitch =
4829 cl_uint sourceNumMIPLevels =
4831 cl_uint sourceNumSamples =
4833 cl_image_format sourceFormat =
4838 sourceFormat.image_channel_order = order;
4839 cl_image_desc desc =
4841 CL_MEM_OBJECT_IMAGE2D,
4852 object_ = ::clCreateImage(
4860 detail::errHandler(error, __CREATE_IMAGE_ERR);
4861 if (err !=
nullptr) {
4865 #endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200
4877 explicit Image2D(
const cl_mem& image2D,
bool retainObject =
false) :
4878 Image(image2D, retainObject) { }
4921 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
4945 cl_int * err = NULL)
4948 object_ = ::clCreateFromGLTexture2D(
4956 detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR);
4973 explicit Image2DGL(
const cl_mem& image,
bool retainObject =
false) :
4974 Image2D(image, retainObject) { }
5014 } CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
5015 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5017 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5028 size_type arraySize,
5032 size_type slicePitch,
5033 void* host_ptr = NULL,
5037 cl_image_desc desc =
5039 CL_MEM_OBJECT_IMAGE2D_ARRAY,
5048 object_ = ::clCreateImage(
5056 detail::errHandler(error, __CREATE_IMAGE_ERR);
5071 explicit Image2DArray(
const cl_mem& imageArray,
bool retainObject =
false) :
Image(imageArray, retainObject) { }
5107 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5129 size_type row_pitch = 0,
5130 size_type slice_pitch = 0,
5131 void* host_ptr = NULL,
5135 bool useCreateImage;
5137 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
5140 cl_uint version = detail::getContextPlatformVersion(context());
5141 useCreateImage = (version >= 0x10002);
5143 #elif CL_HPP_TARGET_OPENCL_VERSION >= 120
5144 useCreateImage =
true;
5146 useCreateImage =
false;
5149 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5152 cl_image_desc desc =
5154 CL_MEM_OBJECT_IMAGE3D,
5163 object_ = ::clCreateImage(
5171 detail::errHandler(error, __CREATE_IMAGE_ERR);
5176 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5177 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
5178 if (!useCreateImage)
5180 object_ = ::clCreateImage3D(
5181 context(), flags, &format, width, height, depth, row_pitch,
5182 slice_pitch, host_ptr, &error);
5184 detail::errHandler(error, __CREATE_IMAGE3D_ERR);
5189 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
5202 explicit Image3D(
const cl_mem& image3D,
bool retainObject =
false) :
5203 Image(image3D, retainObject) { }
5244 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
5267 cl_int * err = NULL)
5270 object_ = ::clCreateFromGLTexture3D(
5278 detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR);
5294 explicit Image3DGL(
const cl_mem& image,
bool retainObject =
false) :
5295 Image3D(image, retainObject) { }
5335 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5337 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5353 cl_int * err = NULL)
5356 object_ = ::clCreateFromGLTexture(
5364 detail::errHandler(error, __CREATE_GL_TEXTURE_ERR);
5379 explicit ImageGL(
const cl_mem& image,
bool retainObject =
false) :
5380 Image(image, retainObject) { }
5382 ImageGL& operator = (
const cl_mem& rhs)
5416 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5420 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5442 cl_uint packet_size,
5443 cl_uint max_packets,
5448 cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5449 object_ = ::clCreatePipe(context(), flags, packet_size, max_packets,
nullptr, &error);
5451 detail::errHandler(error, __CREATE_PIPE_ERR);
5466 cl_uint packet_size,
5467 cl_uint max_packets,
5474 cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5475 object_ = ::clCreatePipe(context(), flags, packet_size, max_packets,
nullptr, &error);
5477 detail::errHandler(error, __CREATE_PIPE_ERR);
5493 explicit Pipe(
const cl_mem& pipe,
bool retainObject =
false) :
5494 Memory(pipe, retainObject) { }
5535 template <
typename T>
5538 return detail::errHandler(
5539 detail::getInfo(&::clGetPipeInfo, object_, name, param),
5540 __GET_PIPE_INFO_ERR);
5544 template <cl_pipe_info name>
typename
5549 detail::cl_pipe_info, name>::param_type param;
5550 cl_int result =
getInfo(name, ¶m);
5557 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
5580 cl_bool normalized_coords,
5581 cl_addressing_mode addressing_mode,
5582 cl_filter_mode filter_mode,
5587 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5588 cl_sampler_properties sampler_properties[] = {
5589 CL_SAMPLER_NORMALIZED_COORDS, normalized_coords,
5590 CL_SAMPLER_ADDRESSING_MODE, addressing_mode,
5591 CL_SAMPLER_FILTER_MODE, filter_mode,
5593 object_ = ::clCreateSamplerWithProperties(
5598 detail::errHandler(error, __CREATE_SAMPLER_WITH_PROPERTIES_ERR);
5603 object_ = ::clCreateSampler(
5610 detail::errHandler(error, __CREATE_SAMPLER_ERR);
5625 explicit Sampler(
const cl_sampler& sampler,
bool retainObject =
false) :
5626 detail::Wrapper<cl_type>(sampler, retainObject) { }
5668 template <
typename T>
5669 cl_int
getInfo(cl_sampler_info name, T* param)
const
5671 return detail::errHandler(
5672 detail::getInfo(&::clGetSamplerInfo, object_, name, param),
5673 __GET_SAMPLER_INFO_ERR);
5677 template <cl_sampler_info name>
typename
5682 detail::cl_sampler_info, name>::param_type param;
5683 cl_int result =
getInfo(name, ¶m);
5693 class DeviceCommandQueue;
5700 size_type sizes_[3];
5701 cl_uint dimensions_;
5732 NDRange(size_type size0, size_type size1, size_type size2)
5744 operator const size_type*()
const {
5758 return dimensions_*
sizeof(size_type);
5766 const size_type* get()
const
5773 static const NDRange NullRange;
5783 template <
typename T,
class Enable =
void>
5788 template <
typename T>
5791 static size_type size(
const T&) {
return sizeof(T); }
5792 static const T* ptr(
const T& value) {
return &value; }
5797 template <
typename T>
5800 static size_type size(
const T&) {
return sizeof(cl_mem); }
5801 static const cl_mem* ptr(
const T& value) {
return &(value()); }
5809 static size_type size(
const LocalSpaceArg& value) {
return value.size_; }
5810 static const void* ptr(
const LocalSpaceArg&) {
return NULL; }
5837 inline Kernel(
const Program& program,
const char* name, cl_int* err = NULL);
5850 explicit Kernel(
const cl_kernel& kernel,
bool retainObject =
false) :
5851 detail::Wrapper<cl_type>(kernel, retainObject) { }
5892 template <
typename T>
5893 cl_int getInfo(cl_kernel_info name, T* param)
const
5895 return detail::errHandler(
5896 detail::getInfo(&::clGetKernelInfo, object_, name, param),
5897 __GET_KERNEL_INFO_ERR);
5900 template <cl_kernel_info name>
typename
5901 detail::param_traits<detail::cl_kernel_info, name>::param_type
5902 getInfo(cl_int* err = NULL)
const
5904 typename detail::param_traits<
5905 detail::cl_kernel_info, name>::param_type param;
5906 cl_int result = getInfo(name, ¶m);
5913 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5914 template <
typename T>
5915 cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param)
const
5917 return detail::errHandler(
5918 detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param),
5919 __GET_KERNEL_ARG_INFO_ERR);
5922 template <cl_kernel_arg_info name>
typename
5923 detail::param_traits<detail::cl_kernel_arg_info, name>::param_type
5924 getArgInfo(cl_uint argIndex, cl_int* err = NULL)
const
5926 typename detail::param_traits<
5927 detail::cl_kernel_arg_info, name>::param_type param;
5928 cl_int result = getArgInfo(argIndex, name, ¶m);
5934 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5936 template <
typename T>
5937 cl_int getWorkGroupInfo(
5938 const Device& device, cl_kernel_work_group_info name, T* param)
const
5940 return detail::errHandler(
5942 &::clGetKernelWorkGroupInfo, object_, device(), name, param),
5943 __GET_KERNEL_WORK_GROUP_INFO_ERR);
5946 template <cl_kernel_work_group_info name>
typename
5947 detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
5948 getWorkGroupInfo(
const Device& device, cl_int* err = NULL)
const
5950 typename detail::param_traits<
5951 detail::cl_kernel_work_group_info, name>::param_type param;
5952 cl_int result = getWorkGroupInfo(device, name, ¶m);
5959 #if (CL_HPP_TARGET_OPENCL_VERSION >= 200 && defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)) || CL_HPP_TARGET_OPENCL_VERSION >= 210
5960 cl_int getSubGroupInfo(
const cl::Device &dev, cl_kernel_sub_group_info name,
const cl::NDRange &range, size_type* param)
const
5962 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
5964 return detail::errHandler(
5965 clGetKernelSubGroupInfo(object_, dev(), name, range.
size(), range.get(),
sizeof(size_type), param,
nullptr),
5966 __GET_KERNEL_SUB_GROUP_INFO_ERR);
5968 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
5970 typedef clGetKernelSubGroupInfoKHR_fn PFN_clGetKernelSubGroupInfoKHR;
5971 static PFN_clGetKernelSubGroupInfoKHR pfn_clGetKernelSubGroupInfoKHR = NULL;
5972 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetKernelSubGroupInfoKHR);
5974 return detail::errHandler(
5975 pfn_clGetKernelSubGroupInfoKHR(object_, dev(), name, range.
size(), range.get(),
sizeof(size_type), param,
nullptr),
5976 __GET_KERNEL_SUB_GROUP_INFO_ERR);
5978 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
5981 template <cl_kernel_sub_group_info name>
5982 size_type getSubGroupInfo(
const cl::Device &dev,
const cl::NDRange &range, cl_int* err = NULL)
const
5985 cl_int result = getSubGroupInfo(dev, name, range, ¶m);
5991 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5993 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5996 template<
typename T,
class D>
5997 cl_int
setArg(cl_uint index,
const cl::pointer<T, D> &argPtr)
5999 return detail::errHandler(
6000 ::clSetKernelArgSVMPointer(object_, index, argPtr.get()),
6001 __SET_KERNEL_ARGS_ERR);
6006 template<
typename T,
class Alloc>
6007 cl_int
setArg(cl_uint index,
const cl::vector<T, Alloc> &argPtr)
6009 return detail::errHandler(
6010 ::clSetKernelArgSVMPointer(object_, index, argPtr.data()),
6011 __SET_KERNEL_ARGS_ERR);
6016 template<
typename T>
6017 typename std::enable_if<std::is_pointer<T>::value, cl_int>::type
6020 return detail::errHandler(
6021 ::clSetKernelArgSVMPointer(object_, index, argPtr),
6022 __SET_KERNEL_ARGS_ERR);
6024 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6028 template <
typename T>
6029 typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6032 return detail::errHandler(
6038 __SET_KERNEL_ARGS_ERR);
6041 cl_int
setArg(cl_uint index, size_type size,
const void* argPtr)
6043 return detail::errHandler(
6044 ::clSetKernelArg(object_, index, size, argPtr),
6045 __SET_KERNEL_ARGS_ERR);
6048 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6055 return detail::errHandler(
6056 ::clSetKernelExecInfo(
6058 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6059 sizeof(
void*)*pointerList.size(),
6060 pointerList.data()));
6067 template<
int ArrayLength>
6070 return detail::errHandler(
6071 ::clSetKernelExecInfo(
6073 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6074 sizeof(
void*)*pointerList.size(),
6075 pointerList.data()));
6091 cl_bool svmEnabled_ = svmEnabled ? CL_TRUE : CL_FALSE;
6092 return detail::errHandler(
6093 ::clSetKernelExecInfo(
6095 CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM,
6102 template<
int index,
int ArrayLength,
class D,
typename T0,
typename T1,
typename... Ts>
6103 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList,
const pointer<T0, D> &t0,
const pointer<T1, D> &t1, Ts & ... ts)
6105 pointerList[index] =
static_cast<void*
>(t0.get());
6106 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6109 template<
int index,
int ArrayLength,
typename T0,
typename T1,
typename... Ts>
6110 typename std::enable_if<std::is_pointer<T0>::value,
void>::type
6111 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0, T1 t1, Ts... ts)
6113 pointerList[index] =
static_cast<void*
>(t0);
6114 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6117 template<
int index,
int ArrayLength,
typename T0,
class D>
6118 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList,
const pointer<T0, D> &t0)
6120 pointerList[index] =
static_cast<void*
>(t0.get());
6124 template<
int index,
int ArrayLength,
typename T0>
6125 typename std::enable_if<std::is_pointer<T0>::value,
void>::type
6126 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0)
6128 pointerList[index] =
static_cast<void*
>(t0);
6131 template<
typename T0,
typename... Ts>
6134 std::array<
void*, 1 +
sizeof...(Ts)> pointerList;
6136 setSVMPointersHelper<0, 1 +
sizeof...(Ts)>(pointerList, t0, ts...);
6137 return detail::errHandler(
6138 ::clSetKernelExecInfo(
6140 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6141 sizeof(
void*)*(1 +
sizeof...(Ts)),
6142 pointerList.data()));
6144 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6146 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6155 Kernel retValue(clCloneKernel(this->get(), &error));
6157 detail::errHandler(error, __CLONE_KERNEL_ERR);
6160 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6169 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6170 typedef vector<vector<unsigned char>> Binaries;
6171 typedef vector<string> Sources;
6172 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6173 typedef vector<std::pair<const void*, size_type> > Binaries;
6174 typedef vector<std::pair<const char*, size_type> > Sources;
6175 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6178 const string& source,
6184 const char * strings = source.c_str();
6185 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) {
6196 error = ::clBuildProgram(
6200 #
if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6208 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6218 const string& source,
6224 const char * strings = source.c_str();
6225 const size_type length = source.size();
6227 object_ = ::clCreateProgramWithSource(
6228 context(), (cl_uint)1, &strings, &length, &error);
6230 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6232 if (error == CL_SUCCESS && build) {
6233 error = ::clBuildProgram(
6237 #
if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6245 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6258 const Sources& sources,
6264 const size_type n = (size_type)sources.size();
6266 vector<size_type> lengths(n);
6267 vector<const char*> strings(n);
6269 for (size_type i = 0; i < n; ++i) {
6270 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6271 strings[i] = sources[(int)i].data();
6272 lengths[i] = sources[(int)i].length();
6273 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6274 strings[i] = sources[(int)i].first;
6275 lengths[i] = sources[(int)i].second;
6276 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6279 object_ = ::clCreateProgramWithSource(
6280 context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6282 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6294 const Sources& sources,
6299 const size_type n = (size_type)sources.size();
6301 vector<size_type> lengths(n);
6302 vector<const char*> strings(n);
6304 for (size_type i = 0; i < n; ++i) {
6305 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6306 strings[i] = sources[(int)i].data();
6307 lengths[i] = sources[(int)i].length();
6308 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6309 strings[i] = sources[(int)i].first;
6310 lengths[i] = sources[(int)i].second;
6311 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6314 object_ = ::clCreateProgramWithSource(
6315 context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6317 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6324 #if CL_HPP_TARGET_OPENCL_VERSION >= 210 || (CL_HPP_TARGET_OPENCL_VERSION==200 && defined(CL_HPP_USE_IL_KHR))
6330 const vector<char>& IL,
6338 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6340 object_ = ::clCreateProgramWithIL(
6341 context(),
static_cast<const void*
>(IL.data()), IL.size(), &error);
6343 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6345 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6346 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6347 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6349 return detail::errHandler(
6350 pfn_clCreateProgramWithILKHR(
6351 context(),
static_cast<const void*
>(IL.data()), IL.size(), &error);
6355 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6357 if (error == CL_SUCCESS && build) {
6359 error = ::clBuildProgram(
6363 #
if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6371 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6386 const vector<char>& IL,
6392 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6394 object_ = ::clCreateProgramWithIL(
6395 context(),
static_cast<const void*
>(IL.data()), IL.size(), &error);
6397 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6399 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6400 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6401 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6403 return detail::errHandler(
6404 pfn_clCreateProgramWithILKHR(
6405 context(),
static_cast<const void*
>(IL.data()), IL.size(), &error);
6409 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6411 if (error == CL_SUCCESS && build) {
6412 error = ::clBuildProgram(
6416 #
if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6424 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6431 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6454 const vector<Device>& devices,
6455 const Binaries& binaries,
6456 vector<cl_int>* binaryStatus = NULL,
6461 const size_type numDevices = devices.size();
6464 if(binaries.size() != numDevices) {
6465 error = CL_INVALID_VALUE;
6466 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6474 vector<size_type> lengths(numDevices);
6475 vector<const unsigned char*> images(numDevices);
6476 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6477 for (size_type i = 0; i < numDevices; ++i) {
6478 images[i] = binaries[i].data();
6479 lengths[i] = binaries[(int)i].size();
6481 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6482 for (size_type i = 0; i < numDevices; ++i) {
6483 images[i] = (
const unsigned char*)binaries[i].first;
6484 lengths[i] = binaries[(int)i].second;
6486 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6488 vector<cl_device_id> deviceIDs(numDevices);
6489 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6490 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6494 binaryStatus->resize(numDevices);
6497 object_ = ::clCreateProgramWithBinary(
6498 context(), (cl_uint) devices.size(),
6500 lengths.data(), images.data(), (binaryStatus != NULL && numDevices > 0)
6501 ? &binaryStatus->front()
6504 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6511 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6518 const vector<Device>& devices,
6519 const string& kernelNames,
6525 size_type numDevices = devices.size();
6526 vector<cl_device_id> deviceIDs(numDevices);
6527 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6528 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6531 object_ = ::clCreateProgramWithBuiltInKernels(
6533 (cl_uint) devices.size(),
6535 kernelNames.c_str(),
6538 detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR);
6543 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6554 explicit Program(
const cl_program& program,
bool retainObject =
false) :
6555 detail::Wrapper<cl_type>(program, retainObject) { }
6557 Program& operator = (
const cl_program& rhs)
6592 const vector<Device>& devices,
6593 const char* options = NULL,
6594 void (CL_CALLBACK * notifyFptr)(cl_program,
void *) = NULL,
6595 void* data = NULL)
const
6597 size_type numDevices = devices.size();
6598 vector<cl_device_id> deviceIDs(numDevices);
6600 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6601 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6604 cl_int buildError = ::clBuildProgram(
6613 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6617 const char* options = NULL,
6618 void (CL_CALLBACK * notifyFptr)(cl_program,
void *) = NULL,
6619 void* data = NULL)
const
6621 cl_int buildError = ::clBuildProgram(
6630 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6633 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6635 const char* options = NULL,
6636 void (CL_CALLBACK * notifyFptr)(cl_program,
void *) = NULL,
6637 void* data = NULL)
const
6639 cl_int error = ::clCompileProgram(
6649 return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6651 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6653 template <
typename T>
6654 cl_int getInfo(cl_program_info name, T* param)
const
6656 return detail::errHandler(
6657 detail::getInfo(&::clGetProgramInfo, object_, name, param),
6658 __GET_PROGRAM_INFO_ERR);
6661 template <cl_program_info name>
typename
6662 detail::param_traits<detail::cl_program_info, name>::param_type
6663 getInfo(cl_int* err = NULL)
const
6665 typename detail::param_traits<
6666 detail::cl_program_info, name>::param_type param;
6667 cl_int result = getInfo(name, ¶m);
6674 template <
typename T>
6675 cl_int getBuildInfo(
6676 const Device& device, cl_program_build_info name, T* param)
const
6678 return detail::errHandler(
6680 &::clGetProgramBuildInfo, object_, device(), name, param),
6681 __GET_PROGRAM_BUILD_INFO_ERR);
6684 template <cl_program_build_info name>
typename
6685 detail::param_traits<detail::cl_program_build_info, name>::param_type
6686 getBuildInfo(
const Device& device, cl_int* err = NULL)
const
6688 typename detail::param_traits<
6689 detail::cl_program_build_info, name>::param_type param;
6690 cl_int result = getBuildInfo(device, name, ¶m);
6702 template <cl_program_build_info name>
6703 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6706 cl_int result = CL_SUCCESS;
6708 auto devs = getInfo<CL_PROGRAM_DEVICES>(&result);
6709 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6713 if (result != CL_SUCCESS) {
6722 detail::cl_program_build_info, name>::param_type param;
6723 result = getBuildInfo(d, name, ¶m);
6727 if (result != CL_SUCCESS) {
6735 if (result != CL_SUCCESS) {
6741 cl_int createKernels(vector<Kernel>* kernels)
6744 cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
6745 if (err != CL_SUCCESS) {
6746 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6749 vector<cl_kernel> value(numKernels);
6751 err = ::clCreateKernelsInProgram(
6752 object_, numKernels, value.data(), NULL);
6753 if (err != CL_SUCCESS) {
6754 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6758 kernels->resize(value.size());
6762 for (size_type i = 0; i < value.size(); i++) {
6765 (*kernels)[i] = Kernel(value[i],
false);
6771 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
6783 void (CL_CALLBACK * pfn_notify)(cl_program program,
void * user_data),
6784 void * user_data = NULL)
6786 return detail::errHandler(
6787 ::clSetProgramReleaseCallback(
6791 __SET_PROGRAM_RELEASE_CALLBACK_ERR);
6798 template <
typename T>
6799 typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6802 return detail::errHandler(
6803 ::clSetProgramSpecializationConstant(
6808 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6817 return detail::errHandler(
6818 ::clSetProgramSpecializationConstant(
6823 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6825 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
6828 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6829 inline Program linkProgram(
6832 const char* options = NULL,
6833 void (CL_CALLBACK * notifyFptr)(cl_program,
void *) = NULL,
6837 cl_int error_local = CL_SUCCESS;
6839 cl_program programs[2] = { input1(), input2() };
6841 Context ctx = input1.getInfo<CL_PROGRAM_CONTEXT>(&error_local);
6842 if(error_local!=CL_SUCCESS) {
6843 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
6846 cl_program prog = ::clLinkProgram(
6857 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
6862 return Program(prog);
6865 inline Program linkProgram(
6866 vector<Program> inputPrograms,
6867 const char* options = NULL,
6868 void (CL_CALLBACK * notifyFptr)(cl_program,
void *) = NULL,
6872 cl_int error_local = CL_SUCCESS;
6874 vector<cl_program> programs(inputPrograms.size());
6876 for (
unsigned int i = 0; i < inputPrograms.size(); i++) {
6877 programs[i] = inputPrograms[i]();
6881 if(inputPrograms.size() > 0) {
6882 ctx = inputPrograms[0].getInfo<CL_PROGRAM_CONTEXT>(&error_local);
6883 if(error_local!=CL_SUCCESS) {
6884 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
6887 cl_program prog = ::clLinkProgram(
6892 (cl_uint)inputPrograms.size(),
6898 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
6903 return Program(prog,
false);
6905 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6909 inline cl_int cl::Program::getInfo(cl_program_info name, vector<vector<unsigned char>>* param)
const
6911 if (name != CL_PROGRAM_BINARIES) {
6912 return CL_INVALID_VALUE;
6918 vector<size_type> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>();
6919 size_type numBinaries = sizes.size();
6922 param->resize(numBinaries);
6923 for (size_type i = 0; i < numBinaries; ++i) {
6924 (*param)[i].resize(sizes[i]);
6927 return detail::errHandler(
6928 detail::getInfo(&::clGetProgramInfo, object_, name, param),
6929 __GET_PROGRAM_INFO_ERR);
6936 inline vector<vector<unsigned char>> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err)
const
6938 vector<vector<unsigned char>> binariesVectors;
6940 cl_int result = getInfo(CL_PROGRAM_BINARIES, &binariesVectors);
6944 return binariesVectors;
6947 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
6952 cl_uchar ucValue = value ? CL_UCHAR_MAX : 0;
6953 return detail::errHandler(
6954 ::clSetProgramSpecializationConstant(
6959 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6961 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
6963 inline Kernel::Kernel(
const Program& program,
const char* name, cl_int* err)
6967 object_ = ::clCreateKernel(program(), name, &error);
6968 detail::errHandler(error, __CREATE_KERNEL_ERR);
6976 enum class QueueProperties : cl_command_queue_properties
6979 Profiling = CL_QUEUE_PROFILING_ENABLE,
6980 OutOfOrder = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,
6983 inline QueueProperties operator|(QueueProperties lhs, QueueProperties rhs)
6985 return static_cast<QueueProperties
>(
static_cast<cl_command_queue_properties
>(lhs) |
static_cast<cl_command_queue_properties
>(rhs));
6994 static std::once_flag default_initialized_;
6996 static cl_int default_error_;
7003 static void makeDefault()
7008 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
7015 if (error != CL_SUCCESS) {
7016 default_error_ = error;
7020 default_ =
CommandQueue(context, device, 0, &default_error_);
7023 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
7024 catch (cl::Error &e) {
7025 default_error_ = e.err();
7035 static void makeDefaultProvided(
const CommandQueue &c) {
7040 #ifdef CL_HPP_UNIT_TEST_ENABLE
7047 static void unitTestClearDefault() {
7050 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
7058 cl_command_queue_properties properties,
7064 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7066 if (error != CL_SUCCESS) {
7073 bool useWithProperties;
7075 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7078 cl_uint version = detail::getContextPlatformVersion(context());
7079 useWithProperties = (version >= 0x20000);
7081 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7082 useWithProperties =
true;
7084 useWithProperties =
false;
7087 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7088 if (useWithProperties) {
7089 cl_queue_properties queue_properties[] = {
7090 CL_QUEUE_PROPERTIES, properties, 0 };
7091 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7092 object_ = ::clCreateCommandQueueWithProperties(
7093 context(), device(), queue_properties, &error);
7096 error = CL_INVALID_QUEUE_PROPERTIES;
7099 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7104 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7105 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7106 if (!useWithProperties) {
7107 object_ = ::clCreateCommandQueue(
7108 context(), device(), properties, &error);
7110 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7115 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7124 QueueProperties properties,
7130 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7132 if (error != CL_SUCCESS) {
7139 bool useWithProperties;
7141 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7144 cl_uint version = detail::getContextPlatformVersion(context());
7145 useWithProperties = (version >= 0x20000);
7147 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7148 useWithProperties =
true;
7150 useWithProperties =
false;
7153 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7154 if (useWithProperties) {
7155 cl_queue_properties queue_properties[] = {
7156 CL_QUEUE_PROPERTIES,
static_cast<cl_queue_properties
>(properties), 0 };
7158 object_ = ::clCreateCommandQueueWithProperties(
7159 context(), device(), queue_properties, &error);
7161 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7166 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7167 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7168 if (!useWithProperties) {
7169 object_ = ::clCreateCommandQueue(
7170 context(), device(),
static_cast<cl_command_queue_properties
>(properties), &error);
7172 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7177 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7188 cl_command_queue_properties properties = 0,
7192 bool useWithProperties;
7193 vector<cl::Device> devices;
7194 error = context.
getInfo(CL_CONTEXT_DEVICES, &devices);
7196 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7198 if (error != CL_SUCCESS)
7206 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7209 cl_uint version = detail::getContextPlatformVersion(context());
7210 useWithProperties = (version >= 0x20000);
7212 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7213 useWithProperties =
true;
7215 useWithProperties =
false;
7218 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7219 if (useWithProperties) {
7220 cl_queue_properties queue_properties[] = {
7221 CL_QUEUE_PROPERTIES, properties, 0 };
7222 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7223 object_ = ::clCreateCommandQueueWithProperties(
7224 context(), devices[0](), queue_properties, &error);
7227 error = CL_INVALID_QUEUE_PROPERTIES;
7230 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7235 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7236 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7237 if (!useWithProperties) {
7238 object_ = ::clCreateCommandQueue(
7239 context(), devices[0](), properties, &error);
7241 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7246 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7255 QueueProperties properties,
7259 bool useWithProperties;
7260 vector<cl::Device> devices;
7261 error = context.
getInfo(CL_CONTEXT_DEVICES, &devices);
7263 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7265 if (error != CL_SUCCESS)
7273 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7276 cl_uint version = detail::getContextPlatformVersion(context());
7277 useWithProperties = (version >= 0x20000);
7279 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7280 useWithProperties =
true;
7282 useWithProperties =
false;
7285 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7286 if (useWithProperties) {
7287 cl_queue_properties queue_properties[] = {
7288 CL_QUEUE_PROPERTIES,
static_cast<cl_queue_properties
>(properties), 0 };
7289 object_ = ::clCreateCommandQueueWithProperties(
7290 context(), devices[0](), queue_properties, &error);
7292 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7297 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7298 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7299 if (!useWithProperties) {
7300 object_ = ::clCreateCommandQueue(
7301 context(), devices[0](),
static_cast<cl_command_queue_properties
>(properties), &error);
7303 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7308 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7318 cl_command_queue_properties properties = 0,
7322 bool useWithProperties;
7324 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7327 cl_uint version = detail::getContextPlatformVersion(context());
7328 useWithProperties = (version >= 0x20000);
7330 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7331 useWithProperties =
true;
7333 useWithProperties =
false;
7336 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7337 if (useWithProperties) {
7338 cl_queue_properties queue_properties[] = {
7339 CL_QUEUE_PROPERTIES, properties, 0 };
7340 object_ = ::clCreateCommandQueueWithProperties(
7341 context(), device(), queue_properties, &error);
7343 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7348 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7349 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7350 if (!useWithProperties) {
7351 object_ = ::clCreateCommandQueue(
7352 context(), device(), properties, &error);
7354 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7359 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7369 QueueProperties properties,
7373 bool useWithProperties;
7375 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7378 cl_uint version = detail::getContextPlatformVersion(context());
7379 useWithProperties = (version >= 0x20000);
7381 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7382 useWithProperties =
true;
7384 useWithProperties =
false;
7387 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7388 if (useWithProperties) {
7389 cl_queue_properties queue_properties[] = {
7390 CL_QUEUE_PROPERTIES,
static_cast<cl_queue_properties
>(properties), 0 };
7391 object_ = ::clCreateCommandQueueWithProperties(
7392 context(), device(), queue_properties, &error);
7394 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7399 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7400 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7401 if (!useWithProperties) {
7402 object_ = ::clCreateCommandQueue(
7403 context(), device(),
static_cast<cl_command_queue_properties
>(properties), &error);
7405 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7410 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7415 std::call_once(default_initialized_, makeDefault);
7416 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7417 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7418 #else // CL_HPP_TARGET_OPENCL_VERSION >= 200
7419 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_ERR);
7420 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7422 *err = default_error_;
7436 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_queue));
7437 detail::errHandler(default_error_);
7450 explicit CommandQueue(
const cl_command_queue& commandQueue,
bool retainObject =
false) :
7451 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
7487 template <
typename T>
7488 cl_int getInfo(cl_command_queue_info name, T* param)
const
7490 return detail::errHandler(
7492 &::clGetCommandQueueInfo, object_, name, param),
7493 __GET_COMMAND_QUEUE_INFO_ERR);
7496 template <cl_command_queue_info name>
typename
7497 detail::param_traits<detail::cl_command_queue_info, name>::param_type
7498 getInfo(cl_int* err = NULL)
const
7500 typename detail::param_traits<
7501 detail::cl_command_queue_info, name>::param_type param;
7502 cl_int result = getInfo(name, ¶m);
7509 cl_int enqueueReadBuffer(
7510 const Buffer& buffer,
7515 const vector<Event>* events = NULL,
7516 Event* event = NULL)
const
7519 cl_int err = detail::errHandler(
7520 ::clEnqueueReadBuffer(
7521 object_, buffer(), blocking, offset, size,
7523 (events != NULL) ? (cl_uint) events->size() : 0,
7524 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7525 (event != NULL) ? &tmp : NULL),
7526 __ENQUEUE_READ_BUFFER_ERR);
7528 if (event != NULL && err == CL_SUCCESS)
7534 cl_int enqueueWriteBuffer(
7535 const Buffer& buffer,
7540 const vector<Event>* events = NULL,
7541 Event* event = NULL)
const
7544 cl_int err = detail::errHandler(
7545 ::clEnqueueWriteBuffer(
7546 object_, buffer(), blocking, offset, size,
7548 (events != NULL) ? (cl_uint) events->size() : 0,
7549 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7550 (event != NULL) ? &tmp : NULL),
7551 __ENQUEUE_WRITE_BUFFER_ERR);
7553 if (event != NULL && err == CL_SUCCESS)
7559 cl_int enqueueCopyBuffer(
7562 size_type src_offset,
7563 size_type dst_offset,
7565 const vector<Event>* events = NULL,
7566 Event* event = NULL)
const
7569 cl_int err = detail::errHandler(
7570 ::clEnqueueCopyBuffer(
7571 object_, src(), dst(), src_offset, dst_offset, size,
7572 (events != NULL) ? (cl_uint) events->size() : 0,
7573 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7574 (event != NULL) ? &tmp : NULL),
7575 __ENQEUE_COPY_BUFFER_ERR);
7577 if (event != NULL && err == CL_SUCCESS)
7582 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
7583 cl_int enqueueReadBufferRect(
7584 const Buffer& buffer,
7586 const array<size_type, 3>& buffer_offset,
7587 const array<size_type, 3>& host_offset,
7588 const array<size_type, 3>& region,
7589 size_type buffer_row_pitch,
7590 size_type buffer_slice_pitch,
7591 size_type host_row_pitch,
7592 size_type host_slice_pitch,
7594 const vector<Event>* events = NULL,
7595 Event* event = NULL)
const
7598 cl_int err = detail::errHandler(
7599 ::clEnqueueReadBufferRect(
7603 buffer_offset.data(),
7611 (events != NULL) ? (cl_uint) events->size() : 0,
7612 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7613 (event != NULL) ? &tmp : NULL),
7614 __ENQUEUE_READ_BUFFER_RECT_ERR);
7616 if (event != NULL && err == CL_SUCCESS)
7622 cl_int enqueueWriteBufferRect(
7623 const Buffer& buffer,
7625 const array<size_type, 3>& buffer_offset,
7626 const array<size_type, 3>& host_offset,
7627 const array<size_type, 3>& region,
7628 size_type buffer_row_pitch,
7629 size_type buffer_slice_pitch,
7630 size_type host_row_pitch,
7631 size_type host_slice_pitch,
7633 const vector<Event>* events = NULL,
7634 Event* event = NULL)
const
7637 cl_int err = detail::errHandler(
7638 ::clEnqueueWriteBufferRect(
7642 buffer_offset.data(),
7650 (events != NULL) ? (cl_uint) events->size() : 0,
7651 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7652 (event != NULL) ? &tmp : NULL),
7653 __ENQUEUE_WRITE_BUFFER_RECT_ERR);
7655 if (event != NULL && err == CL_SUCCESS)
7661 cl_int enqueueCopyBufferRect(
7664 const array<size_type, 3>& src_origin,
7665 const array<size_type, 3>& dst_origin,
7666 const array<size_type, 3>& region,
7667 size_type src_row_pitch,
7668 size_type src_slice_pitch,
7669 size_type dst_row_pitch,
7670 size_type dst_slice_pitch,
7671 const vector<Event>* events = NULL,
7672 Event* event = NULL)
const
7675 cl_int err = detail::errHandler(
7676 ::clEnqueueCopyBufferRect(
7687 (events != NULL) ? (cl_uint) events->size() : 0,
7688 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7689 (event != NULL) ? &tmp : NULL),
7690 __ENQEUE_COPY_BUFFER_RECT_ERR);
7692 if (event != NULL && err == CL_SUCCESS)
7697 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
7698 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
7710 template<
typename PatternType>
7713 PatternType pattern,
7716 const vector<Event>* events = NULL,
7717 Event* event = NULL)
const
7720 cl_int err = detail::errHandler(
7721 ::clEnqueueFillBuffer(
7724 static_cast<void*
>(&pattern),
7725 sizeof(PatternType),
7728 (events != NULL) ? (cl_uint) events->size() : 0,
7729 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7730 (event != NULL) ? &tmp : NULL),
7731 __ENQUEUE_FILL_BUFFER_ERR);
7733 if (event != NULL && err == CL_SUCCESS)
7738 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7740 cl_int enqueueReadImage(
7743 const array<size_type, 3>& origin,
7744 const array<size_type, 3>& region,
7745 size_type row_pitch,
7746 size_type slice_pitch,
7748 const vector<Event>* events = NULL,
7749 Event* event = NULL)
const
7752 cl_int err = detail::errHandler(
7753 ::clEnqueueReadImage(
7762 (events != NULL) ? (cl_uint) events->size() : 0,
7763 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7764 (event != NULL) ? &tmp : NULL),
7765 __ENQUEUE_READ_IMAGE_ERR);
7767 if (event != NULL && err == CL_SUCCESS)
7773 cl_int enqueueWriteImage(
7776 const array<size_type, 3>& origin,
7777 const array<size_type, 3>& region,
7778 size_type row_pitch,
7779 size_type slice_pitch,
7781 const vector<Event>* events = NULL,
7782 Event* event = NULL)
const
7785 cl_int err = detail::errHandler(
7786 ::clEnqueueWriteImage(
7795 (events != NULL) ? (cl_uint) events->size() : 0,
7796 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7797 (event != NULL) ? &tmp : NULL),
7798 __ENQUEUE_WRITE_IMAGE_ERR);
7800 if (event != NULL && err == CL_SUCCESS)
7806 cl_int enqueueCopyImage(
7809 const array<size_type, 3>& src_origin,
7810 const array<size_type, 3>& dst_origin,
7811 const array<size_type, 3>& region,
7812 const vector<Event>* events = NULL,
7813 Event* event = NULL)
const
7816 cl_int err = detail::errHandler(
7817 ::clEnqueueCopyImage(
7824 (events != NULL) ? (cl_uint) events->size() : 0,
7825 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7826 (event != NULL) ? &tmp : NULL),
7827 __ENQUEUE_COPY_IMAGE_ERR);
7829 if (event != NULL && err == CL_SUCCESS)
7835 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
7845 cl_float4 fillColor,
7846 const array<size_type, 3>& origin,
7847 const array<size_type, 3>& region,
7848 const vector<Event>* events = NULL,
7849 Event* event = NULL)
const
7852 cl_int err = detail::errHandler(
7853 ::clEnqueueFillImage(
7856 static_cast<void*
>(&fillColor),
7859 (events != NULL) ? (cl_uint) events->size() : 0,
7860 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7861 (event != NULL) ? &tmp : NULL),
7862 __ENQUEUE_FILL_IMAGE_ERR);
7864 if (event != NULL && err == CL_SUCCESS)
7880 const array<size_type, 3>& origin,
7881 const array<size_type, 3>& region,
7882 const vector<Event>* events = NULL,
7883 Event* event = NULL)
const
7886 cl_int err = detail::errHandler(
7887 ::clEnqueueFillImage(
7890 static_cast<void*
>(&fillColor),
7893 (events != NULL) ? (cl_uint) events->size() : 0,
7894 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7895 (event != NULL) ? &tmp : NULL),
7896 __ENQUEUE_FILL_IMAGE_ERR);
7898 if (event != NULL && err == CL_SUCCESS)
7914 const array<size_type, 3>& origin,
7915 const array<size_type, 3>& region,
7916 const vector<Event>* events = NULL,
7917 Event* event = NULL)
const
7920 cl_int err = detail::errHandler(
7921 ::clEnqueueFillImage(
7924 static_cast<void*
>(&fillColor),
7927 (events != NULL) ? (cl_uint) events->size() : 0,
7928 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7929 (event != NULL) ? &tmp : NULL),
7930 __ENQUEUE_FILL_IMAGE_ERR);
7932 if (event != NULL && err == CL_SUCCESS)
7937 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7939 cl_int enqueueCopyImageToBuffer(
7942 const array<size_type, 3>& src_origin,
7943 const array<size_type, 3>& region,
7944 size_type dst_offset,
7945 const vector<Event>* events = NULL,
7946 Event* event = NULL)
const
7949 cl_int err = detail::errHandler(
7950 ::clEnqueueCopyImageToBuffer(
7957 (events != NULL) ? (cl_uint) events->size() : 0,
7958 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7959 (event != NULL) ? &tmp : NULL),
7960 __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
7962 if (event != NULL && err == CL_SUCCESS)
7968 cl_int enqueueCopyBufferToImage(
7971 size_type src_offset,
7972 const array<size_type, 3>& dst_origin,
7973 const array<size_type, 3>& region,
7974 const vector<Event>* events = NULL,
7975 Event* event = NULL)
const
7978 cl_int err = detail::errHandler(
7979 ::clEnqueueCopyBufferToImage(
7986 (events != NULL) ? (cl_uint) events->size() : 0,
7987 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7988 (event != NULL) ? &tmp : NULL),
7989 __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
7991 if (event != NULL && err == CL_SUCCESS)
7997 void* enqueueMapBuffer(
7998 const Buffer& buffer,
8003 const vector<Event>* events = NULL,
8004 Event* event = NULL,
8005 cl_int* err = NULL)
const
8009 void * result = ::clEnqueueMapBuffer(
8010 object_, buffer(), blocking, flags, offset, size,
8011 (events != NULL) ? (cl_uint) events->size() : 0,
8012 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8013 (event != NULL) ? &tmp : NULL,
8016 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
8020 if (event != NULL && error == CL_SUCCESS)
8026 void* enqueueMapImage(
8027 const Image& buffer,
8030 const array<size_type, 3>& origin,
8031 const array<size_type, 3>& region,
8032 size_type * row_pitch,
8033 size_type * slice_pitch,
8034 const vector<Event>* events = NULL,
8035 Event* event = NULL,
8036 cl_int* err = NULL)
const
8040 void * result = ::clEnqueueMapImage(
8041 object_, buffer(), blocking, flags,
8044 row_pitch, slice_pitch,
8045 (events != NULL) ? (cl_uint) events->size() : 0,
8046 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8047 (event != NULL) ? &tmp : NULL,
8050 detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
8054 if (event != NULL && error == CL_SUCCESS)
8059 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8064 template<
typename T>
8070 const vector<Event>* events = NULL,
8071 Event* event = NULL)
const
8074 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8075 object_, blocking, flags,
static_cast<void*
>(ptr), size,
8076 (events != NULL) ? (cl_uint)events->size() : 0,
8077 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8078 (event != NULL) ? &tmp : NULL),
8079 __ENQUEUE_MAP_BUFFER_ERR);
8081 if (event != NULL && err == CL_SUCCESS)
8092 template<
typename T,
class D>
8094 cl::pointer<T, D> &ptr,
8098 const vector<Event>* events = NULL,
8099 Event* event = NULL)
const
8102 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8103 object_, blocking, flags,
static_cast<void*
>(ptr.get()), size,
8104 (events != NULL) ? (cl_uint)events->size() : 0,
8105 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8106 (event != NULL) ? &tmp : NULL),
8107 __ENQUEUE_MAP_BUFFER_ERR);
8109 if (event != NULL && err == CL_SUCCESS)
8119 template<
typename T,
class Alloc>
8121 cl::vector<T, Alloc> &container,
8124 const vector<Event>* events = NULL,
8125 Event* event = NULL)
const
8128 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8129 object_, blocking, flags,
static_cast<void*
>(container.data()), container.size(),
8130 (events != NULL) ? (cl_uint)events->size() : 0,
8131 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8132 (event != NULL) ? &tmp : NULL),
8133 __ENQUEUE_MAP_BUFFER_ERR);
8135 if (event != NULL && err == CL_SUCCESS)
8140 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8142 cl_int enqueueUnmapMemObject(
8145 const vector<Event>* events = NULL,
8146 Event* event = NULL)
const
8149 cl_int err = detail::errHandler(
8150 ::clEnqueueUnmapMemObject(
8151 object_, memory(), mapped_ptr,
8152 (events != NULL) ? (cl_uint) events->size() : 0,
8153 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8154 (event != NULL) ? &tmp : NULL),
8155 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8157 if (event != NULL && err == CL_SUCCESS)
8164 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8169 template<
typename T>
8172 const vector<Event>* events = NULL,
8173 Event* event = NULL)
const
8176 cl_int err = detail::errHandler(
8177 ::clEnqueueSVMUnmap(
8178 object_,
static_cast<void*
>(ptr),
8179 (events != NULL) ? (cl_uint)events->size() : 0,
8180 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8181 (event != NULL) ? &tmp : NULL),
8182 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8184 if (event != NULL && err == CL_SUCCESS)
8194 template<
typename T,
class D>
8196 cl::pointer<T, D> &ptr,
8197 const vector<Event>* events = NULL,
8198 Event* event = NULL)
const
8201 cl_int err = detail::errHandler(
8202 ::clEnqueueSVMUnmap(
8203 object_,
static_cast<void*
>(ptr.get()),
8204 (events != NULL) ? (cl_uint)events->size() : 0,
8205 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8206 (event != NULL) ? &tmp : NULL),
8207 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8209 if (event != NULL && err == CL_SUCCESS)
8219 template<
typename T,
class Alloc>
8221 cl::vector<T, Alloc> &container,
8222 const vector<Event>* events = NULL,
8223 Event* event = NULL)
const
8226 cl_int err = detail::errHandler(
8227 ::clEnqueueSVMUnmap(
8228 object_,
static_cast<void*
>(container.data()),
8229 (events != NULL) ? (cl_uint)events->size() : 0,
8230 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8231 (event != NULL) ? &tmp : NULL),
8232 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8234 if (event != NULL && err == CL_SUCCESS)
8239 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8241 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8254 const vector<Event> *events = 0,
8255 Event *event = 0)
const
8258 cl_int err = detail::errHandler(
8259 ::clEnqueueMarkerWithWaitList(
8261 (events != NULL) ? (cl_uint) events->size() : 0,
8262 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8263 (event != NULL) ? &tmp : NULL),
8264 __ENQUEUE_MARKER_WAIT_LIST_ERR);
8266 if (event != NULL && err == CL_SUCCESS)
8284 const vector<Event> *events = 0,
8285 Event *event = 0)
const
8288 cl_int err = detail::errHandler(
8289 ::clEnqueueBarrierWithWaitList(
8291 (events != NULL) ? (cl_uint) events->size() : 0,
8292 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8293 (event != NULL) ? &tmp : NULL),
8294 __ENQUEUE_BARRIER_WAIT_LIST_ERR);
8296 if (event != NULL && err == CL_SUCCESS)
8307 const vector<Memory> &memObjects,
8308 cl_mem_migration_flags flags,
8309 const vector<Event>* events = NULL,
8315 vector<cl_mem> localMemObjects(memObjects.size());
8317 for(
int i = 0; i < (int)memObjects.size(); ++i ) {
8318 localMemObjects[i] = memObjects[i]();
8321 cl_int err = detail::errHandler(
8322 ::clEnqueueMigrateMemObjects(
8324 (cl_uint)memObjects.size(),
8325 localMemObjects.data(),
8327 (events != NULL) ? (cl_uint) events->size() : 0,
8328 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8329 (event != NULL) ? &tmp : NULL),
8330 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8332 if (event != NULL && err == CL_SUCCESS)
8337 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8340 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8346 template<
typename T>
8348 const cl::vector<T*> &svmRawPointers,
8349 const cl::vector<size_type> &sizes,
8350 cl_mem_migration_flags flags = 0,
8351 const vector<Event>* events = NULL,
8352 Event* event = NULL)
const
8355 cl_int err = detail::errHandler(::clEnqueueSVMMigrateMem(
8357 svmRawPointers.size(),
static_cast<void**
>(svmRawPointers.data()),
8360 (events != NULL) ? (cl_uint)events->size() : 0,
8361 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8362 (event != NULL) ? &tmp : NULL),
8363 __ENQUEUE_MIGRATE_SVM_ERR);
8365 if (event != NULL && err == CL_SUCCESS)
8375 template<
typename T>
8377 const cl::vector<T*> &svmRawPointers,
8378 cl_mem_migration_flags flags = 0,
8379 const vector<Event>* events = NULL,
8380 Event* event = NULL)
const
8382 return enqueueMigrateSVM(svmRawPointers, cl::vector<size_type>(svmRawPointers.size()), flags, events, event);
8391 template<
typename T,
class D>
8393 const cl::vector<cl::pointer<T, D>> &svmPointers,
8394 const cl::vector<size_type> &sizes,
8395 cl_mem_migration_flags flags = 0,
8396 const vector<Event>* events = NULL,
8397 Event* event = NULL)
const
8399 cl::vector<void*> svmRawPointers;
8400 svmRawPointers.reserve(svmPointers.size());
8401 for (
auto p : svmPointers) {
8402 svmRawPointers.push_back(
static_cast<void*
>(p.get()));
8413 template<
typename T,
class D>
8415 const cl::vector<cl::pointer<T, D>> &svmPointers,
8416 cl_mem_migration_flags flags = 0,
8417 const vector<Event>* events = NULL,
8418 Event* event = NULL)
const
8420 return enqueueMigrateSVM(svmPointers, cl::vector<size_type>(svmPointers.size()), flags, events, event);
8428 template<
typename T,
class Alloc>
8430 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8431 const cl::vector<size_type> &sizes,
8432 cl_mem_migration_flags flags = 0,
8433 const vector<Event>* events = NULL,
8434 Event* event = NULL)
const
8436 cl::vector<void*> svmRawPointers;
8437 svmRawPointers.reserve(svmContainers.size());
8438 for (
auto p : svmContainers) {
8439 svmRawPointers.push_back(
static_cast<void*
>(p.data()));
8449 template<
typename T,
class Alloc>
8451 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8452 cl_mem_migration_flags flags = 0,
8453 const vector<Event>* events = NULL,
8454 Event* event = NULL)
const
8456 return enqueueMigrateSVM(svmContainers, cl::vector<size_type>(svmContainers.size()), flags, events, event);
8459 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8461 cl_int enqueueNDRangeKernel(
8465 const NDRange& local = NullRange,
8466 const vector<Event>* events = NULL,
8467 Event* event = NULL)
const
8470 cl_int err = detail::errHandler(
8471 ::clEnqueueNDRangeKernel(
8472 object_, kernel(), (cl_uint) global.
dimensions(),
8473 offset.
dimensions() != 0 ? (
const size_type*) offset : NULL,
8474 (
const size_type*) global,
8475 local.dimensions() != 0 ? (
const size_type*) local : NULL,
8476 (events != NULL) ? (cl_uint) events->size() : 0,
8477 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8478 (event != NULL) ? &tmp : NULL),
8479 __ENQUEUE_NDRANGE_KERNEL_ERR);
8481 if (event != NULL && err == CL_SUCCESS)
8487 #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8488 CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_int enqueueTask(
8489 const Kernel& kernel,
8490 const vector<Event>* events = NULL,
8491 Event* event = NULL)
const CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED
8494 cl_int err = detail::errHandler(
8497 (events != NULL) ? (cl_uint) events->size() : 0,
8498 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8499 (event != NULL) ? &tmp : NULL),
8500 __ENQUEUE_TASK_ERR);
8502 if (event != NULL && err == CL_SUCCESS)
8507 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8509 cl_int enqueueNativeKernel(
8510 void (CL_CALLBACK *userFptr)(
void *),
8511 std::pair<void*, size_type> args,
8512 const vector<Memory>* mem_objects = NULL,
8513 const vector<const void*>* mem_locs = NULL,
8514 const vector<Event>* events = NULL,
8515 Event* event = NULL)
const
8517 size_type elements = 0;
8518 if (mem_objects != NULL) {
8519 elements = mem_objects->size();
8521 vector<cl_mem> mems(elements);
8522 for (
unsigned int i = 0; i < elements; i++) {
8523 mems[i] = ((*mem_objects)[i])();
8527 cl_int err = detail::errHandler(
8528 ::clEnqueueNativeKernel(
8529 object_, userFptr, args.first, args.second,
8530 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8532 (mem_locs != NULL && mem_locs->size() > 0) ? (
const void **) &mem_locs->front() : NULL,
8533 (events != NULL) ? (cl_uint) events->size() : 0,
8534 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8535 (event != NULL) ? &tmp : NULL),
8536 __ENQUEUE_NATIVE_KERNEL);
8538 if (event != NULL && err == CL_SUCCESS)
8547 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8548 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
8552 cl_int err = detail::errHandler(
8555 (event != NULL) ? &tmp : NULL),
8556 __ENQUEUE_MARKER_ERR);
8558 if (event != NULL && err == CL_SUCCESS)
8564 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
8565 cl_int enqueueWaitForEvents(
const vector<Event>& events)
const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
8567 return detail::errHandler(
8568 ::clEnqueueWaitForEvents(
8570 (cl_uint) events.size(),
8571 events.size() > 0 ? (
const cl_event*) &events.front() : NULL),
8572 __ENQUEUE_WAIT_FOR_EVENTS_ERR);
8574 #endif // defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8576 cl_int enqueueAcquireGLObjects(
8577 const vector<Memory>* mem_objects = NULL,
8578 const vector<Event>* events = NULL,
8579 Event* event = NULL)
const
8582 cl_int err = detail::errHandler(
8583 ::clEnqueueAcquireGLObjects(
8585 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8586 (mem_objects != NULL && mem_objects->size() > 0) ? (
const cl_mem *) &mem_objects->front(): NULL,
8587 (events != NULL) ? (cl_uint) events->size() : 0,
8588 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8589 (event != NULL) ? &tmp : NULL),
8590 __ENQUEUE_ACQUIRE_GL_ERR);
8592 if (event != NULL && err == CL_SUCCESS)
8598 cl_int enqueueReleaseGLObjects(
8599 const vector<Memory>* mem_objects = NULL,
8600 const vector<Event>* events = NULL,
8601 Event* event = NULL)
const
8604 cl_int err = detail::errHandler(
8605 ::clEnqueueReleaseGLObjects(
8607 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8608 (mem_objects != NULL && mem_objects->size() > 0) ? (
const cl_mem *) &mem_objects->front(): NULL,
8609 (events != NULL) ? (cl_uint) events->size() : 0,
8610 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8611 (event != NULL) ? &tmp : NULL),
8612 __ENQUEUE_RELEASE_GL_ERR);
8614 if (event != NULL && err == CL_SUCCESS)
8620 #if defined (CL_HPP_USE_DX_INTEROP)
8621 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
8622 cl_command_queue command_queue, cl_uint num_objects,
8623 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8624 const cl_event* event_wait_list, cl_event* event);
8625 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
8626 cl_command_queue command_queue, cl_uint num_objects,
8627 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8628 const cl_event* event_wait_list, cl_event* event);
8630 cl_int enqueueAcquireD3D10Objects(
8631 const vector<Memory>* mem_objects = NULL,
8632 const vector<Event>* events = NULL,
8633 Event* event = NULL)
const
8635 static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
8636 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8637 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8638 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8639 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8640 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireD3D10ObjectsKHR);
8642 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
8643 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueAcquireD3D10ObjectsKHR);
8647 cl_int err = detail::errHandler(
8648 pfn_clEnqueueAcquireD3D10ObjectsKHR(
8650 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8651 (mem_objects != NULL && mem_objects->size() > 0) ? (
const cl_mem *) &mem_objects->front(): NULL,
8652 (events != NULL) ? (cl_uint) events->size() : 0,
8653 (events != NULL) ? (cl_event*) &events->front() : NULL,
8654 (event != NULL) ? &tmp : NULL),
8655 __ENQUEUE_ACQUIRE_GL_ERR);
8657 if (event != NULL && err == CL_SUCCESS)
8663 cl_int enqueueReleaseD3D10Objects(
8664 const vector<Memory>* mem_objects = NULL,
8665 const vector<Event>* events = NULL,
8666 Event* event = NULL)
const
8668 static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL;
8669 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8670 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8671 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8672 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8673 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseD3D10ObjectsKHR);
8674 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8675 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
8676 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueReleaseD3D10ObjectsKHR);
8677 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
8680 cl_int err = detail::errHandler(
8681 pfn_clEnqueueReleaseD3D10ObjectsKHR(
8683 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8684 (mem_objects != NULL && mem_objects->size() > 0) ? (
const cl_mem *) &mem_objects->front(): NULL,
8685 (events != NULL) ? (cl_uint) events->size() : 0,
8686 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8687 (event != NULL) ? &tmp : NULL),
8688 __ENQUEUE_RELEASE_GL_ERR);
8690 if (event != NULL && err == CL_SUCCESS)
8700 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8701 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
8704 return detail::errHandler(
8705 ::clEnqueueBarrier(object_),
8706 __ENQUEUE_BARRIER_ERR);
8708 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
8710 cl_int flush()
const
8712 return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
8715 cl_int finish()
const
8717 return detail::errHandler(::clFinish(object_), __FINISH_ERR);
8721 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::default_initialized_;
8722 CL_HPP_DEFINE_STATIC_MEMBER_ CommandQueue CommandQueue::default_;
8723 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int CommandQueue::default_error_ = CL_SUCCESS;
8726 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8727 enum class DeviceQueueProperties : cl_command_queue_properties
8730 Profiling = CL_QUEUE_PROFILING_ENABLE,
8733 inline DeviceQueueProperties operator|(DeviceQueueProperties lhs, DeviceQueueProperties rhs)
8735 return static_cast<DeviceQueueProperties
>(
static_cast<cl_command_queue_properties
>(lhs) |
static_cast<cl_command_queue_properties
>(rhs));
8759 cl_command_queue_properties mergedProperties =
8760 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE |
static_cast<cl_command_queue_properties
>(properties);
8762 cl_queue_properties queue_properties[] = {
8763 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8764 object_ = ::clCreateCommandQueueWithProperties(
8765 context(), device(), queue_properties, &error);
8767 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8779 DeviceQueueProperties properties = DeviceQueueProperties::None,
8784 cl_command_queue_properties mergedProperties =
8785 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE |
static_cast<cl_command_queue_properties
>(properties);
8786 cl_queue_properties queue_properties[] = {
8787 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8788 object_ = ::clCreateCommandQueueWithProperties(
8789 context(), device(), queue_properties, &error);
8791 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8804 DeviceQueueProperties properties = DeviceQueueProperties::None,
8809 cl_command_queue_properties mergedProperties =
8810 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE |
static_cast<cl_command_queue_properties
>(properties);
8811 cl_queue_properties queue_properties[] = {
8812 CL_QUEUE_PROPERTIES, mergedProperties,
8813 CL_QUEUE_SIZE, queueSize,
8815 object_ = ::clCreateCommandQueueWithProperties(
8816 context(), device(), queue_properties, &error);
8818 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8831 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
8867 template <
typename T>
8868 cl_int getInfo(cl_command_queue_info name, T* param)
const
8870 return detail::errHandler(
8872 &::clGetCommandQueueInfo, object_, name, param),
8873 __GET_COMMAND_QUEUE_INFO_ERR);
8876 template <cl_command_queue_info name>
typename
8877 detail::param_traits<detail::cl_command_queue_info, name>::param_type
8878 getInfo(cl_int* err = NULL)
const
8880 typename detail::param_traits<
8881 detail::cl_command_queue_info, name>::param_type param;
8882 cl_int result = getInfo(name, ¶m);
8896 cl_int *err =
nullptr)
8902 cl_command_queue_properties properties =
8903 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
8904 cl_queue_properties queue_properties[] = {
8905 CL_QUEUE_PROPERTIES, properties,
8908 ::clCreateCommandQueueWithProperties(
8909 context(), device(), queue_properties, &error));
8911 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8926 const Context &context,
const Device &device, cl_int *err =
nullptr)
8930 cl_command_queue_properties properties =
8931 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
8932 cl_queue_properties queue_properties[] = {
8933 CL_QUEUE_PROPERTIES, properties,
8936 ::clCreateCommandQueueWithProperties(
8937 context(), device(), queue_properties, &error));
8939 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8954 const Context &context,
const Device &device, cl_uint queueSize, cl_int *err =
nullptr)
8958 cl_command_queue_properties properties =
8959 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
8960 cl_queue_properties queue_properties[] = {
8961 CL_QUEUE_PROPERTIES, properties,
8962 CL_QUEUE_SIZE, queueSize,
8965 ::clCreateCommandQueueWithProperties(
8966 context(), device(), queue_properties, &error));
8968 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8978 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8988 error = clSetDefaultDeviceCommandQueue(context.get(), device.get(), default_queue.get());
8990 detail::errHandler(error, __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR);
8994 return default_queue;
9002 return queue.getInfo<CL_QUEUE_DEVICE_DEFAULT>(err);
9005 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
9019 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9022 template<
typename IteratorType >
9025 IteratorType startIterator,
9026 IteratorType endIterator,
9031 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9034 cl_mem_flags flags = 0;
9036 flags |= CL_MEM_READ_ONLY;
9039 flags |= CL_MEM_READ_WRITE;
9042 flags |= CL_MEM_USE_HOST_PTR;
9045 size_type size =
sizeof(DataType)*(endIterator - startIterator);
9048 object_ = ::clCreateBuffer(context(), flags, size,
static_cast<DataType*
>(&*startIterator), &error);
9050 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9053 detail::errHandler(error, __CREATE_BUFFER_ERR);
9060 detail::errHandler(error, __CREATE_BUFFER_ERR);
9065 error =
cl::copy(queue, startIterator, endIterator, *
this);
9066 detail::errHandler(error, __CREATE_BUFFER_ERR);
9073 template<
typename IteratorType >
9076 IteratorType startIterator,
9077 IteratorType endIterator,
9082 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9085 cl_mem_flags flags = 0;
9087 flags |= CL_MEM_READ_ONLY;
9090 flags |= CL_MEM_READ_WRITE;
9093 flags |= CL_MEM_USE_HOST_PTR;
9096 size_type size =
sizeof(DataType)*(endIterator - startIterator);
9098 Context context = queue.getInfo<CL_QUEUE_CONTEXT>();
9101 object_ = ::clCreateBuffer(context(), flags, size,
static_cast<DataType*
>(&*startIterator), &error);
9104 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9107 detail::errHandler(error, __CREATE_BUFFER_ERR);
9113 error =
cl::copy(queue, startIterator, endIterator, *
this);
9114 detail::errHandler(error, __CREATE_BUFFER_ERR);
9121 inline cl_int enqueueReadBuffer(
9127 const vector<Event>* events = NULL,
9128 Event* event = NULL)
9133 if (error != CL_SUCCESS) {
9137 return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event);
9140 inline cl_int enqueueWriteBuffer(
9141 const Buffer& buffer,
9146 const vector<Event>* events = NULL,
9147 Event* event = NULL)
9150 CommandQueue queue = CommandQueue::getDefault(&error);
9152 if (error != CL_SUCCESS) {
9156 return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event);
9159 inline void* enqueueMapBuffer(
9160 const Buffer& buffer,
9165 const vector<Event>* events = NULL,
9166 Event* event = NULL,
9170 CommandQueue queue = CommandQueue::getDefault(&error);
9171 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9176 void * result = ::clEnqueueMapBuffer(
9177 queue(), buffer(), blocking, flags, offset, size,
9178 (events != NULL) ? (cl_uint) events->size() : 0,
9179 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
9183 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9191 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9197 template<
typename T>
9203 const vector<Event>* events,
9208 if (error != CL_SUCCESS) {
9209 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9213 ptr, blocking, flags, size, events, event);
9221 template<
typename T,
class D>
9223 cl::pointer<T, D> ptr,
9227 const vector<Event>* events = NULL,
9228 Event* event = NULL)
9232 if (error != CL_SUCCESS) {
9233 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9237 ptr, blocking, flags, size, events, event);
9245 template<
typename T,
class Alloc>
9247 cl::vector<T, Alloc> container,
9250 const vector<Event>* events = NULL,
9251 Event* event = NULL)
9255 if (error != CL_SUCCESS) {
9256 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9260 container, blocking, flags, events, event);
9263 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9265 inline cl_int enqueueUnmapMemObject(
9266 const Memory& memory,
9268 const vector<Event>* events = NULL,
9269 Event* event = NULL)
9272 CommandQueue queue = CommandQueue::getDefault(&error);
9273 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9274 if (error != CL_SUCCESS) {
9279 cl_int err = detail::errHandler(
9280 ::clEnqueueUnmapMemObject(
9281 queue(), memory(), mapped_ptr,
9282 (events != NULL) ? (cl_uint)events->size() : 0,
9283 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
9284 (event != NULL) ? &tmp : NULL),
9285 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9287 if (event != NULL && err == CL_SUCCESS)
9293 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9299 template<
typename T>
9302 const vector<Event>* events = NULL,
9303 Event* event = NULL)
9307 if (error != CL_SUCCESS) {
9308 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9312 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9321 template<
typename T,
class D>
9323 cl::pointer<T, D> &ptr,
9324 const vector<Event>* events = NULL,
9325 Event* event = NULL)
9329 if (error != CL_SUCCESS) {
9330 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9334 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9342 template<
typename T,
class Alloc>
9344 cl::vector<T, Alloc> &container,
9345 const vector<Event>* events = NULL,
9346 Event* event = NULL)
9350 if (error != CL_SUCCESS) {
9351 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9354 return detail::errHandler(queue.
enqueueUnmapSVM(container, events, event),
9355 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9358 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9360 inline cl_int enqueueCopyBuffer(
9363 size_type src_offset,
9364 size_type dst_offset,
9366 const vector<Event>* events = NULL,
9367 Event* event = NULL)
9370 CommandQueue queue = CommandQueue::getDefault(&error);
9372 if (error != CL_SUCCESS) {
9376 return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event);
9384 template<
typename IteratorType >
9385 inline cl_int
copy( IteratorType startIterator, IteratorType endIterator,
cl::Buffer &buffer )
9389 if (error != CL_SUCCESS)
9392 return cl::copy(queue, startIterator, endIterator, buffer);
9400 template<
typename IteratorType >
9401 inline cl_int
copy(
const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
9405 if (error != CL_SUCCESS)
9408 return cl::copy(queue, buffer, startIterator, endIterator);
9416 template<
typename IteratorType >
9419 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9422 size_type length = endIterator-startIterator;
9423 size_type byteLength = length*
sizeof(DataType);
9426 static_cast<DataType*
>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error));
9428 if( error != CL_SUCCESS ) {
9431 #if defined(_MSC_VER)
9435 stdext::checked_array_iterator<DataType*>(
9438 std::copy(startIterator, endIterator, pointer);
9441 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9443 if( error != CL_SUCCESS ) {
9455 template<
typename IteratorType >
9458 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9461 size_type length = endIterator-startIterator;
9462 size_type byteLength = length*
sizeof(DataType);
9465 static_cast<DataType*
>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error));
9467 if( error != CL_SUCCESS ) {
9470 std::copy(pointer, pointer + length, startIterator);
9472 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9474 if( error != CL_SUCCESS ) {
9482 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9486 template<
typename T,
class Alloc>
9487 inline cl_int
mapSVM(cl::vector<T, Alloc> &container)
9489 return enqueueMapSVM(container, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE);
9495 template<
typename T,
class Alloc>
9496 inline cl_int
unmapSVM(cl::vector<T, Alloc> &container)
9501 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9503 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
9504 inline cl_int enqueueReadBufferRect(
9505 const Buffer& buffer,
9507 const array<size_type, 3>& buffer_offset,
9508 const array<size_type, 3>& host_offset,
9509 const array<size_type, 3>& region,
9510 size_type buffer_row_pitch,
9511 size_type buffer_slice_pitch,
9512 size_type host_row_pitch,
9513 size_type host_slice_pitch,
9515 const vector<Event>* events = NULL,
9516 Event* event = NULL)
9519 CommandQueue queue = CommandQueue::getDefault(&error);
9521 if (error != CL_SUCCESS) {
9525 return queue.enqueueReadBufferRect(
9540 inline cl_int enqueueWriteBufferRect(
9541 const Buffer& buffer,
9543 const array<size_type, 3>& buffer_offset,
9544 const array<size_type, 3>& host_offset,
9545 const array<size_type, 3>& region,
9546 size_type buffer_row_pitch,
9547 size_type buffer_slice_pitch,
9548 size_type host_row_pitch,
9549 size_type host_slice_pitch,
9551 const vector<Event>* events = NULL,
9552 Event* event = NULL)
9555 CommandQueue queue = CommandQueue::getDefault(&error);
9557 if (error != CL_SUCCESS) {
9561 return queue.enqueueWriteBufferRect(
9576 inline cl_int enqueueCopyBufferRect(
9579 const array<size_type, 3>& src_origin,
9580 const array<size_type, 3>& dst_origin,
9581 const array<size_type, 3>& region,
9582 size_type src_row_pitch,
9583 size_type src_slice_pitch,
9584 size_type dst_row_pitch,
9585 size_type dst_slice_pitch,
9586 const vector<Event>* events = NULL,
9587 Event* event = NULL)
9590 CommandQueue queue = CommandQueue::getDefault(&error);
9592 if (error != CL_SUCCESS) {
9596 return queue.enqueueCopyBufferRect(
9609 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
9611 inline cl_int enqueueReadImage(
9614 const array<size_type, 3>& origin,
9615 const array<size_type, 3>& region,
9616 size_type row_pitch,
9617 size_type slice_pitch,
9619 const vector<Event>* events = NULL,
9620 Event* event = NULL)
9623 CommandQueue queue = CommandQueue::getDefault(&error);
9625 if (error != CL_SUCCESS) {
9629 return queue.enqueueReadImage(
9641 inline cl_int enqueueWriteImage(
9644 const array<size_type, 3>& origin,
9645 const array<size_type, 3>& region,
9646 size_type row_pitch,
9647 size_type slice_pitch,
9649 const vector<Event>* events = NULL,
9650 Event* event = NULL)
9653 CommandQueue queue = CommandQueue::getDefault(&error);
9655 if (error != CL_SUCCESS) {
9659 return queue.enqueueWriteImage(
9671 inline cl_int enqueueCopyImage(
9674 const array<size_type, 3>& src_origin,
9675 const array<size_type, 3>& dst_origin,
9676 const array<size_type, 3>& region,
9677 const vector<Event>* events = NULL,
9678 Event* event = NULL)
9681 CommandQueue queue = CommandQueue::getDefault(&error);
9683 if (error != CL_SUCCESS) {
9687 return queue.enqueueCopyImage(
9697 inline cl_int enqueueCopyImageToBuffer(
9700 const array<size_type, 3>& src_origin,
9701 const array<size_type, 3>& region,
9702 size_type dst_offset,
9703 const vector<Event>* events = NULL,
9704 Event* event = NULL)
9707 CommandQueue queue = CommandQueue::getDefault(&error);
9709 if (error != CL_SUCCESS) {
9713 return queue.enqueueCopyImageToBuffer(
9723 inline cl_int enqueueCopyBufferToImage(
9726 size_type src_offset,
9727 const array<size_type, 3>& dst_origin,
9728 const array<size_type, 3>& region,
9729 const vector<Event>* events = NULL,
9730 Event* event = NULL)
9733 CommandQueue queue = CommandQueue::getDefault(&error);
9735 if (error != CL_SUCCESS) {
9739 return queue.enqueueCopyBufferToImage(
9750 inline cl_int flush(
void)
9753 CommandQueue queue = CommandQueue::getDefault(&error);
9755 if (error != CL_SUCCESS) {
9759 return queue.flush();
9762 inline cl_int finish(
void)
9765 CommandQueue queue = CommandQueue::getDefault(&error);
9767 if (error != CL_SUCCESS) {
9772 return queue.finish();
9782 vector<Event> events_;
9784 template<
typename... Ts>
9789 queue_(CommandQueue::getDefault()),
9798 queue_(CommandQueue::getDefault()),
9807 queue_(CommandQueue::getDefault()),
9816 queue_(CommandQueue::getDefault()),
9821 events_.push_back(e);
9825 queue_(CommandQueue::getDefault()),
9830 events_.push_back(e);
9834 queue_(CommandQueue::getDefault()),
9839 events_.push_back(e);
9843 queue_(CommandQueue::getDefault()),
9853 queue_(CommandQueue::getDefault()),
9863 queue_(CommandQueue::getDefault()),
9905 events_.push_back(e);
9914 events_.push_back(e);
9923 events_.push_back(e);
9965 template<
typename... Ts>
9971 template<
int index,
typename T0,
typename... T1s>
9972 void setArgs(T0&& t0, T1s&&... t1s)
9974 kernel_.
setArg(index, t0);
9975 setArgs<index + 1, T1s...>(std::forward<T1s>(t1s)...);
9978 template<
int index,
typename T0>
9979 void setArgs(T0&& t0)
9981 kernel_.
setArg(index, t0);
9997 cl_int * err = NULL) :
9998 kernel_(program, name.c_str(), err)
10014 setArgs<0>(std::forward<Ts>(ts)...);
10016 args.queue_.enqueueNDRangeKernel(
10039 setArgs<0>(std::forward<Ts>(ts)...);
10041 error = args.queue_.enqueueNDRangeKernel(
10052 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10053 cl_int setSVMPointers(
const vector<void*> &pointerList)
10058 template<
typename T0,
typename... T1s>
10059 cl_int setSVMPointers(
const T0 &t0, T1s &... ts)
10063 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10071 namespace compatibility {
10076 template<
typename... Ts>
10086 cl_int * err = NULL) :
10108 enqueueArgs, args...);
10116 #undef CL_HPP_ERR_STR_
10117 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
10118 #undef __GET_DEVICE_INFO_ERR
10119 #undef __GET_PLATFORM_INFO_ERR
10120 #undef __GET_DEVICE_IDS_ERR
10121 #undef __GET_PLATFORM_IDS_ERR
10122 #undef __GET_CONTEXT_INFO_ERR
10123 #undef __GET_EVENT_INFO_ERR
10124 #undef __GET_EVENT_PROFILE_INFO_ERR
10125 #undef __GET_MEM_OBJECT_INFO_ERR
10126 #undef __GET_IMAGE_INFO_ERR
10127 #undef __GET_SAMPLER_INFO_ERR
10128 #undef __GET_KERNEL_INFO_ERR
10129 #undef __GET_KERNEL_ARG_INFO_ERR
10130 #undef __GET_KERNEL_SUB_GROUP_INFO_ERR
10131 #undef __GET_KERNEL_WORK_GROUP_INFO_ERR
10132 #undef __GET_PROGRAM_INFO_ERR
10133 #undef __GET_PROGRAM_BUILD_INFO_ERR
10134 #undef __GET_COMMAND_QUEUE_INFO_ERR
10135 #undef __CREATE_CONTEXT_ERR
10136 #undef __CREATE_CONTEXT_FROM_TYPE_ERR
10137 #undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
10138 #undef __CREATE_BUFFER_ERR
10140 #undef __CREATE_SUBBUFFER_ERR
10141 #undef __CREATE_GL_BUFFER_ERR
10142 #undef __CREATE_GL_RENDER_BUFFER_ERR
10143 #undef __GET_GL_OBJECT_INFO_ERR
10144 #undef __CREATE_IMAGE_ERR
10145 #undef __CREATE_GL_TEXTURE_ERR
10146 #undef __IMAGE_DIMENSION_ERR
10147 #undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
10148 #undef __CREATE_USER_EVENT_ERR
10149 #undef __SET_USER_EVENT_STATUS_ERR
10150 #undef __SET_EVENT_CALLBACK_ERR
10151 #undef __WAIT_FOR_EVENTS_ERR
10152 #undef __CREATE_KERNEL_ERR
10153 #undef __SET_KERNEL_ARGS_ERR
10154 #undef __CREATE_PROGRAM_WITH_SOURCE_ERR
10155 #undef __CREATE_PROGRAM_WITH_IL_ERR
10156 #undef __CREATE_PROGRAM_WITH_BINARY_ERR
10157 #undef __CREATE_PROGRAM_WITH_IL_ERR
10158 #undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR
10159 #undef __BUILD_PROGRAM_ERR
10160 #undef __COMPILE_PROGRAM_ERR
10161 #undef __LINK_PROGRAM_ERR
10162 #undef __CREATE_KERNELS_IN_PROGRAM_ERR
10163 #undef __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR
10164 #undef __CREATE_SAMPLER_WITH_PROPERTIES_ERR
10165 #undef __SET_COMMAND_QUEUE_PROPERTY_ERR
10166 #undef __ENQUEUE_READ_BUFFER_ERR
10167 #undef __ENQUEUE_READ_BUFFER_RECT_ERR
10168 #undef __ENQUEUE_WRITE_BUFFER_ERR
10169 #undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
10170 #undef __ENQEUE_COPY_BUFFER_ERR
10171 #undef __ENQEUE_COPY_BUFFER_RECT_ERR
10172 #undef __ENQUEUE_FILL_BUFFER_ERR
10173 #undef __ENQUEUE_READ_IMAGE_ERR
10174 #undef __ENQUEUE_WRITE_IMAGE_ERR
10175 #undef __ENQUEUE_COPY_IMAGE_ERR
10176 #undef __ENQUEUE_FILL_IMAGE_ERR
10177 #undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
10178 #undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
10179 #undef __ENQUEUE_MAP_BUFFER_ERR
10180 #undef __ENQUEUE_MAP_IMAGE_ERR
10181 #undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
10182 #undef __ENQUEUE_NDRANGE_KERNEL_ERR
10183 #undef __ENQUEUE_NATIVE_KERNEL
10184 #undef __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR
10185 #undef __ENQUEUE_MIGRATE_SVM_ERR
10186 #undef __ENQUEUE_ACQUIRE_GL_ERR
10187 #undef __ENQUEUE_RELEASE_GL_ERR
10188 #undef __CREATE_PIPE_ERR
10189 #undef __GET_PIPE_INFO_ERR
10190 #undef __RETAIN_ERR
10191 #undef __RELEASE_ERR
10193 #undef __FINISH_ERR
10194 #undef __VECTOR_CAPACITY_ERR
10195 #undef __CREATE_SUB_DEVICES_ERR
10196 #undef __CREATE_SUB_DEVICES_ERR
10197 #undef __ENQUEUE_MARKER_ERR
10198 #undef __ENQUEUE_WAIT_FOR_EVENTS_ERR
10199 #undef __ENQUEUE_BARRIER_ERR
10200 #undef __UNLOAD_COMPILER_ERR
10201 #undef __CREATE_GL_TEXTURE_2D_ERR
10202 #undef __CREATE_GL_TEXTURE_3D_ERR
10203 #undef __CREATE_IMAGE2D_ERR
10204 #undef __CREATE_IMAGE3D_ERR
10205 #undef __CREATE_COMMAND_QUEUE_ERR
10206 #undef __ENQUEUE_TASK_ERR
10207 #undef __CREATE_SAMPLER_ERR
10208 #undef __ENQUEUE_MARKER_WAIT_LIST_ERR
10209 #undef __ENQUEUE_BARRIER_WAIT_LIST_ERR
10210 #undef __CLONE_KERNEL_ERR
10211 #undef __GET_HOST_TIMER_ERR
10212 #undef __GET_DEVICE_AND_HOST_TIMER_ERR
10214 #endif //CL_HPP_USER_OVERRIDE_ERROR_STRINGS
10217 #undef CL_HPP_INIT_CL_EXT_FCN_PTR_
10218 #undef CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_
10220 #if defined(CL_HPP_USE_CL_DEVICE_FISSION)
10221 #undef CL_HPP_PARAM_NAME_DEVICE_FISSION_
10222 #endif // CL_HPP_USE_CL_DEVICE_FISSION
10224 #undef CL_HPP_NOEXCEPT_
10225 #undef CL_HPP_DEFINE_STATIC_MEMBER_