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 # pragma message("cl2.hpp: CL_HPP_TARGET_OPENCL_VERSION is not a valid value (100, 110, 120, 200, 210 or 220). It will be set to 220")
448 # undef CL_HPP_TARGET_OPENCL_VERSION
449 # define CL_HPP_TARGET_OPENCL_VERSION 220
453 #if defined(CL_TARGET_OPENCL_VERSION)
456 #if CL_TARGET_OPENCL_VERSION < CL_HPP_TARGET_OPENCL_VERSION
457 # pragma message("CL_TARGET_OPENCL_VERSION is already defined as is lower than CL_HPP_TARGET_OPENCL_VERSION")
460 # define CL_TARGET_OPENCL_VERSION CL_HPP_TARGET_OPENCL_VERSION
463 #if !defined(CL_HPP_MINIMUM_OPENCL_VERSION)
464 # define CL_HPP_MINIMUM_OPENCL_VERSION 200
466 #if CL_HPP_MINIMUM_OPENCL_VERSION != 100 && \
467 CL_HPP_MINIMUM_OPENCL_VERSION != 110 && \
468 CL_HPP_MINIMUM_OPENCL_VERSION != 120 && \
469 CL_HPP_MINIMUM_OPENCL_VERSION != 200 && \
470 CL_HPP_MINIMUM_OPENCL_VERSION != 210 && \
471 CL_HPP_MINIMUM_OPENCL_VERSION != 220
472 # pragma message("cl2.hpp: CL_HPP_MINIMUM_OPENCL_VERSION is not a valid value (100, 110, 120, 200, 210 or 220). It will be set to 100")
473 # undef CL_HPP_MINIMUM_OPENCL_VERSION
474 # define CL_HPP_MINIMUM_OPENCL_VERSION 100
476 #if CL_HPP_MINIMUM_OPENCL_VERSION > CL_HPP_TARGET_OPENCL_VERSION
477 # error "CL_HPP_MINIMUM_OPENCL_VERSION must not be greater than CL_HPP_TARGET_OPENCL_VERSION"
480 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 100 && !defined(CL_USE_DEPRECATED_OPENCL_1_0_APIS)
481 # define CL_USE_DEPRECATED_OPENCL_1_0_APIS
483 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 110 && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
484 # define CL_USE_DEPRECATED_OPENCL_1_1_APIS
486 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 120 && !defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
487 # define CL_USE_DEPRECATED_OPENCL_1_2_APIS
489 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 200 && !defined(CL_USE_DEPRECATED_OPENCL_2_0_APIS)
490 # define CL_USE_DEPRECATED_OPENCL_2_0_APIS
492 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 210 && !defined(CL_USE_DEPRECATED_OPENCL_2_1_APIS)
493 # define CL_USE_DEPRECATED_OPENCL_2_1_APIS
495 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 220 && !defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
496 # define CL_USE_DEPRECATED_OPENCL_2_2_APIS
503 #if defined(CL_HPP_USE_DX_INTEROP)
504 #include <CL/cl_d3d10.h>
505 #include <CL/cl_dx9_media_sharing.h>
509 #if defined(_MSC_VER)
517 #if (!defined(_MSC_VER) && __cplusplus < 201103L) || (defined(_MSC_VER) && _MSC_VER < 1700)
518 #error Visual studio 2013 or another C++11-supporting compiler required
522 #if defined(CL_HPP_USE_CL_DEVICE_FISSION) || defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)
523 #include <CL/cl_ext.h>
526 #if defined(__APPLE__) || defined(__MACOSX)
527 #include <OpenCL/opencl.h>
529 #include <CL/opencl.h>
532 #if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L )
533 #define CL_HPP_NOEXCEPT_ noexcept
535 #define CL_HPP_NOEXCEPT_
538 #if __cplusplus >= 201703L
539 # define CL_HPP_DEFINE_STATIC_MEMBER_ inline
540 #elif defined(_MSC_VER)
541 # define CL_HPP_DEFINE_STATIC_MEMBER_ __declspec(selectany)
542 #elif defined(__MINGW32__)
543 # define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((selectany))
545 # define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((weak))
550 #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
551 #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
552 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
553 #if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED)
554 #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
555 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
557 #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED)
558 #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED
559 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED)
560 #if !defined(CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED)
561 #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED
562 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED)
564 #if !defined(CL_CALLBACK)
573 #include <functional>
577 #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
579 using size_type = ::size_t;
581 #else // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
583 using size_type = size_t;
585 #endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
588 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
590 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
592 #if !defined(CL_HPP_NO_STD_VECTOR)
595 template <
class T,
class Alloc = std::allocator<T> >
596 using vector = std::vector<T, Alloc>;
598 #endif // #if !defined(CL_HPP_NO_STD_VECTOR)
600 #if !defined(CL_HPP_NO_STD_STRING)
603 using string = std::string;
605 #endif // #if !defined(CL_HPP_NO_STD_STRING)
607 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
609 #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
614 template<
class T,
class D>
615 using pointer = std::unique_ptr<T, D>;
618 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
619 #if !defined(CL_HPP_NO_STD_ARRAY)
622 template <
class T,
size_type N >
623 using array = std::array<T, N>;
625 #endif // #if !defined(CL_HPP_NO_STD_ARRAY)
629 #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
631 namespace compatibility {
646 for (
int i = 0; i < N; ++i) {
651 size_t(
const array<size_type, N> &rhs)
653 for (
int i = 0; i < N; ++i) {
658 size_type& operator[](
int index)
663 const size_type& operator[](
int index)
const
669 operator size_type* () {
return data_; }
672 operator const size_type* ()
const {
return data_; }
674 operator array<size_type, N>()
const
676 array<size_type, N> ret;
678 for (
int i = 0; i < N; ++i) {
687 using size_t = compatibility::size_t<N>;
689 #endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
694 using size_t_array = array<size_type, 3>;
707 #define CL_HPP_INIT_CL_EXT_FCN_PTR_(name) \
709 pfn_##name = (PFN_##name) \
710 clGetExtensionFunctionAddress(#name); \
715 #define CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, name) \
717 pfn_##name = (PFN_##name) \
718 clGetExtensionFunctionAddressForPlatform(platform, #name); \
727 class DeviceCommandQueue;
732 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
737 class Error :
public std::exception
741 const char * errStr_;
752 Error(cl_int err,
const char * errStr = NULL) : err_(err), errStr_(errStr)
761 virtual const char * what()
const throw ()
763 if (errStr_ == NULL) {
775 cl_int err(
void)
const {
return err_; }
777 #define CL_HPP_ERR_STR_(x) #x
779 #define CL_HPP_ERR_STR_(x) NULL
780 #endif // CL_HPP_ENABLE_EXCEPTIONS
785 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
786 static inline cl_int errHandler (
788 const char * errStr = NULL)
790 if (err != CL_SUCCESS) {
791 throw Error(err, errStr);
796 static inline cl_int errHandler (cl_int err,
const char * errStr = NULL)
801 #endif // CL_HPP_ENABLE_EXCEPTIONS
807 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
808 #define __GET_DEVICE_INFO_ERR CL_HPP_ERR_STR_(clGetDeviceInfo)
809 #define __GET_PLATFORM_INFO_ERR CL_HPP_ERR_STR_(clGetPlatformInfo)
810 #define __GET_DEVICE_IDS_ERR CL_HPP_ERR_STR_(clGetDeviceIDs)
811 #define __GET_PLATFORM_IDS_ERR CL_HPP_ERR_STR_(clGetPlatformIDs)
812 #define __GET_CONTEXT_INFO_ERR CL_HPP_ERR_STR_(clGetContextInfo)
813 #define __GET_EVENT_INFO_ERR CL_HPP_ERR_STR_(clGetEventInfo)
814 #define __GET_EVENT_PROFILE_INFO_ERR CL_HPP_ERR_STR_(clGetEventProfileInfo)
815 #define __GET_MEM_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetMemObjectInfo)
816 #define __GET_IMAGE_INFO_ERR CL_HPP_ERR_STR_(clGetImageInfo)
817 #define __GET_SAMPLER_INFO_ERR CL_HPP_ERR_STR_(clGetSamplerInfo)
818 #define __GET_KERNEL_INFO_ERR CL_HPP_ERR_STR_(clGetKernelInfo)
819 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
820 #define __GET_KERNEL_ARG_INFO_ERR CL_HPP_ERR_STR_(clGetKernelArgInfo)
821 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
822 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
823 #define __GET_KERNEL_SUB_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelSubGroupInfo)
824 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
825 #define __GET_KERNEL_WORK_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelWorkGroupInfo)
826 #define __GET_PROGRAM_INFO_ERR CL_HPP_ERR_STR_(clGetProgramInfo)
827 #define __GET_PROGRAM_BUILD_INFO_ERR CL_HPP_ERR_STR_(clGetProgramBuildInfo)
828 #define __GET_COMMAND_QUEUE_INFO_ERR CL_HPP_ERR_STR_(clGetCommandQueueInfo)
830 #define __CREATE_CONTEXT_ERR CL_HPP_ERR_STR_(clCreateContext)
831 #define __CREATE_CONTEXT_FROM_TYPE_ERR CL_HPP_ERR_STR_(clCreateContextFromType)
832 #define __GET_SUPPORTED_IMAGE_FORMATS_ERR CL_HPP_ERR_STR_(clGetSupportedImageFormats)
834 #define __CREATE_BUFFER_ERR CL_HPP_ERR_STR_(clCreateBuffer)
835 #define __COPY_ERR CL_HPP_ERR_STR_(cl::copy)
836 #define __CREATE_SUBBUFFER_ERR CL_HPP_ERR_STR_(clCreateSubBuffer)
837 #define __CREATE_GL_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
838 #define __CREATE_GL_RENDER_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
839 #define __GET_GL_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetGLObjectInfo)
840 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
841 #define __CREATE_IMAGE_ERR CL_HPP_ERR_STR_(clCreateImage)
842 #define __CREATE_GL_TEXTURE_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture)
843 #define __IMAGE_DIMENSION_ERR CL_HPP_ERR_STR_(Incorrect image dimensions)
844 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
845 #define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR CL_HPP_ERR_STR_(clSetMemObjectDestructorCallback)
847 #define __CREATE_USER_EVENT_ERR CL_HPP_ERR_STR_(clCreateUserEvent)
848 #define __SET_USER_EVENT_STATUS_ERR CL_HPP_ERR_STR_(clSetUserEventStatus)
849 #define __SET_EVENT_CALLBACK_ERR CL_HPP_ERR_STR_(clSetEventCallback)
850 #define __WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clWaitForEvents)
852 #define __CREATE_KERNEL_ERR CL_HPP_ERR_STR_(clCreateKernel)
853 #define __SET_KERNEL_ARGS_ERR CL_HPP_ERR_STR_(clSetKernelArg)
854 #define __CREATE_PROGRAM_WITH_SOURCE_ERR CL_HPP_ERR_STR_(clCreateProgramWithSource)
855 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
856 #define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
857 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
858 #define __CREATE_PROGRAM_WITH_BINARY_ERR CL_HPP_ERR_STR_(clCreateProgramWithBinary)
859 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
860 #define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
861 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
862 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
863 #define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR CL_HPP_ERR_STR_(clCreateProgramWithBuiltInKernels)
864 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
865 #define __BUILD_PROGRAM_ERR CL_HPP_ERR_STR_(clBuildProgram)
866 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
867 #define __COMPILE_PROGRAM_ERR CL_HPP_ERR_STR_(clCompileProgram)
868 #define __LINK_PROGRAM_ERR CL_HPP_ERR_STR_(clLinkProgram)
869 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
870 #define __CREATE_KERNELS_IN_PROGRAM_ERR CL_HPP_ERR_STR_(clCreateKernelsInProgram)
872 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
873 #define __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateCommandQueueWithProperties)
874 #define __CREATE_SAMPLER_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateSamplerWithProperties)
875 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
876 #define __SET_COMMAND_QUEUE_PROPERTY_ERR CL_HPP_ERR_STR_(clSetCommandQueueProperty)
877 #define __ENQUEUE_READ_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueReadBuffer)
878 #define __ENQUEUE_READ_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueReadBufferRect)
879 #define __ENQUEUE_WRITE_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueWriteBuffer)
880 #define __ENQUEUE_WRITE_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueWriteBufferRect)
881 #define __ENQEUE_COPY_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyBuffer)
882 #define __ENQEUE_COPY_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferRect)
883 #define __ENQUEUE_FILL_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueFillBuffer)
884 #define __ENQUEUE_READ_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueReadImage)
885 #define __ENQUEUE_WRITE_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueWriteImage)
886 #define __ENQUEUE_COPY_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyImage)
887 #define __ENQUEUE_FILL_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueFillImage)
888 #define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyImageToBuffer)
889 #define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferToImage)
890 #define __ENQUEUE_MAP_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueMapBuffer)
891 #define __ENQUEUE_MAP_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueMapImage)
892 #define __ENQUEUE_UNMAP_MEM_OBJECT_ERR CL_HPP_ERR_STR_(clEnqueueUnMapMemObject)
893 #define __ENQUEUE_NDRANGE_KERNEL_ERR CL_HPP_ERR_STR_(clEnqueueNDRangeKernel)
894 #define __ENQUEUE_NATIVE_KERNEL CL_HPP_ERR_STR_(clEnqueueNativeKernel)
895 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
896 #define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR CL_HPP_ERR_STR_(clEnqueueMigrateMemObjects)
897 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
898 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
899 #define __ENQUEUE_MIGRATE_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMMigrateMem)
900 #define __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clSetDefaultDeviceCommandQueue)
901 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
904 #define __ENQUEUE_ACQUIRE_GL_ERR CL_HPP_ERR_STR_(clEnqueueAcquireGLObjects)
905 #define __ENQUEUE_RELEASE_GL_ERR CL_HPP_ERR_STR_(clEnqueueReleaseGLObjects)
907 #define __CREATE_PIPE_ERR CL_HPP_ERR_STR_(clCreatePipe)
908 #define __GET_PIPE_INFO_ERR CL_HPP_ERR_STR_(clGetPipeInfo)
911 #define __RETAIN_ERR CL_HPP_ERR_STR_(Retain Object)
912 #define __RELEASE_ERR CL_HPP_ERR_STR_(Release Object)
913 #define __FLUSH_ERR CL_HPP_ERR_STR_(clFlush)
914 #define __FINISH_ERR CL_HPP_ERR_STR_(clFinish)
915 #define __VECTOR_CAPACITY_ERR CL_HPP_ERR_STR_(Vector capacity error)
917 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
918 #define __GET_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetHostTimer)
919 #define __GET_DEVICE_AND_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetDeviceAndHostTimer)
921 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
922 #define __SET_PROGRAM_RELEASE_CALLBACK_ERR CL_HPP_ERR_STR_(clSetProgramReleaseCallback)
923 #define __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR CL_HPP_ERR_STR_(clSetProgramSpecializationConstant)
930 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
931 #define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevices)
933 #define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevicesEXT)
934 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
939 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
940 #define __ENQUEUE_MARKER_ERR CL_HPP_ERR_STR_(clEnqueueMarker)
941 #define __ENQUEUE_WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clEnqueueWaitForEvents)
942 #define __ENQUEUE_BARRIER_ERR CL_HPP_ERR_STR_(clEnqueueBarrier)
943 #define __UNLOAD_COMPILER_ERR CL_HPP_ERR_STR_(clUnloadCompiler)
944 #define __CREATE_GL_TEXTURE_2D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture2D)
945 #define __CREATE_GL_TEXTURE_3D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture3D)
946 #define __CREATE_IMAGE2D_ERR CL_HPP_ERR_STR_(clCreateImage2D)
947 #define __CREATE_IMAGE3D_ERR CL_HPP_ERR_STR_(clCreateImage3D)
948 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
953 #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
954 #define __CREATE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clCreateCommandQueue)
955 #define __ENQUEUE_TASK_ERR CL_HPP_ERR_STR_(clEnqueueTask)
956 #define __CREATE_SAMPLER_ERR CL_HPP_ERR_STR_(clCreateSampler)
957 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
962 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
963 #define __ENQUEUE_MARKER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueMarkerWithWaitList)
964 #define __ENQUEUE_BARRIER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueBarrierWithWaitList)
965 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
967 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
968 #define __CLONE_KERNEL_ERR CL_HPP_ERR_STR_(clCloneKernel)
969 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
971 #endif // CL_HPP_USER_OVERRIDE_ERROR_STRINGS
981 template<
typename Functor,
typename T>
982 inline cl_int getInfoHelper(Functor f, cl_uint name, T* param,
long)
984 return f(name,
sizeof(T), param, NULL);
989 template <
typename Func>
990 inline cl_int getInfoHelper(Func f, cl_uint name, vector<vector<unsigned char>>* param,
int)
992 if (name != CL_PROGRAM_BINARIES) {
993 return CL_INVALID_VALUE;
997 size_type numBinaries = param->size();
998 vector<unsigned char*> binariesPointers(numBinaries);
1000 for (size_type i = 0; i < numBinaries; ++i)
1002 binariesPointers[i] = (*param)[i].data();
1005 cl_int err = f(name, numBinaries *
sizeof(
unsigned char*), binariesPointers.data(), NULL);
1007 if (err != CL_SUCCESS) {
1017 template <
typename Func,
typename T>
1018 inline cl_int getInfoHelper(Func f, cl_uint name, vector<T>* param,
long)
1021 cl_int err = f(name, 0, NULL, &required);
1022 if (err != CL_SUCCESS) {
1025 const size_type elements = required /
sizeof(T);
1028 vector<T> localData(elements);
1029 err = f(name, required, localData.data(), NULL);
1030 if (err != CL_SUCCESS) {
1034 *param = std::move(localData);
1046 template <
typename Func,
typename T>
1047 inline cl_int getInfoHelper(
1048 Func f, cl_uint name, vector<T>* param,
int,
typename T::cl_type = 0)
1051 cl_int err = f(name, 0, NULL, &required);
1052 if (err != CL_SUCCESS) {
1056 const size_type elements = required /
sizeof(
typename T::cl_type);
1058 vector<typename T::cl_type> value(elements);
1059 err = f(name, required, value.data(), NULL);
1060 if (err != CL_SUCCESS) {
1066 param->resize(elements);
1070 for (size_type i = 0; i < elements; i++) {
1071 (*param)[i] = T(value[i],
true);
1078 template <
typename Func>
1079 inline cl_int getInfoHelper(Func f, cl_uint name,
string* param,
long)
1082 cl_int err = f(name, 0, NULL, &required);
1083 if (err != CL_SUCCESS) {
1090 vector<char> value(required);
1091 err = f(name, required, value.data(), NULL);
1092 if (err != CL_SUCCESS) {
1096 param->assign(begin(value), prev(end(value)));
1106 template <
typename Func,
size_type N>
1107 inline cl_int getInfoHelper(Func f, cl_uint name, array<size_type, N>* param,
long)
1110 cl_int err = f(name, 0, NULL, &required);
1111 if (err != CL_SUCCESS) {
1115 size_type elements = required /
sizeof(size_type);
1116 vector<size_type> value(elements, 0);
1118 err = f(name, required, value.data(), NULL);
1119 if (err != CL_SUCCESS) {
1128 for (size_type i = 0; i < elements; ++i) {
1129 (*param)[i] = value[i];
1143 template<
typename Func,
typename T>
1144 inline cl_int getInfoHelper(Func f, cl_uint name, T* param,
int,
typename T::cl_type = 0)
1146 typename T::cl_type value;
1147 cl_int err = f(name,
sizeof(value), &value, NULL);
1148 if (err != CL_SUCCESS) {
1154 err = param->retain();
1155 if (err != CL_SUCCESS) {
1162 #define CL_HPP_PARAM_NAME_INFO_1_0_(F) \
1163 F(cl_platform_info, CL_PLATFORM_PROFILE, string) \
1164 F(cl_platform_info, CL_PLATFORM_VERSION, string) \
1165 F(cl_platform_info, CL_PLATFORM_NAME, string) \
1166 F(cl_platform_info, CL_PLATFORM_VENDOR, string) \
1167 F(cl_platform_info, CL_PLATFORM_EXTENSIONS, string) \
1169 F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
1170 F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
1171 F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
1172 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
1173 F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, size_type) \
1174 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, cl::vector<size_type>) \
1175 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
1176 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
1177 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
1178 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
1179 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
1180 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
1181 F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
1182 F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \
1183 F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
1184 F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
1185 F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
1186 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, size_type) \
1187 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, size_type) \
1188 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, size_type) \
1189 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, size_type) \
1190 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, size_type) \
1191 F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \
1192 F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, size_type) \
1193 F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
1194 F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
1195 F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
1196 F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
1197 F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
1198 F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
1199 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
1200 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
1201 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
1202 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
1203 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
1204 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
1205 F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
1206 F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
1207 F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
1208 F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, size_type) \
1209 F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
1210 F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
1211 F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
1212 F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
1213 F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
1214 F(cl_device_info, CL_DEVICE_NAME, string) \
1215 F(cl_device_info, CL_DEVICE_VENDOR, string) \
1216 F(cl_device_info, CL_DRIVER_VERSION, string) \
1217 F(cl_device_info, CL_DEVICE_PROFILE, string) \
1218 F(cl_device_info, CL_DEVICE_VERSION, string) \
1219 F(cl_device_info, CL_DEVICE_EXTENSIONS, string) \
1221 F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
1222 F(cl_context_info, CL_CONTEXT_DEVICES, cl::vector<Device>) \
1223 F(cl_context_info, CL_CONTEXT_PROPERTIES, cl::vector<cl_context_properties>) \
1225 F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
1226 F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
1227 F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
1228 F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \
1230 F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
1231 F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
1232 F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
1233 F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
1235 F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
1236 F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
1237 F(cl_mem_info, CL_MEM_SIZE, size_type) \
1238 F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
1239 F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
1240 F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
1241 F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
1243 F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
1244 F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, size_type) \
1245 F(cl_image_info, CL_IMAGE_ROW_PITCH, size_type) \
1246 F(cl_image_info, CL_IMAGE_SLICE_PITCH, size_type) \
1247 F(cl_image_info, CL_IMAGE_WIDTH, size_type) \
1248 F(cl_image_info, CL_IMAGE_HEIGHT, size_type) \
1249 F(cl_image_info, CL_IMAGE_DEPTH, size_type) \
1251 F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
1252 F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
1253 F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \
1254 F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \
1255 F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \
1257 F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
1258 F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
1259 F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
1260 F(cl_program_info, CL_PROGRAM_DEVICES, cl::vector<Device>) \
1261 F(cl_program_info, CL_PROGRAM_SOURCE, string) \
1262 F(cl_program_info, CL_PROGRAM_BINARY_SIZES, cl::vector<size_type>) \
1263 F(cl_program_info, CL_PROGRAM_BINARIES, cl::vector<cl::vector<unsigned char>>) \
1265 F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
1266 F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, string) \
1267 F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, string) \
1269 F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, string) \
1270 F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
1271 F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
1272 F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
1273 F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
1275 F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, size_type) \
1276 F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::detail::size_t_array) \
1277 F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
1279 F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
1280 F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
1281 F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
1282 F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
1285 #define CL_HPP_PARAM_NAME_INFO_1_1_(F) \
1286 F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
1287 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
1288 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
1289 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
1290 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
1291 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
1292 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
1293 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
1294 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
1295 F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, string) \
1297 F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
1298 F(cl_mem_info, CL_MEM_OFFSET, size_type) \
1300 F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1301 F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
1303 F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
1305 #define CL_HPP_PARAM_NAME_INFO_1_2_(F) \
1306 F(cl_program_info, CL_PROGRAM_NUM_KERNELS, size_type) \
1307 F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, string) \
1309 F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \
1311 F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, string) \
1313 F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \
1314 F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \
1315 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, string) \
1316 F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, string) \
1317 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \
1319 F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl::Device) \
1320 F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, cl::vector<cl_device_partition_property>) \
1321 F(cl_device_info, CL_DEVICE_PARTITION_TYPE, cl::vector<cl_device_partition_property>) \
1322 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \
1323 F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, size_type) \
1324 F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \
1325 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, string) \
1327 F(cl_image_info, CL_IMAGE_ARRAY_SIZE, size_type) \
1328 F(cl_image_info, CL_IMAGE_NUM_MIP_LEVELS, cl_uint) \
1329 F(cl_image_info, CL_IMAGE_NUM_SAMPLES, cl_uint)
1331 #define CL_HPP_PARAM_NAME_INFO_2_0_(F) \
1332 F(cl_device_info, CL_DEVICE_QUEUE_ON_HOST_PROPERTIES, cl_command_queue_properties) \
1333 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES, cl_command_queue_properties) \
1334 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, cl_uint) \
1335 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, cl_uint) \
1336 F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_QUEUES, cl_uint) \
1337 F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_EVENTS, cl_uint) \
1338 F(cl_device_info, CL_DEVICE_MAX_PIPE_ARGS, cl_uint) \
1339 F(cl_device_info, CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS, cl_uint) \
1340 F(cl_device_info, CL_DEVICE_PIPE_MAX_PACKET_SIZE, cl_uint) \
1341 F(cl_device_info, CL_DEVICE_SVM_CAPABILITIES, cl_device_svm_capabilities) \
1342 F(cl_device_info, CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT, cl_uint) \
1343 F(cl_device_info, CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT, cl_uint) \
1344 F(cl_device_info, CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT, cl_uint) \
1345 F(cl_command_queue_info, CL_QUEUE_SIZE, cl_uint) \
1346 F(cl_mem_info, CL_MEM_USES_SVM_POINTER, cl_bool) \
1347 F(cl_program_build_info, CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, size_type) \
1348 F(cl_pipe_info, CL_PIPE_PACKET_SIZE, cl_uint) \
1349 F(cl_pipe_info, CL_PIPE_MAX_PACKETS, cl_uint)
1351 #define CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(F) \
1352 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR, size_type) \
1353 F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR, size_type)
1355 #define CL_HPP_PARAM_NAME_INFO_IL_KHR_(F) \
1356 F(cl_device_info, CL_DEVICE_IL_VERSION_KHR, string) \
1357 F(cl_program_info, CL_PROGRAM_IL_KHR, cl::vector<unsigned char>)
1359 #define CL_HPP_PARAM_NAME_INFO_2_1_(F) \
1360 F(cl_platform_info, CL_PLATFORM_HOST_TIMER_RESOLUTION, size_type) \
1361 F(cl_program_info, CL_PROGRAM_IL, cl::vector<unsigned char>) \
1362 F(cl_kernel_info, CL_KERNEL_MAX_NUM_SUB_GROUPS, size_type) \
1363 F(cl_kernel_info, CL_KERNEL_COMPILE_NUM_SUB_GROUPS, size_type) \
1364 F(cl_device_info, CL_DEVICE_MAX_NUM_SUB_GROUPS, cl_uint) \
1365 F(cl_device_info, CL_DEVICE_IL_VERSION, string) \
1366 F(cl_device_info, CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS, cl_bool) \
1367 F(cl_command_queue_info, CL_QUEUE_DEVICE_DEFAULT, cl::DeviceCommandQueue) \
1368 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE, size_type) \
1369 F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE, size_type) \
1370 F(cl_kernel_sub_group_info, CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT, cl::detail::size_t_array)
1372 #define CL_HPP_PARAM_NAME_INFO_2_2_(F) \
1373 F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_CTORS_PRESENT, cl_bool) \
1374 F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_DTORS_PRESENT, cl_bool)
1376 #define CL_HPP_PARAM_NAME_DEVICE_FISSION_(F) \
1377 F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
1378 F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, cl::vector<cl_device_partition_property_ext>) \
1379 F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, cl::vector<cl_device_partition_property_ext>) \
1380 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
1381 F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, cl::vector<cl_device_partition_property_ext>)
1383 #define CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_(F) \
1384 F(cl_platform_info, CL_PLATFORM_NUMERIC_VERSION_KHR, cl_version_khr) \
1385 F(cl_platform_info, CL_PLATFORM_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1387 F(cl_device_info, CL_DEVICE_NUMERIC_VERSION_KHR, cl_version_khr) \
1388 F(cl_device_info, CL_DEVICE_OPENCL_C_NUMERIC_VERSION_KHR, cl_version_khr) \
1389 F(cl_device_info, CL_DEVICE_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1390 F(cl_device_info, CL_DEVICE_ILS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1391 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>)
1393 template <
typename enum_type, cl_
int Name>
1396 #define CL_HPP_DECLARE_PARAM_TRAITS_(token, param_name, T) \
1399 struct param_traits<detail:: token,param_name> \
1401 enum { value = param_name }; \
1402 typedef T param_type; \
1405 CL_HPP_PARAM_NAME_INFO_1_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1406 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
1407 CL_HPP_PARAM_NAME_INFO_1_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1408 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
1409 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1410 CL_HPP_PARAM_NAME_INFO_1_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1411 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1412 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
1413 CL_HPP_PARAM_NAME_INFO_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1414 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
1415 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
1416 CL_HPP_PARAM_NAME_INFO_2_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1417 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
1418 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
1419 CL_HPP_PARAM_NAME_INFO_2_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1420 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
1422 #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1423 CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1424 #endif // #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1426 #if defined(CL_HPP_USE_IL_KHR)
1427 CL_HPP_PARAM_NAME_INFO_IL_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1428 #endif // #if defined(CL_HPP_USE_IL_KHR)
1432 #define CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(F) \
1433 F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties)
1435 #define CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(F) \
1436 F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool)
1438 #define CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(F) \
1439 F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer)
1443 #if CL_HPP_TARGET_OPENCL_VERSION > 100 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 && CL_HPP_TARGET_OPENCL_VERSION < 200
1444 CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1445 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 110
1446 #if CL_HPP_TARGET_OPENCL_VERSION > 110 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1447 CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1448 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1449 #if CL_HPP_TARGET_OPENCL_VERSION > 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1450 CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1451 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
1453 #if defined(CL_HPP_USE_CL_DEVICE_FISSION)
1454 CL_HPP_PARAM_NAME_DEVICE_FISSION_(CL_HPP_DECLARE_PARAM_TRAITS_);
1455 #endif // CL_HPP_USE_CL_DEVICE_FISSION
1457 #if defined(cl_khr_extended_versioning)
1458 CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_(CL_HPP_DECLARE_PARAM_TRAITS_);
1459 #endif // cl_khr_extended_versioning
1461 #ifdef CL_PLATFORM_ICD_SUFFIX_KHR
1462 CL_HPP_DECLARE_PARAM_TRAITS_(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR,
string)
1465 #ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
1466 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong)
1469 #ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
1470 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, vector<size_type>)
1472 #ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
1473 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint)
1475 #ifdef CL_DEVICE_SIMD_WIDTH_AMD
1476 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint)
1478 #ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD
1479 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint)
1481 #ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD
1482 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint)
1484 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
1485 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint)
1487 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
1488 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint)
1490 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
1491 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint)
1493 #ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
1494 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint)
1496 #ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
1497 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint)
1500 #ifdef CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM
1501 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM, cl_ulong)
1503 #ifdef CL_DEVICE_JOB_SLOTS_ARM
1504 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_JOB_SLOTS_ARM, cl_uint)
1507 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
1508 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint)
1510 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV
1511 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint)
1513 #ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV
1514 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint)
1516 #ifdef CL_DEVICE_WARP_SIZE_NV
1517 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint)
1519 #ifdef CL_DEVICE_GPU_OVERLAP_NV
1520 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool)
1522 #ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV
1523 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool)
1525 #ifdef CL_DEVICE_INTEGRATED_MEMORY_NV
1526 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool)
1531 template <
typename Func,
typename T>
1533 getInfo(Func f, cl_uint name, T* param)
1535 return getInfoHelper(f, name, param, 0);
1538 template <
typename Func,
typename Arg0>
1541 Func f_;
const Arg0& arg0_;
1543 cl_uint param, size_type size,
void* value, size_type* size_ret)
1544 {
return f_(arg0_, param, size, value, size_ret); }
1547 template <
typename Func,
typename Arg0,
typename Arg1>
1550 Func f_;
const Arg0& arg0_;
const Arg1& arg1_;
1552 cl_uint param, size_type size,
void* value, size_type* size_ret)
1553 {
return f_(arg0_, arg1_, param, size, value, size_ret); }
1556 template <
typename Func,
typename Arg0,
typename T>
1558 getInfo(Func f,
const Arg0& arg0, cl_uint name, T* param)
1561 return getInfoHelper(f0, name, param, 0);
1564 template <
typename Func,
typename Arg0,
typename Arg1,
typename T>
1566 getInfo(Func f,
const Arg0& arg0,
const Arg1& arg1, cl_uint name, T* param)
1568 GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
1569 return getInfoHelper(f0, name, param, 0);
1573 template<
typename T>
1574 struct ReferenceHandler
1577 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1594 { return ::clRetainDevice(device); }
1605 { return ::clReleaseDevice(device); }
1607 #else // CL_HPP_TARGET_OPENCL_VERSION >= 120
1612 struct ReferenceHandler<cl_device_id>
1615 static cl_int retain(cl_device_id)
1616 {
return CL_SUCCESS; }
1618 static cl_int release(cl_device_id)
1619 {
return CL_SUCCESS; }
1621 #endif // ! (CL_HPP_TARGET_OPENCL_VERSION >= 120)
1627 static cl_int retain(cl_platform_id)
1628 {
return CL_SUCCESS; }
1630 static cl_int release(cl_platform_id)
1631 {
return CL_SUCCESS; }
1637 static cl_int retain(cl_context context)
1638 { return ::clRetainContext(context); }
1639 static cl_int release(cl_context context)
1640 { return ::clReleaseContext(context); }
1646 static cl_int retain(cl_command_queue queue)
1647 { return ::clRetainCommandQueue(queue); }
1648 static cl_int release(cl_command_queue queue)
1649 { return ::clReleaseCommandQueue(queue); }
1655 static cl_int retain(cl_mem memory)
1656 { return ::clRetainMemObject(memory); }
1657 static cl_int release(cl_mem memory)
1658 { return ::clReleaseMemObject(memory); }
1664 static cl_int retain(cl_sampler sampler)
1665 { return ::clRetainSampler(sampler); }
1666 static cl_int release(cl_sampler sampler)
1667 { return ::clReleaseSampler(sampler); }
1673 static cl_int retain(cl_program program)
1674 { return ::clRetainProgram(program); }
1675 static cl_int release(cl_program program)
1676 { return ::clReleaseProgram(program); }
1682 static cl_int retain(cl_kernel kernel)
1683 { return ::clRetainKernel(kernel); }
1684 static cl_int release(cl_kernel kernel)
1685 { return ::clReleaseKernel(kernel); }
1691 static cl_int retain(cl_event event)
1692 { return ::clRetainEvent(event); }
1693 static cl_int release(cl_event event)
1694 { return ::clReleaseEvent(event); }
1698 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1700 static cl_uint getVersion(
const vector<char> &versionInfo)
1702 int highVersion = 0;
1705 while(versionInfo[index] !=
'.' ) {
1707 highVersion += versionInfo[index]-
'0';
1711 while(versionInfo[index] !=
' ' && versionInfo[index] !=
'\0') {
1713 lowVersion += versionInfo[index]-
'0';
1716 return (highVersion << 16) | lowVersion;
1719 static cl_uint getPlatformVersion(cl_platform_id platform)
1722 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size);
1724 vector<char> versionInfo(size);
1725 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, versionInfo.data(), &size);
1726 return getVersion(versionInfo);
1729 static cl_uint getDevicePlatformVersion(cl_device_id device)
1731 cl_platform_id platform;
1732 clGetDeviceInfo(device, CL_DEVICE_PLATFORM,
sizeof(platform), &platform, NULL);
1733 return getPlatformVersion(platform);
1736 static cl_uint getContextPlatformVersion(cl_context context)
1741 clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size);
1744 vector<cl_device_id> devices(size/
sizeof(cl_device_id));
1745 clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices.data(), NULL);
1746 return getDevicePlatformVersion(devices[0]);
1748 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1750 template <
typename T>
1762 Wrapper(
const cl_type &obj,
bool retainObject) : object_(obj)
1765 detail::errHandler(retain(), __RETAIN_ERR);
1771 if (object_ != NULL) { release(); }
1776 object_ = rhs.object_;
1777 detail::errHandler(retain(), __RETAIN_ERR);
1782 object_ = rhs.object_;
1789 detail::errHandler(release(), __RELEASE_ERR);
1790 object_ = rhs.object_;
1791 detail::errHandler(retain(), __RETAIN_ERR);
1799 detail::errHandler(release(), __RELEASE_ERR);
1800 object_ = rhs.object_;
1808 detail::errHandler(release(), __RELEASE_ERR);
1813 const cl_type& operator ()()
const {
return object_; }
1815 cl_type& operator ()() {
return object_; }
1817 cl_type get()
const {
return object_; }
1820 template<
typename Func,
typename U>
1821 friend inline cl_int getInfoHelper(Func, cl_uint, U*,
int,
typename U::cl_type);
1823 cl_int retain()
const
1825 if (object_ !=
nullptr) {
1833 cl_int release()
const
1835 if (object_ !=
nullptr) {
1848 typedef cl_device_id cl_type;
1852 bool referenceCountable_;
1854 static bool isReferenceCountable(cl_device_id device)
1856 bool retVal =
false;
1857 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1858 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
1859 if (device != NULL) {
1860 int version = getDevicePlatformVersion(device);
1861 if(version > ((1 << 16) + 1)) {
1865 #else // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1867 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1868 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1873 Wrapper() : object_(NULL), referenceCountable_(
false)
1877 Wrapper(
const cl_type &obj,
bool retainObject) :
1879 referenceCountable_(
false)
1881 referenceCountable_ = isReferenceCountable(obj);
1884 detail::errHandler(retain(), __RETAIN_ERR);
1895 object_ = rhs.object_;
1896 referenceCountable_ = isReferenceCountable(object_);
1897 detail::errHandler(retain(), __RETAIN_ERR);
1902 object_ = rhs.object_;
1903 referenceCountable_ = rhs.referenceCountable_;
1905 rhs.referenceCountable_ =
false;
1911 detail::errHandler(release(), __RELEASE_ERR);
1912 object_ = rhs.object_;
1913 referenceCountable_ = rhs.referenceCountable_;
1914 detail::errHandler(retain(), __RETAIN_ERR);
1922 detail::errHandler(release(), __RELEASE_ERR);
1923 object_ = rhs.object_;
1924 referenceCountable_ = rhs.referenceCountable_;
1926 rhs.referenceCountable_ =
false;
1933 detail::errHandler(release(), __RELEASE_ERR);
1935 referenceCountable_ = isReferenceCountable(object_);
1939 const cl_type& operator ()()
const {
return object_; }
1941 cl_type& operator ()() {
return object_; }
1943 cl_type get()
const {
return object_; }
1946 template<
typename Func,
typename U>
1947 friend inline cl_int getInfoHelper(Func, cl_uint, U*,
int,
typename U::cl_type);
1949 template<
typename Func,
typename U>
1950 friend inline cl_int getInfoHelper(Func, cl_uint, vector<U>*,
int,
typename U::cl_type);
1952 cl_int retain()
const
1954 if( object_ !=
nullptr && referenceCountable_ ) {
1962 cl_int release()
const
1964 if (object_ !=
nullptr && referenceCountable_) {
1973 template <
typename T>
1976 return lhs() == rhs();
1979 template <
typename T>
1980 inline bool operator!=(
const Wrapper<T> &lhs,
const Wrapper<T> &rhs)
1982 return !operator==(lhs, rhs);
1989 using BuildLogType = vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, CL_PROGRAM_BUILD_LOG>::param_type>>;
1990 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
1994 class BuildError :
public Error
1997 BuildLogType buildLogs;
1999 BuildError(cl_int err,
const char * errStr,
const BuildLogType &vec) : Error(err, errStr), buildLogs(vec)
2003 BuildLogType getBuildLog()
const
2009 static inline cl_int buildErrHandler(
2011 const char * errStr,
2012 const BuildLogType &buildLogs)
2014 if (err != CL_SUCCESS) {
2015 throw BuildError(err, errStr, buildLogs);
2023 static inline cl_int buildErrHandler(
2025 const char * errStr,
2026 const BuildLogType &buildLogs)
2033 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2049 image_channel_order = order;
2050 image_channel_data_type = type;
2057 this->image_channel_data_type = rhs.image_channel_data_type;
2058 this->image_channel_order = rhs.image_channel_order;
2074 static std::once_flag default_initialized_;
2076 static cl_int default_error_;
2083 static void makeDefault();
2090 static void makeDefaultProvided(
const Device &p) {
2095 #ifdef CL_HPP_UNIT_TEST_ENABLE
2102 static void unitTestClearDefault() {
2105 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2114 explicit Device(
const cl_device_id &device,
bool retainObject =
false) :
2115 detail::Wrapper<cl_type>(device, retainObject) { }
2122 cl_int *errResult = NULL)
2124 std::call_once(default_initialized_, makeDefault);
2125 detail::errHandler(default_error_);
2126 if (errResult != NULL) {
2127 *errResult = default_error_;
2141 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_device));
2142 detail::errHandler(default_error_);
2185 template <
typename T>
2186 cl_int
getInfo(cl_device_info name, T* param)
const
2188 return detail::errHandler(
2189 detail::getInfo(&::clGetDeviceInfo, object_, name, param),
2190 __GET_DEVICE_INFO_ERR);
2194 template <cl_device_info name>
typename
2199 detail::cl_device_info, name>::param_type param;
2200 cl_int result =
getInfo(name, ¶m);
2208 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2217 cl_ulong retVal = 0;
2219 clGetHostTimer(this->get(), &retVal);
2222 __GET_HOST_TIMER_ERR);
2241 std::pair<cl_ulong, cl_ulong> retVal;
2243 clGetDeviceAndHostTimer(this->get(), &(retVal.first), &(retVal.second));
2246 __GET_DEVICE_AND_HOST_TIMER_ERR);
2252 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2257 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
2260 const cl_device_partition_property * properties,
2261 vector<Device>* devices)
2264 cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n);
2265 if (err != CL_SUCCESS) {
2266 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2269 vector<cl_device_id> ids(n);
2270 err = clCreateSubDevices(object_, properties, n, ids.data(), NULL);
2271 if (err != CL_SUCCESS) {
2272 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2278 devices->resize(ids.size());
2282 for (size_type i = 0; i < ids.size(); i++) {
2285 (*devices)[i] =
Device(ids[i],
false);
2291 #elif defined(CL_HPP_USE_CL_DEVICE_FISSION)
2297 const cl_device_partition_property_ext * properties,
2298 vector<Device>* devices)
2300 typedef CL_API_ENTRY cl_int
2301 ( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
2303 const cl_device_partition_property_ext * ,
2306 cl_uint * ) CL_EXT_SUFFIX__VERSION_1_1;
2308 static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
2309 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSubDevicesEXT);
2312 cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
2313 if (err != CL_SUCCESS) {
2314 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2317 vector<cl_device_id> ids(n);
2318 err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids.data(), NULL);
2319 if (err != CL_SUCCESS) {
2320 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2325 devices->resize(ids.size());
2329 for (size_type i = 0; i < ids.size(); i++) {
2332 (*devices)[i] =
Device(ids[i],
false);
2337 #endif // defined(CL_HPP_USE_CL_DEVICE_FISSION)
2340 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Device::default_initialized_;
2341 CL_HPP_DEFINE_STATIC_MEMBER_ Device Device::default_;
2342 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Device::default_error_ = CL_SUCCESS;
2354 static std::once_flag default_initialized_;
2356 static cl_int default_error_;
2363 static void makeDefault() {
2367 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2375 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2376 if (err != CL_SUCCESS) {
2377 default_error_ = err;
2381 default_error_ = CL_INVALID_PLATFORM;
2385 vector<cl_platform_id> ids(n);
2386 err = ::clGetPlatformIDs(n, ids.data(), NULL);
2387 if (err != CL_SUCCESS) {
2388 default_error_ = err;
2394 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2395 catch (cl::Error &e) {
2396 default_error_ = e.err();
2406 static void makeDefaultProvided(
const Platform &p) {
2411 #ifdef CL_HPP_UNIT_TEST_ENABLE
2418 static void unitTestClearDefault() {
2421 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2433 explicit Platform(
const cl_platform_id &platform,
bool retainObject =
false) :
2434 detail::Wrapper<cl_type>(platform, retainObject) { }
2447 cl_int *errResult = NULL)
2449 std::call_once(default_initialized_, makeDefault);
2450 detail::errHandler(default_error_);
2451 if (errResult != NULL) {
2452 *errResult = default_error_;
2466 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_platform));
2467 detail::errHandler(default_error_);
2472 template <
typename T>
2473 cl_int
getInfo(cl_platform_info name, T* param)
const
2475 return detail::errHandler(
2476 detail::getInfo(&::clGetPlatformInfo, object_, name, param),
2477 __GET_PLATFORM_INFO_ERR);
2481 template <cl_platform_info name>
typename
2486 detail::cl_platform_info, name>::param_type param;
2487 cl_int result =
getInfo(name, ¶m);
2499 cl_device_type type,
2500 vector<Device>* devices)
const
2503 if( devices == NULL ) {
2504 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2506 cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
2507 if (err != CL_SUCCESS && err != CL_DEVICE_NOT_FOUND) {
2508 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2511 vector<cl_device_id> ids(n);
2513 err = ::clGetDeviceIDs(object_, type, n, ids.data(), NULL);
2514 if (err != CL_SUCCESS) {
2515 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2524 devices->resize(ids.size());
2528 for (size_type i = 0; i < ids.size(); i++) {
2529 (*devices)[i] =
Device(ids[i],
true);
2535 #if defined(CL_HPP_USE_DX_INTEROP)
2560 cl_d3d10_device_source_khr d3d_device_source,
2562 cl_d3d10_device_set_khr d3d_device_set,
2563 vector<Device>* devices)
const
2565 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
2566 cl_platform_id platform,
2567 cl_d3d10_device_source_khr d3d_device_source,
2569 cl_d3d10_device_set_khr d3d_device_set,
2570 cl_uint num_entries,
2571 cl_device_id * devices,
2572 cl_uint* num_devices);
2574 if( devices == NULL ) {
2575 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2578 static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
2579 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(object_, clGetDeviceIDsFromD3D10KHR);
2582 cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
2590 if (err != CL_SUCCESS) {
2591 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2594 vector<cl_device_id> ids(n);
2595 err = pfn_clGetDeviceIDsFromD3D10KHR(
2603 if (err != CL_SUCCESS) {
2604 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2612 devices->resize(ids.size());
2616 for (size_type i = 0; i < ids.size(); i++) {
2617 (*devices)[i] = Device(ids[i],
true);
2629 vector<Platform>* platforms)
2633 if( platforms == NULL ) {
2634 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
2637 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2638 if (err != CL_SUCCESS) {
2639 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2642 vector<cl_platform_id> ids(n);
2643 err = ::clGetPlatformIDs(n, ids.data(), NULL);
2644 if (err != CL_SUCCESS) {
2645 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2649 platforms->resize(ids.size());
2652 for (size_type i = 0; i < ids.size(); i++) {
2653 (*platforms)[i] =
Platform(ids[i]);
2667 Platform default_platform = Platform::getDefault(&err);
2669 *platform = default_platform;
2683 cl_int * errResult = NULL)
2686 Platform default_platform = Platform::getDefault(&err);
2690 return default_platform;
2693 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
2698 return ::clUnloadPlatformCompiler(object_);
2700 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
2703 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Platform::default_initialized_;
2704 CL_HPP_DEFINE_STATIC_MEMBER_ Platform Platform::default_;
2705 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Platform::default_error_ = CL_SUCCESS;
2711 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2716 inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int
2721 return ::clUnloadCompiler();
2723 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2737 static std::once_flag default_initialized_;
2739 static cl_int default_error_;
2746 static void makeDefault() {
2750 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2754 #if !defined(__APPLE__) && !defined(__MACOS)
2755 const Platform &p = Platform::getDefault();
2756 cl_platform_id defaultPlatform = p();
2757 cl_context_properties properties[3] = {
2758 CL_CONTEXT_PLATFORM, (cl_context_properties)defaultPlatform, 0
2760 #else // #if !defined(__APPLE__) && !defined(__MACOS)
2761 cl_context_properties *properties =
nullptr;
2762 #endif // #if !defined(__APPLE__) && !defined(__MACOS)
2765 CL_DEVICE_TYPE_DEFAULT,
2771 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2772 catch (cl::Error &e) {
2773 default_error_ = e.err();
2784 static void makeDefaultProvided(
const Context &c) {
2789 #ifdef CL_HPP_UNIT_TEST_ENABLE
2796 static void unitTestClearDefault() {
2799 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2806 const vector<Device>& devices,
2807 cl_context_properties* properties = NULL,
2808 void (CL_CALLBACK * notifyFptr)(
2818 size_type numDevices = devices.size();
2819 vector<cl_device_id> deviceIDs(numDevices);
2821 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
2822 deviceIDs[deviceIndex] = (devices[deviceIndex])();
2825 object_ = ::clCreateContext(
2826 properties, (cl_uint) numDevices,
2828 notifyFptr, data, &error);
2830 detail::errHandler(error, __CREATE_CONTEXT_ERR);
2838 cl_context_properties* properties = NULL,
2839 void (CL_CALLBACK * notifyFptr)(
2849 cl_device_id deviceID = device();
2851 object_ = ::clCreateContext(
2854 notifyFptr, data, &error);
2856 detail::errHandler(error, __CREATE_CONTEXT_ERR);
2867 cl_device_type type,
2868 cl_context_properties* properties = NULL,
2869 void (CL_CALLBACK * notifyFptr)(
2879 #if !defined(__APPLE__) && !defined(__MACOS)
2880 cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 };
2882 if (properties == NULL) {
2884 vector<Platform> platforms;
2885 error = Platform::get(&platforms);
2886 if (error != CL_SUCCESS) {
2887 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2895 cl_context_properties platform_id = 0;
2896 for (
unsigned int i = 0; i < platforms.size(); i++) {
2898 vector<Device> devices;
2900 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2904 error = platforms[i].getDevices(type, &devices);
2906 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2907 }
catch (cl::Error& e) {
2915 if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) {
2916 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2922 if (devices.size() > 0) {
2923 platform_id = (cl_context_properties)platforms[i]();
2928 if (platform_id == 0) {
2929 detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR);
2931 *err = CL_DEVICE_NOT_FOUND;
2936 prop[1] = platform_id;
2937 properties = &prop[0];
2940 object_ = ::clCreateContextFromType(
2941 properties, type, notifyFptr, data, &error);
2943 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2984 std::call_once(default_initialized_, makeDefault);
2985 detail::errHandler(default_error_);
2987 *err = default_error_;
3001 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_context));
3002 detail::errHandler(default_error_);
3014 explicit Context(
const cl_context& context,
bool retainObject =
false) :
3015 detail::Wrapper<cl_type>(context, retainObject) { }
3029 template <
typename T>
3030 cl_int
getInfo(cl_context_info name, T* param)
const
3032 return detail::errHandler(
3033 detail::getInfo(&::clGetContextInfo, object_, name, param),
3034 __GET_CONTEXT_INFO_ERR);
3038 template <cl_context_info name>
typename
3043 detail::cl_context_info, name>::param_type param;
3044 cl_int result =
getInfo(name, ¶m);
3057 cl_mem_object_type type,
3058 vector<ImageFormat>* formats)
const
3066 cl_int err = ::clGetSupportedImageFormats(
3073 if (err != CL_SUCCESS) {
3074 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3077 if (numEntries > 0) {
3078 vector<ImageFormat> value(numEntries);
3079 err = ::clGetSupportedImageFormats(
3084 (cl_image_format*)value.data(),
3086 if (err != CL_SUCCESS) {
3087 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3090 formats->assign(begin(value), end(value));
3101 inline void Device::makeDefault()
3106 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3113 detail::errHandler(error, __CREATE_CONTEXT_ERR);
3115 if (error != CL_SUCCESS) {
3116 default_error_ = error;
3119 default_ = context.
getInfo<CL_CONTEXT_DEVICES>()[0];
3120 default_error_ = CL_SUCCESS;
3123 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3124 catch (cl::Error &e) {
3125 default_error_ = e.err();
3130 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Context::default_initialized_;
3131 CL_HPP_DEFINE_STATIC_MEMBER_ Context Context::default_;
3132 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Context::default_error_ = CL_SUCCESS;
3146 Event() : detail::Wrapper<cl_type>() { }
3156 explicit Event(
const cl_event& event,
bool retainObject =
false) :
3157 detail::Wrapper<cl_type>(event, retainObject) { }
3171 template <
typename T>
3172 cl_int
getInfo(cl_event_info name, T* param)
const
3174 return detail::errHandler(
3175 detail::getInfo(&::clGetEventInfo, object_, name, param),
3176 __GET_EVENT_INFO_ERR);
3180 template <cl_event_info name>
typename
3185 detail::cl_event_info, name>::param_type param;
3186 cl_int result =
getInfo(name, ¶m);
3194 template <
typename T>
3197 return detail::errHandler(detail::getInfo(
3198 &::clGetEventProfilingInfo, object_, name, param),
3199 __GET_EVENT_PROFILE_INFO_ERR);
3203 template <cl_profiling_info name>
typename
3208 detail::cl_profiling_info, name>::param_type param;
3222 return detail::errHandler(
3223 ::clWaitForEvents(1, &object_),
3224 __WAIT_FOR_EVENTS_ERR);
3227 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3234 void (CL_CALLBACK * pfn_notify)(cl_event, cl_int,
void *),
3235 void * user_data = NULL)
3237 return detail::errHandler(
3238 ::clSetEventCallback(
3243 __SET_EVENT_CALLBACK_ERR);
3245 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3254 return detail::errHandler(
3256 (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3257 __WAIT_FOR_EVENTS_ERR);
3261 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3275 cl_int * err = NULL)
3278 object_ = ::clCreateUserEvent(
3282 detail::errHandler(error, __CREATE_USER_EVENT_ERR);
3297 return detail::errHandler(
3298 ::clSetUserEventStatus(object_,status),
3299 __SET_USER_EVENT_STATUS_ERR);
3302 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3308 inline static cl_int
3309 WaitForEvents(
const vector<Event>& events)
3311 return detail::errHandler(
3313 (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3314 __WAIT_FOR_EVENTS_ERR);
3342 explicit Memory(
const cl_mem& memory,
bool retainObject) :
3343 detail::Wrapper<cl_type>(memory, retainObject) { }
3386 template <
typename T>
3389 return detail::errHandler(
3390 detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
3391 __GET_MEM_OBJECT_INFO_ERR);
3395 template <cl_mem_info name>
typename
3400 detail::cl_mem_info, name>::param_type param;
3401 cl_int result =
getInfo(name, ¶m);
3408 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3423 void (CL_CALLBACK * pfn_notify)(cl_mem,
void *),
3424 void * user_data = NULL)
3426 return detail::errHandler(
3427 ::clSetMemObjectDestructorCallback(
3431 __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
3433 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3439 template<
typename IteratorType >
3440 cl_int
copy( IteratorType startIterator, IteratorType endIterator,
cl::Buffer &buffer );
3441 template<
typename IteratorType >
3442 cl_int
copy(
const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3443 template<
typename IteratorType >
3444 cl_int
copy(
const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator,
cl::Buffer &buffer );
3445 template<
typename IteratorType >
3446 cl_int
copy(
const CommandQueue &queue,
const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3449 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
3455 static cl_svm_mem_flags getSVMMemFlags()
3462 template<
class Trait = detail::SVMTraitNull>
3466 static cl_svm_mem_flags getSVMMemFlags()
3468 return CL_MEM_READ_WRITE |
3469 Trait::getSVMMemFlags();
3473 template<
class Trait = detail::SVMTraitNull>
3477 static cl_svm_mem_flags getSVMMemFlags()
3479 return CL_MEM_READ_ONLY |
3480 Trait::getSVMMemFlags();
3484 template<
class Trait = detail::SVMTraitNull>
3488 static cl_svm_mem_flags getSVMMemFlags()
3490 return CL_MEM_WRITE_ONLY |
3491 Trait::getSVMMemFlags();
3495 template<
class Trait = SVMTraitReadWrite<>>
3499 static cl_svm_mem_flags getSVMMemFlags()
3501 return Trait::getSVMMemFlags();
3505 template<
class Trait = SVMTraitReadWrite<>>
3509 static cl_svm_mem_flags getSVMMemFlags()
3511 return CL_MEM_SVM_FINE_GRAIN_BUFFER |
3512 Trait::getSVMMemFlags();
3516 template<
class Trait = SVMTraitReadWrite<>>
3520 static cl_svm_mem_flags getSVMMemFlags()
3523 CL_MEM_SVM_FINE_GRAIN_BUFFER |
3524 CL_MEM_SVM_ATOMICS |
3525 Trait::getSVMMemFlags();
3530 template<
typename T>
3536 const vector<Event>* events = NULL,
3537 Event* event = NULL);
3550 template<
typename T,
class SVMTrait>
3556 typedef T value_type;
3557 typedef value_type* pointer;
3558 typedef const value_type* const_pointer;
3559 typedef value_type& reference;
3560 typedef const value_type& const_reference;
3561 typedef std::size_t size_type;
3562 typedef std::ptrdiff_t difference_type;
3564 template<
typename U>
3570 template<
typename U,
typename V>
3574 context_(
Context::getDefault())
3584 SVMAllocator(
const SVMAllocator &other) :
3585 context_(other.context_)
3589 template<
typename U>
3590 SVMAllocator(
const SVMAllocator<U, SVMTrait> &other) :
3591 context_(other.context_)
3599 pointer address(reference r) CL_HPP_NOEXCEPT_
3601 return std::addressof(r);
3604 const_pointer address(const_reference r) CL_HPP_NOEXCEPT_
3606 return std::addressof(r);
3623 SVMTrait::getSVMMemFlags(),
3626 pointer retValue =
reinterpret_cast<pointer
>(
3628 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3630 std::bad_alloc excep;
3633 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3636 if (!(SVMTrait::getSVMMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) {
3637 cl_int err =
enqueueMapSVM(retValue, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, size*
sizeof(T));
3638 if (err != CL_SUCCESS) {
3639 std::bad_alloc excep;
3648 void deallocate(pointer p, size_type)
3650 clSVMFree(context_(), p);
3659 size_type maxSize = std::numeric_limits<size_type>::max() /
sizeof(T);
3661 for (
const Device &d : context_.
getInfo<CL_CONTEXT_DEVICES>()) {
3664 static_cast<size_type
>(d.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>()));
3670 template<
class U,
class... Args >
3671 void construct(U* p, Args&&... args)
3687 return (context_==rhs.context_);
3697 template<
class SVMTrait>
3700 typedef void value_type;
3701 typedef value_type* pointer;
3702 typedef const value_type* const_pointer;
3704 template<
typename U>
3710 template<
typename U,
typename V>
3714 #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3717 template<
class Alloc>
3724 typedef typename std::allocator_traits<Alloc>::pointer pointer;
3726 Deleter(
const Alloc &alloc, size_type copies) : alloc_{ alloc }, copies_{ copies }
3730 void operator()(pointer ptr)
const {
3731 Alloc tmpAlloc{ alloc_ };
3732 std::allocator_traits<Alloc>::destroy(tmpAlloc, std::addressof(*ptr));
3733 std::allocator_traits<Alloc>::deallocate(tmpAlloc, ptr, copies_);
3744 template <
class T,
class Alloc,
class... Args>
3747 Alloc alloc(alloc_);
3748 static const size_type copies = 1;
3753 T* tmp = std::allocator_traits<Alloc>::allocate(alloc, copies);
3755 std::bad_alloc excep;
3759 std::allocator_traits<Alloc>::construct(
3761 std::addressof(*tmp),
3762 std::forward<Args>(args)...);
3766 catch (std::bad_alloc& b)
3768 std::allocator_traits<Alloc>::deallocate(alloc, tmp, copies);
3773 template<
class T,
class SVMTrait,
class... Args >
3774 cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(Args... args)
3776 SVMAllocator<T, SVMTrait> alloc;
3777 return cl::allocate_pointer<T>(alloc, args...);
3780 template<
class T,
class SVMTrait,
class... Args >
3781 cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(
const cl::Context &c, Args... args)
3783 SVMAllocator<T, SVMTrait> alloc(c);
3784 return cl::allocate_pointer<T>(alloc, args...);
3786 #endif // #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3791 template <
class T >
3797 template <
class T >
3803 template <
class T >
3806 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
3830 void* host_ptr = NULL,
3834 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3836 detail::errHandler(error, __CREATE_BUFFER_ERR);
3854 void* host_ptr = NULL,
3861 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3863 detail::errHandler(error, __CREATE_BUFFER_ERR);
3874 template<
typename IteratorType >
3876 IteratorType startIterator,
3877 IteratorType endIterator,
3879 bool useHostPtr =
false,
3882 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
3885 cl_mem_flags flags = 0;
3887 flags |= CL_MEM_READ_ONLY;
3890 flags |= CL_MEM_READ_WRITE;
3893 flags |= CL_MEM_USE_HOST_PTR;
3896 size_type size =
sizeof(DataType)*(endIterator - startIterator);
3901 object_ = ::clCreateBuffer(context(), flags, size,
static_cast<DataType*
>(&*startIterator), &error);
3903 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
3906 detail::errHandler(error, __CREATE_BUFFER_ERR);
3912 error =
cl::copy(startIterator, endIterator, *
this);
3913 detail::errHandler(error, __CREATE_BUFFER_ERR);
3925 template<
typename IteratorType >
3926 Buffer(
const Context &context, IteratorType startIterator, IteratorType endIterator,
3927 bool readOnly,
bool useHostPtr =
false, cl_int* err = NULL);
3933 template<
typename IteratorType >
3934 Buffer(
const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator,
3935 bool readOnly,
bool useHostPtr =
false, cl_int* err = NULL);
3947 explicit Buffer(
const cl_mem& buffer,
bool retainObject =
false) :
3948 Memory(buffer, retainObject) { }
3988 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3995 cl_buffer_create_type buffer_create_type,
3996 const void * buffer_create_info,
3997 cl_int * err = NULL)
4001 result.object_ = ::clCreateSubBuffer(
4008 detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
4015 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
4018 #if defined (CL_HPP_USE_DX_INTEROP)
4027 class BufferD3D10 :
public Buffer
4038 const Context& context,
4040 ID3D10Buffer* bufobj,
4041 cl_int * err = NULL) : pfn_clCreateFromD3D10BufferKHR(nullptr)
4043 typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
4044 cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
4045 cl_int* errcode_ret);
4046 PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR;
4047 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4048 vector<cl_context_properties> props = context.getInfo<CL_CONTEXT_PROPERTIES>();
4049 cl_platform platform = -1;
4050 for(
int i = 0; i < props.size(); ++i ) {
4051 if( props[i] == CL_CONTEXT_PLATFORM ) {
4052 platform = props[i+1];
4055 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateFromD3D10BufferKHR);
4056 #elif CL_HPP_TARGET_OPENCL_VERSION >= 110
4057 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateFromD3D10BufferKHR);
4061 object_ = pfn_clCreateFromD3D10BufferKHR(
4067 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4074 BufferD3D10() : Buffer() { }
4083 explicit BufferD3D10(
const cl_mem& buffer,
bool retainObject =
false) :
4084 Buffer(buffer, retainObject) { }
4090 BufferD3D10& operator = (
const cl_mem& rhs)
4099 BufferD3D10(
const BufferD3D10& buf) :
4105 BufferD3D10& operator = (
const BufferD3D10 &buf)
4114 BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4119 BufferD3D10& operator = (BufferD3D10 &&buf)
4147 cl_int * err = NULL)
4150 object_ = ::clCreateFromGLBuffer(
4156 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4172 explicit BufferGL(
const cl_mem& buffer,
bool retainObject =
false) :
4173 Buffer(buffer, retainObject) { }
4215 cl_gl_object_type *type,
4216 cl_GLuint * gl_object_name)
4218 return detail::errHandler(
4219 ::clGetGLObjectInfo(object_,type,gl_object_name),
4220 __GET_GL_OBJECT_INFO_ERR);
4244 cl_int * err = NULL)
4247 object_ = ::clCreateFromGLRenderbuffer(
4253 detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR);
4270 Buffer(buffer, retainObject) { }
4312 cl_gl_object_type *type,
4313 cl_GLuint * gl_object_name)
4315 return detail::errHandler(
4316 ::clGetGLObjectInfo(object_,type,gl_object_name),
4317 __GET_GL_OBJECT_INFO_ERR);
4340 explicit Image(
const cl_mem& image,
bool retainObject =
false) :
4341 Memory(image, retainObject) { }
4384 template <
typename T>
4387 return detail::errHandler(
4388 detail::getInfo(&::clGetImageInfo, object_, name, param),
4389 __GET_IMAGE_INFO_ERR);
4393 template <cl_image_info name>
typename
4398 detail::cl_image_info, name>::param_type param;
4407 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4426 void* host_ptr = NULL,
4430 cl_image_desc desc =
4432 CL_MEM_OBJECT_IMAGE1D,
4434 0, 0, 0, 0, 0, 0, 0, 0
4436 object_ = ::clCreateImage(
4444 detail::errHandler(error, __CREATE_IMAGE_ERR);
4460 explicit Image1D(
const cl_mem& image1D,
bool retainObject =
false) :
4461 Image(image1D, retainObject) { }
4518 cl_image_desc desc =
4520 CL_MEM_OBJECT_IMAGE1D_BUFFER,
4522 0, 0, 0, 0, 0, 0, 0,
4525 object_ = ::clCreateImage(
4533 detail::errHandler(error, __CREATE_IMAGE_ERR);
4549 Image(image1D, retainObject) { }
4597 size_type arraySize,
4600 void* host_ptr = NULL,
4604 cl_image_desc desc =
4606 CL_MEM_OBJECT_IMAGE1D_ARRAY,
4613 object_ = ::clCreateImage(
4621 detail::errHandler(error, __CREATE_IMAGE_ERR);
4636 explicit Image1DArray(
const cl_mem& imageArray,
bool retainObject =
false) :
4637 Image(imageArray, retainObject) { }
4675 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4697 size_type row_pitch = 0,
4698 void* host_ptr = NULL,
4702 bool useCreateImage;
4704 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
4707 cl_uint version = detail::getContextPlatformVersion(context());
4708 useCreateImage = (version >= 0x10002);
4710 #elif CL_HPP_TARGET_OPENCL_VERSION >= 120
4711 useCreateImage =
true;
4713 useCreateImage =
false;
4716 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4719 cl_image_desc desc =
4721 CL_MEM_OBJECT_IMAGE2D,
4728 object_ = ::clCreateImage(
4736 detail::errHandler(error, __CREATE_IMAGE_ERR);
4741 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
4742 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
4743 if (!useCreateImage)
4745 object_ = ::clCreateImage2D(
4746 context(), flags,&format, width, height, row_pitch, host_ptr, &error);
4748 detail::errHandler(error, __CREATE_IMAGE2D_ERR);
4753 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
4756 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4765 const Buffer &sourceBuffer,
4768 size_type row_pitch = 0,
4769 cl_int* err =
nullptr)
4773 cl_image_desc desc =
4775 CL_MEM_OBJECT_IMAGE2D,
4784 object_ = ::clCreateImage(
4792 detail::errHandler(error, __CREATE_IMAGE_ERR);
4793 if (err !=
nullptr) {
4797 #endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4799 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
4814 cl_channel_order order,
4815 const Image &sourceImage,
4816 cl_int* err =
nullptr)
4821 size_type sourceWidth =
4823 size_type sourceHeight =
4825 size_type sourceRowPitch =
4827 cl_uint sourceNumMIPLevels =
4829 cl_uint sourceNumSamples =
4831 cl_image_format sourceFormat =
4836 sourceFormat.image_channel_order = order;
4837 cl_image_desc desc =
4839 CL_MEM_OBJECT_IMAGE2D,
4850 object_ = ::clCreateImage(
4858 detail::errHandler(error, __CREATE_IMAGE_ERR);
4859 if (err !=
nullptr) {
4863 #endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200
4875 explicit Image2D(
const cl_mem& image2D,
bool retainObject =
false) :
4876 Image(image2D, retainObject) { }
4919 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
4943 cl_int * err = NULL)
4946 object_ = ::clCreateFromGLTexture2D(
4954 detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR);
4971 explicit Image2DGL(
const cl_mem& image,
bool retainObject =
false) :
4972 Image2D(image, retainObject) { }
5012 } CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
5013 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5015 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5026 size_type arraySize,
5030 size_type slicePitch,
5031 void* host_ptr = NULL,
5035 cl_image_desc desc =
5037 CL_MEM_OBJECT_IMAGE2D_ARRAY,
5046 object_ = ::clCreateImage(
5054 detail::errHandler(error, __CREATE_IMAGE_ERR);
5069 explicit Image2DArray(
const cl_mem& imageArray,
bool retainObject =
false) :
Image(imageArray, retainObject) { }
5105 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5127 size_type row_pitch = 0,
5128 size_type slice_pitch = 0,
5129 void* host_ptr = NULL,
5133 bool useCreateImage;
5135 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
5138 cl_uint version = detail::getContextPlatformVersion(context());
5139 useCreateImage = (version >= 0x10002);
5141 #elif CL_HPP_TARGET_OPENCL_VERSION >= 120
5142 useCreateImage =
true;
5144 useCreateImage =
false;
5147 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5150 cl_image_desc desc =
5152 CL_MEM_OBJECT_IMAGE3D,
5161 object_ = ::clCreateImage(
5169 detail::errHandler(error, __CREATE_IMAGE_ERR);
5174 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5175 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
5176 if (!useCreateImage)
5178 object_ = ::clCreateImage3D(
5179 context(), flags, &format, width, height, depth, row_pitch,
5180 slice_pitch, host_ptr, &error);
5182 detail::errHandler(error, __CREATE_IMAGE3D_ERR);
5187 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
5200 explicit Image3D(
const cl_mem& image3D,
bool retainObject =
false) :
5201 Image(image3D, retainObject) { }
5242 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
5265 cl_int * err = NULL)
5268 object_ = ::clCreateFromGLTexture3D(
5276 detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR);
5292 explicit Image3DGL(
const cl_mem& image,
bool retainObject =
false) :
5293 Image3D(image, retainObject) { }
5333 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5335 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5351 cl_int * err = NULL)
5354 object_ = ::clCreateFromGLTexture(
5362 detail::errHandler(error, __CREATE_GL_TEXTURE_ERR);
5377 explicit ImageGL(
const cl_mem& image,
bool retainObject =
false) :
5378 Image(image, retainObject) { }
5380 ImageGL& operator = (
const cl_mem& rhs)
5414 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5418 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5440 cl_uint packet_size,
5441 cl_uint max_packets,
5446 cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5447 object_ = ::clCreatePipe(context(), flags, packet_size, max_packets,
nullptr, &error);
5449 detail::errHandler(error, __CREATE_PIPE_ERR);
5464 cl_uint packet_size,
5465 cl_uint max_packets,
5472 cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5473 object_ = ::clCreatePipe(context(), flags, packet_size, max_packets,
nullptr, &error);
5475 detail::errHandler(error, __CREATE_PIPE_ERR);
5491 explicit Pipe(
const cl_mem& pipe,
bool retainObject =
false) :
5492 Memory(pipe, retainObject) { }
5533 template <
typename T>
5536 return detail::errHandler(
5537 detail::getInfo(&::clGetPipeInfo, object_, name, param),
5538 __GET_PIPE_INFO_ERR);
5542 template <cl_pipe_info name>
typename
5547 detail::cl_pipe_info, name>::param_type param;
5548 cl_int result =
getInfo(name, ¶m);
5555 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
5578 cl_bool normalized_coords,
5579 cl_addressing_mode addressing_mode,
5580 cl_filter_mode filter_mode,
5585 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5586 cl_sampler_properties sampler_properties[] = {
5587 CL_SAMPLER_NORMALIZED_COORDS, normalized_coords,
5588 CL_SAMPLER_ADDRESSING_MODE, addressing_mode,
5589 CL_SAMPLER_FILTER_MODE, filter_mode,
5591 object_ = ::clCreateSamplerWithProperties(
5596 detail::errHandler(error, __CREATE_SAMPLER_WITH_PROPERTIES_ERR);
5601 object_ = ::clCreateSampler(
5608 detail::errHandler(error, __CREATE_SAMPLER_ERR);
5623 explicit Sampler(
const cl_sampler& sampler,
bool retainObject =
false) :
5624 detail::Wrapper<cl_type>(sampler, retainObject) { }
5666 template <
typename T>
5667 cl_int
getInfo(cl_sampler_info name, T* param)
const
5669 return detail::errHandler(
5670 detail::getInfo(&::clGetSamplerInfo, object_, name, param),
5671 __GET_SAMPLER_INFO_ERR);
5675 template <cl_sampler_info name>
typename
5680 detail::cl_sampler_info, name>::param_type param;
5681 cl_int result =
getInfo(name, ¶m);
5691 class DeviceCommandQueue;
5698 size_type sizes_[3];
5699 cl_uint dimensions_;
5730 NDRange(size_type size0, size_type size1, size_type size2)
5742 operator const size_type*()
const {
5756 return dimensions_*
sizeof(size_type);
5764 const size_type* get()
const
5771 static const NDRange NullRange;
5781 template <
typename T,
class Enable =
void>
5786 template <
typename T>
5789 static size_type size(
const T&) {
return sizeof(T); }
5790 static const T* ptr(
const T& value) {
return &value; }
5795 template <
typename T>
5798 static size_type size(
const T&) {
return sizeof(cl_mem); }
5799 static const cl_mem* ptr(
const T& value) {
return &(value()); }
5807 static size_type size(
const LocalSpaceArg& value) {
return value.size_; }
5808 static const void* ptr(
const LocalSpaceArg&) {
return NULL; }
5835 inline Kernel(
const Program& program,
const char* name, cl_int* err = NULL);
5848 explicit Kernel(
const cl_kernel& kernel,
bool retainObject =
false) :
5849 detail::Wrapper<cl_type>(kernel, retainObject) { }
5890 template <
typename T>
5891 cl_int getInfo(cl_kernel_info name, T* param)
const
5893 return detail::errHandler(
5894 detail::getInfo(&::clGetKernelInfo, object_, name, param),
5895 __GET_KERNEL_INFO_ERR);
5898 template <cl_kernel_info name>
typename
5899 detail::param_traits<detail::cl_kernel_info, name>::param_type
5900 getInfo(cl_int* err = NULL)
const
5902 typename detail::param_traits<
5903 detail::cl_kernel_info, name>::param_type param;
5904 cl_int result = getInfo(name, ¶m);
5911 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5912 template <
typename T>
5913 cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param)
const
5915 return detail::errHandler(
5916 detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param),
5917 __GET_KERNEL_ARG_INFO_ERR);
5920 template <cl_kernel_arg_info name>
typename
5921 detail::param_traits<detail::cl_kernel_arg_info, name>::param_type
5922 getArgInfo(cl_uint argIndex, cl_int* err = NULL)
const
5924 typename detail::param_traits<
5925 detail::cl_kernel_arg_info, name>::param_type param;
5926 cl_int result = getArgInfo(argIndex, name, ¶m);
5932 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5934 template <
typename T>
5935 cl_int getWorkGroupInfo(
5936 const Device& device, cl_kernel_work_group_info name, T* param)
const
5938 return detail::errHandler(
5940 &::clGetKernelWorkGroupInfo, object_, device(), name, param),
5941 __GET_KERNEL_WORK_GROUP_INFO_ERR);
5944 template <cl_kernel_work_group_info name>
typename
5945 detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
5946 getWorkGroupInfo(
const Device& device, cl_int* err = NULL)
const
5948 typename detail::param_traits<
5949 detail::cl_kernel_work_group_info, name>::param_type param;
5950 cl_int result = getWorkGroupInfo(device, name, ¶m);
5957 #if (CL_HPP_TARGET_OPENCL_VERSION >= 200 && defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)) || CL_HPP_TARGET_OPENCL_VERSION >= 210
5958 cl_int getSubGroupInfo(
const cl::Device &dev, cl_kernel_sub_group_info name,
const cl::NDRange &range, size_type* param)
const
5960 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
5962 return detail::errHandler(
5963 clGetKernelSubGroupInfo(object_, dev(), name, range.
size(), range.get(),
sizeof(size_type), param,
nullptr),
5964 __GET_KERNEL_SUB_GROUP_INFO_ERR);
5966 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
5968 typedef clGetKernelSubGroupInfoKHR_fn PFN_clGetKernelSubGroupInfoKHR;
5969 static PFN_clGetKernelSubGroupInfoKHR pfn_clGetKernelSubGroupInfoKHR = NULL;
5970 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetKernelSubGroupInfoKHR);
5972 return detail::errHandler(
5973 pfn_clGetKernelSubGroupInfoKHR(object_, dev(), name, range.
size(), range.get(),
sizeof(size_type), param,
nullptr),
5974 __GET_KERNEL_SUB_GROUP_INFO_ERR);
5976 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
5979 template <cl_kernel_sub_group_info name>
5980 size_type getSubGroupInfo(
const cl::Device &dev,
const cl::NDRange &range, cl_int* err = NULL)
const
5983 cl_int result = getSubGroupInfo(dev, name, range, ¶m);
5989 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5991 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5994 template<
typename T,
class D>
5995 cl_int
setArg(cl_uint index,
const cl::pointer<T, D> &argPtr)
5997 return detail::errHandler(
5998 ::clSetKernelArgSVMPointer(object_, index, argPtr.get()),
5999 __SET_KERNEL_ARGS_ERR);
6004 template<
typename T,
class Alloc>
6005 cl_int
setArg(cl_uint index,
const cl::vector<T, Alloc> &argPtr)
6007 return detail::errHandler(
6008 ::clSetKernelArgSVMPointer(object_, index, argPtr.data()),
6009 __SET_KERNEL_ARGS_ERR);
6014 template<
typename T>
6015 typename std::enable_if<std::is_pointer<T>::value, cl_int>::type
6018 return detail::errHandler(
6019 ::clSetKernelArgSVMPointer(object_, index, argPtr),
6020 __SET_KERNEL_ARGS_ERR);
6022 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6026 template <
typename T>
6027 typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6030 return detail::errHandler(
6036 __SET_KERNEL_ARGS_ERR);
6039 cl_int
setArg(cl_uint index, size_type size,
const void* argPtr)
6041 return detail::errHandler(
6042 ::clSetKernelArg(object_, index, size, argPtr),
6043 __SET_KERNEL_ARGS_ERR);
6046 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6053 return detail::errHandler(
6054 ::clSetKernelExecInfo(
6056 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6057 sizeof(
void*)*pointerList.size(),
6058 pointerList.data()));
6065 template<
int ArrayLength>
6068 return detail::errHandler(
6069 ::clSetKernelExecInfo(
6071 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6072 sizeof(
void*)*pointerList.size(),
6073 pointerList.data()));
6089 cl_bool svmEnabled_ = svmEnabled ? CL_TRUE : CL_FALSE;
6090 return detail::errHandler(
6091 ::clSetKernelExecInfo(
6093 CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM,
6100 template<
int index,
int ArrayLength,
class D,
typename T0,
typename T1,
typename... Ts>
6101 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList,
const pointer<T0, D> &t0,
const pointer<T1, D> &t1, Ts & ... ts)
6103 pointerList[index] =
static_cast<void*
>(t0.get());
6104 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6107 template<
int index,
int ArrayLength,
typename T0,
typename T1,
typename... Ts>
6108 typename std::enable_if<std::is_pointer<T0>::value,
void>::type
6109 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0, T1 t1, Ts... ts)
6111 pointerList[index] =
static_cast<void*
>(t0);
6112 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6115 template<
int index,
int ArrayLength,
typename T0,
class D>
6116 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList,
const pointer<T0, D> &t0)
6118 pointerList[index] =
static_cast<void*
>(t0.get());
6122 template<
int index,
int ArrayLength,
typename T0>
6123 typename std::enable_if<std::is_pointer<T0>::value,
void>::type
6124 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0)
6126 pointerList[index] =
static_cast<void*
>(t0);
6129 template<
typename T0,
typename... Ts>
6132 std::array<
void*, 1 +
sizeof...(Ts)> pointerList;
6134 setSVMPointersHelper<0, 1 +
sizeof...(Ts)>(pointerList, t0, ts...);
6135 return detail::errHandler(
6136 ::clSetKernelExecInfo(
6138 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6139 sizeof(
void*)*(1 +
sizeof...(Ts)),
6140 pointerList.data()));
6142 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6144 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6153 Kernel retValue(clCloneKernel(this->get(), &error));
6155 detail::errHandler(error, __CLONE_KERNEL_ERR);
6158 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6167 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6168 typedef vector<vector<unsigned char>> Binaries;
6169 typedef vector<string> Sources;
6170 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6171 typedef vector<std::pair<const void*, size_type> > Binaries;
6172 typedef vector<std::pair<const char*, size_type> > Sources;
6173 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6176 const string& source,
6182 const char * strings = source.c_str();
6183 const size_type length = source.size();
6187 object_ = ::clCreateProgramWithSource(
6188 context(), (cl_uint)1, &strings, &length, &error);
6190 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6192 if (error == CL_SUCCESS && build) {
6194 error = ::clBuildProgram(
6198 #
if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6206 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6216 const string& source,
6222 const char * strings = source.c_str();
6223 const size_type length = source.size();
6225 object_ = ::clCreateProgramWithSource(
6226 context(), (cl_uint)1, &strings, &length, &error);
6228 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6230 if (error == CL_SUCCESS && build) {
6231 error = ::clBuildProgram(
6235 #
if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6243 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6256 const Sources& sources,
6262 const size_type n = (size_type)sources.size();
6264 vector<size_type> lengths(n);
6265 vector<const char*> strings(n);
6267 for (size_type i = 0; i < n; ++i) {
6268 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6269 strings[i] = sources[(int)i].data();
6270 lengths[i] = sources[(int)i].length();
6271 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6272 strings[i] = sources[(int)i].first;
6273 lengths[i] = sources[(int)i].second;
6274 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6277 object_ = ::clCreateProgramWithSource(
6278 context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6280 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6292 const Sources& sources,
6297 const size_type n = (size_type)sources.size();
6299 vector<size_type> lengths(n);
6300 vector<const char*> strings(n);
6302 for (size_type i = 0; i < n; ++i) {
6303 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6304 strings[i] = sources[(int)i].data();
6305 lengths[i] = sources[(int)i].length();
6306 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6307 strings[i] = sources[(int)i].first;
6308 lengths[i] = sources[(int)i].second;
6309 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6312 object_ = ::clCreateProgramWithSource(
6313 context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6315 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6322 #if CL_HPP_TARGET_OPENCL_VERSION >= 210 || (CL_HPP_TARGET_OPENCL_VERSION==200 && defined(CL_HPP_USE_IL_KHR))
6328 const vector<char>& IL,
6336 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6338 object_ = ::clCreateProgramWithIL(
6339 context(),
static_cast<const void*
>(IL.data()), IL.size(), &error);
6341 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6343 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6344 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6345 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6347 return detail::errHandler(
6348 pfn_clCreateProgramWithILKHR(
6349 context(),
static_cast<const void*
>(IL.data()), IL.size(), &error);
6353 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6355 if (error == CL_SUCCESS && build) {
6357 error = ::clBuildProgram(
6361 #
if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6369 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6384 const vector<char>& IL,
6390 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6392 object_ = ::clCreateProgramWithIL(
6393 context(),
static_cast<const void*
>(IL.data()), IL.size(), &error);
6395 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6397 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6398 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6399 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6401 return detail::errHandler(
6402 pfn_clCreateProgramWithILKHR(
6403 context(),
static_cast<const void*
>(IL.data()), IL.size(), &error);
6407 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6409 if (error == CL_SUCCESS && build) {
6410 error = ::clBuildProgram(
6414 #
if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6422 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6429 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6452 const vector<Device>& devices,
6453 const Binaries& binaries,
6454 vector<cl_int>* binaryStatus = NULL,
6459 const size_type numDevices = devices.size();
6462 if(binaries.size() != numDevices) {
6463 error = CL_INVALID_VALUE;
6464 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6472 vector<size_type> lengths(numDevices);
6473 vector<const unsigned char*> images(numDevices);
6474 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6475 for (size_type i = 0; i < numDevices; ++i) {
6476 images[i] = binaries[i].data();
6477 lengths[i] = binaries[(int)i].size();
6479 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6480 for (size_type i = 0; i < numDevices; ++i) {
6481 images[i] = (
const unsigned char*)binaries[i].first;
6482 lengths[i] = binaries[(int)i].second;
6484 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6486 vector<cl_device_id> deviceIDs(numDevices);
6487 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6488 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6492 binaryStatus->resize(numDevices);
6495 object_ = ::clCreateProgramWithBinary(
6496 context(), (cl_uint) devices.size(),
6498 lengths.data(), images.data(), (binaryStatus != NULL && numDevices > 0)
6499 ? &binaryStatus->front()
6502 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6509 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6516 const vector<Device>& devices,
6517 const string& kernelNames,
6523 size_type numDevices = devices.size();
6524 vector<cl_device_id> deviceIDs(numDevices);
6525 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6526 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6529 object_ = ::clCreateProgramWithBuiltInKernels(
6531 (cl_uint) devices.size(),
6533 kernelNames.c_str(),
6536 detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR);
6541 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6552 explicit Program(
const cl_program& program,
bool retainObject =
false) :
6553 detail::Wrapper<cl_type>(program, retainObject) { }
6555 Program& operator = (
const cl_program& rhs)
6590 const vector<Device>& devices,
6591 const char* options = NULL,
6592 void (CL_CALLBACK * notifyFptr)(cl_program,
void *) = NULL,
6593 void* data = NULL)
const
6595 size_type numDevices = devices.size();
6596 vector<cl_device_id> deviceIDs(numDevices);
6598 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6599 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6602 cl_int buildError = ::clBuildProgram(
6611 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6615 const char* options = NULL,
6616 void (CL_CALLBACK * notifyFptr)(cl_program,
void *) = NULL,
6617 void* data = NULL)
const
6619 cl_int buildError = ::clBuildProgram(
6628 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6631 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6633 const char* options = NULL,
6634 void (CL_CALLBACK * notifyFptr)(cl_program,
void *) = NULL,
6635 void* data = NULL)
const
6637 cl_int error = ::clCompileProgram(
6647 return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6649 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6651 template <
typename T>
6652 cl_int getInfo(cl_program_info name, T* param)
const
6654 return detail::errHandler(
6655 detail::getInfo(&::clGetProgramInfo, object_, name, param),
6656 __GET_PROGRAM_INFO_ERR);
6659 template <cl_program_info name>
typename
6660 detail::param_traits<detail::cl_program_info, name>::param_type
6661 getInfo(cl_int* err = NULL)
const
6663 typename detail::param_traits<
6664 detail::cl_program_info, name>::param_type param;
6665 cl_int result = getInfo(name, ¶m);
6672 template <
typename T>
6673 cl_int getBuildInfo(
6674 const Device& device, cl_program_build_info name, T* param)
const
6676 return detail::errHandler(
6678 &::clGetProgramBuildInfo, object_, device(), name, param),
6679 __GET_PROGRAM_BUILD_INFO_ERR);
6682 template <cl_program_build_info name>
typename
6683 detail::param_traits<detail::cl_program_build_info, name>::param_type
6684 getBuildInfo(
const Device& device, cl_int* err = NULL)
const
6686 typename detail::param_traits<
6687 detail::cl_program_build_info, name>::param_type param;
6688 cl_int result = getBuildInfo(device, name, ¶m);
6700 template <cl_program_build_info name>
6701 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6704 cl_int result = CL_SUCCESS;
6706 auto devs = getInfo<CL_PROGRAM_DEVICES>(&result);
6707 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6711 if (result != CL_SUCCESS) {
6720 detail::cl_program_build_info, name>::param_type param;
6721 result = getBuildInfo(d, name, ¶m);
6725 if (result != CL_SUCCESS) {
6733 if (result != CL_SUCCESS) {
6739 cl_int createKernels(vector<Kernel>* kernels)
6742 cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
6743 if (err != CL_SUCCESS) {
6744 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6747 vector<cl_kernel> value(numKernels);
6749 err = ::clCreateKernelsInProgram(
6750 object_, numKernels, value.data(), NULL);
6751 if (err != CL_SUCCESS) {
6752 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6756 kernels->resize(value.size());
6760 for (size_type i = 0; i < value.size(); i++) {
6763 (*kernels)[i] = Kernel(value[i],
false);
6769 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
6781 void (CL_CALLBACK * pfn_notify)(cl_program program,
void * user_data),
6782 void * user_data = NULL)
6784 return detail::errHandler(
6785 ::clSetProgramReleaseCallback(
6789 __SET_PROGRAM_RELEASE_CALLBACK_ERR);
6796 template <
typename T>
6797 typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6800 return detail::errHandler(
6801 ::clSetProgramSpecializationConstant(
6806 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6815 return detail::errHandler(
6816 ::clSetProgramSpecializationConstant(
6821 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6823 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
6826 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6827 inline Program linkProgram(
6830 const char* options = NULL,
6831 void (CL_CALLBACK * notifyFptr)(cl_program,
void *) = NULL,
6835 cl_int error_local = CL_SUCCESS;
6837 cl_program programs[2] = { input1(), input2() };
6839 Context ctx = input1.getInfo<CL_PROGRAM_CONTEXT>(&error_local);
6840 if(error_local!=CL_SUCCESS) {
6841 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
6844 cl_program prog = ::clLinkProgram(
6855 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
6860 return Program(prog);
6863 inline Program linkProgram(
6864 vector<Program> inputPrograms,
6865 const char* options = NULL,
6866 void (CL_CALLBACK * notifyFptr)(cl_program,
void *) = NULL,
6870 cl_int error_local = CL_SUCCESS;
6872 vector<cl_program> programs(inputPrograms.size());
6874 for (
unsigned int i = 0; i < inputPrograms.size(); i++) {
6875 programs[i] = inputPrograms[i]();
6879 if(inputPrograms.size() > 0) {
6880 ctx = inputPrograms[0].getInfo<CL_PROGRAM_CONTEXT>(&error_local);
6881 if(error_local!=CL_SUCCESS) {
6882 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
6885 cl_program prog = ::clLinkProgram(
6890 (cl_uint)inputPrograms.size(),
6896 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
6901 return Program(prog,
false);
6903 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6907 inline cl_int cl::Program::getInfo(cl_program_info name, vector<vector<unsigned char>>* param)
const
6909 if (name != CL_PROGRAM_BINARIES) {
6910 return CL_INVALID_VALUE;
6916 vector<size_type> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>();
6917 size_type numBinaries = sizes.size();
6920 param->resize(numBinaries);
6921 for (size_type i = 0; i < numBinaries; ++i) {
6922 (*param)[i].resize(sizes[i]);
6925 return detail::errHandler(
6926 detail::getInfo(&::clGetProgramInfo, object_, name, param),
6927 __GET_PROGRAM_INFO_ERR);
6934 inline vector<vector<unsigned char>> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err)
const
6936 vector<vector<unsigned char>> binariesVectors;
6938 cl_int result = getInfo(CL_PROGRAM_BINARIES, &binariesVectors);
6942 return binariesVectors;
6945 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
6950 cl_uchar ucValue = value ? CL_UCHAR_MAX : 0;
6951 return detail::errHandler(
6952 ::clSetProgramSpecializationConstant(
6957 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6959 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
6961 inline Kernel::Kernel(
const Program& program,
const char* name, cl_int* err)
6965 object_ = ::clCreateKernel(program(), name, &error);
6966 detail::errHandler(error, __CREATE_KERNEL_ERR);
6974 enum class QueueProperties : cl_command_queue_properties
6977 Profiling = CL_QUEUE_PROFILING_ENABLE,
6978 OutOfOrder = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,
6981 inline QueueProperties operator|(QueueProperties lhs, QueueProperties rhs)
6983 return static_cast<QueueProperties
>(
static_cast<cl_command_queue_properties
>(lhs) |
static_cast<cl_command_queue_properties
>(rhs));
6992 static std::once_flag default_initialized_;
6994 static cl_int default_error_;
7001 static void makeDefault()
7006 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
7013 if (error != CL_SUCCESS) {
7014 default_error_ = error;
7018 default_ =
CommandQueue(context, device, 0, &default_error_);
7021 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
7022 catch (cl::Error &e) {
7023 default_error_ = e.err();
7033 static void makeDefaultProvided(
const CommandQueue &c) {
7038 #ifdef CL_HPP_UNIT_TEST_ENABLE
7045 static void unitTestClearDefault() {
7048 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
7056 cl_command_queue_properties properties,
7062 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7064 if (error != CL_SUCCESS) {
7071 bool useWithProperties;
7073 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7076 cl_uint version = detail::getContextPlatformVersion(context());
7077 useWithProperties = (version >= 0x20000);
7079 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7080 useWithProperties =
true;
7082 useWithProperties =
false;
7085 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7086 if (useWithProperties) {
7087 cl_queue_properties queue_properties[] = {
7088 CL_QUEUE_PROPERTIES, properties, 0 };
7089 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7090 object_ = ::clCreateCommandQueueWithProperties(
7091 context(), device(), queue_properties, &error);
7094 error = CL_INVALID_QUEUE_PROPERTIES;
7097 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7102 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7103 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7104 if (!useWithProperties) {
7105 object_ = ::clCreateCommandQueue(
7106 context(), device(), properties, &error);
7108 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7113 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7122 QueueProperties properties,
7128 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7130 if (error != CL_SUCCESS) {
7137 bool useWithProperties;
7139 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7142 cl_uint version = detail::getContextPlatformVersion(context());
7143 useWithProperties = (version >= 0x20000);
7145 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7146 useWithProperties =
true;
7148 useWithProperties =
false;
7151 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7152 if (useWithProperties) {
7153 cl_queue_properties queue_properties[] = {
7154 CL_QUEUE_PROPERTIES,
static_cast<cl_queue_properties
>(properties), 0 };
7156 object_ = ::clCreateCommandQueueWithProperties(
7157 context(), device(), queue_properties, &error);
7159 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7164 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7165 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7166 if (!useWithProperties) {
7167 object_ = ::clCreateCommandQueue(
7168 context(), device(),
static_cast<cl_command_queue_properties
>(properties), &error);
7170 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7175 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7186 cl_command_queue_properties properties = 0,
7190 bool useWithProperties;
7191 vector<cl::Device> devices;
7192 error = context.
getInfo(CL_CONTEXT_DEVICES, &devices);
7194 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7196 if (error != CL_SUCCESS)
7204 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7207 cl_uint version = detail::getContextPlatformVersion(context());
7208 useWithProperties = (version >= 0x20000);
7210 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7211 useWithProperties =
true;
7213 useWithProperties =
false;
7216 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7217 if (useWithProperties) {
7218 cl_queue_properties queue_properties[] = {
7219 CL_QUEUE_PROPERTIES, properties, 0 };
7220 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7221 object_ = ::clCreateCommandQueueWithProperties(
7222 context(), devices[0](), queue_properties, &error);
7225 error = CL_INVALID_QUEUE_PROPERTIES;
7228 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7233 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7234 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7235 if (!useWithProperties) {
7236 object_ = ::clCreateCommandQueue(
7237 context(), devices[0](), properties, &error);
7239 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7244 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7253 QueueProperties properties,
7257 bool useWithProperties;
7258 vector<cl::Device> devices;
7259 error = context.
getInfo(CL_CONTEXT_DEVICES, &devices);
7261 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7263 if (error != CL_SUCCESS)
7271 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7274 cl_uint version = detail::getContextPlatformVersion(context());
7275 useWithProperties = (version >= 0x20000);
7277 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7278 useWithProperties =
true;
7280 useWithProperties =
false;
7283 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7284 if (useWithProperties) {
7285 cl_queue_properties queue_properties[] = {
7286 CL_QUEUE_PROPERTIES,
static_cast<cl_queue_properties
>(properties), 0 };
7287 object_ = ::clCreateCommandQueueWithProperties(
7288 context(), devices[0](), queue_properties, &error);
7290 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7295 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7296 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7297 if (!useWithProperties) {
7298 object_ = ::clCreateCommandQueue(
7299 context(), devices[0](),
static_cast<cl_command_queue_properties
>(properties), &error);
7301 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7306 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7316 cl_command_queue_properties properties = 0,
7320 bool useWithProperties;
7322 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7325 cl_uint version = detail::getContextPlatformVersion(context());
7326 useWithProperties = (version >= 0x20000);
7328 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7329 useWithProperties =
true;
7331 useWithProperties =
false;
7334 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7335 if (useWithProperties) {
7336 cl_queue_properties queue_properties[] = {
7337 CL_QUEUE_PROPERTIES, properties, 0 };
7338 object_ = ::clCreateCommandQueueWithProperties(
7339 context(), device(), queue_properties, &error);
7341 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7346 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7347 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7348 if (!useWithProperties) {
7349 object_ = ::clCreateCommandQueue(
7350 context(), device(), properties, &error);
7352 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7357 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7367 QueueProperties properties,
7371 bool useWithProperties;
7373 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7376 cl_uint version = detail::getContextPlatformVersion(context());
7377 useWithProperties = (version >= 0x20000);
7379 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7380 useWithProperties =
true;
7382 useWithProperties =
false;
7385 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7386 if (useWithProperties) {
7387 cl_queue_properties queue_properties[] = {
7388 CL_QUEUE_PROPERTIES,
static_cast<cl_queue_properties
>(properties), 0 };
7389 object_ = ::clCreateCommandQueueWithProperties(
7390 context(), device(), queue_properties, &error);
7392 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7397 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7398 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7399 if (!useWithProperties) {
7400 object_ = ::clCreateCommandQueue(
7401 context(), device(),
static_cast<cl_command_queue_properties
>(properties), &error);
7403 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7408 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7413 std::call_once(default_initialized_, makeDefault);
7414 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7415 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7416 #else // CL_HPP_TARGET_OPENCL_VERSION >= 200
7417 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_ERR);
7418 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7420 *err = default_error_;
7434 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_queue));
7435 detail::errHandler(default_error_);
7448 explicit CommandQueue(
const cl_command_queue& commandQueue,
bool retainObject =
false) :
7449 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
7485 template <
typename T>
7486 cl_int getInfo(cl_command_queue_info name, T* param)
const
7488 return detail::errHandler(
7490 &::clGetCommandQueueInfo, object_, name, param),
7491 __GET_COMMAND_QUEUE_INFO_ERR);
7494 template <cl_command_queue_info name>
typename
7495 detail::param_traits<detail::cl_command_queue_info, name>::param_type
7496 getInfo(cl_int* err = NULL)
const
7498 typename detail::param_traits<
7499 detail::cl_command_queue_info, name>::param_type param;
7500 cl_int result = getInfo(name, ¶m);
7507 cl_int enqueueReadBuffer(
7508 const Buffer& buffer,
7513 const vector<Event>* events = NULL,
7514 Event* event = NULL)
const
7517 cl_int err = detail::errHandler(
7518 ::clEnqueueReadBuffer(
7519 object_, buffer(), blocking, offset, size,
7521 (events != NULL) ? (cl_uint) events->size() : 0,
7522 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7523 (event != NULL) ? &tmp : NULL),
7524 __ENQUEUE_READ_BUFFER_ERR);
7526 if (event != NULL && err == CL_SUCCESS)
7532 cl_int enqueueWriteBuffer(
7533 const Buffer& buffer,
7538 const vector<Event>* events = NULL,
7539 Event* event = NULL)
const
7542 cl_int err = detail::errHandler(
7543 ::clEnqueueWriteBuffer(
7544 object_, buffer(), blocking, offset, size,
7546 (events != NULL) ? (cl_uint) events->size() : 0,
7547 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7548 (event != NULL) ? &tmp : NULL),
7549 __ENQUEUE_WRITE_BUFFER_ERR);
7551 if (event != NULL && err == CL_SUCCESS)
7557 cl_int enqueueCopyBuffer(
7560 size_type src_offset,
7561 size_type dst_offset,
7563 const vector<Event>* events = NULL,
7564 Event* event = NULL)
const
7567 cl_int err = detail::errHandler(
7568 ::clEnqueueCopyBuffer(
7569 object_, src(), dst(), src_offset, dst_offset, size,
7570 (events != NULL) ? (cl_uint) events->size() : 0,
7571 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7572 (event != NULL) ? &tmp : NULL),
7573 __ENQEUE_COPY_BUFFER_ERR);
7575 if (event != NULL && err == CL_SUCCESS)
7580 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
7581 cl_int enqueueReadBufferRect(
7582 const Buffer& buffer,
7584 const array<size_type, 3>& buffer_offset,
7585 const array<size_type, 3>& host_offset,
7586 const array<size_type, 3>& region,
7587 size_type buffer_row_pitch,
7588 size_type buffer_slice_pitch,
7589 size_type host_row_pitch,
7590 size_type host_slice_pitch,
7592 const vector<Event>* events = NULL,
7593 Event* event = NULL)
const
7596 cl_int err = detail::errHandler(
7597 ::clEnqueueReadBufferRect(
7601 buffer_offset.data(),
7609 (events != NULL) ? (cl_uint) events->size() : 0,
7610 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7611 (event != NULL) ? &tmp : NULL),
7612 __ENQUEUE_READ_BUFFER_RECT_ERR);
7614 if (event != NULL && err == CL_SUCCESS)
7620 cl_int enqueueWriteBufferRect(
7621 const Buffer& buffer,
7623 const array<size_type, 3>& buffer_offset,
7624 const array<size_type, 3>& host_offset,
7625 const array<size_type, 3>& region,
7626 size_type buffer_row_pitch,
7627 size_type buffer_slice_pitch,
7628 size_type host_row_pitch,
7629 size_type host_slice_pitch,
7631 const vector<Event>* events = NULL,
7632 Event* event = NULL)
const
7635 cl_int err = detail::errHandler(
7636 ::clEnqueueWriteBufferRect(
7640 buffer_offset.data(),
7648 (events != NULL) ? (cl_uint) events->size() : 0,
7649 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7650 (event != NULL) ? &tmp : NULL),
7651 __ENQUEUE_WRITE_BUFFER_RECT_ERR);
7653 if (event != NULL && err == CL_SUCCESS)
7659 cl_int enqueueCopyBufferRect(
7662 const array<size_type, 3>& src_origin,
7663 const array<size_type, 3>& dst_origin,
7664 const array<size_type, 3>& region,
7665 size_type src_row_pitch,
7666 size_type src_slice_pitch,
7667 size_type dst_row_pitch,
7668 size_type dst_slice_pitch,
7669 const vector<Event>* events = NULL,
7670 Event* event = NULL)
const
7673 cl_int err = detail::errHandler(
7674 ::clEnqueueCopyBufferRect(
7685 (events != NULL) ? (cl_uint) events->size() : 0,
7686 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7687 (event != NULL) ? &tmp : NULL),
7688 __ENQEUE_COPY_BUFFER_RECT_ERR);
7690 if (event != NULL && err == CL_SUCCESS)
7695 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
7696 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
7708 template<
typename PatternType>
7711 PatternType pattern,
7714 const vector<Event>* events = NULL,
7715 Event* event = NULL)
const
7718 cl_int err = detail::errHandler(
7719 ::clEnqueueFillBuffer(
7722 static_cast<void*
>(&pattern),
7723 sizeof(PatternType),
7726 (events != NULL) ? (cl_uint) events->size() : 0,
7727 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7728 (event != NULL) ? &tmp : NULL),
7729 __ENQUEUE_FILL_BUFFER_ERR);
7731 if (event != NULL && err == CL_SUCCESS)
7736 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7738 cl_int enqueueReadImage(
7741 const array<size_type, 3>& origin,
7742 const array<size_type, 3>& region,
7743 size_type row_pitch,
7744 size_type slice_pitch,
7746 const vector<Event>* events = NULL,
7747 Event* event = NULL)
const
7750 cl_int err = detail::errHandler(
7751 ::clEnqueueReadImage(
7760 (events != NULL) ? (cl_uint) events->size() : 0,
7761 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7762 (event != NULL) ? &tmp : NULL),
7763 __ENQUEUE_READ_IMAGE_ERR);
7765 if (event != NULL && err == CL_SUCCESS)
7771 cl_int enqueueWriteImage(
7774 const array<size_type, 3>& origin,
7775 const array<size_type, 3>& region,
7776 size_type row_pitch,
7777 size_type slice_pitch,
7779 const vector<Event>* events = NULL,
7780 Event* event = NULL)
const
7783 cl_int err = detail::errHandler(
7784 ::clEnqueueWriteImage(
7793 (events != NULL) ? (cl_uint) events->size() : 0,
7794 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7795 (event != NULL) ? &tmp : NULL),
7796 __ENQUEUE_WRITE_IMAGE_ERR);
7798 if (event != NULL && err == CL_SUCCESS)
7804 cl_int enqueueCopyImage(
7807 const array<size_type, 3>& src_origin,
7808 const array<size_type, 3>& dst_origin,
7809 const array<size_type, 3>& region,
7810 const vector<Event>* events = NULL,
7811 Event* event = NULL)
const
7814 cl_int err = detail::errHandler(
7815 ::clEnqueueCopyImage(
7822 (events != NULL) ? (cl_uint) events->size() : 0,
7823 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7824 (event != NULL) ? &tmp : NULL),
7825 __ENQUEUE_COPY_IMAGE_ERR);
7827 if (event != NULL && err == CL_SUCCESS)
7833 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
7843 cl_float4 fillColor,
7844 const array<size_type, 3>& origin,
7845 const array<size_type, 3>& region,
7846 const vector<Event>* events = NULL,
7847 Event* event = NULL)
const
7850 cl_int err = detail::errHandler(
7851 ::clEnqueueFillImage(
7854 static_cast<void*
>(&fillColor),
7857 (events != NULL) ? (cl_uint) events->size() : 0,
7858 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7859 (event != NULL) ? &tmp : NULL),
7860 __ENQUEUE_FILL_IMAGE_ERR);
7862 if (event != NULL && err == CL_SUCCESS)
7878 const array<size_type, 3>& origin,
7879 const array<size_type, 3>& region,
7880 const vector<Event>* events = NULL,
7881 Event* event = NULL)
const
7884 cl_int err = detail::errHandler(
7885 ::clEnqueueFillImage(
7888 static_cast<void*
>(&fillColor),
7891 (events != NULL) ? (cl_uint) events->size() : 0,
7892 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7893 (event != NULL) ? &tmp : NULL),
7894 __ENQUEUE_FILL_IMAGE_ERR);
7896 if (event != NULL && err == CL_SUCCESS)
7912 const array<size_type, 3>& origin,
7913 const array<size_type, 3>& region,
7914 const vector<Event>* events = NULL,
7915 Event* event = NULL)
const
7918 cl_int err = detail::errHandler(
7919 ::clEnqueueFillImage(
7922 static_cast<void*
>(&fillColor),
7925 (events != NULL) ? (cl_uint) events->size() : 0,
7926 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7927 (event != NULL) ? &tmp : NULL),
7928 __ENQUEUE_FILL_IMAGE_ERR);
7930 if (event != NULL && err == CL_SUCCESS)
7935 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7937 cl_int enqueueCopyImageToBuffer(
7940 const array<size_type, 3>& src_origin,
7941 const array<size_type, 3>& region,
7942 size_type dst_offset,
7943 const vector<Event>* events = NULL,
7944 Event* event = NULL)
const
7947 cl_int err = detail::errHandler(
7948 ::clEnqueueCopyImageToBuffer(
7955 (events != NULL) ? (cl_uint) events->size() : 0,
7956 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7957 (event != NULL) ? &tmp : NULL),
7958 __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
7960 if (event != NULL && err == CL_SUCCESS)
7966 cl_int enqueueCopyBufferToImage(
7969 size_type src_offset,
7970 const array<size_type, 3>& dst_origin,
7971 const array<size_type, 3>& region,
7972 const vector<Event>* events = NULL,
7973 Event* event = NULL)
const
7976 cl_int err = detail::errHandler(
7977 ::clEnqueueCopyBufferToImage(
7984 (events != NULL) ? (cl_uint) events->size() : 0,
7985 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7986 (event != NULL) ? &tmp : NULL),
7987 __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
7989 if (event != NULL && err == CL_SUCCESS)
7995 void* enqueueMapBuffer(
7996 const Buffer& buffer,
8001 const vector<Event>* events = NULL,
8002 Event* event = NULL,
8003 cl_int* err = NULL)
const
8007 void * result = ::clEnqueueMapBuffer(
8008 object_, buffer(), blocking, flags, offset, size,
8009 (events != NULL) ? (cl_uint) events->size() : 0,
8010 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8011 (event != NULL) ? &tmp : NULL,
8014 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
8018 if (event != NULL && error == CL_SUCCESS)
8024 void* enqueueMapImage(
8025 const Image& buffer,
8028 const array<size_type, 3>& origin,
8029 const array<size_type, 3>& region,
8030 size_type * row_pitch,
8031 size_type * slice_pitch,
8032 const vector<Event>* events = NULL,
8033 Event* event = NULL,
8034 cl_int* err = NULL)
const
8038 void * result = ::clEnqueueMapImage(
8039 object_, buffer(), blocking, flags,
8042 row_pitch, slice_pitch,
8043 (events != NULL) ? (cl_uint) events->size() : 0,
8044 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8045 (event != NULL) ? &tmp : NULL,
8048 detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
8052 if (event != NULL && error == CL_SUCCESS)
8057 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8062 template<
typename T>
8068 const vector<Event>* events = NULL,
8069 Event* event = NULL)
const
8072 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8073 object_, blocking, flags,
static_cast<void*
>(ptr), size,
8074 (events != NULL) ? (cl_uint)events->size() : 0,
8075 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8076 (event != NULL) ? &tmp : NULL),
8077 __ENQUEUE_MAP_BUFFER_ERR);
8079 if (event != NULL && err == CL_SUCCESS)
8090 template<
typename T,
class D>
8092 cl::pointer<T, D> &ptr,
8096 const vector<Event>* events = NULL,
8097 Event* event = NULL)
const
8100 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8101 object_, blocking, flags,
static_cast<void*
>(ptr.get()), size,
8102 (events != NULL) ? (cl_uint)events->size() : 0,
8103 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8104 (event != NULL) ? &tmp : NULL),
8105 __ENQUEUE_MAP_BUFFER_ERR);
8107 if (event != NULL && err == CL_SUCCESS)
8117 template<
typename T,
class Alloc>
8119 cl::vector<T, Alloc> &container,
8122 const vector<Event>* events = NULL,
8123 Event* event = NULL)
const
8126 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8127 object_, blocking, flags,
static_cast<void*
>(container.data()), container.size(),
8128 (events != NULL) ? (cl_uint)events->size() : 0,
8129 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8130 (event != NULL) ? &tmp : NULL),
8131 __ENQUEUE_MAP_BUFFER_ERR);
8133 if (event != NULL && err == CL_SUCCESS)
8138 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8140 cl_int enqueueUnmapMemObject(
8143 const vector<Event>* events = NULL,
8144 Event* event = NULL)
const
8147 cl_int err = detail::errHandler(
8148 ::clEnqueueUnmapMemObject(
8149 object_, memory(), mapped_ptr,
8150 (events != NULL) ? (cl_uint) events->size() : 0,
8151 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8152 (event != NULL) ? &tmp : NULL),
8153 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8155 if (event != NULL && err == CL_SUCCESS)
8162 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8167 template<
typename T>
8170 const vector<Event>* events = NULL,
8171 Event* event = NULL)
const
8174 cl_int err = detail::errHandler(
8175 ::clEnqueueSVMUnmap(
8176 object_,
static_cast<void*
>(ptr),
8177 (events != NULL) ? (cl_uint)events->size() : 0,
8178 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8179 (event != NULL) ? &tmp : NULL),
8180 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8182 if (event != NULL && err == CL_SUCCESS)
8192 template<
typename T,
class D>
8194 cl::pointer<T, D> &ptr,
8195 const vector<Event>* events = NULL,
8196 Event* event = NULL)
const
8199 cl_int err = detail::errHandler(
8200 ::clEnqueueSVMUnmap(
8201 object_,
static_cast<void*
>(ptr.get()),
8202 (events != NULL) ? (cl_uint)events->size() : 0,
8203 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8204 (event != NULL) ? &tmp : NULL),
8205 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8207 if (event != NULL && err == CL_SUCCESS)
8217 template<
typename T,
class Alloc>
8219 cl::vector<T, Alloc> &container,
8220 const vector<Event>* events = NULL,
8221 Event* event = NULL)
const
8224 cl_int err = detail::errHandler(
8225 ::clEnqueueSVMUnmap(
8226 object_,
static_cast<void*
>(container.data()),
8227 (events != NULL) ? (cl_uint)events->size() : 0,
8228 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8229 (event != NULL) ? &tmp : NULL),
8230 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8232 if (event != NULL && err == CL_SUCCESS)
8237 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8239 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8252 const vector<Event> *events = 0,
8253 Event *event = 0)
const
8256 cl_int err = detail::errHandler(
8257 ::clEnqueueMarkerWithWaitList(
8259 (events != NULL) ? (cl_uint) events->size() : 0,
8260 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8261 (event != NULL) ? &tmp : NULL),
8262 __ENQUEUE_MARKER_WAIT_LIST_ERR);
8264 if (event != NULL && err == CL_SUCCESS)
8282 const vector<Event> *events = 0,
8283 Event *event = 0)
const
8286 cl_int err = detail::errHandler(
8287 ::clEnqueueBarrierWithWaitList(
8289 (events != NULL) ? (cl_uint) events->size() : 0,
8290 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8291 (event != NULL) ? &tmp : NULL),
8292 __ENQUEUE_BARRIER_WAIT_LIST_ERR);
8294 if (event != NULL && err == CL_SUCCESS)
8305 const vector<Memory> &memObjects,
8306 cl_mem_migration_flags flags,
8307 const vector<Event>* events = NULL,
8313 vector<cl_mem> localMemObjects(memObjects.size());
8315 for(
int i = 0; i < (int)memObjects.size(); ++i ) {
8316 localMemObjects[i] = memObjects[i]();
8319 cl_int err = detail::errHandler(
8320 ::clEnqueueMigrateMemObjects(
8322 (cl_uint)memObjects.size(),
8323 localMemObjects.data(),
8325 (events != NULL) ? (cl_uint) events->size() : 0,
8326 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8327 (event != NULL) ? &tmp : NULL),
8328 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8330 if (event != NULL && err == CL_SUCCESS)
8335 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8338 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8344 template<
typename T>
8346 const cl::vector<T*> &svmRawPointers,
8347 const cl::vector<size_type> &sizes,
8348 cl_mem_migration_flags flags = 0,
8349 const vector<Event>* events = NULL,
8350 Event* event = NULL)
const
8353 cl_int err = detail::errHandler(::clEnqueueSVMMigrateMem(
8355 svmRawPointers.size(),
static_cast<void**
>(svmRawPointers.data()),
8358 (events != NULL) ? (cl_uint)events->size() : 0,
8359 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8360 (event != NULL) ? &tmp : NULL),
8361 __ENQUEUE_MIGRATE_SVM_ERR);
8363 if (event != NULL && err == CL_SUCCESS)
8373 template<
typename T>
8375 const cl::vector<T*> &svmRawPointers,
8376 cl_mem_migration_flags flags = 0,
8377 const vector<Event>* events = NULL,
8378 Event* event = NULL)
const
8380 return enqueueMigrateSVM(svmRawPointers, cl::vector<size_type>(svmRawPointers.size()), flags, events, event);
8389 template<
typename T,
class D>
8391 const cl::vector<cl::pointer<T, D>> &svmPointers,
8392 const cl::vector<size_type> &sizes,
8393 cl_mem_migration_flags flags = 0,
8394 const vector<Event>* events = NULL,
8395 Event* event = NULL)
const
8397 cl::vector<void*> svmRawPointers;
8398 svmRawPointers.reserve(svmPointers.size());
8399 for (
auto p : svmPointers) {
8400 svmRawPointers.push_back(
static_cast<void*
>(p.get()));
8411 template<
typename T,
class D>
8413 const cl::vector<cl::pointer<T, D>> &svmPointers,
8414 cl_mem_migration_flags flags = 0,
8415 const vector<Event>* events = NULL,
8416 Event* event = NULL)
const
8418 return enqueueMigrateSVM(svmPointers, cl::vector<size_type>(svmPointers.size()), flags, events, event);
8426 template<
typename T,
class Alloc>
8428 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8429 const cl::vector<size_type> &sizes,
8430 cl_mem_migration_flags flags = 0,
8431 const vector<Event>* events = NULL,
8432 Event* event = NULL)
const
8434 cl::vector<void*> svmRawPointers;
8435 svmRawPointers.reserve(svmContainers.size());
8436 for (
auto p : svmContainers) {
8437 svmRawPointers.push_back(
static_cast<void*
>(p.data()));
8447 template<
typename T,
class Alloc>
8449 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8450 cl_mem_migration_flags flags = 0,
8451 const vector<Event>* events = NULL,
8452 Event* event = NULL)
const
8454 return enqueueMigrateSVM(svmContainers, cl::vector<size_type>(svmContainers.size()), flags, events, event);
8457 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8459 cl_int enqueueNDRangeKernel(
8463 const NDRange& local = NullRange,
8464 const vector<Event>* events = NULL,
8465 Event* event = NULL)
const
8468 cl_int err = detail::errHandler(
8469 ::clEnqueueNDRangeKernel(
8470 object_, kernel(), (cl_uint) global.
dimensions(),
8471 offset.
dimensions() != 0 ? (
const size_type*) offset : NULL,
8472 (
const size_type*) global,
8473 local.dimensions() != 0 ? (
const size_type*) local : NULL,
8474 (events != NULL) ? (cl_uint) events->size() : 0,
8475 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8476 (event != NULL) ? &tmp : NULL),
8477 __ENQUEUE_NDRANGE_KERNEL_ERR);
8479 if (event != NULL && err == CL_SUCCESS)
8485 #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8486 CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_int enqueueTask(
8487 const Kernel& kernel,
8488 const vector<Event>* events = NULL,
8489 Event* event = NULL)
const CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED
8492 cl_int err = detail::errHandler(
8495 (events != NULL) ? (cl_uint) events->size() : 0,
8496 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8497 (event != NULL) ? &tmp : NULL),
8498 __ENQUEUE_TASK_ERR);
8500 if (event != NULL && err == CL_SUCCESS)
8505 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8507 cl_int enqueueNativeKernel(
8508 void (CL_CALLBACK *userFptr)(
void *),
8509 std::pair<void*, size_type> args,
8510 const vector<Memory>* mem_objects = NULL,
8511 const vector<const void*>* mem_locs = NULL,
8512 const vector<Event>* events = NULL,
8513 Event* event = NULL)
const
8515 size_type elements = 0;
8516 if (mem_objects != NULL) {
8517 elements = mem_objects->size();
8519 vector<cl_mem> mems(elements);
8520 for (
unsigned int i = 0; i < elements; i++) {
8521 mems[i] = ((*mem_objects)[i])();
8525 cl_int err = detail::errHandler(
8526 ::clEnqueueNativeKernel(
8527 object_, userFptr, args.first, args.second,
8528 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8530 (mem_locs != NULL && mem_locs->size() > 0) ? (
const void **) &mem_locs->front() : NULL,
8531 (events != NULL) ? (cl_uint) events->size() : 0,
8532 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8533 (event != NULL) ? &tmp : NULL),
8534 __ENQUEUE_NATIVE_KERNEL);
8536 if (event != NULL && err == CL_SUCCESS)
8545 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8546 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
8550 cl_int err = detail::errHandler(
8553 (event != NULL) ? &tmp : NULL),
8554 __ENQUEUE_MARKER_ERR);
8556 if (event != NULL && err == CL_SUCCESS)
8562 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
8563 cl_int enqueueWaitForEvents(
const vector<Event>& events)
const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
8565 return detail::errHandler(
8566 ::clEnqueueWaitForEvents(
8568 (cl_uint) events.size(),
8569 events.size() > 0 ? (
const cl_event*) &events.front() : NULL),
8570 __ENQUEUE_WAIT_FOR_EVENTS_ERR);
8572 #endif // defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8574 cl_int enqueueAcquireGLObjects(
8575 const vector<Memory>* mem_objects = NULL,
8576 const vector<Event>* events = NULL,
8577 Event* event = NULL)
const
8580 cl_int err = detail::errHandler(
8581 ::clEnqueueAcquireGLObjects(
8583 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8584 (mem_objects != NULL && mem_objects->size() > 0) ? (
const cl_mem *) &mem_objects->front(): NULL,
8585 (events != NULL) ? (cl_uint) events->size() : 0,
8586 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8587 (event != NULL) ? &tmp : NULL),
8588 __ENQUEUE_ACQUIRE_GL_ERR);
8590 if (event != NULL && err == CL_SUCCESS)
8596 cl_int enqueueReleaseGLObjects(
8597 const vector<Memory>* mem_objects = NULL,
8598 const vector<Event>* events = NULL,
8599 Event* event = NULL)
const
8602 cl_int err = detail::errHandler(
8603 ::clEnqueueReleaseGLObjects(
8605 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8606 (mem_objects != NULL && mem_objects->size() > 0) ? (
const cl_mem *) &mem_objects->front(): NULL,
8607 (events != NULL) ? (cl_uint) events->size() : 0,
8608 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8609 (event != NULL) ? &tmp : NULL),
8610 __ENQUEUE_RELEASE_GL_ERR);
8612 if (event != NULL && err == CL_SUCCESS)
8618 #if defined (CL_HPP_USE_DX_INTEROP)
8619 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
8620 cl_command_queue command_queue, cl_uint num_objects,
8621 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8622 const cl_event* event_wait_list, cl_event* event);
8623 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
8624 cl_command_queue command_queue, cl_uint num_objects,
8625 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8626 const cl_event* event_wait_list, cl_event* event);
8628 cl_int enqueueAcquireD3D10Objects(
8629 const vector<Memory>* mem_objects = NULL,
8630 const vector<Event>* events = NULL,
8631 Event* event = NULL)
const
8633 static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
8634 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8635 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8636 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8637 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8638 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireD3D10ObjectsKHR);
8640 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
8641 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueAcquireD3D10ObjectsKHR);
8645 cl_int err = detail::errHandler(
8646 pfn_clEnqueueAcquireD3D10ObjectsKHR(
8648 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8649 (mem_objects != NULL && mem_objects->size() > 0) ? (
const cl_mem *) &mem_objects->front(): NULL,
8650 (events != NULL) ? (cl_uint) events->size() : 0,
8651 (events != NULL) ? (cl_event*) &events->front() : NULL,
8652 (event != NULL) ? &tmp : NULL),
8653 __ENQUEUE_ACQUIRE_GL_ERR);
8655 if (event != NULL && err == CL_SUCCESS)
8661 cl_int enqueueReleaseD3D10Objects(
8662 const vector<Memory>* mem_objects = NULL,
8663 const vector<Event>* events = NULL,
8664 Event* event = NULL)
const
8666 static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL;
8667 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8668 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8669 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8670 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8671 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseD3D10ObjectsKHR);
8672 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8673 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
8674 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueReleaseD3D10ObjectsKHR);
8675 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
8678 cl_int err = detail::errHandler(
8679 pfn_clEnqueueReleaseD3D10ObjectsKHR(
8681 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8682 (mem_objects != NULL && mem_objects->size() > 0) ? (
const cl_mem *) &mem_objects->front(): NULL,
8683 (events != NULL) ? (cl_uint) events->size() : 0,
8684 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8685 (event != NULL) ? &tmp : NULL),
8686 __ENQUEUE_RELEASE_GL_ERR);
8688 if (event != NULL && err == CL_SUCCESS)
8698 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8699 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
8702 return detail::errHandler(
8703 ::clEnqueueBarrier(object_),
8704 __ENQUEUE_BARRIER_ERR);
8706 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
8708 cl_int flush()
const
8710 return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
8713 cl_int finish()
const
8715 return detail::errHandler(::clFinish(object_), __FINISH_ERR);
8719 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::default_initialized_;
8720 CL_HPP_DEFINE_STATIC_MEMBER_ CommandQueue CommandQueue::default_;
8721 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int CommandQueue::default_error_ = CL_SUCCESS;
8724 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8725 enum class DeviceQueueProperties : cl_command_queue_properties
8728 Profiling = CL_QUEUE_PROFILING_ENABLE,
8731 inline DeviceQueueProperties operator|(DeviceQueueProperties lhs, DeviceQueueProperties rhs)
8733 return static_cast<DeviceQueueProperties
>(
static_cast<cl_command_queue_properties
>(lhs) |
static_cast<cl_command_queue_properties
>(rhs));
8757 cl_command_queue_properties mergedProperties =
8758 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE |
static_cast<cl_command_queue_properties
>(properties);
8760 cl_queue_properties queue_properties[] = {
8761 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8762 object_ = ::clCreateCommandQueueWithProperties(
8763 context(), device(), queue_properties, &error);
8765 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8777 DeviceQueueProperties properties = DeviceQueueProperties::None,
8782 cl_command_queue_properties mergedProperties =
8783 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE |
static_cast<cl_command_queue_properties
>(properties);
8784 cl_queue_properties queue_properties[] = {
8785 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8786 object_ = ::clCreateCommandQueueWithProperties(
8787 context(), device(), queue_properties, &error);
8789 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8802 DeviceQueueProperties properties = DeviceQueueProperties::None,
8807 cl_command_queue_properties mergedProperties =
8808 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE |
static_cast<cl_command_queue_properties
>(properties);
8809 cl_queue_properties queue_properties[] = {
8810 CL_QUEUE_PROPERTIES, mergedProperties,
8811 CL_QUEUE_SIZE, queueSize,
8813 object_ = ::clCreateCommandQueueWithProperties(
8814 context(), device(), queue_properties, &error);
8816 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8829 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
8865 template <
typename T>
8866 cl_int getInfo(cl_command_queue_info name, T* param)
const
8868 return detail::errHandler(
8870 &::clGetCommandQueueInfo, object_, name, param),
8871 __GET_COMMAND_QUEUE_INFO_ERR);
8874 template <cl_command_queue_info name>
typename
8875 detail::param_traits<detail::cl_command_queue_info, name>::param_type
8876 getInfo(cl_int* err = NULL)
const
8878 typename detail::param_traits<
8879 detail::cl_command_queue_info, name>::param_type param;
8880 cl_int result = getInfo(name, ¶m);
8894 cl_int *err =
nullptr)
8900 cl_command_queue_properties properties =
8901 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
8902 cl_queue_properties queue_properties[] = {
8903 CL_QUEUE_PROPERTIES, properties,
8906 ::clCreateCommandQueueWithProperties(
8907 context(), device(), queue_properties, &error));
8909 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8924 const Context &context,
const Device &device, cl_int *err =
nullptr)
8928 cl_command_queue_properties properties =
8929 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
8930 cl_queue_properties queue_properties[] = {
8931 CL_QUEUE_PROPERTIES, properties,
8934 ::clCreateCommandQueueWithProperties(
8935 context(), device(), queue_properties, &error));
8937 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8952 const Context &context,
const Device &device, cl_uint queueSize, cl_int *err =
nullptr)
8956 cl_command_queue_properties properties =
8957 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
8958 cl_queue_properties queue_properties[] = {
8959 CL_QUEUE_PROPERTIES, properties,
8960 CL_QUEUE_SIZE, queueSize,
8963 ::clCreateCommandQueueWithProperties(
8964 context(), device(), queue_properties, &error));
8966 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8976 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8986 error = clSetDefaultDeviceCommandQueue(context.get(), device.get(), default_queue.get());
8988 detail::errHandler(error, __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR);
8992 return default_queue;
9000 return queue.getInfo<CL_QUEUE_DEVICE_DEFAULT>(err);
9003 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
9017 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9020 template<
typename IteratorType >
9023 IteratorType startIterator,
9024 IteratorType endIterator,
9029 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9032 cl_mem_flags flags = 0;
9034 flags |= CL_MEM_READ_ONLY;
9037 flags |= CL_MEM_READ_WRITE;
9040 flags |= CL_MEM_USE_HOST_PTR;
9043 size_type size =
sizeof(DataType)*(endIterator - startIterator);
9046 object_ = ::clCreateBuffer(context(), flags, size,
static_cast<DataType*
>(&*startIterator), &error);
9048 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9051 detail::errHandler(error, __CREATE_BUFFER_ERR);
9058 detail::errHandler(error, __CREATE_BUFFER_ERR);
9063 error =
cl::copy(queue, startIterator, endIterator, *
this);
9064 detail::errHandler(error, __CREATE_BUFFER_ERR);
9071 template<
typename IteratorType >
9074 IteratorType startIterator,
9075 IteratorType endIterator,
9080 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9083 cl_mem_flags flags = 0;
9085 flags |= CL_MEM_READ_ONLY;
9088 flags |= CL_MEM_READ_WRITE;
9091 flags |= CL_MEM_USE_HOST_PTR;
9094 size_type size =
sizeof(DataType)*(endIterator - startIterator);
9096 Context context = queue.getInfo<CL_QUEUE_CONTEXT>();
9099 object_ = ::clCreateBuffer(context(), flags, size,
static_cast<DataType*
>(&*startIterator), &error);
9102 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9105 detail::errHandler(error, __CREATE_BUFFER_ERR);
9111 error =
cl::copy(queue, startIterator, endIterator, *
this);
9112 detail::errHandler(error, __CREATE_BUFFER_ERR);
9119 inline cl_int enqueueReadBuffer(
9125 const vector<Event>* events = NULL,
9126 Event* event = NULL)
9131 if (error != CL_SUCCESS) {
9135 return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event);
9138 inline cl_int enqueueWriteBuffer(
9139 const Buffer& buffer,
9144 const vector<Event>* events = NULL,
9145 Event* event = NULL)
9148 CommandQueue queue = CommandQueue::getDefault(&error);
9150 if (error != CL_SUCCESS) {
9154 return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event);
9157 inline void* enqueueMapBuffer(
9158 const Buffer& buffer,
9163 const vector<Event>* events = NULL,
9164 Event* event = NULL,
9168 CommandQueue queue = CommandQueue::getDefault(&error);
9169 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9174 void * result = ::clEnqueueMapBuffer(
9175 queue(), buffer(), blocking, flags, offset, size,
9176 (events != NULL) ? (cl_uint) events->size() : 0,
9177 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
9181 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9189 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9195 template<
typename T>
9201 const vector<Event>* events,
9206 if (error != CL_SUCCESS) {
9207 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9211 ptr, blocking, flags, size, events, event);
9219 template<
typename T,
class D>
9221 cl::pointer<T, D> ptr,
9225 const vector<Event>* events = NULL,
9226 Event* event = NULL)
9230 if (error != CL_SUCCESS) {
9231 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9235 ptr, blocking, flags, size, events, event);
9243 template<
typename T,
class Alloc>
9245 cl::vector<T, Alloc> container,
9248 const vector<Event>* events = NULL,
9249 Event* event = NULL)
9253 if (error != CL_SUCCESS) {
9254 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9258 container, blocking, flags, events, event);
9261 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9263 inline cl_int enqueueUnmapMemObject(
9264 const Memory& memory,
9266 const vector<Event>* events = NULL,
9267 Event* event = NULL)
9270 CommandQueue queue = CommandQueue::getDefault(&error);
9271 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9272 if (error != CL_SUCCESS) {
9277 cl_int err = detail::errHandler(
9278 ::clEnqueueUnmapMemObject(
9279 queue(), memory(), mapped_ptr,
9280 (events != NULL) ? (cl_uint)events->size() : 0,
9281 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
9282 (event != NULL) ? &tmp : NULL),
9283 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9285 if (event != NULL && err == CL_SUCCESS)
9291 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9297 template<
typename T>
9300 const vector<Event>* events = NULL,
9301 Event* event = NULL)
9305 if (error != CL_SUCCESS) {
9306 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9310 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9319 template<
typename T,
class D>
9321 cl::pointer<T, D> &ptr,
9322 const vector<Event>* events = NULL,
9323 Event* event = NULL)
9327 if (error != CL_SUCCESS) {
9328 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9332 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9340 template<
typename T,
class Alloc>
9342 cl::vector<T, Alloc> &container,
9343 const vector<Event>* events = NULL,
9344 Event* event = NULL)
9348 if (error != CL_SUCCESS) {
9349 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9352 return detail::errHandler(queue.
enqueueUnmapSVM(container, events, event),
9353 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9356 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9358 inline cl_int enqueueCopyBuffer(
9361 size_type src_offset,
9362 size_type dst_offset,
9364 const vector<Event>* events = NULL,
9365 Event* event = NULL)
9368 CommandQueue queue = CommandQueue::getDefault(&error);
9370 if (error != CL_SUCCESS) {
9374 return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event);
9382 template<
typename IteratorType >
9383 inline cl_int
copy( IteratorType startIterator, IteratorType endIterator,
cl::Buffer &buffer )
9387 if (error != CL_SUCCESS)
9390 return cl::copy(queue, startIterator, endIterator, buffer);
9398 template<
typename IteratorType >
9399 inline cl_int
copy(
const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
9403 if (error != CL_SUCCESS)
9406 return cl::copy(queue, buffer, startIterator, endIterator);
9414 template<
typename IteratorType >
9417 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9420 size_type length = endIterator-startIterator;
9421 size_type byteLength = length*
sizeof(DataType);
9424 static_cast<DataType*
>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error));
9426 if( error != CL_SUCCESS ) {
9429 #if defined(_MSC_VER)
9433 stdext::checked_array_iterator<DataType*>(
9436 std::copy(startIterator, endIterator, pointer);
9439 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9441 if( error != CL_SUCCESS ) {
9453 template<
typename IteratorType >
9456 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9459 size_type length = endIterator-startIterator;
9460 size_type byteLength = length*
sizeof(DataType);
9463 static_cast<DataType*
>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error));
9465 if( error != CL_SUCCESS ) {
9468 std::copy(pointer, pointer + length, startIterator);
9470 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9472 if( error != CL_SUCCESS ) {
9480 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9484 template<
typename T,
class Alloc>
9485 inline cl_int
mapSVM(cl::vector<T, Alloc> &container)
9487 return enqueueMapSVM(container, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE);
9493 template<
typename T,
class Alloc>
9494 inline cl_int
unmapSVM(cl::vector<T, Alloc> &container)
9499 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9501 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
9502 inline cl_int enqueueReadBufferRect(
9503 const Buffer& buffer,
9505 const array<size_type, 3>& buffer_offset,
9506 const array<size_type, 3>& host_offset,
9507 const array<size_type, 3>& region,
9508 size_type buffer_row_pitch,
9509 size_type buffer_slice_pitch,
9510 size_type host_row_pitch,
9511 size_type host_slice_pitch,
9513 const vector<Event>* events = NULL,
9514 Event* event = NULL)
9517 CommandQueue queue = CommandQueue::getDefault(&error);
9519 if (error != CL_SUCCESS) {
9523 return queue.enqueueReadBufferRect(
9538 inline cl_int enqueueWriteBufferRect(
9539 const Buffer& buffer,
9541 const array<size_type, 3>& buffer_offset,
9542 const array<size_type, 3>& host_offset,
9543 const array<size_type, 3>& region,
9544 size_type buffer_row_pitch,
9545 size_type buffer_slice_pitch,
9546 size_type host_row_pitch,
9547 size_type host_slice_pitch,
9549 const vector<Event>* events = NULL,
9550 Event* event = NULL)
9553 CommandQueue queue = CommandQueue::getDefault(&error);
9555 if (error != CL_SUCCESS) {
9559 return queue.enqueueWriteBufferRect(
9574 inline cl_int enqueueCopyBufferRect(
9577 const array<size_type, 3>& src_origin,
9578 const array<size_type, 3>& dst_origin,
9579 const array<size_type, 3>& region,
9580 size_type src_row_pitch,
9581 size_type src_slice_pitch,
9582 size_type dst_row_pitch,
9583 size_type dst_slice_pitch,
9584 const vector<Event>* events = NULL,
9585 Event* event = NULL)
9588 CommandQueue queue = CommandQueue::getDefault(&error);
9590 if (error != CL_SUCCESS) {
9594 return queue.enqueueCopyBufferRect(
9607 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
9609 inline cl_int enqueueReadImage(
9612 const array<size_type, 3>& origin,
9613 const array<size_type, 3>& region,
9614 size_type row_pitch,
9615 size_type slice_pitch,
9617 const vector<Event>* events = NULL,
9618 Event* event = NULL)
9621 CommandQueue queue = CommandQueue::getDefault(&error);
9623 if (error != CL_SUCCESS) {
9627 return queue.enqueueReadImage(
9639 inline cl_int enqueueWriteImage(
9642 const array<size_type, 3>& origin,
9643 const array<size_type, 3>& region,
9644 size_type row_pitch,
9645 size_type slice_pitch,
9647 const vector<Event>* events = NULL,
9648 Event* event = NULL)
9651 CommandQueue queue = CommandQueue::getDefault(&error);
9653 if (error != CL_SUCCESS) {
9657 return queue.enqueueWriteImage(
9669 inline cl_int enqueueCopyImage(
9672 const array<size_type, 3>& src_origin,
9673 const array<size_type, 3>& dst_origin,
9674 const array<size_type, 3>& region,
9675 const vector<Event>* events = NULL,
9676 Event* event = NULL)
9679 CommandQueue queue = CommandQueue::getDefault(&error);
9681 if (error != CL_SUCCESS) {
9685 return queue.enqueueCopyImage(
9695 inline cl_int enqueueCopyImageToBuffer(
9698 const array<size_type, 3>& src_origin,
9699 const array<size_type, 3>& region,
9700 size_type dst_offset,
9701 const vector<Event>* events = NULL,
9702 Event* event = NULL)
9705 CommandQueue queue = CommandQueue::getDefault(&error);
9707 if (error != CL_SUCCESS) {
9711 return queue.enqueueCopyImageToBuffer(
9721 inline cl_int enqueueCopyBufferToImage(
9724 size_type src_offset,
9725 const array<size_type, 3>& dst_origin,
9726 const array<size_type, 3>& region,
9727 const vector<Event>* events = NULL,
9728 Event* event = NULL)
9731 CommandQueue queue = CommandQueue::getDefault(&error);
9733 if (error != CL_SUCCESS) {
9737 return queue.enqueueCopyBufferToImage(
9748 inline cl_int flush(
void)
9751 CommandQueue queue = CommandQueue::getDefault(&error);
9753 if (error != CL_SUCCESS) {
9757 return queue.flush();
9760 inline cl_int finish(
void)
9763 CommandQueue queue = CommandQueue::getDefault(&error);
9765 if (error != CL_SUCCESS) {
9770 return queue.finish();
9780 vector<Event> events_;
9782 template<
typename... Ts>
9787 queue_(CommandQueue::getDefault()),
9796 queue_(CommandQueue::getDefault()),
9805 queue_(CommandQueue::getDefault()),
9814 queue_(CommandQueue::getDefault()),
9819 events_.push_back(e);
9823 queue_(CommandQueue::getDefault()),
9828 events_.push_back(e);
9832 queue_(CommandQueue::getDefault()),
9837 events_.push_back(e);
9841 queue_(CommandQueue::getDefault()),
9851 queue_(CommandQueue::getDefault()),
9861 queue_(CommandQueue::getDefault()),
9903 events_.push_back(e);
9912 events_.push_back(e);
9921 events_.push_back(e);
9963 template<
typename... Ts>
9969 template<
int index,
typename T0,
typename... T1s>
9970 void setArgs(T0&& t0, T1s&&... t1s)
9972 kernel_.
setArg(index, t0);
9973 setArgs<index + 1, T1s...>(std::forward<T1s>(t1s)...);
9976 template<
int index,
typename T0>
9977 void setArgs(T0&& t0)
9979 kernel_.
setArg(index, t0);
9995 cl_int * err = NULL) :
9996 kernel_(program, name.c_str(), err)
10012 setArgs<0>(std::forward<Ts>(ts)...);
10014 args.queue_.enqueueNDRangeKernel(
10037 setArgs<0>(std::forward<Ts>(ts)...);
10039 error = args.queue_.enqueueNDRangeKernel(
10050 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10051 cl_int setSVMPointers(
const vector<void*> &pointerList)
10056 template<
typename T0,
typename... T1s>
10057 cl_int setSVMPointers(
const T0 &t0, T1s &... ts)
10061 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10069 namespace compatibility {
10074 template<
typename... Ts>
10084 cl_int * err = NULL) :
10106 enqueueArgs, args...);
10114 #undef CL_HPP_ERR_STR_
10115 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
10116 #undef __GET_DEVICE_INFO_ERR
10117 #undef __GET_PLATFORM_INFO_ERR
10118 #undef __GET_DEVICE_IDS_ERR
10119 #undef __GET_PLATFORM_IDS_ERR
10120 #undef __GET_CONTEXT_INFO_ERR
10121 #undef __GET_EVENT_INFO_ERR
10122 #undef __GET_EVENT_PROFILE_INFO_ERR
10123 #undef __GET_MEM_OBJECT_INFO_ERR
10124 #undef __GET_IMAGE_INFO_ERR
10125 #undef __GET_SAMPLER_INFO_ERR
10126 #undef __GET_KERNEL_INFO_ERR
10127 #undef __GET_KERNEL_ARG_INFO_ERR
10128 #undef __GET_KERNEL_SUB_GROUP_INFO_ERR
10129 #undef __GET_KERNEL_WORK_GROUP_INFO_ERR
10130 #undef __GET_PROGRAM_INFO_ERR
10131 #undef __GET_PROGRAM_BUILD_INFO_ERR
10132 #undef __GET_COMMAND_QUEUE_INFO_ERR
10133 #undef __CREATE_CONTEXT_ERR
10134 #undef __CREATE_CONTEXT_FROM_TYPE_ERR
10135 #undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
10136 #undef __CREATE_BUFFER_ERR
10138 #undef __CREATE_SUBBUFFER_ERR
10139 #undef __CREATE_GL_BUFFER_ERR
10140 #undef __CREATE_GL_RENDER_BUFFER_ERR
10141 #undef __GET_GL_OBJECT_INFO_ERR
10142 #undef __CREATE_IMAGE_ERR
10143 #undef __CREATE_GL_TEXTURE_ERR
10144 #undef __IMAGE_DIMENSION_ERR
10145 #undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
10146 #undef __CREATE_USER_EVENT_ERR
10147 #undef __SET_USER_EVENT_STATUS_ERR
10148 #undef __SET_EVENT_CALLBACK_ERR
10149 #undef __WAIT_FOR_EVENTS_ERR
10150 #undef __CREATE_KERNEL_ERR
10151 #undef __SET_KERNEL_ARGS_ERR
10152 #undef __CREATE_PROGRAM_WITH_SOURCE_ERR
10153 #undef __CREATE_PROGRAM_WITH_IL_ERR
10154 #undef __CREATE_PROGRAM_WITH_BINARY_ERR
10155 #undef __CREATE_PROGRAM_WITH_IL_ERR
10156 #undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR
10157 #undef __BUILD_PROGRAM_ERR
10158 #undef __COMPILE_PROGRAM_ERR
10159 #undef __LINK_PROGRAM_ERR
10160 #undef __CREATE_KERNELS_IN_PROGRAM_ERR
10161 #undef __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR
10162 #undef __CREATE_SAMPLER_WITH_PROPERTIES_ERR
10163 #undef __SET_COMMAND_QUEUE_PROPERTY_ERR
10164 #undef __ENQUEUE_READ_BUFFER_ERR
10165 #undef __ENQUEUE_READ_BUFFER_RECT_ERR
10166 #undef __ENQUEUE_WRITE_BUFFER_ERR
10167 #undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
10168 #undef __ENQEUE_COPY_BUFFER_ERR
10169 #undef __ENQEUE_COPY_BUFFER_RECT_ERR
10170 #undef __ENQUEUE_FILL_BUFFER_ERR
10171 #undef __ENQUEUE_READ_IMAGE_ERR
10172 #undef __ENQUEUE_WRITE_IMAGE_ERR
10173 #undef __ENQUEUE_COPY_IMAGE_ERR
10174 #undef __ENQUEUE_FILL_IMAGE_ERR
10175 #undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
10176 #undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
10177 #undef __ENQUEUE_MAP_BUFFER_ERR
10178 #undef __ENQUEUE_MAP_IMAGE_ERR
10179 #undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
10180 #undef __ENQUEUE_NDRANGE_KERNEL_ERR
10181 #undef __ENQUEUE_NATIVE_KERNEL
10182 #undef __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR
10183 #undef __ENQUEUE_MIGRATE_SVM_ERR
10184 #undef __ENQUEUE_ACQUIRE_GL_ERR
10185 #undef __ENQUEUE_RELEASE_GL_ERR
10186 #undef __CREATE_PIPE_ERR
10187 #undef __GET_PIPE_INFO_ERR
10188 #undef __RETAIN_ERR
10189 #undef __RELEASE_ERR
10191 #undef __FINISH_ERR
10192 #undef __VECTOR_CAPACITY_ERR
10193 #undef __CREATE_SUB_DEVICES_ERR
10194 #undef __CREATE_SUB_DEVICES_ERR
10195 #undef __ENQUEUE_MARKER_ERR
10196 #undef __ENQUEUE_WAIT_FOR_EVENTS_ERR
10197 #undef __ENQUEUE_BARRIER_ERR
10198 #undef __UNLOAD_COMPILER_ERR
10199 #undef __CREATE_GL_TEXTURE_2D_ERR
10200 #undef __CREATE_GL_TEXTURE_3D_ERR
10201 #undef __CREATE_IMAGE2D_ERR
10202 #undef __CREATE_IMAGE3D_ERR
10203 #undef __CREATE_COMMAND_QUEUE_ERR
10204 #undef __ENQUEUE_TASK_ERR
10205 #undef __CREATE_SAMPLER_ERR
10206 #undef __ENQUEUE_MARKER_WAIT_LIST_ERR
10207 #undef __ENQUEUE_BARRIER_WAIT_LIST_ERR
10208 #undef __CLONE_KERNEL_ERR
10209 #undef __GET_HOST_TIMER_ERR
10210 #undef __GET_DEVICE_AND_HOST_TIMER_ERR
10212 #endif //CL_HPP_USER_OVERRIDE_ERROR_STRINGS
10215 #undef CL_HPP_INIT_CL_EXT_FCN_PTR_
10216 #undef CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_
10218 #if defined(CL_HPP_USE_CL_DEVICE_FISSION)
10219 #undef CL_HPP_PARAM_NAME_DEVICE_FISSION_
10220 #endif // CL_HPP_USE_CL_DEVICE_FISSION
10222 #undef CL_HPP_NOEXCEPT_
10223 #undef CL_HPP_DEFINE_STATIC_MEMBER_