1 /*******************************************************************************
2 * Copyright (c) 2008-2015 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;
152 #if defined(USE_DX_INTEROP)
153 #include <CL/cl_d3d10.h>
154 #include <CL/cl_dx9_media_sharing.h>
158 #if defined(_MSC_VER)
163 #if defined(USE_CL_DEVICE_FISSION)
164 #include <CL/cl_ext.h>
167 #if defined(__APPLE__) || defined(__MACOSX)
168 #include <OpenCL/opencl.h>
170 #include <CL/opencl.h>
173 #if (_MSC_VER >= 1700) || (__cplusplus >= 201103L)
174 #define CL_HPP_RVALUE_REFERENCES_SUPPORTED
175 #define CL_HPP_CPP11_ATOMICS_SUPPORTED
179 #if (__cplusplus >= 201103L)
180 #define CL_HPP_NOEXCEPT noexcept
182 #define CL_HPP_NOEXCEPT
186 // To avoid accidentally taking ownership of core OpenCL types
187 // such as cl_kernel constructors are made explicit
189 #if defined(CL_VERSION_1_2) && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
190 #define __CL_EXPLICIT_CONSTRUCTORS explicit
191 #else // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
192 #define __CL_EXPLICIT_CONSTRUCTORS
193 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
195 // Define deprecated prefixes and suffixes to ensure compilation
196 // in case they are not pre-defined
197 #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
198 #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
199 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
200 #if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED)
201 #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
202 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
204 #if !defined(CL_CALLBACK)
212 #if defined(__CL_ENABLE_EXCEPTIONS)
214 #endif // #if defined(__CL_ENABLE_EXCEPTIONS)
216 #if !defined(__NO_STD_VECTOR)
220 #if !defined(__NO_STD_STRING)
224 #if defined(__ANDROID__) || defined(linux) || defined(__APPLE__) || defined(__MACOSX)
233 * \brief The OpenCL C++ bindings are defined within this namespace.
241 * Deprecated APIs for 1.2
243 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
244 #define __INIT_CL_EXT_FCN_PTR(name) \
246 pfn_##name = (PFN_##name) \
247 clGetExtensionFunctionAddress(#name); \
251 #endif // #if defined(CL_VERSION_1_1)
253 #if defined(CL_VERSION_1_2)
254 #define __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, name) \
256 pfn_##name = (PFN_##name) \
257 clGetExtensionFunctionAddressForPlatform(platform, #name); \
261 #endif // #if defined(CL_VERSION_1_1)
270 #if defined(__CL_ENABLE_EXCEPTIONS)
271 /*! \brief Exception class
273 * This may be thrown by API functions when __CL_ENABLE_EXCEPTIONS is defined.
275 class Error : public std::exception
279 const char * errStr_;
281 /*! \brief Create a new CL error exception for a given error code
282 * and corresponding message.
284 * \param err error code value.
286 * \param errStr a descriptive string that must remain in scope until
287 * handling of the exception has concluded. If set, it
288 * will be returned by what().
290 Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr)
295 /*! \brief Get error string associated with exception
297 * \return A memory pointer to the error message string.
299 virtual const char * what() const throw ()
301 if (errStr_ == NULL) {
309 /*! \brief Get error code associated with exception
311 * \return The error code.
313 cl_int err(void) const { return err_; }
316 #define __ERR_STR(x) #x
318 #define __ERR_STR(x) NULL
319 #endif // __CL_ENABLE_EXCEPTIONS
324 #if defined(__CL_ENABLE_EXCEPTIONS)
325 static inline cl_int errHandler (
327 const char * errStr = NULL)
329 if (err != CL_SUCCESS) {
330 throw Error(err, errStr);
335 static inline cl_int errHandler (cl_int err, const char * errStr = NULL)
337 (void) errStr; // suppress unused variable warning
340 #endif // __CL_ENABLE_EXCEPTIONS
345 //! \cond DOXYGEN_DETAIL
346 #if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
347 #define __GET_DEVICE_INFO_ERR __ERR_STR(clGetDeviceInfo)
348 #define __GET_PLATFORM_INFO_ERR __ERR_STR(clGetPlatformInfo)
349 #define __GET_DEVICE_IDS_ERR __ERR_STR(clGetDeviceIDs)
350 #define __GET_PLATFORM_IDS_ERR __ERR_STR(clGetPlatformIDs)
351 #define __GET_CONTEXT_INFO_ERR __ERR_STR(clGetContextInfo)
352 #define __GET_EVENT_INFO_ERR __ERR_STR(clGetEventInfo)
353 #define __GET_EVENT_PROFILE_INFO_ERR __ERR_STR(clGetEventProfileInfo)
354 #define __GET_MEM_OBJECT_INFO_ERR __ERR_STR(clGetMemObjectInfo)
355 #define __GET_IMAGE_INFO_ERR __ERR_STR(clGetImageInfo)
356 #define __GET_SAMPLER_INFO_ERR __ERR_STR(clGetSamplerInfo)
357 #define __GET_KERNEL_INFO_ERR __ERR_STR(clGetKernelInfo)
358 #if defined(CL_VERSION_1_2)
359 #define __GET_KERNEL_ARG_INFO_ERR __ERR_STR(clGetKernelArgInfo)
360 #endif // #if defined(CL_VERSION_1_2)
361 #define __GET_KERNEL_WORK_GROUP_INFO_ERR __ERR_STR(clGetKernelWorkGroupInfo)
362 #define __GET_PROGRAM_INFO_ERR __ERR_STR(clGetProgramInfo)
363 #define __GET_PROGRAM_BUILD_INFO_ERR __ERR_STR(clGetProgramBuildInfo)
364 #define __GET_COMMAND_QUEUE_INFO_ERR __ERR_STR(clGetCommandQueueInfo)
366 #define __CREATE_CONTEXT_ERR __ERR_STR(clCreateContext)
367 #define __CREATE_CONTEXT_FROM_TYPE_ERR __ERR_STR(clCreateContextFromType)
368 #define __GET_SUPPORTED_IMAGE_FORMATS_ERR __ERR_STR(clGetSupportedImageFormats)
370 #define __CREATE_BUFFER_ERR __ERR_STR(clCreateBuffer)
371 #define __COPY_ERR __ERR_STR(cl::copy)
372 #define __CREATE_SUBBUFFER_ERR __ERR_STR(clCreateSubBuffer)
373 #define __CREATE_GL_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer)
374 #define __CREATE_GL_RENDER_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer)
375 #define __GET_GL_OBJECT_INFO_ERR __ERR_STR(clGetGLObjectInfo)
376 #if defined(CL_VERSION_1_2)
377 #define __CREATE_IMAGE_ERR __ERR_STR(clCreateImage)
378 #define __CREATE_GL_TEXTURE_ERR __ERR_STR(clCreateFromGLTexture)
379 #define __IMAGE_DIMENSION_ERR __ERR_STR(Incorrect image dimensions)
380 #endif // #if defined(CL_VERSION_1_2)
381 #define __CREATE_SAMPLER_ERR __ERR_STR(clCreateSampler)
382 #define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR __ERR_STR(clSetMemObjectDestructorCallback)
384 #define __CREATE_USER_EVENT_ERR __ERR_STR(clCreateUserEvent)
385 #define __SET_USER_EVENT_STATUS_ERR __ERR_STR(clSetUserEventStatus)
386 #define __SET_EVENT_CALLBACK_ERR __ERR_STR(clSetEventCallback)
387 #define __WAIT_FOR_EVENTS_ERR __ERR_STR(clWaitForEvents)
389 #define __CREATE_KERNEL_ERR __ERR_STR(clCreateKernel)
390 #define __SET_KERNEL_ARGS_ERR __ERR_STR(clSetKernelArg)
391 #define __CREATE_PROGRAM_WITH_SOURCE_ERR __ERR_STR(clCreateProgramWithSource)
392 #define __CREATE_PROGRAM_WITH_BINARY_ERR __ERR_STR(clCreateProgramWithBinary)
393 #if defined(CL_VERSION_1_2)
394 #define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR __ERR_STR(clCreateProgramWithBuiltInKernels)
395 #endif // #if defined(CL_VERSION_1_2)
396 #define __BUILD_PROGRAM_ERR __ERR_STR(clBuildProgram)
397 #if defined(CL_VERSION_1_2)
398 #define __COMPILE_PROGRAM_ERR __ERR_STR(clCompileProgram)
399 #define __LINK_PROGRAM_ERR __ERR_STR(clLinkProgram)
400 #endif // #if defined(CL_VERSION_1_2)
401 #define __CREATE_KERNELS_IN_PROGRAM_ERR __ERR_STR(clCreateKernelsInProgram)
403 #define __CREATE_COMMAND_QUEUE_ERR __ERR_STR(clCreateCommandQueue)
404 #define __SET_COMMAND_QUEUE_PROPERTY_ERR __ERR_STR(clSetCommandQueueProperty)
405 #define __ENQUEUE_READ_BUFFER_ERR __ERR_STR(clEnqueueReadBuffer)
406 #define __ENQUEUE_READ_BUFFER_RECT_ERR __ERR_STR(clEnqueueReadBufferRect)
407 #define __ENQUEUE_WRITE_BUFFER_ERR __ERR_STR(clEnqueueWriteBuffer)
408 #define __ENQUEUE_WRITE_BUFFER_RECT_ERR __ERR_STR(clEnqueueWriteBufferRect)
409 #define __ENQEUE_COPY_BUFFER_ERR __ERR_STR(clEnqueueCopyBuffer)
410 #define __ENQEUE_COPY_BUFFER_RECT_ERR __ERR_STR(clEnqueueCopyBufferRect)
411 #define __ENQUEUE_FILL_BUFFER_ERR __ERR_STR(clEnqueueFillBuffer)
412 #define __ENQUEUE_READ_IMAGE_ERR __ERR_STR(clEnqueueReadImage)
413 #define __ENQUEUE_WRITE_IMAGE_ERR __ERR_STR(clEnqueueWriteImage)
414 #define __ENQUEUE_COPY_IMAGE_ERR __ERR_STR(clEnqueueCopyImage)
415 #define __ENQUEUE_FILL_IMAGE_ERR __ERR_STR(clEnqueueFillImage)
416 #define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR __ERR_STR(clEnqueueCopyImageToBuffer)
417 #define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR __ERR_STR(clEnqueueCopyBufferToImage)
418 #define __ENQUEUE_MAP_BUFFER_ERR __ERR_STR(clEnqueueMapBuffer)
419 #define __ENQUEUE_MAP_IMAGE_ERR __ERR_STR(clEnqueueMapImage)
420 #define __ENQUEUE_UNMAP_MEM_OBJECT_ERR __ERR_STR(clEnqueueUnMapMemObject)
421 #define __ENQUEUE_NDRANGE_KERNEL_ERR __ERR_STR(clEnqueueNDRangeKernel)
422 #define __ENQUEUE_TASK_ERR __ERR_STR(clEnqueueTask)
423 #define __ENQUEUE_NATIVE_KERNEL __ERR_STR(clEnqueueNativeKernel)
424 #if defined(CL_VERSION_1_2)
425 #define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR __ERR_STR(clEnqueueMigrateMemObjects)
426 #endif // #if defined(CL_VERSION_1_2)
428 #define __ENQUEUE_ACQUIRE_GL_ERR __ERR_STR(clEnqueueAcquireGLObjects)
429 #define __ENQUEUE_RELEASE_GL_ERR __ERR_STR(clEnqueueReleaseGLObjects)
432 #define __RETAIN_ERR __ERR_STR(Retain Object)
433 #define __RELEASE_ERR __ERR_STR(Release Object)
434 #define __FLUSH_ERR __ERR_STR(clFlush)
435 #define __FINISH_ERR __ERR_STR(clFinish)
436 #define __VECTOR_CAPACITY_ERR __ERR_STR(Vector capacity error)
439 * CL 1.2 version that uses device fission.
441 #if defined(CL_VERSION_1_2)
442 #define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevices)
444 #define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevicesEXT)
445 #endif // #if defined(CL_VERSION_1_2)
448 * Deprecated APIs for 1.2
450 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
451 #define __ENQUEUE_MARKER_ERR __ERR_STR(clEnqueueMarker)
452 #define __ENQUEUE_WAIT_FOR_EVENTS_ERR __ERR_STR(clEnqueueWaitForEvents)
453 #define __ENQUEUE_BARRIER_ERR __ERR_STR(clEnqueueBarrier)
454 #define __UNLOAD_COMPILER_ERR __ERR_STR(clUnloadCompiler)
455 #define __CREATE_GL_TEXTURE_2D_ERR __ERR_STR(clCreateFromGLTexture2D)
456 #define __CREATE_GL_TEXTURE_3D_ERR __ERR_STR(clCreateFromGLTexture3D)
457 #define __CREATE_IMAGE2D_ERR __ERR_STR(clCreateImage2D)
458 #define __CREATE_IMAGE3D_ERR __ERR_STR(clCreateImage3D)
459 #endif // #if defined(CL_VERSION_1_1)
461 #endif // __CL_USER_OVERRIDE_ERROR_STRINGS
465 * CL 1.2 marker and barrier commands
467 #if defined(CL_VERSION_1_2)
468 #define __ENQUEUE_MARKER_WAIT_LIST_ERR __ERR_STR(clEnqueueMarkerWithWaitList)
469 #define __ENQUEUE_BARRIER_WAIT_LIST_ERR __ERR_STR(clEnqueueBarrierWithWaitList)
470 #endif // #if defined(CL_VERSION_1_2)
472 #if !defined(__USE_DEV_STRING) && !defined(__NO_STD_STRING)
473 typedef std::string STRING_CLASS;
474 #elif !defined(__USE_DEV_STRING)
477 * \brief Simple string class, that provides a limited subset of std::string
478 * functionality but avoids many of the issues that come with that class.
480 * \note Deprecated. Please use std::string as default or
481 * re-define the string class to match the std::string
482 * interface by defining STRING_CLASS
484 class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED string CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
490 //! \brief Constructs an empty string, allocating no memory.
491 string(void) : size_(0), str_(NULL)
495 /*! \brief Constructs a string populated from an arbitrary value of
498 * An extra '\0' is added, in case none was contained in str.
500 * \param str the initial value of the string instance. Note that '\0'
501 * characters receive no special treatment. If NULL,
502 * the string is left empty, with a size of 0.
504 * \param size the number of characters to copy from str.
506 string(const char * str, ::size_t size) :
511 str_ = new char[size_+1];
513 memcpy(str_, str, size_ * sizeof(char));
522 /*! \brief Constructs a string populated from a null-terminated value.
524 * \param str the null-terminated initial value of the string instance.
525 * If NULL, the string is left empty, with a size of 0.
527 string(const char * str) :
532 size_= ::strlen(str);
535 str_ = new char[size_ + 1];
537 memcpy(str_, str, (size_ + 1) * sizeof(char));
542 void resize( ::size_t n )
555 char *newString = new char[n + 1];
556 ::size_t copySize = n;
563 memcpy(newString, str_, (copySize + 1) * sizeof(char));
565 if( copySize < size_ ) {
566 memset(newString + copySize, 0, size_ - copySize);
568 newString[size_] = '\0';
575 const char& operator[] ( ::size_t pos ) const
580 char& operator[] ( ::size_t pos )
585 /*! \brief Copies the value of another string to this one.
587 * \param rhs the string to copy.
589 * \returns a reference to the modified instance.
591 string& operator=(const string& rhs)
603 if (rhs.size_ == 0 || rhs.str_ == NULL) {
608 str_ = new char[rhs.size_ + 1];
612 memcpy(str_, rhs.str_, (size_ + 1) * sizeof(char));
622 /*! \brief Constructs a string by copying the value of another instance.
624 * \param rhs the string to copy.
626 string(const string& rhs) :
633 //! \brief Destructor - frees memory used to hold the current value.
640 //! \brief Queries the length of the string, excluding any added '\0's.
641 ::size_t size(void) const { return size_; }
643 //! \brief Queries the length of the string, excluding any added '\0's.
644 ::size_t length(void) const { return size(); }
646 /*! \brief Returns a pointer to the private copy held by this instance,
647 * or "" if empty/unset.
649 const char * c_str(void) const { return (str_) ? str_ : "";}
651 typedef cl::string STRING_CLASS;
652 #endif // #elif !defined(__USE_DEV_STRING)
654 #if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR)
655 #define VECTOR_CLASS std::vector
656 #elif !defined(__USE_DEV_VECTOR)
657 #define VECTOR_CLASS cl::vector
659 #if !defined(__MAX_DEFAULT_VECTOR_SIZE)
660 #define __MAX_DEFAULT_VECTOR_SIZE 10
664 * \brief Fixed sized vector implementation that mirroring
666 * \note Deprecated. Please use std::vector as default or
667 * re-define the vector class to match the std::vector
668 * interface by defining VECTOR_CLASS
670 * \note Not recommended for use with custom objects as
671 * current implementation will construct N elements
673 * std::vector functionality.
674 * \brief Fixed sized vector compatible with std::vector.
677 * This differs from std::vector<> not just in memory allocation,
678 * but also in terms of when members are constructed, destroyed,
679 * and assigned instead of being copy constructed.
681 * \param T type of element contained in the vector.
683 * \param N maximum size of the vector.
685 template <typename T, unsigned int N = __MAX_DEFAULT_VECTOR_SIZE>
686 class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED vector
693 //! \brief Constructs an empty vector with no memory allocated.
695 size_(static_cast<unsigned int>(0))
698 //! \brief Deallocates the vector's memory and destroys all of its elements.
704 //! \brief Returns the number of elements currently contained.
705 unsigned int size(void) const
710 /*! \brief Empties the vector of all elements.
712 * This does not deallocate memory but will invoke destructors
713 * on contained elements.
722 /*! \brief Appends an element after the last valid element.
723 * Calling this on a vector that has reached capacity will throw an
724 * exception if exceptions are enabled.
726 void push_back (const T& x)
729 new (&data_[size_]) T(x);
732 detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR);
736 /*! \brief Removes the last valid element from the vector.
737 * Calling this on an empty vector will throw an exception
738 * if exceptions are enabled.
746 detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR);
750 /*! \brief Constructs with a value copied from another.
752 * \param vec the vector to copy.
754 vector(const vector<T, N>& vec) :
758 assign(vec.begin(), vec.end());
762 /*! \brief Constructs with a specified number of initial elements.
764 * \param size number of initial elements.
766 * \param val value of initial elements.
768 vector(unsigned int size, const T& val = T()) :
771 for (unsigned int i = 0; i < size; i++) {
776 /*! \brief Overwrites the current content with that copied from another
779 * \param rhs vector to copy.
781 * \returns a reference to this.
783 vector<T, N>& operator=(const vector<T, N>& rhs)
789 if (rhs.size_ != 0) {
790 assign(rhs.begin(), rhs.end());
798 /*! \brief Tests equality against another instance.
800 * \param vec the vector against which to compare.
802 bool operator==(vector<T,N> &vec)
804 if (size() != vec.size()) {
808 for( unsigned int i = 0; i < size(); ++i ) {
809 if( operator[](i) != vec[i] ) {
816 //! \brief Conversion operator to T*.
817 operator T* () { return data_; }
819 //! \brief Conversion operator to const T*.
820 operator const T* () const { return data_; }
822 //! \brief Tests whether this instance has any elements.
823 bool empty (void) const
828 //! \brief Returns the maximum number of elements this instance can hold.
829 unsigned int max_size (void) const
834 //! \brief Returns the maximum number of elements this instance can hold.
835 unsigned int capacity () const
840 //! \brief Resizes the vector to the given size
841 void resize(unsigned int newSize, T fill = T())
845 detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR);
849 while (size_ < newSize)
851 new (&data_[size_]) T(fill);
854 while (size_ > newSize)
862 /*! \brief Returns a reference to a given element.
864 * \param index which element to access. *
866 * The caller is responsible for ensuring index is >= 0 and < size().
868 T& operator[](int index)
873 /*! \brief Returns a const reference to a given element.
875 * \param index which element to access.
878 * The caller is responsible for ensuring index is >= 0 and < size().
880 const T& operator[](int index) const
885 /*! \brief Assigns elements of the vector based on a source iterator range.
887 * \param start Beginning iterator of source range
888 * \param end Enditerator of source range
891 * Will throw an exception if exceptions are enabled and size exceeded.
894 void assign(I start, I end)
897 while(start != end) {
904 * \brief Const iterator class for vectors
909 const vector<T,N> *vec_;
913 * Internal iterator constructor to capture reference
914 * to the vector it iterates over rather than taking
915 * the vector by copy.
917 iterator (const vector<T,N> &vec, int index) :
934 iterator(const iterator& rhs) :
942 static iterator begin(const cl::vector<T,N> &vec)
949 static iterator end(const cl::vector<T,N> &vec)
951 iterator i(vec, vec.size());
956 bool operator==(iterator i)
958 return ((vec_ == i.vec_) &&
959 (index_ == i.index_));
962 bool operator!=(iterator i)
964 return (!(*this==i));
967 iterator& operator++()
973 iterator operator++(int)
975 iterator retVal(*this);
980 iterator& operator--()
986 iterator operator--(int)
988 iterator retVal(*this);
993 const T& operator *() const
995 return (*vec_)[index_];
1001 return iterator::begin(*this);
1004 iterator begin(void) const
1006 return iterator::begin(*this);
1011 return iterator::end(*this);
1014 iterator end(void) const
1016 return iterator::end(*this);
1026 return data_[size_];
1029 const T& front(void) const
1034 const T& back(void) const
1036 return data_[size_-1];
1038 } CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
1039 #endif // #if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR)
1046 #define __DEFAULT_NOT_INITIALIZED 1
1047 #define __DEFAULT_BEING_INITIALIZED 2
1048 #define __DEFAULT_INITIALIZED 4
1051 * Compare and exchange primitives are needed for handling of defaults
1054 #ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED
1055 inline int compare_exchange(std::atomic<int> * dest, int exchange, int comparand)
1056 #else // !CL_HPP_CPP11_ATOMICS_SUPPORTED
1057 inline int compare_exchange(volatile int * dest, int exchange, int comparand)
1058 #endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED
1060 #ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED
1061 std::atomic_compare_exchange_strong(dest, &comparand, exchange);
1064 return (int)(_InterlockedCompareExchange(
1065 (volatile long*)dest,
1068 #else // !_MSC_VER && !CL_HPP_CPP11_ATOMICS_SUPPORTED
1069 return (__sync_val_compare_and_swap(
1073 #endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED
1076 inline void fence() {
1077 #ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED
1078 std::atomic_thread_fence(std::memory_order_seq_cst);
1079 #elif _MSC_VER // !CL_HPP_CPP11_ATOMICS_SUPPORTED
1080 _ReadWriteBarrier();
1081 #else // !_MSC_VER && !CL_HPP_CPP11_ATOMICS_SUPPORTED
1082 __sync_synchronize();
1083 #endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED
1085 } // namespace detail
1088 /*! \brief class used to interface between C++ and
1089 * OpenCL C calls that require arrays of size_t values, whose
1090 * size is known statically.
1099 //! \brief Initialize size_t to all 0s
1102 for( int i = 0; i < N; ++i ) {
1107 ::size_t& operator[](int index)
1109 return data_[index];
1112 const ::size_t& operator[](int index) const
1114 return data_[index];
1117 //! \brief Conversion operator to T*.
1118 operator ::size_t* () { return data_; }
1120 //! \brief Conversion operator to const T*.
1121 operator const ::size_t* () const { return data_; }
1126 // Generic getInfoHelper. The final parameter is used to guide overload
1127 // resolution: the actual parameter passed is an int, which makes this
1128 // a worse conversion sequence than a specialization that declares the
1129 // parameter as an int.
1130 template<typename Functor, typename T>
1131 inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long)
1133 return f(name, sizeof(T), param, NULL);
1136 // Specialized getInfoHelper for VECTOR_CLASS params
1137 template <typename Func, typename T>
1138 inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS<T>* param, long)
1141 cl_int err = f(name, 0, NULL, &required);
1142 if (err != CL_SUCCESS) {
1146 T* value = (T*) alloca(required);
1147 err = f(name, required, value, NULL);
1148 if (err != CL_SUCCESS) {
1152 param->assign(&value[0], &value[required/sizeof(T)]);
1156 /* Specialization for reference-counted types. This depends on the
1157 * existence of Wrapper<T>::cl_type, and none of the other types having the
1158 * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1159 * does not work, because when using a derived type (e.g. Context) the generic
1160 * template will provide a better match.
1162 template <typename Func, typename T>
1163 inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS<T>* param, int, typename T::cl_type = 0)
1166 cl_int err = f(name, 0, NULL, &required);
1167 if (err != CL_SUCCESS) {
1171 typename T::cl_type * value = (typename T::cl_type *) alloca(required);
1172 err = f(name, required, value, NULL);
1173 if (err != CL_SUCCESS) {
1177 ::size_t elements = required / sizeof(typename T::cl_type);
1178 param->assign(&value[0], &value[elements]);
1179 for (::size_t i = 0; i < elements; i++)
1181 if (value[i] != NULL)
1183 err = (*param)[i].retain();
1184 if (err != CL_SUCCESS) {
1192 // Specialized for getInfo<CL_PROGRAM_BINARIES>
1193 template <typename Func>
1194 inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS<char *>* param, int)
1196 cl_int err = f(name, param->size() * sizeof(char *), &(*param)[0], NULL);
1198 if (err != CL_SUCCESS) {
1205 // Specialized GetInfoHelper for STRING_CLASS params
1206 template <typename Func>
1207 inline cl_int getInfoHelper(Func f, cl_uint name, STRING_CLASS* param, long)
1209 #if defined(__NO_STD_VECTOR) || defined(__NO_STD_STRING)
1211 cl_int err = f(name, 0, NULL, &required);
1212 if (err != CL_SUCCESS) {
1216 char* value = (char*)alloca(required);
1217 err = f(name, required, value, NULL);
1218 if (err != CL_SUCCESS) {
1226 cl_int err = f(name, 0, NULL, &required);
1227 if (err != CL_SUCCESS) {
1231 // std::string has a constant data member
1232 // a char vector does not
1233 VECTOR_CLASS<char> value(required);
1234 err = f(name, required, value.data(), NULL);
1235 if (err != CL_SUCCESS) {
1239 param->assign(value.begin(), value.end());
1245 // Specialized GetInfoHelper for cl::size_t params
1246 template <typename Func, ::size_t N>
1247 inline cl_int getInfoHelper(Func f, cl_uint name, size_t<N>* param, long)
1250 cl_int err = f(name, 0, NULL, &required);
1251 if (err != CL_SUCCESS) {
1255 ::size_t* value = (::size_t*) alloca(required);
1256 err = f(name, required, value, NULL);
1257 if (err != CL_SUCCESS) {
1261 for(int i = 0; i < N; ++i) {
1262 (*param)[i] = value[i];
1268 template<typename T> struct ReferenceHandler;
1270 /* Specialization for reference-counted types. This depends on the
1271 * existence of Wrapper<T>::cl_type, and none of the other types having the
1272 * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1273 * does not work, because when using a derived type (e.g. Context) the generic
1274 * template will provide a better match.
1276 template<typename Func, typename T>
1277 inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0)
1279 typename T::cl_type value;
1280 cl_int err = f(name, sizeof(value), &value, NULL);
1281 if (err != CL_SUCCESS) {
1287 err = param->retain();
1288 if (err != CL_SUCCESS) {
1295 #define __PARAM_NAME_INFO_1_0(F) \
1296 F(cl_platform_info, CL_PLATFORM_PROFILE, STRING_CLASS) \
1297 F(cl_platform_info, CL_PLATFORM_VERSION, STRING_CLASS) \
1298 F(cl_platform_info, CL_PLATFORM_NAME, STRING_CLASS) \
1299 F(cl_platform_info, CL_PLATFORM_VENDOR, STRING_CLASS) \
1300 F(cl_platform_info, CL_PLATFORM_EXTENSIONS, STRING_CLASS) \
1302 F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
1303 F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
1304 F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
1305 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
1306 F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, ::size_t) \
1307 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, VECTOR_CLASS< ::size_t>) \
1308 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
1309 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
1310 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
1311 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
1312 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
1313 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
1314 F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
1315 F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \
1316 F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
1317 F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
1318 F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
1319 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, ::size_t) \
1320 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, ::size_t) \
1321 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, ::size_t) \
1322 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, ::size_t) \
1323 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, ::size_t) \
1324 F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \
1325 F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, ::size_t) \
1326 F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
1327 F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
1328 F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
1329 F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
1330 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
1331 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
1332 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
1333 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
1334 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
1335 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
1336 F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
1337 F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
1338 F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
1339 F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, ::size_t) \
1340 F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
1341 F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
1342 F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
1343 F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
1344 F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties) \
1345 F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
1346 F(cl_device_info, CL_DEVICE_NAME, STRING_CLASS) \
1347 F(cl_device_info, CL_DEVICE_VENDOR, STRING_CLASS) \
1348 F(cl_device_info, CL_DRIVER_VERSION, STRING_CLASS) \
1349 F(cl_device_info, CL_DEVICE_PROFILE, STRING_CLASS) \
1350 F(cl_device_info, CL_DEVICE_VERSION, STRING_CLASS) \
1351 F(cl_device_info, CL_DEVICE_EXTENSIONS, STRING_CLASS) \
1353 F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
1354 F(cl_context_info, CL_CONTEXT_DEVICES, VECTOR_CLASS<Device>) \
1355 F(cl_context_info, CL_CONTEXT_PROPERTIES, VECTOR_CLASS<cl_context_properties>) \
1357 F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
1358 F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
1359 F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
1360 F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \
1362 F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
1363 F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
1364 F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
1365 F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
1367 F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
1368 F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
1369 F(cl_mem_info, CL_MEM_SIZE, ::size_t) \
1370 F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
1371 F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
1372 F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
1373 F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
1375 F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
1376 F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, ::size_t) \
1377 F(cl_image_info, CL_IMAGE_ROW_PITCH, ::size_t) \
1378 F(cl_image_info, CL_IMAGE_SLICE_PITCH, ::size_t) \
1379 F(cl_image_info, CL_IMAGE_WIDTH, ::size_t) \
1380 F(cl_image_info, CL_IMAGE_HEIGHT, ::size_t) \
1381 F(cl_image_info, CL_IMAGE_DEPTH, ::size_t) \
1383 F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
1384 F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
1385 F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \
1386 F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \
1387 F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \
1389 F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
1390 F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
1391 F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
1392 F(cl_program_info, CL_PROGRAM_DEVICES, VECTOR_CLASS<Device>) \
1393 F(cl_program_info, CL_PROGRAM_SOURCE, STRING_CLASS) \
1394 F(cl_program_info, CL_PROGRAM_BINARY_SIZES, VECTOR_CLASS< ::size_t>) \
1395 F(cl_program_info, CL_PROGRAM_BINARIES, VECTOR_CLASS<char *>) \
1397 F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
1398 F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, STRING_CLASS) \
1399 F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, STRING_CLASS) \
1401 F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, STRING_CLASS) \
1402 F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
1403 F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
1404 F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
1405 F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
1407 F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, ::size_t) \
1408 F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::size_t<3>) \
1409 F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
1411 F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
1412 F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
1413 F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
1414 F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
1416 #if defined(CL_VERSION_1_1)
1417 #define __PARAM_NAME_INFO_1_1(F) \
1418 F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
1419 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
1420 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
1421 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
1422 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
1423 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
1424 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
1425 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
1426 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
1427 F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
1428 F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
1429 F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) \
1430 F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, STRING_CLASS) \
1432 F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
1433 F(cl_mem_info, CL_MEM_OFFSET, ::size_t) \
1435 F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, ::size_t) \
1436 F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
1438 F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
1439 #endif // CL_VERSION_1_1
1442 #if defined(CL_VERSION_1_2)
1443 #define __PARAM_NAME_INFO_1_2(F) \
1444 F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer) \
1446 F(cl_program_info, CL_PROGRAM_NUM_KERNELS, ::size_t) \
1447 F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, STRING_CLASS) \
1449 F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \
1451 F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, STRING_CLASS) \
1453 F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \
1454 F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \
1455 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, STRING_CLASS) \
1456 F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, STRING_CLASS) \
1457 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \
1459 F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl_device_id) \
1460 F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, VECTOR_CLASS<cl_device_partition_property>) \
1461 F(cl_device_info, CL_DEVICE_PARTITION_TYPE, VECTOR_CLASS<cl_device_partition_property>) \
1462 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \
1463 F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, ::size_t) \
1464 F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \
1465 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, STRING_CLASS)
1466 #endif // #if defined(CL_VERSION_1_2)
1468 #if defined(USE_CL_DEVICE_FISSION)
1469 #define __PARAM_NAME_DEVICE_FISSION(F) \
1470 F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
1471 F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \
1472 F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \
1473 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
1474 F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, VECTOR_CLASS<cl_device_partition_property_ext>)
1475 #endif // USE_CL_DEVICE_FISSION
1477 template <typename enum_type, cl_int Name>
1478 struct param_traits {};
1480 #define __CL_DECLARE_PARAM_TRAITS(token, param_name, T) \
1483 struct param_traits<detail:: token,param_name> \
1485 enum { value = param_name }; \
1486 typedef T param_type; \
1489 __PARAM_NAME_INFO_1_0(__CL_DECLARE_PARAM_TRAITS)
1490 #if defined(CL_VERSION_1_1)
1491 __PARAM_NAME_INFO_1_1(__CL_DECLARE_PARAM_TRAITS)
1492 #endif // CL_VERSION_1_1
1493 #if defined(CL_VERSION_1_2)
1494 __PARAM_NAME_INFO_1_2(__CL_DECLARE_PARAM_TRAITS)
1495 #endif // CL_VERSION_1_1
1497 #if defined(USE_CL_DEVICE_FISSION)
1498 __PARAM_NAME_DEVICE_FISSION(__CL_DECLARE_PARAM_TRAITS);
1499 #endif // USE_CL_DEVICE_FISSION
1501 #ifdef CL_PLATFORM_ICD_SUFFIX_KHR
1502 __CL_DECLARE_PARAM_TRAITS(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, STRING_CLASS)
1505 #ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
1506 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong)
1509 #ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
1510 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, VECTOR_CLASS< ::size_t>)
1512 #ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
1513 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint)
1515 #ifdef CL_DEVICE_SIMD_WIDTH_AMD
1516 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint)
1518 #ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD
1519 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint)
1521 #ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD
1522 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint)
1524 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
1525 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint)
1527 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
1528 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint)
1530 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
1531 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint)
1533 #ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
1534 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint)
1536 #ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
1537 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint)
1540 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
1541 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint)
1543 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV
1544 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint)
1546 #ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV
1547 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint)
1549 #ifdef CL_DEVICE_WARP_SIZE_NV
1550 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint)
1552 #ifdef CL_DEVICE_GPU_OVERLAP_NV
1553 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool)
1555 #ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV
1556 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool)
1558 #ifdef CL_DEVICE_INTEGRATED_MEMORY_NV
1559 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool)
1562 // Convenience functions
1564 template <typename Func, typename T>
1566 getInfo(Func f, cl_uint name, T* param)
1568 return getInfoHelper(f, name, param, 0);
1571 template <typename Func, typename Arg0>
1572 struct GetInfoFunctor0
1574 Func f_; const Arg0& arg0_;
1576 cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
1577 { return f_(arg0_, param, size, value, size_ret); }
1580 template <typename Func, typename Arg0, typename Arg1>
1581 struct GetInfoFunctor1
1583 Func f_; const Arg0& arg0_; const Arg1& arg1_;
1585 cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
1586 { return f_(arg0_, arg1_, param, size, value, size_ret); }
1589 template <typename Func, typename Arg0, typename T>
1591 getInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
1593 GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
1594 return getInfoHelper(f0, name, param, 0);
1597 template <typename Func, typename Arg0, typename Arg1, typename T>
1599 getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
1601 GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
1602 return getInfoHelper(f0, name, param, 0);
1605 template<typename T>
1606 struct ReferenceHandler
1609 #if defined(CL_VERSION_1_2)
1611 * OpenCL 1.2 devices do have retain/release.
1614 struct ReferenceHandler<cl_device_id>
1617 * Retain the device.
1618 * \param device A valid device created using createSubDevices
1620 * CL_SUCCESS if the function executed successfully.
1621 * CL_INVALID_DEVICE if device was not a valid subdevice
1622 * CL_OUT_OF_RESOURCES
1623 * CL_OUT_OF_HOST_MEMORY
1625 static cl_int retain(cl_device_id device)
1626 { return ::clRetainDevice(device); }
1628 * Retain the device.
1629 * \param device A valid device created using createSubDevices
1631 * CL_SUCCESS if the function executed successfully.
1632 * CL_INVALID_DEVICE if device was not a valid subdevice
1633 * CL_OUT_OF_RESOURCES
1634 * CL_OUT_OF_HOST_MEMORY
1636 static cl_int release(cl_device_id device)
1637 { return ::clReleaseDevice(device); }
1639 #else // #if defined(CL_VERSION_1_2)
1641 * OpenCL 1.1 devices do not have retain/release.
1644 struct ReferenceHandler<cl_device_id>
1646 // cl_device_id does not have retain().
1647 static cl_int retain(cl_device_id)
1648 { return CL_SUCCESS; }
1649 // cl_device_id does not have release().
1650 static cl_int release(cl_device_id)
1651 { return CL_SUCCESS; }
1653 #endif // #if defined(CL_VERSION_1_2)
1656 struct ReferenceHandler<cl_platform_id>
1658 // cl_platform_id does not have retain().
1659 static cl_int retain(cl_platform_id)
1660 { return CL_SUCCESS; }
1661 // cl_platform_id does not have release().
1662 static cl_int release(cl_platform_id)
1663 { return CL_SUCCESS; }
1667 struct ReferenceHandler<cl_context>
1669 static cl_int retain(cl_context context)
1670 { return ::clRetainContext(context); }
1671 static cl_int release(cl_context context)
1672 { return ::clReleaseContext(context); }
1676 struct ReferenceHandler<cl_command_queue>
1678 static cl_int retain(cl_command_queue queue)
1679 { return ::clRetainCommandQueue(queue); }
1680 static cl_int release(cl_command_queue queue)
1681 { return ::clReleaseCommandQueue(queue); }
1685 struct ReferenceHandler<cl_mem>
1687 static cl_int retain(cl_mem memory)
1688 { return ::clRetainMemObject(memory); }
1689 static cl_int release(cl_mem memory)
1690 { return ::clReleaseMemObject(memory); }
1694 struct ReferenceHandler<cl_sampler>
1696 static cl_int retain(cl_sampler sampler)
1697 { return ::clRetainSampler(sampler); }
1698 static cl_int release(cl_sampler sampler)
1699 { return ::clReleaseSampler(sampler); }
1703 struct ReferenceHandler<cl_program>
1705 static cl_int retain(cl_program program)
1706 { return ::clRetainProgram(program); }
1707 static cl_int release(cl_program program)
1708 { return ::clReleaseProgram(program); }
1712 struct ReferenceHandler<cl_kernel>
1714 static cl_int retain(cl_kernel kernel)
1715 { return ::clRetainKernel(kernel); }
1716 static cl_int release(cl_kernel kernel)
1717 { return ::clReleaseKernel(kernel); }
1721 struct ReferenceHandler<cl_event>
1723 static cl_int retain(cl_event event)
1724 { return ::clRetainEvent(event); }
1725 static cl_int release(cl_event event)
1726 { return ::clReleaseEvent(event); }
1730 // Extracts version number with major in the upper 16 bits, minor in the lower 16
1731 static cl_uint getVersion(const char *versionInfo)
1733 int highVersion = 0;
1736 while(versionInfo[index] != '.' ) {
1738 highVersion += versionInfo[index]-'0';
1742 while(versionInfo[index] != ' ' && versionInfo[index] != '\0') {
1744 lowVersion += versionInfo[index]-'0';
1747 return (highVersion << 16) | lowVersion;
1750 static cl_uint getPlatformVersion(cl_platform_id platform)
1753 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size);
1754 char *versionInfo = (char *) alloca(size);
1755 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, &versionInfo[0], &size);
1756 return getVersion(versionInfo);
1759 static cl_uint getDevicePlatformVersion(cl_device_id device)
1761 cl_platform_id platform;
1762 clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL);
1763 return getPlatformVersion(platform);
1766 #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
1767 static cl_uint getContextPlatformVersion(cl_context context)
1769 // The platform cannot be queried directly, so we first have to grab a
1770 // device and obtain its context
1772 clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size);
1775 cl_device_id *devices = (cl_device_id *) alloca(size);
1776 clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices, NULL);
1777 return getDevicePlatformVersion(devices[0]);
1779 #endif // #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
1781 template <typename T>
1791 Wrapper() : object_(NULL) { }
1793 Wrapper(const cl_type &obj) : object_(obj) { }
1797 if (object_ != NULL) { release(); }
1800 Wrapper(const Wrapper<cl_type>& rhs)
1802 object_ = rhs.object_;
1803 if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); }
1806 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
1807 Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT
1809 object_ = rhs.object_;
1814 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
1817 if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
1818 object_ = rhs.object_;
1819 if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); }
1824 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
1825 Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
1828 if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
1829 object_ = rhs.object_;
1836 Wrapper<cl_type>& operator = (const cl_type &rhs)
1838 if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
1843 cl_type operator ()() const { return object_; }
1845 cl_type& operator ()() { return object_; }
1848 template<typename Func, typename U>
1849 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
1851 cl_int retain() const
1853 return ReferenceHandler<cl_type>::retain(object_);
1856 cl_int release() const
1858 return ReferenceHandler<cl_type>::release(object_);
1863 class Wrapper<cl_device_id>
1866 typedef cl_device_id cl_type;
1870 bool referenceCountable_;
1872 static bool isReferenceCountable(cl_device_id device)
1874 bool retVal = false;
1875 if (device != NULL) {
1876 int version = getDevicePlatformVersion(device);
1877 if(version > ((1 << 16) + 1)) {
1885 Wrapper() : object_(NULL), referenceCountable_(false)
1889 Wrapper(const cl_type &obj) : object_(obj), referenceCountable_(false)
1891 referenceCountable_ = isReferenceCountable(obj);
1896 if (object_ != NULL) { release(); }
1899 Wrapper(const Wrapper<cl_type>& rhs)
1901 object_ = rhs.object_;
1902 referenceCountable_ = isReferenceCountable(object_);
1903 if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); }
1906 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
1907 Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT
1909 object_ = rhs.object_;
1910 referenceCountable_ = rhs.referenceCountable_;
1912 rhs.referenceCountable_ = false;
1916 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
1919 if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
1920 object_ = rhs.object_;
1921 referenceCountable_ = rhs.referenceCountable_;
1922 if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); }
1927 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
1928 Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
1931 if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
1932 object_ = rhs.object_;
1933 referenceCountable_ = rhs.referenceCountable_;
1935 rhs.referenceCountable_ = false;
1941 Wrapper<cl_type>& operator = (const cl_type &rhs)
1943 if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
1945 referenceCountable_ = isReferenceCountable(object_);
1949 cl_type operator ()() const { return object_; }
1951 cl_type& operator ()() { return object_; }
1954 template<typename Func, typename U>
1955 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
1957 template<typename Func, typename U>
1958 friend inline cl_int getInfoHelper(Func, cl_uint, VECTOR_CLASS<U>*, int, typename U::cl_type);
1960 cl_int retain() const
1962 if( referenceCountable_ ) {
1963 return ReferenceHandler<cl_type>::retain(object_);
1970 cl_int release() const
1972 if( referenceCountable_ ) {
1973 return ReferenceHandler<cl_type>::release(object_);
1981 } // namespace detail
1984 /*! \stuct ImageFormat
1985 * \brief Adds constructors and member functions for cl_image_format.
1987 * \see cl_image_format
1989 struct ImageFormat : public cl_image_format
1991 //! \brief Default constructor - performs no initialization.
1994 //! \brief Initializing constructor.
1995 ImageFormat(cl_channel_order order, cl_channel_type type)
1997 image_channel_order = order;
1998 image_channel_data_type = type;
2001 //! \brief Assignment operator.
2002 ImageFormat& operator = (const ImageFormat& rhs)
2005 this->image_channel_data_type = rhs.image_channel_data_type;
2006 this->image_channel_order = rhs.image_channel_order;
2012 /*! \brief Class interface for cl_device_id.
2014 * \note Copies of these objects are inexpensive, since they don't 'own'
2015 * any underlying resources or data structures.
2019 class Device : public detail::Wrapper<cl_device_id>
2022 //! \brief Default constructor - initializes to NULL.
2023 Device() : detail::Wrapper<cl_type>() { }
2025 /*! \brief Constructor from cl_device_id.
2027 * This simply copies the device ID value, which is an inexpensive operation.
2029 __CL_EXPLICIT_CONSTRUCTORS Device(const cl_device_id &device) : detail::Wrapper<cl_type>(device) { }
2031 /*! \brief Returns the first device on the default context.
2033 * \see Context::getDefault()
2035 static Device getDefault(cl_int * err = NULL);
2037 /*! \brief Assignment operator from cl_device_id.
2039 * This simply copies the device ID value, which is an inexpensive operation.
2041 Device& operator = (const cl_device_id& rhs)
2043 detail::Wrapper<cl_type>::operator=(rhs);
2047 /*! \brief Copy constructor to forward copy to the superclass correctly.
2048 * Required for MSVC.
2050 Device(const Device& dev) : detail::Wrapper<cl_type>(dev) {}
2052 /*! \brief Copy assignment to forward copy to the superclass correctly.
2053 * Required for MSVC.
2055 Device& operator = (const Device &dev)
2057 detail::Wrapper<cl_type>::operator=(dev);
2061 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
2062 /*! \brief Move constructor to forward move to the superclass correctly.
2063 * Required for MSVC.
2065 Device(Device&& dev) CL_HPP_NOEXCEPT : detail::Wrapper<cl_type>(std::move(dev)) {}
2067 /*! \brief Move assignment to forward move to the superclass correctly.
2068 * Required for MSVC.
2070 Device& operator = (Device &&dev)
2072 detail::Wrapper<cl_type>::operator=(std::move(dev));
2075 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
2077 //! \brief Wrapper for clGetDeviceInfo().
2078 template <typename T>
2079 cl_int getInfo(cl_device_info name, T* param) const
2081 return detail::errHandler(
2082 detail::getInfo(&::clGetDeviceInfo, object_, name, param),
2083 __GET_DEVICE_INFO_ERR);
2086 //! \brief Wrapper for clGetDeviceInfo() that returns by value.
2087 template <cl_int name> typename
2088 detail::param_traits<detail::cl_device_info, name>::param_type
2089 getInfo(cl_int* err = NULL) const
2091 typename detail::param_traits<
2092 detail::cl_device_info, name>::param_type param;
2093 cl_int result = getInfo(name, ¶m);
2103 #if defined(CL_VERSION_1_2)
2104 //! \brief Wrapper for clCreateSubDevicesEXT().
2105 cl_int createSubDevices(
2106 const cl_device_partition_property * properties,
2107 VECTOR_CLASS<Device>* devices)
2110 cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n);
2111 if (err != CL_SUCCESS) {
2112 return detail::errHandler(err, __CREATE_SUB_DEVICES);
2115 cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
2116 err = clCreateSubDevices(object_, properties, n, ids, NULL);
2117 if (err != CL_SUCCESS) {
2118 return detail::errHandler(err, __CREATE_SUB_DEVICES);
2121 devices->assign(&ids[0], &ids[n]);
2124 #endif // #if defined(CL_VERSION_1_2)
2127 * CL 1.1 version that uses device fission.
2129 #if defined(CL_VERSION_1_1)
2130 #if defined(USE_CL_DEVICE_FISSION)
2131 cl_int createSubDevices(
2132 const cl_device_partition_property_ext * properties,
2133 VECTOR_CLASS<Device>* devices)
2135 typedef CL_API_ENTRY cl_int
2136 ( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
2137 cl_device_id /*in_device*/,
2138 const cl_device_partition_property_ext * /* properties */,
2139 cl_uint /*num_entries*/,
2140 cl_device_id * /*out_devices*/,
2141 cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1;
2143 static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
2144 __INIT_CL_EXT_FCN_PTR(clCreateSubDevicesEXT);
2147 cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
2148 if (err != CL_SUCCESS) {
2149 return detail::errHandler(err, __CREATE_SUB_DEVICES);
2152 cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
2153 err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids, NULL);
2154 if (err != CL_SUCCESS) {
2155 return detail::errHandler(err, __CREATE_SUB_DEVICES);
2158 devices->assign(&ids[0], &ids[n]);
2161 #endif // #if defined(USE_CL_DEVICE_FISSION)
2162 #endif // #if defined(CL_VERSION_1_1)
2165 /*! \brief Class interface for cl_platform_id.
2167 * \note Copies of these objects are inexpensive, since they don't 'own'
2168 * any underlying resources or data structures.
2170 * \see cl_platform_id
2172 class Platform : public detail::Wrapper<cl_platform_id>
2175 //! \brief Default constructor - initializes to NULL.
2176 Platform() : detail::Wrapper<cl_type>() { }
2178 /*! \brief Constructor from cl_platform_id.
2180 * This simply copies the platform ID value, which is an inexpensive operation.
2182 __CL_EXPLICIT_CONSTRUCTORS Platform(const cl_platform_id &platform) : detail::Wrapper<cl_type>(platform) { }
2184 /*! \brief Assignment operator from cl_platform_id.
2186 * This simply copies the platform ID value, which is an inexpensive operation.
2188 Platform& operator = (const cl_platform_id& rhs)
2190 detail::Wrapper<cl_type>::operator=(rhs);
2194 //! \brief Wrapper for clGetPlatformInfo().
2195 cl_int getInfo(cl_platform_info name, STRING_CLASS* param) const
2197 return detail::errHandler(
2198 detail::getInfo(&::clGetPlatformInfo, object_, name, param),
2199 __GET_PLATFORM_INFO_ERR);
2202 //! \brief Wrapper for clGetPlatformInfo() that returns by value.
2203 template <cl_int name> typename
2204 detail::param_traits<detail::cl_platform_info, name>::param_type
2205 getInfo(cl_int* err = NULL) const
2207 typename detail::param_traits<
2208 detail::cl_platform_info, name>::param_type param;
2209 cl_int result = getInfo(name, ¶m);
2216 /*! \brief Gets a list of devices for this platform.
2218 * Wraps clGetDeviceIDs().
2221 cl_device_type type,
2222 VECTOR_CLASS<Device>* devices) const
2225 if( devices == NULL ) {
2226 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2228 cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
2229 if (err != CL_SUCCESS) {
2230 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2233 cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
2234 err = ::clGetDeviceIDs(object_, type, n, ids, NULL);
2235 if (err != CL_SUCCESS) {
2236 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2239 devices->assign(&ids[0], &ids[n]);
2243 #if defined(USE_DX_INTEROP)
2244 /*! \brief Get the list of available D3D10 devices.
2246 * \param d3d_device_source.
2248 * \param d3d_object.
2250 * \param d3d_device_set.
2252 * \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device
2253 * values returned in devices can be used to identify a specific OpenCL
2254 * device. If \a devices argument is NULL, this argument is ignored.
2256 * \return One of the following values:
2257 * - CL_SUCCESS if the function is executed successfully.
2259 * The application can query specific capabilities of the OpenCL device(s)
2260 * returned by cl::getDevices. This can be used by the application to
2261 * determine which device(s) to use.
2263 * \note In the case that exceptions are enabled and a return value
2264 * other than CL_SUCCESS is generated, then cl::Error exception is
2268 cl_d3d10_device_source_khr d3d_device_source,
2270 cl_d3d10_device_set_khr d3d_device_set,
2271 VECTOR_CLASS<Device>* devices) const
2273 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
2274 cl_platform_id platform,
2275 cl_d3d10_device_source_khr d3d_device_source,
2277 cl_d3d10_device_set_khr d3d_device_set,
2278 cl_uint num_entries,
2279 cl_device_id * devices,
2280 cl_uint* num_devices);
2282 if( devices == NULL ) {
2283 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2286 static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
2287 __INIT_CL_EXT_FCN_PTR_PLATFORM(object_, clGetDeviceIDsFromD3D10KHR);
2290 cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
2298 if (err != CL_SUCCESS) {
2299 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2302 cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
2303 err = pfn_clGetDeviceIDsFromD3D10KHR(
2311 if (err != CL_SUCCESS) {
2312 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2315 devices->assign(&ids[0], &ids[n]);
2320 /*! \brief Gets a list of available platforms.
2322 * Wraps clGetPlatformIDs().
2325 VECTOR_CLASS<Platform>* platforms)
2329 if( platforms == NULL ) {
2330 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
2333 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2334 if (err != CL_SUCCESS) {
2335 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2338 cl_platform_id* ids = (cl_platform_id*) alloca(
2339 n * sizeof(cl_platform_id));
2340 err = ::clGetPlatformIDs(n, ids, NULL);
2341 if (err != CL_SUCCESS) {
2342 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2345 platforms->assign(&ids[0], &ids[n]);
2349 /*! \brief Gets the first available platform.
2351 * Wraps clGetPlatformIDs(), returning the first result.
2354 Platform * platform)
2358 if( platform == NULL ) {
2359 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
2362 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2363 if (err != CL_SUCCESS) {
2364 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2367 cl_platform_id* ids = (cl_platform_id*) alloca(
2368 n * sizeof(cl_platform_id));
2369 err = ::clGetPlatformIDs(n, ids, NULL);
2370 if (err != CL_SUCCESS) {
2371 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2378 /*! \brief Gets the first available platform, returning it by value.
2380 * Wraps clGetPlatformIDs(), returning the first result.
2382 static Platform get(
2383 cl_int * errResult = NULL)
2387 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2388 if (err != CL_SUCCESS) {
2389 detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2390 if (errResult != NULL) {
2396 cl_platform_id* ids = (cl_platform_id*) alloca(
2397 n * sizeof(cl_platform_id));
2398 err = ::clGetPlatformIDs(n, ids, NULL);
2400 if (err != CL_SUCCESS) {
2401 detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2402 if (errResult != NULL) {
2409 return Platform(ids[0]);
2412 static Platform getDefault(
2413 cl_int *errResult = NULL )
2415 return get(errResult);
2419 #if defined(CL_VERSION_1_2)
2420 //! \brief Wrapper for clUnloadCompiler().
2424 return ::clUnloadPlatformCompiler(object_);
2426 #endif // #if defined(CL_VERSION_1_2)
2427 }; // class Platform
2430 * Deprecated APIs for 1.2
2432 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
2434 * Unload the OpenCL compiler.
2435 * \note Deprecated for OpenCL 1.2. Use Platform::unloadCompiler instead.
2437 inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int
2438 UnloadCompiler() CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
2442 return ::clUnloadCompiler();
2444 #endif // #if defined(CL_VERSION_1_1)
2446 /*! \brief Class interface for cl_context.
2448 * \note Copies of these objects are shallow, meaning that the copy will refer
2449 * to the same underlying cl_context as the original. For details, see
2450 * clRetainContext() and clReleaseContext().
2455 : public detail::Wrapper<cl_context>
2459 #ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED
2460 static std::atomic<int> default_initialized_;
2461 #else // !CL_HPP_CPP11_ATOMICS_SUPPORTED
2462 static volatile int default_initialized_;
2463 #endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED
2464 static Context default_;
2465 static volatile cl_int default_error_;
2467 /*! \brief Constructs a context including a list of specified devices.
2469 * Wraps clCreateContext().
2472 const VECTOR_CLASS<Device>& devices,
2473 cl_context_properties* properties = NULL,
2474 void (CL_CALLBACK * notifyFptr)(
2484 ::size_t numDevices = devices.size();
2485 cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id));
2486 for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
2487 deviceIDs[deviceIndex] = (devices[deviceIndex])();
2490 object_ = ::clCreateContext(
2491 properties, (cl_uint) numDevices,
2493 notifyFptr, data, &error);
2495 detail::errHandler(error, __CREATE_CONTEXT_ERR);
2502 const Device& device,
2503 cl_context_properties* properties = NULL,
2504 void (CL_CALLBACK * notifyFptr)(
2514 cl_device_id deviceID = device();
2516 object_ = ::clCreateContext(
2519 notifyFptr, data, &error);
2521 detail::errHandler(error, __CREATE_CONTEXT_ERR);
2527 /*! \brief Constructs a context including all or a subset of devices of a specified type.
2529 * Wraps clCreateContextFromType().
2532 cl_device_type type,
2533 cl_context_properties* properties = NULL,
2534 void (CL_CALLBACK * notifyFptr)(
2544 #if !defined(__APPLE__) && !defined(__MACOS)
2545 cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 };
2547 if (properties == NULL) {
2548 // Get a valid platform ID as we cannot send in a blank one
2549 VECTOR_CLASS<Platform> platforms;
2550 error = Platform::get(&platforms);
2551 if (error != CL_SUCCESS) {
2552 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2559 // Check the platforms we found for a device of our specified type
2560 cl_context_properties platform_id = 0;
2561 for (unsigned int i = 0; i < platforms.size(); i++) {
2563 VECTOR_CLASS<Device> devices;
2565 #if defined(__CL_ENABLE_EXCEPTIONS)
2569 error = platforms[i].getDevices(type, &devices);
2571 #if defined(__CL_ENABLE_EXCEPTIONS)
2573 // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type
2574 // We do error checking next anyway, and can throw there if needed
2577 // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND
2578 if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) {
2579 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2585 if (devices.size() > 0) {
2586 platform_id = (cl_context_properties)platforms[i]();
2591 if (platform_id == 0) {
2592 detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR);
2594 *err = CL_DEVICE_NOT_FOUND;
2599 prop[1] = platform_id;
2600 properties = &prop[0];
2603 object_ = ::clCreateContextFromType(
2604 properties, type, notifyFptr, data, &error);
2606 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2612 /*! \brief Copy constructor to forward copy to the superclass correctly.
2613 * Required for MSVC.
2615 Context(const Context& ctx) : detail::Wrapper<cl_type>(ctx) {}
2617 /*! \brief Copy assignment to forward copy to the superclass correctly.
2618 * Required for MSVC.
2620 Context& operator = (const Context &ctx)
2622 detail::Wrapper<cl_type>::operator=(ctx);
2626 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
2627 /*! \brief Move constructor to forward move to the superclass correctly.
2628 * Required for MSVC.
2630 Context(Context&& ctx) CL_HPP_NOEXCEPT : detail::Wrapper<cl_type>(std::move(ctx)) {}
2632 /*! \brief Move assignment to forward move to the superclass correctly.
2633 * Required for MSVC.
2635 Context& operator = (Context &&ctx)
2637 detail::Wrapper<cl_type>::operator=(std::move(ctx));
2640 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
2642 /*! \brief Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT.
2644 * \note All calls to this function return the same cl_context as the first.
2646 static Context getDefault(cl_int * err = NULL)
2648 int state = detail::compare_exchange(
2649 &default_initialized_,
2650 __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED);
2652 if (state & __DEFAULT_INITIALIZED) {
2654 *err = default_error_;
2659 if (state & __DEFAULT_BEING_INITIALIZED) {
2660 // Assume writes will propagate eventually...
2661 while(default_initialized_ != __DEFAULT_INITIALIZED) {
2666 *err = default_error_;
2673 CL_DEVICE_TYPE_DEFAULT,
2681 default_error_ = error;
2682 // Assume writes will propagate eventually...
2683 default_initialized_ = __DEFAULT_INITIALIZED;
2688 *err = default_error_;
2694 //! \brief Default constructor - initializes to NULL.
2695 Context() : detail::Wrapper<cl_type>() { }
2697 /*! \brief Constructor from cl_context - takes ownership.
2699 * This effectively transfers ownership of a refcount on the cl_context
2700 * into the new Context object.
2702 __CL_EXPLICIT_CONSTRUCTORS Context(const cl_context& context) : detail::Wrapper<cl_type>(context) { }
2704 /*! \brief Assignment operator from cl_context - takes ownership.
2706 * This effectively transfers ownership of a refcount on the rhs and calls
2707 * clReleaseContext() on the value previously held by this instance.
2709 Context& operator = (const cl_context& rhs)
2711 detail::Wrapper<cl_type>::operator=(rhs);
2715 //! \brief Wrapper for clGetContextInfo().
2716 template <typename T>
2717 cl_int getInfo(cl_context_info name, T* param) const
2719 return detail::errHandler(
2720 detail::getInfo(&::clGetContextInfo, object_, name, param),
2721 __GET_CONTEXT_INFO_ERR);
2724 //! \brief Wrapper for clGetContextInfo() that returns by value.
2725 template <cl_int name> typename
2726 detail::param_traits<detail::cl_context_info, name>::param_type
2727 getInfo(cl_int* err = NULL) const
2729 typename detail::param_traits<
2730 detail::cl_context_info, name>::param_type param;
2731 cl_int result = getInfo(name, ¶m);
2738 /*! \brief Gets a list of supported image formats.
2740 * Wraps clGetSupportedImageFormats().
2742 cl_int getSupportedImageFormats(
2744 cl_mem_object_type type,
2745 VECTOR_CLASS<ImageFormat>* formats) const
2753 cl_int err = ::clGetSupportedImageFormats(
2760 if (err != CL_SUCCESS) {
2761 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
2764 if (numEntries > 0) {
2765 ImageFormat* value = (ImageFormat*)
2766 alloca(numEntries * sizeof(ImageFormat));
2767 err = ::clGetSupportedImageFormats(
2772 (cl_image_format*)value,
2774 if (err != CL_SUCCESS) {
2775 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
2778 formats->assign(&value[0], &value[numEntries]);
2787 inline Device Device::getDefault(cl_int * err)
2792 Context context = Context::getDefault(&error);
2793 detail::errHandler(error, __CREATE_CONTEXT_ERR);
2795 if (error != CL_SUCCESS) {
2801 device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
2812 #ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED
2813 __declspec(selectany) std::atomic<int> Context::default_initialized_;
2814 #else // !CL_HPP_CPP11_ATOMICS_SUPPORTED
2815 __declspec(selectany) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED;
2816 #endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED
2817 __declspec(selectany) Context Context::default_;
2818 __declspec(selectany) volatile cl_int Context::default_error_ = CL_SUCCESS;
2820 #ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED
2821 __attribute__((weak)) std::atomic<int> Context::default_initialized_;
2822 #else // !CL_HPP_CPP11_ATOMICS_SUPPORTED
2823 __attribute__((weak)) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED;
2824 #endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED
2825 __attribute__((weak)) Context Context::default_;
2826 __attribute__((weak)) volatile cl_int Context::default_error_ = CL_SUCCESS;
2829 /*! \brief Class interface for cl_event.
2831 * \note Copies of these objects are shallow, meaning that the copy will refer
2832 * to the same underlying cl_event as the original. For details, see
2833 * clRetainEvent() and clReleaseEvent().
2837 class Event : public detail::Wrapper<cl_event>
2840 //! \brief Default constructor - initializes to NULL.
2841 Event() : detail::Wrapper<cl_type>() { }
2843 /*! \brief Constructor from cl_event - takes ownership.
2845 * This effectively transfers ownership of a refcount on the cl_event
2846 * into the new Event object.
2848 __CL_EXPLICIT_CONSTRUCTORS Event(const cl_event& event) : detail::Wrapper<cl_type>(event) { }
2850 /*! \brief Assignment operator from cl_event - takes ownership.
2852 * This effectively transfers ownership of a refcount on the rhs and calls
2853 * clReleaseEvent() on the value previously held by this instance.
2855 Event& operator = (const cl_event& rhs)
2857 detail::Wrapper<cl_type>::operator=(rhs);
2861 //! \brief Wrapper for clGetEventInfo().
2862 template <typename T>
2863 cl_int getInfo(cl_event_info name, T* param) const
2865 return detail::errHandler(
2866 detail::getInfo(&::clGetEventInfo, object_, name, param),
2867 __GET_EVENT_INFO_ERR);
2870 //! \brief Wrapper for clGetEventInfo() that returns by value.
2871 template <cl_int name> typename
2872 detail::param_traits<detail::cl_event_info, name>::param_type
2873 getInfo(cl_int* err = NULL) const
2875 typename detail::param_traits<
2876 detail::cl_event_info, name>::param_type param;
2877 cl_int result = getInfo(name, ¶m);
2884 //! \brief Wrapper for clGetEventProfilingInfo().
2885 template <typename T>
2886 cl_int getProfilingInfo(cl_profiling_info name, T* param) const
2888 return detail::errHandler(detail::getInfo(
2889 &::clGetEventProfilingInfo, object_, name, param),
2890 __GET_EVENT_PROFILE_INFO_ERR);
2893 //! \brief Wrapper for clGetEventProfilingInfo() that returns by value.
2894 template <cl_int name> typename
2895 detail::param_traits<detail::cl_profiling_info, name>::param_type
2896 getProfilingInfo(cl_int* err = NULL) const
2898 typename detail::param_traits<
2899 detail::cl_profiling_info, name>::param_type param;
2900 cl_int result = getProfilingInfo(name, ¶m);
2907 /*! \brief Blocks the calling thread until this event completes.
2909 * Wraps clWaitForEvents().
2913 return detail::errHandler(
2914 ::clWaitForEvents(1, &object_),
2915 __WAIT_FOR_EVENTS_ERR);
2918 #if defined(CL_VERSION_1_1)
2919 /*! \brief Registers a user callback function for a specific command execution status.
2921 * Wraps clSetEventCallback().
2925 void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
2926 void * user_data = NULL)
2928 return detail::errHandler(
2929 ::clSetEventCallback(
2934 __SET_EVENT_CALLBACK_ERR);
2938 /*! \brief Blocks the calling thread until every event specified is complete.
2940 * Wraps clWaitForEvents().
2943 waitForEvents(const VECTOR_CLASS<Event>& events)
2945 return detail::errHandler(
2947 (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
2948 __WAIT_FOR_EVENTS_ERR);
2952 #if defined(CL_VERSION_1_1)
2953 /*! \brief Class interface for user events (a subset of cl_event's).
2955 * See Event for details about copy semantics, etc.
2957 class UserEvent : public Event
2960 /*! \brief Constructs a user event on a given context.
2962 * Wraps clCreateUserEvent().
2965 const Context& context,
2966 cl_int * err = NULL)
2969 object_ = ::clCreateUserEvent(
2973 detail::errHandler(error, __CREATE_USER_EVENT_ERR);
2979 //! \brief Default constructor - initializes to NULL.
2980 UserEvent() : Event() { }
2982 /*! \brief Sets the execution status of a user event object.
2984 * Wraps clSetUserEventStatus().
2986 cl_int setStatus(cl_int status)
2988 return detail::errHandler(
2989 ::clSetUserEventStatus(object_,status),
2990 __SET_USER_EVENT_STATUS_ERR);
2995 /*! \brief Blocks the calling thread until every event specified is complete.
2997 * Wraps clWaitForEvents().
2999 inline static cl_int
3000 WaitForEvents(const VECTOR_CLASS<Event>& events)
3002 return detail::errHandler(
3004 (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3005 __WAIT_FOR_EVENTS_ERR);
3008 /*! \brief Class interface for cl_mem.
3010 * \note Copies of these objects are shallow, meaning that the copy will refer
3011 * to the same underlying cl_mem as the original. For details, see
3012 * clRetainMemObject() and clReleaseMemObject().
3016 class Memory : public detail::Wrapper<cl_mem>
3019 //! \brief Default constructor - initializes to NULL.
3020 Memory() : detail::Wrapper<cl_type>() { }
3022 /*! \brief Constructor from cl_mem - takes ownership.
3024 * This effectively transfers ownership of a refcount on the cl_mem
3025 * into the new Memory object.
3027 __CL_EXPLICIT_CONSTRUCTORS Memory(const cl_mem& memory) : detail::Wrapper<cl_type>(memory) { }
3029 /*! \brief Assignment operator from cl_mem - takes ownership.
3031 * This effectively transfers ownership of a refcount on the rhs and calls
3032 * clReleaseMemObject() on the value previously held by this instance.
3034 Memory& operator = (const cl_mem& rhs)
3036 detail::Wrapper<cl_type>::operator=(rhs);
3040 /*! \brief Copy constructor to forward copy to the superclass correctly.
3041 * Required for MSVC.
3043 Memory(const Memory& mem) : detail::Wrapper<cl_type>(mem) {}
3045 /*! \brief Copy assignment to forward copy to the superclass correctly.
3046 * Required for MSVC.
3048 Memory& operator = (const Memory &mem)
3050 detail::Wrapper<cl_type>::operator=(mem);
3054 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
3055 /*! \brief Move constructor to forward move to the superclass correctly.
3056 * Required for MSVC.
3058 Memory(Memory&& mem) CL_HPP_NOEXCEPT : detail::Wrapper<cl_type>(std::move(mem)) {}
3060 /*! \brief Move assignment to forward move to the superclass correctly.
3061 * Required for MSVC.
3063 Memory& operator = (Memory &&mem)
3065 detail::Wrapper<cl_type>::operator=(std::move(mem));
3068 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
3070 //! \brief Wrapper for clGetMemObjectInfo().
3071 template <typename T>
3072 cl_int getInfo(cl_mem_info name, T* param) const
3074 return detail::errHandler(
3075 detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
3076 __GET_MEM_OBJECT_INFO_ERR);
3079 //! \brief Wrapper for clGetMemObjectInfo() that returns by value.
3080 template <cl_int name> typename
3081 detail::param_traits<detail::cl_mem_info, name>::param_type
3082 getInfo(cl_int* err = NULL) const
3084 typename detail::param_traits<
3085 detail::cl_mem_info, name>::param_type param;
3086 cl_int result = getInfo(name, ¶m);
3093 #if defined(CL_VERSION_1_1)
3094 /*! \brief Registers a callback function to be called when the memory object
3095 * is no longer needed.
3097 * Wraps clSetMemObjectDestructorCallback().
3099 * Repeated calls to this function, for a given cl_mem value, will append
3100 * to the list of functions called (in reverse order) when memory object's
3101 * resources are freed and the memory object is deleted.
3104 * The registered callbacks are associated with the underlying cl_mem
3105 * value - not the Memory class instance.
3107 cl_int setDestructorCallback(
3108 void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
3109 void * user_data = NULL)
3111 return detail::errHandler(
3112 ::clSetMemObjectDestructorCallback(
3116 __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
3122 // Pre-declare copy functions
3124 template< typename IteratorType >
3125 cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3126 template< typename IteratorType >
3127 cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3128 template< typename IteratorType >
3129 cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3130 template< typename IteratorType >
3131 cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3134 /*! \brief Class interface for Buffer Memory Objects.
3136 * See Memory for details about copy semantics, etc.
3140 class Buffer : public Memory
3144 /*! \brief Constructs a Buffer in a specified context.
3146 * Wraps clCreateBuffer().
3148 * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
3149 * specified. Note alignment & exclusivity requirements.
3152 const Context& context,
3155 void* host_ptr = NULL,
3159 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3161 detail::errHandler(error, __CREATE_BUFFER_ERR);
3167 /*! \brief Constructs a Buffer in the default context.
3169 * Wraps clCreateBuffer().
3171 * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
3172 * specified. Note alignment & exclusivity requirements.
3174 * \see Context::getDefault()
3179 void* host_ptr = NULL,
3184 Context context = Context::getDefault(err);
3186 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3188 detail::errHandler(error, __CREATE_BUFFER_ERR);
3195 * \brief Construct a Buffer from a host container via iterators.
3196 * IteratorType must be random access.
3197 * If useHostPtr is specified iterators must represent contiguous data.
3199 template< typename IteratorType >
3201 IteratorType startIterator,
3202 IteratorType endIterator,
3204 bool useHostPtr = false,
3207 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
3210 cl_mem_flags flags = 0;
3212 flags |= CL_MEM_READ_ONLY;
3215 flags |= CL_MEM_READ_WRITE;
3218 flags |= CL_MEM_USE_HOST_PTR;
3221 ::size_t size = sizeof(DataType)*(endIterator - startIterator);
3223 Context context = Context::getDefault(err);
3226 object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
3228 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
3231 detail::errHandler(error, __CREATE_BUFFER_ERR);
3237 error = cl::copy(startIterator, endIterator, *this);
3238 detail::errHandler(error, __CREATE_BUFFER_ERR);
3246 * \brief Construct a Buffer from a host container via iterators using a specified context.
3247 * IteratorType must be random access.
3248 * If useHostPtr is specified iterators must represent contiguous data.
3250 template< typename IteratorType >
3251 Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator,
3252 bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
3255 * \brief Construct a Buffer from a host container via iterators using a specified queue.
3256 * If useHostPtr is specified iterators must represent contiguous data.
3258 template< typename IteratorType >
3259 Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator,
3260 bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
3262 //! \brief Default constructor - initializes to NULL.
3263 Buffer() : Memory() { }
3265 /*! \brief Constructor from cl_mem - takes ownership.
3267 * See Memory for further details.
3269 __CL_EXPLICIT_CONSTRUCTORS Buffer(const cl_mem& buffer) : Memory(buffer) { }
3271 /*! \brief Assignment from cl_mem - performs shallow copy.
3273 * See Memory for further details.
3275 Buffer& operator = (const cl_mem& rhs)
3277 Memory::operator=(rhs);
3281 /*! \brief Copy constructor to forward copy to the superclass correctly.
3282 * Required for MSVC.
3284 Buffer(const Buffer& buf) : Memory(buf) {}
3286 /*! \brief Copy assignment to forward copy to the superclass correctly.
3287 * Required for MSVC.
3289 Buffer& operator = (const Buffer &buf)
3291 Memory::operator=(buf);
3295 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
3296 /*! \brief Move constructor to forward move to the superclass correctly.
3297 * Required for MSVC.
3299 Buffer(Buffer&& buf) CL_HPP_NOEXCEPT : Memory(std::move(buf)) {}
3301 /*! \brief Move assignment to forward move to the superclass correctly.
3302 * Required for MSVC.
3304 Buffer& operator = (Buffer &&buf)
3306 Memory::operator=(std::move(buf));
3309 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
3311 #if defined(CL_VERSION_1_1)
3312 /*! \brief Creates a new buffer object from this.
3314 * Wraps clCreateSubBuffer().
3316 Buffer createSubBuffer(
3318 cl_buffer_create_type buffer_create_type,
3319 const void * buffer_create_info,
3320 cl_int * err = NULL)
3324 result.object_ = ::clCreateSubBuffer(
3331 detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
3341 #if defined (USE_DX_INTEROP)
3342 /*! \brief Class interface for creating OpenCL buffers from ID3D10Buffer's.
3344 * This is provided to facilitate interoperability with Direct3D.
3346 * See Memory for details about copy semantics, etc.
3350 class BufferD3D10 : public Buffer
3353 typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
3354 cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
3355 cl_int* errcode_ret);
3357 /*! \brief Constructs a BufferD3D10, in a specified context, from a
3358 * given ID3D10Buffer.
3360 * Wraps clCreateFromD3D10BufferKHR().
3363 const Context& context,
3365 ID3D10Buffer* bufobj,
3366 cl_int * err = NULL)
3368 static PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR = NULL;
3370 #if defined(CL_VERSION_1_2)
3371 vector<cl_context_properties> props = context.getInfo<CL_CONTEXT_PROPERTIES>();
3372 cl_platform platform = -1;
3373 for( int i = 0; i < props.size(); ++i ) {
3374 if( props[i] == CL_CONTEXT_PLATFORM ) {
3375 platform = props[i+1];
3378 __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clCreateFromD3D10BufferKHR);
3380 #if defined(CL_VERSION_1_1)
3381 __INIT_CL_EXT_FCN_PTR(clCreateFromD3D10BufferKHR);
3385 object_ = pfn_clCreateFromD3D10BufferKHR(
3391 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
3397 //! \brief Default constructor - initializes to NULL.
3398 BufferD3D10() : Buffer() { }
3400 /*! \brief Constructor from cl_mem - takes ownership.
3402 * See Memory for further details.
3404 __CL_EXPLICIT_CONSTRUCTORS BufferD3D10(const cl_mem& buffer) : Buffer(buffer) { }
3406 /*! \brief Assignment from cl_mem - performs shallow copy.
3408 * See Memory for further details.
3410 BufferD3D10& operator = (const cl_mem& rhs)
3412 Buffer::operator=(rhs);
3416 /*! \brief Copy constructor to forward copy to the superclass correctly.
3417 * Required for MSVC.
3419 BufferD3D10(const BufferD3D10& buf) : Buffer(buf) {}
3421 /*! \brief Copy assignment to forward copy to the superclass correctly.
3422 * Required for MSVC.
3424 BufferD3D10& operator = (const BufferD3D10 &buf)
3426 Buffer::operator=(buf);
3430 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
3431 /*! \brief Move constructor to forward move to the superclass correctly.
3432 * Required for MSVC.
3434 BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT : Buffer(std::move(buf)) {}
3436 /*! \brief Move assignment to forward move to the superclass correctly.
3437 * Required for MSVC.
3439 BufferD3D10& operator = (BufferD3D10 &&buf)
3441 Buffer::operator=(std::move(buf));
3444 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
3448 /*! \brief Class interface for GL Buffer Memory Objects.
3450 * This is provided to facilitate interoperability with OpenGL.
3452 * See Memory for details about copy semantics, etc.
3456 class BufferGL : public Buffer
3459 /*! \brief Constructs a BufferGL in a specified context, from a given
3462 * Wraps clCreateFromGLBuffer().
3465 const Context& context,
3468 cl_int * err = NULL)
3471 object_ = ::clCreateFromGLBuffer(
3477 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
3483 //! \brief Default constructor - initializes to NULL.
3484 BufferGL() : Buffer() { }
3486 /*! \brief Constructor from cl_mem - takes ownership.
3488 * See Memory for further details.
3490 __CL_EXPLICIT_CONSTRUCTORS BufferGL(const cl_mem& buffer) : Buffer(buffer) { }
3492 /*! \brief Assignment from cl_mem - performs shallow copy.
3494 * See Memory for further details.
3496 BufferGL& operator = (const cl_mem& rhs)
3498 Buffer::operator=(rhs);
3502 /*! \brief Copy constructor to forward copy to the superclass correctly.
3503 * Required for MSVC.
3505 BufferGL(const BufferGL& buf) : Buffer(buf) {}
3507 /*! \brief Copy assignment to forward copy to the superclass correctly.
3508 * Required for MSVC.
3510 BufferGL& operator = (const BufferGL &buf)
3512 Buffer::operator=(buf);
3516 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
3517 /*! \brief Move constructor to forward move to the superclass correctly.
3518 * Required for MSVC.
3520 BufferGL(BufferGL&& buf) CL_HPP_NOEXCEPT : Buffer(std::move(buf)) {}
3522 /*! \brief Move assignment to forward move to the superclass correctly.
3523 * Required for MSVC.
3525 BufferGL& operator = (BufferGL &&buf)
3527 Buffer::operator=(std::move(buf));
3530 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
3532 //! \brief Wrapper for clGetGLObjectInfo().
3533 cl_int getObjectInfo(
3534 cl_gl_object_type *type,
3535 cl_GLuint * gl_object_name)
3537 return detail::errHandler(
3538 ::clGetGLObjectInfo(object_,type,gl_object_name),
3539 __GET_GL_OBJECT_INFO_ERR);
3543 /*! \brief C++ base class for Image Memory objects.
3545 * See Memory for details about copy semantics, etc.
3549 class Image : public Memory
3552 //! \brief Default constructor - initializes to NULL.
3553 Image() : Memory() { }
3555 /*! \brief Constructor from cl_mem - takes ownership.
3557 * See Memory for further details.
3559 __CL_EXPLICIT_CONSTRUCTORS Image(const cl_mem& image) : Memory(image) { }
3561 /*! \brief Assignment from cl_mem - performs shallow copy.
3563 * See Memory for further details.
3565 Image& operator = (const cl_mem& rhs)
3567 Memory::operator=(rhs);
3571 /*! \brief Copy constructor to forward copy to the superclass correctly.
3572 * Required for MSVC.
3574 Image(const Image& img) : Memory(img) {}
3576 /*! \brief Copy assignment to forward copy to the superclass correctly.
3577 * Required for MSVC.
3579 Image& operator = (const Image &img)
3581 Memory::operator=(img);
3585 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
3586 /*! \brief Move constructor to forward move to the superclass correctly.
3587 * Required for MSVC.
3589 Image(Image&& img) CL_HPP_NOEXCEPT : Memory(std::move(img)) {}
3591 /*! \brief Move assignment to forward move to the superclass correctly.
3592 * Required for MSVC.
3594 Image& operator = (Image &&img)
3596 Memory::operator=(std::move(img));
3599 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
3602 //! \brief Wrapper for clGetImageInfo().
3603 template <typename T>
3604 cl_int getImageInfo(cl_image_info name, T* param) const
3606 return detail::errHandler(
3607 detail::getInfo(&::clGetImageInfo, object_, name, param),
3608 __GET_IMAGE_INFO_ERR);
3611 //! \brief Wrapper for clGetImageInfo() that returns by value.
3612 template <cl_int name> typename
3613 detail::param_traits<detail::cl_image_info, name>::param_type
3614 getImageInfo(cl_int* err = NULL) const
3616 typename detail::param_traits<
3617 detail::cl_image_info, name>::param_type param;
3618 cl_int result = getImageInfo(name, ¶m);
3626 #if defined(CL_VERSION_1_2)
3627 /*! \brief Class interface for 1D Image Memory objects.
3629 * See Memory for details about copy semantics, etc.
3633 class Image1D : public Image
3636 /*! \brief Constructs a 1D Image in a specified context.
3638 * Wraps clCreateImage().
3641 const Context& context,
3645 void* host_ptr = NULL,
3649 cl_image_desc desc =
3651 CL_MEM_OBJECT_IMAGE1D,
3653 0, 0, 0, 0, 0, 0, 0, 0
3655 object_ = ::clCreateImage(
3663 detail::errHandler(error, __CREATE_IMAGE_ERR);
3669 //! \brief Default constructor - initializes to NULL.
3672 /*! \brief Constructor from cl_mem - takes ownership.
3674 * See Memory for further details.
3676 __CL_EXPLICIT_CONSTRUCTORS Image1D(const cl_mem& image1D) : Image(image1D) { }
3678 /*! \brief Assignment from cl_mem - performs shallow copy.
3680 * See Memory for further details.
3682 Image1D& operator = (const cl_mem& rhs)
3684 Image::operator=(rhs);
3688 /*! \brief Copy constructor to forward copy to the superclass correctly.
3689 * Required for MSVC.
3691 Image1D(const Image1D& img) : Image(img) {}
3693 /*! \brief Copy assignment to forward copy to the superclass correctly.
3694 * Required for MSVC.
3696 Image1D& operator = (const Image1D &img)
3698 Image::operator=(img);
3702 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
3703 /*! \brief Move constructor to forward move to the superclass correctly.
3704 * Required for MSVC.
3706 Image1D(Image1D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {}
3708 /*! \brief Move assignment to forward move to the superclass correctly.
3709 * Required for MSVC.
3711 Image1D& operator = (Image1D &&img)
3713 Image::operator=(std::move(img));
3716 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
3719 /*! \class Image1DBuffer
3720 * \brief Image interface for 1D buffer images.
3722 class Image1DBuffer : public Image
3726 const Context& context,
3730 const Buffer &buffer,
3734 cl_image_desc desc =
3736 CL_MEM_OBJECT_IMAGE1D_BUFFER,
3738 0, 0, 0, 0, 0, 0, 0,
3741 object_ = ::clCreateImage(
3749 detail::errHandler(error, __CREATE_IMAGE_ERR);
3757 __CL_EXPLICIT_CONSTRUCTORS Image1DBuffer(const cl_mem& image1D) : Image(image1D) { }
3759 Image1DBuffer& operator = (const cl_mem& rhs)
3761 Image::operator=(rhs);
3765 /*! \brief Copy constructor to forward copy to the superclass correctly.
3766 * Required for MSVC.
3768 Image1DBuffer(const Image1DBuffer& img) : Image(img) {}
3770 /*! \brief Copy assignment to forward copy to the superclass correctly.
3771 * Required for MSVC.
3773 Image1DBuffer& operator = (const Image1DBuffer &img)
3775 Image::operator=(img);
3779 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
3780 /*! \brief Move constructor to forward move to the superclass correctly.
3781 * Required for MSVC.
3783 Image1DBuffer(Image1DBuffer&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {}
3785 /*! \brief Move assignment to forward move to the superclass correctly.
3786 * Required for MSVC.
3788 Image1DBuffer& operator = (Image1DBuffer &&img)
3790 Image::operator=(std::move(img));
3793 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
3796 /*! \class Image1DArray
3797 * \brief Image interface for arrays of 1D images.
3799 class Image1DArray : public Image
3803 const Context& context,
3809 void* host_ptr = NULL,
3813 cl_image_desc desc =
3815 CL_MEM_OBJECT_IMAGE1D_ARRAY,
3817 0, 0, // height, depth (unused)
3822 object_ = ::clCreateImage(
3830 detail::errHandler(error, __CREATE_IMAGE_ERR);
3838 __CL_EXPLICIT_CONSTRUCTORS Image1DArray(const cl_mem& imageArray) : Image(imageArray) { }
3840 Image1DArray& operator = (const cl_mem& rhs)
3842 Image::operator=(rhs);
3846 /*! \brief Copy constructor to forward copy to the superclass correctly.
3847 * Required for MSVC.
3849 Image1DArray(const Image1DArray& img) : Image(img) {}
3851 /*! \brief Copy assignment to forward copy to the superclass correctly.
3852 * Required for MSVC.
3854 Image1DArray& operator = (const Image1DArray &img)
3856 Image::operator=(img);
3860 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
3861 /*! \brief Move constructor to forward move to the superclass correctly.
3862 * Required for MSVC.
3864 Image1DArray(Image1DArray&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {}
3866 /*! \brief Move assignment to forward move to the superclass correctly.
3867 * Required for MSVC.
3869 Image1DArray& operator = (Image1DArray &&img)
3871 Image::operator=(std::move(img));
3874 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
3876 #endif // #if defined(CL_VERSION_1_2)
3879 /*! \brief Class interface for 2D Image Memory objects.
3881 * See Memory for details about copy semantics, etc.
3885 class Image2D : public Image
3888 /*! \brief Constructs a 1D Image in a specified context.
3890 * Wraps clCreateImage().
3893 const Context& context,
3898 ::size_t row_pitch = 0,
3899 void* host_ptr = NULL,
3903 bool useCreateImage;
3905 #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
3906 // Run-time decision based on the actual platform
3908 cl_uint version = detail::getContextPlatformVersion(context());
3909 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
3911 #elif defined(CL_VERSION_1_2)
3912 useCreateImage = true;
3914 useCreateImage = false;
3917 #if defined(CL_VERSION_1_2)
3920 cl_image_desc desc =
3922 CL_MEM_OBJECT_IMAGE2D,
3925 0, 0, // depth, array size (unused)
3929 object_ = ::clCreateImage(
3937 detail::errHandler(error, __CREATE_IMAGE_ERR);
3942 #endif // #if defined(CL_VERSION_1_2)
3943 #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
3944 if (!useCreateImage)
3946 object_ = ::clCreateImage2D(
3947 context(), flags,&format, width, height, row_pitch, host_ptr, &error);
3949 detail::errHandler(error, __CREATE_IMAGE2D_ERR);
3954 #endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
3957 //! \brief Default constructor - initializes to NULL.
3960 /*! \brief Constructor from cl_mem - takes ownership.
3962 * See Memory for further details.
3964 __CL_EXPLICIT_CONSTRUCTORS Image2D(const cl_mem& image2D) : Image(image2D) { }
3966 /*! \brief Assignment from cl_mem - performs shallow copy.
3968 * See Memory for further details.
3970 Image2D& operator = (const cl_mem& rhs)
3972 Image::operator=(rhs);
3976 /*! \brief Copy constructor to forward copy to the superclass correctly.
3977 * Required for MSVC.
3979 Image2D(const Image2D& img) : Image(img) {}
3981 /*! \brief Copy assignment to forward copy to the superclass correctly.
3982 * Required for MSVC.
3984 Image2D& operator = (const Image2D &img)
3986 Image::operator=(img);
3990 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
3991 /*! \brief Move constructor to forward move to the superclass correctly.
3992 * Required for MSVC.
3994 Image2D(Image2D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {}
3996 /*! \brief Move assignment to forward move to the superclass correctly.
3997 * Required for MSVC.
3999 Image2D& operator = (Image2D &&img)
4001 Image::operator=(std::move(img));
4004 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
4008 #if !defined(CL_VERSION_1_2)
4009 /*! \brief Class interface for GL 2D Image Memory objects.
4011 * This is provided to facilitate interoperability with OpenGL.
4013 * See Memory for details about copy semantics, etc.
4016 * \note Deprecated for OpenCL 1.2. Please use ImageGL instead.
4018 class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED Image2DGL CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED : public Image2D
4021 /*! \brief Constructs an Image2DGL in a specified context, from a given
4024 * Wraps clCreateFromGLTexture2D().
4027 const Context& context,
4032 cl_int * err = NULL)
4035 object_ = ::clCreateFromGLTexture2D(
4043 detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR);
4050 //! \brief Default constructor - initializes to NULL.
4051 Image2DGL() : Image2D() { }
4053 /*! \brief Constructor from cl_mem - takes ownership.
4055 * See Memory for further details.
4057 __CL_EXPLICIT_CONSTRUCTORS Image2DGL(const cl_mem& image) : Image2D(image) { }
4059 /*! \brief Assignment from cl_mem - performs shallow copy.
4061 * See Memory for further details.
4063 Image2DGL& operator = (const cl_mem& rhs)
4065 Image2D::operator=(rhs);
4069 /*! \brief Copy constructor to forward copy to the superclass correctly.
4070 * Required for MSVC.
4072 Image2DGL(const Image2DGL& img) : Image2D(img) {}
4074 /*! \brief Copy assignment to forward copy to the superclass correctly.
4075 * Required for MSVC.
4077 Image2DGL& operator = (const Image2DGL &img)
4079 Image2D::operator=(img);
4083 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
4084 /*! \brief Move constructor to forward move to the superclass correctly.
4085 * Required for MSVC.
4087 Image2DGL(Image2DGL&& img) CL_HPP_NOEXCEPT : Image2D(std::move(img)) {}
4089 /*! \brief Move assignment to forward move to the superclass correctly.
4090 * Required for MSVC.
4092 Image2DGL& operator = (Image2DGL &&img)
4094 Image2D::operator=(std::move(img));
4097 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
4099 #endif // #if !defined(CL_VERSION_1_2)
4101 #if defined(CL_VERSION_1_2)
4102 /*! \class Image2DArray
4103 * \brief Image interface for arrays of 2D images.
4105 class Image2DArray : public Image
4109 const Context& context,
4116 ::size_t slicePitch,
4117 void* host_ptr = NULL,
4121 cl_image_desc desc =
4123 CL_MEM_OBJECT_IMAGE2D_ARRAY,
4126 0, // depth (unused)
4132 object_ = ::clCreateImage(
4140 detail::errHandler(error, __CREATE_IMAGE_ERR);
4148 __CL_EXPLICIT_CONSTRUCTORS Image2DArray(const cl_mem& imageArray) : Image(imageArray) { }
4150 Image2DArray& operator = (const cl_mem& rhs)
4152 Image::operator=(rhs);
4156 /*! \brief Copy constructor to forward copy to the superclass correctly.
4157 * Required for MSVC.
4159 Image2DArray(const Image2DArray& img) : Image(img) {}
4161 /*! \brief Copy assignment to forward copy to the superclass correctly.
4162 * Required for MSVC.
4164 Image2DArray& operator = (const Image2DArray &img)
4166 Image::operator=(img);
4170 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
4171 /*! \brief Move constructor to forward move to the superclass correctly.
4172 * Required for MSVC.
4174 Image2DArray(Image2DArray&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {}
4176 /*! \brief Move assignment to forward move to the superclass correctly.
4177 * Required for MSVC.
4179 Image2DArray& operator = (Image2DArray &&img)
4181 Image::operator=(std::move(img));
4184 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
4186 #endif // #if defined(CL_VERSION_1_2)
4188 /*! \brief Class interface for 3D Image Memory objects.
4190 * See Memory for details about copy semantics, etc.
4194 class Image3D : public Image
4197 /*! \brief Constructs a 3D Image in a specified context.
4199 * Wraps clCreateImage().
4202 const Context& context,
4208 ::size_t row_pitch = 0,
4209 ::size_t slice_pitch = 0,
4210 void* host_ptr = NULL,
4214 bool useCreateImage;
4216 #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
4217 // Run-time decision based on the actual platform
4219 cl_uint version = detail::getContextPlatformVersion(context());
4220 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
4222 #elif defined(CL_VERSION_1_2)
4223 useCreateImage = true;
4225 useCreateImage = false;
4228 #if defined(CL_VERSION_1_2)
4231 cl_image_desc desc =
4233 CL_MEM_OBJECT_IMAGE3D,
4237 0, // array size (unused)
4242 object_ = ::clCreateImage(
4250 detail::errHandler(error, __CREATE_IMAGE_ERR);
4255 #endif // #if defined(CL_VERSION_1_2)
4256 #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
4257 if (!useCreateImage)
4259 object_ = ::clCreateImage3D(
4260 context(), flags, &format, width, height, depth, row_pitch,
4261 slice_pitch, host_ptr, &error);
4263 detail::errHandler(error, __CREATE_IMAGE3D_ERR);
4268 #endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
4271 //! \brief Default constructor - initializes to NULL.
4272 Image3D() : Image() { }
4274 /*! \brief Constructor from cl_mem - takes ownership.
4276 * See Memory for further details.
4278 __CL_EXPLICIT_CONSTRUCTORS Image3D(const cl_mem& image3D) : Image(image3D) { }
4280 /*! \brief Assignment from cl_mem - performs shallow copy.
4282 * See Memory for further details.
4284 Image3D& operator = (const cl_mem& rhs)
4286 Image::operator=(rhs);
4290 /*! \brief Copy constructor to forward copy to the superclass correctly.
4291 * Required for MSVC.
4293 Image3D(const Image3D& img) : Image(img) {}
4295 /*! \brief Copy assignment to forward copy to the superclass correctly.
4296 * Required for MSVC.
4298 Image3D& operator = (const Image3D &img)
4300 Image::operator=(img);
4304 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
4305 /*! \brief Move constructor to forward move to the superclass correctly.
4306 * Required for MSVC.
4308 Image3D(Image3D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {}
4310 /*! \brief Move assignment to forward move to the superclass correctly.
4311 * Required for MSVC.
4313 Image3D& operator = (Image3D &&img)
4315 Image::operator=(std::move(img));
4318 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
4321 #if !defined(CL_VERSION_1_2)
4322 /*! \brief Class interface for GL 3D Image Memory objects.
4324 * This is provided to facilitate interoperability with OpenGL.
4326 * See Memory for details about copy semantics, etc.
4330 class Image3DGL : public Image3D
4333 /*! \brief Constructs an Image3DGL in a specified context, from a given
4336 * Wraps clCreateFromGLTexture3D().
4339 const Context& context,
4344 cl_int * err = NULL)
4347 object_ = ::clCreateFromGLTexture3D(
4355 detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR);
4361 //! \brief Default constructor - initializes to NULL.
4362 Image3DGL() : Image3D() { }
4364 /*! \brief Constructor from cl_mem - takes ownership.
4366 * See Memory for further details.
4368 __CL_EXPLICIT_CONSTRUCTORS Image3DGL(const cl_mem& image) : Image3D(image) { }
4370 /*! \brief Assignment from cl_mem - performs shallow copy.
4372 * See Memory for further details.
4374 Image3DGL& operator = (const cl_mem& rhs)
4376 Image3D::operator=(rhs);
4380 /*! \brief Copy constructor to forward copy to the superclass correctly.
4381 * Required for MSVC.
4383 Image3DGL(const Image3DGL& img) : Image3D(img) {}
4385 /*! \brief Copy assignment to forward copy to the superclass correctly.
4386 * Required for MSVC.
4388 Image3DGL& operator = (const Image3DGL &img)
4390 Image3D::operator=(img);
4394 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
4395 /*! \brief Move constructor to forward move to the superclass correctly.
4396 * Required for MSVC.
4398 Image3DGL(Image3DGL&& img) CL_HPP_NOEXCEPT : Image3D(std::move(img)) {}
4400 /*! \brief Move assignment to forward move to the superclass correctly.
4401 * Required for MSVC.
4403 Image3DGL& operator = (Image3DGL &&img)
4405 Image3D::operator=(std::move(img));
4408 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
4410 #endif // #if !defined(CL_VERSION_1_2)
4412 #if defined(CL_VERSION_1_2)
4414 * \brief general image interface for GL interop.
4415 * We abstract the 2D and 3D GL images into a single instance here
4416 * that wraps all GL sourced images on the grounds that setup information
4417 * was performed by OpenCL anyway.
4419 class ImageGL : public Image
4423 const Context& context,
4428 cl_int * err = NULL)
4431 object_ = ::clCreateFromGLTexture(
4439 detail::errHandler(error, __CREATE_GL_TEXTURE_ERR);
4445 ImageGL() : Image() { }
4447 __CL_EXPLICIT_CONSTRUCTORS ImageGL(const cl_mem& image) : Image(image) { }
4449 ImageGL& operator = (const cl_mem& rhs)
4451 Image::operator=(rhs);
4455 /*! \brief Copy constructor to forward copy to the superclass correctly.
4456 * Required for MSVC.
4458 ImageGL(const ImageGL& img) : Image(img) {}
4460 /*! \brief Copy assignment to forward copy to the superclass correctly.
4461 * Required for MSVC.
4463 ImageGL& operator = (const ImageGL &img)
4465 Image::operator=(img);
4469 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
4470 /*! \brief Move constructor to forward move to the superclass correctly.
4471 * Required for MSVC.
4473 ImageGL(ImageGL&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {}
4475 /*! \brief Move assignment to forward move to the superclass correctly.
4476 * Required for MSVC.
4478 ImageGL& operator = (ImageGL &&img)
4480 Image::operator=(std::move(img));
4483 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
4485 #endif // #if defined(CL_VERSION_1_2)
4487 /*! \brief Class interface for GL Render Buffer Memory Objects.
4489 * This is provided to facilitate interoperability with OpenGL.
4491 * See Memory for details about copy semantics, etc.
4495 class BufferRenderGL :
4496 #if defined(CL_VERSION_1_2)
4498 #else // #if defined(CL_VERSION_1_2)
4500 #endif //#if defined(CL_VERSION_1_2)
4503 /*! \brief Constructs a BufferRenderGL in a specified context, from a given
4506 * Wraps clCreateFromGLRenderbuffer().
4509 const Context& context,
4512 cl_int * err = NULL)
4515 object_ = ::clCreateFromGLRenderbuffer(
4521 detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR);
4527 //! \brief Default constructor - initializes to NULL.
4528 #if defined(CL_VERSION_1_2)
4529 BufferRenderGL() : ImageGL() {};
4530 #else // #if defined(CL_VERSION_1_2)
4531 BufferRenderGL() : Image2DGL() {};
4532 #endif //#if defined(CL_VERSION_1_2)
4534 /*! \brief Constructor from cl_mem - takes ownership.
4536 * See Memory for further details.
4538 #if defined(CL_VERSION_1_2)
4539 __CL_EXPLICIT_CONSTRUCTORS BufferRenderGL(const cl_mem& buffer) : ImageGL(buffer) { }
4540 #else // #if defined(CL_VERSION_1_2)
4541 __CL_EXPLICIT_CONSTRUCTORS BufferRenderGL(const cl_mem& buffer) : Image2DGL(buffer) { }
4542 #endif //#if defined(CL_VERSION_1_2)
4545 /*! \brief Assignment from cl_mem - performs shallow copy.
4547 * See Memory for further details.
4549 BufferRenderGL& operator = (const cl_mem& rhs)
4551 #if defined(CL_VERSION_1_2)
4552 ImageGL::operator=(rhs);
4553 #else // #if defined(CL_VERSION_1_2)
4554 Image2DGL::operator=(rhs);
4555 #endif //#if defined(CL_VERSION_1_2)
4560 /*! \brief Copy constructor to forward copy to the superclass correctly.
4561 * Required for MSVC.
4563 #if defined(CL_VERSION_1_2)
4564 BufferRenderGL(const BufferRenderGL& buf) : ImageGL(buf) {}
4565 #else // #if defined(CL_VERSION_1_2)
4566 BufferRenderGL(const BufferRenderGL& buf) : Image2DGL(buf) {}
4567 #endif //#if defined(CL_VERSION_1_2)
4569 /*! \brief Copy assignment to forward copy to the superclass correctly.
4570 * Required for MSVC.
4572 BufferRenderGL& operator = (const BufferRenderGL &rhs)
4574 #if defined(CL_VERSION_1_2)
4575 ImageGL::operator=(rhs);
4576 #else // #if defined(CL_VERSION_1_2)
4577 Image2DGL::operator=(rhs);
4578 #endif //#if defined(CL_VERSION_1_2)
4582 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
4583 /*! \brief Move constructor to forward move to the superclass correctly.
4584 * Required for MSVC.
4586 #if defined(CL_VERSION_1_2)
4587 BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT : ImageGL(std::move(buf)) {}
4588 #else // #if defined(CL_VERSION_1_2)
4589 BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT : Image2DGL(std::move(buf)) {}
4590 #endif //#if defined(CL_VERSION_1_2)
4593 /*! \brief Move assignment to forward move to the superclass correctly.
4594 * Required for MSVC.
4596 BufferRenderGL& operator = (BufferRenderGL &&buf)
4598 #if defined(CL_VERSION_1_2)
4599 ImageGL::operator=(std::move(buf));
4600 #else // #if defined(CL_VERSION_1_2)
4601 Image2DGL::operator=(std::move(buf));
4602 #endif //#if defined(CL_VERSION_1_2)
4606 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
4608 //! \brief Wrapper for clGetGLObjectInfo().
4609 cl_int getObjectInfo(
4610 cl_gl_object_type *type,
4611 cl_GLuint * gl_object_name)
4613 return detail::errHandler(
4614 ::clGetGLObjectInfo(object_, type, gl_object_name),
4615 __GET_GL_OBJECT_INFO_ERR);
4619 /*! \brief Class interface for cl_sampler.
4621 * \note Copies of these objects are shallow, meaning that the copy will refer
4622 * to the same underlying cl_sampler as the original. For details, see
4623 * clRetainSampler() and clReleaseSampler().
4627 class Sampler : public detail::Wrapper<cl_sampler>
4630 //! \brief Default constructor - initializes to NULL.
4633 /*! \brief Constructs a Sampler in a specified context.
4635 * Wraps clCreateSampler().
4638 const Context& context,
4639 cl_bool normalized_coords,
4640 cl_addressing_mode addressing_mode,
4641 cl_filter_mode filter_mode,
4645 object_ = ::clCreateSampler(
4652 detail::errHandler(error, __CREATE_SAMPLER_ERR);
4658 /*! \brief Constructor from cl_sampler - takes ownership.
4660 * This effectively transfers ownership of a refcount on the cl_sampler
4661 * into the new Sampler object.
4663 __CL_EXPLICIT_CONSTRUCTORS Sampler(const cl_sampler& sampler) : detail::Wrapper<cl_type>(sampler) { }
4665 /*! \brief Assignment operator from cl_sampler - takes ownership.
4667 * This effectively transfers ownership of a refcount on the rhs and calls
4668 * clReleaseSampler() on the value previously held by this instance.
4670 Sampler& operator = (const cl_sampler& rhs)
4672 detail::Wrapper<cl_type>::operator=(rhs);
4676 /*! \brief Copy constructor to forward copy to the superclass correctly.
4677 * Required for MSVC.
4679 Sampler(const Sampler& sam) : detail::Wrapper<cl_type>(sam) {}
4681 /*! \brief Copy assignment to forward copy to the superclass correctly.
4682 * Required for MSVC.
4684 Sampler& operator = (const Sampler &sam)
4686 detail::Wrapper<cl_type>::operator=(sam);
4690 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
4691 /*! \brief Move constructor to forward move to the superclass correctly.
4692 * Required for MSVC.
4694 Sampler(Sampler&& sam) CL_HPP_NOEXCEPT : detail::Wrapper<cl_type>(std::move(sam)) {}
4696 /*! \brief Move assignment to forward move to the superclass correctly.
4697 * Required for MSVC.
4699 Sampler& operator = (Sampler &&sam)
4701 detail::Wrapper<cl_type>::operator=(std::move(sam));
4704 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
4706 //! \brief Wrapper for clGetSamplerInfo().
4707 template <typename T>
4708 cl_int getInfo(cl_sampler_info name, T* param) const
4710 return detail::errHandler(
4711 detail::getInfo(&::clGetSamplerInfo, object_, name, param),
4712 __GET_SAMPLER_INFO_ERR);
4715 //! \brief Wrapper for clGetSamplerInfo() that returns by value.
4716 template <cl_int name> typename
4717 detail::param_traits<detail::cl_sampler_info, name>::param_type
4718 getInfo(cl_int* err = NULL) const
4720 typename detail::param_traits<
4721 detail::cl_sampler_info, name>::param_type param;
4722 cl_int result = getInfo(name, ¶m);
4734 //! \brief Class interface for specifying NDRange values.
4739 cl_uint dimensions_;
4742 //! \brief Default constructor - resulting range has zero dimensions.
4747 //! \brief Constructs one-dimensional range.
4748 NDRange(::size_t size0)
4754 //! \brief Constructs two-dimensional range.
4755 NDRange(::size_t size0, ::size_t size1)
4762 //! \brief Constructs three-dimensional range.
4763 NDRange(::size_t size0, ::size_t size1, ::size_t size2)
4771 /*! \brief Conversion operator to const ::size_t *.
4773 * \returns a pointer to the size of the first dimension.
4775 operator const ::size_t*() const {
4776 return (const ::size_t*) sizes_;
4779 //! \brief Queries the number of dimensions in the range.
4780 ::size_t dimensions() const { return dimensions_; }
4783 //! \brief A zero-dimensional range.
4784 static const NDRange NullRange;
4786 //! \brief Local address wrapper for use with Kernel::setArg
4787 struct LocalSpaceArg
4794 template <typename T>
4795 struct KernelArgumentHandler
4797 static ::size_t size(const T&) { return sizeof(T); }
4798 static const T* ptr(const T& value) { return &value; }
4802 struct KernelArgumentHandler<LocalSpaceArg>
4804 static ::size_t size(const LocalSpaceArg& value) { return value.size_; }
4805 static const void* ptr(const LocalSpaceArg&) { return NULL; }
4812 * \brief Helper function for generating LocalSpaceArg objects.
4813 * Deprecated. Replaced with Local.
4815 inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED LocalSpaceArg
4816 __local(::size_t size) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
4817 inline LocalSpaceArg
4818 __local(::size_t size)
4820 LocalSpaceArg ret = { size };
4825 * \brief Helper function for generating LocalSpaceArg objects.
4827 inline LocalSpaceArg
4828 Local(::size_t size)
4830 LocalSpaceArg ret = { size };
4834 //class KernelFunctor;
4836 /*! \brief Class interface for cl_kernel.
4838 * \note Copies of these objects are shallow, meaning that the copy will refer
4839 * to the same underlying cl_kernel as the original. For details, see
4840 * clRetainKernel() and clReleaseKernel().
4844 class Kernel : public detail::Wrapper<cl_kernel>
4847 inline Kernel(const Program& program, const char* name, cl_int* err = NULL);
4849 //! \brief Default constructor - initializes to NULL.
4852 /*! \brief Constructor from cl_kernel - takes ownership.
4854 * This effectively transfers ownership of a refcount on the cl_kernel
4855 * into the new Kernel object.
4857 __CL_EXPLICIT_CONSTRUCTORS Kernel(const cl_kernel& kernel) : detail::Wrapper<cl_type>(kernel) { }
4859 /*! \brief Assignment operator from cl_kernel - takes ownership.
4861 * This effectively transfers ownership of a refcount on the rhs and calls
4862 * clReleaseKernel() on the value previously held by this instance.
4864 Kernel& operator = (const cl_kernel& rhs)
4866 detail::Wrapper<cl_type>::operator=(rhs);
4870 /*! \brief Copy constructor to forward copy to the superclass correctly.
4871 * Required for MSVC.
4873 Kernel(const Kernel& kernel) : detail::Wrapper<cl_type>(kernel) {}
4875 /*! \brief Copy assignment to forward copy to the superclass correctly.
4876 * Required for MSVC.
4878 Kernel& operator = (const Kernel &kernel)
4880 detail::Wrapper<cl_type>::operator=(kernel);
4884 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
4885 /*! \brief Move constructor to forward move to the superclass correctly.
4886 * Required for MSVC.
4888 Kernel(Kernel&& kernel) CL_HPP_NOEXCEPT : detail::Wrapper<cl_type>(std::move(kernel)) {}
4890 /*! \brief Move assignment to forward move to the superclass correctly.
4891 * Required for MSVC.
4893 Kernel& operator = (Kernel &&kernel)
4895 detail::Wrapper<cl_type>::operator=(std::move(kernel));
4898 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
4900 template <typename T>
4901 cl_int getInfo(cl_kernel_info name, T* param) const
4903 return detail::errHandler(
4904 detail::getInfo(&::clGetKernelInfo, object_, name, param),
4905 __GET_KERNEL_INFO_ERR);
4908 template <cl_int name> typename
4909 detail::param_traits<detail::cl_kernel_info, name>::param_type
4910 getInfo(cl_int* err = NULL) const
4912 typename detail::param_traits<
4913 detail::cl_kernel_info, name>::param_type param;
4914 cl_int result = getInfo(name, ¶m);
4921 #if defined(CL_VERSION_1_2)
4922 template <typename T>
4923 cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const
4925 return detail::errHandler(
4926 detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param),
4927 __GET_KERNEL_ARG_INFO_ERR);
4930 template <cl_int name> typename
4931 detail::param_traits<detail::cl_kernel_arg_info, name>::param_type
4932 getArgInfo(cl_uint argIndex, cl_int* err = NULL) const
4934 typename detail::param_traits<
4935 detail::cl_kernel_arg_info, name>::param_type param;
4936 cl_int result = getArgInfo(argIndex, name, ¶m);
4942 #endif // #if defined(CL_VERSION_1_2)
4944 template <typename T>
4945 cl_int getWorkGroupInfo(
4946 const Device& device, cl_kernel_work_group_info name, T* param) const
4948 return detail::errHandler(
4950 &::clGetKernelWorkGroupInfo, object_, device(), name, param),
4951 __GET_KERNEL_WORK_GROUP_INFO_ERR);
4954 template <cl_int name> typename
4955 detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
4956 getWorkGroupInfo(const Device& device, cl_int* err = NULL) const
4958 typename detail::param_traits<
4959 detail::cl_kernel_work_group_info, name>::param_type param;
4960 cl_int result = getWorkGroupInfo(device, name, ¶m);
4967 template <typename T>
4968 cl_int setArg(cl_uint index, const T &value)
4970 return detail::errHandler(
4974 detail::KernelArgumentHandler<T>::size(value),
4975 detail::KernelArgumentHandler<T>::ptr(value)),
4976 __SET_KERNEL_ARGS_ERR);
4979 cl_int setArg(cl_uint index, ::size_t size, const void* argPtr)
4981 return detail::errHandler(
4982 ::clSetKernelArg(object_, index, size, argPtr),
4983 __SET_KERNEL_ARGS_ERR);
4988 * \brief Program interface that implements cl_program.
4990 class Program : public detail::Wrapper<cl_program>
4993 typedef VECTOR_CLASS<std::pair<const void*, ::size_t> > Binaries;
4994 typedef VECTOR_CLASS<std::pair<const char*, ::size_t> > Sources;
4997 const STRING_CLASS& source,
5003 const char * strings = source.c_str();
5004 const ::size_t length = source.size();
5006 Context context = Context::getDefault(err);
5008 object_ = ::clCreateProgramWithSource(
5009 context(), (cl_uint)1, &strings, &length, &error);
5011 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
5013 if (error == CL_SUCCESS && build) {
5015 error = ::clBuildProgram(
5023 detail::errHandler(error, __BUILD_PROGRAM_ERR);
5032 const Context& context,
5033 const STRING_CLASS& source,
5039 const char * strings = source.c_str();
5040 const ::size_t length = source.size();
5042 object_ = ::clCreateProgramWithSource(
5043 context(), (cl_uint)1, &strings, &length, &error);
5045 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
5047 if (error == CL_SUCCESS && build) {
5049 error = ::clBuildProgram(
5057 detail::errHandler(error, __BUILD_PROGRAM_ERR);
5066 const Context& context,
5067 const Sources& sources,
5072 const ::size_t n = (::size_t)sources.size();
5073 ::size_t* lengths = (::size_t*) alloca(n * sizeof(::size_t));
5074 const char** strings = (const char**) alloca(n * sizeof(const char*));
5076 for (::size_t i = 0; i < n; ++i) {
5077 strings[i] = sources[(int)i].first;
5078 lengths[i] = sources[(int)i].second;
5081 object_ = ::clCreateProgramWithSource(
5082 context(), (cl_uint)n, strings, lengths, &error);
5084 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
5091 * Construct a program object from a list of devices and a per-device list of binaries.
5092 * \param context A valid OpenCL context in which to construct the program.
5093 * \param devices A vector of OpenCL device objects for which the program will be created.
5094 * \param binaries A vector of pairs of a pointer to a binary object and its length.
5095 * \param binaryStatus An optional vector that on completion will be resized to
5096 * match the size of binaries and filled with values to specify if each binary
5097 * was successfully loaded.
5098 * Set to CL_SUCCESS if the binary was successfully loaded.
5099 * Set to CL_INVALID_VALUE if the length is 0 or the binary pointer is NULL.
5100 * Set to CL_INVALID_BINARY if the binary provided is not valid for the matching device.
5101 * \param err if non-NULL will be set to CL_SUCCESS on successful operation or one of the following errors:
5102 * CL_INVALID_CONTEXT if context is not a valid context.
5103 * CL_INVALID_VALUE if the length of devices is zero; or if the length of binaries does not match the length of devices;
5104 * or if any entry in binaries is NULL or has length 0.
5105 * CL_INVALID_DEVICE if OpenCL devices listed in devices are not in the list of devices associated with context.
5106 * CL_INVALID_BINARY if an invalid program binary was encountered for any device. binaryStatus will return specific status for each device.
5107 * CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host.
5110 const Context& context,
5111 const VECTOR_CLASS<Device>& devices,
5112 const Binaries& binaries,
5113 VECTOR_CLASS<cl_int>* binaryStatus = NULL,
5118 const ::size_t numDevices = devices.size();
5120 // Catch size mismatch early and return
5121 if(binaries.size() != numDevices) {
5122 error = CL_INVALID_VALUE;
5123 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
5130 ::size_t* lengths = (::size_t*) alloca(numDevices * sizeof(::size_t));
5131 const unsigned char** images = (const unsigned char**) alloca(numDevices * sizeof(const unsigned char**));
5133 for (::size_t i = 0; i < numDevices; ++i) {
5134 images[i] = (const unsigned char*)binaries[i].first;
5135 lengths[i] = binaries[(int)i].second;
5138 cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id));
5139 for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
5140 deviceIDs[deviceIndex] = (devices[deviceIndex])();
5144 binaryStatus->resize(numDevices);
5147 object_ = ::clCreateProgramWithBinary(
5148 context(), (cl_uint) devices.size(),
5150 lengths, images, (binaryStatus != NULL && numDevices > 0)
5151 ? &binaryStatus->front()
5154 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
5161 #if defined(CL_VERSION_1_2)
5163 * Create program using builtin kernels.
5164 * \param kernelNames Semi-colon separated list of builtin kernel names
5167 const Context& context,
5168 const VECTOR_CLASS<Device>& devices,
5169 const STRING_CLASS& kernelNames,
5175 ::size_t numDevices = devices.size();
5176 cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id));
5177 for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
5178 deviceIDs[deviceIndex] = (devices[deviceIndex])();
5181 object_ = ::clCreateProgramWithBuiltInKernels(
5183 (cl_uint) devices.size(),
5185 kernelNames.c_str(),
5188 detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR);
5193 #endif // #if defined(CL_VERSION_1_2)
5197 __CL_EXPLICIT_CONSTRUCTORS Program(const cl_program& program) : detail::Wrapper<cl_type>(program) { }
5199 Program& operator = (const cl_program& rhs)
5201 detail::Wrapper<cl_type>::operator=(rhs);
5205 /*! \brief Copy constructor to forward copy to the superclass correctly.
5206 * Required for MSVC.
5208 Program(const Program& program) : detail::Wrapper<cl_type>(program) {}
5210 /*! \brief Copy assignment to forward copy to the superclass correctly.
5211 * Required for MSVC.
5213 Program& operator = (const Program &program)
5215 detail::Wrapper<cl_type>::operator=(program);
5219 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
5220 /*! \brief Move constructor to forward move to the superclass correctly.
5221 * Required for MSVC.
5223 Program(Program&& program) CL_HPP_NOEXCEPT : detail::Wrapper<cl_type>(std::move(program)) {}
5225 /*! \brief Move assignment to forward move to the superclass correctly.
5226 * Required for MSVC.
5228 Program& operator = (Program &&program)
5230 detail::Wrapper<cl_type>::operator=(std::move(program));
5233 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
5236 const VECTOR_CLASS<Device>& devices,
5237 const char* options = NULL,
5238 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
5239 void* data = NULL) const
5241 ::size_t numDevices = devices.size();
5242 cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id));
5243 for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
5244 deviceIDs[deviceIndex] = (devices[deviceIndex])();
5247 return detail::errHandler(
5256 __BUILD_PROGRAM_ERR);
5260 const char* options = NULL,
5261 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
5262 void* data = NULL) const
5264 return detail::errHandler(
5272 __BUILD_PROGRAM_ERR);
5275 #if defined(CL_VERSION_1_2)
5277 const char* options = NULL,
5278 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
5279 void* data = NULL) const
5281 return detail::errHandler(
5292 __COMPILE_PROGRAM_ERR);
5296 template <typename T>
5297 cl_int getInfo(cl_program_info name, T* param) const
5299 return detail::errHandler(
5300 detail::getInfo(&::clGetProgramInfo, object_, name, param),
5301 __GET_PROGRAM_INFO_ERR);
5304 template <cl_int name> typename
5305 detail::param_traits<detail::cl_program_info, name>::param_type
5306 getInfo(cl_int* err = NULL) const
5308 typename detail::param_traits<
5309 detail::cl_program_info, name>::param_type param;
5310 cl_int result = getInfo(name, ¶m);
5317 template <typename T>
5318 cl_int getBuildInfo(
5319 const Device& device, cl_program_build_info name, T* param) const
5321 return detail::errHandler(
5323 &::clGetProgramBuildInfo, object_, device(), name, param),
5324 __GET_PROGRAM_BUILD_INFO_ERR);
5327 template <cl_int name> typename
5328 detail::param_traits<detail::cl_program_build_info, name>::param_type
5329 getBuildInfo(const Device& device, cl_int* err = NULL) const
5331 typename detail::param_traits<
5332 detail::cl_program_build_info, name>::param_type param;
5333 cl_int result = getBuildInfo(device, name, ¶m);
5340 cl_int createKernels(VECTOR_CLASS<Kernel>* kernels)
5343 cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
5344 if (err != CL_SUCCESS) {
5345 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
5348 Kernel* value = (Kernel*) alloca(numKernels * sizeof(Kernel));
5349 err = ::clCreateKernelsInProgram(
5350 object_, numKernels, (cl_kernel*) value, NULL);
5351 if (err != CL_SUCCESS) {
5352 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
5355 kernels->assign(&value[0], &value[numKernels]);
5360 #if defined(CL_VERSION_1_2)
5361 inline Program linkProgram(
5364 const char* options = NULL,
5365 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
5369 cl_int error_local = CL_SUCCESS;
5371 cl_program programs[2] = { input1(), input2() };
5373 Context ctx = input1.getInfo<CL_PROGRAM_CONTEXT>(&error_local);
5374 if(error_local!=CL_SUCCESS) {
5375 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
5378 cl_program prog = ::clLinkProgram(
5389 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
5394 return Program(prog);
5397 inline Program linkProgram(
5398 VECTOR_CLASS<Program> inputPrograms,
5399 const char* options = NULL,
5400 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
5404 cl_int error_local = CL_SUCCESS;
5406 cl_program * programs = (cl_program*) alloca(inputPrograms.size() * sizeof(cl_program));
5408 if (programs != NULL) {
5409 for (unsigned int i = 0; i < inputPrograms.size(); i++) {
5410 programs[i] = inputPrograms[i]();
5415 if(inputPrograms.size() > 0) {
5416 ctx = inputPrograms[0].getInfo<CL_PROGRAM_CONTEXT>(&error_local);
5417 if(error_local!=CL_SUCCESS) {
5418 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
5421 cl_program prog = ::clLinkProgram(
5426 (cl_uint)inputPrograms.size(),
5432 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
5437 return Program(prog);
5442 inline VECTOR_CLASS<char *> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err) const
5444 VECTOR_CLASS< ::size_t> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>();
5445 VECTOR_CLASS<char *> binaries;
5446 for (VECTOR_CLASS< ::size_t>::iterator s = sizes.begin(); s != sizes.end(); ++s)
5451 binaries.push_back(ptr);
5454 cl_int result = getInfo(CL_PROGRAM_BINARIES, &binaries);
5461 inline Kernel::Kernel(const Program& program, const char* name, cl_int* err)
5465 object_ = ::clCreateKernel(program(), name, &error);
5466 detail::errHandler(error, __CREATE_KERNEL_ERR);
5474 /*! \class CommandQueue
5475 * \brief CommandQueue interface for cl_command_queue.
5477 class CommandQueue : public detail::Wrapper<cl_command_queue>
5480 #ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED
5481 static std::atomic<int> default_initialized_;
5482 #else // !CL_HPP_CPP11_ATOMICS_SUPPORTED
5483 static volatile int default_initialized_;
5484 #endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED
5485 static CommandQueue default_;
5486 static volatile cl_int default_error_;
5489 cl_command_queue_properties properties,
5494 Context context = Context::getDefault(&error);
5495 detail::errHandler(error, __CREATE_CONTEXT_ERR);
5497 if (error != CL_SUCCESS) {
5503 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
5505 object_ = ::clCreateCommandQueue(
5506 context(), device(), properties, &error);
5508 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
5515 * \brief Constructs a CommandQueue for an implementation defined device in the given context
5517 explicit CommandQueue(
5518 const Context& context,
5519 cl_command_queue_properties properties = 0,
5523 VECTOR_CLASS<cl::Device> devices;
5524 error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
5526 detail::errHandler(error, __CREATE_CONTEXT_ERR);
5528 if (error != CL_SUCCESS)
5536 object_ = ::clCreateCommandQueue(context(), devices[0](), properties, &error);
5538 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
5547 const Context& context,
5548 const Device& device,
5549 cl_command_queue_properties properties = 0,
5553 object_ = ::clCreateCommandQueue(
5554 context(), device(), properties, &error);
5556 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
5562 /*! \brief Copy constructor to forward copy to the superclass correctly.
5563 * Required for MSVC.
5565 CommandQueue(const CommandQueue& queue) : detail::Wrapper<cl_type>(queue) {}
5567 /*! \brief Copy assignment to forward copy to the superclass correctly.
5568 * Required for MSVC.
5570 CommandQueue& operator = (const CommandQueue &queue)
5572 detail::Wrapper<cl_type>::operator=(queue);
5576 #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
5577 /*! \brief Move constructor to forward move to the superclass correctly.
5578 * Required for MSVC.
5580 CommandQueue(CommandQueue&& queue) CL_HPP_NOEXCEPT : detail::Wrapper<cl_type>(std::move(queue)) {}
5582 /*! \brief Move assignment to forward move to the superclass correctly.
5583 * Required for MSVC.
5585 CommandQueue& operator = (CommandQueue &&queue)
5587 detail::Wrapper<cl_type>::operator=(std::move(queue));
5590 #endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED)
5592 static CommandQueue getDefault(cl_int * err = NULL)
5594 int state = detail::compare_exchange(
5595 &default_initialized_,
5596 __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED);
5598 if (state & __DEFAULT_INITIALIZED) {
5600 *err = default_error_;
5605 if (state & __DEFAULT_BEING_INITIALIZED) {
5606 // Assume writes will propagate eventually...
5607 while(default_initialized_ != __DEFAULT_INITIALIZED) {
5612 *err = default_error_;
5619 Context context = Context::getDefault(&error);
5620 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
5622 if (error != CL_SUCCESS) {
5628 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
5630 default_ = CommandQueue(context, device, 0, &error);
5632 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
5640 default_error_ = error;
5641 // Assume writes will propagate eventually...
5642 default_initialized_ = __DEFAULT_INITIALIZED;
5647 *err = default_error_;
5655 __CL_EXPLICIT_CONSTRUCTORS CommandQueue(const cl_command_queue& commandQueue) : detail::Wrapper<cl_type>(commandQueue) { }
5657 CommandQueue& operator = (const cl_command_queue& rhs)
5659 detail::Wrapper<cl_type>::operator=(rhs);
5663 template <typename T>
5664 cl_int getInfo(cl_command_queue_info name, T* param) const
5666 return detail::errHandler(
5668 &::clGetCommandQueueInfo, object_, name, param),
5669 __GET_COMMAND_QUEUE_INFO_ERR);
5672 template <cl_int name> typename
5673 detail::param_traits<detail::cl_command_queue_info, name>::param_type
5674 getInfo(cl_int* err = NULL) const
5676 typename detail::param_traits<
5677 detail::cl_command_queue_info, name>::param_type param;
5678 cl_int result = getInfo(name, ¶m);
5685 cl_int enqueueReadBuffer(
5686 const Buffer& buffer,
5691 const VECTOR_CLASS<Event>* events = NULL,
5692 Event* event = NULL) const
5695 cl_int err = detail::errHandler(
5696 ::clEnqueueReadBuffer(
5697 object_, buffer(), blocking, offset, size,
5699 (events != NULL) ? (cl_uint) events->size() : 0,
5700 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5701 (event != NULL) ? &tmp : NULL),
5702 __ENQUEUE_READ_BUFFER_ERR);
5704 if (event != NULL && err == CL_SUCCESS)
5710 cl_int enqueueWriteBuffer(
5711 const Buffer& buffer,
5716 const VECTOR_CLASS<Event>* events = NULL,
5717 Event* event = NULL) const
5720 cl_int err = detail::errHandler(
5721 ::clEnqueueWriteBuffer(
5722 object_, buffer(), blocking, offset, size,
5724 (events != NULL) ? (cl_uint) events->size() : 0,
5725 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5726 (event != NULL) ? &tmp : NULL),
5727 __ENQUEUE_WRITE_BUFFER_ERR);
5729 if (event != NULL && err == CL_SUCCESS)
5735 cl_int enqueueCopyBuffer(
5738 ::size_t src_offset,
5739 ::size_t dst_offset,
5741 const VECTOR_CLASS<Event>* events = NULL,
5742 Event* event = NULL) const
5745 cl_int err = detail::errHandler(
5746 ::clEnqueueCopyBuffer(
5747 object_, src(), dst(), src_offset, dst_offset, size,
5748 (events != NULL) ? (cl_uint) events->size() : 0,
5749 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5750 (event != NULL) ? &tmp : NULL),
5751 __ENQEUE_COPY_BUFFER_ERR);
5753 if (event != NULL && err == CL_SUCCESS)
5759 cl_int enqueueReadBufferRect(
5760 const Buffer& buffer,
5762 const size_t<3>& buffer_offset,
5763 const size_t<3>& host_offset,
5764 const size_t<3>& region,
5765 ::size_t buffer_row_pitch,
5766 ::size_t buffer_slice_pitch,
5767 ::size_t host_row_pitch,
5768 ::size_t host_slice_pitch,
5770 const VECTOR_CLASS<Event>* events = NULL,
5771 Event* event = NULL) const
5774 cl_int err = detail::errHandler(
5775 ::clEnqueueReadBufferRect(
5779 (const ::size_t *)buffer_offset,
5780 (const ::size_t *)host_offset,
5781 (const ::size_t *)region,
5787 (events != NULL) ? (cl_uint) events->size() : 0,
5788 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5789 (event != NULL) ? &tmp : NULL),
5790 __ENQUEUE_READ_BUFFER_RECT_ERR);
5792 if (event != NULL && err == CL_SUCCESS)
5798 cl_int enqueueWriteBufferRect(
5799 const Buffer& buffer,
5801 const size_t<3>& buffer_offset,
5802 const size_t<3>& host_offset,
5803 const size_t<3>& region,
5804 ::size_t buffer_row_pitch,
5805 ::size_t buffer_slice_pitch,
5806 ::size_t host_row_pitch,
5807 ::size_t host_slice_pitch,
5809 const VECTOR_CLASS<Event>* events = NULL,
5810 Event* event = NULL) const
5813 cl_int err = detail::errHandler(
5814 ::clEnqueueWriteBufferRect(
5818 (const ::size_t *)buffer_offset,
5819 (const ::size_t *)host_offset,
5820 (const ::size_t *)region,
5826 (events != NULL) ? (cl_uint) events->size() : 0,
5827 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5828 (event != NULL) ? &tmp : NULL),
5829 __ENQUEUE_WRITE_BUFFER_RECT_ERR);
5831 if (event != NULL && err == CL_SUCCESS)
5837 cl_int enqueueCopyBufferRect(
5840 const size_t<3>& src_origin,
5841 const size_t<3>& dst_origin,
5842 const size_t<3>& region,
5843 ::size_t src_row_pitch,
5844 ::size_t src_slice_pitch,
5845 ::size_t dst_row_pitch,
5846 ::size_t dst_slice_pitch,
5847 const VECTOR_CLASS<Event>* events = NULL,
5848 Event* event = NULL) const
5851 cl_int err = detail::errHandler(
5852 ::clEnqueueCopyBufferRect(
5856 (const ::size_t *)src_origin,
5857 (const ::size_t *)dst_origin,
5858 (const ::size_t *)region,
5863 (events != NULL) ? (cl_uint) events->size() : 0,
5864 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5865 (event != NULL) ? &tmp : NULL),
5866 __ENQEUE_COPY_BUFFER_RECT_ERR);
5868 if (event != NULL && err == CL_SUCCESS)
5874 #if defined(CL_VERSION_1_2)
5876 * Enqueue a command to fill a buffer object with a pattern
5877 * of a given size. The pattern is specified a as vector.
5878 * \tparam PatternType The datatype of the pattern field.
5879 * The pattern type must be an accepted OpenCL data type.
5881 template<typename PatternType>
5882 cl_int enqueueFillBuffer(
5883 const Buffer& buffer,
5884 PatternType pattern,
5887 const VECTOR_CLASS<Event>* events = NULL,
5888 Event* event = NULL) const
5891 cl_int err = detail::errHandler(
5892 ::clEnqueueFillBuffer(
5895 static_cast<void*>(&pattern),
5896 sizeof(PatternType),
5899 (events != NULL) ? (cl_uint) events->size() : 0,
5900 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5901 (event != NULL) ? &tmp : NULL),
5902 __ENQUEUE_FILL_BUFFER_ERR);
5904 if (event != NULL && err == CL_SUCCESS)
5909 #endif // #if defined(CL_VERSION_1_2)
5911 cl_int enqueueReadImage(
5914 const size_t<3>& origin,
5915 const size_t<3>& region,
5917 ::size_t slice_pitch,
5919 const VECTOR_CLASS<Event>* events = NULL,
5920 Event* event = NULL) const
5923 cl_int err = detail::errHandler(
5924 ::clEnqueueReadImage(
5925 object_, image(), blocking, (const ::size_t *) origin,
5926 (const ::size_t *) region, row_pitch, slice_pitch, ptr,
5927 (events != NULL) ? (cl_uint) events->size() : 0,
5928 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5929 (event != NULL) ? &tmp : NULL),
5930 __ENQUEUE_READ_IMAGE_ERR);
5932 if (event != NULL && err == CL_SUCCESS)
5938 cl_int enqueueWriteImage(
5941 const size_t<3>& origin,
5942 const size_t<3>& region,
5944 ::size_t slice_pitch,
5946 const VECTOR_CLASS<Event>* events = NULL,
5947 Event* event = NULL) const
5950 cl_int err = detail::errHandler(
5951 ::clEnqueueWriteImage(
5952 object_, image(), blocking, (const ::size_t *) origin,
5953 (const ::size_t *) region, row_pitch, slice_pitch, ptr,
5954 (events != NULL) ? (cl_uint) events->size() : 0,
5955 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5956 (event != NULL) ? &tmp : NULL),
5957 __ENQUEUE_WRITE_IMAGE_ERR);
5959 if (event != NULL && err == CL_SUCCESS)
5965 cl_int enqueueCopyImage(
5968 const size_t<3>& src_origin,
5969 const size_t<3>& dst_origin,
5970 const size_t<3>& region,
5971 const VECTOR_CLASS<Event>* events = NULL,
5972 Event* event = NULL) const
5975 cl_int err = detail::errHandler(
5976 ::clEnqueueCopyImage(
5977 object_, src(), dst(), (const ::size_t *) src_origin,
5978 (const ::size_t *)dst_origin, (const ::size_t *) region,
5979 (events != NULL) ? (cl_uint) events->size() : 0,
5980 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
5981 (event != NULL) ? &tmp : NULL),
5982 __ENQUEUE_COPY_IMAGE_ERR);
5984 if (event != NULL && err == CL_SUCCESS)
5990 #if defined(CL_VERSION_1_2)
5992 * Enqueue a command to fill an image object with a specified color.
5993 * \param fillColor is the color to use to fill the image.
5994 * This is a four component RGBA floating-point color value if
5995 * the image channel data type is not an unnormalized signed or
5996 * unsigned data type.
5998 cl_int enqueueFillImage(
6000 cl_float4 fillColor,
6001 const size_t<3>& origin,
6002 const size_t<3>& region,
6003 const VECTOR_CLASS<Event>* events = NULL,
6004 Event* event = NULL) const
6007 cl_int err = detail::errHandler(
6008 ::clEnqueueFillImage(
6011 static_cast<void*>(&fillColor),
6012 (const ::size_t *) origin,
6013 (const ::size_t *) region,
6014 (events != NULL) ? (cl_uint) events->size() : 0,
6015 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6016 (event != NULL) ? &tmp : NULL),
6017 __ENQUEUE_FILL_IMAGE_ERR);
6019 if (event != NULL && err == CL_SUCCESS)
6026 * Enqueue a command to fill an image object with a specified color.
6027 * \param fillColor is the color to use to fill the image.
6028 * This is a four component RGBA signed integer color value if
6029 * the image channel data type is an unnormalized signed integer
6032 cl_int enqueueFillImage(
6035 const size_t<3>& origin,
6036 const size_t<3>& region,
6037 const VECTOR_CLASS<Event>* events = NULL,
6038 Event* event = NULL) const
6041 cl_int err = detail::errHandler(
6042 ::clEnqueueFillImage(
6045 static_cast<void*>(&fillColor),
6046 (const ::size_t *) origin,
6047 (const ::size_t *) region,
6048 (events != NULL) ? (cl_uint) events->size() : 0,
6049 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6050 (event != NULL) ? &tmp : NULL),
6051 __ENQUEUE_FILL_IMAGE_ERR);
6053 if (event != NULL && err == CL_SUCCESS)
6060 * Enqueue a command to fill an image object with a specified color.
6061 * \param fillColor is the color to use to fill the image.
6062 * This is a four component RGBA unsigned integer color value if
6063 * the image channel data type is an unnormalized unsigned integer
6066 cl_int enqueueFillImage(
6069 const size_t<3>& origin,
6070 const size_t<3>& region,
6071 const VECTOR_CLASS<Event>* events = NULL,
6072 Event* event = NULL) const
6075 cl_int err = detail::errHandler(
6076 ::clEnqueueFillImage(
6079 static_cast<void*>(&fillColor),
6080 (const ::size_t *) origin,
6081 (const ::size_t *) region,
6082 (events != NULL) ? (cl_uint) events->size() : 0,
6083 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6084 (event != NULL) ? &tmp : NULL),
6085 __ENQUEUE_FILL_IMAGE_ERR);
6087 if (event != NULL && err == CL_SUCCESS)
6092 #endif // #if defined(CL_VERSION_1_2)
6094 cl_int enqueueCopyImageToBuffer(
6097 const size_t<3>& src_origin,
6098 const size_t<3>& region,
6099 ::size_t dst_offset,
6100 const VECTOR_CLASS<Event>* events = NULL,
6101 Event* event = NULL) const
6104 cl_int err = detail::errHandler(
6105 ::clEnqueueCopyImageToBuffer(
6106 object_, src(), dst(), (const ::size_t *) src_origin,
6107 (const ::size_t *) region, dst_offset,
6108 (events != NULL) ? (cl_uint) events->size() : 0,
6109 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6110 (event != NULL) ? &tmp : NULL),
6111 __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
6113 if (event != NULL && err == CL_SUCCESS)
6119 cl_int enqueueCopyBufferToImage(
6122 ::size_t src_offset,
6123 const size_t<3>& dst_origin,
6124 const size_t<3>& region,
6125 const VECTOR_CLASS<Event>* events = NULL,
6126 Event* event = NULL) const
6129 cl_int err = detail::errHandler(
6130 ::clEnqueueCopyBufferToImage(
6131 object_, src(), dst(), src_offset,
6132 (const ::size_t *) dst_origin, (const ::size_t *) region,
6133 (events != NULL) ? (cl_uint) events->size() : 0,
6134 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6135 (event != NULL) ? &tmp : NULL),
6136 __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
6138 if (event != NULL && err == CL_SUCCESS)
6144 void* enqueueMapBuffer(
6145 const Buffer& buffer,
6150 const VECTOR_CLASS<Event>* events = NULL,
6151 Event* event = NULL,
6152 cl_int* err = NULL) const
6156 void * result = ::clEnqueueMapBuffer(
6157 object_, buffer(), blocking, flags, offset, size,
6158 (events != NULL) ? (cl_uint) events->size() : 0,
6159 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6160 (event != NULL) ? &tmp : NULL,
6163 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
6167 if (event != NULL && error == CL_SUCCESS)
6173 void* enqueueMapImage(
6174 const Image& buffer,
6177 const size_t<3>& origin,
6178 const size_t<3>& region,
6179 ::size_t * row_pitch,
6180 ::size_t * slice_pitch,
6181 const VECTOR_CLASS<Event>* events = NULL,
6182 Event* event = NULL,
6183 cl_int* err = NULL) const
6187 void * result = ::clEnqueueMapImage(
6188 object_, buffer(), blocking, flags,
6189 (const ::size_t *) origin, (const ::size_t *) region,
6190 row_pitch, slice_pitch,
6191 (events != NULL) ? (cl_uint) events->size() : 0,
6192 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6193 (event != NULL) ? &tmp : NULL,
6196 detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
6200 if (event != NULL && error == CL_SUCCESS)
6205 cl_int enqueueUnmapMemObject(
6206 const Memory& memory,
6208 const VECTOR_CLASS<Event>* events = NULL,
6209 Event* event = NULL) const
6212 cl_int err = detail::errHandler(
6213 ::clEnqueueUnmapMemObject(
6214 object_, memory(), mapped_ptr,
6215 (events != NULL) ? (cl_uint) events->size() : 0,
6216 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6217 (event != NULL) ? &tmp : NULL),
6218 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
6220 if (event != NULL && err == CL_SUCCESS)
6226 #if defined(CL_VERSION_1_2)
6228 * Enqueues a marker command which waits for either a list of events to complete,
6229 * or all previously enqueued commands to complete.
6231 * Enqueues a marker command which waits for either a list of events to complete,
6232 * or if the list is empty it waits for all commands previously enqueued in command_queue
6233 * to complete before it completes. This command returns an event which can be waited on,
6234 * i.e. this event can be waited on to insure that all events either in the event_wait_list
6235 * or all previously enqueued commands, queued before this command to command_queue,
6238 cl_int enqueueMarkerWithWaitList(
6239 const VECTOR_CLASS<Event> *events = 0,
6243 cl_int err = detail::errHandler(
6244 ::clEnqueueMarkerWithWaitList(
6246 (events != NULL) ? (cl_uint) events->size() : 0,
6247 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6248 (event != NULL) ? &tmp : NULL),
6249 __ENQUEUE_MARKER_WAIT_LIST_ERR);
6251 if (event != NULL && err == CL_SUCCESS)
6258 * A synchronization point that enqueues a barrier operation.
6260 * Enqueues a barrier command which waits for either a list of events to complete,
6261 * or if the list is empty it waits for all commands previously enqueued in command_queue
6262 * to complete before it completes. This command blocks command execution, that is, any
6263 * following commands enqueued after it do not execute until it completes. This command
6264 * returns an event which can be waited on, i.e. this event can be waited on to insure that
6265 * all events either in the event_wait_list or all previously enqueued commands, queued
6266 * before this command to command_queue, have completed.
6268 cl_int enqueueBarrierWithWaitList(
6269 const VECTOR_CLASS<Event> *events = 0,
6273 cl_int err = detail::errHandler(
6274 ::clEnqueueBarrierWithWaitList(
6276 (events != NULL) ? (cl_uint) events->size() : 0,
6277 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6278 (event != NULL) ? &tmp : NULL),
6279 __ENQUEUE_BARRIER_WAIT_LIST_ERR);
6281 if (event != NULL && err == CL_SUCCESS)
6288 * Enqueues a command to indicate with which device a set of memory objects
6289 * should be associated.
6291 cl_int enqueueMigrateMemObjects(
6292 const VECTOR_CLASS<Memory> &memObjects,
6293 cl_mem_migration_flags flags,
6294 const VECTOR_CLASS<Event>* events = NULL,
6300 cl_mem* localMemObjects = static_cast<cl_mem*>(alloca(memObjects.size() * sizeof(cl_mem)));
6301 for( int i = 0; i < (int)memObjects.size(); ++i ) {
6302 localMemObjects[i] = memObjects[i]();
6306 cl_int err = detail::errHandler(
6307 ::clEnqueueMigrateMemObjects(
6309 (cl_uint)memObjects.size(),
6310 static_cast<const cl_mem*>(localMemObjects),
6312 (events != NULL) ? (cl_uint) events->size() : 0,
6313 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6314 (event != NULL) ? &tmp : NULL),
6315 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
6317 if (event != NULL && err == CL_SUCCESS)
6322 #endif // #if defined(CL_VERSION_1_2)
6324 cl_int enqueueNDRangeKernel(
6325 const Kernel& kernel,
6326 const NDRange& offset,
6327 const NDRange& global,
6328 const NDRange& local = NullRange,
6329 const VECTOR_CLASS<Event>* events = NULL,
6330 Event* event = NULL) const
6333 cl_int err = detail::errHandler(
6334 ::clEnqueueNDRangeKernel(
6335 object_, kernel(), (cl_uint) global.dimensions(),
6336 offset.dimensions() != 0 ? (const ::size_t*) offset : NULL,
6337 (const ::size_t*) global,
6338 local.dimensions() != 0 ? (const ::size_t*) local : NULL,
6339 (events != NULL) ? (cl_uint) events->size() : 0,
6340 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6341 (event != NULL) ? &tmp : NULL),
6342 __ENQUEUE_NDRANGE_KERNEL_ERR);
6344 if (event != NULL && err == CL_SUCCESS)
6351 const Kernel& kernel,
6352 const VECTOR_CLASS<Event>* events = NULL,
6353 Event* event = NULL) const
6356 cl_int err = detail::errHandler(
6359 (events != NULL) ? (cl_uint) events->size() : 0,
6360 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6361 (event != NULL) ? &tmp : NULL),
6362 __ENQUEUE_TASK_ERR);
6364 if (event != NULL && err == CL_SUCCESS)
6370 cl_int enqueueNativeKernel(
6371 void (CL_CALLBACK *userFptr)(void *),
6372 std::pair<void*, ::size_t> args,
6373 const VECTOR_CLASS<Memory>* mem_objects = NULL,
6374 const VECTOR_CLASS<const void*>* mem_locs = NULL,
6375 const VECTOR_CLASS<Event>* events = NULL,
6376 Event* event = NULL) const
6378 cl_mem * mems = (mem_objects != NULL && mem_objects->size() > 0)
6379 ? (cl_mem*) alloca(mem_objects->size() * sizeof(cl_mem))
6383 for (unsigned int i = 0; i < mem_objects->size(); i++) {
6384 mems[i] = ((*mem_objects)[i])();
6389 cl_int err = detail::errHandler(
6390 ::clEnqueueNativeKernel(
6391 object_, userFptr, args.first, args.second,
6392 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
6394 (mem_locs != NULL && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : NULL,
6395 (events != NULL) ? (cl_uint) events->size() : 0,
6396 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6397 (event != NULL) ? &tmp : NULL),
6398 __ENQUEUE_NATIVE_KERNEL);
6400 if (event != NULL && err == CL_SUCCESS)
6407 * Deprecated APIs for 1.2
6409 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
6410 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
6411 cl_int enqueueMarker(Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
6414 cl_int err = detail::errHandler(
6417 (event != NULL) ? &tmp : NULL),
6418 __ENQUEUE_MARKER_ERR);
6420 if (event != NULL && err == CL_SUCCESS)
6426 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
6427 cl_int enqueueWaitForEvents(const VECTOR_CLASS<Event>& events) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
6429 return detail::errHandler(
6430 ::clEnqueueWaitForEvents(
6432 (cl_uint) events.size(),
6433 events.size() > 0 ? (const cl_event*) &events.front() : NULL),
6434 __ENQUEUE_WAIT_FOR_EVENTS_ERR);
6436 #endif // #if defined(CL_VERSION_1_1)
6438 cl_int enqueueAcquireGLObjects(
6439 const VECTOR_CLASS<Memory>* mem_objects = NULL,
6440 const VECTOR_CLASS<Event>* events = NULL,
6441 Event* event = NULL) const
6444 cl_int err = detail::errHandler(
6445 ::clEnqueueAcquireGLObjects(
6447 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
6448 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
6449 (events != NULL) ? (cl_uint) events->size() : 0,
6450 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6451 (event != NULL) ? &tmp : NULL),
6452 __ENQUEUE_ACQUIRE_GL_ERR);
6454 if (event != NULL && err == CL_SUCCESS)
6460 cl_int enqueueReleaseGLObjects(
6461 const VECTOR_CLASS<Memory>* mem_objects = NULL,
6462 const VECTOR_CLASS<Event>* events = NULL,
6463 Event* event = NULL) const
6466 cl_int err = detail::errHandler(
6467 ::clEnqueueReleaseGLObjects(
6469 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
6470 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
6471 (events != NULL) ? (cl_uint) events->size() : 0,
6472 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6473 (event != NULL) ? &tmp : NULL),
6474 __ENQUEUE_RELEASE_GL_ERR);
6476 if (event != NULL && err == CL_SUCCESS)
6482 #if defined (USE_DX_INTEROP)
6483 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
6484 cl_command_queue command_queue, cl_uint num_objects,
6485 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
6486 const cl_event* event_wait_list, cl_event* event);
6487 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
6488 cl_command_queue command_queue, cl_uint num_objects,
6489 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
6490 const cl_event* event_wait_list, cl_event* event);
6492 cl_int enqueueAcquireD3D10Objects(
6493 const VECTOR_CLASS<Memory>* mem_objects = NULL,
6494 const VECTOR_CLASS<Event>* events = NULL,
6495 Event* event = NULL) const
6497 static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
6498 #if defined(CL_VERSION_1_2)
6499 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
6500 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
6501 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
6502 __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueAcquireD3D10ObjectsKHR);
6504 #if defined(CL_VERSION_1_1)
6505 __INIT_CL_EXT_FCN_PTR(clEnqueueAcquireD3D10ObjectsKHR);
6509 cl_int err = detail::errHandler(
6510 pfn_clEnqueueAcquireD3D10ObjectsKHR(
6512 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
6513 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
6514 (events != NULL) ? (cl_uint) events->size() : 0,
6515 (events != NULL) ? (cl_event*) &events->front() : NULL,
6516 (event != NULL) ? &tmp : NULL),
6517 __ENQUEUE_ACQUIRE_GL_ERR);
6519 if (event != NULL && err == CL_SUCCESS)
6525 cl_int enqueueReleaseD3D10Objects(
6526 const VECTOR_CLASS<Memory>* mem_objects = NULL,
6527 const VECTOR_CLASS<Event>* events = NULL,
6528 Event* event = NULL) const
6530 static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL;
6531 #if defined(CL_VERSION_1_2)
6532 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
6533 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
6534 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
6535 __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueReleaseD3D10ObjectsKHR);
6536 #endif // #if defined(CL_VERSION_1_2)
6537 #if defined(CL_VERSION_1_1)
6538 __INIT_CL_EXT_FCN_PTR(clEnqueueReleaseD3D10ObjectsKHR);
6539 #endif // #if defined(CL_VERSION_1_1)
6542 cl_int err = detail::errHandler(
6543 pfn_clEnqueueReleaseD3D10ObjectsKHR(
6545 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
6546 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
6547 (events != NULL) ? (cl_uint) events->size() : 0,
6548 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6549 (event != NULL) ? &tmp : NULL),
6550 __ENQUEUE_RELEASE_GL_ERR);
6552 if (event != NULL && err == CL_SUCCESS)
6560 * Deprecated APIs for 1.2
6562 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
6563 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
6564 cl_int enqueueBarrier() const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
6566 return detail::errHandler(
6567 ::clEnqueueBarrier(object_),
6568 __ENQUEUE_BARRIER_ERR);
6570 #endif // #if defined(CL_VERSION_1_1)
6572 cl_int flush() const
6574 return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
6577 cl_int finish() const
6579 return detail::errHandler(::clFinish(object_), __FINISH_ERR);
6584 #ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED
6585 __declspec(selectany) std::atomic<int> CommandQueue::default_initialized_;
6586 #else // !CL_HPP_CPP11_ATOMICS_SUPPORTED
6587 __declspec(selectany) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED;
6588 #endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED
6589 __declspec(selectany) CommandQueue CommandQueue::default_;
6590 __declspec(selectany) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS;
6592 #ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED
6593 __attribute__((weak)) std::atomic<int> CommandQueue::default_initialized_;
6594 #else // !CL_HPP_CPP11_ATOMICS_SUPPORTED
6595 __attribute__((weak)) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED;
6596 #endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED
6597 __attribute__((weak)) CommandQueue CommandQueue::default_;
6598 __attribute__((weak)) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS;
6601 template< typename IteratorType >
6603 const Context &context,
6604 IteratorType startIterator,
6605 IteratorType endIterator,
6610 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
6613 cl_mem_flags flags = 0;
6615 flags |= CL_MEM_READ_ONLY;
6618 flags |= CL_MEM_READ_WRITE;
6621 flags |= CL_MEM_USE_HOST_PTR;
6624 ::size_t size = sizeof(DataType)*(endIterator - startIterator);
6627 object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
6629 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
6632 detail::errHandler(error, __CREATE_BUFFER_ERR);
6638 CommandQueue queue(context, 0, &error);
6639 detail::errHandler(error, __CREATE_BUFFER_ERR);
6644 error = cl::copy(queue, startIterator, endIterator, *this);
6645 detail::errHandler(error, __CREATE_BUFFER_ERR);
6652 template< typename IteratorType >
6654 const CommandQueue &queue,
6655 IteratorType startIterator,
6656 IteratorType endIterator,
6661 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
6664 cl_mem_flags flags = 0;
6666 flags |= CL_MEM_READ_ONLY;
6669 flags |= CL_MEM_READ_WRITE;
6672 flags |= CL_MEM_USE_HOST_PTR;
6675 ::size_t size = sizeof(DataType)*(endIterator - startIterator);
6677 Context context = queue.getInfo<CL_QUEUE_CONTEXT>();
6680 object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
6683 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
6686 detail::errHandler(error, __CREATE_BUFFER_ERR);
6692 error = cl::copy(queue, startIterator, endIterator, *this);
6693 detail::errHandler(error, __CREATE_BUFFER_ERR);
6700 inline cl_int enqueueReadBuffer(
6701 const Buffer& buffer,
6706 const VECTOR_CLASS<Event>* events = NULL,
6707 Event* event = NULL)
6710 CommandQueue queue = CommandQueue::getDefault(&error);
6712 if (error != CL_SUCCESS) {
6716 return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event);
6719 inline cl_int enqueueWriteBuffer(
6720 const Buffer& buffer,
6725 const VECTOR_CLASS<Event>* events = NULL,
6726 Event* event = NULL)
6729 CommandQueue queue = CommandQueue::getDefault(&error);
6731 if (error != CL_SUCCESS) {
6735 return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event);
6738 inline void* enqueueMapBuffer(
6739 const Buffer& buffer,
6744 const VECTOR_CLASS<Event>* events = NULL,
6745 Event* event = NULL,
6749 CommandQueue queue = CommandQueue::getDefault(&error);
6750 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
6755 void * result = ::clEnqueueMapBuffer(
6756 queue(), buffer(), blocking, flags, offset, size,
6757 (events != NULL) ? (cl_uint) events->size() : 0,
6758 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6762 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
6769 inline cl_int enqueueUnmapMemObject(
6770 const Memory& memory,
6772 const VECTOR_CLASS<Event>* events = NULL,
6773 Event* event = NULL)
6776 CommandQueue queue = CommandQueue::getDefault(&error);
6777 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
6778 if (error != CL_SUCCESS) {
6783 cl_int err = detail::errHandler(
6784 ::clEnqueueUnmapMemObject(
6785 queue(), memory(), mapped_ptr,
6786 (events != NULL) ? (cl_uint) events->size() : 0,
6787 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
6788 (event != NULL) ? &tmp : NULL),
6789 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
6791 if (event != NULL && err == CL_SUCCESS)
6797 inline cl_int enqueueCopyBuffer(
6800 ::size_t src_offset,
6801 ::size_t dst_offset,
6803 const VECTOR_CLASS<Event>* events = NULL,
6804 Event* event = NULL)
6807 CommandQueue queue = CommandQueue::getDefault(&error);
6809 if (error != CL_SUCCESS) {
6813 return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event);
6817 * Blocking copy operation between iterators and a buffer.
6819 * Uses default command queue.
6821 template< typename IteratorType >
6822 inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
6825 CommandQueue queue = CommandQueue::getDefault(&error);
6826 if (error != CL_SUCCESS)
6829 return cl::copy(queue, startIterator, endIterator, buffer);
6833 * Blocking copy operation between iterators and a buffer.
6835 * Uses default command queue.
6837 template< typename IteratorType >
6838 inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
6841 CommandQueue queue = CommandQueue::getDefault(&error);
6842 if (error != CL_SUCCESS)
6845 return cl::copy(queue, buffer, startIterator, endIterator);
6849 * Blocking copy operation between iterators and a buffer.
6851 * Uses specified queue.
6853 template< typename IteratorType >
6854 inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
6856 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
6859 ::size_t length = endIterator-startIterator;
6860 ::size_t byteLength = length*sizeof(DataType);
6863 static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error));
6864 // if exceptions enabled, enqueueMapBuffer will throw
6865 if( error != CL_SUCCESS ) {
6868 #if defined(_MSC_VER)
6872 stdext::checked_array_iterator<DataType*>(
6875 std::copy(startIterator, endIterator, pointer);
6878 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
6879 // if exceptions enabled, enqueueUnmapMemObject will throw
6880 if( error != CL_SUCCESS ) {
6888 * Blocking copy operation between iterators and a buffer.
6890 * Uses specified queue.
6892 template< typename IteratorType >
6893 inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
6895 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
6898 ::size_t length = endIterator-startIterator;
6899 ::size_t byteLength = length*sizeof(DataType);
6902 static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error));
6903 // if exceptions enabled, enqueueMapBuffer will throw
6904 if( error != CL_SUCCESS ) {
6907 std::copy(pointer, pointer + length, startIterator);
6909 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
6910 // if exceptions enabled, enqueueUnmapMemObject will throw
6911 if( error != CL_SUCCESS ) {
6918 #if defined(CL_VERSION_1_1)
6919 inline cl_int enqueueReadBufferRect(
6920 const Buffer& buffer,
6922 const size_t<3>& buffer_offset,
6923 const size_t<3>& host_offset,
6924 const size_t<3>& region,
6925 ::size_t buffer_row_pitch,
6926 ::size_t buffer_slice_pitch,
6927 ::size_t host_row_pitch,
6928 ::size_t host_slice_pitch,
6930 const VECTOR_CLASS<Event>* events = NULL,
6931 Event* event = NULL)
6934 CommandQueue queue = CommandQueue::getDefault(&error);
6936 if (error != CL_SUCCESS) {
6940 return queue.enqueueReadBufferRect(
6955 inline cl_int enqueueWriteBufferRect(
6956 const Buffer& buffer,
6958 const size_t<3>& buffer_offset,
6959 const size_t<3>& host_offset,
6960 const size_t<3>& region,
6961 ::size_t buffer_row_pitch,
6962 ::size_t buffer_slice_pitch,
6963 ::size_t host_row_pitch,
6964 ::size_t host_slice_pitch,
6966 const VECTOR_CLASS<Event>* events = NULL,
6967 Event* event = NULL)
6970 CommandQueue queue = CommandQueue::getDefault(&error);
6972 if (error != CL_SUCCESS) {
6976 return queue.enqueueWriteBufferRect(
6991 inline cl_int enqueueCopyBufferRect(
6994 const size_t<3>& src_origin,
6995 const size_t<3>& dst_origin,
6996 const size_t<3>& region,
6997 ::size_t src_row_pitch,
6998 ::size_t src_slice_pitch,
6999 ::size_t dst_row_pitch,
7000 ::size_t dst_slice_pitch,
7001 const VECTOR_CLASS<Event>* events = NULL,
7002 Event* event = NULL)
7005 CommandQueue queue = CommandQueue::getDefault(&error);
7007 if (error != CL_SUCCESS) {
7011 return queue.enqueueCopyBufferRect(
7026 inline cl_int enqueueReadImage(
7029 const size_t<3>& origin,
7030 const size_t<3>& region,
7032 ::size_t slice_pitch,
7034 const VECTOR_CLASS<Event>* events = NULL,
7035 Event* event = NULL)
7038 CommandQueue queue = CommandQueue::getDefault(&error);
7040 if (error != CL_SUCCESS) {
7044 return queue.enqueueReadImage(
7056 inline cl_int enqueueWriteImage(
7059 const size_t<3>& origin,
7060 const size_t<3>& region,
7062 ::size_t slice_pitch,
7064 const VECTOR_CLASS<Event>* events = NULL,
7065 Event* event = NULL)
7068 CommandQueue queue = CommandQueue::getDefault(&error);
7070 if (error != CL_SUCCESS) {
7074 return queue.enqueueWriteImage(
7086 inline cl_int enqueueCopyImage(
7089 const size_t<3>& src_origin,
7090 const size_t<3>& dst_origin,
7091 const size_t<3>& region,
7092 const VECTOR_CLASS<Event>* events = NULL,
7093 Event* event = NULL)
7096 CommandQueue queue = CommandQueue::getDefault(&error);
7098 if (error != CL_SUCCESS) {
7102 return queue.enqueueCopyImage(
7112 inline cl_int enqueueCopyImageToBuffer(
7115 const size_t<3>& src_origin,
7116 const size_t<3>& region,
7117 ::size_t dst_offset,
7118 const VECTOR_CLASS<Event>* events = NULL,
7119 Event* event = NULL)
7122 CommandQueue queue = CommandQueue::getDefault(&error);
7124 if (error != CL_SUCCESS) {
7128 return queue.enqueueCopyImageToBuffer(
7138 inline cl_int enqueueCopyBufferToImage(
7141 ::size_t src_offset,
7142 const size_t<3>& dst_origin,
7143 const size_t<3>& region,
7144 const VECTOR_CLASS<Event>* events = NULL,
7145 Event* event = NULL)
7148 CommandQueue queue = CommandQueue::getDefault(&error);
7150 if (error != CL_SUCCESS) {
7154 return queue.enqueueCopyBufferToImage(
7165 inline cl_int flush(void)
7168 CommandQueue queue = CommandQueue::getDefault(&error);
7170 if (error != CL_SUCCESS) {
7174 return queue.flush();
7177 inline cl_int finish(void)
7180 CommandQueue queue = CommandQueue::getDefault(&error);
7182 if (error != CL_SUCCESS) {
7187 return queue.finish();
7190 // Kernel Functor support
7191 // New interface as of September 2011
7192 // Requires the C++11 std::tr1::function (note do not support TR1)
7193 // Visual Studio 2010 and GCC 4.2
7197 CommandQueue queue_;
7198 const NDRange offset_;
7199 const NDRange global_;
7200 const NDRange local_;
7201 VECTOR_CLASS<Event> events_;
7203 EnqueueArgs(NDRange global) :
7204 queue_(CommandQueue::getDefault()),
7212 EnqueueArgs(NDRange global, NDRange local) :
7213 queue_(CommandQueue::getDefault()),
7221 EnqueueArgs(NDRange offset, NDRange global, NDRange local) :
7222 queue_(CommandQueue::getDefault()),
7230 EnqueueArgs(Event e, NDRange global) :
7231 queue_(CommandQueue::getDefault()),
7236 events_.push_back(e);
7239 EnqueueArgs(Event e, NDRange global, NDRange local) :
7240 queue_(CommandQueue::getDefault()),
7245 events_.push_back(e);
7248 EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) :
7249 queue_(CommandQueue::getDefault()),
7254 events_.push_back(e);
7257 EnqueueArgs(const VECTOR_CLASS<Event> &events, NDRange global) :
7258 queue_(CommandQueue::getDefault()),
7267 EnqueueArgs(const VECTOR_CLASS<Event> &events, NDRange global, NDRange local) :
7268 queue_(CommandQueue::getDefault()),
7277 EnqueueArgs(const VECTOR_CLASS<Event> &events, NDRange offset, NDRange global, NDRange local) :
7278 queue_(CommandQueue::getDefault()),
7287 EnqueueArgs(CommandQueue &queue, NDRange global) :
7296 EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) :
7305 EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) :
7314 EnqueueArgs(CommandQueue &queue, Event e, NDRange global) :
7320 events_.push_back(e);
7323 EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) :
7329 events_.push_back(e);
7332 EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) :
7338 events_.push_back(e);
7341 EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS<Event> &events, NDRange global) :
7351 EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS<Event> &events, NDRange global, NDRange local) :
7361 EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS<Event> &events, NDRange offset, NDRange global, NDRange local) :
7376 template<int index, typename T0>
7379 static void set (Kernel kernel, T0 arg)
7381 kernel.setArg(index, arg);
7386 struct SetArg<index, NullType>
7388 static void set (Kernel, NullType)
7394 typename T0, typename T1, typename T2, typename T3,
7395 typename T4, typename T5, typename T6, typename T7,
7396 typename T8, typename T9, typename T10, typename T11,
7397 typename T12, typename T13, typename T14, typename T15,
7398 typename T16, typename T17, typename T18, typename T19,
7399 typename T20, typename T21, typename T22, typename T23,
7400 typename T24, typename T25, typename T26, typename T27,
7401 typename T28, typename T29, typename T30, typename T31
7403 class KernelFunctorGlobal
7409 KernelFunctorGlobal(
7414 KernelFunctorGlobal(
7415 const Program& program,
7416 const STRING_CLASS name,
7417 cl_int * err = NULL) :
7418 kernel_(program, name.c_str(), err)
7422 const EnqueueArgs& args,
7433 T10 t10 = NullType(),
7434 T11 t11 = NullType(),
7435 T12 t12 = NullType(),
7436 T13 t13 = NullType(),
7437 T14 t14 = NullType(),
7438 T15 t15 = NullType(),
7439 T16 t16 = NullType(),
7440 T17 t17 = NullType(),
7441 T18 t18 = NullType(),
7442 T19 t19 = NullType(),
7443 T20 t20 = NullType(),
7444 T21 t21 = NullType(),
7445 T22 t22 = NullType(),
7446 T23 t23 = NullType(),
7447 T24 t24 = NullType(),
7448 T25 t25 = NullType(),
7449 T26 t26 = NullType(),
7450 T27 t27 = NullType(),
7451 T28 t28 = NullType(),
7452 T29 t29 = NullType(),
7453 T30 t30 = NullType(),
7454 T31 t31 = NullType()
7458 SetArg<0, T0>::set(kernel_, t0);
7459 SetArg<1, T1>::set(kernel_, t1);
7460 SetArg<2, T2>::set(kernel_, t2);
7461 SetArg<3, T3>::set(kernel_, t3);
7462 SetArg<4, T4>::set(kernel_, t4);
7463 SetArg<5, T5>::set(kernel_, t5);
7464 SetArg<6, T6>::set(kernel_, t6);
7465 SetArg<7, T7>::set(kernel_, t7);
7466 SetArg<8, T8>::set(kernel_, t8);
7467 SetArg<9, T9>::set(kernel_, t9);
7468 SetArg<10, T10>::set(kernel_, t10);
7469 SetArg<11, T11>::set(kernel_, t11);
7470 SetArg<12, T12>::set(kernel_, t12);
7471 SetArg<13, T13>::set(kernel_, t13);
7472 SetArg<14, T14>::set(kernel_, t14);
7473 SetArg<15, T15>::set(kernel_, t15);
7474 SetArg<16, T16>::set(kernel_, t16);
7475 SetArg<17, T17>::set(kernel_, t17);
7476 SetArg<18, T18>::set(kernel_, t18);
7477 SetArg<19, T19>::set(kernel_, t19);
7478 SetArg<20, T20>::set(kernel_, t20);
7479 SetArg<21, T21>::set(kernel_, t21);
7480 SetArg<22, T22>::set(kernel_, t22);
7481 SetArg<23, T23>::set(kernel_, t23);
7482 SetArg<24, T24>::set(kernel_, t24);
7483 SetArg<25, T25>::set(kernel_, t25);
7484 SetArg<26, T26>::set(kernel_, t26);
7485 SetArg<27, T27>::set(kernel_, t27);
7486 SetArg<28, T28>::set(kernel_, t28);
7487 SetArg<29, T29>::set(kernel_, t29);
7488 SetArg<30, T30>::set(kernel_, t30);
7489 SetArg<31, T31>::set(kernel_, t31);
7491 args.queue_.enqueueNDRangeKernel(
7504 //------------------------------------------------------------------------------------------------------
7540 struct functionImplementation_
7542 typedef detail::KernelFunctorGlobal<
7576 FunctorType functor_;
7578 functionImplementation_(const FunctorType &functor) :
7582 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 32))
7583 // Fail variadic expansion for dev11
7584 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.");
7589 //! \brief Return type of the functor
7590 typedef Event result_type;
7592 //! \brief Function signature of kernel functor with no event dependency.
7593 typedef Event type_(
7629 const EnqueueArgs& enqueueArgs,
7734 struct functionImplementation_
7768 typedef detail::KernelFunctorGlobal<
7800 NullType> FunctorType;
7802 FunctorType functor_;
7804 functionImplementation_(const FunctorType &functor) :
7808 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 31))
7809 // Fail variadic expansion for dev11
7810 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.");
7815 //! \brief Return type of the functor
7816 typedef Event result_type;
7818 //! \brief Function signature of kernel functor with no event dependency.
7819 typedef Event type_(
7854 const EnqueueArgs& enqueueArgs,
7956 struct functionImplementation_
7990 typedef detail::KernelFunctorGlobal<
8022 NullType> FunctorType;
8024 FunctorType functor_;
8026 functionImplementation_(const FunctorType &functor) :
8030 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 30))
8031 // Fail variadic expansion for dev11
8032 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.");
8037 //! \brief Return type of the functor
8038 typedef Event result_type;
8040 //! \brief Function signature of kernel functor with no event dependency.
8041 typedef Event type_(
8075 const EnqueueArgs& enqueueArgs,
8174 struct functionImplementation_
8208 typedef detail::KernelFunctorGlobal<
8240 NullType> FunctorType;
8242 FunctorType functor_;
8244 functionImplementation_(const FunctorType &functor) :
8248 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 29))
8249 // Fail variadic expansion for dev11
8250 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.");
8255 //! \brief Return type of the functor
8256 typedef Event result_type;
8258 //! \brief Function signature of kernel functor with no event dependency.
8259 typedef Event type_(
8292 const EnqueueArgs& enqueueArgs,
8388 struct functionImplementation_
8422 typedef detail::KernelFunctorGlobal<
8454 NullType> FunctorType;
8456 FunctorType functor_;
8458 functionImplementation_(const FunctorType &functor) :
8462 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 28))
8463 // Fail variadic expansion for dev11
8464 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.");
8469 //! \brief Return type of the functor
8470 typedef Event result_type;
8472 //! \brief Function signature of kernel functor with no event dependency.
8473 typedef Event type_(
8505 const EnqueueArgs& enqueueArgs,
8598 struct functionImplementation_
8632 typedef detail::KernelFunctorGlobal<
8664 NullType> FunctorType;
8666 FunctorType functor_;
8668 functionImplementation_(const FunctorType &functor) :
8672 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 27))
8673 // Fail variadic expansion for dev11
8674 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.");
8679 //! \brief Return type of the functor
8680 typedef Event result_type;
8682 //! \brief Function signature of kernel functor with no event dependency.
8683 typedef Event type_(
8714 const EnqueueArgs& enqueueArgs,
8804 struct functionImplementation_
8838 typedef detail::KernelFunctorGlobal<
8870 NullType> FunctorType;
8872 FunctorType functor_;
8874 functionImplementation_(const FunctorType &functor) :
8878 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 26))
8879 // Fail variadic expansion for dev11
8880 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.");
8885 //! \brief Return type of the functor
8886 typedef Event result_type;
8888 //! \brief Function signature of kernel functor with no event dependency.
8889 typedef Event type_(
8919 const EnqueueArgs& enqueueArgs,
9006 struct functionImplementation_
9040 typedef detail::KernelFunctorGlobal<
9072 NullType> FunctorType;
9074 FunctorType functor_;
9076 functionImplementation_(const FunctorType &functor) :
9080 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 25))
9081 // Fail variadic expansion for dev11
9082 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.");
9087 //! \brief Return type of the functor
9088 typedef Event result_type;
9090 //! \brief Function signature of kernel functor with no event dependency.
9091 typedef Event type_(
9120 const EnqueueArgs& enqueueArgs,
9204 struct functionImplementation_
9238 typedef detail::KernelFunctorGlobal<
9270 NullType> FunctorType;
9272 FunctorType functor_;
9274 functionImplementation_(const FunctorType &functor) :
9278 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 24))
9279 // Fail variadic expansion for dev11
9280 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.");
9285 //! \brief Return type of the functor
9286 typedef Event result_type;
9288 //! \brief Function signature of kernel functor with no event dependency.
9289 typedef Event type_(
9317 const EnqueueArgs& enqueueArgs,
9398 struct functionImplementation_
9432 typedef detail::KernelFunctorGlobal<
9464 NullType> FunctorType;
9466 FunctorType functor_;
9468 functionImplementation_(const FunctorType &functor) :
9472 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 23))
9473 // Fail variadic expansion for dev11
9474 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.");
9479 //! \brief Return type of the functor
9480 typedef Event result_type;
9482 //! \brief Function signature of kernel functor with no event dependency.
9483 typedef Event type_(
9510 const EnqueueArgs& enqueueArgs,
9588 struct functionImplementation_
9622 typedef detail::KernelFunctorGlobal<
9654 NullType> FunctorType;
9656 FunctorType functor_;
9658 functionImplementation_(const FunctorType &functor) :
9662 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 22))
9663 // Fail variadic expansion for dev11
9664 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.");
9669 //! \brief Return type of the functor
9670 typedef Event result_type;
9672 //! \brief Function signature of kernel functor with no event dependency.
9673 typedef Event type_(
9699 const EnqueueArgs& enqueueArgs,
9774 struct functionImplementation_
9808 typedef detail::KernelFunctorGlobal<
9840 NullType> FunctorType;
9842 FunctorType functor_;
9844 functionImplementation_(const FunctorType &functor) :
9848 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 21))
9849 // Fail variadic expansion for dev11
9850 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.");
9855 //! \brief Return type of the functor
9856 typedef Event result_type;
9858 //! \brief Function signature of kernel functor with no event dependency.
9859 typedef Event type_(
9884 const EnqueueArgs& enqueueArgs,
9956 struct functionImplementation_
9990 typedef detail::KernelFunctorGlobal<
10022 NullType> FunctorType;
10024 FunctorType functor_;
10026 functionImplementation_(const FunctorType &functor) :
10030 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 20))
10031 // Fail variadic expansion for dev11
10032 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.");
10037 //! \brief Return type of the functor
10038 typedef Event result_type;
10040 //! \brief Function signature of kernel functor with no event dependency.
10041 typedef Event type_(
10042 const EnqueueArgs&,
10065 const EnqueueArgs& enqueueArgs,
10134 struct functionImplementation_
10168 typedef detail::KernelFunctorGlobal<
10200 NullType> FunctorType;
10202 FunctorType functor_;
10204 functionImplementation_(const FunctorType &functor) :
10208 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 19))
10209 // Fail variadic expansion for dev11
10210 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.");
10215 //! \brief Return type of the functor
10216 typedef Event result_type;
10218 //! \brief Function signature of kernel functor with no event dependency.
10219 typedef Event type_(
10220 const EnqueueArgs&,
10242 const EnqueueArgs& enqueueArgs,
10308 struct functionImplementation_
10342 typedef detail::KernelFunctorGlobal<
10374 NullType> FunctorType;
10376 FunctorType functor_;
10378 functionImplementation_(const FunctorType &functor) :
10382 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 18))
10383 // Fail variadic expansion for dev11
10384 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.");
10389 //! \brief Return type of the functor
10390 typedef Event result_type;
10392 //! \brief Function signature of kernel functor with no event dependency.
10393 typedef Event type_(
10394 const EnqueueArgs&,
10415 const EnqueueArgs& enqueueArgs,
10478 struct functionImplementation_
10512 typedef detail::KernelFunctorGlobal<
10544 NullType> FunctorType;
10546 FunctorType functor_;
10548 functionImplementation_(const FunctorType &functor) :
10552 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 17))
10553 // Fail variadic expansion for dev11
10554 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.");
10559 //! \brief Return type of the functor
10560 typedef Event result_type;
10562 //! \brief Function signature of kernel functor with no event dependency.
10563 typedef Event type_(
10564 const EnqueueArgs&,
10584 const EnqueueArgs& enqueueArgs,
10644 struct functionImplementation_
10678 typedef detail::KernelFunctorGlobal<
10710 NullType> FunctorType;
10712 FunctorType functor_;
10714 functionImplementation_(const FunctorType &functor) :
10718 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 16))
10719 // Fail variadic expansion for dev11
10720 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.");
10725 //! \brief Return type of the functor
10726 typedef Event result_type;
10728 //! \brief Function signature of kernel functor with no event dependency.
10729 typedef Event type_(
10730 const EnqueueArgs&,
10749 const EnqueueArgs& enqueueArgs,
10806 struct functionImplementation_
10840 typedef detail::KernelFunctorGlobal<
10872 NullType> FunctorType;
10874 FunctorType functor_;
10876 functionImplementation_(const FunctorType &functor) :
10880 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 15))
10881 // Fail variadic expansion for dev11
10882 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.");
10887 //! \brief Return type of the functor
10888 typedef Event result_type;
10890 //! \brief Function signature of kernel functor with no event dependency.
10891 typedef Event type_(
10892 const EnqueueArgs&,
10910 const EnqueueArgs& enqueueArgs,
10964 struct functionImplementation_
10998 typedef detail::KernelFunctorGlobal<
11030 NullType> FunctorType;
11032 FunctorType functor_;
11034 functionImplementation_(const FunctorType &functor) :
11038 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 14))
11039 // Fail variadic expansion for dev11
11040 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.");
11045 //! \brief Return type of the functor
11046 typedef Event result_type;
11048 //! \brief Function signature of kernel functor with no event dependency.
11049 typedef Event type_(
11050 const EnqueueArgs&,
11067 const EnqueueArgs& enqueueArgs,
11118 struct functionImplementation_
11152 typedef detail::KernelFunctorGlobal<
11184 NullType> FunctorType;
11186 FunctorType functor_;
11188 functionImplementation_(const FunctorType &functor) :
11192 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 13))
11193 // Fail variadic expansion for dev11
11194 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.");
11199 //! \brief Return type of the functor
11200 typedef Event result_type;
11202 //! \brief Function signature of kernel functor with no event dependency.
11203 typedef Event type_(
11204 const EnqueueArgs&,
11220 const EnqueueArgs& enqueueArgs,
11268 struct functionImplementation_
11302 typedef detail::KernelFunctorGlobal<
11334 NullType> FunctorType;
11336 FunctorType functor_;
11338 functionImplementation_(const FunctorType &functor) :
11342 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 12))
11343 // Fail variadic expansion for dev11
11344 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.");
11349 //! \brief Return type of the functor
11350 typedef Event result_type;
11352 //! \brief Function signature of kernel functor with no event dependency.
11353 typedef Event type_(
11354 const EnqueueArgs&,
11369 const EnqueueArgs& enqueueArgs,
11414 struct functionImplementation_
11448 typedef detail::KernelFunctorGlobal<
11480 NullType> FunctorType;
11482 FunctorType functor_;
11484 functionImplementation_(const FunctorType &functor) :
11488 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 11))
11489 // Fail variadic expansion for dev11
11490 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.");
11495 //! \brief Return type of the functor
11496 typedef Event result_type;
11498 //! \brief Function signature of kernel functor with no event dependency.
11499 typedef Event type_(
11500 const EnqueueArgs&,
11514 const EnqueueArgs& enqueueArgs,
11556 struct functionImplementation_
11590 typedef detail::KernelFunctorGlobal<
11622 NullType> FunctorType;
11624 FunctorType functor_;
11626 functionImplementation_(const FunctorType &functor) :
11630 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 10))
11631 // Fail variadic expansion for dev11
11632 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.");
11637 //! \brief Return type of the functor
11638 typedef Event result_type;
11640 //! \brief Function signature of kernel functor with no event dependency.
11641 typedef Event type_(
11642 const EnqueueArgs&,
11655 const EnqueueArgs& enqueueArgs,
11694 struct functionImplementation_
11728 typedef detail::KernelFunctorGlobal<
11760 NullType> FunctorType;
11762 FunctorType functor_;
11764 functionImplementation_(const FunctorType &functor) :
11768 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 9))
11769 // Fail variadic expansion for dev11
11770 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.");
11775 //! \brief Return type of the functor
11776 typedef Event result_type;
11778 //! \brief Function signature of kernel functor with no event dependency.
11779 typedef Event type_(
11780 const EnqueueArgs&,
11792 const EnqueueArgs& enqueueArgs,
11828 struct functionImplementation_
11862 typedef detail::KernelFunctorGlobal<
11894 NullType> FunctorType;
11896 FunctorType functor_;
11898 functionImplementation_(const FunctorType &functor) :
11902 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 8))
11903 // Fail variadic expansion for dev11
11904 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.");
11909 //! \brief Return type of the functor
11910 typedef Event result_type;
11912 //! \brief Function signature of kernel functor with no event dependency.
11913 typedef Event type_(
11914 const EnqueueArgs&,
11925 const EnqueueArgs& enqueueArgs,
11958 struct functionImplementation_
11992 typedef detail::KernelFunctorGlobal<
12024 NullType> FunctorType;
12026 FunctorType functor_;
12028 functionImplementation_(const FunctorType &functor) :
12032 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 7))
12033 // Fail variadic expansion for dev11
12034 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.");
12039 //! \brief Return type of the functor
12040 typedef Event result_type;
12042 //! \brief Function signature of kernel functor with no event dependency.
12043 typedef Event type_(
12044 const EnqueueArgs&,
12054 const EnqueueArgs& enqueueArgs,
12084 struct functionImplementation_
12118 typedef detail::KernelFunctorGlobal<
12150 NullType> FunctorType;
12152 FunctorType functor_;
12154 functionImplementation_(const FunctorType &functor) :
12158 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 6))
12159 // Fail variadic expansion for dev11
12160 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.");
12165 //! \brief Return type of the functor
12166 typedef Event result_type;
12168 //! \brief Function signature of kernel functor with no event dependency.
12169 typedef Event type_(
12170 const EnqueueArgs&,
12179 const EnqueueArgs& enqueueArgs,
12206 struct functionImplementation_
12240 typedef detail::KernelFunctorGlobal<
12272 NullType> FunctorType;
12274 FunctorType functor_;
12276 functionImplementation_(const FunctorType &functor) :
12280 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 5))
12281 // Fail variadic expansion for dev11
12282 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.");
12287 //! \brief Return type of the functor
12288 typedef Event result_type;
12290 //! \brief Function signature of kernel functor with no event dependency.
12291 typedef Event type_(
12292 const EnqueueArgs&,
12300 const EnqueueArgs& enqueueArgs,
12324 struct functionImplementation_
12358 typedef detail::KernelFunctorGlobal<
12390 NullType> FunctorType;
12392 FunctorType functor_;
12394 functionImplementation_(const FunctorType &functor) :
12398 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 4))
12399 // Fail variadic expansion for dev11
12400 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.");
12405 //! \brief Return type of the functor
12406 typedef Event result_type;
12408 //! \brief Function signature of kernel functor with no event dependency.
12409 typedef Event type_(
12410 const EnqueueArgs&,
12417 const EnqueueArgs& enqueueArgs,
12438 struct functionImplementation_
12472 typedef detail::KernelFunctorGlobal<
12504 NullType> FunctorType;
12506 FunctorType functor_;
12508 functionImplementation_(const FunctorType &functor) :
12512 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 3))
12513 // Fail variadic expansion for dev11
12514 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.");
12519 //! \brief Return type of the functor
12520 typedef Event result_type;
12522 //! \brief Function signature of kernel functor with no event dependency.
12523 typedef Event type_(
12524 const EnqueueArgs&,
12530 const EnqueueArgs& enqueueArgs,
12548 struct functionImplementation_
12582 typedef detail::KernelFunctorGlobal<
12614 NullType> FunctorType;
12616 FunctorType functor_;
12618 functionImplementation_(const FunctorType &functor) :
12622 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 2))
12623 // Fail variadic expansion for dev11
12624 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.");
12629 //! \brief Return type of the functor
12630 typedef Event result_type;
12632 //! \brief Function signature of kernel functor with no event dependency.
12633 typedef Event type_(
12634 const EnqueueArgs&,
12639 const EnqueueArgs& enqueueArgs,
12654 struct functionImplementation_
12688 typedef detail::KernelFunctorGlobal<
12720 NullType> FunctorType;
12722 FunctorType functor_;
12724 functionImplementation_(const FunctorType &functor) :
12728 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 1))
12729 // Fail variadic expansion for dev11
12730 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.");
12735 //! \brief Return type of the functor
12736 typedef Event result_type;
12738 //! \brief Function signature of kernel functor with no event dependency.
12739 typedef Event type_(
12740 const EnqueueArgs&,
12744 const EnqueueArgs& enqueueArgs,
12759 } // namespace detail
12761 //----------------------------------------------------------------------------------------------
12764 typename T0, typename T1 = detail::NullType, typename T2 = detail::NullType,
12765 typename T3 = detail::NullType, typename T4 = detail::NullType,
12766 typename T5 = detail::NullType, typename T6 = detail::NullType,
12767 typename T7 = detail::NullType, typename T8 = detail::NullType,
12768 typename T9 = detail::NullType, typename T10 = detail::NullType,
12769 typename T11 = detail::NullType, typename T12 = detail::NullType,
12770 typename T13 = detail::NullType, typename T14 = detail::NullType,
12771 typename T15 = detail::NullType, typename T16 = detail::NullType,
12772 typename T17 = detail::NullType, typename T18 = detail::NullType,
12773 typename T19 = detail::NullType, typename T20 = detail::NullType,
12774 typename T21 = detail::NullType, typename T22 = detail::NullType,
12775 typename T23 = detail::NullType, typename T24 = detail::NullType,
12776 typename T25 = detail::NullType, typename T26 = detail::NullType,
12777 typename T27 = detail::NullType, typename T28 = detail::NullType,
12778 typename T29 = detail::NullType, typename T30 = detail::NullType,
12779 typename T31 = detail::NullType
12781 struct make_kernel :
12782 public detail::functionImplementation_<
12786 T12, T13, T14, T15,
12787 T16, T17, T18, T19,
12788 T20, T21, T22, T23,
12789 T24, T25, T26, T27,
12794 typedef detail::KernelFunctorGlobal<
12798 T12, T13, T14, T15,
12799 T16, T17, T18, T19,
12800 T20, T21, T22, T23,
12801 T24, T25, T26, T27,
12806 const Program& program,
12807 const STRING_CLASS name,
12808 cl_int * err = NULL) :
12809 detail::functionImplementation_<
12813 T12, T13, T14, T15,
12814 T16, T17, T18, T19,
12815 T20, T21, T22, T23,
12816 T24, T25, T26, T27,
12819 FunctorType(program, name, err))
12823 const Kernel kernel) :
12824 detail::functionImplementation_<
12828 T12, T13, T14, T15,
12829 T16, T17, T18, T19,
12830 T20, T21, T22, T23,
12831 T24, T25, T26, T27,
12834 FunctorType(kernel))
12839 //----------------------------------------------------------------------------------------------------------------------
12842 #if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
12843 #undef __GET_DEVICE_INFO_ERR
12844 #undef __GET_PLATFORM_INFO_ERR
12845 #undef __GET_DEVICE_IDS_ERR
12846 #undef __GET_CONTEXT_INFO_ERR
12847 #undef __GET_EVENT_INFO_ERR
12848 #undef __GET_EVENT_PROFILE_INFO_ERR
12849 #undef __GET_MEM_OBJECT_INFO_ERR
12850 #undef __GET_IMAGE_INFO_ERR
12851 #undef __GET_SAMPLER_INFO_ERR
12852 #undef __GET_KERNEL_INFO_ERR
12853 #undef __GET_KERNEL_ARG_INFO_ERR
12854 #undef __GET_KERNEL_WORK_GROUP_INFO_ERR
12855 #undef __GET_PROGRAM_INFO_ERR
12856 #undef __GET_PROGRAM_BUILD_INFO_ERR
12857 #undef __GET_COMMAND_QUEUE_INFO_ERR
12859 #undef __CREATE_CONTEXT_ERR
12860 #undef __CREATE_CONTEXT_FROM_TYPE_ERR
12861 #undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
12863 #undef __CREATE_BUFFER_ERR
12864 #undef __CREATE_SUBBUFFER_ERR
12865 #undef __CREATE_IMAGE2D_ERR
12866 #undef __CREATE_IMAGE3D_ERR
12867 #undef __CREATE_SAMPLER_ERR
12868 #undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
12870 #undef __CREATE_USER_EVENT_ERR
12871 #undef __SET_USER_EVENT_STATUS_ERR
12872 #undef __SET_EVENT_CALLBACK_ERR
12873 #undef __SET_PRINTF_CALLBACK_ERR
12875 #undef __WAIT_FOR_EVENTS_ERR
12877 #undef __CREATE_KERNEL_ERR
12878 #undef __SET_KERNEL_ARGS_ERR
12879 #undef __CREATE_PROGRAM_WITH_SOURCE_ERR
12880 #undef __CREATE_PROGRAM_WITH_BINARY_ERR
12881 #undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR
12882 #undef __BUILD_PROGRAM_ERR
12883 #undef __CREATE_KERNELS_IN_PROGRAM_ERR
12885 #undef __CREATE_COMMAND_QUEUE_ERR
12886 #undef __SET_COMMAND_QUEUE_PROPERTY_ERR
12887 #undef __ENQUEUE_READ_BUFFER_ERR
12888 #undef __ENQUEUE_WRITE_BUFFER_ERR
12889 #undef __ENQUEUE_READ_BUFFER_RECT_ERR
12890 #undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
12891 #undef __ENQEUE_COPY_BUFFER_ERR
12892 #undef __ENQEUE_COPY_BUFFER_RECT_ERR
12893 #undef __ENQUEUE_READ_IMAGE_ERR
12894 #undef __ENQUEUE_WRITE_IMAGE_ERR
12895 #undef __ENQUEUE_COPY_IMAGE_ERR
12896 #undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
12897 #undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
12898 #undef __ENQUEUE_MAP_BUFFER_ERR
12899 #undef __ENQUEUE_MAP_IMAGE_ERR
12900 #undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
12901 #undef __ENQUEUE_NDRANGE_KERNEL_ERR
12902 #undef __ENQUEUE_TASK_ERR
12903 #undef __ENQUEUE_NATIVE_KERNEL
12905 #undef __CL_EXPLICIT_CONSTRUCTORS
12907 #undef __UNLOAD_COMPILER_ERR
12908 #endif //__CL_USER_OVERRIDE_ERROR_STRINGS
12910 #undef __CL_FUNCTION_TYPE
12914 * Deprecated APIs for 1.2
12916 #if defined(CL_VERSION_1_1)
12917 #undef __INIT_CL_EXT_FCN_PTR
12918 #endif // #if defined(CL_VERSION_1_1)
12919 #undef __CREATE_SUB_DEVICES
12921 #if defined(USE_CL_DEVICE_FISSION)
12922 #undef __PARAM_NAME_DEVICE_FISSION
12923 #endif // USE_CL_DEVICE_FISSION
12925 #undef __DEFAULT_NOT_INITIALIZED
12926 #undef __DEFAULT_BEING_INITIALIZED
12927 #undef __DEFAULT_INITIALIZED
12929 #undef CL_HPP_RVALUE_REFERENCES_SUPPORTED
12930 #undef CL_HPP_NOEXCEPT