1 /*******************************************************************************
2 * Copyright (c) 2008-2013 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), OpenCL 1.1 (rev 33) and
28 * \author Benedict R. Gaster, Laurent Morichetti and Lee Howes
30 * Additions and fixes from:
31 * Brian Cole, March 3rd 2010 and April 2012
32 * Matt Gruenke, April 2012.
33 * Bruce Merry, February 2013.
34 * Tom Deakin and Simon McIntosh-Smith, July 2013
39 * Optional extension support
42 * cl_ext_device_fission
43 * #define USE_CL_DEVICE_FISSION
47 * \section intro Introduction
48 * For many large applications C++ is the language of choice and so it seems
49 * reasonable to define C++ bindings for OpenCL.
52 * The interface is contained with a single C++ header file \em cl.hpp and all
53 * definitions are contained within the namespace \em cl. There is no additional
54 * requirement to include \em cl.h and to use either the C++ or original C
55 * bindings it is enough to simply include \em cl.hpp.
57 * The bindings themselves are lightweight and correspond closely to the
58 * underlying C API. Using the C++ bindings introduces no additional execution
61 * For detail documentation on the bindings see:
63 * The OpenCL C++ Wrapper API 1.2 (revision 09)
64 * http://www.khronos.org/registry/cl/specs/opencl-cplusplus-1.2.pdf
66 * \section example Example
68 * The following example shows a general use case for the C++
69 * bindings, including support for the optional exception feature and
70 * also the supplied vector and string classes, see following sections for
71 * decriptions of these features.
74 * #define __CL_ENABLE_EXCEPTIONS
76 * #if defined(__APPLE__) || defined(__MACOSX)
77 * #include <OpenCL/cl.hpp>
79 * #include <CL/cl.hpp>
85 * const char * helloStr = "__kernel void "
94 * cl_int err = CL_SUCCESS;
97 * std::vector<cl::Platform> platforms;
98 * cl::Platform::get(&platforms);
99 * if (platforms.size() == 0) {
100 * std::cout << "Platform size 0\n";
104 * cl_context_properties properties[] =
105 * { CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0};
106 * cl::Context context(CL_DEVICE_TYPE_CPU, properties);
108 * std::vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>();
110 * cl::Program::Sources source(1,
111 * std::make_pair(helloStr,strlen(helloStr)));
112 * cl::Program program_ = cl::Program(context, source);
113 * program_.build(devices);
115 * cl::Kernel kernel(program_, "hello", &err);
118 * cl::CommandQueue queue(context, devices[0], 0, &err);
119 * queue.enqueueNDRangeKernel(
129 * catch (cl::Error err) {
139 * return EXIT_SUCCESS;
155 #if defined(__CL_ENABLE_EXCEPTIONS)
157 #endif // #if defined(__CL_ENABLE_EXCEPTIONS)
159 #pragma push_macro("max")
161 #if defined(USE_DX_INTEROP)
162 #include <CL/cl_d3d10.h>
163 #include <CL/cl_dx9_media_sharing.h>
168 #if defined(USE_CL_DEVICE_FISSION)
169 #include <CL/cl_ext.h>
172 #if defined(__APPLE__) || defined(__MACOSX)
173 #include <OpenGL/OpenGL.h>
174 #include <OpenCL/opencl.h>
175 #include <libkern/OSAtomic.h>
178 #include <CL/opencl.h>
181 // To avoid accidentally taking ownership of core OpenCL types
182 // such as cl_kernel constructors are made explicit
184 #if defined(CL_VERSION_1_2) && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
185 #define __CL_EXPLICIT_CONSTRUCTORS explicit
186 #else // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
187 #define __CL_EXPLICIT_CONSTRUCTORS
188 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
190 // Define deprecated prefixes and suffixes to ensure compilation
191 // in case they are not pre-defined
192 #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
193 #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
194 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
195 #if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED)
196 #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
197 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
199 #if !defined(CL_CALLBACK)
206 #if !defined(__NO_STD_VECTOR)
210 #if !defined(__NO_STD_STRING)
214 #if defined(linux) || defined(__APPLE__) || defined(__MACOSX)
217 #include <emmintrin.h>
218 #include <xmmintrin.h>
226 * \brief The OpenCL C++ bindings are defined within this namespace.
234 * Deprecated APIs for 1.2
236 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
237 #define __INIT_CL_EXT_FCN_PTR(name) \
239 pfn_##name = (PFN_##name) \
240 clGetExtensionFunctionAddress(#name); \
244 #endif // #if defined(CL_VERSION_1_1)
246 #if defined(CL_VERSION_1_2)
247 #define __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, name) \
249 pfn_##name = (PFN_##name) \
250 clGetExtensionFunctionAddressForPlatform(platform, #name); \
254 #endif // #if defined(CL_VERSION_1_1)
263 #if defined(__CL_ENABLE_EXCEPTIONS)
264 /*! \brief Exception class
266 * This may be thrown by API functions when __CL_ENABLE_EXCEPTIONS is defined.
268 class Error : public std::exception
272 const char * errStr_;
274 /*! \brief Create a new CL error exception for a given error code
275 * and corresponding message.
277 * \param err error code value.
279 * \param errStr a descriptive string that must remain in scope until
280 * handling of the exception has concluded. If set, it
281 * will be returned by what().
283 Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr)
288 /*! \brief Get error string associated with exception
290 * \return A memory pointer to the error message string.
292 virtual const char * what() const throw ()
294 if (errStr_ == NULL) {
302 /*! \brief Get error code associated with exception
304 * \return The error code.
306 cl_int err(void) const { return err_; }
309 #define __ERR_STR(x) #x
311 #define __ERR_STR(x) NULL
312 #endif // __CL_ENABLE_EXCEPTIONS
317 #if defined(__CL_ENABLE_EXCEPTIONS)
318 static inline cl_int errHandler (
320 const char * errStr = NULL)
322 if (err != CL_SUCCESS) {
323 throw Error(err, errStr);
328 static inline cl_int errHandler (cl_int err, const char * errStr = NULL)
330 (void) errStr; // suppress unused variable warning
333 #endif // __CL_ENABLE_EXCEPTIONS
338 //! \cond DOXYGEN_DETAIL
339 #if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
340 #define __GET_DEVICE_INFO_ERR __ERR_STR(clGetDeviceInfo)
341 #define __GET_PLATFORM_INFO_ERR __ERR_STR(clGetPlatformInfo)
342 #define __GET_DEVICE_IDS_ERR __ERR_STR(clGetDeviceIDs)
343 #define __GET_PLATFORM_IDS_ERR __ERR_STR(clGetPlatformIDs)
344 #define __GET_CONTEXT_INFO_ERR __ERR_STR(clGetContextInfo)
345 #define __GET_EVENT_INFO_ERR __ERR_STR(clGetEventInfo)
346 #define __GET_EVENT_PROFILE_INFO_ERR __ERR_STR(clGetEventProfileInfo)
347 #define __GET_MEM_OBJECT_INFO_ERR __ERR_STR(clGetMemObjectInfo)
348 #define __GET_IMAGE_INFO_ERR __ERR_STR(clGetImageInfo)
349 #define __GET_SAMPLER_INFO_ERR __ERR_STR(clGetSamplerInfo)
350 #define __GET_KERNEL_INFO_ERR __ERR_STR(clGetKernelInfo)
351 #if defined(CL_VERSION_1_2)
352 #define __GET_KERNEL_ARG_INFO_ERR __ERR_STR(clGetKernelArgInfo)
353 #endif // #if defined(CL_VERSION_1_2)
354 #define __GET_KERNEL_WORK_GROUP_INFO_ERR __ERR_STR(clGetKernelWorkGroupInfo)
355 #define __GET_PROGRAM_INFO_ERR __ERR_STR(clGetProgramInfo)
356 #define __GET_PROGRAM_BUILD_INFO_ERR __ERR_STR(clGetProgramBuildInfo)
357 #define __GET_COMMAND_QUEUE_INFO_ERR __ERR_STR(clGetCommandQueueInfo)
359 #define __CREATE_CONTEXT_ERR __ERR_STR(clCreateContext)
360 #define __CREATE_CONTEXT_FROM_TYPE_ERR __ERR_STR(clCreateContextFromType)
361 #define __GET_SUPPORTED_IMAGE_FORMATS_ERR __ERR_STR(clGetSupportedImageFormats)
363 #define __CREATE_BUFFER_ERR __ERR_STR(clCreateBuffer)
364 #define __COPY_ERR __ERR_STR(cl::copy)
365 #define __CREATE_SUBBUFFER_ERR __ERR_STR(clCreateSubBuffer)
366 #define __CREATE_GL_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer)
367 #define __CREATE_GL_RENDER_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer)
368 #define __GET_GL_OBJECT_INFO_ERR __ERR_STR(clGetGLObjectInfo)
369 #if defined(CL_VERSION_1_2)
370 #define __CREATE_IMAGE_ERR __ERR_STR(clCreateImage)
371 #define __CREATE_GL_TEXTURE_ERR __ERR_STR(clCreateFromGLTexture)
372 #define __IMAGE_DIMENSION_ERR __ERR_STR(Incorrect image dimensions)
373 #endif // #if defined(CL_VERSION_1_2)
374 #define __CREATE_SAMPLER_ERR __ERR_STR(clCreateSampler)
375 #define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR __ERR_STR(clSetMemObjectDestructorCallback)
377 #define __CREATE_USER_EVENT_ERR __ERR_STR(clCreateUserEvent)
378 #define __SET_USER_EVENT_STATUS_ERR __ERR_STR(clSetUserEventStatus)
379 #define __SET_EVENT_CALLBACK_ERR __ERR_STR(clSetEventCallback)
380 #define __WAIT_FOR_EVENTS_ERR __ERR_STR(clWaitForEvents)
382 #define __CREATE_KERNEL_ERR __ERR_STR(clCreateKernel)
383 #define __SET_KERNEL_ARGS_ERR __ERR_STR(clSetKernelArg)
384 #define __CREATE_PROGRAM_WITH_SOURCE_ERR __ERR_STR(clCreateProgramWithSource)
385 #define __CREATE_PROGRAM_WITH_BINARY_ERR __ERR_STR(clCreateProgramWithBinary)
386 #if defined(CL_VERSION_1_2)
387 #define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR __ERR_STR(clCreateProgramWithBuiltInKernels)
388 #endif // #if defined(CL_VERSION_1_2)
389 #define __BUILD_PROGRAM_ERR __ERR_STR(clBuildProgram)
390 #if defined(CL_VERSION_1_2)
391 #define __COMPILE_PROGRAM_ERR __ERR_STR(clCompileProgram)
393 #endif // #if defined(CL_VERSION_1_2)
394 #define __CREATE_KERNELS_IN_PROGRAM_ERR __ERR_STR(clCreateKernelsInProgram)
396 #define __CREATE_COMMAND_QUEUE_ERR __ERR_STR(clCreateCommandQueue)
397 #define __SET_COMMAND_QUEUE_PROPERTY_ERR __ERR_STR(clSetCommandQueueProperty)
398 #define __ENQUEUE_READ_BUFFER_ERR __ERR_STR(clEnqueueReadBuffer)
399 #define __ENQUEUE_READ_BUFFER_RECT_ERR __ERR_STR(clEnqueueReadBufferRect)
400 #define __ENQUEUE_WRITE_BUFFER_ERR __ERR_STR(clEnqueueWriteBuffer)
401 #define __ENQUEUE_WRITE_BUFFER_RECT_ERR __ERR_STR(clEnqueueWriteBufferRect)
402 #define __ENQEUE_COPY_BUFFER_ERR __ERR_STR(clEnqueueCopyBuffer)
403 #define __ENQEUE_COPY_BUFFER_RECT_ERR __ERR_STR(clEnqueueCopyBufferRect)
404 #define __ENQUEUE_FILL_BUFFER_ERR __ERR_STR(clEnqueueFillBuffer)
405 #define __ENQUEUE_READ_IMAGE_ERR __ERR_STR(clEnqueueReadImage)
406 #define __ENQUEUE_WRITE_IMAGE_ERR __ERR_STR(clEnqueueWriteImage)
407 #define __ENQUEUE_COPY_IMAGE_ERR __ERR_STR(clEnqueueCopyImage)
408 #define __ENQUEUE_FILL_IMAGE_ERR __ERR_STR(clEnqueueFillImage)
409 #define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR __ERR_STR(clEnqueueCopyImageToBuffer)
410 #define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR __ERR_STR(clEnqueueCopyBufferToImage)
411 #define __ENQUEUE_MAP_BUFFER_ERR __ERR_STR(clEnqueueMapBuffer)
412 #define __ENQUEUE_MAP_IMAGE_ERR __ERR_STR(clEnqueueMapImage)
413 #define __ENQUEUE_UNMAP_MEM_OBJECT_ERR __ERR_STR(clEnqueueUnMapMemObject)
414 #define __ENQUEUE_NDRANGE_KERNEL_ERR __ERR_STR(clEnqueueNDRangeKernel)
415 #define __ENQUEUE_TASK_ERR __ERR_STR(clEnqueueTask)
416 #define __ENQUEUE_NATIVE_KERNEL __ERR_STR(clEnqueueNativeKernel)
417 #if defined(CL_VERSION_1_2)
418 #define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR __ERR_STR(clEnqueueMigrateMemObjects)
419 #endif // #if defined(CL_VERSION_1_2)
421 #define __ENQUEUE_ACQUIRE_GL_ERR __ERR_STR(clEnqueueAcquireGLObjects)
422 #define __ENQUEUE_RELEASE_GL_ERR __ERR_STR(clEnqueueReleaseGLObjects)
425 #define __RETAIN_ERR __ERR_STR(Retain Object)
426 #define __RELEASE_ERR __ERR_STR(Release Object)
427 #define __FLUSH_ERR __ERR_STR(clFlush)
428 #define __FINISH_ERR __ERR_STR(clFinish)
429 #define __VECTOR_CAPACITY_ERR __ERR_STR(Vector capacity error)
432 * CL 1.2 version that uses device fission.
434 #if defined(CL_VERSION_1_2)
435 #define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevices)
437 #define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevicesEXT)
438 #endif // #if defined(CL_VERSION_1_2)
441 * Deprecated APIs for 1.2
443 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
444 #define __ENQUEUE_MARKER_ERR __ERR_STR(clEnqueueMarker)
445 #define __ENQUEUE_WAIT_FOR_EVENTS_ERR __ERR_STR(clEnqueueWaitForEvents)
446 #define __ENQUEUE_BARRIER_ERR __ERR_STR(clEnqueueBarrier)
447 #define __UNLOAD_COMPILER_ERR __ERR_STR(clUnloadCompiler)
448 #define __CREATE_GL_TEXTURE_2D_ERR __ERR_STR(clCreateFromGLTexture2D)
449 #define __CREATE_GL_TEXTURE_3D_ERR __ERR_STR(clCreateFromGLTexture3D)
450 #define __CREATE_IMAGE2D_ERR __ERR_STR(clCreateImage2D)
451 #define __CREATE_IMAGE3D_ERR __ERR_STR(clCreateImage3D)
452 #endif // #if defined(CL_VERSION_1_1)
454 #endif // __CL_USER_OVERRIDE_ERROR_STRINGS
458 * CL 1.2 marker and barrier commands
460 #if defined(CL_VERSION_1_2)
461 #define __ENQUEUE_MARKER_WAIT_LIST_ERR __ERR_STR(clEnqueueMarkerWithWaitList)
462 #define __ENQUEUE_BARRIER_WAIT_LIST_ERR __ERR_STR(clEnqueueBarrierWithWaitList)
463 #endif // #if defined(CL_VERSION_1_2)
465 #if !defined(__USE_DEV_STRING) && !defined(__NO_STD_STRING)
466 typedef std::string STRING_CLASS;
467 #elif !defined(__USE_DEV_STRING)
470 * \brief Simple string class, that provides a limited subset of std::string
471 * functionality but avoids many of the issues that come with that class.
473 * \note Deprecated. Please use std::string as default or
474 * re-define the string class to match the std::string
475 * interface by defining STRING_CLASS
477 class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED string CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
483 //! \brief Constructs an empty string, allocating no memory.
484 string(void) : size_(0), str_(NULL)
488 /*! \brief Constructs a string populated from an arbitrary value of
491 * An extra '\0' is added, in case none was contained in str.
493 * \param str the initial value of the string instance. Note that '\0'
494 * characters receive no special treatment. If NULL,
495 * the string is left empty, with a size of 0.
497 * \param size the number of characters to copy from str.
499 string(const char * str, ::size_t size) :
504 str_ = new char[size_+1];
506 memcpy(str_, str, size_ * sizeof(char));
515 /*! \brief Constructs a string populated from a null-terminated value.
517 * \param str the null-terminated initial value of the string instance.
518 * If NULL, the string is left empty, with a size of 0.
520 string(const char * str) :
525 size_= ::strlen(str);
528 str_ = new char[size_ + 1];
530 memcpy(str_, str, (size_ + 1) * sizeof(char));
535 void resize( ::size_t n )
548 char *newString = new char[n + 1];
556 memcpy(newString, str_, (copySize + 1) * sizeof(char));
558 if( copySize < size_ ) {
559 memset(newString + copySize, 0, size_ - copySize);
561 newString[size_] = '\0';
568 const char& operator[] ( ::size_t pos ) const
573 char& operator[] ( ::size_t pos )
578 /*! \brief Copies the value of another string to this one.
580 * \param rhs the string to copy.
582 * \returns a reference to the modified instance.
584 string& operator=(const string& rhs)
596 if (rhs.size_ == 0 || rhs.str_ == NULL) {
601 str_ = new char[rhs.size_ + 1];
605 memcpy(str_, rhs.str_, (size_ + 1) * sizeof(char));
615 /*! \brief Constructs a string by copying the value of another instance.
617 * \param rhs the string to copy.
619 string(const string& rhs) :
626 //! \brief Destructor - frees memory used to hold the current value.
633 //! \brief Queries the length of the string, excluding any added '\0's.
634 ::size_t size(void) const { return size_; }
636 //! \brief Queries the length of the string, excluding any added '\0's.
637 ::size_t length(void) const { return size(); }
639 /*! \brief Returns a pointer to the private copy held by this instance,
640 * or "" if empty/unset.
642 const char * c_str(void) const { return (str_) ? str_ : "";}
644 typedef cl::string STRING_CLASS;
645 #endif // #elif !defined(__USE_DEV_STRING)
647 #if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR)
648 #define VECTOR_CLASS std::vector
649 #elif !defined(__USE_DEV_VECTOR)
650 #define VECTOR_CLASS cl::vector
652 #if !defined(__MAX_DEFAULT_VECTOR_SIZE)
653 #define __MAX_DEFAULT_VECTOR_SIZE 10
657 * \brief Fixed sized vector implementation that mirroring
659 * \note Deprecated. Please use std::vector as default or
660 * re-define the vector class to match the std::vector
661 * interface by defining VECTOR_CLASS
663 * \note Not recommended for use with custom objects as
664 * current implementation will construct N elements
666 * std::vector functionality.
667 * \brief Fixed sized vector compatible with std::vector.
670 * This differs from std::vector<> not just in memory allocation,
671 * but also in terms of when members are constructed, destroyed,
672 * and assigned instead of being copy constructed.
674 * \param T type of element contained in the vector.
676 * \param N maximum size of the vector.
678 template <typename T, unsigned int N = __MAX_DEFAULT_VECTOR_SIZE>
679 class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED vector CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
686 //! \brief Constructs an empty vector with no memory allocated.
688 size_(static_cast<unsigned int>(0))
691 //! \brief Deallocates the vector's memory and destroys all of its elements.
697 //! \brief Returns the number of elements currently contained.
698 unsigned int size(void) const
703 /*! \brief Empties the vector of all elements.
705 * This does not deallocate memory but will invoke destructors
706 * on contained elements.
715 /*! \brief Appends an element after the last valid element.
716 * Calling this on a vector that has reached capacity will throw an
717 * exception if exceptions are enabled.
719 void push_back (const T& x)
722 new (&data_[size_]) T(x);
725 detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR);
729 /*! \brief Removes the last valid element from the vector.
730 * Calling this on an empty vector will throw an exception
731 * if exceptions are enabled.
739 detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR);
743 /*! \brief Constructs with a value copied from another.
745 * \param vec the vector to copy.
747 vector(const vector<T, N>& vec) :
751 assign(vec.begin(), vec.end());
755 /*! \brief Constructs with a specified number of initial elements.
757 * \param size number of initial elements.
759 * \param val value of initial elements.
761 vector(unsigned int size, const T& val = T()) :
764 for (unsigned int i = 0; i < size; i++) {
769 /*! \brief Overwrites the current content with that copied from another
772 * \param rhs vector to copy.
774 * \returns a reference to this.
776 vector<T, N>& operator=(const vector<T, N>& rhs)
782 if (rhs.size_ != 0) {
783 assign(rhs.begin(), rhs.end());
791 /*! \brief Tests equality against another instance.
793 * \param vec the vector against which to compare.
795 bool operator==(vector<T,N> &vec)
797 if (size() != vec.size()) {
801 for( unsigned int i = 0; i < size(); ++i ) {
802 if( operator[](i) != vec[i] ) {
809 //! \brief Conversion operator to T*.
810 operator T* () { return data_; }
812 //! \brief Conversion operator to const T*.
813 operator const T* () const { return data_; }
815 //! \brief Tests whether this instance has any elements.
816 bool empty (void) const
821 //! \brief Returns the maximum number of elements this instance can hold.
822 unsigned int max_size (void) const
827 //! \brief Returns the maximum number of elements this instance can hold.
828 unsigned int capacity () const
833 /*! \brief Returns a reference to a given element.
835 * \param index which element to access. *
837 * The caller is responsible for ensuring index is >= 0 and < size().
839 T& operator[](int index)
844 /*! \brief Returns a const reference to a given element.
846 * \param index which element to access.
849 * The caller is responsible for ensuring index is >= 0 and < size().
851 const T& operator[](int index) const
856 /*! \brief Assigns elements of the vector based on a source iterator range.
858 * \param start Beginning iterator of source range
859 * \param end Enditerator of source range
862 * Will throw an exception if exceptions are enabled and size exceeded.
865 void assign(I start, I end)
868 while(start != end) {
875 * \brief Const iterator class for vectors
880 const vector<T,N> *vec_;
884 * Internal iterator constructor to capture reference
885 * to the vector it iterates over rather than taking
886 * the vector by copy.
888 iterator (const vector<T,N> &vec, int index) :
905 iterator(const iterator& rhs) :
913 static iterator begin(const cl::vector<T,N> &vec)
920 static iterator end(const cl::vector<T,N> &vec)
922 iterator i(vec, vec.size());
927 bool operator==(iterator i)
929 return ((vec_ == i.vec_) &&
930 (index_ == i.index_));
933 bool operator!=(iterator i)
935 return (!(*this==i));
938 iterator& operator++()
944 iterator operator++(int)
946 iterator retVal(*this);
951 iterator& operator--()
957 iterator operator--(int)
959 iterator retVal(*this);
964 const T& operator *() const
966 return (*vec_)[index_];
972 return iterator::begin(*this);
975 iterator begin(void) const
977 return iterator::begin(*this);
982 return iterator::end(*this);
985 iterator end(void) const
987 return iterator::end(*this);
1000 const T& front(void) const
1005 const T& back(void) const
1007 return data_[size_-1];
1010 #endif // #if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR)
1017 #define __DEFAULT_NOT_INITIALIZED 1
1018 #define __DEFAULT_BEING_INITIALIZED 2
1019 #define __DEFAULT_INITIALIZED 4
1022 * Compare and exchange primitives are needed for handling of defaults
1024 inline int compare_exchange(volatile int * dest, int exchange, int comparand)
1027 return (int)(InterlockedCompareExchange(
1028 (volatile long*)dest,
1031 #elif defined(__APPLE__) || defined(__MACOSX)
1032 return OSAtomicOr32Orig((uint32_t)exchange, (volatile uint32_t*)dest);
1033 #else // !_WIN32 || defined(__APPLE__) || defined(__MACOSX)
1034 return (__sync_val_compare_and_swap(
1041 inline void fence() { _mm_mfence(); }
1042 }; // namespace detail
1045 /*! \brief class used to interface between C++ and
1046 * OpenCL C calls that require arrays of size_t values, whose
1047 * size is known statically.
1056 //! \brief Initialize size_t to all 0s
1059 for( int i = 0; i < N; ++i ) {
1064 ::size_t& operator[](int index)
1066 return data_[index];
1069 const ::size_t& operator[](int index) const
1071 return data_[index];
1074 //! \brief Conversion operator to T*.
1075 operator ::size_t* () { return data_; }
1077 //! \brief Conversion operator to const T*.
1078 operator const ::size_t* () const { return data_; }
1083 // Generic getInfoHelper. The final parameter is used to guide overload
1084 // resolution: the actual parameter passed is an int, which makes this
1085 // a worse conversion sequence than a specialization that declares the
1086 // parameter as an int.
1087 template<typename Functor, typename T>
1088 inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long)
1090 return f(name, sizeof(T), param, NULL);
1093 // Specialized getInfoHelper for VECTOR_CLASS params
1094 template <typename Func, typename T>
1095 inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS<T>* param, long)
1098 cl_int err = f(name, 0, NULL, &required);
1099 if (err != CL_SUCCESS) {
1103 T* value = (T*) alloca(required);
1104 err = f(name, required, value, NULL);
1105 if (err != CL_SUCCESS) {
1109 param->assign(&value[0], &value[required/sizeof(T)]);
1113 /* Specialization for reference-counted types. This depends on the
1114 * existence of Wrapper<T>::cl_type, and none of the other types having the
1115 * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1116 * does not work, because when using a derived type (e.g. Context) the generic
1117 * template will provide a better match.
1119 template <typename Func, typename T>
1120 inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS<T>* param, int, typename T::cl_type = 0)
1123 cl_int err = f(name, 0, NULL, &required);
1124 if (err != CL_SUCCESS) {
1128 typename T::cl_type * value = (typename T::cl_type *) alloca(required);
1129 err = f(name, required, value, NULL);
1130 if (err != CL_SUCCESS) {
1134 ::size_t elements = required / sizeof(typename T::cl_type);
1135 param->assign(&value[0], &value[elements]);
1136 for (::size_t i = 0; i < elements; i++)
1138 if (value[i] != NULL)
1140 err = (*param)[i].retain();
1141 if (err != CL_SUCCESS) {
1149 // Specialized for getInfo<CL_PROGRAM_BINARIES>
1150 template <typename Func>
1151 inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS<char *>* param, int)
1153 cl_int err = f(name, param->size() * sizeof(char *), &(*param)[0], NULL);
1155 if (err != CL_SUCCESS) {
1162 // Specialized GetInfoHelper for STRING_CLASS params
1163 template <typename Func>
1164 inline cl_int getInfoHelper(Func f, cl_uint name, STRING_CLASS* param, long)
1167 cl_int err = f(name, 0, NULL, &required);
1168 if (err != CL_SUCCESS) {
1172 char* value = (char*) alloca(required);
1173 err = f(name, required, value, NULL);
1174 if (err != CL_SUCCESS) {
1182 // Specialized GetInfoHelper for cl::size_t params
1183 template <typename Func, ::size_t N>
1184 inline cl_int getInfoHelper(Func f, cl_uint name, size_t<N>* param, long)
1187 cl_int err = f(name, 0, NULL, &required);
1188 if (err != CL_SUCCESS) {
1192 ::size_t* value = (::size_t*) alloca(required);
1193 err = f(name, required, value, NULL);
1194 if (err != CL_SUCCESS) {
1198 for(int i = 0; i < N; ++i) {
1199 (*param)[i] = value[i];
1205 template<typename T> struct ReferenceHandler;
1207 /* Specialization for reference-counted types. This depends on the
1208 * existence of Wrapper<T>::cl_type, and none of the other types having the
1209 * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1210 * does not work, because when using a derived type (e.g. Context) the generic
1211 * template will provide a better match.
1213 template<typename Func, typename T>
1214 inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0)
1216 typename T::cl_type value;
1217 cl_int err = f(name, sizeof(value), &value, NULL);
1218 if (err != CL_SUCCESS) {
1224 err = param->retain();
1225 if (err != CL_SUCCESS) {
1232 #define __PARAM_NAME_INFO_1_0(F) \
1233 F(cl_platform_info, CL_PLATFORM_PROFILE, STRING_CLASS) \
1234 F(cl_platform_info, CL_PLATFORM_VERSION, STRING_CLASS) \
1235 F(cl_platform_info, CL_PLATFORM_NAME, STRING_CLASS) \
1236 F(cl_platform_info, CL_PLATFORM_VENDOR, STRING_CLASS) \
1237 F(cl_platform_info, CL_PLATFORM_EXTENSIONS, STRING_CLASS) \
1239 F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
1240 F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
1241 F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
1242 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
1243 F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, ::size_t) \
1244 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, VECTOR_CLASS< ::size_t>) \
1245 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
1246 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
1247 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
1248 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
1249 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
1250 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
1251 F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
1252 F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \
1253 F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
1254 F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
1255 F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
1256 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, ::size_t) \
1257 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, ::size_t) \
1258 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, ::size_t) \
1259 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, ::size_t) \
1260 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, ::size_t) \
1261 F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \
1262 F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, ::size_t) \
1263 F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
1264 F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
1265 F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
1266 F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
1267 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
1268 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
1269 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
1270 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
1271 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
1272 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
1273 F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
1274 F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
1275 F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
1276 F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, ::size_t) \
1277 F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
1278 F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
1279 F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
1280 F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
1281 F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties) \
1282 F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
1283 F(cl_device_info, CL_DEVICE_NAME, STRING_CLASS) \
1284 F(cl_device_info, CL_DEVICE_VENDOR, STRING_CLASS) \
1285 F(cl_device_info, CL_DRIVER_VERSION, STRING_CLASS) \
1286 F(cl_device_info, CL_DEVICE_PROFILE, STRING_CLASS) \
1287 F(cl_device_info, CL_DEVICE_VERSION, STRING_CLASS) \
1288 F(cl_device_info, CL_DEVICE_EXTENSIONS, STRING_CLASS) \
1290 F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
1291 F(cl_context_info, CL_CONTEXT_DEVICES, VECTOR_CLASS<Device>) \
1292 F(cl_context_info, CL_CONTEXT_PROPERTIES, VECTOR_CLASS<cl_context_properties>) \
1294 F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
1295 F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
1296 F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
1297 F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_uint) \
1299 F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
1300 F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
1301 F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
1302 F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
1304 F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
1305 F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
1306 F(cl_mem_info, CL_MEM_SIZE, ::size_t) \
1307 F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
1308 F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
1309 F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
1310 F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
1312 F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
1313 F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, ::size_t) \
1314 F(cl_image_info, CL_IMAGE_ROW_PITCH, ::size_t) \
1315 F(cl_image_info, CL_IMAGE_SLICE_PITCH, ::size_t) \
1316 F(cl_image_info, CL_IMAGE_WIDTH, ::size_t) \
1317 F(cl_image_info, CL_IMAGE_HEIGHT, ::size_t) \
1318 F(cl_image_info, CL_IMAGE_DEPTH, ::size_t) \
1320 F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
1321 F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
1322 F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_addressing_mode) \
1323 F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_filter_mode) \
1324 F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_bool) \
1326 F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
1327 F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
1328 F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
1329 F(cl_program_info, CL_PROGRAM_DEVICES, VECTOR_CLASS<Device>) \
1330 F(cl_program_info, CL_PROGRAM_SOURCE, STRING_CLASS) \
1331 F(cl_program_info, CL_PROGRAM_BINARY_SIZES, VECTOR_CLASS< ::size_t>) \
1332 F(cl_program_info, CL_PROGRAM_BINARIES, VECTOR_CLASS<char *>) \
1334 F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
1335 F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, STRING_CLASS) \
1336 F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, STRING_CLASS) \
1338 F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, STRING_CLASS) \
1339 F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
1340 F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
1341 F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
1342 F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
1344 F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, ::size_t) \
1345 F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::size_t<3>) \
1346 F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
1348 F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
1349 F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
1350 F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
1351 F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
1353 #if defined(CL_VERSION_1_1)
1354 #define __PARAM_NAME_INFO_1_1(F) \
1355 F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
1356 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
1357 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
1358 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
1359 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
1360 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
1361 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
1362 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
1363 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
1364 F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
1365 F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
1366 F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) \
1367 F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, STRING_CLASS) \
1369 F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
1370 F(cl_mem_info, CL_MEM_OFFSET, ::size_t) \
1372 F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, ::size_t) \
1373 F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
1375 F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
1376 #endif // CL_VERSION_1_1
1379 #if defined(CL_VERSION_1_2)
1380 #define __PARAM_NAME_INFO_1_2(F) \
1381 F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer) \
1383 F(cl_program_info, CL_PROGRAM_NUM_KERNELS, ::size_t) \
1384 F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, STRING_CLASS) \
1386 F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \
1388 F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, STRING_CLASS) \
1390 F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \
1391 F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \
1392 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, STRING_CLASS) \
1393 F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, STRING_CLASS) \
1395 F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl_device_id) \
1396 F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, VECTOR_CLASS<cl_device_partition_property>) \
1397 F(cl_device_info, CL_DEVICE_PARTITION_TYPE, VECTOR_CLASS<cl_device_partition_property>) \
1398 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \
1399 F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, ::size_t) \
1400 F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \
1401 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, STRING_CLASS)
1402 #endif // #if defined(CL_VERSION_1_2)
1404 #if defined(USE_CL_DEVICE_FISSION)
1405 #define __PARAM_NAME_DEVICE_FISSION(F) \
1406 F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
1407 F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \
1408 F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \
1409 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
1410 F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, VECTOR_CLASS<cl_device_partition_property_ext>)
1411 #endif // USE_CL_DEVICE_FISSION
1413 template <typename enum_type, cl_int Name>
1414 struct param_traits {};
1416 #define __CL_DECLARE_PARAM_TRAITS(token, param_name, T) \
1419 struct param_traits<detail:: token,param_name> \
1421 enum { value = param_name }; \
1422 typedef T param_type; \
1425 __PARAM_NAME_INFO_1_0(__CL_DECLARE_PARAM_TRAITS)
1426 #if defined(CL_VERSION_1_1)
1427 __PARAM_NAME_INFO_1_1(__CL_DECLARE_PARAM_TRAITS)
1428 #endif // CL_VERSION_1_1
1429 #if defined(CL_VERSION_1_2)
1430 __PARAM_NAME_INFO_1_2(__CL_DECLARE_PARAM_TRAITS)
1431 #endif // CL_VERSION_1_1
1433 #if defined(USE_CL_DEVICE_FISSION)
1434 __PARAM_NAME_DEVICE_FISSION(__CL_DECLARE_PARAM_TRAITS);
1435 #endif // USE_CL_DEVICE_FISSION
1437 #ifdef CL_PLATFORM_ICD_SUFFIX_KHR
1438 __CL_DECLARE_PARAM_TRAITS(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, STRING_CLASS)
1441 #ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
1442 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong)
1445 #ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
1446 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, VECTOR_CLASS< ::size_t>)
1448 #ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
1449 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint)
1451 #ifdef CL_DEVICE_SIMD_WIDTH_AMD
1452 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint)
1454 #ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD
1455 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint)
1457 #ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD
1458 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint)
1460 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
1461 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint)
1463 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
1464 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint)
1466 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
1467 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint)
1469 #ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
1470 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint)
1472 #ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
1473 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint)
1476 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
1477 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint)
1479 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV
1480 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint)
1482 #ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV
1483 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint)
1485 #ifdef CL_DEVICE_WARP_SIZE_NV
1486 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint)
1488 #ifdef CL_DEVICE_GPU_OVERLAP_NV
1489 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool)
1491 #ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV
1492 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool)
1494 #ifdef CL_DEVICE_INTEGRATED_MEMORY_NV
1495 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool)
1498 // Convenience functions
1500 template <typename Func, typename T>
1502 getInfo(Func f, cl_uint name, T* param)
1504 return getInfoHelper(f, name, param, 0);
1507 template <typename Func, typename Arg0>
1508 struct GetInfoFunctor0
1510 Func f_; const Arg0& arg0_;
1512 cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
1513 { return f_(arg0_, param, size, value, size_ret); }
1516 template <typename Func, typename Arg0, typename Arg1>
1517 struct GetInfoFunctor1
1519 Func f_; const Arg0& arg0_; const Arg1& arg1_;
1521 cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
1522 { return f_(arg0_, arg1_, param, size, value, size_ret); }
1525 template <typename Func, typename Arg0, typename T>
1527 getInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
1529 GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
1530 return getInfoHelper(f0, name, param, 0);
1533 template <typename Func, typename Arg0, typename Arg1, typename T>
1535 getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
1537 GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
1538 return getInfoHelper(f0, name, param, 0);
1541 template<typename T>
1542 struct ReferenceHandler
1545 #if defined(CL_VERSION_1_2)
1547 * OpenCL 1.2 devices do have retain/release.
1550 struct ReferenceHandler<cl_device_id>
1553 * Retain the device.
1554 * \param device A valid device created using createSubDevices
1556 * CL_SUCCESS if the function executed successfully.
1557 * CL_INVALID_DEVICE if device was not a valid subdevice
1558 * CL_OUT_OF_RESOURCES
1559 * CL_OUT_OF_HOST_MEMORY
1561 static cl_int retain(cl_device_id device)
1562 { return ::clRetainDevice(device); }
1564 * Retain the device.
1565 * \param device A valid device created using createSubDevices
1567 * CL_SUCCESS if the function executed successfully.
1568 * CL_INVALID_DEVICE if device was not a valid subdevice
1569 * CL_OUT_OF_RESOURCES
1570 * CL_OUT_OF_HOST_MEMORY
1572 static cl_int release(cl_device_id device)
1573 { return ::clReleaseDevice(device); }
1575 #else // #if defined(CL_VERSION_1_2)
1577 * OpenCL 1.1 devices do not have retain/release.
1580 struct ReferenceHandler<cl_device_id>
1582 // cl_device_id does not have retain().
1583 static cl_int retain(cl_device_id)
1584 { return CL_SUCCESS; }
1585 // cl_device_id does not have release().
1586 static cl_int release(cl_device_id)
1587 { return CL_SUCCESS; }
1589 #endif // #if defined(CL_VERSION_1_2)
1592 struct ReferenceHandler<cl_platform_id>
1594 // cl_platform_id does not have retain().
1595 static cl_int retain(cl_platform_id)
1596 { return CL_SUCCESS; }
1597 // cl_platform_id does not have release().
1598 static cl_int release(cl_platform_id)
1599 { return CL_SUCCESS; }
1603 struct ReferenceHandler<cl_context>
1605 static cl_int retain(cl_context context)
1606 { return ::clRetainContext(context); }
1607 static cl_int release(cl_context context)
1608 { return ::clReleaseContext(context); }
1612 struct ReferenceHandler<cl_command_queue>
1614 static cl_int retain(cl_command_queue queue)
1615 { return ::clRetainCommandQueue(queue); }
1616 static cl_int release(cl_command_queue queue)
1617 { return ::clReleaseCommandQueue(queue); }
1621 struct ReferenceHandler<cl_mem>
1623 static cl_int retain(cl_mem memory)
1624 { return ::clRetainMemObject(memory); }
1625 static cl_int release(cl_mem memory)
1626 { return ::clReleaseMemObject(memory); }
1630 struct ReferenceHandler<cl_sampler>
1632 static cl_int retain(cl_sampler sampler)
1633 { return ::clRetainSampler(sampler); }
1634 static cl_int release(cl_sampler sampler)
1635 { return ::clReleaseSampler(sampler); }
1639 struct ReferenceHandler<cl_program>
1641 static cl_int retain(cl_program program)
1642 { return ::clRetainProgram(program); }
1643 static cl_int release(cl_program program)
1644 { return ::clReleaseProgram(program); }
1648 struct ReferenceHandler<cl_kernel>
1650 static cl_int retain(cl_kernel kernel)
1651 { return ::clRetainKernel(kernel); }
1652 static cl_int release(cl_kernel kernel)
1653 { return ::clReleaseKernel(kernel); }
1657 struct ReferenceHandler<cl_event>
1659 static cl_int retain(cl_event event)
1660 { return ::clRetainEvent(event); }
1661 static cl_int release(cl_event event)
1662 { return ::clReleaseEvent(event); }
1666 // Extracts version number with major in the upper 16 bits, minor in the lower 16
1667 static cl_uint getVersion(const char *versionInfo)
1669 int highVersion = 0;
1672 while(versionInfo[index] != '.' ) {
1674 highVersion += versionInfo[index]-'0';
1678 while(versionInfo[index] != ' ' ) {
1680 lowVersion += versionInfo[index]-'0';
1683 return (highVersion << 16) | lowVersion;
1686 static cl_uint getPlatformVersion(cl_platform_id platform)
1689 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size);
1690 char *versionInfo = (char *) alloca(size);
1691 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, &versionInfo[0], &size);
1692 return getVersion(versionInfo);
1695 static cl_uint getDevicePlatformVersion(cl_device_id device)
1697 cl_platform_id platform;
1698 clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL);
1699 return getPlatformVersion(platform);
1702 #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
1703 static cl_uint getContextPlatformVersion(cl_context context)
1705 // The platform cannot be queried directly, so we first have to grab a
1706 // device and obtain its context
1708 clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size);
1711 cl_device_id *devices = (cl_device_id *) alloca(size);
1712 clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices, NULL);
1713 return getDevicePlatformVersion(devices[0]);
1715 #endif // #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
1717 template <typename T>
1727 Wrapper() : object_(NULL) { }
1729 Wrapper(const cl_type &obj) : object_(obj) { }
1733 if (object_ != NULL) { release(); }
1736 Wrapper(const Wrapper<cl_type>& rhs)
1738 object_ = rhs.object_;
1739 if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); }
1742 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
1744 if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
1745 object_ = rhs.object_;
1746 if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); }
1750 Wrapper<cl_type>& operator = (const cl_type &rhs)
1752 if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
1757 cl_type operator ()() const { return object_; }
1759 cl_type& operator ()() { return object_; }
1762 template<typename Func, typename U>
1763 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
1765 cl_int retain() const
1767 return ReferenceHandler<cl_type>::retain(object_);
1770 cl_int release() const
1772 return ReferenceHandler<cl_type>::release(object_);
1777 class Wrapper<cl_device_id>
1780 typedef cl_device_id cl_type;
1784 bool referenceCountable_;
1786 static bool isReferenceCountable(cl_device_id device)
1788 bool retVal = false;
1789 if (device != NULL) {
1790 int version = getDevicePlatformVersion(device);
1791 if(version > ((1 << 16) + 1)) {
1799 Wrapper() : object_(NULL), referenceCountable_(false)
1803 Wrapper(const cl_type &obj) : object_(obj), referenceCountable_(false)
1805 referenceCountable_ = isReferenceCountable(obj);
1810 if (object_ != NULL) { release(); }
1813 Wrapper(const Wrapper<cl_type>& rhs)
1815 object_ = rhs.object_;
1816 referenceCountable_ = isReferenceCountable(object_);
1817 if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); }
1820 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
1822 if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
1823 object_ = rhs.object_;
1824 referenceCountable_ = rhs.referenceCountable_;
1825 if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); }
1829 Wrapper<cl_type>& operator = (const cl_type &rhs)
1831 if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
1833 referenceCountable_ = isReferenceCountable(object_);
1837 cl_type operator ()() const { return object_; }
1839 cl_type& operator ()() { return object_; }
1842 template<typename Func, typename U>
1843 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
1845 template<typename Func, typename U>
1846 friend inline cl_int getInfoHelper(Func, cl_uint, VECTOR_CLASS<U>*, int, typename U::cl_type);
1848 cl_int retain() const
1850 if( referenceCountable_ ) {
1851 return ReferenceHandler<cl_type>::retain(object_);
1858 cl_int release() const
1860 if( referenceCountable_ ) {
1861 return ReferenceHandler<cl_type>::release(object_);
1869 } // namespace detail
1872 /*! \stuct ImageFormat
1873 * \brief Adds constructors and member functions for cl_image_format.
1875 * \see cl_image_format
1877 struct ImageFormat : public cl_image_format
1879 //! \brief Default constructor - performs no initialization.
1882 //! \brief Initializing constructor.
1883 ImageFormat(cl_channel_order order, cl_channel_type type)
1885 image_channel_order = order;
1886 image_channel_data_type = type;
1889 //! \brief Assignment operator.
1890 ImageFormat& operator = (const ImageFormat& rhs)
1893 this->image_channel_data_type = rhs.image_channel_data_type;
1894 this->image_channel_order = rhs.image_channel_order;
1900 /*! \brief Class interface for cl_device_id.
1902 * \note Copies of these objects are inexpensive, since they don't 'own'
1903 * any underlying resources or data structures.
1907 class Device : public detail::Wrapper<cl_device_id>
1910 //! \brief Default constructor - initializes to NULL.
1911 Device() : detail::Wrapper<cl_type>() { }
1913 /*! \brief Copy constructor.
1915 * This simply copies the device ID value, which is an inexpensive operation.
1917 Device(const Device& device) : detail::Wrapper<cl_type>(device) { }
1919 /*! \brief Constructor from cl_device_id.
1921 * This simply copies the device ID value, which is an inexpensive operation.
1923 Device(const cl_device_id &device) : detail::Wrapper<cl_type>(device) { }
1925 /*! \brief Returns the first device on the default context.
1927 * \see Context::getDefault()
1929 static Device getDefault(cl_int * err = NULL);
1931 /*! \brief Assignment operator from Device.
1933 * This simply copies the device ID value, which is an inexpensive operation.
1935 Device& operator = (const Device& rhs)
1938 detail::Wrapper<cl_type>::operator=(rhs);
1943 /*! \brief Assignment operator from cl_device_id.
1945 * This simply copies the device ID value, which is an inexpensive operation.
1947 Device& operator = (const cl_device_id& rhs)
1949 detail::Wrapper<cl_type>::operator=(rhs);
1953 //! \brief Wrapper for clGetDeviceInfo().
1954 template <typename T>
1955 cl_int getInfo(cl_device_info name, T* param) const
1957 return detail::errHandler(
1958 detail::getInfo(&::clGetDeviceInfo, object_, name, param),
1959 __GET_DEVICE_INFO_ERR);
1962 //! \brief Wrapper for clGetDeviceInfo() that returns by value.
1963 template <cl_int name> typename
1964 detail::param_traits<detail::cl_device_info, name>::param_type
1965 getInfo(cl_int* err = NULL) const
1967 typename detail::param_traits<
1968 detail::cl_device_info, name>::param_type param;
1969 cl_int result = getInfo(name, ¶m);
1979 #if defined(CL_VERSION_1_2)
1980 //! \brief Wrapper for clCreateSubDevicesEXT().
1981 cl_int createSubDevices(
1982 const cl_device_partition_property * properties,
1983 VECTOR_CLASS<Device>* devices)
1986 cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n);
1987 if (err != CL_SUCCESS) {
1988 return detail::errHandler(err, __CREATE_SUB_DEVICES);
1991 cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
1992 err = clCreateSubDevices(object_, properties, n, ids, NULL);
1993 if (err != CL_SUCCESS) {
1994 return detail::errHandler(err, __CREATE_SUB_DEVICES);
1997 devices->assign(&ids[0], &ids[n]);
2000 #endif // #if defined(CL_VERSION_1_2)
2003 * CL 1.1 version that uses device fission.
2005 #if defined(CL_VERSION_1_1)
2006 #if defined(USE_CL_DEVICE_FISSION)
2007 cl_int createSubDevices(
2008 const cl_device_partition_property_ext * properties,
2009 VECTOR_CLASS<Device>* devices)
2011 typedef CL_API_ENTRY cl_int
2012 ( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
2013 cl_device_id /*in_device*/,
2014 const cl_device_partition_property_ext * /* properties */,
2015 cl_uint /*num_entries*/,
2016 cl_device_id * /*out_devices*/,
2017 cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1;
2019 static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
2020 __INIT_CL_EXT_FCN_PTR(clCreateSubDevicesEXT);
2023 cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
2024 if (err != CL_SUCCESS) {
2025 return detail::errHandler(err, __CREATE_SUB_DEVICES);
2028 cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
2029 err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids, NULL);
2030 if (err != CL_SUCCESS) {
2031 return detail::errHandler(err, __CREATE_SUB_DEVICES);
2034 devices->assign(&ids[0], &ids[n]);
2037 #endif // #if defined(USE_CL_DEVICE_FISSION)
2038 #endif // #if defined(CL_VERSION_1_1)
2041 /*! \brief Class interface for cl_platform_id.
2043 * \note Copies of these objects are inexpensive, since they don't 'own'
2044 * any underlying resources or data structures.
2046 * \see cl_platform_id
2048 class Platform : public detail::Wrapper<cl_platform_id>
2051 //! \brief Default constructor - initializes to NULL.
2052 Platform() : detail::Wrapper<cl_type>() { }
2054 /*! \brief Copy constructor.
2056 * This simply copies the platform ID value, which is an inexpensive operation.
2058 Platform(const Platform& platform) : detail::Wrapper<cl_type>(platform) { }
2060 /*! \brief Constructor from cl_platform_id.
2062 * This simply copies the platform ID value, which is an inexpensive operation.
2064 Platform(const cl_platform_id &platform) : detail::Wrapper<cl_type>(platform) { }
2066 /*! \brief Assignment operator from Platform.
2068 * This simply copies the platform ID value, which is an inexpensive operation.
2070 Platform& operator = (const Platform& rhs)
2073 detail::Wrapper<cl_type>::operator=(rhs);
2078 /*! \brief Assignment operator from cl_platform_id.
2080 * This simply copies the platform ID value, which is an inexpensive operation.
2082 Platform& operator = (const cl_platform_id& rhs)
2084 detail::Wrapper<cl_type>::operator=(rhs);
2088 //! \brief Wrapper for clGetPlatformInfo().
2089 cl_int getInfo(cl_platform_info name, STRING_CLASS* param) const
2091 return detail::errHandler(
2092 detail::getInfo(&::clGetPlatformInfo, object_, name, param),
2093 __GET_PLATFORM_INFO_ERR);
2096 //! \brief Wrapper for clGetPlatformInfo() that returns by value.
2097 template <cl_int name> typename
2098 detail::param_traits<detail::cl_platform_info, name>::param_type
2099 getInfo(cl_int* err = NULL) const
2101 typename detail::param_traits<
2102 detail::cl_platform_info, name>::param_type param;
2103 cl_int result = getInfo(name, ¶m);
2110 /*! \brief Gets a list of devices for this platform.
2112 * Wraps clGetDeviceIDs().
2115 cl_device_type type,
2116 VECTOR_CLASS<Device>* devices) const
2119 if( devices == NULL ) {
2120 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2122 cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
2123 if (err != CL_SUCCESS) {
2124 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2127 cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
2128 err = ::clGetDeviceIDs(object_, type, n, ids, NULL);
2129 if (err != CL_SUCCESS) {
2130 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2133 devices->assign(&ids[0], &ids[n]);
2137 #if defined(USE_DX_INTEROP)
2138 /*! \brief Get the list of available D3D10 devices.
2140 * \param d3d_device_source.
2142 * \param d3d_object.
2144 * \param d3d_device_set.
2146 * \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device
2147 * values returned in devices can be used to identify a specific OpenCL
2148 * device. If \a devices argument is NULL, this argument is ignored.
2150 * \return One of the following values:
2151 * - CL_SUCCESS if the function is executed successfully.
2153 * The application can query specific capabilities of the OpenCL device(s)
2154 * returned by cl::getDevices. This can be used by the application to
2155 * determine which device(s) to use.
2157 * \note In the case that exceptions are enabled and a return value
2158 * other than CL_SUCCESS is generated, then cl::Error exception is
2162 cl_d3d10_device_source_khr d3d_device_source,
2164 cl_d3d10_device_set_khr d3d_device_set,
2165 VECTOR_CLASS<Device>* devices) const
2167 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
2168 cl_platform_id platform,
2169 cl_d3d10_device_source_khr d3d_device_source,
2171 cl_d3d10_device_set_khr d3d_device_set,
2172 cl_uint num_entries,
2173 cl_device_id * devices,
2174 cl_uint* num_devices);
2176 if( devices == NULL ) {
2177 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2180 static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
2181 __INIT_CL_EXT_FCN_PTR_PLATFORM(object_, clGetDeviceIDsFromD3D10KHR);
2184 cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
2192 if (err != CL_SUCCESS) {
2193 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2196 cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
2197 err = pfn_clGetDeviceIDsFromD3D10KHR(
2205 if (err != CL_SUCCESS) {
2206 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2209 devices->assign(&ids[0], &ids[n]);
2214 /*! \brief Gets a list of available platforms.
2216 * Wraps clGetPlatformIDs().
2219 VECTOR_CLASS<Platform>* platforms)
2223 if( platforms == NULL ) {
2224 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
2227 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2228 if (err != CL_SUCCESS) {
2229 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2232 cl_platform_id* ids = (cl_platform_id*) alloca(
2233 n * sizeof(cl_platform_id));
2234 err = ::clGetPlatformIDs(n, ids, NULL);
2235 if (err != CL_SUCCESS) {
2236 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2239 platforms->assign(&ids[0], &ids[n]);
2243 /*! \brief Gets the first available platform.
2245 * Wraps clGetPlatformIDs(), returning the first result.
2248 Platform * platform)
2252 if( platform == NULL ) {
2253 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
2256 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2257 if (err != CL_SUCCESS) {
2258 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2261 cl_platform_id* ids = (cl_platform_id*) alloca(
2262 n * sizeof(cl_platform_id));
2263 err = ::clGetPlatformIDs(n, ids, NULL);
2264 if (err != CL_SUCCESS) {
2265 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2272 /*! \brief Gets the first available platform, returning it by value.
2274 * Wraps clGetPlatformIDs(), returning the first result.
2276 static Platform get(
2277 cl_int * errResult = NULL)
2281 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2282 if (err != CL_SUCCESS) {
2283 detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2284 if (errResult != NULL) {
2289 cl_platform_id* ids = (cl_platform_id*) alloca(
2290 n * sizeof(cl_platform_id));
2291 err = ::clGetPlatformIDs(n, ids, NULL);
2293 if (err != CL_SUCCESS) {
2294 detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2297 if (errResult != NULL) {
2304 static Platform getDefault(
2305 cl_int *errResult = NULL )
2307 return get(errResult);
2311 #if defined(CL_VERSION_1_2)
2312 //! \brief Wrapper for clUnloadCompiler().
2316 return ::clUnloadPlatformCompiler(object_);
2318 #endif // #if defined(CL_VERSION_1_2)
2319 }; // class Platform
2322 * Deprecated APIs for 1.2
2324 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
2326 * Unload the OpenCL compiler.
2327 * \note Deprecated for OpenCL 1.2. Use Platform::unloadCompiler instead.
2329 inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int
2330 UnloadCompiler() CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
2334 return ::clUnloadCompiler();
2336 #endif // #if defined(CL_VERSION_1_1)
2338 /*! \brief Class interface for cl_context.
2340 * \note Copies of these objects are shallow, meaning that the copy will refer
2341 * to the same underlying cl_context as the original. For details, see
2342 * clRetainContext() and clReleaseContext().
2347 : public detail::Wrapper<cl_context>
2350 static volatile int default_initialized_;
2351 static Context default_;
2352 static volatile cl_int default_error_;
2354 /*! \brief Destructor.
2356 * This calls clReleaseContext() on the value held by this instance.
2360 /*! \brief Constructs a context including a list of specified devices.
2362 * Wraps clCreateContext().
2365 const VECTOR_CLASS<Device>& devices,
2366 cl_context_properties* properties = NULL,
2367 void (CL_CALLBACK * notifyFptr)(
2377 ::size_t numDevices = devices.size();
2378 cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id));
2379 for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
2380 deviceIDs[deviceIndex] = (devices[deviceIndex])();
2383 object_ = ::clCreateContext(
2384 properties, (cl_uint) numDevices,
2386 notifyFptr, data, &error);
2388 detail::errHandler(error, __CREATE_CONTEXT_ERR);
2395 const Device& device,
2396 cl_context_properties* properties = NULL,
2397 void (CL_CALLBACK * notifyFptr)(
2407 cl_device_id deviceID = device();
2409 object_ = ::clCreateContext(
2412 notifyFptr, data, &error);
2414 detail::errHandler(error, __CREATE_CONTEXT_ERR);
2420 /*! \brief Constructs a context including all or a subset of devices of a specified type.
2422 * Wraps clCreateContextFromType().
2425 cl_device_type type,
2426 cl_context_properties* properties = NULL,
2427 void (CL_CALLBACK * notifyFptr)(
2437 #if !defined(__APPLE__) || !defined(__MACOS)
2438 cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 };
2440 if (properties == NULL) {
2441 // Get a valid platform ID as we cannot send in a blank one
2442 VECTOR_CLASS<Platform> platforms;
2443 error = Platform::get(&platforms);
2444 if (error != CL_SUCCESS) {
2445 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2452 // Check the platforms we found for a device of our specified type
2453 cl_context_properties platform_id = 0;
2454 for (unsigned int i = 0; i < platforms.size(); i++) {
2456 VECTOR_CLASS<Device> devices;
2458 #if defined(__CL_ENABLE_EXCEPTIONS)
2462 error = platforms[i].getDevices(type, &devices);
2464 #if defined(__CL_ENABLE_EXCEPTIONS)
2466 // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type
2467 // We do error checking next anyway, and can throw there if needed
2470 // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND
2471 if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) {
2472 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2478 if (devices.size() > 0) {
2479 platform_id = (cl_context_properties)platforms[i]();
2484 if (platform_id == 0) {
2485 detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR);
2487 *err = CL_DEVICE_NOT_FOUND;
2492 prop[1] = platform_id;
2493 properties = &prop[0];
2496 object_ = ::clCreateContextFromType(
2497 properties, type, notifyFptr, data, &error);
2499 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2505 /*! \brief Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT.
2507 * \note All calls to this function return the same cl_context as the first.
2509 static Context getDefault(cl_int * err = NULL)
2511 int state = detail::compare_exchange(
2512 &default_initialized_,
2513 __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED);
2515 if (state & __DEFAULT_INITIALIZED) {
2517 *err = default_error_;
2522 if (state & __DEFAULT_BEING_INITIALIZED) {
2523 // Assume writes will propagate eventually...
2524 while(default_initialized_ != __DEFAULT_INITIALIZED) {
2529 *err = default_error_;
2536 CL_DEVICE_TYPE_DEFAULT,
2544 default_error_ = error;
2545 // Assume writes will propagate eventually...
2546 default_initialized_ = __DEFAULT_INITIALIZED;
2551 *err = default_error_;
2557 //! \brief Default constructor - initializes to NULL.
2558 Context() : detail::Wrapper<cl_type>() { }
2560 /*! \brief Copy constructor.
2562 * This calls clRetainContext() on the parameter's cl_context.
2564 Context(const Context& context) : detail::Wrapper<cl_type>(context) { }
2566 /*! \brief Constructor from cl_context - takes ownership.
2568 * This effectively transfers ownership of a refcount on the cl_context
2569 * into the new Context object.
2571 __CL_EXPLICIT_CONSTRUCTORS Context(const cl_context& context) : detail::Wrapper<cl_type>(context) { }
2573 /*! \brief Assignment operator from Context.
2575 * This calls clRetainContext() on the parameter and clReleaseContext() on
2576 * the previous value held by this instance.
2578 Context& operator = (const Context& rhs)
2581 detail::Wrapper<cl_type>::operator=(rhs);
2586 /*! \brief Assignment operator from cl_context - takes ownership.
2588 * This effectively transfers ownership of a refcount on the rhs and calls
2589 * clReleaseContext() on the value previously held by this instance.
2591 Context& operator = (const cl_context& rhs)
2593 detail::Wrapper<cl_type>::operator=(rhs);
2597 //! \brief Wrapper for clGetContextInfo().
2598 template <typename T>
2599 cl_int getInfo(cl_context_info name, T* param) const
2601 return detail::errHandler(
2602 detail::getInfo(&::clGetContextInfo, object_, name, param),
2603 __GET_CONTEXT_INFO_ERR);
2606 //! \brief Wrapper for clGetContextInfo() that returns by value.
2607 template <cl_int name> typename
2608 detail::param_traits<detail::cl_context_info, name>::param_type
2609 getInfo(cl_int* err = NULL) const
2611 typename detail::param_traits<
2612 detail::cl_context_info, name>::param_type param;
2613 cl_int result = getInfo(name, ¶m);
2620 /*! \brief Gets a list of supported image formats.
2622 * Wraps clGetSupportedImageFormats().
2624 cl_int getSupportedImageFormats(
2626 cl_mem_object_type type,
2627 VECTOR_CLASS<ImageFormat>* formats) const
2630 cl_int err = ::clGetSupportedImageFormats(
2637 if (err != CL_SUCCESS) {
2638 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
2641 ImageFormat* value = (ImageFormat*)
2642 alloca(numEntries * sizeof(ImageFormat));
2643 err = ::clGetSupportedImageFormats(
2648 (cl_image_format*) value,
2650 if (err != CL_SUCCESS) {
2651 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
2654 formats->assign(&value[0], &value[numEntries]);
2659 inline Device Device::getDefault(cl_int * err)
2664 Context context = Context::getDefault(&error);
2665 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
2667 if (error != CL_SUCCESS) {
2673 device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
2684 __declspec(selectany) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED;
2685 __declspec(selectany) Context Context::default_;
2686 __declspec(selectany) volatile cl_int Context::default_error_ = CL_SUCCESS;
2688 __attribute__((weak)) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED;
2689 __attribute__((weak)) Context Context::default_;
2690 __attribute__((weak)) volatile cl_int Context::default_error_ = CL_SUCCESS;
2693 /*! \brief Class interface for cl_event.
2695 * \note Copies of these objects are shallow, meaning that the copy will refer
2696 * to the same underlying cl_event as the original. For details, see
2697 * clRetainEvent() and clReleaseEvent().
2701 class Event : public detail::Wrapper<cl_event>
2704 /*! \brief Destructor.
2706 * This calls clReleaseEvent() on the value held by this instance.
2710 //! \brief Default constructor - initializes to NULL.
2711 Event() : detail::Wrapper<cl_type>() { }
2713 /*! \brief Copy constructor.
2715 * This calls clRetainEvent() on the parameter's cl_event.
2717 Event(const Event& event) : detail::Wrapper<cl_type>(event) { }
2719 /*! \brief Constructor from cl_event - takes ownership.
2721 * This effectively transfers ownership of a refcount on the cl_event
2722 * into the new Event object.
2724 Event(const cl_event& event) : detail::Wrapper<cl_type>(event) { }
2726 /*! \brief Assignment operator from cl_event - takes ownership.
2728 * This effectively transfers ownership of a refcount on the rhs and calls
2729 * clReleaseEvent() on the value previously held by this instance.
2731 Event& operator = (const Event& rhs)
2734 detail::Wrapper<cl_type>::operator=(rhs);
2739 /*! \brief Assignment operator from cl_event.
2741 * This calls clRetainEvent() on the parameter and clReleaseEvent() on
2742 * the previous value held by this instance.
2744 Event& operator = (const cl_event& rhs)
2746 detail::Wrapper<cl_type>::operator=(rhs);
2750 //! \brief Wrapper for clGetEventInfo().
2751 template <typename T>
2752 cl_int getInfo(cl_event_info name, T* param) const
2754 return detail::errHandler(
2755 detail::getInfo(&::clGetEventInfo, object_, name, param),
2756 __GET_EVENT_INFO_ERR);
2759 //! \brief Wrapper for clGetEventInfo() that returns by value.
2760 template <cl_int name> typename
2761 detail::param_traits<detail::cl_event_info, name>::param_type
2762 getInfo(cl_int* err = NULL) const
2764 typename detail::param_traits<
2765 detail::cl_event_info, name>::param_type param;
2766 cl_int result = getInfo(name, ¶m);
2773 //! \brief Wrapper for clGetEventProfilingInfo().
2774 template <typename T>
2775 cl_int getProfilingInfo(cl_profiling_info name, T* param) const
2777 return detail::errHandler(detail::getInfo(
2778 &::clGetEventProfilingInfo, object_, name, param),
2779 __GET_EVENT_PROFILE_INFO_ERR);
2782 //! \brief Wrapper for clGetEventProfilingInfo() that returns by value.
2783 template <cl_int name> typename
2784 detail::param_traits<detail::cl_profiling_info, name>::param_type
2785 getProfilingInfo(cl_int* err = NULL) const
2787 typename detail::param_traits<
2788 detail::cl_profiling_info, name>::param_type param;
2789 cl_int result = getProfilingInfo(name, ¶m);
2796 /*! \brief Blocks the calling thread until this event completes.
2798 * Wraps clWaitForEvents().
2802 return detail::errHandler(
2803 ::clWaitForEvents(1, &object_),
2804 __WAIT_FOR_EVENTS_ERR);
2807 #if defined(CL_VERSION_1_1)
2808 /*! \brief Registers a user callback function for a specific command execution status.
2810 * Wraps clSetEventCallback().
2814 void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
2815 void * user_data = NULL)
2817 return detail::errHandler(
2818 ::clSetEventCallback(
2823 __SET_EVENT_CALLBACK_ERR);
2827 /*! \brief Blocks the calling thread until every event specified is complete.
2829 * Wraps clWaitForEvents().
2832 waitForEvents(const VECTOR_CLASS<Event>& events)
2834 return detail::errHandler(
2836 (cl_uint) events.size(), (cl_event*)&events.front()),
2837 __WAIT_FOR_EVENTS_ERR);
2841 #if defined(CL_VERSION_1_1)
2842 /*! \brief Class interface for user events (a subset of cl_event's).
2844 * See Event for details about copy semantics, etc.
2846 class UserEvent : public Event
2849 /*! \brief Constructs a user event on a given context.
2851 * Wraps clCreateUserEvent().
2854 const Context& context,
2855 cl_int * err = NULL)
2858 object_ = ::clCreateUserEvent(
2862 detail::errHandler(error, __CREATE_USER_EVENT_ERR);
2868 //! \brief Default constructor - initializes to NULL.
2869 UserEvent() : Event() { }
2871 //! \brief Copy constructor - performs shallow copy.
2872 UserEvent(const UserEvent& event) : Event(event) { }
2874 //! \brief Assignment Operator - performs shallow copy.
2875 UserEvent& operator = (const UserEvent& rhs)
2878 Event::operator=(rhs);
2883 /*! \brief Sets the execution status of a user event object.
2885 * Wraps clSetUserEventStatus().
2887 cl_int setStatus(cl_int status)
2889 return detail::errHandler(
2890 ::clSetUserEventStatus(object_,status),
2891 __SET_USER_EVENT_STATUS_ERR);
2896 /*! \brief Blocks the calling thread until every event specified is complete.
2898 * Wraps clWaitForEvents().
2900 inline static cl_int
2901 WaitForEvents(const VECTOR_CLASS<Event>& events)
2903 return detail::errHandler(
2905 (cl_uint) events.size(), (cl_event*)&events.front()),
2906 __WAIT_FOR_EVENTS_ERR);
2909 /*! \brief Class interface for cl_mem.
2911 * \note Copies of these objects are shallow, meaning that the copy will refer
2912 * to the same underlying cl_mem as the original. For details, see
2913 * clRetainMemObject() and clReleaseMemObject().
2917 class Memory : public detail::Wrapper<cl_mem>
2921 /*! \brief Destructor.
2923 * This calls clReleaseMemObject() on the value held by this instance.
2927 //! \brief Default constructor - initializes to NULL.
2928 Memory() : detail::Wrapper<cl_type>() { }
2930 /*! \brief Copy constructor - performs shallow copy.
2932 * This calls clRetainMemObject() on the parameter's cl_mem.
2934 Memory(const Memory& memory) : detail::Wrapper<cl_type>(memory) { }
2936 /*! \brief Constructor from cl_mem - takes ownership.
2938 * This effectively transfers ownership of a refcount on the cl_mem
2939 * into the new Memory object.
2941 __CL_EXPLICIT_CONSTRUCTORS Memory(const cl_mem& memory) : detail::Wrapper<cl_type>(memory) { }
2943 /*! \brief Assignment operator from Memory.
2945 * This calls clRetainMemObject() on the parameter and clReleaseMemObject()
2946 * on the previous value held by this instance.
2948 Memory& operator = (const Memory& rhs)
2951 detail::Wrapper<cl_type>::operator=(rhs);
2956 /*! \brief Assignment operator from cl_mem - takes ownership.
2958 * This effectively transfers ownership of a refcount on the rhs and calls
2959 * clReleaseMemObject() on the value previously held by this instance.
2961 Memory& operator = (const cl_mem& rhs)
2963 detail::Wrapper<cl_type>::operator=(rhs);
2967 //! \brief Wrapper for clGetMemObjectInfo().
2968 template <typename T>
2969 cl_int getInfo(cl_mem_info name, T* param) const
2971 return detail::errHandler(
2972 detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
2973 __GET_MEM_OBJECT_INFO_ERR);
2976 //! \brief Wrapper for clGetMemObjectInfo() that returns by value.
2977 template <cl_int name> typename
2978 detail::param_traits<detail::cl_mem_info, name>::param_type
2979 getInfo(cl_int* err = NULL) const
2981 typename detail::param_traits<
2982 detail::cl_mem_info, name>::param_type param;
2983 cl_int result = getInfo(name, ¶m);
2990 #if defined(CL_VERSION_1_1)
2991 /*! \brief Registers a callback function to be called when the memory object
2992 * is no longer needed.
2994 * Wraps clSetMemObjectDestructorCallback().
2996 * Repeated calls to this function, for a given cl_mem value, will append
2997 * to the list of functions called (in reverse order) when memory object's
2998 * resources are freed and the memory object is deleted.
3001 * The registered callbacks are associated with the underlying cl_mem
3002 * value - not the Memory class instance.
3004 cl_int setDestructorCallback(
3005 void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
3006 void * user_data = NULL)
3008 return detail::errHandler(
3009 ::clSetMemObjectDestructorCallback(
3013 __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
3019 // Pre-declare copy functions
3021 template< typename IteratorType >
3022 cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3023 template< typename IteratorType >
3024 cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3025 template< typename IteratorType >
3026 cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3027 template< typename IteratorType >
3028 cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3031 /*! \brief Class interface for Buffer Memory Objects.
3033 * See Memory for details about copy semantics, etc.
3037 class Buffer : public Memory
3041 /*! \brief Constructs a Buffer in a specified context.
3043 * Wraps clCreateBuffer().
3045 * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
3046 * specified. Note alignment & exclusivity requirements.
3049 const Context& context,
3052 void* host_ptr = NULL,
3056 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3058 detail::errHandler(error, __CREATE_BUFFER_ERR);
3064 /*! \brief Constructs a Buffer in the default context.
3066 * Wraps clCreateBuffer().
3068 * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
3069 * specified. Note alignment & exclusivity requirements.
3071 * \see Context::getDefault()
3076 void* host_ptr = NULL,
3081 Context context = Context::getDefault(err);
3083 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3085 detail::errHandler(error, __CREATE_BUFFER_ERR);
3092 * \brief Construct a Buffer from a host container via iterators.
3093 * IteratorType must be random access.
3094 * If useHostPtr is specified iterators must represent contiguous data.
3096 template< typename IteratorType >
3098 IteratorType startIterator,
3099 IteratorType endIterator,
3101 bool useHostPtr = false,
3104 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
3107 cl_mem_flags flags = 0;
3109 flags |= CL_MEM_READ_ONLY;
3112 flags |= CL_MEM_READ_WRITE;
3115 flags |= CL_MEM_USE_HOST_PTR;
3118 ::size_t size = sizeof(DataType)*(endIterator - startIterator);
3120 Context context = Context::getDefault(err);
3123 object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
3125 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
3128 detail::errHandler(error, __CREATE_BUFFER_ERR);
3134 error = cl::copy(startIterator, endIterator, *this);
3135 detail::errHandler(error, __CREATE_BUFFER_ERR);
3143 * \brief Construct a Buffer from a host container via iterators using a specified context.
3144 * IteratorType must be random access.
3145 * If useHostPtr is specified iterators must represent contiguous data.
3147 template< typename IteratorType >
3148 Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator,
3149 bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
3151 //! \brief Default constructor - initializes to NULL.
3152 Buffer() : Memory() { }
3154 /*! \brief Copy constructor - performs shallow copy.
3156 * See Memory for further details.
3158 Buffer(const Buffer& buffer) : Memory(buffer) { }
3160 /*! \brief Constructor from cl_mem - takes ownership.
3162 * See Memory for further details.
3164 __CL_EXPLICIT_CONSTRUCTORS Buffer(const cl_mem& buffer) : Memory(buffer) { }
3166 /*! \brief Assignment from Buffer - performs shallow copy.
3168 * See Memory for further details.
3170 Buffer& operator = (const Buffer& rhs)
3173 Memory::operator=(rhs);
3178 /*! \brief Assignment from cl_mem - performs shallow copy.
3180 * See Memory for further details.
3182 Buffer& operator = (const cl_mem& rhs)
3184 Memory::operator=(rhs);
3188 #if defined(CL_VERSION_1_1)
3189 /*! \brief Creates a new buffer object from this.
3191 * Wraps clCreateSubBuffer().
3193 Buffer createSubBuffer(
3195 cl_buffer_create_type buffer_create_type,
3196 const void * buffer_create_info,
3197 cl_int * err = NULL)
3201 result.object_ = ::clCreateSubBuffer(
3208 detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
3218 #if defined (USE_DX_INTEROP)
3219 /*! \brief Class interface for creating OpenCL buffers from ID3D10Buffer's.
3221 * This is provided to facilitate interoperability with Direct3D.
3223 * See Memory for details about copy semantics, etc.
3227 class BufferD3D10 : public Buffer
3230 typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
3231 cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
3232 cl_int* errcode_ret);
3234 /*! \brief Constructs a BufferD3D10, in a specified context, from a
3235 * given ID3D10Buffer.
3237 * Wraps clCreateFromD3D10BufferKHR().
3240 const Context& context,
3242 ID3D10Buffer* bufobj,
3243 cl_int * err = NULL)
3245 static PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR = NULL;
3247 #if defined(CL_VERSION_1_2)
3248 vector<cl_context_properties> props = context.getInfo<CL_CONTEXT_PROPERTIES>();
3249 cl_platform platform = -1;
3250 for( int i = 0; i < props.size(); ++i ) {
3251 if( props[i] == CL_CONTEXT_PLATFORM ) {
3252 platform = props[i+1];
3255 __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clCreateFromD3D10BufferKHR);
3257 #if defined(CL_VERSION_1_1)
3258 __INIT_CL_EXT_FCN_PTR(clCreateFromD3D10BufferKHR);
3262 object_ = pfn_clCreateFromD3D10BufferKHR(
3268 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
3274 //! \brief Default constructor - initializes to NULL.
3275 BufferD3D10() : Buffer() { }
3277 /*! \brief Copy constructor - performs shallow copy.
3279 * See Memory for further details.
3281 BufferD3D10(const BufferD3D10& buffer) : Buffer(buffer) { }
3283 /*! \brief Constructor from cl_mem - takes ownership.
3285 * See Memory for further details.
3287 __CL_EXPLICIT_CONSTRUCTORS BufferD3D10(const cl_mem& buffer) : Buffer(buffer) { }
3289 /*! \brief Assignment from BufferD3D10 - performs shallow copy.
3291 * See Memory for further details.
3293 BufferD3D10& operator = (const BufferD3D10& rhs)
3296 Buffer::operator=(rhs);
3301 /*! \brief Assignment from cl_mem - performs shallow copy.
3303 * See Memory for further details.
3305 BufferD3D10& operator = (const cl_mem& rhs)
3307 Buffer::operator=(rhs);
3313 /*! \brief Class interface for GL Buffer Memory Objects.
3315 * This is provided to facilitate interoperability with OpenGL.
3317 * See Memory for details about copy semantics, etc.
3321 class BufferGL : public Buffer
3324 /*! \brief Constructs a BufferGL in a specified context, from a given
3327 * Wraps clCreateFromGLBuffer().
3330 const Context& context,
3333 cl_int * err = NULL)
3336 object_ = ::clCreateFromGLBuffer(
3342 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
3348 //! \brief Default constructor - initializes to NULL.
3349 BufferGL() : Buffer() { }
3351 /*! \brief Copy constructor - performs shallow copy.
3353 * See Memory for further details.
3355 BufferGL(const BufferGL& buffer) : Buffer(buffer) { }
3357 /*! \brief Constructor from cl_mem - takes ownership.
3359 * See Memory for further details.
3361 __CL_EXPLICIT_CONSTRUCTORS BufferGL(const cl_mem& buffer) : Buffer(buffer) { }
3363 /*! \brief Assignment from BufferGL - performs shallow copy.
3365 * See Memory for further details.
3367 BufferGL& operator = (const BufferGL& rhs)
3370 Buffer::operator=(rhs);
3375 /*! \brief Assignment from cl_mem - performs shallow copy.
3377 * See Memory for further details.
3379 BufferGL& operator = (const cl_mem& rhs)
3381 Buffer::operator=(rhs);
3385 //! \brief Wrapper for clGetGLObjectInfo().
3386 cl_int getObjectInfo(
3387 cl_gl_object_type *type,
3388 GLuint * gl_object_name)
3390 return detail::errHandler(
3391 ::clGetGLObjectInfo(object_,type,gl_object_name),
3392 __GET_GL_OBJECT_INFO_ERR);
3396 /*! \brief Class interface for GL Render Buffer Memory Objects.
3398 * This is provided to facilitate interoperability with OpenGL.
3400 * See Memory for details about copy semantics, etc.
3404 class BufferRenderGL : public Buffer
3407 /*! \brief Constructs a BufferRenderGL in a specified context, from a given
3410 * Wraps clCreateFromGLRenderbuffer().
3413 const Context& context,
3416 cl_int * err = NULL)
3419 object_ = ::clCreateFromGLRenderbuffer(
3425 detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR);
3431 //! \brief Default constructor - initializes to NULL.
3432 BufferRenderGL() : Buffer() { }
3434 /*! \brief Copy constructor - performs shallow copy.
3436 * See Memory for further details.
3438 BufferRenderGL(const BufferGL& buffer) : Buffer(buffer) { }
3440 /*! \brief Constructor from cl_mem - takes ownership.
3442 * See Memory for further details.
3444 __CL_EXPLICIT_CONSTRUCTORS BufferRenderGL(const cl_mem& buffer) : Buffer(buffer) { }
3446 /*! \brief Assignment from BufferGL - performs shallow copy.
3448 * See Memory for further details.
3450 BufferRenderGL& operator = (const BufferRenderGL& rhs)
3453 Buffer::operator=(rhs);
3458 /*! \brief Assignment from cl_mem - performs shallow copy.
3460 * See Memory for further details.
3462 BufferRenderGL& operator = (const cl_mem& rhs)
3464 Buffer::operator=(rhs);
3468 //! \brief Wrapper for clGetGLObjectInfo().
3469 cl_int getObjectInfo(
3470 cl_gl_object_type *type,
3471 GLuint * gl_object_name)
3473 return detail::errHandler(
3474 ::clGetGLObjectInfo(object_,type,gl_object_name),
3475 __GET_GL_OBJECT_INFO_ERR);
3479 /*! \brief C++ base class for Image Memory objects.
3481 * See Memory for details about copy semantics, etc.
3485 class Image : public Memory
3488 //! \brief Default constructor - initializes to NULL.
3489 Image() : Memory() { }
3491 /*! \brief Copy constructor - performs shallow copy.
3493 * See Memory for further details.
3495 Image(const Image& image) : Memory(image) { }
3497 /*! \brief Constructor from cl_mem - takes ownership.
3499 * See Memory for further details.
3501 __CL_EXPLICIT_CONSTRUCTORS Image(const cl_mem& image) : Memory(image) { }
3503 /*! \brief Assignment from Image - performs shallow copy.
3505 * See Memory for further details.
3507 Image& operator = (const Image& rhs)
3510 Memory::operator=(rhs);
3515 /*! \brief Assignment from cl_mem - performs shallow copy.
3517 * See Memory for further details.
3519 Image& operator = (const cl_mem& rhs)
3521 Memory::operator=(rhs);
3526 //! \brief Wrapper for clGetImageInfo().
3527 template <typename T>
3528 cl_int getImageInfo(cl_image_info name, T* param) const
3530 return detail::errHandler(
3531 detail::getInfo(&::clGetImageInfo, object_, name, param),
3532 __GET_IMAGE_INFO_ERR);
3535 //! \brief Wrapper for clGetImageInfo() that returns by value.
3536 template <cl_int name> typename
3537 detail::param_traits<detail::cl_image_info, name>::param_type
3538 getImageInfo(cl_int* err = NULL) const
3540 typename detail::param_traits<
3541 detail::cl_image_info, name>::param_type param;
3542 cl_int result = getImageInfo(name, ¶m);
3550 #if defined(CL_VERSION_1_2)
3551 /*! \brief Class interface for 1D Image Memory objects.
3553 * See Memory for details about copy semantics, etc.
3557 class Image1D : public Image
3560 /*! \brief Constructs a 1D Image in a specified context.
3562 * Wraps clCreateImage().
3565 const Context& context,
3569 void* host_ptr = NULL,
3573 cl_image_desc desc =
3575 CL_MEM_OBJECT_IMAGE1D,
3577 0, 0, 0, 0, 0, 0, 0, 0
3579 object_ = ::clCreateImage(
3587 detail::errHandler(error, __CREATE_IMAGE_ERR);
3593 //! \brief Default constructor - initializes to NULL.
3596 /*! \brief Copy constructor - performs shallow copy.
3598 * See Memory for further details.
3600 Image1D(const Image1D& image1D) : Image(image1D) { }
3602 /*! \brief Constructor from cl_mem - takes ownership.
3604 * See Memory for further details.
3606 __CL_EXPLICIT_CONSTRUCTORS Image1D(const cl_mem& image1D) : Image(image1D) { }
3608 /*! \brief Assignment from Image1D - performs shallow copy.
3610 * See Memory for further details.
3612 Image1D& operator = (const Image1D& rhs)
3615 Image::operator=(rhs);
3620 /*! \brief Assignment from cl_mem - performs shallow copy.
3622 * See Memory for further details.
3624 Image1D& operator = (const cl_mem& rhs)
3626 Image::operator=(rhs);
3631 /*! \class Image1DBuffer
3632 * \brief Image interface for 1D buffer images.
3634 class Image1DBuffer : public Image
3638 const Context& context,
3642 const Buffer &buffer,
3646 cl_image_desc desc =
3648 CL_MEM_OBJECT_IMAGE1D_BUFFER,
3650 0, 0, 0, 0, 0, 0, 0,
3653 object_ = ::clCreateImage(
3661 detail::errHandler(error, __CREATE_IMAGE_ERR);
3669 Image1DBuffer(const Image1DBuffer& image1D) : Image(image1D) { }
3671 __CL_EXPLICIT_CONSTRUCTORS Image1DBuffer(const cl_mem& image1D) : Image(image1D) { }
3673 Image1DBuffer& operator = (const Image1DBuffer& rhs)
3676 Image::operator=(rhs);
3681 Image1DBuffer& operator = (const cl_mem& rhs)
3683 Image::operator=(rhs);
3688 /*! \class Image1DArray
3689 * \brief Image interface for arrays of 1D images.
3691 class Image1DArray : public Image
3695 const Context& context,
3701 void* host_ptr = NULL,
3705 cl_image_desc desc =
3707 CL_MEM_OBJECT_IMAGE1D_ARRAY,
3709 0, 0, // height, depth (unused)
3714 object_ = ::clCreateImage(
3722 detail::errHandler(error, __CREATE_IMAGE_ERR);
3730 Image1DArray(const Image1DArray& imageArray) : Image(imageArray) { }
3732 __CL_EXPLICIT_CONSTRUCTORS Image1DArray(const cl_mem& imageArray) : Image(imageArray) { }
3734 Image1DArray& operator = (const Image1DArray& rhs)
3737 Image::operator=(rhs);
3742 Image1DArray& operator = (const cl_mem& rhs)
3744 Image::operator=(rhs);
3748 #endif // #if defined(CL_VERSION_1_2)
3751 /*! \brief Class interface for 2D Image Memory objects.
3753 * See Memory for details about copy semantics, etc.
3757 class Image2D : public Image
3760 /*! \brief Constructs a 1D Image in a specified context.
3762 * Wraps clCreateImage().
3765 const Context& context,
3770 ::size_t row_pitch = 0,
3771 void* host_ptr = NULL,
3775 bool useCreateImage;
3777 #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
3778 // Run-time decision based on the actual platform
3780 cl_uint version = detail::getContextPlatformVersion(context());
3781 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
3783 #elif defined(CL_VERSION_1_2)
3784 useCreateImage = true;
3786 useCreateImage = false;
3789 #if defined(CL_VERSION_1_2)
3792 cl_image_desc desc =
3794 CL_MEM_OBJECT_IMAGE2D,
3797 0, 0, // depth, array size (unused)
3801 object_ = ::clCreateImage(
3809 detail::errHandler(error, __CREATE_IMAGE_ERR);
3814 #endif // #if defined(CL_VERSION_1_2)
3815 #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
3816 if (!useCreateImage)
3818 object_ = ::clCreateImage2D(
3819 context(), flags,&format, width, height, row_pitch, host_ptr, &error);
3821 detail::errHandler(error, __CREATE_IMAGE2D_ERR);
3826 #endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
3829 //! \brief Default constructor - initializes to NULL.
3832 /*! \brief Copy constructor - performs shallow copy.
3834 * See Memory for further details.
3836 Image2D(const Image2D& image2D) : Image(image2D) { }
3838 /*! \brief Constructor from cl_mem - takes ownership.
3840 * See Memory for further details.
3842 __CL_EXPLICIT_CONSTRUCTORS Image2D(const cl_mem& image2D) : Image(image2D) { }
3844 /*! \brief Assignment from Image2D - performs shallow copy.
3846 * See Memory for further details.
3848 Image2D& operator = (const Image2D& rhs)
3851 Image::operator=(rhs);
3856 /*! \brief Assignment from cl_mem - performs shallow copy.
3858 * See Memory for further details.
3860 Image2D& operator = (const cl_mem& rhs)
3862 Image::operator=(rhs);
3868 #if !defined(CL_VERSION_1_2)
3869 /*! \brief Class interface for GL 2D Image Memory objects.
3871 * This is provided to facilitate interoperability with OpenGL.
3873 * See Memory for details about copy semantics, etc.
3876 * \note Deprecated for OpenCL 1.2. Please use ImageGL instead.
3878 class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED Image2DGL CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED : public Image2D
3881 /*! \brief Constructs an Image2DGL in a specified context, from a given
3884 * Wraps clCreateFromGLTexture2D().
3887 const Context& context,
3892 cl_int * err = NULL)
3895 object_ = ::clCreateFromGLTexture2D(
3903 detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR);
3910 //! \brief Default constructor - initializes to NULL.
3911 Image2DGL() : Image2D() { }
3913 /*! \brief Copy constructor - performs shallow copy.
3915 * See Memory for further details.
3917 Image2DGL(const Image2DGL& image) : Image2D(image) { }
3919 /*! \brief Constructor from cl_mem - takes ownership.
3921 * See Memory for further details.
3923 __CL_EXPLICIT_CONSTRUCTORS Image2DGL(const cl_mem& image) : Image2D(image) { }
3925 /*! \brief Assignment from Image2DGL - performs shallow copy.
3927 * See Memory for further details.
3929 Image2DGL& operator = (const Image2DGL& rhs)
3932 Image2D::operator=(rhs);
3937 /*! \brief Assignment from cl_mem - performs shallow copy.
3939 * See Memory for further details.
3941 Image2DGL& operator = (const cl_mem& rhs)
3943 Image2D::operator=(rhs);
3947 #endif // #if !defined(CL_VERSION_1_2)
3949 #if defined(CL_VERSION_1_2)
3950 /*! \class Image2DArray
3951 * \brief Image interface for arrays of 2D images.
3953 class Image2DArray : public Image
3957 const Context& context,
3964 ::size_t slicePitch,
3965 void* host_ptr = NULL,
3969 cl_image_desc desc =
3971 CL_MEM_OBJECT_IMAGE2D_ARRAY,
3974 0, // depth (unused)
3980 object_ = ::clCreateImage(
3988 detail::errHandler(error, __CREATE_IMAGE_ERR);
3996 Image2DArray(const Image2DArray& imageArray) : Image(imageArray) { }
3998 __CL_EXPLICIT_CONSTRUCTORS Image2DArray(const cl_mem& imageArray) : Image(imageArray) { }
4000 Image2DArray& operator = (const Image2DArray& rhs)
4003 Image::operator=(rhs);
4008 Image2DArray& operator = (const cl_mem& rhs)
4010 Image::operator=(rhs);
4014 #endif // #if defined(CL_VERSION_1_2)
4016 /*! \brief Class interface for 3D Image Memory objects.
4018 * See Memory for details about copy semantics, etc.
4022 class Image3D : public Image
4025 /*! \brief Constructs a 3D Image in a specified context.
4027 * Wraps clCreateImage().
4030 const Context& context,
4036 ::size_t row_pitch = 0,
4037 ::size_t slice_pitch = 0,
4038 void* host_ptr = NULL,
4042 bool useCreateImage;
4044 #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
4045 // Run-time decision based on the actual platform
4047 cl_uint version = detail::getContextPlatformVersion(context());
4048 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
4050 #elif defined(CL_VERSION_1_2)
4051 useCreateImage = true;
4053 useCreateImage = false;
4056 #if defined(CL_VERSION_1_2)
4059 cl_image_desc desc =
4061 CL_MEM_OBJECT_IMAGE3D,
4065 0, // array size (unused)
4070 object_ = ::clCreateImage(
4078 detail::errHandler(error, __CREATE_IMAGE_ERR);
4083 #endif // #if defined(CL_VERSION_1_2)
4084 #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
4085 if (!useCreateImage)
4087 object_ = ::clCreateImage3D(
4088 context(), flags, &format, width, height, depth, row_pitch,
4089 slice_pitch, host_ptr, &error);
4091 detail::errHandler(error, __CREATE_IMAGE3D_ERR);
4096 #endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
4099 //! \brief Default constructor - initializes to NULL.
4102 /*! \brief Copy constructor - performs shallow copy.
4104 * See Memory for further details.
4106 Image3D(const Image3D& image3D) : Image(image3D) { }
4108 /*! \brief Constructor from cl_mem - takes ownership.
4110 * See Memory for further details.
4112 __CL_EXPLICIT_CONSTRUCTORS Image3D(const cl_mem& image3D) : Image(image3D) { }
4114 /*! \brief Assignment from Image3D - performs shallow copy.
4116 * See Memory for further details.
4118 Image3D& operator = (const Image3D& rhs)
4121 Image::operator=(rhs);
4126 /*! \brief Assignment from cl_mem - performs shallow copy.
4128 * See Memory for further details.
4130 Image3D& operator = (const cl_mem& rhs)
4132 Image::operator=(rhs);
4137 #if !defined(CL_VERSION_1_2)
4138 /*! \brief Class interface for GL 3D Image Memory objects.
4140 * This is provided to facilitate interoperability with OpenGL.
4142 * See Memory for details about copy semantics, etc.
4146 class Image3DGL : public Image3D
4149 /*! \brief Constructs an Image3DGL in a specified context, from a given
4152 * Wraps clCreateFromGLTexture3D().
4155 const Context& context,
4160 cl_int * err = NULL)
4163 object_ = ::clCreateFromGLTexture3D(
4171 detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR);
4177 //! \brief Default constructor - initializes to NULL.
4178 Image3DGL() : Image3D() { }
4180 /*! \brief Copy constructor - performs shallow copy.
4182 * See Memory for further details.
4184 Image3DGL(const Image3DGL& image) : Image3D(image) { }
4186 /*! \brief Constructor from cl_mem - takes ownership.
4188 * See Memory for further details.
4190 __CL_EXPLICIT_CONSTRUCTORS Image3DGL(const cl_mem& image) : Image3D(image) { }
4192 /*! \brief Assignment from Image3DGL - performs shallow copy.
4194 * See Memory for further details.
4196 Image3DGL& operator = (const Image3DGL& rhs)
4199 Image3D::operator=(rhs);
4204 /*! \brief Assignment from cl_mem - performs shallow copy.
4206 * See Memory for further details.
4208 Image3DGL& operator = (const cl_mem& rhs)
4210 Image3D::operator=(rhs);
4214 #endif // #if !defined(CL_VERSION_1_2)
4216 #if defined(CL_VERSION_1_2)
4218 * \brief general image interface for GL interop.
4219 * We abstract the 2D and 3D GL images into a single instance here
4220 * that wraps all GL sourced images on the grounds that setup information
4221 * was performed by OpenCL anyway.
4223 class ImageGL : public Image
4227 const Context& context,
4232 cl_int * err = NULL)
4235 object_ = ::clCreateFromGLTexture(
4243 detail::errHandler(error, __CREATE_GL_TEXTURE_ERR);
4249 ImageGL() : Image() { }
4251 ImageGL(const ImageGL& image) : Image(image) { }
4253 __CL_EXPLICIT_CONSTRUCTORS ImageGL(const cl_mem& image) : Image(image) { }
4255 ImageGL& operator = (const ImageGL& rhs)
4258 Image::operator=(rhs);
4263 ImageGL& operator = (const cl_mem& rhs)
4265 Image::operator=(rhs);
4269 #endif // #if defined(CL_VERSION_1_2)
4271 /*! \brief Class interface for cl_sampler.
4273 * \note Copies of these objects are shallow, meaning that the copy will refer
4274 * to the same underlying cl_sampler as the original. For details, see
4275 * clRetainSampler() and clReleaseSampler().
4279 class Sampler : public detail::Wrapper<cl_sampler>
4282 /*! \brief Destructor.
4284 * This calls clReleaseSampler() on the value held by this instance.
4288 //! \brief Default constructor - initializes to NULL.
4291 /*! \brief Constructs a Sampler in a specified context.
4293 * Wraps clCreateSampler().
4296 const Context& context,
4297 cl_bool normalized_coords,
4298 cl_addressing_mode addressing_mode,
4299 cl_filter_mode filter_mode,
4303 object_ = ::clCreateSampler(
4310 detail::errHandler(error, __CREATE_SAMPLER_ERR);
4316 /*! \brief Copy constructor - performs shallow copy.
4318 * This calls clRetainSampler() on the parameter's cl_sampler.
4320 Sampler(const Sampler& sampler) : detail::Wrapper<cl_type>(sampler) { }
4322 /*! \brief Constructor from cl_sampler - takes ownership.
4324 * This effectively transfers ownership of a refcount on the cl_sampler
4325 * into the new Sampler object.
4327 Sampler(const cl_sampler& sampler) : detail::Wrapper<cl_type>(sampler) { }
4329 /*! \brief Assignment operator from Sampler.
4331 * This calls clRetainSampler() on the parameter and clReleaseSampler()
4332 * on the previous value held by this instance.
4334 Sampler& operator = (const Sampler& rhs)
4337 detail::Wrapper<cl_type>::operator=(rhs);
4342 /*! \brief Assignment operator from cl_sampler - takes ownership.
4344 * This effectively transfers ownership of a refcount on the rhs and calls
4345 * clReleaseSampler() on the value previously held by this instance.
4347 Sampler& operator = (const cl_sampler& rhs)
4349 detail::Wrapper<cl_type>::operator=(rhs);
4353 //! \brief Wrapper for clGetSamplerInfo().
4354 template <typename T>
4355 cl_int getInfo(cl_sampler_info name, T* param) const
4357 return detail::errHandler(
4358 detail::getInfo(&::clGetSamplerInfo, object_, name, param),
4359 __GET_SAMPLER_INFO_ERR);
4362 //! \brief Wrapper for clGetSamplerInfo() that returns by value.
4363 template <cl_int name> typename
4364 detail::param_traits<detail::cl_sampler_info, name>::param_type
4365 getInfo(cl_int* err = NULL) const
4367 typename detail::param_traits<
4368 detail::cl_sampler_info, name>::param_type param;
4369 cl_int result = getInfo(name, ¶m);
4381 //! \brief Class interface for specifying NDRange values.
4386 cl_uint dimensions_;
4389 //! \brief Default constructor - resulting range has zero dimensions.
4394 //! \brief Constructs one-dimensional range.
4395 NDRange(::size_t size0)
4401 //! \brief Constructs two-dimensional range.
4402 NDRange(::size_t size0, ::size_t size1)
4409 //! \brief Constructs three-dimensional range.
4410 NDRange(::size_t size0, ::size_t size1, ::size_t size2)
4418 /*! \brief Conversion operator to const ::size_t *.
4420 * \returns a pointer to the size of the first dimension.
4422 operator const ::size_t*() const {
4423 return (const ::size_t*) sizes_;
4426 //! \brief Queries the number of dimensions in the range.
4427 ::size_t dimensions() const { return dimensions_; }
4430 //! \brief A zero-dimensional range.
4431 static const NDRange NullRange;
4433 //! \brief Local address wrapper for use with Kernel::setArg
4434 struct LocalSpaceArg
4441 template <typename T>
4442 struct KernelArgumentHandler
4444 static ::size_t size(const T&) { return sizeof(T); }
4445 static T* ptr(T& value) { return &value; }
4449 struct KernelArgumentHandler<LocalSpaceArg>
4451 static ::size_t size(const LocalSpaceArg& value) { return value.size_; }
4452 static void* ptr(LocalSpaceArg&) { return NULL; }
4459 * \brief Helper function for generating LocalSpaceArg objects.
4460 * Deprecated. Replaced with Local.
4462 inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED LocalSpaceArg
4463 __local(::size_t size) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
4464 inline LocalSpaceArg
4465 __local(::size_t size)
4467 LocalSpaceArg ret = { size };
4472 * \brief Helper function for generating LocalSpaceArg objects.
4474 inline LocalSpaceArg
4475 Local(::size_t size)
4477 LocalSpaceArg ret = { size };
4481 //class KernelFunctor;
4483 /*! \brief Class interface for cl_kernel.
4485 * \note Copies of these objects are shallow, meaning that the copy will refer
4486 * to the same underlying cl_kernel as the original. For details, see
4487 * clRetainKernel() and clReleaseKernel().
4491 class Kernel : public detail::Wrapper<cl_kernel>
4494 inline Kernel(const Program& program, const char* name, cl_int* err = NULL);
4496 /*! \brief Destructor.
4498 * This calls clReleaseKernel() on the value held by this instance.
4502 //! \brief Default constructor - initializes to NULL.
4505 /*! \brief Copy constructor - performs shallow copy.
4507 * This calls clRetainKernel() on the parameter's cl_kernel.
4509 Kernel(const Kernel& kernel) : detail::Wrapper<cl_type>(kernel) { }
4511 /*! \brief Constructor from cl_kernel - takes ownership.
4513 * This effectively transfers ownership of a refcount on the cl_kernel
4514 * into the new Kernel object.
4516 __CL_EXPLICIT_CONSTRUCTORS Kernel(const cl_kernel& kernel) : detail::Wrapper<cl_type>(kernel) { }
4518 /*! \brief Assignment operator from Kernel.
4520 * This calls clRetainKernel() on the parameter and clReleaseKernel()
4521 * on the previous value held by this instance.
4523 Kernel& operator = (const Kernel& rhs)
4526 detail::Wrapper<cl_type>::operator=(rhs);
4531 /*! \brief Assignment operator from cl_kernel - takes ownership.
4533 * This effectively transfers ownership of a refcount on the rhs and calls
4534 * clReleaseKernel() on the value previously held by this instance.
4536 Kernel& operator = (const cl_kernel& rhs)
4538 detail::Wrapper<cl_type>::operator=(rhs);
4542 template <typename T>
4543 cl_int getInfo(cl_kernel_info name, T* param) const
4545 return detail::errHandler(
4546 detail::getInfo(&::clGetKernelInfo, object_, name, param),
4547 __GET_KERNEL_INFO_ERR);
4550 template <cl_int name> typename
4551 detail::param_traits<detail::cl_kernel_info, name>::param_type
4552 getInfo(cl_int* err = NULL) const
4554 typename detail::param_traits<
4555 detail::cl_kernel_info, name>::param_type param;
4556 cl_int result = getInfo(name, ¶m);
4563 #if defined(CL_VERSION_1_2)
4564 template <typename T>
4565 cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const
4567 return detail::errHandler(
4568 detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param),
4569 __GET_KERNEL_ARG_INFO_ERR);
4572 template <cl_int name> typename
4573 detail::param_traits<detail::cl_kernel_arg_info, name>::param_type
4574 getArgInfo(cl_uint argIndex, cl_int* err = NULL) const
4576 typename detail::param_traits<
4577 detail::cl_kernel_arg_info, name>::param_type param;
4578 cl_int result = getArgInfo(argIndex, name, ¶m);
4584 #endif // #if defined(CL_VERSION_1_2)
4586 template <typename T>
4587 cl_int getWorkGroupInfo(
4588 const Device& device, cl_kernel_work_group_info name, T* param) const
4590 return detail::errHandler(
4592 &::clGetKernelWorkGroupInfo, object_, device(), name, param),
4593 __GET_KERNEL_WORK_GROUP_INFO_ERR);
4596 template <cl_int name> typename
4597 detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
4598 getWorkGroupInfo(const Device& device, cl_int* err = NULL) const
4600 typename detail::param_traits<
4601 detail::cl_kernel_work_group_info, name>::param_type param;
4602 cl_int result = getWorkGroupInfo(device, name, ¶m);
4609 template <typename T>
4610 cl_int setArg(cl_uint index, T value)
4612 return detail::errHandler(
4616 detail::KernelArgumentHandler<T>::size(value),
4617 detail::KernelArgumentHandler<T>::ptr(value)),
4618 __SET_KERNEL_ARGS_ERR);
4621 cl_int setArg(cl_uint index, ::size_t size, void* argPtr)
4623 return detail::errHandler(
4624 ::clSetKernelArg(object_, index, size, argPtr),
4625 __SET_KERNEL_ARGS_ERR);
4630 * \brief Program interface that implements cl_program.
4632 class Program : public detail::Wrapper<cl_program>
4635 typedef VECTOR_CLASS<std::pair<const void*, ::size_t> > Binaries;
4636 typedef VECTOR_CLASS<std::pair<const char*, ::size_t> > Sources;
4639 const STRING_CLASS& source,
4645 const char * strings = source.c_str();
4646 const ::size_t length = source.size();
4648 Context context = Context::getDefault(err);
4650 object_ = ::clCreateProgramWithSource(
4651 context(), (cl_uint)1, &strings, &length, &error);
4653 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
4655 if (error == CL_SUCCESS && build) {
4657 error = ::clBuildProgram(
4665 detail::errHandler(error, __BUILD_PROGRAM_ERR);
4674 const Context& context,
4675 const STRING_CLASS& source,
4681 const char * strings = source.c_str();
4682 const ::size_t length = source.size();
4684 object_ = ::clCreateProgramWithSource(
4685 context(), (cl_uint)1, &strings, &length, &error);
4687 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
4689 if (error == CL_SUCCESS && build) {
4691 error = ::clBuildProgram(
4699 detail::errHandler(error, __BUILD_PROGRAM_ERR);
4708 const Context& context,
4709 const Sources& sources,
4714 const ::size_t n = (::size_t)sources.size();
4715 ::size_t* lengths = (::size_t*) alloca(n * sizeof(::size_t));
4716 const char** strings = (const char**) alloca(n * sizeof(const char*));
4718 for (::size_t i = 0; i < n; ++i) {
4719 strings[i] = sources[(int)i].first;
4720 lengths[i] = sources[(int)i].second;
4723 object_ = ::clCreateProgramWithSource(
4724 context(), (cl_uint)n, strings, lengths, &error);
4726 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
4733 * Construct a program object from a list of devices and a per-device list of binaries.
4734 * \param context A valid OpenCL context in which to construct the program.
4735 * \param devices A vector of OpenCL device objects for which the program will be created.
4736 * \param binaries A vector of pairs of a pointer to a binary object and its length.
4737 * \param binaryStatus An optional vector that on completion will be resized to
4738 * match the size of binaries and filled with values to specify if each binary
4739 * was successfully loaded.
4740 * Set to CL_SUCCESS if the binary was successfully loaded.
4741 * Set to CL_INVALID_VALUE if the length is 0 or the binary pointer is NULL.
4742 * Set to CL_INVALID_BINARY if the binary provided is not valid for the matching device.
4743 * \param err if non-NULL will be set to CL_SUCCESS on successful operation or one of the following errors:
4744 * CL_INVALID_CONTEXT if context is not a valid context.
4745 * CL_INVALID_VALUE if the length of devices is zero; or if the length of binaries does not match the length of devices;
4746 * or if any entry in binaries is NULL or has length 0.
4747 * CL_INVALID_DEVICE if OpenCL devices listed in devices are not in the list of devices associated with context.
4748 * CL_INVALID_BINARY if an invalid program binary was encountered for any device. binaryStatus will return specific status for each device.
4749 * CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host.
4752 const Context& context,
4753 const VECTOR_CLASS<Device>& devices,
4754 const Binaries& binaries,
4755 VECTOR_CLASS<cl_int>* binaryStatus = NULL,
4760 const ::size_t numDevices = devices.size();
4762 // Catch size mismatch early and return
4763 if(binaries.size() != numDevices) {
4764 error = CL_INVALID_VALUE;
4765 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
4772 ::size_t* lengths = (::size_t*) alloca(numDevices * sizeof(::size_t));
4773 const unsigned char** images = (const unsigned char**) alloca(numDevices * sizeof(const unsigned char**));
4775 for (::size_t i = 0; i < numDevices; ++i) {
4776 images[i] = (const unsigned char*)binaries[i].first;
4777 lengths[i] = binaries[(int)i].second;
4780 cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id));
4781 for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
4782 deviceIDs[deviceIndex] = (devices[deviceIndex])();
4786 binaryStatus->resize(numDevices);
4789 object_ = ::clCreateProgramWithBinary(
4790 context(), (cl_uint) devices.size(),
4792 lengths, images, binaryStatus != NULL
4793 ? &binaryStatus->front()
4796 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
4803 #if defined(CL_VERSION_1_2)
4805 * Create program using builtin kernels.
4806 * \param kernelNames Semi-colon separated list of builtin kernel names
4809 const Context& context,
4810 const VECTOR_CLASS<Device>& devices,
4811 const STRING_CLASS& kernelNames,
4817 ::size_t numDevices = devices.size();
4818 cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id));
4819 for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
4820 deviceIDs[deviceIndex] = (devices[deviceIndex])();
4823 object_ = ::clCreateProgramWithBuiltInKernels(
4825 (cl_uint) devices.size(),
4827 kernelNames.c_str(),
4830 detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR);
4835 #endif // #if defined(CL_VERSION_1_2)
4839 Program(const Program& program) : detail::Wrapper<cl_type>(program) { }
4841 __CL_EXPLICIT_CONSTRUCTORS Program(const cl_program& program) : detail::Wrapper<cl_type>(program) { }
4843 Program& operator = (const Program& rhs)
4846 detail::Wrapper<cl_type>::operator=(rhs);
4851 Program& operator = (const cl_program& rhs)
4853 detail::Wrapper<cl_type>::operator=(rhs);
4858 const VECTOR_CLASS<Device>& devices,
4859 const char* options = NULL,
4860 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
4861 void* data = NULL) const
4863 ::size_t numDevices = devices.size();
4864 cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id));
4865 for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
4866 deviceIDs[deviceIndex] = (devices[deviceIndex])();
4869 return detail::errHandler(
4878 __BUILD_PROGRAM_ERR);
4882 const char* options = NULL,
4883 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
4884 void* data = NULL) const
4886 return detail::errHandler(
4894 __BUILD_PROGRAM_ERR);
4897 #if defined(CL_VERSION_1_2)
4899 const char* options = NULL,
4900 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
4901 void* data = NULL) const
4903 return detail::errHandler(
4914 __COMPILE_PROGRAM_ERR);
4918 template <typename T>
4919 cl_int getInfo(cl_program_info name, T* param) const
4921 return detail::errHandler(
4922 detail::getInfo(&::clGetProgramInfo, object_, name, param),
4923 __GET_PROGRAM_INFO_ERR);
4926 template <cl_int name> typename
4927 detail::param_traits<detail::cl_program_info, name>::param_type
4928 getInfo(cl_int* err = NULL) const
4930 typename detail::param_traits<
4931 detail::cl_program_info, name>::param_type param;
4932 cl_int result = getInfo(name, ¶m);
4939 template <typename T>
4940 cl_int getBuildInfo(
4941 const Device& device, cl_program_build_info name, T* param) const
4943 return detail::errHandler(
4945 &::clGetProgramBuildInfo, object_, device(), name, param),
4946 __GET_PROGRAM_BUILD_INFO_ERR);
4949 template <cl_int name> typename
4950 detail::param_traits<detail::cl_program_build_info, name>::param_type
4951 getBuildInfo(const Device& device, cl_int* err = NULL) const
4953 typename detail::param_traits<
4954 detail::cl_program_build_info, name>::param_type param;
4955 cl_int result = getBuildInfo(device, name, ¶m);
4962 cl_int createKernels(VECTOR_CLASS<Kernel>* kernels)
4965 cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
4966 if (err != CL_SUCCESS) {
4967 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
4970 Kernel* value = (Kernel*) alloca(numKernels * sizeof(Kernel));
4971 err = ::clCreateKernelsInProgram(
4972 object_, numKernels, (cl_kernel*) value, NULL);
4973 if (err != CL_SUCCESS) {
4974 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
4977 kernels->assign(&value[0], &value[numKernels]);
4982 #if defined(CL_VERSION_1_2)
4983 inline Program linkProgram(
4986 const char* options = NULL,
4987 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
4991 cl_int err_local = CL_SUCCESS;
4993 cl_program programs[2] = { input1(), input2() };
4995 Context ctx = input1.getInfo<CL_PROGRAM_CONTEXT>();
4997 cl_program prog = ::clLinkProgram(
5008 detail::errHandler(err_local,__COMPILE_PROGRAM_ERR);
5013 return Program(prog);
5016 inline Program linkProgram(
5017 VECTOR_CLASS<Program> inputPrograms,
5018 const char* options = NULL,
5019 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
5023 cl_int err_local = CL_SUCCESS;
5025 cl_program * programs = (cl_program*) alloca(inputPrograms.size() * sizeof(cl_program));
5027 if (programs != NULL) {
5028 for (unsigned int i = 0; i < inputPrograms.size(); i++) {
5029 programs[i] = inputPrograms[i]();
5033 cl_program prog = ::clLinkProgram(
5034 Context::getDefault()(),
5038 (cl_uint)inputPrograms.size(),
5044 detail::errHandler(err_local,__COMPILE_PROGRAM_ERR);
5049 return Program(prog);
5054 inline VECTOR_CLASS<char *> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err) const
5056 VECTOR_CLASS< ::size_t> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>();
5057 VECTOR_CLASS<char *> binaries;
5058 for (VECTOR_CLASS< ::size_t>::iterator s = sizes.begin(); s != sizes.end(); ++s)
5063 binaries.push_back(ptr);
5066 cl_int result = getInfo(CL_PROGRAM_BINARIES, &binaries);
5073 inline Kernel::Kernel(const Program& program, const char* name, cl_int* err)
5077 object_ = ::clCreateKernel(program(), name, &error);
5078 detail::errHandler(error, __CREATE_KERNEL_ERR);
5086 /*! \class CommandQueue
5087 * \brief CommandQueue interface for cl_command_queue.
5089 class CommandQueue : public detail::Wrapper<cl_command_queue>
5092 static volatile int default_initialized_;
5093 static CommandQueue default_;
5094 static volatile cl_int default_error_;
5097 cl_command_queue_properties properties,
5102 Context context = Context::getDefault(&error);
5103 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
5105 if (error != CL_SUCCESS) {
5111 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
5113 object_ = ::clCreateCommandQueue(
5114 context(), device(), properties, &error);
5116 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
5123 * \brief Constructs a CommandQueue for an implementation defined device in the given context
5125 explicit CommandQueue(
5126 const Context& context,
5127 cl_command_queue_properties properties = 0,
5131 VECTOR_CLASS<cl::Device> devices;
5132 error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
5134 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
5136 if (error != CL_SUCCESS)
5144 object_ = ::clCreateCommandQueue(context(), devices[0](), properties, &error);
5146 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
5155 const Context& context,
5156 const Device& device,
5157 cl_command_queue_properties properties = 0,
5161 object_ = ::clCreateCommandQueue(
5162 context(), device(), properties, &error);
5164 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
5170 static CommandQueue getDefault(cl_int * err = NULL)
5172 int state = detail::compare_exchange(
5173 &default_initialized_,
5174 __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED);
5176 if (state & __DEFAULT_INITIALIZED) {
5178 *err = default_error_;
5183 if (state & __DEFAULT_BEING_INITIALIZED) {
5184 // Assume writes will propagate eventually...
5185 while(default_initialized_ != __DEFAULT_INITIALIZED) {
5190 *err = default_error_;
5197 Context context = Context::getDefault(&error);
5198 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
5200 if (error != CL_SUCCESS) {
5206 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
5208 default_ = CommandQueue(context, device, 0, &error);
5210 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
5218 default_error_ = error;
5219 // Assume writes will propagate eventually...
5220 default_initialized_ = __DEFAULT_INITIALIZED;
5225 *err = default_error_;
5233 CommandQueue(const CommandQueue& commandQueue) : detail::Wrapper<cl_type>(commandQueue) { }
5235 CommandQueue(const cl_command_queue& commandQueue) : detail::Wrapper<cl_type>(commandQueue) { }
5237 CommandQueue& operator = (const CommandQueue& rhs)
5240 detail::Wrapper<cl_type>::operator=(rhs);
5245 CommandQueue& operator = (const cl_command_queue& rhs)
5247 detail::Wrapper<cl_type>::operator=(rhs);
5251 template <typename T>
5252 cl_int getInfo(cl_command_queue_info name, T* param) const
5254 return detail::errHandler(
5256 &::clGetCommandQueueInfo, object_, name, param),
5257 __GET_COMMAND_QUEUE_INFO_ERR);
5260 template <cl_int name> typename
5261 detail::param_traits<detail::cl_command_queue_info, name>::param_type
5262 getInfo(cl_int* err = NULL) const
5264 typename detail::param_traits<
5265 detail::cl_command_queue_info, name>::param_type param;
5266 cl_int result = getInfo(name, ¶m);
5273 cl_int enqueueReadBuffer(
5274 const Buffer& buffer,
5279 const VECTOR_CLASS<Event>* events = NULL,
5280 Event* event = NULL) const
5283 cl_int err = detail::errHandler(
5284 ::clEnqueueReadBuffer(
5285 object_, buffer(), blocking, offset, size,
5287 (events != NULL) ? (cl_uint) events->size() : 0,
5288 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5289 (event != NULL) ? &tmp : NULL),
5290 __ENQUEUE_READ_BUFFER_ERR);
5292 if (event != NULL && err == CL_SUCCESS)
5298 cl_int enqueueWriteBuffer(
5299 const Buffer& buffer,
5304 const VECTOR_CLASS<Event>* events = NULL,
5305 Event* event = NULL) const
5308 cl_int err = detail::errHandler(
5309 ::clEnqueueWriteBuffer(
5310 object_, buffer(), blocking, offset, size,
5312 (events != NULL) ? (cl_uint) events->size() : 0,
5313 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5314 (event != NULL) ? &tmp : NULL),
5315 __ENQUEUE_WRITE_BUFFER_ERR);
5317 if (event != NULL && err == CL_SUCCESS)
5323 cl_int enqueueCopyBuffer(
5326 ::size_t src_offset,
5327 ::size_t dst_offset,
5329 const VECTOR_CLASS<Event>* events = NULL,
5330 Event* event = NULL) const
5333 cl_int err = detail::errHandler(
5334 ::clEnqueueCopyBuffer(
5335 object_, src(), dst(), src_offset, dst_offset, size,
5336 (events != NULL) ? (cl_uint) events->size() : 0,
5337 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5338 (event != NULL) ? &tmp : NULL),
5339 __ENQEUE_COPY_BUFFER_ERR);
5341 if (event != NULL && err == CL_SUCCESS)
5347 cl_int enqueueReadBufferRect(
5348 const Buffer& buffer,
5350 const size_t<3>& buffer_offset,
5351 const size_t<3>& host_offset,
5352 const size_t<3>& region,
5353 ::size_t buffer_row_pitch,
5354 ::size_t buffer_slice_pitch,
5355 ::size_t host_row_pitch,
5356 ::size_t host_slice_pitch,
5358 const VECTOR_CLASS<Event>* events = NULL,
5359 Event* event = NULL) const
5362 cl_int err = detail::errHandler(
5363 ::clEnqueueReadBufferRect(
5367 (const ::size_t *)buffer_offset,
5368 (const ::size_t *)host_offset,
5369 (const ::size_t *)region,
5375 (events != NULL) ? (cl_uint) events->size() : 0,
5376 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5377 (event != NULL) ? &tmp : NULL),
5378 __ENQUEUE_READ_BUFFER_RECT_ERR);
5380 if (event != NULL && err == CL_SUCCESS)
5386 cl_int enqueueWriteBufferRect(
5387 const Buffer& buffer,
5389 const size_t<3>& buffer_offset,
5390 const size_t<3>& host_offset,
5391 const size_t<3>& region,
5392 ::size_t buffer_row_pitch,
5393 ::size_t buffer_slice_pitch,
5394 ::size_t host_row_pitch,
5395 ::size_t host_slice_pitch,
5397 const VECTOR_CLASS<Event>* events = NULL,
5398 Event* event = NULL) const
5401 cl_int err = detail::errHandler(
5402 ::clEnqueueWriteBufferRect(
5406 (const ::size_t *)buffer_offset,
5407 (const ::size_t *)host_offset,
5408 (const ::size_t *)region,
5414 (events != NULL) ? (cl_uint) events->size() : 0,
5415 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5416 (event != NULL) ? &tmp : NULL),
5417 __ENQUEUE_WRITE_BUFFER_RECT_ERR);
5419 if (event != NULL && err == CL_SUCCESS)
5425 cl_int enqueueCopyBufferRect(
5428 const size_t<3>& src_origin,
5429 const size_t<3>& dst_origin,
5430 const size_t<3>& region,
5431 ::size_t src_row_pitch,
5432 ::size_t src_slice_pitch,
5433 ::size_t dst_row_pitch,
5434 ::size_t dst_slice_pitch,
5435 const VECTOR_CLASS<Event>* events = NULL,
5436 Event* event = NULL) const
5439 cl_int err = detail::errHandler(
5440 ::clEnqueueCopyBufferRect(
5444 (const ::size_t *)src_origin,
5445 (const ::size_t *)dst_origin,
5446 (const ::size_t *)region,
5451 (events != NULL) ? (cl_uint) events->size() : 0,
5452 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5453 (event != NULL) ? &tmp : NULL),
5454 __ENQEUE_COPY_BUFFER_RECT_ERR);
5456 if (event != NULL && err == CL_SUCCESS)
5462 #if defined(CL_VERSION_1_2)
5464 * Enqueue a command to fill a buffer object with a pattern
5465 * of a given size. The pattern is specified a as vector.
5466 * \tparam PatternType The datatype of the pattern field.
5467 * The pattern type must be an accepted OpenCL data type.
5469 template<typename PatternType>
5470 cl_int enqueueFillBuffer(
5471 const Buffer& buffer,
5472 PatternType pattern,
5475 const VECTOR_CLASS<Event>* events = NULL,
5476 Event* event = NULL) const
5479 cl_int err = detail::errHandler(
5480 ::clEnqueueFillBuffer(
5483 static_cast<void*>(&pattern),
5484 sizeof(PatternType),
5487 (events != NULL) ? (cl_uint) events->size() : 0,
5488 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5489 (event != NULL) ? &tmp : NULL),
5490 __ENQUEUE_FILL_BUFFER_ERR);
5492 if (event != NULL && err == CL_SUCCESS)
5497 #endif // #if defined(CL_VERSION_1_2)
5499 cl_int enqueueReadImage(
5502 const size_t<3>& origin,
5503 const size_t<3>& region,
5505 ::size_t slice_pitch,
5507 const VECTOR_CLASS<Event>* events = NULL,
5508 Event* event = NULL) const
5511 cl_int err = detail::errHandler(
5512 ::clEnqueueReadImage(
5513 object_, image(), blocking, (const ::size_t *) origin,
5514 (const ::size_t *) region, row_pitch, slice_pitch, ptr,
5515 (events != NULL) ? (cl_uint) events->size() : 0,
5516 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5517 (event != NULL) ? &tmp : NULL),
5518 __ENQUEUE_READ_IMAGE_ERR);
5520 if (event != NULL && err == CL_SUCCESS)
5526 cl_int enqueueWriteImage(
5529 const size_t<3>& origin,
5530 const size_t<3>& region,
5532 ::size_t slice_pitch,
5534 const VECTOR_CLASS<Event>* events = NULL,
5535 Event* event = NULL) const
5538 cl_int err = detail::errHandler(
5539 ::clEnqueueWriteImage(
5540 object_, image(), blocking, (const ::size_t *) origin,
5541 (const ::size_t *) region, row_pitch, slice_pitch, ptr,
5542 (events != NULL) ? (cl_uint) events->size() : 0,
5543 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5544 (event != NULL) ? &tmp : NULL),
5545 __ENQUEUE_WRITE_IMAGE_ERR);
5547 if (event != NULL && err == CL_SUCCESS)
5553 cl_int enqueueCopyImage(
5556 const size_t<3>& src_origin,
5557 const size_t<3>& dst_origin,
5558 const size_t<3>& region,
5559 const VECTOR_CLASS<Event>* events = NULL,
5560 Event* event = NULL) const
5563 cl_int err = detail::errHandler(
5564 ::clEnqueueCopyImage(
5565 object_, src(), dst(), (const ::size_t *) src_origin,
5566 (const ::size_t *)dst_origin, (const ::size_t *) region,
5567 (events != NULL) ? (cl_uint) events->size() : 0,
5568 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5569 (event != NULL) ? &tmp : NULL),
5570 __ENQUEUE_COPY_IMAGE_ERR);
5572 if (event != NULL && err == CL_SUCCESS)
5578 #if defined(CL_VERSION_1_2)
5580 * Enqueue a command to fill an image object with a specified color.
5581 * \param fillColor is the color to use to fill the image.
5582 * This is a four component RGBA floating-point color value if
5583 * the image channel data type is not an unnormalized signed or
5584 * unsigned data type.
5586 cl_int enqueueFillImage(
5588 cl_float4 fillColor,
5589 const size_t<3>& origin,
5590 const size_t<3>& region,
5591 const VECTOR_CLASS<Event>* events = NULL,
5592 Event* event = NULL) const
5595 cl_int err = detail::errHandler(
5596 ::clEnqueueFillImage(
5599 static_cast<void*>(&fillColor),
5600 (const ::size_t *) origin,
5601 (const ::size_t *) region,
5602 (events != NULL) ? (cl_uint) events->size() : 0,
5603 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5604 (event != NULL) ? &tmp : NULL),
5605 __ENQUEUE_FILL_IMAGE_ERR);
5607 if (event != NULL && err == CL_SUCCESS)
5614 * Enqueue a command to fill an image object with a specified color.
5615 * \param fillColor is the color to use to fill the image.
5616 * This is a four component RGBA signed integer color value if
5617 * the image channel data type is an unnormalized signed integer
5620 cl_int enqueueFillImage(
5623 const size_t<3>& origin,
5624 const size_t<3>& region,
5625 const VECTOR_CLASS<Event>* events = NULL,
5626 Event* event = NULL) const
5629 cl_int err = detail::errHandler(
5630 ::clEnqueueFillImage(
5633 static_cast<void*>(&fillColor),
5634 (const ::size_t *) origin,
5635 (const ::size_t *) region,
5636 (events != NULL) ? (cl_uint) events->size() : 0,
5637 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5638 (event != NULL) ? &tmp : NULL),
5639 __ENQUEUE_FILL_IMAGE_ERR);
5641 if (event != NULL && err == CL_SUCCESS)
5648 * Enqueue a command to fill an image object with a specified color.
5649 * \param fillColor is the color to use to fill the image.
5650 * This is a four component RGBA unsigned integer color value if
5651 * the image channel data type is an unnormalized unsigned integer
5654 cl_int enqueueFillImage(
5657 const size_t<3>& origin,
5658 const size_t<3>& region,
5659 const VECTOR_CLASS<Event>* events = NULL,
5660 Event* event = NULL) const
5663 cl_int err = detail::errHandler(
5664 ::clEnqueueFillImage(
5667 static_cast<void*>(&fillColor),
5668 (const ::size_t *) origin,
5669 (const ::size_t *) region,
5670 (events != NULL) ? (cl_uint) events->size() : 0,
5671 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5672 (event != NULL) ? &tmp : NULL),
5673 __ENQUEUE_FILL_IMAGE_ERR);
5675 if (event != NULL && err == CL_SUCCESS)
5680 #endif // #if defined(CL_VERSION_1_2)
5682 cl_int enqueueCopyImageToBuffer(
5685 const size_t<3>& src_origin,
5686 const size_t<3>& region,
5687 ::size_t dst_offset,
5688 const VECTOR_CLASS<Event>* events = NULL,
5689 Event* event = NULL) const
5692 cl_int err = detail::errHandler(
5693 ::clEnqueueCopyImageToBuffer(
5694 object_, src(), dst(), (const ::size_t *) src_origin,
5695 (const ::size_t *) region, dst_offset,
5696 (events != NULL) ? (cl_uint) events->size() : 0,
5697 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5698 (event != NULL) ? &tmp : NULL),
5699 __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
5701 if (event != NULL && err == CL_SUCCESS)
5707 cl_int enqueueCopyBufferToImage(
5710 ::size_t src_offset,
5711 const size_t<3>& dst_origin,
5712 const size_t<3>& region,
5713 const VECTOR_CLASS<Event>* events = NULL,
5714 Event* event = NULL) const
5717 cl_int err = detail::errHandler(
5718 ::clEnqueueCopyBufferToImage(
5719 object_, src(), dst(), src_offset,
5720 (const ::size_t *) dst_origin, (const ::size_t *) region,
5721 (events != NULL) ? (cl_uint) events->size() : 0,
5722 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5723 (event != NULL) ? &tmp : NULL),
5724 __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
5726 if (event != NULL && err == CL_SUCCESS)
5732 void* enqueueMapBuffer(
5733 const Buffer& buffer,
5738 const VECTOR_CLASS<Event>* events = NULL,
5739 Event* event = NULL,
5740 cl_int* err = NULL) const
5743 void * result = ::clEnqueueMapBuffer(
5744 object_, buffer(), blocking, flags, offset, size,
5745 (events != NULL) ? (cl_uint) events->size() : 0,
5746 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5750 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
5757 void* enqueueMapImage(
5758 const Image& buffer,
5761 const size_t<3>& origin,
5762 const size_t<3>& region,
5763 ::size_t * row_pitch,
5764 ::size_t * slice_pitch,
5765 const VECTOR_CLASS<Event>* events = NULL,
5766 Event* event = NULL,
5767 cl_int* err = NULL) const
5770 void * result = ::clEnqueueMapImage(
5771 object_, buffer(), blocking, flags,
5772 (const ::size_t *) origin, (const ::size_t *) region,
5773 row_pitch, slice_pitch,
5774 (events != NULL) ? (cl_uint) events->size() : 0,
5775 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5779 detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
5786 cl_int enqueueUnmapMemObject(
5787 const Memory& memory,
5789 const VECTOR_CLASS<Event>* events = NULL,
5790 Event* event = NULL) const
5793 cl_int err = detail::errHandler(
5794 ::clEnqueueUnmapMemObject(
5795 object_, memory(), mapped_ptr,
5796 (events != NULL) ? (cl_uint) events->size() : 0,
5797 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5798 (event != NULL) ? &tmp : NULL),
5799 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
5801 if (event != NULL && err == CL_SUCCESS)
5807 #if defined(CL_VERSION_1_2)
5809 * Enqueues a marker command which waits for either a list of events to complete,
5810 * or all previously enqueued commands to complete.
5812 * Enqueues a marker command which waits for either a list of events to complete,
5813 * or if the list is empty it waits for all commands previously enqueued in command_queue
5814 * to complete before it completes. This command returns an event which can be waited on,
5815 * i.e. this event can be waited on to insure that all events either in the event_wait_list
5816 * or all previously enqueued commands, queued before this command to command_queue,
5819 cl_int enqueueMarkerWithWaitList(
5820 const VECTOR_CLASS<Event> *events = 0,
5824 cl_int err = detail::errHandler(
5825 ::clEnqueueMarkerWithWaitList(
5827 (events != NULL) ? (cl_uint) events->size() : 0,
5828 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5829 (event != NULL) ? &tmp : NULL),
5830 __ENQUEUE_MARKER_WAIT_LIST_ERR);
5832 if (event != NULL && err == CL_SUCCESS)
5839 * A synchronization point that enqueues a barrier operation.
5841 * Enqueues a barrier command which waits for either a list of events to complete,
5842 * or if the list is empty it waits for all commands previously enqueued in command_queue
5843 * to complete before it completes. This command blocks command execution, that is, any
5844 * following commands enqueued after it do not execute until it completes. This command
5845 * returns an event which can be waited on, i.e. this event can be waited on to insure that
5846 * all events either in the event_wait_list or all previously enqueued commands, queued
5847 * before this command to command_queue, have completed.
5849 cl_int enqueueBarrierWithWaitList(
5850 const VECTOR_CLASS<Event> *events = 0,
5854 cl_int err = detail::errHandler(
5855 ::clEnqueueBarrierWithWaitList(
5857 (events != NULL) ? (cl_uint) events->size() : 0,
5858 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5859 (event != NULL) ? &tmp : NULL),
5860 __ENQUEUE_BARRIER_WAIT_LIST_ERR);
5862 if (event != NULL && err == CL_SUCCESS)
5869 * Enqueues a command to indicate with which device a set of memory objects
5870 * should be associated.
5872 cl_int enqueueMigrateMemObjects(
5873 const VECTOR_CLASS<Memory> &memObjects,
5874 cl_mem_migration_flags flags,
5875 const VECTOR_CLASS<Event>* events = NULL,
5881 cl_mem* localMemObjects = static_cast<cl_mem*>(alloca(memObjects.size() * sizeof(cl_mem)));
5882 for( int i = 0; i < (int)memObjects.size(); ++i ) {
5883 localMemObjects[i] = memObjects[i]();
5887 cl_int err = detail::errHandler(
5888 ::clEnqueueMigrateMemObjects(
5890 (cl_uint)memObjects.size(),
5891 static_cast<const cl_mem*>(localMemObjects),
5893 (events != NULL) ? (cl_uint) events->size() : 0,
5894 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5895 (event != NULL) ? &tmp : NULL),
5896 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
5898 if (event != NULL && err == CL_SUCCESS)
5903 #endif // #if defined(CL_VERSION_1_2)
5905 cl_int enqueueNDRangeKernel(
5906 const Kernel& kernel,
5907 const NDRange& offset,
5908 const NDRange& global,
5909 const NDRange& local = NullRange,
5910 const VECTOR_CLASS<Event>* events = NULL,
5911 Event* event = NULL) const
5914 cl_int err = detail::errHandler(
5915 ::clEnqueueNDRangeKernel(
5916 object_, kernel(), (cl_uint) global.dimensions(),
5917 offset.dimensions() != 0 ? (const ::size_t*) offset : NULL,
5918 (const ::size_t*) global,
5919 local.dimensions() != 0 ? (const ::size_t*) local : NULL,
5920 (events != NULL) ? (cl_uint) events->size() : 0,
5921 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5922 (event != NULL) ? &tmp : NULL),
5923 __ENQUEUE_NDRANGE_KERNEL_ERR);
5925 if (event != NULL && err == CL_SUCCESS)
5932 const Kernel& kernel,
5933 const VECTOR_CLASS<Event>* events = NULL,
5934 Event* event = NULL) const
5937 cl_int err = detail::errHandler(
5940 (events != NULL) ? (cl_uint) events->size() : 0,
5941 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5942 (event != NULL) ? &tmp : NULL),
5943 __ENQUEUE_TASK_ERR);
5945 if (event != NULL && err == CL_SUCCESS)
5951 cl_int enqueueNativeKernel(
5952 void (CL_CALLBACK *userFptr)(void *),
5953 std::pair<void*, ::size_t> args,
5954 const VECTOR_CLASS<Memory>* mem_objects = NULL,
5955 const VECTOR_CLASS<const void*>* mem_locs = NULL,
5956 const VECTOR_CLASS<Event>* events = NULL,
5957 Event* event = NULL) const
5959 cl_mem * mems = (mem_objects != NULL && mem_objects->size() > 0)
5960 ? (cl_mem*) alloca(mem_objects->size() * sizeof(cl_mem))
5964 for (unsigned int i = 0; i < mem_objects->size(); i++) {
5965 mems[i] = ((*mem_objects)[i])();
5970 cl_int err = detail::errHandler(
5971 ::clEnqueueNativeKernel(
5972 object_, userFptr, args.first, args.second,
5973 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
5975 (mem_locs != NULL) ? (const void **) &mem_locs->front() : NULL,
5976 (events != NULL) ? (cl_uint) events->size() : 0,
5977 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5978 (event != NULL) ? &tmp : NULL),
5979 __ENQUEUE_NATIVE_KERNEL);
5981 if (event != NULL && err == CL_SUCCESS)
5988 * Deprecated APIs for 1.2
5990 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
5991 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
5992 cl_int enqueueMarker(Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
5994 return detail::errHandler(
5995 ::clEnqueueMarker(object_, (cl_event*) event),
5996 __ENQUEUE_MARKER_ERR);
5999 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
6000 cl_int enqueueWaitForEvents(const VECTOR_CLASS<Event>& events) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
6002 return detail::errHandler(
6003 ::clEnqueueWaitForEvents(
6005 (cl_uint) events.size(),
6006 (const cl_event*) &events.front()),
6007 __ENQUEUE_WAIT_FOR_EVENTS_ERR);
6009 #endif // #if defined(CL_VERSION_1_1)
6011 cl_int enqueueAcquireGLObjects(
6012 const VECTOR_CLASS<Memory>* mem_objects = NULL,
6013 const VECTOR_CLASS<Event>* events = NULL,
6014 Event* event = NULL) const
6017 cl_int err = detail::errHandler(
6018 ::clEnqueueAcquireGLObjects(
6020 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
6021 (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
6022 (events != NULL) ? (cl_uint) events->size() : 0,
6023 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6024 (event != NULL) ? &tmp : NULL),
6025 __ENQUEUE_ACQUIRE_GL_ERR);
6027 if (event != NULL && err == CL_SUCCESS)
6033 cl_int enqueueReleaseGLObjects(
6034 const VECTOR_CLASS<Memory>* mem_objects = NULL,
6035 const VECTOR_CLASS<Event>* events = NULL,
6036 Event* event = NULL) const
6039 cl_int err = detail::errHandler(
6040 ::clEnqueueReleaseGLObjects(
6042 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
6043 (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
6044 (events != NULL) ? (cl_uint) events->size() : 0,
6045 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6046 (event != NULL) ? &tmp : NULL),
6047 __ENQUEUE_RELEASE_GL_ERR);
6049 if (event != NULL && err == CL_SUCCESS)
6055 #if defined (USE_DX_INTEROP)
6056 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
6057 cl_command_queue command_queue, cl_uint num_objects,
6058 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
6059 const cl_event* event_wait_list, cl_event* event);
6060 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
6061 cl_command_queue command_queue, cl_uint num_objects,
6062 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
6063 const cl_event* event_wait_list, cl_event* event);
6065 cl_int enqueueAcquireD3D10Objects(
6066 const VECTOR_CLASS<Memory>* mem_objects = NULL,
6067 const VECTOR_CLASS<Event>* events = NULL,
6068 Event* event = NULL) const
6070 static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
6071 #if defined(CL_VERSION_1_2)
6072 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
6073 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
6074 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
6075 __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueAcquireD3D10ObjectsKHR);
6077 #if defined(CL_VERSION_1_1)
6078 __INIT_CL_EXT_FCN_PTR(clEnqueueAcquireD3D10ObjectsKHR);
6082 cl_int err = detail::errHandler(
6083 pfn_clEnqueueAcquireD3D10ObjectsKHR(
6085 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
6086 (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
6087 (events != NULL) ? (cl_uint) events->size() : 0,
6088 (events != NULL) ? (cl_event*) &events->front() : NULL,
6089 (event != NULL) ? &tmp : NULL),
6090 __ENQUEUE_ACQUIRE_GL_ERR);
6092 if (event != NULL && err == CL_SUCCESS)
6098 cl_int enqueueReleaseD3D10Objects(
6099 const VECTOR_CLASS<Memory>* mem_objects = NULL,
6100 const VECTOR_CLASS<Event>* events = NULL,
6101 Event* event = NULL) const
6103 static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL;
6104 #if defined(CL_VERSION_1_2)
6105 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
6106 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
6107 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
6108 __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueReleaseD3D10ObjectsKHR);
6109 #endif // #if defined(CL_VERSION_1_2)
6110 #if defined(CL_VERSION_1_1)
6111 __INIT_CL_EXT_FCN_PTR(clEnqueueReleaseD3D10ObjectsKHR);
6112 #endif // #if defined(CL_VERSION_1_1)
6115 cl_int err = detail::errHandler(
6116 pfn_clEnqueueReleaseD3D10ObjectsKHR(
6118 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
6119 (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
6120 (events != NULL) ? (cl_uint) events->size() : 0,
6121 (events != NULL) ? (cl_event*) &events->front() : NULL,
6122 (event != NULL) ? &tmp : NULL),
6123 __ENQUEUE_RELEASE_GL_ERR);
6125 if (event != NULL && err == CL_SUCCESS)
6133 * Deprecated APIs for 1.2
6135 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
6136 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
6137 cl_int enqueueBarrier() const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
6139 return detail::errHandler(
6140 ::clEnqueueBarrier(object_),
6141 __ENQUEUE_BARRIER_ERR);
6143 #endif // #if defined(CL_VERSION_1_1)
6145 cl_int flush() const
6147 return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
6150 cl_int finish() const
6152 return detail::errHandler(::clFinish(object_), __FINISH_ERR);
6157 __declspec(selectany) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED;
6158 __declspec(selectany) CommandQueue CommandQueue::default_;
6159 __declspec(selectany) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS;
6161 __attribute__((weak)) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED;
6162 __attribute__((weak)) CommandQueue CommandQueue::default_;
6163 __attribute__((weak)) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS;
6166 template< typename IteratorType >
6168 const Context &context,
6169 IteratorType startIterator,
6170 IteratorType endIterator,
6175 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
6178 cl_mem_flags flags = 0;
6180 flags |= CL_MEM_READ_ONLY;
6183 flags |= CL_MEM_READ_WRITE;
6186 flags |= CL_MEM_USE_HOST_PTR;
6189 ::size_t size = sizeof(DataType)*(endIterator - startIterator);
6192 object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
6194 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
6197 detail::errHandler(error, __CREATE_BUFFER_ERR);
6203 CommandQueue queue(context, 0, &error);
6204 detail::errHandler(error, __CREATE_BUFFER_ERR);
6209 error = cl::copy(queue, startIterator, endIterator, *this);
6210 detail::errHandler(error, __CREATE_BUFFER_ERR);
6217 inline cl_int enqueueReadBuffer(
6218 const Buffer& buffer,
6223 const VECTOR_CLASS<Event>* events = NULL,
6224 Event* event = NULL)
6227 CommandQueue queue = CommandQueue::getDefault(&error);
6229 if (error != CL_SUCCESS) {
6233 return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event);
6236 inline cl_int enqueueWriteBuffer(
6237 const Buffer& buffer,
6242 const VECTOR_CLASS<Event>* events = NULL,
6243 Event* event = NULL)
6246 CommandQueue queue = CommandQueue::getDefault(&error);
6248 if (error != CL_SUCCESS) {
6252 return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event);
6255 inline void* enqueueMapBuffer(
6256 const Buffer& buffer,
6261 const VECTOR_CLASS<Event>* events = NULL,
6262 Event* event = NULL,
6266 CommandQueue queue = CommandQueue::getDefault(&error);
6267 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
6272 void * result = ::clEnqueueMapBuffer(
6273 queue(), buffer(), blocking, flags, offset, size,
6274 (events != NULL) ? (cl_uint) events->size() : 0,
6275 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6279 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
6286 inline cl_int enqueueUnmapMemObject(
6287 const Memory& memory,
6289 const VECTOR_CLASS<Event>* events = NULL,
6290 Event* event = NULL)
6293 CommandQueue queue = CommandQueue::getDefault(&error);
6294 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
6295 if (error != CL_SUCCESS) {
6300 cl_int err = detail::errHandler(
6301 ::clEnqueueUnmapMemObject(
6302 queue(), memory(), mapped_ptr,
6303 (events != NULL) ? (cl_uint) events->size() : 0,
6304 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6305 (event != NULL) ? &tmp : NULL),
6306 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
6308 if (event != NULL && err == CL_SUCCESS)
6314 inline cl_int enqueueCopyBuffer(
6317 ::size_t src_offset,
6318 ::size_t dst_offset,
6320 const VECTOR_CLASS<Event>* events = NULL,
6321 Event* event = NULL)
6324 CommandQueue queue = CommandQueue::getDefault(&error);
6326 if (error != CL_SUCCESS) {
6330 return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event);
6334 * Blocking copy operation between iterators and a buffer.
6336 * Uses default command queue.
6338 template< typename IteratorType >
6339 inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
6342 CommandQueue queue = CommandQueue::getDefault(&error);
6343 if (error != CL_SUCCESS)
6346 return cl::copy(queue, startIterator, endIterator, buffer);
6350 * Blocking copy operation between iterators and a buffer.
6352 * Uses default command queue.
6354 template< typename IteratorType >
6355 inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
6358 CommandQueue queue = CommandQueue::getDefault(&error);
6359 if (error != CL_SUCCESS)
6362 return cl::copy(queue, buffer, startIterator, endIterator);
6366 * Blocking copy operation between iterators and a buffer.
6368 * Uses specified queue.
6370 template< typename IteratorType >
6371 inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
6373 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
6376 ::size_t length = endIterator-startIterator;
6377 ::size_t byteLength = length*sizeof(DataType);
6380 static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error));
6381 // if exceptions enabled, enqueueMapBuffer will throw
6382 if( error != CL_SUCCESS ) {
6385 #if defined(_MSC_VER)
6389 stdext::checked_array_iterator<DataType*>(
6392 std::copy(startIterator, endIterator, pointer);
6395 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
6396 // if exceptions enabled, enqueueUnmapMemObject will throw
6397 if( error != CL_SUCCESS ) {
6405 * Blocking copy operation between iterators and a buffer.
6407 * Uses specified queue.
6409 template< typename IteratorType >
6410 inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
6412 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
6415 ::size_t length = endIterator-startIterator;
6416 ::size_t byteLength = length*sizeof(DataType);
6419 static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error));
6420 // if exceptions enabled, enqueueMapBuffer will throw
6421 if( error != CL_SUCCESS ) {
6424 std::copy(pointer, pointer + length, startIterator);
6426 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
6427 // if exceptions enabled, enqueueUnmapMemObject will throw
6428 if( error != CL_SUCCESS ) {
6435 #if defined(CL_VERSION_1_1)
6436 inline cl_int enqueueReadBufferRect(
6437 const Buffer& buffer,
6439 const size_t<3>& buffer_offset,
6440 const size_t<3>& host_offset,
6441 const size_t<3>& region,
6442 ::size_t buffer_row_pitch,
6443 ::size_t buffer_slice_pitch,
6444 ::size_t host_row_pitch,
6445 ::size_t host_slice_pitch,
6447 const VECTOR_CLASS<Event>* events = NULL,
6448 Event* event = NULL)
6451 CommandQueue queue = CommandQueue::getDefault(&error);
6453 if (error != CL_SUCCESS) {
6457 return queue.enqueueReadBufferRect(
6472 inline cl_int enqueueWriteBufferRect(
6473 const Buffer& buffer,
6475 const size_t<3>& buffer_offset,
6476 const size_t<3>& host_offset,
6477 const size_t<3>& region,
6478 ::size_t buffer_row_pitch,
6479 ::size_t buffer_slice_pitch,
6480 ::size_t host_row_pitch,
6481 ::size_t host_slice_pitch,
6483 const VECTOR_CLASS<Event>* events = NULL,
6484 Event* event = NULL)
6487 CommandQueue queue = CommandQueue::getDefault(&error);
6489 if (error != CL_SUCCESS) {
6493 return queue.enqueueWriteBufferRect(
6508 inline cl_int enqueueCopyBufferRect(
6511 const size_t<3>& src_origin,
6512 const size_t<3>& dst_origin,
6513 const size_t<3>& region,
6514 ::size_t src_row_pitch,
6515 ::size_t src_slice_pitch,
6516 ::size_t dst_row_pitch,
6517 ::size_t dst_slice_pitch,
6518 const VECTOR_CLASS<Event>* events = NULL,
6519 Event* event = NULL)
6522 CommandQueue queue = CommandQueue::getDefault(&error);
6524 if (error != CL_SUCCESS) {
6528 return queue.enqueueCopyBufferRect(
6543 inline cl_int enqueueReadImage(
6546 const size_t<3>& origin,
6547 const size_t<3>& region,
6549 ::size_t slice_pitch,
6551 const VECTOR_CLASS<Event>* events = NULL,
6552 Event* event = NULL)
6555 CommandQueue queue = CommandQueue::getDefault(&error);
6557 if (error != CL_SUCCESS) {
6561 return queue.enqueueReadImage(
6573 inline cl_int enqueueWriteImage(
6576 const size_t<3>& origin,
6577 const size_t<3>& region,
6579 ::size_t slice_pitch,
6581 const VECTOR_CLASS<Event>* events = NULL,
6582 Event* event = NULL)
6585 CommandQueue queue = CommandQueue::getDefault(&error);
6587 if (error != CL_SUCCESS) {
6591 return queue.enqueueWriteImage(
6603 inline cl_int enqueueCopyImage(
6606 const size_t<3>& src_origin,
6607 const size_t<3>& dst_origin,
6608 const size_t<3>& region,
6609 const VECTOR_CLASS<Event>* events = NULL,
6610 Event* event = NULL)
6613 CommandQueue queue = CommandQueue::getDefault(&error);
6615 if (error != CL_SUCCESS) {
6619 return queue.enqueueCopyImage(
6629 inline cl_int enqueueCopyImageToBuffer(
6632 const size_t<3>& src_origin,
6633 const size_t<3>& region,
6634 ::size_t dst_offset,
6635 const VECTOR_CLASS<Event>* events = NULL,
6636 Event* event = NULL)
6639 CommandQueue queue = CommandQueue::getDefault(&error);
6641 if (error != CL_SUCCESS) {
6645 return queue.enqueueCopyImageToBuffer(
6655 inline cl_int enqueueCopyBufferToImage(
6658 ::size_t src_offset,
6659 const size_t<3>& dst_origin,
6660 const size_t<3>& region,
6661 const VECTOR_CLASS<Event>* events = NULL,
6662 Event* event = NULL)
6665 CommandQueue queue = CommandQueue::getDefault(&error);
6667 if (error != CL_SUCCESS) {
6671 return queue.enqueueCopyBufferToImage(
6682 inline cl_int flush(void)
6685 CommandQueue queue = CommandQueue::getDefault(&error);
6687 if (error != CL_SUCCESS) {
6691 return queue.flush();
6694 inline cl_int finish(void)
6697 CommandQueue queue = CommandQueue::getDefault(&error);
6699 if (error != CL_SUCCESS) {
6704 return queue.finish();
6707 // Kernel Functor support
6708 // New interface as of September 2011
6709 // Requires the C++11 std::tr1::function (note do not support TR1)
6710 // Visual Studio 2010 and GCC 4.2
6714 CommandQueue queue_;
6715 const NDRange offset_;
6716 const NDRange global_;
6717 const NDRange local_;
6718 VECTOR_CLASS<Event> events_;
6720 EnqueueArgs(NDRange global) :
6721 queue_(CommandQueue::getDefault()),
6729 EnqueueArgs(NDRange global, NDRange local) :
6730 queue_(CommandQueue::getDefault()),
6738 EnqueueArgs(NDRange offset, NDRange global, NDRange local) :
6739 queue_(CommandQueue::getDefault()),
6747 EnqueueArgs(Event e, NDRange global) :
6748 queue_(CommandQueue::getDefault()),
6753 events_.push_back(e);
6756 EnqueueArgs(Event e, NDRange global, NDRange local) :
6757 queue_(CommandQueue::getDefault()),
6762 events_.push_back(e);
6765 EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) :
6766 queue_(CommandQueue::getDefault()),
6771 events_.push_back(e);
6774 EnqueueArgs(const VECTOR_CLASS<Event> &events, NDRange global) :
6775 queue_(CommandQueue::getDefault()),
6784 EnqueueArgs(const VECTOR_CLASS<Event> &events, NDRange global, NDRange local) :
6785 queue_(CommandQueue::getDefault()),
6794 EnqueueArgs(const VECTOR_CLASS<Event> &events, NDRange offset, NDRange global, NDRange local) :
6795 queue_(CommandQueue::getDefault()),
6804 EnqueueArgs(CommandQueue &queue, NDRange global) :
6813 EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) :
6822 EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) :
6831 EnqueueArgs(CommandQueue &queue, Event e, NDRange global) :
6837 events_.push_back(e);
6840 EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) :
6846 events_.push_back(e);
6849 EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) :
6855 events_.push_back(e);
6858 EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS<Event> &events, NDRange global) :
6868 EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS<Event> &events, NDRange global, NDRange local) :
6878 EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS<Event> &events, NDRange offset, NDRange global, NDRange local) :
6893 template<int index, typename T0>
6896 static void set (Kernel kernel, T0 arg)
6898 kernel.setArg(index, arg);
6903 struct SetArg<index, NullType>
6905 static void set (Kernel, NullType)
6911 typename T0, typename T1, typename T2, typename T3,
6912 typename T4, typename T5, typename T6, typename T7,
6913 typename T8, typename T9, typename T10, typename T11,
6914 typename T12, typename T13, typename T14, typename T15,
6915 typename T16, typename T17, typename T18, typename T19,
6916 typename T20, typename T21, typename T22, typename T23,
6917 typename T24, typename T25, typename T26, typename T27,
6918 typename T28, typename T29, typename T30, typename T31
6920 class KernelFunctorGlobal
6926 KernelFunctorGlobal(
6931 KernelFunctorGlobal(
6932 const Program& program,
6933 const STRING_CLASS name,
6934 cl_int * err = NULL) :
6935 kernel_(program, name.c_str(), err)
6939 const EnqueueArgs& args,
6950 T10 t10 = NullType(),
6951 T11 t11 = NullType(),
6952 T12 t12 = NullType(),
6953 T13 t13 = NullType(),
6954 T14 t14 = NullType(),
6955 T15 t15 = NullType(),
6956 T16 t16 = NullType(),
6957 T17 t17 = NullType(),
6958 T18 t18 = NullType(),
6959 T19 t19 = NullType(),
6960 T20 t20 = NullType(),
6961 T21 t21 = NullType(),
6962 T22 t22 = NullType(),
6963 T23 t23 = NullType(),
6964 T24 t24 = NullType(),
6965 T25 t25 = NullType(),
6966 T26 t26 = NullType(),
6967 T27 t27 = NullType(),
6968 T28 t28 = NullType(),
6969 T29 t29 = NullType(),
6970 T30 t30 = NullType(),
6971 T31 t31 = NullType()
6975 SetArg<0, T0>::set(kernel_, t0);
6976 SetArg<1, T1>::set(kernel_, t1);
6977 SetArg<2, T2>::set(kernel_, t2);
6978 SetArg<3, T3>::set(kernel_, t3);
6979 SetArg<4, T4>::set(kernel_, t4);
6980 SetArg<5, T5>::set(kernel_, t5);
6981 SetArg<6, T6>::set(kernel_, t6);
6982 SetArg<7, T7>::set(kernel_, t7);
6983 SetArg<8, T8>::set(kernel_, t8);
6984 SetArg<9, T9>::set(kernel_, t9);
6985 SetArg<10, T10>::set(kernel_, t10);
6986 SetArg<11, T11>::set(kernel_, t11);
6987 SetArg<12, T12>::set(kernel_, t12);
6988 SetArg<13, T13>::set(kernel_, t13);
6989 SetArg<14, T14>::set(kernel_, t14);
6990 SetArg<15, T15>::set(kernel_, t15);
6991 SetArg<16, T16>::set(kernel_, t16);
6992 SetArg<17, T17>::set(kernel_, t17);
6993 SetArg<18, T18>::set(kernel_, t18);
6994 SetArg<19, T19>::set(kernel_, t19);
6995 SetArg<20, T20>::set(kernel_, t20);
6996 SetArg<21, T21>::set(kernel_, t21);
6997 SetArg<22, T22>::set(kernel_, t22);
6998 SetArg<23, T23>::set(kernel_, t23);
6999 SetArg<24, T24>::set(kernel_, t24);
7000 SetArg<25, T25>::set(kernel_, t25);
7001 SetArg<26, T26>::set(kernel_, t26);
7002 SetArg<27, T27>::set(kernel_, t27);
7003 SetArg<28, T28>::set(kernel_, t28);
7004 SetArg<29, T29>::set(kernel_, t29);
7005 SetArg<30, T30>::set(kernel_, t30);
7006 SetArg<31, T31>::set(kernel_, t31);
7008 args.queue_.enqueueNDRangeKernel(
7021 //------------------------------------------------------------------------------------------------------
7057 struct functionImplementation_
7059 typedef detail::KernelFunctorGlobal<
7093 FunctorType functor_;
7095 functionImplementation_(const FunctorType &functor) :
7099 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 32))
7100 // Fail variadic expansion for dev11
7101 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
7106 //! \brief Return type of the functor
7107 typedef Event result_type;
7109 //! \brief Function signature of kernel functor with no event dependency.
7110 typedef Event type_(
7146 const EnqueueArgs& enqueueArgs,
7251 struct functionImplementation_
7285 typedef detail::KernelFunctorGlobal<
7317 NullType> FunctorType;
7319 FunctorType functor_;
7321 functionImplementation_(const FunctorType &functor) :
7325 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 31))
7326 // Fail variadic expansion for dev11
7327 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
7332 //! \brief Return type of the functor
7333 typedef Event result_type;
7335 //! \brief Function signature of kernel functor with no event dependency.
7336 typedef Event type_(
7371 const EnqueueArgs& enqueueArgs,
7473 struct functionImplementation_
7507 typedef detail::KernelFunctorGlobal<
7539 NullType> FunctorType;
7541 FunctorType functor_;
7543 functionImplementation_(const FunctorType &functor) :
7547 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 30))
7548 // Fail variadic expansion for dev11
7549 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
7554 //! \brief Return type of the functor
7555 typedef Event result_type;
7557 //! \brief Function signature of kernel functor with no event dependency.
7558 typedef Event type_(
7592 const EnqueueArgs& enqueueArgs,
7691 struct functionImplementation_
7725 typedef detail::KernelFunctorGlobal<
7757 NullType> FunctorType;
7759 FunctorType functor_;
7761 functionImplementation_(const FunctorType &functor) :
7765 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 29))
7766 // Fail variadic expansion for dev11
7767 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
7772 //! \brief Return type of the functor
7773 typedef Event result_type;
7775 //! \brief Function signature of kernel functor with no event dependency.
7776 typedef Event type_(
7809 const EnqueueArgs& enqueueArgs,
7905 struct functionImplementation_
7939 typedef detail::KernelFunctorGlobal<
7971 NullType> FunctorType;
7973 FunctorType functor_;
7975 functionImplementation_(const FunctorType &functor) :
7979 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 28))
7980 // Fail variadic expansion for dev11
7981 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
7986 //! \brief Return type of the functor
7987 typedef Event result_type;
7989 //! \brief Function signature of kernel functor with no event dependency.
7990 typedef Event type_(
8022 const EnqueueArgs& enqueueArgs,
8115 struct functionImplementation_
8149 typedef detail::KernelFunctorGlobal<
8181 NullType> FunctorType;
8183 FunctorType functor_;
8185 functionImplementation_(const FunctorType &functor) :
8189 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 27))
8190 // Fail variadic expansion for dev11
8191 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
8196 //! \brief Return type of the functor
8197 typedef Event result_type;
8199 //! \brief Function signature of kernel functor with no event dependency.
8200 typedef Event type_(
8231 const EnqueueArgs& enqueueArgs,
8321 struct functionImplementation_
8355 typedef detail::KernelFunctorGlobal<
8387 NullType> FunctorType;
8389 FunctorType functor_;
8391 functionImplementation_(const FunctorType &functor) :
8395 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 26))
8396 // Fail variadic expansion for dev11
8397 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
8402 //! \brief Return type of the functor
8403 typedef Event result_type;
8405 //! \brief Function signature of kernel functor with no event dependency.
8406 typedef Event type_(
8436 const EnqueueArgs& enqueueArgs,
8523 struct functionImplementation_
8557 typedef detail::KernelFunctorGlobal<
8589 NullType> FunctorType;
8591 FunctorType functor_;
8593 functionImplementation_(const FunctorType &functor) :
8597 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 25))
8598 // Fail variadic expansion for dev11
8599 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
8604 //! \brief Return type of the functor
8605 typedef Event result_type;
8607 //! \brief Function signature of kernel functor with no event dependency.
8608 typedef Event type_(
8637 const EnqueueArgs& enqueueArgs,
8721 struct functionImplementation_
8755 typedef detail::KernelFunctorGlobal<
8787 NullType> FunctorType;
8789 FunctorType functor_;
8791 functionImplementation_(const FunctorType &functor) :
8795 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 24))
8796 // Fail variadic expansion for dev11
8797 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
8802 //! \brief Return type of the functor
8803 typedef Event result_type;
8805 //! \brief Function signature of kernel functor with no event dependency.
8806 typedef Event type_(
8834 const EnqueueArgs& enqueueArgs,
8915 struct functionImplementation_
8949 typedef detail::KernelFunctorGlobal<
8981 NullType> FunctorType;
8983 FunctorType functor_;
8985 functionImplementation_(const FunctorType &functor) :
8989 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 23))
8990 // Fail variadic expansion for dev11
8991 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
8996 //! \brief Return type of the functor
8997 typedef Event result_type;
8999 //! \brief Function signature of kernel functor with no event dependency.
9000 typedef Event type_(
9027 const EnqueueArgs& enqueueArgs,
9105 struct functionImplementation_
9139 typedef detail::KernelFunctorGlobal<
9171 NullType> FunctorType;
9173 FunctorType functor_;
9175 functionImplementation_(const FunctorType &functor) :
9179 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 22))
9180 // Fail variadic expansion for dev11
9181 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
9186 //! \brief Return type of the functor
9187 typedef Event result_type;
9189 //! \brief Function signature of kernel functor with no event dependency.
9190 typedef Event type_(
9216 const EnqueueArgs& enqueueArgs,
9291 struct functionImplementation_
9325 typedef detail::KernelFunctorGlobal<
9357 NullType> FunctorType;
9359 FunctorType functor_;
9361 functionImplementation_(const FunctorType &functor) :
9365 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 21))
9366 // Fail variadic expansion for dev11
9367 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
9372 //! \brief Return type of the functor
9373 typedef Event result_type;
9375 //! \brief Function signature of kernel functor with no event dependency.
9376 typedef Event type_(
9401 const EnqueueArgs& enqueueArgs,
9473 struct functionImplementation_
9507 typedef detail::KernelFunctorGlobal<
9539 NullType> FunctorType;
9541 FunctorType functor_;
9543 functionImplementation_(const FunctorType &functor) :
9547 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 20))
9548 // Fail variadic expansion for dev11
9549 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
9554 //! \brief Return type of the functor
9555 typedef Event result_type;
9557 //! \brief Function signature of kernel functor with no event dependency.
9558 typedef Event type_(
9582 const EnqueueArgs& enqueueArgs,
9651 struct functionImplementation_
9685 typedef detail::KernelFunctorGlobal<
9717 NullType> FunctorType;
9719 FunctorType functor_;
9721 functionImplementation_(const FunctorType &functor) :
9725 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 19))
9726 // Fail variadic expansion for dev11
9727 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
9732 //! \brief Return type of the functor
9733 typedef Event result_type;
9735 //! \brief Function signature of kernel functor with no event dependency.
9736 typedef Event type_(
9759 const EnqueueArgs& enqueueArgs,
9825 struct functionImplementation_
9859 typedef detail::KernelFunctorGlobal<
9891 NullType> FunctorType;
9893 FunctorType functor_;
9895 functionImplementation_(const FunctorType &functor) :
9899 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 18))
9900 // Fail variadic expansion for dev11
9901 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
9906 //! \brief Return type of the functor
9907 typedef Event result_type;
9909 //! \brief Function signature of kernel functor with no event dependency.
9910 typedef Event type_(
9932 const EnqueueArgs& enqueueArgs,
9995 struct functionImplementation_
10029 typedef detail::KernelFunctorGlobal<
10061 NullType> FunctorType;
10063 FunctorType functor_;
10065 functionImplementation_(const FunctorType &functor) :
10069 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 17))
10070 // Fail variadic expansion for dev11
10071 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
10076 //! \brief Return type of the functor
10077 typedef Event result_type;
10079 //! \brief Function signature of kernel functor with no event dependency.
10080 typedef Event type_(
10081 const EnqueueArgs&,
10101 const EnqueueArgs& enqueueArgs,
10161 struct functionImplementation_
10195 typedef detail::KernelFunctorGlobal<
10227 NullType> FunctorType;
10229 FunctorType functor_;
10231 functionImplementation_(const FunctorType &functor) :
10235 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 16))
10236 // Fail variadic expansion for dev11
10237 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
10242 //! \brief Return type of the functor
10243 typedef Event result_type;
10245 //! \brief Function signature of kernel functor with no event dependency.
10246 typedef Event type_(
10247 const EnqueueArgs&,
10266 const EnqueueArgs& enqueueArgs,
10323 struct functionImplementation_
10357 typedef detail::KernelFunctorGlobal<
10389 NullType> FunctorType;
10391 FunctorType functor_;
10393 functionImplementation_(const FunctorType &functor) :
10397 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 15))
10398 // Fail variadic expansion for dev11
10399 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
10404 //! \brief Return type of the functor
10405 typedef Event result_type;
10407 //! \brief Function signature of kernel functor with no event dependency.
10408 typedef Event type_(
10409 const EnqueueArgs&,
10427 const EnqueueArgs& enqueueArgs,
10481 struct functionImplementation_
10515 typedef detail::KernelFunctorGlobal<
10547 NullType> FunctorType;
10549 FunctorType functor_;
10551 functionImplementation_(const FunctorType &functor) :
10555 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 14))
10556 // Fail variadic expansion for dev11
10557 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
10562 //! \brief Return type of the functor
10563 typedef Event result_type;
10565 //! \brief Function signature of kernel functor with no event dependency.
10566 typedef Event type_(
10567 const EnqueueArgs&,
10584 const EnqueueArgs& enqueueArgs,
10635 struct functionImplementation_
10669 typedef detail::KernelFunctorGlobal<
10701 NullType> FunctorType;
10703 FunctorType functor_;
10705 functionImplementation_(const FunctorType &functor) :
10709 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 13))
10710 // Fail variadic expansion for dev11
10711 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
10716 //! \brief Return type of the functor
10717 typedef Event result_type;
10719 //! \brief Function signature of kernel functor with no event dependency.
10720 typedef Event type_(
10721 const EnqueueArgs&,
10737 const EnqueueArgs& enqueueArgs,
10785 struct functionImplementation_
10819 typedef detail::KernelFunctorGlobal<
10851 NullType> FunctorType;
10853 FunctorType functor_;
10855 functionImplementation_(const FunctorType &functor) :
10859 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 12))
10860 // Fail variadic expansion for dev11
10861 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
10866 //! \brief Return type of the functor
10867 typedef Event result_type;
10869 //! \brief Function signature of kernel functor with no event dependency.
10870 typedef Event type_(
10871 const EnqueueArgs&,
10886 const EnqueueArgs& enqueueArgs,
10931 struct functionImplementation_
10965 typedef detail::KernelFunctorGlobal<
10997 NullType> FunctorType;
10999 FunctorType functor_;
11001 functionImplementation_(const FunctorType &functor) :
11005 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 11))
11006 // Fail variadic expansion for dev11
11007 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
11012 //! \brief Return type of the functor
11013 typedef Event result_type;
11015 //! \brief Function signature of kernel functor with no event dependency.
11016 typedef Event type_(
11017 const EnqueueArgs&,
11031 const EnqueueArgs& enqueueArgs,
11073 struct functionImplementation_
11107 typedef detail::KernelFunctorGlobal<
11139 NullType> FunctorType;
11141 FunctorType functor_;
11143 functionImplementation_(const FunctorType &functor) :
11147 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 10))
11148 // Fail variadic expansion for dev11
11149 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
11154 //! \brief Return type of the functor
11155 typedef Event result_type;
11157 //! \brief Function signature of kernel functor with no event dependency.
11158 typedef Event type_(
11159 const EnqueueArgs&,
11172 const EnqueueArgs& enqueueArgs,
11211 struct functionImplementation_
11245 typedef detail::KernelFunctorGlobal<
11277 NullType> FunctorType;
11279 FunctorType functor_;
11281 functionImplementation_(const FunctorType &functor) :
11285 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 9))
11286 // Fail variadic expansion for dev11
11287 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
11292 //! \brief Return type of the functor
11293 typedef Event result_type;
11295 //! \brief Function signature of kernel functor with no event dependency.
11296 typedef Event type_(
11297 const EnqueueArgs&,
11309 const EnqueueArgs& enqueueArgs,
11345 struct functionImplementation_
11379 typedef detail::KernelFunctorGlobal<
11411 NullType> FunctorType;
11413 FunctorType functor_;
11415 functionImplementation_(const FunctorType &functor) :
11419 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 8))
11420 // Fail variadic expansion for dev11
11421 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
11426 //! \brief Return type of the functor
11427 typedef Event result_type;
11429 //! \brief Function signature of kernel functor with no event dependency.
11430 typedef Event type_(
11431 const EnqueueArgs&,
11442 const EnqueueArgs& enqueueArgs,
11475 struct functionImplementation_
11509 typedef detail::KernelFunctorGlobal<
11541 NullType> FunctorType;
11543 FunctorType functor_;
11545 functionImplementation_(const FunctorType &functor) :
11549 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 7))
11550 // Fail variadic expansion for dev11
11551 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
11556 //! \brief Return type of the functor
11557 typedef Event result_type;
11559 //! \brief Function signature of kernel functor with no event dependency.
11560 typedef Event type_(
11561 const EnqueueArgs&,
11571 const EnqueueArgs& enqueueArgs,
11601 struct functionImplementation_
11635 typedef detail::KernelFunctorGlobal<
11667 NullType> FunctorType;
11669 FunctorType functor_;
11671 functionImplementation_(const FunctorType &functor) :
11675 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 6))
11676 // Fail variadic expansion for dev11
11677 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
11682 //! \brief Return type of the functor
11683 typedef Event result_type;
11685 //! \brief Function signature of kernel functor with no event dependency.
11686 typedef Event type_(
11687 const EnqueueArgs&,
11696 const EnqueueArgs& enqueueArgs,
11723 struct functionImplementation_
11757 typedef detail::KernelFunctorGlobal<
11789 NullType> FunctorType;
11791 FunctorType functor_;
11793 functionImplementation_(const FunctorType &functor) :
11797 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 5))
11798 // Fail variadic expansion for dev11
11799 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
11804 //! \brief Return type of the functor
11805 typedef Event result_type;
11807 //! \brief Function signature of kernel functor with no event dependency.
11808 typedef Event type_(
11809 const EnqueueArgs&,
11817 const EnqueueArgs& enqueueArgs,
11841 struct functionImplementation_
11875 typedef detail::KernelFunctorGlobal<
11907 NullType> FunctorType;
11909 FunctorType functor_;
11911 functionImplementation_(const FunctorType &functor) :
11915 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 4))
11916 // Fail variadic expansion for dev11
11917 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
11922 //! \brief Return type of the functor
11923 typedef Event result_type;
11925 //! \brief Function signature of kernel functor with no event dependency.
11926 typedef Event type_(
11927 const EnqueueArgs&,
11934 const EnqueueArgs& enqueueArgs,
11955 struct functionImplementation_
11989 typedef detail::KernelFunctorGlobal<
12021 NullType> FunctorType;
12023 FunctorType functor_;
12025 functionImplementation_(const FunctorType &functor) :
12029 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 3))
12030 // Fail variadic expansion for dev11
12031 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
12036 //! \brief Return type of the functor
12037 typedef Event result_type;
12039 //! \brief Function signature of kernel functor with no event dependency.
12040 typedef Event type_(
12041 const EnqueueArgs&,
12047 const EnqueueArgs& enqueueArgs,
12065 struct functionImplementation_
12099 typedef detail::KernelFunctorGlobal<
12131 NullType> FunctorType;
12133 FunctorType functor_;
12135 functionImplementation_(const FunctorType &functor) :
12139 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 2))
12140 // Fail variadic expansion for dev11
12141 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
12146 //! \brief Return type of the functor
12147 typedef Event result_type;
12149 //! \brief Function signature of kernel functor with no event dependency.
12150 typedef Event type_(
12151 const EnqueueArgs&,
12156 const EnqueueArgs& enqueueArgs,
12171 struct functionImplementation_
12205 typedef detail::KernelFunctorGlobal<
12237 NullType> FunctorType;
12239 FunctorType functor_;
12241 functionImplementation_(const FunctorType &functor) :
12245 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 1))
12246 // Fail variadic expansion for dev11
12247 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
12252 //! \brief Return type of the functor
12253 typedef Event result_type;
12255 //! \brief Function signature of kernel functor with no event dependency.
12256 typedef Event type_(
12257 const EnqueueArgs&,
12261 const EnqueueArgs& enqueueArgs,
12276 } // namespace detail
12278 //----------------------------------------------------------------------------------------------
12281 typename T0, typename T1 = detail::NullType, typename T2 = detail::NullType,
12282 typename T3 = detail::NullType, typename T4 = detail::NullType,
12283 typename T5 = detail::NullType, typename T6 = detail::NullType,
12284 typename T7 = detail::NullType, typename T8 = detail::NullType,
12285 typename T9 = detail::NullType, typename T10 = detail::NullType,
12286 typename T11 = detail::NullType, typename T12 = detail::NullType,
12287 typename T13 = detail::NullType, typename T14 = detail::NullType,
12288 typename T15 = detail::NullType, typename T16 = detail::NullType,
12289 typename T17 = detail::NullType, typename T18 = detail::NullType,
12290 typename T19 = detail::NullType, typename T20 = detail::NullType,
12291 typename T21 = detail::NullType, typename T22 = detail::NullType,
12292 typename T23 = detail::NullType, typename T24 = detail::NullType,
12293 typename T25 = detail::NullType, typename T26 = detail::NullType,
12294 typename T27 = detail::NullType, typename T28 = detail::NullType,
12295 typename T29 = detail::NullType, typename T30 = detail::NullType,
12296 typename T31 = detail::NullType
12298 struct make_kernel :
12299 public detail::functionImplementation_<
12303 T12, T13, T14, T15,
12304 T16, T17, T18, T19,
12305 T20, T21, T22, T23,
12306 T24, T25, T26, T27,
12311 typedef detail::KernelFunctorGlobal<
12315 T12, T13, T14, T15,
12316 T16, T17, T18, T19,
12317 T20, T21, T22, T23,
12318 T24, T25, T26, T27,
12323 const Program& program,
12324 const STRING_CLASS name,
12325 cl_int * err = NULL) :
12326 detail::functionImplementation_<
12330 T12, T13, T14, T15,
12331 T16, T17, T18, T19,
12332 T20, T21, T22, T23,
12333 T24, T25, T26, T27,
12336 FunctorType(program, name, err))
12340 const Kernel kernel) :
12341 detail::functionImplementation_<
12345 T12, T13, T14, T15,
12346 T16, T17, T18, T19,
12347 T20, T21, T22, T23,
12348 T24, T25, T26, T27,
12351 FunctorType(kernel))
12356 //----------------------------------------------------------------------------------------------------------------------
12359 #if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
12360 #undef __GET_DEVICE_INFO_ERR
12361 #undef __GET_PLATFORM_INFO_ERR
12362 #undef __GET_DEVICE_IDS_ERR
12363 #undef __GET_CONTEXT_INFO_ERR
12364 #undef __GET_EVENT_INFO_ERR
12365 #undef __GET_EVENT_PROFILE_INFO_ERR
12366 #undef __GET_MEM_OBJECT_INFO_ERR
12367 #undef __GET_IMAGE_INFO_ERR
12368 #undef __GET_SAMPLER_INFO_ERR
12369 #undef __GET_KERNEL_INFO_ERR
12370 #undef __GET_KERNEL_ARG_INFO_ERR
12371 #undef __GET_KERNEL_WORK_GROUP_INFO_ERR
12372 #undef __GET_PROGRAM_INFO_ERR
12373 #undef __GET_PROGRAM_BUILD_INFO_ERR
12374 #undef __GET_COMMAND_QUEUE_INFO_ERR
12376 #undef __CREATE_CONTEXT_ERR
12377 #undef __CREATE_CONTEXT_FROM_TYPE_ERR
12378 #undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
12380 #undef __CREATE_BUFFER_ERR
12381 #undef __CREATE_SUBBUFFER_ERR
12382 #undef __CREATE_IMAGE2D_ERR
12383 #undef __CREATE_IMAGE3D_ERR
12384 #undef __CREATE_SAMPLER_ERR
12385 #undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
12387 #undef __CREATE_USER_EVENT_ERR
12388 #undef __SET_USER_EVENT_STATUS_ERR
12389 #undef __SET_EVENT_CALLBACK_ERR
12390 #undef __SET_PRINTF_CALLBACK_ERR
12392 #undef __WAIT_FOR_EVENTS_ERR
12394 #undef __CREATE_KERNEL_ERR
12395 #undef __SET_KERNEL_ARGS_ERR
12396 #undef __CREATE_PROGRAM_WITH_SOURCE_ERR
12397 #undef __CREATE_PROGRAM_WITH_BINARY_ERR
12398 #undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR
12399 #undef __BUILD_PROGRAM_ERR
12400 #undef __CREATE_KERNELS_IN_PROGRAM_ERR
12402 #undef __CREATE_COMMAND_QUEUE_ERR
12403 #undef __SET_COMMAND_QUEUE_PROPERTY_ERR
12404 #undef __ENQUEUE_READ_BUFFER_ERR
12405 #undef __ENQUEUE_WRITE_BUFFER_ERR
12406 #undef __ENQUEUE_READ_BUFFER_RECT_ERR
12407 #undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
12408 #undef __ENQEUE_COPY_BUFFER_ERR
12409 #undef __ENQEUE_COPY_BUFFER_RECT_ERR
12410 #undef __ENQUEUE_READ_IMAGE_ERR
12411 #undef __ENQUEUE_WRITE_IMAGE_ERR
12412 #undef __ENQUEUE_COPY_IMAGE_ERR
12413 #undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
12414 #undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
12415 #undef __ENQUEUE_MAP_BUFFER_ERR
12416 #undef __ENQUEUE_MAP_IMAGE_ERR
12417 #undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
12418 #undef __ENQUEUE_NDRANGE_KERNEL_ERR
12419 #undef __ENQUEUE_TASK_ERR
12420 #undef __ENQUEUE_NATIVE_KERNEL
12422 #undef __CL_EXPLICIT_CONSTRUCTORS
12424 #undef __UNLOAD_COMPILER_ERR
12425 #endif //__CL_USER_OVERRIDE_ERROR_STRINGS
12427 #undef __CL_FUNCTION_TYPE
12431 * Deprecated APIs for 1.2
12433 #if defined(CL_VERSION_1_1)
12434 #undef __INIT_CL_EXT_FCN_PTR
12435 #endif // #if defined(CL_VERSION_1_1)
12436 #undef __CREATE_SUB_DEVICES
12438 #if defined(USE_CL_DEVICE_FISSION)
12439 #undef __PARAM_NAME_DEVICE_FISSION
12440 #endif // USE_CL_DEVICE_FISSION
12442 #undef __DEFAULT_NOT_INITIALIZED
12443 #undef __DEFAULT_BEING_INITIALIZED
12444 #undef __DEFAULT_INITIALIZED
12449 #pragma pop_macro("max")