1 /*******************************************************************************
2 * Copyright (c) 2008-2010 The Khronos Group Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and/or associated documentation files (the
6 * "Materials"), to deal in the Materials without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Materials, and to
9 * permit persons to whom the Materials are furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Materials.
15 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
22 ******************************************************************************/
26 * \brief C++ bindings for OpenCL 1.0 (rev 48) and OpenCL 1.1 (rev 33)
27 * \author Benedict R. Gaster and Laurent Morichetti
29 * Additions and fixes from Brian Cole, March 3rd 2010.
34 * Optional extension support
37 * cl_ext_device_fission
38 * #define USE_CL_DEVICE_FISSION
42 * \section intro Introduction
43 * For many large applications C++ is the language of choice and so it seems
44 * reasonable to define C++ bindings for OpenCL.
47 * The interface is contained with a single C++ header file \em cl.hpp and all
48 * definitions are contained within the namespace \em cl. There is no additional
49 * requirement to include \em cl.h and to use either the C++ or original C
50 * bindings it is enough to simply include \em cl.hpp.
52 * The bindings themselves are lightweight and correspond closely to the
53 * underlying C API. Using the C++ bindings introduces no additional execution
56 * For detail documentation on the bindings see:
58 * The OpenCL C++ Wrapper API 1.1 (revision 04)
59 * http://www.khronos.org/registry/cl/specs/opencl-cplusplus-1.1.pdf
61 * \section example Example
63 * The following example shows a general use case for the C++
64 * bindings, including support for the optional exception feature and
65 * also the supplied vector and string classes, see following sections for
66 * decriptions of these features.
69 * #define __CL_ENABLE_EXCEPTIONS
71 * #if defined(__APPLE__) || defined(__MACOSX)
72 * #include <OpenCL/cl.hpp>
74 * #include <CL/cl.hpp>
80 * const char * helloStr = "__kernel void "
89 * cl_int err = CL_SUCCESS;
92 * std::vector<cl::Platform> platforms;
93 * cl::Platform::get(&platforms);
94 * if (platforms.size() == 0) {
95 * std::cout << "Platform size 0\n";
99 * cl_context_properties properties[] =
100 * { CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0};
101 * cl::Context context(CL_DEVICE_TYPE_CPU, properties);
103 * std::vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>();
105 * cl::Program::Sources source(1,
106 * std::make_pair(helloStr,strlen(helloStr)));
107 * cl::Program program_ = cl::Program(context, source);
108 * program_.build(devices);
110 * cl::Kernel kernel(program_, "hello", &err);
113 * cl::CommandQueue queue(context, devices[0], 0, &err);
114 * queue.enqueueNDRangeKernel(
124 * catch (cl::Error err) {
134 * return EXIT_SUCCESS;
146 #if defined(USE_DX_INTEROP)
147 #include <CL/cl_d3d10.h>
152 #if defined(USE_CL_DEVICE_FISSION)
153 #include <CL/cl_ext.h>
156 #if defined(__APPLE__) || defined(__MACOSX)
157 #include <OpenGL/OpenGL.h>
158 #include <OpenCL/opencl.h>
161 #include <CL/opencl.h>
164 #if !defined(CL_CALLBACK)
170 #if !defined(__NO_STD_VECTOR)
174 #if !defined(__NO_STD_STRING)
178 #if defined(linux) || defined(__APPLE__) || defined(__MACOSX)
186 * \brief The OpenCL C++ bindings are defined within this namespace.
191 #define __INIT_CL_EXT_FCN_PTR(name) \
193 pfn_##name = (PFN_##name) \
194 clGetExtensionFunctionAddress(#name); \
205 #if defined(__CL_ENABLE_EXCEPTIONS)
208 * \brief Exception class
210 class Error : public std::exception
214 const char * errStr_;
216 /*! Create a new CL error exception for a given error code
217 * and corresponding message.
219 Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr)
224 /*! \brief Get error string associated with exception
226 * \return A memory pointer to the error message string.
228 virtual const char * what() const throw ()
230 if (errStr_ == NULL) {
238 /*! \brief Get error code associated with exception
240 * \return The error code.
242 const cl_int err(void) const { return err_; }
245 #define __ERR_STR(x) #x
247 #define __ERR_STR(x) NULL
248 #endif // __CL_ENABLE_EXCEPTIONS
250 //! \cond DOXYGEN_DETAIL
251 #if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
252 #define __GET_DEVICE_INFO_ERR __ERR_STR(clgetDeviceInfo)
253 #define __GET_PLATFORM_INFO_ERR __ERR_STR(clGetPlatformInfo)
254 #define __GET_DEVICE_IDS_ERR __ERR_STR(clGetDeviceIDs)
255 #define __GET_PLATFORM_IDS_ERR __ERR_STR(clGetPlatformIDs)
256 #define __GET_CONTEXT_INFO_ERR __ERR_STR(clGetContextInfo)
257 #define __GET_EVENT_INFO_ERR __ERR_STR(clGetEventInfo)
258 #define __GET_EVENT_PROFILE_INFO_ERR __ERR_STR(clGetEventProfileInfo)
259 #define __GET_MEM_OBJECT_INFO_ERR __ERR_STR(clGetMemObjectInfo)
260 #define __GET_IMAGE_INFO_ERR __ERR_STR(clGetImageInfo)
261 #define __GET_SAMPLER_INFO_ERR __ERR_STR(clGetSamplerInfo)
262 #define __GET_KERNEL_INFO_ERR __ERR_STR(clGetKernelInfo)
263 #define __GET_KERNEL_WORK_GROUP_INFO_ERR __ERR_STR(clGetKernelWorkGroupInfo)
264 #define __GET_PROGRAM_INFO_ERR __ERR_STR(clGetProgramInfo)
265 #define __GET_PROGRAM_BUILD_INFO_ERR __ERR_STR(clGetProgramBuildInfo)
266 #define __GET_COMMAND_QUEUE_INFO_ERR __ERR_STR(clGetCommandQueueInfo)
268 #define __CREATE_CONTEXT_FROM_TYPE_ERR __ERR_STR(clCreateContextFromType)
269 #define __GET_SUPPORTED_IMAGE_FORMATS_ERR __ERR_STR(clGetSupportedImageFormats)
271 #define __CREATE_BUFFER_ERR __ERR_STR(clCreateBuffer)
272 #define __CREATE_SUBBUFFER_ERR __ERR_STR(clCreateSubBuffer)
273 #define __CREATE_GL_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer)
274 #define __GET_GL_OBJECT_INFO_ERR __ERR_STR(clGetGLObjectInfo)
275 #define __CREATE_IMAGE2D_ERR __ERR_STR(clCreateImage2D)
276 #define __CREATE_IMAGE3D_ERR __ERR_STR(clCreateImage3D)
277 #define __CREATE_SAMPLER_ERR __ERR_STR(clCreateSampler)
278 #define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR __ERR_STR(clSetMemObjectDestructorCallback)
280 #define __CREATE_USER_EVENT_ERR __ERR_STR(clCreateUserEvent)
281 #define __SET_USER_EVENT_STATUS_ERR __ERR_STR(clSetUserEventStatus)
282 #define __SET_EVENT_CALLBACK_ERR __ERR_STR(clSetEventCallback)
283 #define __WAIT_FOR_EVENTS_ERR __ERR_STR(clWaitForEvents)
285 #define __CREATE_KERNEL_ERR __ERR_STR(clCreateKernel)
286 #define __SET_KERNEL_ARGS_ERR __ERR_STR(clSetKernelArg)
287 #define __CREATE_PROGRAM_WITH_SOURCE_ERR __ERR_STR(clCreateProgramWithSource)
288 #define __CREATE_PROGRAM_WITH_BINARY_ERR __ERR_STR(clCreateProgramWithBinary)
289 #define __BUILD_PROGRAM_ERR __ERR_STR(clBuildProgram)
290 #define __CREATE_KERNELS_IN_PROGRAM_ERR __ERR_STR(clCreateKernelsInProgram)
292 #define __CREATE_COMMAND_QUEUE_ERR __ERR_STR(clCreateCommandQueue)
293 #define __SET_COMMAND_QUEUE_PROPERTY_ERR __ERR_STR(clSetCommandQueueProperty)
294 #define __ENQUEUE_READ_BUFFER_ERR __ERR_STR(clEnqueueReadBuffer)
295 #define __ENQUEUE_READ_BUFFER_RECT_ERR __ERR_STR(clEnqueueReadBufferRect)
296 #define __ENQUEUE_WRITE_BUFFER_ERR __ERR_STR(clEnqueueWriteBuffer)
297 #define __ENQUEUE_WRITE_BUFFER_RECT_ERR __ERR_STR(clEnqueueWriteBufferRect)
298 #define __ENQEUE_COPY_BUFFER_ERR __ERR_STR(clEnqueueCopyBuffer)
299 #define __ENQEUE_COPY_BUFFER_RECT_ERR __ERR_STR(clEnqueueCopyBufferRect)
300 #define __ENQUEUE_READ_IMAGE_ERR __ERR_STR(clEnqueueReadImage)
301 #define __ENQUEUE_WRITE_IMAGE_ERR __ERR_STR(clEnqueueWriteImage)
302 #define __ENQUEUE_COPY_IMAGE_ERR __ERR_STR(clEnqueueCopyImage)
303 #define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR __ERR_STR(clEnqueueCopyImageToBuffer)
304 #define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR __ERR_STR(clEnqueueCopyBufferToImage)
305 #define __ENQUEUE_MAP_BUFFER_ERR __ERR_STR(clEnqueueMapBuffer)
306 #define __ENQUEUE_MAP_IMAGE_ERR __ERR_STR(clEnqueueMapImage)
307 #define __ENQUEUE_UNMAP_MEM_OBJECT_ERR __ERR_STR(clEnqueueUnMapMemObject)
308 #define __ENQUEUE_NDRANGE_KERNEL_ERR __ERR_STR(clEnqueueNDRangeKernel)
309 #define __ENQUEUE_TASK_ERR __ERR_STR(clEnqueueTask)
310 #define __ENQUEUE_NATIVE_KERNEL __ERR_STR(clEnqueueNativeKernel)
311 #define __ENQUEUE_MARKER_ERR __ERR_STR(clEnqueueMarker)
312 #define __ENQUEUE_WAIT_FOR_EVENTS_ERR __ERR_STR(clEnqueueWaitForEvents)
313 #define __ENQUEUE_BARRIER_ERR __ERR_STR(clEnqueueBarrier)
315 #define __ENQUEUE_ACQUIRE_GL_ERR __ERR_STR(clEnqueueAcquireGLObjects)
316 #define __ENQUEUE_RELEASE_GL_ERR __ERR_STR(clEnqueueReleaseGLObjects)
318 #define __UNLOAD_COMPILER_ERR __ERR_STR(clUnloadCompiler)
320 #define __FLUSH_ERR __ERR_STR(clFlush)
321 #define __FINISH_ERR __ERR_STR(clFinish)
323 #define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevicesEXT)
324 #endif // __CL_USER_OVERRIDE_ERROR_STRINGS
328 * \brief Simple string class, that provides a limited subset of std::string
329 * functionality but avoids many of the issues that come with that class.
337 string(void) : size_(0), str_(NULL)
341 string(char * str, ::size_t size) :
345 str_ = new char[size_+1];
347 memcpy(str_, str, size_ * sizeof(char));
358 size_= ::strlen(str);
359 str_ = new char[size_ + 1];
361 memcpy(str_, str, (size_ + 1) * sizeof(char));
368 string& operator=(const string& rhs)
374 if (rhs.size_ == 0 || rhs.str_ == NULL) {
380 str_ = new char[size_ + 1];
382 memcpy(str_, rhs.str_, (size_ + 1) * sizeof(char));
392 string(const string& rhs)
404 ::size_t size(void) const { return size_; }
405 ::size_t length(void) const { return size(); }
407 const char * c_str(void) const { return (str_) ? str_ : "";}
410 #if !defined(__USE_DEV_STRING) && !defined(__NO_STD_STRING)
412 typedef std::string STRING_CLASS;
413 #elif !defined(__USE_DEV_STRING)
414 typedef cl::string STRING_CLASS;
417 #if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR)
419 #define VECTOR_CLASS std::vector
420 #elif !defined(__USE_DEV_VECTOR)
421 #define VECTOR_CLASS cl::vector
424 #if !defined(__MAX_DEFAULT_VECTOR_SIZE)
425 #define __MAX_DEFAULT_VECTOR_SIZE 10
429 * \brief Fixed sized vector implementation that mirroring
430 * std::vector functionality.
432 template <typename T, unsigned int N = __MAX_DEFAULT_VECTOR_SIZE>
447 unsigned int size(void) const
458 void push_back (const T& x)
478 vector(const vector<T, N>& vec) :
483 memcpy(&data_[0], &vec.data_[0], size() * sizeof(T));
487 vector(unsigned int size, const T& val = T()) :
491 for (unsigned int i = 0; i < size; i++) {
496 vector<T, N>& operator=(const vector<T, N>& rhs)
506 memcpy(&data_[0], &rhs.data_[0], size() * sizeof(T));
512 bool operator==(vector<T,N> &vec)
514 if (empty_ && vec.empty_) {
518 if (size() != vec.size()) {
522 return memcmp(&data_[0], &vec.data_[0], size() * sizeof(T)) == 0 ? true : false;
525 operator T* () { return data_; }
526 operator const T* () const { return data_; }
528 bool empty (void) const
533 unsigned int max_size (void) const
538 unsigned int capacity () const
540 return sizeof(T) * N;
543 T& operator[](int index)
548 T operator[](int index) const
554 void assign(I start, I end)
564 * \brief Iterator class for vectors
578 initialized_ = false;
583 static iterator begin(vector<T,N> &vec)
592 i.initialized_ = true;
596 static iterator end(vector<T,N> &vec)
601 i.index_ = vec.size();
604 i.initialized_ = true;
608 bool operator==(iterator i)
610 return ((vec_ == i.vec_) &&
611 (index_ == i.index_) &&
612 (initialized_ == i.initialized_));
615 bool operator!=(iterator i)
617 return (!(*this==i));
625 void operator++(int x)
635 void operator--(int x)
648 return iterator::begin(*this);
653 return iterator::end(*this);
666 const T& front(void) const
671 const T& back(void) const
678 * \brief size_t class used to interface between C++ and
679 * OpenCL C calls that require arrays of size_t values, who's
680 * size is known statically.
683 struct size_t : public cl::vector< ::size_t, N> { };
687 // GetInfo help struct
688 template <typename Functor, typename T>
692 get(Functor f, cl_uint name, T* param)
694 return f(name, sizeof(T), param, NULL);
698 // Specialized GetInfoHelper for VECTOR_CLASS params
699 template <typename Func, typename T>
700 struct GetInfoHelper<Func, VECTOR_CLASS<T> >
702 static cl_int get(Func f, cl_uint name, VECTOR_CLASS<T>* param)
705 cl_int err = f(name, 0, NULL, &required);
706 if (err != CL_SUCCESS) {
710 T* value = (T*) alloca(required);
711 err = f(name, required, value, NULL);
712 if (err != CL_SUCCESS) {
716 param->assign(&value[0], &value[required/sizeof(T)]);
721 // Specialized for getInfo<CL_PROGRAM_BINARIES>
722 template <typename Func>
723 struct GetInfoHelper<Func, VECTOR_CLASS<char *> >
726 get(Func f, cl_uint name, VECTOR_CLASS<char *>* param)
728 cl_uint err = f(name, param->size() * sizeof(char *), &(*param)[0], NULL);
729 if (err != CL_SUCCESS) {
737 // Specialized GetInfoHelper for STRING_CLASS params
738 template <typename Func>
739 struct GetInfoHelper<Func, STRING_CLASS>
741 static cl_int get(Func f, cl_uint name, STRING_CLASS* param)
744 cl_int err = f(name, 0, NULL, &required);
745 if (err != CL_SUCCESS) {
749 char* value = (char*) alloca(required);
750 err = f(name, required, value, NULL);
751 if (err != CL_SUCCESS) {
760 #define __GET_INFO_HELPER_WITH_RETAIN(CPP_TYPE) \
762 template <typename Func> \
763 struct GetInfoHelper<Func, CPP_TYPE> \
765 static cl_int get(Func f, cl_uint name, CPP_TYPE* param) \
767 cl_uint err = f(name, sizeof(CPP_TYPE), param, NULL); \
768 if (err != CL_SUCCESS) { \
772 return ReferenceHandler<CPP_TYPE::cl_type>::retain((*param)()); \
778 #define __PARAM_NAME_INFO_1_0(F) \
779 F(cl_platform_info, CL_PLATFORM_PROFILE, STRING_CLASS) \
780 F(cl_platform_info, CL_PLATFORM_VERSION, STRING_CLASS) \
781 F(cl_platform_info, CL_PLATFORM_NAME, STRING_CLASS) \
782 F(cl_platform_info, CL_PLATFORM_VENDOR, STRING_CLASS) \
783 F(cl_platform_info, CL_PLATFORM_EXTENSIONS, STRING_CLASS) \
785 F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
786 F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
787 F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
788 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
789 F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, ::size_t) \
790 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, VECTOR_CLASS< ::size_t>) \
791 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
792 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
793 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
794 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
795 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
796 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
797 F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
798 F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_bitfield) \
799 F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
800 F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
801 F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
802 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, ::size_t) \
803 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, ::size_t) \
804 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, ::size_t) \
805 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, ::size_t) \
806 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, ::size_t) \
807 F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_uint) \
808 F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, ::size_t) \
809 F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
810 F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
811 F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
812 F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
813 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
814 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
815 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
816 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
817 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
818 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
819 F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
820 F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
821 F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
822 F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, ::size_t) \
823 F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
824 F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
825 F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
826 F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
827 F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties) \
828 F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
829 F(cl_device_info, CL_DEVICE_NAME, STRING_CLASS) \
830 F(cl_device_info, CL_DEVICE_VENDOR, STRING_CLASS) \
831 F(cl_device_info, CL_DRIVER_VERSION, STRING_CLASS) \
832 F(cl_device_info, CL_DEVICE_PROFILE, STRING_CLASS) \
833 F(cl_device_info, CL_DEVICE_VERSION, STRING_CLASS) \
834 F(cl_device_info, CL_DEVICE_EXTENSIONS, STRING_CLASS) \
836 F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
837 F(cl_context_info, CL_CONTEXT_DEVICES, VECTOR_CLASS<Device>) \
838 F(cl_context_info, CL_CONTEXT_PROPERTIES, VECTOR_CLASS<cl_context_properties>) \
840 F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
841 F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
842 F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
843 F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_uint) \
845 F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
846 F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
847 F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
848 F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
850 F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
851 F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
852 F(cl_mem_info, CL_MEM_SIZE, ::size_t) \
853 F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
854 F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
855 F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
856 F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
858 F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
859 F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, ::size_t) \
860 F(cl_image_info, CL_IMAGE_ROW_PITCH, ::size_t) \
861 F(cl_image_info, CL_IMAGE_SLICE_PITCH, ::size_t) \
862 F(cl_image_info, CL_IMAGE_WIDTH, ::size_t) \
863 F(cl_image_info, CL_IMAGE_HEIGHT, ::size_t) \
864 F(cl_image_info, CL_IMAGE_DEPTH, ::size_t) \
866 F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
867 F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
868 F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_addressing_mode) \
869 F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_filter_mode) \
870 F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_bool) \
872 F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
873 F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
874 F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
875 F(cl_program_info, CL_PROGRAM_DEVICES, VECTOR_CLASS<cl_device_id>) \
876 F(cl_program_info, CL_PROGRAM_SOURCE, STRING_CLASS) \
877 F(cl_program_info, CL_PROGRAM_BINARY_SIZES, VECTOR_CLASS< ::size_t>) \
878 F(cl_program_info, CL_PROGRAM_BINARIES, VECTOR_CLASS<char *>) \
880 F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
881 F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, STRING_CLASS) \
882 F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, STRING_CLASS) \
884 F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, STRING_CLASS) \
885 F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
886 F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
887 F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
888 F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
890 F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, ::size_t) \
891 F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::size_t<3>) \
892 F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
894 F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
895 F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
896 F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
897 F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
899 #if defined(CL_VERSION_1_1)
900 #define __PARAM_NAME_INFO_1_1(F) \
901 F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
902 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
903 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
904 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
905 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
906 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
907 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
908 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
909 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
910 F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
911 F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
912 F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) \
914 F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
915 F(cl_mem_info, CL_MEM_OFFSET, ::size_t) \
917 F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, ::size_t) \
918 F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
920 F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
921 #endif // CL_VERSION_1_1
923 #if defined(USE_CL_DEVICE_FISSION)
924 #define __PARAM_NAME_DEVICE_FISSION(F) \
925 F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
926 F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \
927 F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \
928 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
929 F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, VECTOR_CLASS<cl_device_partition_property_ext>)
930 #endif // USE_CL_DEVICE_FISSION
932 template <typename enum_type, cl_int Name>
933 struct param_traits {};
935 #define __DECLARE_PARAM_TRAITS(token, param_name, T) \
938 struct param_traits<detail:: token,param_name> \
940 enum { value = param_name }; \
941 typedef T param_type; \
944 __PARAM_NAME_INFO_1_0(__DECLARE_PARAM_TRAITS);
945 #if defined(CL_VERSION_1_1)
946 __PARAM_NAME_INFO_1_1(__DECLARE_PARAM_TRAITS);
947 #endif // CL_VERSION_1_1
949 #if defined(USE_CL_DEVICE_FISSION)
950 __PARAM_NAME_DEVICE_FISSION(__DECLARE_PARAM_TRAITS);
951 #endif // USE_CL_DEVICE_FISSION
953 #undef __DECLARE_PARAM_TRAITS
955 // Convenience functions
957 template <typename Func, typename T>
959 getInfo(Func f, cl_uint name, T* param)
961 return GetInfoHelper<Func, T>::get(f, name, param);
964 template <typename Func, typename Arg0>
965 struct GetInfoFunctor0
967 Func f_; const Arg0& arg0_;
969 cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
970 { return f_(arg0_, param, size, value, size_ret); }
973 template <typename Func, typename Arg0, typename Arg1>
974 struct GetInfoFunctor1
976 Func f_; const Arg0& arg0_; const Arg1& arg1_;
978 cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
979 { return f_(arg0_, arg1_, param, size, value, size_ret); }
982 template <typename Func, typename Arg0, typename T>
984 getInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
986 GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
987 return GetInfoHelper<GetInfoFunctor0<Func, Arg0>, T>
988 ::get(f0, name, param);
991 template <typename Func, typename Arg0, typename Arg1, typename T>
993 getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
995 GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
996 return GetInfoHelper<GetInfoFunctor1<Func, Arg0, Arg1>, T>
997 ::get(f0, name, param);
1000 template<typename T>
1001 struct ReferenceHandler
1005 struct ReferenceHandler<cl_device_id>
1007 // cl_device_id does not have retain().
1008 static cl_int retain(cl_device_id)
1009 { return CL_INVALID_DEVICE; }
1010 // cl_device_id does not have release().
1011 static cl_int release(cl_device_id)
1012 { return CL_INVALID_DEVICE; }
1016 struct ReferenceHandler<cl_platform_id>
1018 // cl_platform_id does not have retain().
1019 static cl_int retain(cl_platform_id)
1020 { return CL_INVALID_PLATFORM; }
1021 // cl_platform_id does not have release().
1022 static cl_int release(cl_platform_id)
1023 { return CL_INVALID_PLATFORM; }
1027 struct ReferenceHandler<cl_context>
1029 static cl_int retain(cl_context context)
1030 { return ::clRetainContext(context); }
1031 static cl_int release(cl_context context)
1032 { return ::clReleaseContext(context); }
1036 struct ReferenceHandler<cl_command_queue>
1038 static cl_int retain(cl_command_queue queue)
1039 { return ::clRetainCommandQueue(queue); }
1040 static cl_int release(cl_command_queue queue)
1041 { return ::clReleaseCommandQueue(queue); }
1045 struct ReferenceHandler<cl_mem>
1047 static cl_int retain(cl_mem memory)
1048 { return ::clRetainMemObject(memory); }
1049 static cl_int release(cl_mem memory)
1050 { return ::clReleaseMemObject(memory); }
1054 struct ReferenceHandler<cl_sampler>
1056 static cl_int retain(cl_sampler sampler)
1057 { return ::clRetainSampler(sampler); }
1058 static cl_int release(cl_sampler sampler)
1059 { return ::clReleaseSampler(sampler); }
1063 struct ReferenceHandler<cl_program>
1065 static cl_int retain(cl_program program)
1066 { return ::clRetainProgram(program); }
1067 static cl_int release(cl_program program)
1068 { return ::clReleaseProgram(program); }
1072 struct ReferenceHandler<cl_kernel>
1074 static cl_int retain(cl_kernel kernel)
1075 { return ::clRetainKernel(kernel); }
1076 static cl_int release(cl_kernel kernel)
1077 { return ::clReleaseKernel(kernel); }
1081 struct ReferenceHandler<cl_event>
1083 static cl_int retain(cl_event event)
1084 { return ::clRetainEvent(event); }
1085 static cl_int release(cl_event event)
1086 { return ::clReleaseEvent(event); }
1089 template <typename T>
1099 Wrapper() : object_(NULL) { }
1103 if (object_ != NULL) { release(); }
1106 Wrapper(const Wrapper<cl_type>& rhs)
1108 object_ = rhs.object_;
1109 if (object_ != NULL) { retain(); }
1112 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
1114 if (object_ != NULL) { release(); }
1115 object_ = rhs.object_;
1116 if (object_ != NULL) { retain(); }
1120 cl_type operator ()() const { return object_; }
1122 cl_type& operator ()() { return object_; }
1126 cl_int retain() const
1128 return ReferenceHandler<cl_type>::retain(object_);
1131 cl_int release() const
1133 return ReferenceHandler<cl_type>::release(object_);
1137 #if defined(__CL_ENABLE_EXCEPTIONS)
1138 static inline cl_int errHandler (
1140 const char * errStr = NULL) throw(Error)
1142 if (err != CL_SUCCESS) {
1143 throw Error(err, errStr);
1148 static inline cl_int errHandler (cl_int err, const char * errStr = NULL)
1152 #endif // __CL_ENABLE_EXCEPTIONS
1154 } // namespace detail
1157 /*! \stuct ImageFormat
1158 * \brief ImageFormat interface fro cl_image_format.
1160 struct ImageFormat : public cl_image_format
1164 ImageFormat(cl_channel_order order, cl_channel_type type)
1166 image_channel_order = order;
1167 image_channel_data_type = type;
1170 ImageFormat& operator = (const ImageFormat& rhs)
1173 this->image_channel_data_type = rhs.image_channel_data_type;
1174 this->image_channel_order = rhs.image_channel_order;
1181 * \brief Device interface for cl_device_id.
1183 class Device : public detail::Wrapper<cl_device_id>
1186 Device(cl_device_id device) { object_ = device; }
1188 Device() : detail::Wrapper<cl_type>() { }
1190 Device(const Device& device) : detail::Wrapper<cl_type>(device) { }
1192 Device& operator = (const Device& rhs)
1195 detail::Wrapper<cl_type>::operator=(rhs);
1200 template <typename T>
1201 cl_int getInfo(cl_device_info name, T* param) const
1203 return detail::errHandler(
1204 detail::getInfo(&::clGetDeviceInfo, object_, name, param),
1205 __GET_DEVICE_INFO_ERR);
1208 template <cl_int name> typename
1209 detail::param_traits<detail::cl_device_info, name>::param_type
1210 getInfo(cl_int* err = NULL) const
1212 typename detail::param_traits<
1213 detail::cl_device_info, name>::param_type param;
1214 cl_int result = getInfo(name, ¶m);
1221 #if defined(USE_CL_DEVICE_FISSION)
1222 cl_int createSubDevices(
1223 const cl_device_partition_property_ext * properties,
1224 VECTOR_CLASS<Device>* devices)
1226 typedef CL_API_ENTRY cl_int
1227 ( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
1228 cl_device_id /*in_device*/,
1229 const cl_device_partition_property_ext * /* properties */,
1230 cl_uint /*num_entries*/,
1231 cl_device_id * /*out_devices*/,
1232 cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1;
1234 static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
1235 __INIT_CL_EXT_FCN_PTR(clCreateSubDevicesEXT);
1238 cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
1239 if (err != CL_SUCCESS) {
1240 return detail::errHandler(err, __CREATE_SUB_DEVICES);
1243 cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
1244 err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids, NULL);
1245 if (err != CL_SUCCESS) {
1246 return detail::errHandler(err, __CREATE_SUB_DEVICES);
1249 devices->assign(&ids[0], &ids[n]);
1256 * \brief Platform interface.
1258 class Platform : public detail::Wrapper<cl_platform_id>
1261 static const Platform null();
1263 Platform(cl_platform_id platform) { object_ = platform; }
1265 Platform() : detail::Wrapper<cl_type>() { }
1267 Platform(const Platform& platform) : detail::Wrapper<cl_type>(platform) { }
1269 Platform& operator = (const Platform& rhs)
1272 detail::Wrapper<cl_type>::operator=(rhs);
1277 cl_int getInfo(cl_platform_info name, STRING_CLASS* param) const
1279 return detail::errHandler(
1280 detail::getInfo(&::clGetPlatformInfo, object_, name, param),
1281 __GET_PLATFORM_INFO_ERR);
1284 template <cl_int name> typename
1285 detail::param_traits<detail::cl_platform_info, name>::param_type
1286 getInfo(cl_int* err = NULL) const
1288 typename detail::param_traits<
1289 detail::cl_platform_info, name>::param_type param;
1290 cl_int result = getInfo(name, ¶m);
1298 cl_device_type type,
1299 VECTOR_CLASS<Device>* devices) const
1302 cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
1303 if (err != CL_SUCCESS) {
1304 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
1307 cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
1308 err = ::clGetDeviceIDs(object_, type, n, ids, NULL);
1309 if (err != CL_SUCCESS) {
1310 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
1313 devices->assign(&ids[0], &ids[n]);
1317 #if defined(USE_DX_INTEROP)
1318 /*! \brief Get the list of available D3D10 devices.
1320 * \param d3d_device_source.
1322 * \param d3d_object.
1324 * \param d3d_device_set.
1326 * \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device
1327 * values returned in devices can be used to identify a specific OpenCL
1328 * device. If \a devices argument is NULL, this argument is ignored.
1330 * \return One of the following values:
1331 * - CL_SUCCESS if the function is executed successfully.
1333 * The application can query specific capabilities of the OpenCL device(s)
1334 * returned by cl::getDevices. This can be used by the application to
1335 * determine which device(s) to use.
1337 * \note In the case that exceptions are enabled and a return value
1338 * other than CL_SUCCESS is generated, then cl::Error exception is
1342 cl_d3d10_device_source_khr d3d_device_source,
1344 cl_d3d10_device_set_khr d3d_device_set,
1345 VECTOR_CLASS<Device>* devices) const
1347 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
1348 cl_platform_id platform,
1349 cl_d3d10_device_source_khr d3d_device_source,
1351 cl_d3d10_device_set_khr d3d_device_set,
1352 cl_uint num_entries,
1353 cl_device_id * devices,
1354 cl_uint* num_devices);
1356 static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
1357 __INIT_CL_EXT_FCN_PTR(clGetDeviceIDsFromD3D10KHR);
1360 cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
1368 if (err != CL_SUCCESS) {
1369 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
1372 cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
1373 err = pfn_clGetDeviceIDsFromD3D10KHR(
1381 if (err != CL_SUCCESS) {
1382 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
1385 devices->assign(&ids[0], &ids[n]);
1391 VECTOR_CLASS<Platform>* platforms)
1394 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
1395 if (err != CL_SUCCESS) {
1396 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
1399 cl_platform_id* ids = (cl_platform_id*) alloca(
1400 n * sizeof(cl_platform_id));
1401 err = ::clGetPlatformIDs(n, ids, NULL);
1402 if (err != CL_SUCCESS) {
1403 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
1406 platforms->assign(&ids[0], &ids[n]);
1411 static inline cl_int
1414 return ::clUnloadCompiler();
1417 class Context : public detail::Wrapper<cl_context>
1421 const VECTOR_CLASS<Device>& devices,
1422 cl_context_properties* properties = NULL,
1423 void (CL_CALLBACK * notifyFptr)(
1432 object_ = ::clCreateContext(
1433 properties, (cl_uint) devices.size(),
1434 (cl_device_id*) &devices.front(),
1435 notifyFptr, data, &error);
1437 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
1444 cl_device_type type,
1445 cl_context_properties* properties = NULL,
1446 void (CL_CALLBACK * notifyFptr)(
1455 object_ = ::clCreateContextFromType(
1456 properties, type, notifyFptr, data, &error);
1458 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
1464 Context() : detail::Wrapper<cl_type>() { }
1466 Context(const Context& context) : detail::Wrapper<cl_type>(context) { }
1468 Context& operator = (const Context& rhs)
1471 detail::Wrapper<cl_type>::operator=(rhs);
1476 template <typename T>
1477 cl_int getInfo(cl_context_info name, T* param) const
1479 return detail::errHandler(
1480 detail::getInfo(&::clGetContextInfo, object_, name, param),
1481 __GET_CONTEXT_INFO_ERR);
1484 template <cl_int name> typename
1485 detail::param_traits<detail::cl_context_info, name>::param_type
1486 getInfo(cl_int* err = NULL) const
1488 typename detail::param_traits<
1489 detail::cl_context_info, name>::param_type param;
1490 cl_int result = getInfo(name, ¶m);
1497 cl_int getSupportedImageFormats(
1499 cl_mem_object_type type,
1500 VECTOR_CLASS<ImageFormat>* formats) const
1503 cl_int err = ::clGetSupportedImageFormats(
1510 if (err != CL_SUCCESS) {
1511 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
1514 ImageFormat* value = (ImageFormat*)
1515 alloca(numEntries * sizeof(ImageFormat));
1516 err = ::clGetSupportedImageFormats(
1521 (cl_image_format*) value,
1523 if (err != CL_SUCCESS) {
1524 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
1527 formats->assign(&value[0], &value[numEntries]);
1532 __GET_INFO_HELPER_WITH_RETAIN(cl::Context)
1535 * \brief Event interface for cl_event.
1537 class Event : public detail::Wrapper<cl_event>
1540 Event() : detail::Wrapper<cl_type>() { }
1542 Event(const Event& event) : detail::Wrapper<cl_type>(event) { }
1544 Event& operator = (const Event& rhs)
1547 detail::Wrapper<cl_type>::operator=(rhs);
1552 template <typename T>
1553 cl_int getInfo(cl_event_info name, T* param) const
1555 return detail::errHandler(
1556 detail::getInfo(&::clGetEventInfo, object_, name, param),
1557 __GET_EVENT_INFO_ERR);
1560 template <cl_int name> typename
1561 detail::param_traits<detail::cl_event_info, name>::param_type
1562 getInfo(cl_int* err = NULL) const
1564 typename detail::param_traits<
1565 detail::cl_event_info, name>::param_type param;
1566 cl_int result = getInfo(name, ¶m);
1573 template <typename T>
1574 cl_int getProfilingInfo(cl_profiling_info name, T* param) const
1576 return detail::errHandler(detail::getInfo(
1577 &::clGetEventProfilingInfo, object_, name, param),
1578 __GET_EVENT_PROFILE_INFO_ERR);
1581 template <cl_int name> typename
1582 detail::param_traits<detail::cl_profiling_info, name>::param_type
1583 getProfilingInfo(cl_int* err = NULL) const
1585 typename detail::param_traits<
1586 detail::cl_profiling_info, name>::param_type param;
1587 cl_int result = getProfilingInfo(name, ¶m);
1596 return detail::errHandler(
1597 ::clWaitForEvents(1, &object_),
1598 __WAIT_FOR_EVENTS_ERR);
1601 #if defined(CL_VERSION_1_1)
1604 void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
1605 void * user_data = NULL)
1607 return detail::errHandler(
1608 ::clSetEventCallback(
1613 __SET_EVENT_CALLBACK_ERR);
1618 waitForEvents(const VECTOR_CLASS<Event>& events)
1620 return detail::errHandler(
1622 (cl_uint) events.size(), (cl_event*)&events.front()),
1623 __WAIT_FOR_EVENTS_ERR);
1627 __GET_INFO_HELPER_WITH_RETAIN(cl::Event)
1629 #if defined(CL_VERSION_1_1)
1630 /*! \class UserEvent
1631 * \brief User event interface for cl_event.
1633 class UserEvent : public Event
1637 const Context& context,
1638 cl_int * err = NULL)
1641 object_ = ::clCreateUserEvent(
1645 detail::errHandler(error, __CREATE_USER_EVENT_ERR);
1651 UserEvent() : Event() { }
1653 UserEvent(const UserEvent& event) : Event(event) { }
1655 UserEvent& operator = (const UserEvent& rhs)
1658 Event::operator=(rhs);
1663 cl_int setStatus(cl_int status)
1665 return detail::errHandler(
1666 ::clSetUserEventStatus(object_,status),
1667 __SET_USER_EVENT_STATUS_ERR);
1672 inline static cl_int
1673 WaitForEvents(const VECTOR_CLASS<Event>& events)
1675 return detail::errHandler(
1677 (cl_uint) events.size(), (cl_event*)&events.front()),
1678 __WAIT_FOR_EVENTS_ERR);
1682 * \brief Memory interface for cl_mem.
1684 class Memory : public detail::Wrapper<cl_mem>
1687 Memory() : detail::Wrapper<cl_type>() { }
1689 Memory(const Memory& memory) : detail::Wrapper<cl_type>(memory) { }
1691 Memory& operator = (const Memory& rhs)
1694 detail::Wrapper<cl_type>::operator=(rhs);
1699 template <typename T>
1700 cl_int getInfo(cl_mem_info name, T* param) const
1702 return detail::errHandler(
1703 detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
1704 __GET_MEM_OBJECT_INFO_ERR);
1707 template <cl_int name> typename
1708 detail::param_traits<detail::cl_mem_info, name>::param_type
1709 getInfo(cl_int* err = NULL) const
1711 typename detail::param_traits<
1712 detail::cl_mem_info, name>::param_type param;
1713 cl_int result = getInfo(name, ¶m);
1720 #if defined(CL_VERSION_1_1)
1721 cl_int setDestructorCallback(
1722 void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
1723 void * user_data = NULL)
1725 return detail::errHandler(
1726 ::clSetMemObjectDestructorCallback(
1730 __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
1736 __GET_INFO_HELPER_WITH_RETAIN(cl::Memory)
1739 * \brief Memory buffer interface.
1741 class Buffer : public Memory
1745 const Context& context,
1748 void* host_ptr = NULL,
1752 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
1754 detail::errHandler(error, __CREATE_BUFFER_ERR);
1760 Buffer() : Memory() { }
1762 Buffer(const Buffer& buffer) : Memory(buffer) { }
1764 Buffer& operator = (const Buffer& rhs)
1767 Memory::operator=(rhs);
1772 #if defined(CL_VERSION_1_1)
1773 Buffer createSubBuffer(
1775 cl_buffer_create_type buffer_create_type,
1776 const void * buffer_create_info,
1777 cl_int * err = NULL)
1781 result.object_ = ::clCreateSubBuffer(
1788 detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
1798 #if defined (USE_DX_INTEROP)
1799 class BufferD3D10 : public Buffer
1802 typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
1803 cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
1804 cl_int* errcode_ret);
1807 const Context& context,
1809 ID3D10Buffer* bufobj,
1810 cl_int * err = NULL)
1812 static PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR = NULL;
1813 __INIT_CL_EXT_FCN_PTR(clCreateFromD3D10BufferKHR);
1816 object_ = pfn_clCreateFromD3D10BufferKHR(
1822 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
1828 BufferD3D10() : Buffer() { }
1830 BufferD3D10(const BufferD3D10& buffer) : Buffer(buffer) { }
1832 BufferD3D10& operator = (const BufferD3D10& rhs)
1835 Buffer::operator=(rhs);
1843 * \brief Memory buffer interface for GL interop.
1845 class BufferGL : public Buffer
1849 const Context& context,
1852 cl_int * err = NULL)
1855 object_ = ::clCreateFromGLBuffer(
1861 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
1867 BufferGL() : Buffer() { }
1869 BufferGL(const BufferGL& buffer) : Buffer(buffer) { }
1871 BufferGL& operator = (const BufferGL& rhs)
1874 Buffer::operator=(rhs);
1879 cl_int getObjectInfo(
1880 cl_gl_object_type *type,
1881 GLuint * gl_object_name)
1883 return detail::errHandler(
1884 ::clGetGLObjectInfo(object_,type,gl_object_name),
1885 __GET_GL_OBJECT_INFO_ERR);
1889 /*! \class BufferRenderGL
1890 * \brief Memory buffer interface for GL interop with renderbuffer.
1892 class BufferRenderGL : public Buffer
1896 const Context& context,
1899 cl_int * err = NULL)
1902 object_ = ::clCreateFromGLRenderbuffer(
1908 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
1914 BufferRenderGL() : Buffer() { }
1916 BufferRenderGL(const BufferGL& buffer) : Buffer(buffer) { }
1918 BufferRenderGL& operator = (const BufferRenderGL& rhs)
1921 Buffer::operator=(rhs);
1926 cl_int getObjectInfo(
1927 cl_gl_object_type *type,
1928 GLuint * gl_object_name)
1930 return detail::errHandler(
1931 ::clGetGLObjectInfo(object_,type,gl_object_name),
1932 __GET_GL_OBJECT_INFO_ERR);
1937 * \brief Base class interface for all images.
1939 class Image : public Memory
1942 Image() : Memory() { }
1944 Image(const Image& image) : Memory(image) { }
1946 Image& operator = (const Image& rhs)
1949 Memory::operator=(rhs);
1954 template <typename T>
1955 cl_int getImageInfo(cl_image_info name, T* param) const
1957 return detail::errHandler(
1958 detail::getInfo(&::clGetImageInfo, object_, name, param),
1959 __GET_IMAGE_INFO_ERR);
1962 template <cl_int name> typename
1963 detail::param_traits<detail::cl_image_info, name>::param_type
1964 getImageInfo(cl_int* err = NULL) const
1966 typename detail::param_traits<
1967 detail::cl_image_info, name>::param_type param;
1968 cl_int result = getImageInfo(name, ¶m);
1977 * \brief Image interface for 2D images.
1979 class Image2D : public Image
1983 const Context& context,
1988 ::size_t row_pitch = 0,
1989 void* host_ptr = NULL,
1993 object_ = ::clCreateImage2D(
1994 context(), flags,&format, width, height, row_pitch, host_ptr, &error);
1996 detail::errHandler(error, __CREATE_IMAGE2D_ERR);
2004 Image2D(const Image2D& image2D) : Image(image2D) { }
2006 Image2D& operator = (const Image2D& rhs)
2009 Image::operator=(rhs);
2015 /*! \class Image2DGL
2016 * \brief 2D image interface for GL interop.
2018 class Image2DGL : public Image2D
2022 const Context& context,
2027 cl_int * err = NULL)
2030 object_ = ::clCreateFromGLTexture2D(
2038 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
2044 Image2DGL() : Image2D() { }
2046 Image2DGL(const Image2DGL& image) : Image2D(image) { }
2048 Image2DGL& operator = (const Image2DGL& rhs)
2051 Image2D::operator=(rhs);
2058 * \brief Image interface for 3D images.
2060 class Image3D : public Image
2064 const Context& context,
2070 ::size_t row_pitch = 0,
2071 ::size_t slice_pitch = 0,
2072 void* host_ptr = NULL,
2076 object_ = ::clCreateImage3D(
2077 context(), flags, &format, width, height, depth, row_pitch,
2078 slice_pitch, host_ptr, &error);
2080 detail::errHandler(error, __CREATE_IMAGE3D_ERR);
2088 Image3D(const Image3D& image3D) : Image(image3D) { }
2090 Image3D& operator = (const Image3D& rhs)
2093 Image::operator=(rhs);
2099 /*! \class Image2DGL
2100 * \brief 2D image interface for GL interop.
2102 class Image3DGL : public Image3D
2106 const Context& context,
2111 cl_int * err = NULL)
2114 object_ = ::clCreateFromGLTexture3D(
2122 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
2128 Image3DGL() : Image3D() { }
2130 Image3DGL(const Image3DGL& image) : Image3D(image) { }
2132 Image3DGL& operator = (const Image3DGL& rhs)
2135 Image3D::operator=(rhs);
2142 * \brief Sampler interface for cl_sampler.
2144 class Sampler : public detail::Wrapper<cl_sampler>
2150 const Context& context,
2151 cl_bool normalized_coords,
2152 cl_addressing_mode addressing_mode,
2153 cl_filter_mode filter_mode,
2157 object_ = ::clCreateSampler(
2164 detail::errHandler(error, __CREATE_SAMPLER_ERR);
2170 Sampler(const Sampler& sampler) : detail::Wrapper<cl_type>(sampler) { }
2172 Sampler& operator = (const Sampler& rhs)
2175 detail::Wrapper<cl_type>::operator=(rhs);
2180 template <typename T>
2181 cl_int getInfo(cl_sampler_info name, T* param) const
2183 return detail::errHandler(
2184 detail::getInfo(&::clGetSamplerInfo, object_, name, param),
2185 __GET_SAMPLER_INFO_ERR);
2188 template <cl_int name> typename
2189 detail::param_traits<detail::cl_sampler_info, name>::param_type
2190 getInfo(cl_int* err = NULL) const
2192 typename detail::param_traits<
2193 detail::cl_sampler_info, name>::param_type param;
2194 cl_int result = getInfo(name, ¶m);
2202 __GET_INFO_HELPER_WITH_RETAIN(cl::Sampler)
2209 * \brief NDRange interface
2215 cl_uint dimensions_;
2222 NDRange(::size_t size0)
2225 sizes_.push_back(size0);
2228 NDRange(::size_t size0, ::size_t size1)
2231 sizes_.push_back(size0);
2232 sizes_.push_back(size1);
2235 NDRange(::size_t size0, ::size_t size1, ::size_t size2)
2238 sizes_.push_back(size0);
2239 sizes_.push_back(size1);
2240 sizes_.push_back(size2);
2243 operator const ::size_t*() const { return (const ::size_t*) sizes_; }
2244 ::size_t dimensions() const { return dimensions_; }
2247 static const NDRange NullRange;
2250 * \struct LocalSpaceArg
2251 * \brief Local address raper for use with Kernel::setArg
2253 struct LocalSpaceArg
2260 template <typename T>
2261 struct KernelArgumentHandler
2263 static ::size_t size(const T&) { return sizeof(T); }
2264 static T* ptr(T& value) { return &value; }
2268 struct KernelArgumentHandler<LocalSpaceArg>
2270 static ::size_t size(const LocalSpaceArg& value) { return value.size_; }
2271 static void* ptr(LocalSpaceArg&) { return NULL; }
2277 inline LocalSpaceArg
2278 __local(::size_t size)
2280 LocalSpaceArg ret = { size };
2284 class KernelFunctor;
2287 * \brief Kernel interface that implements cl_kernel
2289 class Kernel : public detail::Wrapper<cl_kernel>
2292 inline Kernel(const Program& program, const char* name, cl_int* err = NULL);
2296 Kernel(const Kernel& kernel) : detail::Wrapper<cl_type>(kernel) { }
2298 Kernel& operator = (const Kernel& rhs)
2301 detail::Wrapper<cl_type>::operator=(rhs);
2306 template <typename T>
2307 cl_int getInfo(cl_kernel_info name, T* param) const
2309 return detail::errHandler(
2310 detail::getInfo(&::clGetKernelInfo, object_, name, param),
2311 __GET_KERNEL_INFO_ERR);
2314 template <cl_int name> typename
2315 detail::param_traits<detail::cl_kernel_info, name>::param_type
2316 getInfo(cl_int* err = NULL) const
2318 typename detail::param_traits<
2319 detail::cl_kernel_info, name>::param_type param;
2320 cl_int result = getInfo(name, ¶m);
2327 template <typename T>
2328 cl_int getWorkGroupInfo(
2329 const Device& device, cl_kernel_work_group_info name, T* param) const
2331 return detail::errHandler(
2333 &::clGetKernelWorkGroupInfo, object_, device(), name, param),
2334 __GET_KERNEL_WORK_GROUP_INFO_ERR);
2337 template <cl_int name> typename
2338 detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
2339 getWorkGroupInfo(const Device& device, cl_int* err = NULL) const
2341 typename detail::param_traits<
2342 detail::cl_kernel_work_group_info, name>::param_type param;
2343 cl_int result = getWorkGroupInfo(device, name, ¶m);
2350 template <typename T>
2351 cl_int setArg(cl_uint index, T value)
2353 return detail::errHandler(
2357 detail::KernelArgumentHandler<T>::size(value),
2358 detail::KernelArgumentHandler<T>::ptr(value)),
2359 __SET_KERNEL_ARGS_ERR);
2362 cl_int setArg(cl_uint index, ::size_t size, void* argPtr)
2364 return detail::errHandler(
2365 ::clSetKernelArg(object_, index, size, argPtr),
2366 __SET_KERNEL_ARGS_ERR);
2370 const CommandQueue& queue,
2371 const NDRange& offset,
2372 const NDRange& global,
2373 const NDRange& local);
2376 const CommandQueue& queue,
2377 const NDRange& global,
2378 const NDRange& local);
2381 __GET_INFO_HELPER_WITH_RETAIN(cl::Kernel)
2384 * \brief Program interface that implements cl_program.
2386 class Program : public detail::Wrapper<cl_program>
2389 typedef VECTOR_CLASS<std::pair<const void*, ::size_t> > Binaries;
2390 typedef VECTOR_CLASS<std::pair<const char*, ::size_t> > Sources;
2393 const Context& context,
2394 const Sources& sources,
2399 const ::size_t n = (::size_t)sources.size();
2400 ::size_t* lengths = (::size_t*) alloca(n * sizeof(::size_t));
2401 const char** strings = (const char**) alloca(n * sizeof(const char*));
2403 for (::size_t i = 0; i < n; ++i) {
2404 strings[i] = sources[(int)i].first;
2405 lengths[i] = sources[(int)i].second;
2408 object_ = ::clCreateProgramWithSource(
2409 context(), (cl_uint)n, strings, lengths, &error);
2411 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
2418 const Context& context,
2419 const VECTOR_CLASS<Device>& devices,
2420 const Binaries& binaries,
2421 VECTOR_CLASS<cl_int>* binaryStatus = NULL,
2425 const ::size_t n = binaries.size();
2426 ::size_t* lengths = (::size_t*) alloca(n * sizeof(::size_t));
2427 const unsigned char** images = (const unsigned char**) alloca(n * sizeof(const void*));
2429 for (::size_t i = 0; i < n; ++i) {
2430 images[i] = (const unsigned char*)binaries[(int)i].first;
2431 lengths[i] = binaries[(int)i].second;
2434 object_ = ::clCreateProgramWithBinary(
2435 context(), (cl_uint) devices.size(),
2436 (cl_device_id*)&devices.front(),
2437 lengths, images, binaryStatus != NULL
2438 ? (cl_int*) &binaryStatus->front()
2441 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
2449 Program(const Program& program) : detail::Wrapper<cl_type>(program) { }
2451 Program& operator = (const Program& rhs)
2454 detail::Wrapper<cl_type>::operator=(rhs);
2460 const VECTOR_CLASS<Device>& devices,
2461 const char* options = NULL,
2462 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
2463 void* data = NULL) const
2465 return detail::errHandler(
2470 (cl_device_id*)&devices.front(),
2474 __BUILD_PROGRAM_ERR);
2477 template <typename T>
2478 cl_int getInfo(cl_program_info name, T* param) const
2480 return detail::errHandler(
2481 detail::getInfo(&::clGetProgramInfo, object_, name, param),
2482 __GET_PROGRAM_INFO_ERR);
2485 template <cl_int name> typename
2486 detail::param_traits<detail::cl_program_info, name>::param_type
2487 getInfo(cl_int* err = NULL) const
2489 typename detail::param_traits<
2490 detail::cl_program_info, name>::param_type param;
2491 cl_int result = getInfo(name, ¶m);
2498 template <typename T>
2499 cl_int getBuildInfo(
2500 const Device& device, cl_program_build_info name, T* param) const
2502 return detail::errHandler(
2504 &::clGetProgramBuildInfo, object_, device(), name, param),
2505 __GET_PROGRAM_BUILD_INFO_ERR);
2508 template <cl_int name> typename
2509 detail::param_traits<detail::cl_program_build_info, name>::param_type
2510 getBuildInfo(const Device& device, cl_int* err = NULL) const
2512 typename detail::param_traits<
2513 detail::cl_program_build_info, name>::param_type param;
2514 cl_int result = getBuildInfo(device, name, ¶m);
2521 cl_int createKernels(VECTOR_CLASS<Kernel>* kernels)
2524 cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
2525 if (err != CL_SUCCESS) {
2526 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
2529 Kernel* value = (Kernel*) alloca(numKernels * sizeof(Kernel));
2530 err = ::clCreateKernelsInProgram(
2531 object_, numKernels, (cl_kernel*) value, NULL);
2532 if (err != CL_SUCCESS) {
2533 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
2536 kernels->assign(&value[0], &value[numKernels]);
2541 __GET_INFO_HELPER_WITH_RETAIN(cl::Program)
2543 inline Kernel::Kernel(const Program& program, const char* name, cl_int* err)
2547 object_ = ::clCreateKernel(program(), name, &error);
2548 detail::errHandler(error, __CREATE_KERNEL_ERR);
2556 /*! \class CommandQueue
2557 * \brief CommandQueue interface for cl_command_queue.
2559 class CommandQueue : public detail::Wrapper<cl_command_queue>
2563 const Context& context,
2564 const Device& device,
2565 cl_command_queue_properties properties = 0,
2569 object_ = ::clCreateCommandQueue(
2570 context(), device(), properties, &error);
2572 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
2580 CommandQueue(const CommandQueue& commandQueue) : detail::Wrapper<cl_type>(commandQueue) { }
2582 CommandQueue& operator = (const CommandQueue& rhs)
2585 detail::Wrapper<cl_type>::operator=(rhs);
2590 template <typename T>
2591 cl_int getInfo(cl_command_queue_info name, T* param) const
2593 return detail::errHandler(
2595 &::clGetCommandQueueInfo, object_, name, param),
2596 __GET_COMMAND_QUEUE_INFO_ERR);
2599 template <cl_int name> typename
2600 detail::param_traits<detail::cl_command_queue_info, name>::param_type
2601 getInfo(cl_int* err = NULL) const
2603 typename detail::param_traits<
2604 detail::cl_command_queue_info, name>::param_type param;
2605 cl_int result = getInfo(name, ¶m);
2612 cl_int enqueueReadBuffer(
2613 const Buffer& buffer,
2618 const VECTOR_CLASS<Event>* events = NULL,
2619 Event* event = NULL) const
2621 return detail::errHandler(
2622 ::clEnqueueReadBuffer(
2623 object_, buffer(), blocking, offset, size,
2625 (events != NULL) ? (cl_uint) events->size() : 0,
2626 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
2628 __ENQUEUE_READ_BUFFER_ERR);
2631 cl_int enqueueWriteBuffer(
2632 const Buffer& buffer,
2637 const VECTOR_CLASS<Event>* events = NULL,
2638 Event* event = NULL) const
2640 return detail::errHandler(
2641 ::clEnqueueWriteBuffer(
2642 object_, buffer(), blocking, offset, size,
2644 (events != NULL) ? (cl_uint) events->size() : 0,
2645 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
2647 __ENQUEUE_WRITE_BUFFER_ERR);
2650 cl_int enqueueCopyBuffer(
2653 ::size_t src_offset,
2654 ::size_t dst_offset,
2656 const VECTOR_CLASS<Event>* events = NULL,
2657 Event* event = NULL) const
2659 return detail::errHandler(
2660 ::clEnqueueCopyBuffer(
2661 object_, src(), dst(), src_offset, dst_offset, size,
2662 (events != NULL) ? (cl_uint) events->size() : 0,
2663 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
2665 __ENQEUE_COPY_BUFFER_ERR);
2668 #if defined(CL_VERSION_1_1)
2669 cl_int enqueueReadBufferRect(
2670 const Buffer& buffer,
2672 const size_t<3>& buffer_offset,
2673 const size_t<3>& host_offset,
2674 const size_t<3>& region,
2675 ::size_t buffer_row_pitch,
2676 ::size_t buffer_slice_pitch,
2677 ::size_t host_row_pitch,
2678 ::size_t host_slice_pitch,
2680 const VECTOR_CLASS<Event>* events = NULL,
2681 Event* event = NULL) const
2683 return detail::errHandler(
2684 ::clEnqueueReadBufferRect(
2688 (const ::size_t *)buffer_offset,
2689 (const ::size_t *)host_offset,
2690 (const ::size_t *)region,
2696 (events != NULL) ? (cl_uint) events->size() : 0,
2697 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
2699 __ENQUEUE_READ_BUFFER_RECT_ERR);
2703 cl_int enqueueWriteBufferRect(
2704 const Buffer& buffer,
2706 const size_t<3>& buffer_offset,
2707 const size_t<3>& host_offset,
2708 const size_t<3>& region,
2709 ::size_t buffer_row_pitch,
2710 ::size_t buffer_slice_pitch,
2711 ::size_t host_row_pitch,
2712 ::size_t host_slice_pitch,
2714 const VECTOR_CLASS<Event>* events = NULL,
2715 Event* event = NULL) const
2717 return detail::errHandler(
2718 ::clEnqueueWriteBufferRect(
2722 (const ::size_t *)buffer_offset,
2723 (const ::size_t *)host_offset,
2724 (const ::size_t *)region,
2730 (events != NULL) ? (cl_uint) events->size() : 0,
2731 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
2733 __ENQUEUE_WRITE_BUFFER_RECT_ERR);
2736 cl_int enqueueCopyBufferRect(
2739 const size_t<3>& src_origin,
2740 const size_t<3>& dst_origin,
2741 const size_t<3>& region,
2742 ::size_t src_row_pitch,
2743 ::size_t src_slice_pitch,
2744 ::size_t dst_row_pitch,
2745 ::size_t dst_slice_pitch,
2746 const VECTOR_CLASS<Event>* events = NULL,
2747 Event* event = NULL) const
2749 return detail::errHandler(
2750 ::clEnqueueCopyBufferRect(
2754 (const ::size_t *)src_origin,
2755 (const ::size_t *)dst_origin,
2756 (const ::size_t *)region,
2761 (events != NULL) ? (cl_uint) events->size() : 0,
2762 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
2764 __ENQEUE_COPY_BUFFER_RECT_ERR);
2768 cl_int enqueueReadImage(
2771 const size_t<3>& origin,
2772 const size_t<3>& region,
2774 ::size_t slice_pitch,
2776 const VECTOR_CLASS<Event>* events = NULL,
2777 Event* event = NULL) const
2779 return detail::errHandler(
2780 ::clEnqueueReadImage(
2781 object_, image(), blocking, (const ::size_t *) origin,
2782 (const ::size_t *) region, row_pitch, slice_pitch, ptr,
2783 (events != NULL) ? (cl_uint) events->size() : 0,
2784 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
2786 __ENQUEUE_READ_IMAGE_ERR);
2789 cl_int enqueueWriteImage(
2792 const size_t<3>& origin,
2793 const size_t<3>& region,
2795 ::size_t slice_pitch,
2797 const VECTOR_CLASS<Event>* events = NULL,
2798 Event* event = NULL) const
2800 return detail::errHandler(
2801 ::clEnqueueWriteImage(
2802 object_, image(), blocking, (const ::size_t *) origin,
2803 (const ::size_t *) region, row_pitch, slice_pitch, ptr,
2804 (events != NULL) ? (cl_uint) events->size() : 0,
2805 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
2807 __ENQUEUE_WRITE_IMAGE_ERR);
2810 cl_int enqueueCopyImage(
2813 const size_t<3>& src_origin,
2814 const size_t<3>& dst_origin,
2815 const size_t<3>& region,
2816 const VECTOR_CLASS<Event>* events = NULL,
2817 Event* event = NULL) const
2819 return detail::errHandler(
2820 ::clEnqueueCopyImage(
2821 object_, src(), dst(), (const ::size_t *) src_origin,
2822 (const ::size_t *)dst_origin, (const ::size_t *) region,
2823 (events != NULL) ? (cl_uint) events->size() : 0,
2824 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
2826 __ENQUEUE_COPY_IMAGE_ERR);
2829 cl_int enqueueCopyImageToBuffer(
2832 const size_t<3>& src_origin,
2833 const size_t<3>& region,
2834 ::size_t dst_offset,
2835 const VECTOR_CLASS<Event>* events = NULL,
2836 Event* event = NULL) const
2838 return detail::errHandler(
2839 ::clEnqueueCopyImageToBuffer(
2840 object_, src(), dst(), (const ::size_t *) src_origin,
2841 (const ::size_t *) region, dst_offset,
2842 (events != NULL) ? (cl_uint) events->size() : 0,
2843 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
2845 __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
2848 cl_int enqueueCopyBufferToImage(
2851 ::size_t src_offset,
2852 const size_t<3>& dst_origin,
2853 const size_t<3>& region,
2854 const VECTOR_CLASS<Event>* events = NULL,
2855 Event* event = NULL) const
2857 return detail::errHandler(
2858 ::clEnqueueCopyBufferToImage(
2859 object_, src(), dst(), src_offset,
2860 (const ::size_t *) dst_origin, (const ::size_t *) region,
2861 (events != NULL) ? (cl_uint) events->size() : 0,
2862 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
2864 __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
2867 void* enqueueMapBuffer(
2868 const Buffer& buffer,
2873 const VECTOR_CLASS<Event>* events = NULL,
2874 Event* event = NULL,
2875 cl_int* err = NULL) const
2878 void * result = ::clEnqueueMapBuffer(
2879 object_, buffer(), blocking, flags, offset, size,
2880 (events != NULL) ? (cl_uint) events->size() : 0,
2881 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
2885 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
2892 void* enqueueMapImage(
2893 const Image& buffer,
2896 const size_t<3>& origin,
2897 const size_t<3>& region,
2898 ::size_t * row_pitch,
2899 ::size_t * slice_pitch,
2900 const VECTOR_CLASS<Event>* events = NULL,
2901 Event* event = NULL,
2902 cl_int* err = NULL) const
2905 void * result = ::clEnqueueMapImage(
2906 object_, buffer(), blocking, flags,
2907 (const ::size_t *) origin, (const ::size_t *) region,
2908 row_pitch, slice_pitch,
2909 (events != NULL) ? (cl_uint) events->size() : 0,
2910 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
2914 detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
2921 cl_int enqueueUnmapMemObject(
2922 const Memory& memory,
2924 const VECTOR_CLASS<Event>* events = NULL,
2925 Event* event = NULL) const
2927 return detail::errHandler(
2928 ::clEnqueueUnmapMemObject(
2929 object_, memory(), mapped_ptr,
2930 (events != NULL) ? (cl_uint) events->size() : 0,
2931 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
2933 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
2936 cl_int enqueueNDRangeKernel(
2937 const Kernel& kernel,
2938 const NDRange& offset,
2939 const NDRange& global,
2940 const NDRange& local,
2941 const VECTOR_CLASS<Event>* events = NULL,
2942 Event* event = NULL) const
2944 return detail::errHandler(
2945 ::clEnqueueNDRangeKernel(
2946 object_, kernel(), (cl_uint) global.dimensions(),
2947 offset.dimensions() != 0 ? (const ::size_t*) offset : NULL,
2948 (const ::size_t*) global,
2949 local.dimensions() != 0 ? (const ::size_t*) local : NULL,
2950 (events != NULL) ? (cl_uint) events->size() : 0,
2951 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
2953 __ENQUEUE_NDRANGE_KERNEL_ERR);
2957 const Kernel& kernel,
2958 const VECTOR_CLASS<Event>* events = NULL,
2959 Event* event = NULL) const
2961 return detail::errHandler(
2964 (events != NULL) ? (cl_uint) events->size() : 0,
2965 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
2967 __ENQUEUE_TASK_ERR);
2970 cl_int enqueueNativeKernel(
2971 void (*userFptr)(void *),
2972 std::pair<void*, ::size_t> args,
2973 const VECTOR_CLASS<Memory>* mem_objects = NULL,
2974 const VECTOR_CLASS<const void*>* mem_locs = NULL,
2975 const VECTOR_CLASS<Event>* events = NULL,
2976 Event* event = NULL) const
2978 cl_mem * mems = (mem_objects != NULL && mem_objects->size() > 0)
2979 ? (cl_mem*) alloca(mem_objects->size() * sizeof(cl_mem))
2983 for (unsigned int i = 0; i < mem_objects->size(); i++) {
2984 mems[i] = ((*mem_objects)[i])();
2988 return detail::errHandler(
2989 ::clEnqueueNativeKernel(
2990 object_, userFptr, args.first, args.second,
2991 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
2993 (mem_locs != NULL) ? (const void **) &mem_locs->front() : NULL,
2994 (events != NULL) ? (cl_uint) events->size() : 0,
2995 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
2997 __ENQUEUE_NATIVE_KERNEL);
3000 cl_int enqueueMarker(Event* event = NULL) const
3002 return detail::errHandler(
3003 ::clEnqueueMarker(object_, (cl_event*) event),
3004 __ENQUEUE_MARKER_ERR);
3007 cl_int enqueueWaitForEvents(const VECTOR_CLASS<Event>& events) const
3009 return detail::errHandler(
3010 ::clEnqueueWaitForEvents(
3012 (cl_uint) events.size(),
3013 (const cl_event*) &events.front()),
3014 __ENQUEUE_WAIT_FOR_EVENTS_ERR);
3017 cl_int enqueueAcquireGLObjects(
3018 const VECTOR_CLASS<Memory>* mem_objects = NULL,
3019 const VECTOR_CLASS<Event>* events = NULL,
3020 Event* event = NULL) const
3022 return detail::errHandler(
3023 ::clEnqueueAcquireGLObjects(
3025 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
3026 (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
3027 (events != NULL) ? (cl_uint) events->size() : 0,
3028 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
3030 __ENQUEUE_ACQUIRE_GL_ERR);
3033 cl_int enqueueReleaseGLObjects(
3034 const VECTOR_CLASS<Memory>* mem_objects = NULL,
3035 const VECTOR_CLASS<Event>* events = NULL,
3036 Event* event = NULL) const
3038 return detail::errHandler(
3039 ::clEnqueueReleaseGLObjects(
3041 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
3042 (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
3043 (events != NULL) ? (cl_uint) events->size() : 0,
3044 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
3046 __ENQUEUE_RELEASE_GL_ERR);
3049 #if defined (USE_DX_INTEROP)
3050 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
3051 cl_command_queue command_queue, cl_uint num_objects,
3052 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
3053 const cl_event* event_wait_list, cl_event* event);
3054 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
3055 cl_command_queue command_queue, cl_uint num_objects,
3056 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
3057 const cl_event* event_wait_list, cl_event* event);
3059 cl_int enqueueAcquireD3D10Objects(
3060 const VECTOR_CLASS<Memory>* mem_objects = NULL,
3061 const VECTOR_CLASS<Event>* events = NULL,
3062 Event* event = NULL) const
3064 static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
3065 __INIT_CL_EXT_FCN_PTR(clEnqueueAcquireD3D10ObjectsKHR);
3067 return detail::errHandler(
3068 pfn_clEnqueueAcquireD3D10ObjectsKHR(
3070 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
3071 (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
3072 (events != NULL) ? (cl_uint) events->size() : 0,
3073 (events != NULL) ? (cl_event*) &events->front() : NULL,
3075 __ENQUEUE_ACQUIRE_GL_ERR);
3078 cl_int enqueueReleaseD3D10Objects(
3079 const VECTOR_CLASS<Memory>* mem_objects = NULL,
3080 const VECTOR_CLASS<Event>* events = NULL,
3081 Event* event = NULL) const
3083 static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL;
3084 __INIT_CL_EXT_FCN_PTR(clEnqueueReleaseD3D10ObjectsKHR);
3086 return detail::errHandler(
3087 pfn_clEnqueueReleaseD3D10ObjectsKHR(
3089 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
3090 (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
3091 (events != NULL) ? (cl_uint) events->size() : 0,
3092 (events != NULL) ? (cl_event*) &events->front() : NULL,
3094 __ENQUEUE_RELEASE_GL_ERR);
3098 cl_int enqueueBarrier() const
3100 return detail::errHandler(
3101 ::clEnqueueBarrier(object_),
3102 __ENQUEUE_BARRIER_ERR);
3105 cl_int flush() const
3107 return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
3110 cl_int finish() const
3112 return detail::errHandler(::clFinish(object_), __FINISH_ERR);
3116 __GET_INFO_HELPER_WITH_RETAIN(cl::CommandQueue)
3118 /*! \class KernelFunctor
3119 * \brief Kernel functor interface
3121 * \note Currently only functors of zero to ten arguments are supported. It
3122 * is straightforward to add more and a more general solution, similar to
3123 * Boost.Lambda could be followed if required in the future.
3129 CommandQueue queue_;
3139 const Kernel& kernel,
3140 const CommandQueue& queue,
3141 const NDRange& offset,
3142 const NDRange& global,
3143 const NDRange& local) :
3152 KernelFunctor& operator=(const KernelFunctor& rhs);
3154 KernelFunctor(const KernelFunctor& rhs);
3156 cl_int getError() { return err_; }
3158 inline Event operator()(const VECTOR_CLASS<Event>* events = NULL);
3160 template<typename A1>
3161 inline Event operator()(
3163 const VECTOR_CLASS<Event>* events = NULL);
3165 template<class A1, class A2>
3166 inline Event operator()(
3169 const VECTOR_CLASS<Event>* events = NULL);
3171 template<class A1, class A2, class A3>
3172 inline Event operator()(
3176 const VECTOR_CLASS<Event>* events = NULL);
3178 template<class A1, class A2, class A3, class A4>
3179 inline Event operator()(
3184 const VECTOR_CLASS<Event>* events = NULL);
3186 template<class A1, class A2, class A3, class A4, class A5>
3187 inline Event operator()(
3193 const VECTOR_CLASS<Event>* events = NULL);
3195 template<class A1, class A2, class A3, class A4, class A5, class A6>
3196 inline Event operator()(
3203 const VECTOR_CLASS<Event>* events = NULL);
3205 template<class A1, class A2, class A3, class A4,
3206 class A5, class A6, class A7>
3207 inline Event operator()(
3215 const VECTOR_CLASS<Event>* events = NULL);
3217 template<class A1, class A2, class A3, class A4, class A5,
3218 class A6, class A7, class A8>
3219 inline Event operator()(
3228 const VECTOR_CLASS<Event>* events = NULL);
3230 template<class A1, class A2, class A3, class A4, class A5,
3231 class A6, class A7, class A8, class A9>
3232 inline Event operator()(
3242 const VECTOR_CLASS<Event>* events = NULL);
3244 template<class A1, class A2, class A3, class A4, class A5,
3245 class A6, class A7, class A8, class A9, class A10>
3246 inline Event operator()(
3257 const VECTOR_CLASS<Event>* events = NULL);
3259 template<class A1, class A2, class A3, class A4, class A5,
3260 class A6, class A7, class A8, class A9, class A10,
3262 inline Event operator()(
3274 const VECTOR_CLASS<Event>* events = NULL);
3276 template<class A1, class A2, class A3, class A4, class A5,
3277 class A6, class A7, class A8, class A9, class A10,
3278 class A11, class A12>
3279 inline Event operator()(
3292 const VECTOR_CLASS<Event>* events = NULL);
3294 template<class A1, class A2, class A3, class A4, class A5,
3295 class A6, class A7, class A8, class A9, class A10,
3296 class A11, class A12, class A13>
3297 inline Event operator()(
3311 const VECTOR_CLASS<Event>* events = NULL);
3313 template<class A1, class A2, class A3, class A4, class A5,
3314 class A6, class A7, class A8, class A9, class A10,
3315 class A11, class A12, class A13, class A14>
3316 inline Event operator()(
3331 const VECTOR_CLASS<Event>* events = NULL);
3333 template<class A1, class A2, class A3, class A4, class A5,
3334 class A6, class A7, class A8, class A9, class A10,
3335 class A11, class A12, class A13, class A14, class A15>
3336 inline Event operator()(
3352 const VECTOR_CLASS<Event>* events = NULL);
3355 inline KernelFunctor Kernel::bind(
3356 const CommandQueue& queue,
3357 const NDRange& offset,
3358 const NDRange& global,
3359 const NDRange& local)
3361 return KernelFunctor(*this,queue,offset,global,local);
3364 inline KernelFunctor Kernel::bind(
3365 const CommandQueue& queue,
3366 const NDRange& global,
3367 const NDRange& local)
3369 return KernelFunctor(*this,queue,NullRange,global,local);
3372 inline KernelFunctor& KernelFunctor::operator=(const KernelFunctor& rhs)
3378 kernel_ = rhs.kernel_;
3379 queue_ = rhs.queue_;
3380 offset_ = rhs.offset_;
3381 global_ = rhs.global_;
3382 local_ = rhs.local_;
3387 inline KernelFunctor::KernelFunctor(const KernelFunctor& rhs) :
3388 kernel_(rhs.kernel_),
3390 offset_(rhs.offset_),
3391 global_(rhs.global_),
3396 Event KernelFunctor::operator()(const VECTOR_CLASS<Event>* events)
3400 err_ = queue_.enqueueNDRangeKernel(
3405 NULL, // bgaster_fixme - do we want to allow wait event lists?
3411 template<typename A1>
3412 Event KernelFunctor::operator()(
3414 const VECTOR_CLASS<Event>* events)
3418 kernel_.setArg(0,a1);
3420 err_ = queue_.enqueueNDRangeKernel(
3425 NULL, // bgaster_fixme - do we want to allow wait event lists?
3431 template<typename A1, typename A2>
3432 Event KernelFunctor::operator()(
3435 const VECTOR_CLASS<Event>* events)
3439 kernel_.setArg(0,a1);
3440 kernel_.setArg(1,a2);
3442 err_ = queue_.enqueueNDRangeKernel(
3447 NULL, // bgaster_fixme - do we want to allow wait event lists?
3453 template<typename A1, typename A2, typename A3>
3454 Event KernelFunctor::operator()(
3458 const VECTOR_CLASS<Event>* events)
3462 kernel_.setArg(0,a1);
3463 kernel_.setArg(1,a2);
3464 kernel_.setArg(2,a3);
3466 err_ = queue_.enqueueNDRangeKernel(
3471 NULL, // bgaster_fixme - do we want to allow wait event lists?
3477 template<typename A1, typename A2, typename A3, typename A4>
3478 Event KernelFunctor::operator()(
3483 const VECTOR_CLASS<Event>* events)
3487 kernel_.setArg(0,a1);
3488 kernel_.setArg(1,a2);
3489 kernel_.setArg(2,a3);
3490 kernel_.setArg(3,a4);
3492 err_ = queue_.enqueueNDRangeKernel(
3497 NULL, // bgaster_fixme - do we want to allow wait event lists?
3503 template<typename A1, typename A2, typename A3, typename A4, typename A5>
3504 Event KernelFunctor::operator()(
3510 const VECTOR_CLASS<Event>* events)
3514 kernel_.setArg(0,a1);
3515 kernel_.setArg(1,a2);
3516 kernel_.setArg(2,a3);
3517 kernel_.setArg(3,a4);
3518 kernel_.setArg(4,a5);
3520 err_ = queue_.enqueueNDRangeKernel(
3525 NULL, // bgaster_fixme - do we want to allow wait event lists?
3531 template<typename A1, typename A2, typename A3, typename A4, typename A5,
3533 Event KernelFunctor::operator()(
3540 const VECTOR_CLASS<Event>* events)
3544 kernel_.setArg(0,a1);
3545 kernel_.setArg(1,a2);
3546 kernel_.setArg(2,a3);
3547 kernel_.setArg(3,a4);
3548 kernel_.setArg(4,a5);
3549 kernel_.setArg(5,a6);
3551 err_ = queue_.enqueueNDRangeKernel(
3556 NULL, // bgaster_fixme - do we want to allow wait event lists?
3562 template<typename A1, typename A2, typename A3, typename A4,
3563 typename A5, typename A6, typename A7>
3564 Event KernelFunctor::operator()(
3572 const VECTOR_CLASS<Event>* events)
3576 kernel_.setArg(0,a1);
3577 kernel_.setArg(1,a2);
3578 kernel_.setArg(2,a3);
3579 kernel_.setArg(3,a4);
3580 kernel_.setArg(4,a5);
3581 kernel_.setArg(5,a6);
3582 kernel_.setArg(6,a7);
3584 err_ = queue_.enqueueNDRangeKernel(
3589 NULL, // bgaster_fixme - do we want to allow wait event lists?
3595 template<typename A1, typename A2, typename A3, typename A4, typename A5,
3596 typename A6, typename A7, typename A8>
3597 Event KernelFunctor::operator()(
3606 const VECTOR_CLASS<Event>* events)
3610 kernel_.setArg(0,a1);
3611 kernel_.setArg(1,a2);
3612 kernel_.setArg(2,a3);
3613 kernel_.setArg(3,a4);
3614 kernel_.setArg(4,a5);
3615 kernel_.setArg(5,a6);
3616 kernel_.setArg(6,a7);
3617 kernel_.setArg(7,a8);
3619 err_ = queue_.enqueueNDRangeKernel(
3624 NULL, // bgaster_fixme - do we want to allow wait event lists?
3630 template<typename A1, typename A2, typename A3, typename A4, typename A5,
3631 typename A6, typename A7, typename A8, typename A9>
3632 Event KernelFunctor::operator()(
3642 const VECTOR_CLASS<Event>* events)
3646 kernel_.setArg(0,a1);
3647 kernel_.setArg(1,a2);
3648 kernel_.setArg(2,a3);
3649 kernel_.setArg(3,a4);
3650 kernel_.setArg(4,a5);
3651 kernel_.setArg(5,a6);
3652 kernel_.setArg(6,a7);
3653 kernel_.setArg(7,a8);
3654 kernel_.setArg(8,a9);
3656 err_ = queue_.enqueueNDRangeKernel(
3661 NULL, // bgaster_fixme - do we want to allow wait event lists?
3667 template<typename A1, typename A2, typename A3, typename A4, typename A5,
3668 typename A6, typename A7, typename A8, typename A9, typename A10>
3669 Event KernelFunctor::operator()(
3680 const VECTOR_CLASS<Event>* events)
3684 kernel_.setArg(0,a1);
3685 kernel_.setArg(1,a2);
3686 kernel_.setArg(2,a3);
3687 kernel_.setArg(3,a4);
3688 kernel_.setArg(4,a5);
3689 kernel_.setArg(5,a6);
3690 kernel_.setArg(6,a7);
3691 kernel_.setArg(7,a8);
3692 kernel_.setArg(8,a9);
3693 kernel_.setArg(9,a10);
3695 err_ = queue_.enqueueNDRangeKernel(
3700 NULL, // bgaster_fixme - do we want to allow wait event lists?
3706 template<class A1, class A2, class A3, class A4, class A5,
3707 class A6, class A7, class A8, class A9, class A10,
3709 Event KernelFunctor::operator()(
3721 const VECTOR_CLASS<Event>* events)
3725 kernel_.setArg(0,a1);
3726 kernel_.setArg(1,a2);
3727 kernel_.setArg(2,a3);
3728 kernel_.setArg(3,a4);
3729 kernel_.setArg(4,a5);
3730 kernel_.setArg(5,a6);
3731 kernel_.setArg(6,a7);
3732 kernel_.setArg(7,a8);
3733 kernel_.setArg(8,a9);
3734 kernel_.setArg(9,a10);
3735 kernel_.setArg(10,a11);
3737 err_ = queue_.enqueueNDRangeKernel(
3742 NULL, // bgaster_fixme - do we want to allow wait event lists?
3748 template<class A1, class A2, class A3, class A4, class A5,
3749 class A6, class A7, class A8, class A9, class A10,
3750 class A11, class A12>
3751 Event KernelFunctor::operator()(
3764 const VECTOR_CLASS<Event>* events)
3768 kernel_.setArg(0,a1);
3769 kernel_.setArg(1,a2);
3770 kernel_.setArg(2,a3);
3771 kernel_.setArg(3,a4);
3772 kernel_.setArg(4,a5);
3773 kernel_.setArg(5,a6);
3774 kernel_.setArg(6,a7);
3775 kernel_.setArg(7,a8);
3776 kernel_.setArg(8,a9);
3777 kernel_.setArg(9,a10);
3778 kernel_.setArg(10,a11);
3779 kernel_.setArg(11,a12);
3781 err_ = queue_.enqueueNDRangeKernel(
3786 NULL, // bgaster_fixme - do we want to allow wait event lists?
3792 template<class A1, class A2, class A3, class A4, class A5,
3793 class A6, class A7, class A8, class A9, class A10,
3794 class A11, class A12, class A13>
3795 Event KernelFunctor::operator()(
3809 const VECTOR_CLASS<Event>* events)
3813 kernel_.setArg(0,a1);
3814 kernel_.setArg(1,a2);
3815 kernel_.setArg(2,a3);
3816 kernel_.setArg(3,a4);
3817 kernel_.setArg(4,a5);
3818 kernel_.setArg(5,a6);
3819 kernel_.setArg(6,a7);
3820 kernel_.setArg(7,a8);
3821 kernel_.setArg(8,a9);
3822 kernel_.setArg(9,a10);
3823 kernel_.setArg(10,a11);
3824 kernel_.setArg(11,a12);
3825 kernel_.setArg(12,a13);
3827 err_ = queue_.enqueueNDRangeKernel(
3832 NULL, // bgaster_fixme - do we want to allow wait event lists?
3838 template<class A1, class A2, class A3, class A4, class A5,
3839 class A6, class A7, class A8, class A9, class A10,
3840 class A11, class A12, class A13, class A14>
3841 Event KernelFunctor::operator()(
3856 const VECTOR_CLASS<Event>* events)
3860 kernel_.setArg(0,a1);
3861 kernel_.setArg(1,a2);
3862 kernel_.setArg(2,a3);
3863 kernel_.setArg(3,a4);
3864 kernel_.setArg(4,a5);
3865 kernel_.setArg(5,a6);
3866 kernel_.setArg(6,a7);
3867 kernel_.setArg(7,a8);
3868 kernel_.setArg(8,a9);
3869 kernel_.setArg(9,a10);
3870 kernel_.setArg(10,a11);
3871 kernel_.setArg(11,a12);
3872 kernel_.setArg(12,a13);
3873 kernel_.setArg(13,a14);
3875 err_ = queue_.enqueueNDRangeKernel(
3880 NULL, // bgaster_fixme - do we want to allow wait event lists?
3886 template<class A1, class A2, class A3, class A4, class A5,
3887 class A6, class A7, class A8, class A9, class A10,
3888 class A11, class A12, class A13, class A14, class A15>
3889 Event KernelFunctor::operator()(
3905 const VECTOR_CLASS<Event>* events)
3909 kernel_.setArg(0,a1);
3910 kernel_.setArg(1,a2);
3911 kernel_.setArg(2,a3);
3912 kernel_.setArg(3,a4);
3913 kernel_.setArg(4,a5);
3914 kernel_.setArg(5,a6);
3915 kernel_.setArg(6,a7);
3916 kernel_.setArg(7,a8);
3917 kernel_.setArg(8,a9);
3918 kernel_.setArg(9,a10);
3919 kernel_.setArg(10,a11);
3920 kernel_.setArg(11,a12);
3921 kernel_.setArg(12,a13);
3922 kernel_.setArg(13,a14);
3923 kernel_.setArg(14,a15);
3925 err_ = queue_.enqueueNDRangeKernel(
3930 NULL, // bgaster_fixme - do we want to allow wait event lists?
3937 #if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
3938 #undef __GET_DEVICE_INFO_ERR
3939 #undef __GET_PLATFORM_INFO_ERR
3940 #undef __GET_DEVICE_IDS_ERR
3941 #undef __GET_CONTEXT_INFO_ERR
3942 #undef __GET_EVENT_INFO_ERR
3943 #undef __GET_EVENT_PROFILE_INFO_ERR
3944 #undef __GET_MEM_OBJECT_INFO_ERR
3945 #undef __GET_IMAGE_INFO_ERR
3946 #undef __GET_SAMPLER_INFO_ERR
3947 #undef __GET_KERNEL_INFO_ERR
3948 #undef __GET_KERNEL_WORK_GROUP_INFO_ERR
3949 #undef __GET_PROGRAM_INFO_ERR
3950 #undef __GET_PROGRAM_BUILD_INFO_ERR
3951 #undef __GET_COMMAND_QUEUE_INFO_ERR
3953 #undef __CREATE_CONTEXT_FROM_TYPE_ERR
3954 #undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
3956 #undef __CREATE_BUFFER_ERR
3957 #undef __CREATE_SUBBUFFER_ERR
3958 #undef __CREATE_IMAGE2D_ERR
3959 #undef __CREATE_IMAGE3D_ERR
3960 #undef __CREATE_SAMPLER_ERR
3961 #undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
3963 #undef __CREATE_USER_EVENT_ERR
3964 #undef __SET_USER_EVENT_STATUS_ERR
3965 #undef __SET_EVENT_CALLBACK_ERR
3967 #undef __WAIT_FOR_EVENTS_ERR
3969 #undef __CREATE_KERNEL_ERR
3970 #undef __SET_KERNEL_ARGS_ERR
3971 #undef __CREATE_PROGRAM_WITH_SOURCE_ERR
3972 #undef __CREATE_PROGRAM_WITH_BINARY_ERR
3973 #undef __BUILD_PROGRAM_ERR
3974 #undef __CREATE_KERNELS_IN_PROGRAM_ERR
3976 #undef __CREATE_COMMAND_QUEUE_ERR
3977 #undef __SET_COMMAND_QUEUE_PROPERTY_ERR
3978 #undef __ENQUEUE_READ_BUFFER_ERR
3979 #undef __ENQUEUE_WRITE_BUFFER_ERR
3980 #undef __ENQUEUE_READ_BUFFER_RECT_ERR
3981 #undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
3982 #undef __ENQEUE_COPY_BUFFER_ERR
3983 #undef __ENQEUE_COPY_BUFFER_RECT_ERR
3984 #undef __ENQUEUE_READ_IMAGE_ERR
3985 #undef __ENQUEUE_WRITE_IMAGE_ERR
3986 #undef __ENQUEUE_COPY_IMAGE_ERR
3987 #undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
3988 #undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
3989 #undef __ENQUEUE_MAP_BUFFER_ERR
3990 #undef __ENQUEUE_MAP_IMAGE_ERR
3991 #undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
3992 #undef __ENQUEUE_NDRANGE_KERNEL_ERR
3993 #undef __ENQUEUE_TASK_ERR
3994 #undef __ENQUEUE_NATIVE_KERNEL
3996 #undef __UNLOAD_COMPILER_ERR
3997 #endif //__CL_USER_OVERRIDE_ERROR_STRINGS
3999 #undef __GET_INFO_HELPER_WITH_RETAIN
4002 #undef __INIT_CL_EXT_FCN_PTR
4003 #undef __CREATE_SUB_DEVICES
4005 #if defined(USE_CL_DEVICE_FISSION)
4006 #undef __PARAM_NAME_DEVICE_FISSION
4007 #endif // USE_CL_DEVICE_FISSION