00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00140 #ifndef CL_HPP_
00141 #define CL_HPP_
00142
00143 #ifdef _WIN32
00144 #include <windows.h>
00145 #include <malloc.h>
00146 #if defined(USE_DX_INTEROP)
00147 #include <CL/cl_d3d10.h>
00148 #endif
00149 #endif // _WIN32
00150
00151
00152 #if defined(USE_CL_DEVICE_FISSION)
00153 #include <CL/cl_ext.h>
00154 #endif
00155
00156 #if defined(__APPLE__) || defined(__MACOSX)
00157 #include <OpenGL/OpenGL.h>
00158 #include <OpenCL/opencl.h>
00159 #else
00160 #include <GL/gl.h>
00161 #include <CL/opencl.h>
00162 #endif // !__APPLE__
00163
00164 #if !defined(CL_CALLBACK)
00165 #define CL_CALLBACK
00166 #endif //CL_CALLBACK
00167
00168 #include <utility>
00169
00170 #if !defined(__NO_STD_VECTOR)
00171 #include <vector>
00172 #endif
00173
00174 #if !defined(__NO_STD_STRING)
00175 #include <string>
00176 #endif
00177
00178 #if defined(linux) || defined(__APPLE__) || defined(__MACOSX)
00179 # include <alloca.h>
00180 #endif // linux
00181
00182 #include <cstring>
00183
00189 namespace cl {
00190
00191 #define __INIT_CL_EXT_FCN_PTR(name) \
00192 if(!pfn_##name) { \
00193 pfn_##name = (PFN_##name) \
00194 clGetExtensionFunctionAddress(#name); \
00195 if(!pfn_##name) { \
00196 } \
00197 }
00198
00199 class Program;
00200 class Device;
00201 class Context;
00202 class CommandQueue;
00203 class Memory;
00204
00205 #if defined(__CL_ENABLE_EXCEPTIONS)
00206 #include <exception>
00210 class Error : public std::exception
00211 {
00212 private:
00213 cl_int err_;
00214 const char * errStr_;
00215 public:
00219 Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr)
00220 {}
00221
00222 ~Error() throw() {}
00223
00228 virtual const char * what() const throw ()
00229 {
00230 if (errStr_ == NULL) {
00231 return "empty";
00232 }
00233 else {
00234 return errStr_;
00235 }
00236 }
00237
00242 const cl_int err(void) const { return err_; }
00243 };
00244
00245 #define __ERR_STR(x) #x
00246 #else
00247 #define __ERR_STR(x) NULL
00248 #endif // __CL_ENABLE_EXCEPTIONS
00249
00251 #if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
00252 #define __GET_DEVICE_INFO_ERR __ERR_STR(clgetDeviceInfo)
00253 #define __GET_PLATFORM_INFO_ERR __ERR_STR(clGetPlatformInfo)
00254 #define __GET_DEVICE_IDS_ERR __ERR_STR(clGetDeviceIDs)
00255 #define __GET_PLATFORM_IDS_ERR __ERR_STR(clGetPlatformIDs)
00256 #define __GET_CONTEXT_INFO_ERR __ERR_STR(clGetContextInfo)
00257 #define __GET_EVENT_INFO_ERR __ERR_STR(clGetEventInfo)
00258 #define __GET_EVENT_PROFILE_INFO_ERR __ERR_STR(clGetEventProfileInfo)
00259 #define __GET_MEM_OBJECT_INFO_ERR __ERR_STR(clGetMemObjectInfo)
00260 #define __GET_IMAGE_INFO_ERR __ERR_STR(clGetImageInfo)
00261 #define __GET_SAMPLER_INFO_ERR __ERR_STR(clGetSamplerInfo)
00262 #define __GET_KERNEL_INFO_ERR __ERR_STR(clGetKernelInfo)
00263 #define __GET_KERNEL_WORK_GROUP_INFO_ERR __ERR_STR(clGetKernelWorkGroupInfo)
00264 #define __GET_PROGRAM_INFO_ERR __ERR_STR(clGetProgramInfo)
00265 #define __GET_PROGRAM_BUILD_INFO_ERR __ERR_STR(clGetProgramBuildInfo)
00266 #define __GET_COMMAND_QUEUE_INFO_ERR __ERR_STR(clGetCommandQueueInfo)
00267
00268 #define __CREATE_CONTEXT_FROM_TYPE_ERR __ERR_STR(clCreateContextFromType)
00269 #define __GET_SUPPORTED_IMAGE_FORMATS_ERR __ERR_STR(clGetSupportedImageFormats)
00270
00271 #define __CREATE_BUFFER_ERR __ERR_STR(clCreateBuffer)
00272 #define __CREATE_SUBBUFFER_ERR __ERR_STR(clCreateSubBuffer)
00273 #define __CREATE_GL_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer)
00274 #define __GET_GL_OBJECT_INFO_ERR __ERR_STR(clGetGLObjectInfo)
00275 #define __CREATE_IMAGE2D_ERR __ERR_STR(clCreateImage2D)
00276 #define __CREATE_IMAGE3D_ERR __ERR_STR(clCreateImage3D)
00277 #define __CREATE_SAMPLER_ERR __ERR_STR(clCreateSampler)
00278 #define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR __ERR_STR(clSetMemObjectDestructorCallback)
00279
00280 #define __CREATE_USER_EVENT_ERR __ERR_STR(clCreateUserEvent)
00281 #define __SET_USER_EVENT_STATUS_ERR __ERR_STR(clSetUserEventStatus)
00282 #define __SET_EVENT_CALLBACK_ERR __ERR_STR(clSetEventCallback)
00283 #define __WAIT_FOR_EVENTS_ERR __ERR_STR(clWaitForEvents)
00284
00285 #define __CREATE_KERNEL_ERR __ERR_STR(clCreateKernel)
00286 #define __SET_KERNEL_ARGS_ERR __ERR_STR(clSetKernelArg)
00287 #define __CREATE_PROGRAM_WITH_SOURCE_ERR __ERR_STR(clCreateProgramWithSource)
00288 #define __CREATE_PROGRAM_WITH_BINARY_ERR __ERR_STR(clCreateProgramWithBinary)
00289 #define __BUILD_PROGRAM_ERR __ERR_STR(clBuildProgram)
00290 #define __CREATE_KERNELS_IN_PROGRAM_ERR __ERR_STR(clCreateKernelsInProgram)
00291
00292 #define __CREATE_COMMAND_QUEUE_ERR __ERR_STR(clCreateCommandQueue)
00293 #define __SET_COMMAND_QUEUE_PROPERTY_ERR __ERR_STR(clSetCommandQueueProperty)
00294 #define __ENQUEUE_READ_BUFFER_ERR __ERR_STR(clEnqueueReadBuffer)
00295 #define __ENQUEUE_READ_BUFFER_RECT_ERR __ERR_STR(clEnqueueReadBufferRect)
00296 #define __ENQUEUE_WRITE_BUFFER_ERR __ERR_STR(clEnqueueWriteBuffer)
00297 #define __ENQUEUE_WRITE_BUFFER_RECT_ERR __ERR_STR(clEnqueueWriteBufferRect)
00298 #define __ENQEUE_COPY_BUFFER_ERR __ERR_STR(clEnqueueCopyBuffer)
00299 #define __ENQEUE_COPY_BUFFER_RECT_ERR __ERR_STR(clEnqueueCopyBufferRect)
00300 #define __ENQUEUE_READ_IMAGE_ERR __ERR_STR(clEnqueueReadImage)
00301 #define __ENQUEUE_WRITE_IMAGE_ERR __ERR_STR(clEnqueueWriteImage)
00302 #define __ENQUEUE_COPY_IMAGE_ERR __ERR_STR(clEnqueueCopyImage)
00303 #define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR __ERR_STR(clEnqueueCopyImageToBuffer)
00304 #define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR __ERR_STR(clEnqueueCopyBufferToImage)
00305 #define __ENQUEUE_MAP_BUFFER_ERR __ERR_STR(clEnqueueMapBuffer)
00306 #define __ENQUEUE_MAP_IMAGE_ERR __ERR_STR(clEnqueueMapImage)
00307 #define __ENQUEUE_UNMAP_MEM_OBJECT_ERR __ERR_STR(clEnqueueUnMapMemObject)
00308 #define __ENQUEUE_NDRANGE_KERNEL_ERR __ERR_STR(clEnqueueNDRangeKernel)
00309 #define __ENQUEUE_TASK_ERR __ERR_STR(clEnqueueTask)
00310 #define __ENQUEUE_NATIVE_KERNEL __ERR_STR(clEnqueueNativeKernel)
00311 #define __ENQUEUE_MARKER_ERR __ERR_STR(clEnqueueMarker)
00312 #define __ENQUEUE_WAIT_FOR_EVENTS_ERR __ERR_STR(clEnqueueWaitForEvents)
00313 #define __ENQUEUE_BARRIER_ERR __ERR_STR(clEnqueueBarrier)
00314
00315 #define __ENQUEUE_ACQUIRE_GL_ERR __ERR_STR(clEnqueueAcquireGLObjects)
00316 #define __ENQUEUE_RELEASE_GL_ERR __ERR_STR(clEnqueueReleaseGLObjects)
00317
00318 #define __UNLOAD_COMPILER_ERR __ERR_STR(clUnloadCompiler)
00319
00320 #define __FLUSH_ERR __ERR_STR(clFlush)
00321 #define __FINISH_ERR __ERR_STR(clFinish)
00322
00323 #define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevicesEXT)
00324 #endif // __CL_USER_OVERRIDE_ERROR_STRINGS
00326
00327
00331 class string
00332 {
00333 private:
00334 ::size_t size_;
00335 char * str_;
00336 public:
00337 string(void) : size_(0), str_(NULL)
00338 {
00339 }
00340
00341 string(char * str, ::size_t size) :
00342 size_(size),
00343 str_(NULL)
00344 {
00345 str_ = new char[size_+1];
00346 if (str_ != NULL) {
00347 memcpy(str_, str, size_ * sizeof(char));
00348 str_[size_] = '\0';
00349 }
00350 else {
00351 size_ = 0;
00352 }
00353 }
00354
00355 string(char * str) :
00356 str_(NULL)
00357 {
00358 size_= ::strlen(str);
00359 str_ = new char[size_ + 1];
00360 if (str_ != NULL) {
00361 memcpy(str_, str, (size_ + 1) * sizeof(char));
00362 }
00363 else {
00364 size_ = 0;
00365 }
00366 }
00367
00368 string& operator=(const string& rhs)
00369 {
00370 if (this == &rhs) {
00371 return *this;
00372 }
00373
00374 if (rhs.size_ == 0 || rhs.str_ == NULL) {
00375 size_ = 0;
00376 str_ = NULL;
00377 }
00378 else {
00379 size_ = rhs.size_;
00380 str_ = new char[size_ + 1];
00381 if (str_ != NULL) {
00382 memcpy(str_, rhs.str_, (size_ + 1) * sizeof(char));
00383 }
00384 else {
00385 size_ = 0;
00386 }
00387 }
00388
00389 return *this;
00390 }
00391
00392 string(const string& rhs)
00393 {
00394 *this = rhs;
00395 }
00396
00397 ~string()
00398 {
00399 if (str_ != NULL) {
00400 delete[] str_;
00401 }
00402 }
00403
00404 ::size_t size(void) const { return size_; }
00405 ::size_t length(void) const { return size(); }
00406
00407 const char * c_str(void) const { return (str_) ? str_ : "";}
00408 };
00409
00410 #if !defined(__USE_DEV_STRING) && !defined(__NO_STD_STRING)
00411 #include <string>
00412 typedef std::string STRING_CLASS;
00413 #elif !defined(__USE_DEV_STRING)
00414 typedef cl::string STRING_CLASS;
00415 #endif
00416
00417 #if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR)
00418 #include <vector>
00419 #define VECTOR_CLASS std::vector
00420 #elif !defined(__USE_DEV_VECTOR)
00421 #define VECTOR_CLASS cl::vector
00422 #endif
00423
00424 #if !defined(__MAX_DEFAULT_VECTOR_SIZE)
00425 #define __MAX_DEFAULT_VECTOR_SIZE 10
00426 #endif
00427
00432 template <typename T, unsigned int N = __MAX_DEFAULT_VECTOR_SIZE>
00433 class vector
00434 {
00435 private:
00436 T data_[N];
00437 unsigned int size_;
00438 bool empty_;
00439 public:
00440 vector() :
00441 size_(-1),
00442 empty_(true)
00443 {}
00444
00445 ~vector() {}
00446
00447 unsigned int size(void) const
00448 {
00449 return size_ + 1;
00450 }
00451
00452 void clear()
00453 {
00454 size_ = -1;
00455 empty_ = true;
00456 }
00457
00458 void push_back (const T& x)
00459 {
00460 if (size() < N) {
00461 size_++;
00462 data_[size_] = x;
00463 empty_ = false;
00464 }
00465 }
00466
00467 void pop_back(void)
00468 {
00469 if (!empty_) {
00470 data_[size_].~T();
00471 size_--;
00472 if (size_ == -1) {
00473 empty_ = true;
00474 }
00475 }
00476 }
00477
00478 vector(const vector<T, N>& vec) :
00479 size_(vec.size_),
00480 empty_(vec.empty_)
00481 {
00482 if (!empty_) {
00483 memcpy(&data_[0], &vec.data_[0], size() * sizeof(T));
00484 }
00485 }
00486
00487 vector(unsigned int size, const T& val = T()) :
00488 size_(-1),
00489 empty_(true)
00490 {
00491 for (unsigned int i = 0; i < size; i++) {
00492 push_back(val);
00493 }
00494 }
00495
00496 vector<T, N>& operator=(const vector<T, N>& rhs)
00497 {
00498 if (this == &rhs) {
00499 return *this;
00500 }
00501
00502 size_ = rhs.size_;
00503 empty_ = rhs.empty_;
00504
00505 if (!empty_) {
00506 memcpy(&data_[0], &rhs.data_[0], size() * sizeof(T));
00507 }
00508
00509 return *this;
00510 }
00511
00512 bool operator==(vector<T,N> &vec)
00513 {
00514 if (empty_ && vec.empty_) {
00515 return true;
00516 }
00517
00518 if (size() != vec.size()) {
00519 return false;
00520 }
00521
00522 return memcmp(&data_[0], &vec.data_[0], size() * sizeof(T)) == 0 ? true : false;
00523 }
00524
00525 operator T* () { return data_; }
00526 operator const T* () const { return data_; }
00527
00528 bool empty (void) const
00529 {
00530 return empty_;
00531 }
00532
00533 unsigned int max_size (void) const
00534 {
00535 return N;
00536 }
00537
00538 unsigned int capacity () const
00539 {
00540 return sizeof(T) * N;
00541 }
00542
00543 T& operator[](int index)
00544 {
00545 return data_[index];
00546 }
00547
00548 T operator[](int index) const
00549 {
00550 return data_[index];
00551 }
00552
00553 template<class I>
00554 void assign(I start, I end)
00555 {
00556 clear();
00557 while(start < end) {
00558 push_back(*start);
00559 start++;
00560 }
00561 }
00562
00566 class iterator
00567 {
00568 private:
00569 vector<T,N> vec_;
00570 int index_;
00571 bool initialized_;
00572 public:
00573 iterator(void) :
00574 index_(-1),
00575 initialized_(false)
00576 {
00577 index_ = -1;
00578 initialized_ = false;
00579 }
00580
00581 ~iterator(void) {}
00582
00583 static iterator begin(vector<T,N> &vec)
00584 {
00585 iterator i;
00586
00587 if (!vec.empty()) {
00588 i.index_ = 0;
00589 }
00590
00591 i.vec_ = vec;
00592 i.initialized_ = true;
00593 return i;
00594 }
00595
00596 static iterator end(vector<T,N> &vec)
00597 {
00598 iterator i;
00599
00600 if (!vec.empty()) {
00601 i.index_ = vec.size();
00602 }
00603 i.vec_ = vec;
00604 i.initialized_ = true;
00605 return i;
00606 }
00607
00608 bool operator==(iterator i)
00609 {
00610 return ((vec_ == i.vec_) &&
00611 (index_ == i.index_) &&
00612 (initialized_ == i.initialized_));
00613 }
00614
00615 bool operator!=(iterator i)
00616 {
00617 return (!(*this==i));
00618 }
00619
00620 void operator++()
00621 {
00622 index_++;
00623 }
00624
00625 void operator++(int x)
00626 {
00627 index_ += x;
00628 }
00629
00630 void operator--()
00631 {
00632 index_--;
00633 }
00634
00635 void operator--(int x)
00636 {
00637 index_ -= x;
00638 }
00639
00640 T operator *()
00641 {
00642 return vec_[index_];
00643 }
00644 };
00645
00646 iterator begin(void)
00647 {
00648 return iterator::begin(*this);
00649 }
00650
00651 iterator end(void)
00652 {
00653 return iterator::end(*this);
00654 }
00655
00656 T& front(void)
00657 {
00658 return data_[0];
00659 }
00660
00661 T& back(void)
00662 {
00663 return data_[size_];
00664 }
00665
00666 const T& front(void) const
00667 {
00668 return data_[0];
00669 }
00670
00671 const T& back(void) const
00672 {
00673 return data_[size_];
00674 }
00675 };
00676
00682 template <int N>
00683 struct size_t : public cl::vector< ::size_t, N> { };
00684
00685 namespace detail {
00686
00687
00688 template <typename Functor, typename T>
00689 struct GetInfoHelper
00690 {
00691 static cl_int
00692 get(Functor f, cl_uint name, T* param)
00693 {
00694 return f(name, sizeof(T), param, NULL);
00695 }
00696 };
00697
00698
00699 template <typename Func, typename T>
00700 struct GetInfoHelper<Func, VECTOR_CLASS<T> >
00701 {
00702 static cl_int get(Func f, cl_uint name, VECTOR_CLASS<T>* param)
00703 {
00704 ::size_t required;
00705 cl_int err = f(name, 0, NULL, &required);
00706 if (err != CL_SUCCESS) {
00707 return err;
00708 }
00709
00710 T* value = (T*) alloca(required);
00711 err = f(name, required, value, NULL);
00712 if (err != CL_SUCCESS) {
00713 return err;
00714 }
00715
00716 param->assign(&value[0], &value[required/sizeof(T)]);
00717 return CL_SUCCESS;
00718 }
00719 };
00720
00721
00722 template <typename Func>
00723 struct GetInfoHelper<Func, VECTOR_CLASS<char *> >
00724 {
00725 static cl_int
00726 get(Func f, cl_uint name, VECTOR_CLASS<char *>* param)
00727 {
00728 cl_uint err = f(name, param->size() * sizeof(char *), &(*param)[0], NULL);
00729 if (err != CL_SUCCESS) {
00730 return err;
00731 }
00732
00733 return CL_SUCCESS;
00734 }
00735 };
00736
00737
00738 template <typename Func>
00739 struct GetInfoHelper<Func, STRING_CLASS>
00740 {
00741 static cl_int get(Func f, cl_uint name, STRING_CLASS* param)
00742 {
00743 ::size_t required;
00744 cl_int err = f(name, 0, NULL, &required);
00745 if (err != CL_SUCCESS) {
00746 return err;
00747 }
00748
00749 char* value = (char*) alloca(required);
00750 err = f(name, required, value, NULL);
00751 if (err != CL_SUCCESS) {
00752 return err;
00753 }
00754
00755 *param = value;
00756 return CL_SUCCESS;
00757 }
00758 };
00759
00760 #define __GET_INFO_HELPER_WITH_RETAIN(CPP_TYPE) \
00761 namespace detail { \
00762 template <typename Func> \
00763 struct GetInfoHelper<Func, CPP_TYPE> \
00764 { \
00765 static cl_int get(Func f, cl_uint name, CPP_TYPE* param) \
00766 { \
00767 cl_uint err = f(name, sizeof(CPP_TYPE), param, NULL); \
00768 if (err != CL_SUCCESS) { \
00769 return err; \
00770 } \
00771 \
00772 return ReferenceHandler<CPP_TYPE::cl_type>::retain((*param)()); \
00773 } \
00774 }; \
00775 }
00776
00777
00778 #define __PARAM_NAME_INFO_1_0(F) \
00779 F(cl_platform_info, CL_PLATFORM_PROFILE, STRING_CLASS) \
00780 F(cl_platform_info, CL_PLATFORM_VERSION, STRING_CLASS) \
00781 F(cl_platform_info, CL_PLATFORM_NAME, STRING_CLASS) \
00782 F(cl_platform_info, CL_PLATFORM_VENDOR, STRING_CLASS) \
00783 F(cl_platform_info, CL_PLATFORM_EXTENSIONS, STRING_CLASS) \
00784 \
00785 F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
00786 F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
00787 F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
00788 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
00789 F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, ::size_t) \
00790 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, VECTOR_CLASS< ::size_t>) \
00791 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
00792 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
00793 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
00794 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
00795 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
00796 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
00797 F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
00798 F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_bitfield) \
00799 F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
00800 F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
00801 F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
00802 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, ::size_t) \
00803 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, ::size_t) \
00804 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, ::size_t) \
00805 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, ::size_t) \
00806 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, ::size_t) \
00807 F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_uint) \
00808 F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, ::size_t) \
00809 F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
00810 F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
00811 F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
00812 F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
00813 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
00814 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
00815 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
00816 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
00817 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
00818 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
00819 F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
00820 F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
00821 F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
00822 F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, ::size_t) \
00823 F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
00824 F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
00825 F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
00826 F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
00827 F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties) \
00828 F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
00829 F(cl_device_info, CL_DEVICE_NAME, STRING_CLASS) \
00830 F(cl_device_info, CL_DEVICE_VENDOR, STRING_CLASS) \
00831 F(cl_device_info, CL_DRIVER_VERSION, STRING_CLASS) \
00832 F(cl_device_info, CL_DEVICE_PROFILE, STRING_CLASS) \
00833 F(cl_device_info, CL_DEVICE_VERSION, STRING_CLASS) \
00834 F(cl_device_info, CL_DEVICE_EXTENSIONS, STRING_CLASS) \
00835 \
00836 F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
00837 F(cl_context_info, CL_CONTEXT_DEVICES, VECTOR_CLASS<Device>) \
00838 F(cl_context_info, CL_CONTEXT_PROPERTIES, VECTOR_CLASS<cl_context_properties>) \
00839 \
00840 F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
00841 F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
00842 F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
00843 F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_uint) \
00844 \
00845 F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
00846 F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
00847 F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
00848 F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
00849 \
00850 F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
00851 F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
00852 F(cl_mem_info, CL_MEM_SIZE, ::size_t) \
00853 F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
00854 F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
00855 F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
00856 F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
00857 \
00858 F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
00859 F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, ::size_t) \
00860 F(cl_image_info, CL_IMAGE_ROW_PITCH, ::size_t) \
00861 F(cl_image_info, CL_IMAGE_SLICE_PITCH, ::size_t) \
00862 F(cl_image_info, CL_IMAGE_WIDTH, ::size_t) \
00863 F(cl_image_info, CL_IMAGE_HEIGHT, ::size_t) \
00864 F(cl_image_info, CL_IMAGE_DEPTH, ::size_t) \
00865 \
00866 F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
00867 F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
00868 F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_addressing_mode) \
00869 F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_filter_mode) \
00870 F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_bool) \
00871 \
00872 F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
00873 F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
00874 F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
00875 F(cl_program_info, CL_PROGRAM_DEVICES, VECTOR_CLASS<cl_device_id>) \
00876 F(cl_program_info, CL_PROGRAM_SOURCE, STRING_CLASS) \
00877 F(cl_program_info, CL_PROGRAM_BINARY_SIZES, VECTOR_CLASS< ::size_t>) \
00878 F(cl_program_info, CL_PROGRAM_BINARIES, VECTOR_CLASS<char *>) \
00879 \
00880 F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
00881 F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, STRING_CLASS) \
00882 F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, STRING_CLASS) \
00883 \
00884 F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, STRING_CLASS) \
00885 F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
00886 F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
00887 F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
00888 F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
00889 \
00890 F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, ::size_t) \
00891 F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::size_t<3>) \
00892 F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
00893 \
00894 F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
00895 F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
00896 F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
00897 F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
00898
00899 #if defined(CL_VERSION_1_1)
00900 #define __PARAM_NAME_INFO_1_1(F) \
00901 F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
00902 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
00903 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
00904 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
00905 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
00906 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
00907 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
00908 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
00909 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
00910 F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
00911 F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
00912 F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) \
00913 \
00914 F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
00915 F(cl_mem_info, CL_MEM_OFFSET, ::size_t) \
00916 \
00917 F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, ::size_t) \
00918 F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
00919 \
00920 F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
00921 #endif // CL_VERSION_1_1
00922
00923 #if defined(USE_CL_DEVICE_FISSION)
00924 #define __PARAM_NAME_DEVICE_FISSION(F) \
00925 F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
00926 F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \
00927 F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \
00928 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
00929 F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, VECTOR_CLASS<cl_device_partition_property_ext>)
00930 #endif // USE_CL_DEVICE_FISSION
00931
00932 template <typename enum_type, cl_int Name>
00933 struct param_traits {};
00934
00935 #define __DECLARE_PARAM_TRAITS(token, param_name, T) \
00936 struct token; \
00937 template<> \
00938 struct param_traits<detail:: token,param_name> \
00939 { \
00940 enum { value = param_name }; \
00941 typedef T param_type; \
00942 };
00943
00944 __PARAM_NAME_INFO_1_0(__DECLARE_PARAM_TRAITS);
00945 #if defined(CL_VERSION_1_1)
00946 __PARAM_NAME_INFO_1_1(__DECLARE_PARAM_TRAITS);
00947 #endif // CL_VERSION_1_1
00948
00949 #if defined(USE_CL_DEVICE_FISSION)
00950 __PARAM_NAME_DEVICE_FISSION(__DECLARE_PARAM_TRAITS);
00951 #endif // USE_CL_DEVICE_FISSION
00952
00953 #undef __DECLARE_PARAM_TRAITS
00954
00955
00956
00957 template <typename Func, typename T>
00958 inline cl_int
00959 getInfo(Func f, cl_uint name, T* param)
00960 {
00961 return GetInfoHelper<Func, T>::get(f, name, param);
00962 }
00963
00964 template <typename Func, typename Arg0>
00965 struct GetInfoFunctor0
00966 {
00967 Func f_; const Arg0& arg0_;
00968 cl_int operator ()(
00969 cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
00970 { return f_(arg0_, param, size, value, size_ret); }
00971 };
00972
00973 template <typename Func, typename Arg0, typename Arg1>
00974 struct GetInfoFunctor1
00975 {
00976 Func f_; const Arg0& arg0_; const Arg1& arg1_;
00977 cl_int operator ()(
00978 cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
00979 { return f_(arg0_, arg1_, param, size, value, size_ret); }
00980 };
00981
00982 template <typename Func, typename Arg0, typename T>
00983 inline cl_int
00984 getInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
00985 {
00986 GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
00987 return GetInfoHelper<GetInfoFunctor0<Func, Arg0>, T>
00988 ::get(f0, name, param);
00989 }
00990
00991 template <typename Func, typename Arg0, typename Arg1, typename T>
00992 inline cl_int
00993 getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
00994 {
00995 GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
00996 return GetInfoHelper<GetInfoFunctor1<Func, Arg0, Arg1>, T>
00997 ::get(f0, name, param);
00998 }
00999
01000 template<typename T>
01001 struct ReferenceHandler
01002 { };
01003
01004 template <>
01005 struct ReferenceHandler<cl_device_id>
01006 {
01007
01008 static cl_int retain(cl_device_id)
01009 { return CL_INVALID_DEVICE; }
01010
01011 static cl_int release(cl_device_id)
01012 { return CL_INVALID_DEVICE; }
01013 };
01014
01015 template <>
01016 struct ReferenceHandler<cl_platform_id>
01017 {
01018
01019 static cl_int retain(cl_platform_id)
01020 { return CL_INVALID_PLATFORM; }
01021
01022 static cl_int release(cl_platform_id)
01023 { return CL_INVALID_PLATFORM; }
01024 };
01025
01026 template <>
01027 struct ReferenceHandler<cl_context>
01028 {
01029 static cl_int retain(cl_context context)
01030 { return ::clRetainContext(context); }
01031 static cl_int release(cl_context context)
01032 { return ::clReleaseContext(context); }
01033 };
01034
01035 template <>
01036 struct ReferenceHandler<cl_command_queue>
01037 {
01038 static cl_int retain(cl_command_queue queue)
01039 { return ::clRetainCommandQueue(queue); }
01040 static cl_int release(cl_command_queue queue)
01041 { return ::clReleaseCommandQueue(queue); }
01042 };
01043
01044 template <>
01045 struct ReferenceHandler<cl_mem>
01046 {
01047 static cl_int retain(cl_mem memory)
01048 { return ::clRetainMemObject(memory); }
01049 static cl_int release(cl_mem memory)
01050 { return ::clReleaseMemObject(memory); }
01051 };
01052
01053 template <>
01054 struct ReferenceHandler<cl_sampler>
01055 {
01056 static cl_int retain(cl_sampler sampler)
01057 { return ::clRetainSampler(sampler); }
01058 static cl_int release(cl_sampler sampler)
01059 { return ::clReleaseSampler(sampler); }
01060 };
01061
01062 template <>
01063 struct ReferenceHandler<cl_program>
01064 {
01065 static cl_int retain(cl_program program)
01066 { return ::clRetainProgram(program); }
01067 static cl_int release(cl_program program)
01068 { return ::clReleaseProgram(program); }
01069 };
01070
01071 template <>
01072 struct ReferenceHandler<cl_kernel>
01073 {
01074 static cl_int retain(cl_kernel kernel)
01075 { return ::clRetainKernel(kernel); }
01076 static cl_int release(cl_kernel kernel)
01077 { return ::clReleaseKernel(kernel); }
01078 };
01079
01080 template <>
01081 struct ReferenceHandler<cl_event>
01082 {
01083 static cl_int retain(cl_event event)
01084 { return ::clRetainEvent(event); }
01085 static cl_int release(cl_event event)
01086 { return ::clReleaseEvent(event); }
01087 };
01088
01089 template <typename T>
01090 class Wrapper
01091 {
01092 public:
01093 typedef T cl_type;
01094
01095 protected:
01096 cl_type object_;
01097
01098 public:
01099 Wrapper() : object_(NULL) { }
01100
01101 ~Wrapper()
01102 {
01103 if (object_ != NULL) { release(); }
01104 }
01105
01106 Wrapper(const Wrapper<cl_type>& rhs)
01107 {
01108 object_ = rhs.object_;
01109 if (object_ != NULL) { retain(); }
01110 }
01111
01112 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
01113 {
01114 if (object_ != NULL) { release(); }
01115 object_ = rhs.object_;
01116 if (object_ != NULL) { retain(); }
01117 return *this;
01118 }
01119
01120 cl_type operator ()() const { return object_; }
01121
01122 cl_type& operator ()() { return object_; }
01123
01124 protected:
01125
01126 cl_int retain() const
01127 {
01128 return ReferenceHandler<cl_type>::retain(object_);
01129 }
01130
01131 cl_int release() const
01132 {
01133 return ReferenceHandler<cl_type>::release(object_);
01134 }
01135 };
01136
01137 #if defined(__CL_ENABLE_EXCEPTIONS)
01138 static inline cl_int errHandler (
01139 cl_int err,
01140 const char * errStr = NULL) throw(Error)
01141 {
01142 if (err != CL_SUCCESS) {
01143 throw Error(err, errStr);
01144 }
01145 return err;
01146 }
01147 #else
01148 static inline cl_int errHandler (cl_int err, const char * errStr = NULL)
01149 {
01150 return err;
01151 }
01152 #endif // __CL_ENABLE_EXCEPTIONS
01153
01154 }
01156
01160 struct ImageFormat : public cl_image_format
01161 {
01162 ImageFormat(){}
01163
01164 ImageFormat(cl_channel_order order, cl_channel_type type)
01165 {
01166 image_channel_order = order;
01167 image_channel_data_type = type;
01168 }
01169
01170 ImageFormat& operator = (const ImageFormat& rhs)
01171 {
01172 if (this != &rhs) {
01173 this->image_channel_data_type = rhs.image_channel_data_type;
01174 this->image_channel_order = rhs.image_channel_order;
01175 }
01176 return *this;
01177 }
01178 };
01179
01183 class Device : public detail::Wrapper<cl_device_id>
01184 {
01185 public:
01186 Device(cl_device_id device) { object_ = device; }
01187
01188 Device() : detail::Wrapper<cl_type>() { }
01189
01190 Device(const Device& device) : detail::Wrapper<cl_type>(device) { }
01191
01192 Device& operator = (const Device& rhs)
01193 {
01194 if (this != &rhs) {
01195 detail::Wrapper<cl_type>::operator=(rhs);
01196 }
01197 return *this;
01198 }
01199
01200 template <typename T>
01201 cl_int getInfo(cl_device_info name, T* param) const
01202 {
01203 return detail::errHandler(
01204 detail::getInfo(&::clGetDeviceInfo, object_, name, param),
01205 __GET_DEVICE_INFO_ERR);
01206 }
01207
01208 template <cl_int name> typename
01209 detail::param_traits<detail::cl_device_info, name>::param_type
01210 getInfo(cl_int* err = NULL) const
01211 {
01212 typename detail::param_traits<
01213 detail::cl_device_info, name>::param_type param;
01214 cl_int result = getInfo(name, ¶m);
01215 if (err != NULL) {
01216 *err = result;
01217 }
01218 return param;
01219 }
01220
01221 #if defined(USE_CL_DEVICE_FISSION)
01222 cl_int createSubDevices(
01223 const cl_device_partition_property_ext * properties,
01224 VECTOR_CLASS<Device>* devices)
01225 {
01226 typedef CL_API_ENTRY cl_int
01227 ( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
01228 cl_device_id ,
01229 const cl_device_partition_property_ext * ,
01230 cl_uint ,
01231 cl_device_id * ,
01232 cl_uint * ) CL_EXT_SUFFIX__VERSION_1_1;
01233
01234 static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
01235 __INIT_CL_EXT_FCN_PTR(clCreateSubDevicesEXT);
01236
01237 cl_uint n = 0;
01238 cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
01239 if (err != CL_SUCCESS) {
01240 return detail::errHandler(err, __CREATE_SUB_DEVICES);
01241 }
01242
01243 cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
01244 err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids, NULL);
01245 if (err != CL_SUCCESS) {
01246 return detail::errHandler(err, __CREATE_SUB_DEVICES);
01247 }
01248
01249 devices->assign(&ids[0], &ids[n]);
01250 return CL_SUCCESS;
01251 }
01252 #endif
01253 };
01254
01258 class Platform : public detail::Wrapper<cl_platform_id>
01259 {
01260 public:
01261 static const Platform null();
01262
01263 Platform(cl_platform_id platform) { object_ = platform; }
01264
01265 Platform() : detail::Wrapper<cl_type>() { }
01266
01267 Platform(const Platform& platform) : detail::Wrapper<cl_type>(platform) { }
01268
01269 Platform& operator = (const Platform& rhs)
01270 {
01271 if (this != &rhs) {
01272 detail::Wrapper<cl_type>::operator=(rhs);
01273 }
01274 return *this;
01275 }
01276
01277 cl_int getInfo(cl_platform_info name, STRING_CLASS* param) const
01278 {
01279 return detail::errHandler(
01280 detail::getInfo(&::clGetPlatformInfo, object_, name, param),
01281 __GET_PLATFORM_INFO_ERR);
01282 }
01283
01284 template <cl_int name> typename
01285 detail::param_traits<detail::cl_platform_info, name>::param_type
01286 getInfo(cl_int* err = NULL) const
01287 {
01288 typename detail::param_traits<
01289 detail::cl_platform_info, name>::param_type param;
01290 cl_int result = getInfo(name, ¶m);
01291 if (err != NULL) {
01292 *err = result;
01293 }
01294 return param;
01295 }
01296
01297 cl_int getDevices(
01298 cl_device_type type,
01299 VECTOR_CLASS<Device>* devices) const
01300 {
01301 cl_uint n = 0;
01302 cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
01303 if (err != CL_SUCCESS) {
01304 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
01305 }
01306
01307 cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
01308 err = ::clGetDeviceIDs(object_, type, n, ids, NULL);
01309 if (err != CL_SUCCESS) {
01310 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
01311 }
01312
01313 devices->assign(&ids[0], &ids[n]);
01314 return CL_SUCCESS;
01315 }
01316
01317 #if defined(USE_DX_INTEROP)
01318
01341 cl_int getDevices(
01342 cl_d3d10_device_source_khr d3d_device_source,
01343 void * d3d_object,
01344 cl_d3d10_device_set_khr d3d_device_set,
01345 VECTOR_CLASS<Device>* devices) const
01346 {
01347 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
01348 cl_platform_id platform,
01349 cl_d3d10_device_source_khr d3d_device_source,
01350 void * d3d_object,
01351 cl_d3d10_device_set_khr d3d_device_set,
01352 cl_uint num_entries,
01353 cl_device_id * devices,
01354 cl_uint* num_devices);
01355
01356 static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
01357 __INIT_CL_EXT_FCN_PTR(clGetDeviceIDsFromD3D10KHR);
01358
01359 cl_uint n = 0;
01360 cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
01361 object_,
01362 d3d_device_source,
01363 d3d_object,
01364 d3d_device_set,
01365 0,
01366 NULL,
01367 &n);
01368 if (err != CL_SUCCESS) {
01369 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
01370 }
01371
01372 cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
01373 err = pfn_clGetDeviceIDsFromD3D10KHR(
01374 object_,
01375 d3d_device_source,
01376 d3d_object,
01377 d3d_device_set,
01378 n,
01379 ids,
01380 NULL);
01381 if (err != CL_SUCCESS) {
01382 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
01383 }
01384
01385 devices->assign(&ids[0], &ids[n]);
01386 return CL_SUCCESS;
01387 }
01388 #endif
01389
01390 static cl_int get(
01391 VECTOR_CLASS<Platform>* platforms)
01392 {
01393 cl_uint n = 0;
01394 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
01395 if (err != CL_SUCCESS) {
01396 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
01397 }
01398
01399 cl_platform_id* ids = (cl_platform_id*) alloca(
01400 n * sizeof(cl_platform_id));
01401 err = ::clGetPlatformIDs(n, ids, NULL);
01402 if (err != CL_SUCCESS) {
01403 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
01404 }
01405
01406 platforms->assign(&ids[0], &ids[n]);
01407 return CL_SUCCESS;
01408 }
01409 };
01410
01411 static inline cl_int
01412 UnloadCompiler()
01413 {
01414 return ::clUnloadCompiler();
01415 }
01416
01417 class Context : public detail::Wrapper<cl_context>
01418 {
01419 public:
01420 Context(
01421 const VECTOR_CLASS<Device>& devices,
01422 cl_context_properties* properties = NULL,
01423 void (CL_CALLBACK * notifyFptr)(
01424 const char *,
01425 const void *,
01426 ::size_t,
01427 void *) = NULL,
01428 void* data = NULL,
01429 cl_int* err = NULL)
01430 {
01431 cl_int error;
01432 object_ = ::clCreateContext(
01433 properties, (cl_uint) devices.size(),
01434 (cl_device_id*) &devices.front(),
01435 notifyFptr, data, &error);
01436
01437 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
01438 if (err != NULL) {
01439 *err = error;
01440 }
01441 }
01442
01443 Context(
01444 cl_device_type type,
01445 cl_context_properties* properties = NULL,
01446 void (CL_CALLBACK * notifyFptr)(
01447 const char *,
01448 const void *,
01449 ::size_t,
01450 void *) = NULL,
01451 void* data = NULL,
01452 cl_int* err = NULL)
01453 {
01454 cl_int error;
01455 object_ = ::clCreateContextFromType(
01456 properties, type, notifyFptr, data, &error);
01457
01458 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
01459 if (err != NULL) {
01460 *err = error;
01461 }
01462 }
01463
01464 Context() : detail::Wrapper<cl_type>() { }
01465
01466 Context(const Context& context) : detail::Wrapper<cl_type>(context) { }
01467
01468 Context& operator = (const Context& rhs)
01469 {
01470 if (this != &rhs) {
01471 detail::Wrapper<cl_type>::operator=(rhs);
01472 }
01473 return *this;
01474 }
01475
01476 template <typename T>
01477 cl_int getInfo(cl_context_info name, T* param) const
01478 {
01479 return detail::errHandler(
01480 detail::getInfo(&::clGetContextInfo, object_, name, param),
01481 __GET_CONTEXT_INFO_ERR);
01482 }
01483
01484 template <cl_int name> typename
01485 detail::param_traits<detail::cl_context_info, name>::param_type
01486 getInfo(cl_int* err = NULL) const
01487 {
01488 typename detail::param_traits<
01489 detail::cl_context_info, name>::param_type param;
01490 cl_int result = getInfo(name, ¶m);
01491 if (err != NULL) {
01492 *err = result;
01493 }
01494 return param;
01495 }
01496
01497 cl_int getSupportedImageFormats(
01498 cl_mem_flags flags,
01499 cl_mem_object_type type,
01500 VECTOR_CLASS<ImageFormat>* formats) const
01501 {
01502 cl_uint numEntries;
01503 cl_int err = ::clGetSupportedImageFormats(
01504 object_,
01505 flags,
01506 type,
01507 0,
01508 NULL,
01509 &numEntries);
01510 if (err != CL_SUCCESS) {
01511 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
01512 }
01513
01514 ImageFormat* value = (ImageFormat*)
01515 alloca(numEntries * sizeof(ImageFormat));
01516 err = ::clGetSupportedImageFormats(
01517 object_,
01518 flags,
01519 type,
01520 numEntries,
01521 (cl_image_format*) value,
01522 NULL);
01523 if (err != CL_SUCCESS) {
01524 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
01525 }
01526
01527 formats->assign(&value[0], &value[numEntries]);
01528 return CL_SUCCESS;
01529 }
01530 };
01531
01532 __GET_INFO_HELPER_WITH_RETAIN(cl::Context)
01533
01534
01537 class Event : public detail::Wrapper<cl_event>
01538 {
01539 public:
01540 Event() : detail::Wrapper<cl_type>() { }
01541
01542 Event(const Event& event) : detail::Wrapper<cl_type>(event) { }
01543
01544 Event& operator = (const Event& rhs)
01545 {
01546 if (this != &rhs) {
01547 detail::Wrapper<cl_type>::operator=(rhs);
01548 }
01549 return *this;
01550 }
01551
01552 template <typename T>
01553 cl_int getInfo(cl_event_info name, T* param) const
01554 {
01555 return detail::errHandler(
01556 detail::getInfo(&::clGetEventInfo, object_, name, param),
01557 __GET_EVENT_INFO_ERR);
01558 }
01559
01560 template <cl_int name> typename
01561 detail::param_traits<detail::cl_event_info, name>::param_type
01562 getInfo(cl_int* err = NULL) const
01563 {
01564 typename detail::param_traits<
01565 detail::cl_event_info, name>::param_type param;
01566 cl_int result = getInfo(name, ¶m);
01567 if (err != NULL) {
01568 *err = result;
01569 }
01570 return param;
01571 }
01572
01573 template <typename T>
01574 cl_int getProfilingInfo(cl_profiling_info name, T* param) const
01575 {
01576 return detail::errHandler(detail::getInfo(
01577 &::clGetEventProfilingInfo, object_, name, param),
01578 __GET_EVENT_PROFILE_INFO_ERR);
01579 }
01580
01581 template <cl_int name> typename
01582 detail::param_traits<detail::cl_profiling_info, name>::param_type
01583 getProfilingInfo(cl_int* err = NULL) const
01584 {
01585 typename detail::param_traits<
01586 detail::cl_profiling_info, name>::param_type param;
01587 cl_int result = getProfilingInfo(name, ¶m);
01588 if (err != NULL) {
01589 *err = result;
01590 }
01591 return param;
01592 }
01593
01594 cl_int wait() const
01595 {
01596 return detail::errHandler(
01597 ::clWaitForEvents(1, &object_),
01598 __WAIT_FOR_EVENTS_ERR);
01599 }
01600
01601 #if defined(CL_VERSION_1_1)
01602 cl_int setCallback(
01603 cl_int type,
01604 void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
01605 void * user_data = NULL)
01606 {
01607 return detail::errHandler(
01608 ::clSetEventCallback(
01609 object_,
01610 type,
01611 pfn_notify,
01612 user_data),
01613 __SET_EVENT_CALLBACK_ERR);
01614 }
01615 #endif
01616
01617 static cl_int
01618 waitForEvents(const VECTOR_CLASS<Event>& events)
01619 {
01620 return detail::errHandler(
01621 ::clWaitForEvents(
01622 (cl_uint) events.size(), (cl_event*)&events.front()),
01623 __WAIT_FOR_EVENTS_ERR);
01624 }
01625 };
01626
01627 __GET_INFO_HELPER_WITH_RETAIN(cl::Event)
01628
01629 #if defined(CL_VERSION_1_1)
01630
01633 class UserEvent : public Event
01634 {
01635 public:
01636 UserEvent(
01637 const Context& context,
01638 cl_int * err = NULL)
01639 {
01640 cl_int error;
01641 object_ = ::clCreateUserEvent(
01642 context(),
01643 &error);
01644
01645 detail::errHandler(error, __CREATE_USER_EVENT_ERR);
01646 if (err != NULL) {
01647 *err = error;
01648 }
01649 }
01650
01651 UserEvent() : Event() { }
01652
01653 UserEvent(const UserEvent& event) : Event(event) { }
01654
01655 UserEvent& operator = (const UserEvent& rhs)
01656 {
01657 if (this != &rhs) {
01658 Event::operator=(rhs);
01659 }
01660 return *this;
01661 }
01662
01663 cl_int setStatus(cl_int status)
01664 {
01665 return detail::errHandler(
01666 ::clSetUserEventStatus(object_,status),
01667 __SET_USER_EVENT_STATUS_ERR);
01668 }
01669 };
01670 #endif
01671
01672 inline static cl_int
01673 WaitForEvents(const VECTOR_CLASS<Event>& events)
01674 {
01675 return detail::errHandler(
01676 ::clWaitForEvents(
01677 (cl_uint) events.size(), (cl_event*)&events.front()),
01678 __WAIT_FOR_EVENTS_ERR);
01679 }
01680
01684 class Memory : public detail::Wrapper<cl_mem>
01685 {
01686 public:
01687 Memory() : detail::Wrapper<cl_type>() { }
01688
01689 Memory(const Memory& memory) : detail::Wrapper<cl_type>(memory) { }
01690
01691 Memory& operator = (const Memory& rhs)
01692 {
01693 if (this != &rhs) {
01694 detail::Wrapper<cl_type>::operator=(rhs);
01695 }
01696 return *this;
01697 }
01698
01699 template <typename T>
01700 cl_int getInfo(cl_mem_info name, T* param) const
01701 {
01702 return detail::errHandler(
01703 detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
01704 __GET_MEM_OBJECT_INFO_ERR);
01705 }
01706
01707 template <cl_int name> typename
01708 detail::param_traits<detail::cl_mem_info, name>::param_type
01709 getInfo(cl_int* err = NULL) const
01710 {
01711 typename detail::param_traits<
01712 detail::cl_mem_info, name>::param_type param;
01713 cl_int result = getInfo(name, ¶m);
01714 if (err != NULL) {
01715 *err = result;
01716 }
01717 return param;
01718 }
01719
01720 #if defined(CL_VERSION_1_1)
01721 cl_int setDestructorCallback(
01722 void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
01723 void * user_data = NULL)
01724 {
01725 return detail::errHandler(
01726 ::clSetMemObjectDestructorCallback(
01727 object_,
01728 pfn_notify,
01729 user_data),
01730 __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
01731 }
01732 #endif
01733
01734 };
01735
01736 __GET_INFO_HELPER_WITH_RETAIN(cl::Memory)
01737
01738
01741 class Buffer : public Memory
01742 {
01743 public:
01744 Buffer(
01745 const Context& context,
01746 cl_mem_flags flags,
01747 ::size_t size,
01748 void* host_ptr = NULL,
01749 cl_int* err = NULL)
01750 {
01751 cl_int error;
01752 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
01753
01754 detail::errHandler(error, __CREATE_BUFFER_ERR);
01755 if (err != NULL) {
01756 *err = error;
01757 }
01758 }
01759
01760 Buffer() : Memory() { }
01761
01762 Buffer(const Buffer& buffer) : Memory(buffer) { }
01763
01764 Buffer& operator = (const Buffer& rhs)
01765 {
01766 if (this != &rhs) {
01767 Memory::operator=(rhs);
01768 }
01769 return *this;
01770 }
01771
01772 #if defined(CL_VERSION_1_1)
01773 Buffer createSubBuffer(
01774 cl_mem_flags flags,
01775 cl_buffer_create_type buffer_create_type,
01776 const void * buffer_create_info,
01777 cl_int * err = NULL)
01778 {
01779 Buffer result;
01780 cl_int error;
01781 result.object_ = ::clCreateSubBuffer(
01782 object_,
01783 flags,
01784 buffer_create_type,
01785 buffer_create_info,
01786 &error);
01787
01788 detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
01789 if (err != NULL) {
01790 *err = error;
01791 }
01792
01793 return result;
01794 }
01795 #endif
01796 };
01797
01798 #if defined (USE_DX_INTEROP)
01799 class BufferD3D10 : public Buffer
01800 {
01801 public:
01802 typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
01803 cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
01804 cl_int* errcode_ret);
01805
01806 BufferD3D10(
01807 const Context& context,
01808 cl_mem_flags flags,
01809 ID3D10Buffer* bufobj,
01810 cl_int * err = NULL)
01811 {
01812 static PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR = NULL;
01813 __INIT_CL_EXT_FCN_PTR(clCreateFromD3D10BufferKHR);
01814
01815 cl_int error;
01816 object_ = pfn_clCreateFromD3D10BufferKHR(
01817 context(),
01818 flags,
01819 bufobj,
01820 &error);
01821
01822 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
01823 if (err != NULL) {
01824 *err = error;
01825 }
01826 }
01827
01828 BufferD3D10() : Buffer() { }
01829
01830 BufferD3D10(const BufferD3D10& buffer) : Buffer(buffer) { }
01831
01832 BufferD3D10& operator = (const BufferD3D10& rhs)
01833 {
01834 if (this != &rhs) {
01835 Buffer::operator=(rhs);
01836 }
01837 return *this;
01838 }
01839 };
01840 #endif
01841
01845 class BufferGL : public Buffer
01846 {
01847 public:
01848 BufferGL(
01849 const Context& context,
01850 cl_mem_flags flags,
01851 GLuint bufobj,
01852 cl_int * err = NULL)
01853 {
01854 cl_int error;
01855 object_ = ::clCreateFromGLBuffer(
01856 context(),
01857 flags,
01858 bufobj,
01859 &error);
01860
01861 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
01862 if (err != NULL) {
01863 *err = error;
01864 }
01865 }
01866
01867 BufferGL() : Buffer() { }
01868
01869 BufferGL(const BufferGL& buffer) : Buffer(buffer) { }
01870
01871 BufferGL& operator = (const BufferGL& rhs)
01872 {
01873 if (this != &rhs) {
01874 Buffer::operator=(rhs);
01875 }
01876 return *this;
01877 }
01878
01879 cl_int getObjectInfo(
01880 cl_gl_object_type *type,
01881 GLuint * gl_object_name)
01882 {
01883 return detail::errHandler(
01884 ::clGetGLObjectInfo(object_,type,gl_object_name),
01885 __GET_GL_OBJECT_INFO_ERR);
01886 }
01887 };
01888
01892 class BufferRenderGL : public Buffer
01893 {
01894 public:
01895 BufferRenderGL(
01896 const Context& context,
01897 cl_mem_flags flags,
01898 GLuint bufobj,
01899 cl_int * err = NULL)
01900 {
01901 cl_int error;
01902 object_ = ::clCreateFromGLRenderbuffer(
01903 context(),
01904 flags,
01905 bufobj,
01906 &error);
01907
01908 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
01909 if (err != NULL) {
01910 *err = error;
01911 }
01912 }
01913
01914 BufferRenderGL() : Buffer() { }
01915
01916 BufferRenderGL(const BufferGL& buffer) : Buffer(buffer) { }
01917
01918 BufferRenderGL& operator = (const BufferRenderGL& rhs)
01919 {
01920 if (this != &rhs) {
01921 Buffer::operator=(rhs);
01922 }
01923 return *this;
01924 }
01925
01926 cl_int getObjectInfo(
01927 cl_gl_object_type *type,
01928 GLuint * gl_object_name)
01929 {
01930 return detail::errHandler(
01931 ::clGetGLObjectInfo(object_,type,gl_object_name),
01932 __GET_GL_OBJECT_INFO_ERR);
01933 }
01934 };
01935
01939 class Image : public Memory
01940 {
01941 protected:
01942 Image() : Memory() { }
01943
01944 Image(const Image& image) : Memory(image) { }
01945
01946 Image& operator = (const Image& rhs)
01947 {
01948 if (this != &rhs) {
01949 Memory::operator=(rhs);
01950 }
01951 return *this;
01952 }
01953 public:
01954 template <typename T>
01955 cl_int getImageInfo(cl_image_info name, T* param) const
01956 {
01957 return detail::errHandler(
01958 detail::getInfo(&::clGetImageInfo, object_, name, param),
01959 __GET_IMAGE_INFO_ERR);
01960 }
01961
01962 template <cl_int name> typename
01963 detail::param_traits<detail::cl_image_info, name>::param_type
01964 getImageInfo(cl_int* err = NULL) const
01965 {
01966 typename detail::param_traits<
01967 detail::cl_image_info, name>::param_type param;
01968 cl_int result = getImageInfo(name, ¶m);
01969 if (err != NULL) {
01970 *err = result;
01971 }
01972 return param;
01973 }
01974 };
01975
01979 class Image2D : public Image
01980 {
01981 public:
01982 Image2D(
01983 const Context& context,
01984 cl_mem_flags flags,
01985 ImageFormat format,
01986 ::size_t width,
01987 ::size_t height,
01988 ::size_t row_pitch = 0,
01989 void* host_ptr = NULL,
01990 cl_int* err = NULL)
01991 {
01992 cl_int error;
01993 object_ = ::clCreateImage2D(
01994 context(), flags,&format, width, height, row_pitch, host_ptr, &error);
01995
01996 detail::errHandler(error, __CREATE_IMAGE2D_ERR);
01997 if (err != NULL) {
01998 *err = error;
01999 }
02000 }
02001
02002 Image2D() { }
02003
02004 Image2D(const Image2D& image2D) : Image(image2D) { }
02005
02006 Image2D& operator = (const Image2D& rhs)
02007 {
02008 if (this != &rhs) {
02009 Image::operator=(rhs);
02010 }
02011 return *this;
02012 }
02013 };
02014
02018 class Image2DGL : public Image2D
02019 {
02020 public:
02021 Image2DGL(
02022 const Context& context,
02023 cl_mem_flags flags,
02024 GLenum target,
02025 GLint miplevel,
02026 GLuint texobj,
02027 cl_int * err = NULL)
02028 {
02029 cl_int error;
02030 object_ = ::clCreateFromGLTexture2D(
02031 context(),
02032 flags,
02033 target,
02034 miplevel,
02035 texobj,
02036 &error);
02037
02038 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
02039 if (err != NULL) {
02040 *err = error;
02041 }
02042 }
02043
02044 Image2DGL() : Image2D() { }
02045
02046 Image2DGL(const Image2DGL& image) : Image2D(image) { }
02047
02048 Image2DGL& operator = (const Image2DGL& rhs)
02049 {
02050 if (this != &rhs) {
02051 Image2D::operator=(rhs);
02052 }
02053 return *this;
02054 }
02055 };
02056
02060 class Image3D : public Image
02061 {
02062 public:
02063 Image3D(
02064 const Context& context,
02065 cl_mem_flags flags,
02066 ImageFormat format,
02067 ::size_t width,
02068 ::size_t height,
02069 ::size_t depth,
02070 ::size_t row_pitch = 0,
02071 ::size_t slice_pitch = 0,
02072 void* host_ptr = NULL,
02073 cl_int* err = NULL)
02074 {
02075 cl_int error;
02076 object_ = ::clCreateImage3D(
02077 context(), flags, &format, width, height, depth, row_pitch,
02078 slice_pitch, host_ptr, &error);
02079
02080 detail::errHandler(error, __CREATE_IMAGE3D_ERR);
02081 if (err != NULL) {
02082 *err = error;
02083 }
02084 }
02085
02086 Image3D() { }
02087
02088 Image3D(const Image3D& image3D) : Image(image3D) { }
02089
02090 Image3D& operator = (const Image3D& rhs)
02091 {
02092 if (this != &rhs) {
02093 Image::operator=(rhs);
02094 }
02095 return *this;
02096 }
02097 };
02098
02102 class Image3DGL : public Image3D
02103 {
02104 public:
02105 Image3DGL(
02106 const Context& context,
02107 cl_mem_flags flags,
02108 GLenum target,
02109 GLint miplevel,
02110 GLuint texobj,
02111 cl_int * err = NULL)
02112 {
02113 cl_int error;
02114 object_ = ::clCreateFromGLTexture3D(
02115 context(),
02116 flags,
02117 target,
02118 miplevel,
02119 texobj,
02120 &error);
02121
02122 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
02123 if (err != NULL) {
02124 *err = error;
02125 }
02126 }
02127
02128 Image3DGL() : Image3D() { }
02129
02130 Image3DGL(const Image3DGL& image) : Image3D(image) { }
02131
02132 Image3DGL& operator = (const Image3DGL& rhs)
02133 {
02134 if (this != &rhs) {
02135 Image3D::operator=(rhs);
02136 }
02137 return *this;
02138 }
02139 };
02140
02144 class Sampler : public detail::Wrapper<cl_sampler>
02145 {
02146 public:
02147 Sampler() { }
02148
02149 Sampler(
02150 const Context& context,
02151 cl_bool normalized_coords,
02152 cl_addressing_mode addressing_mode,
02153 cl_filter_mode filter_mode,
02154 cl_int* err = NULL)
02155 {
02156 cl_int error;
02157 object_ = ::clCreateSampler(
02158 context(),
02159 normalized_coords,
02160 addressing_mode,
02161 filter_mode,
02162 &error);
02163
02164 detail::errHandler(error, __CREATE_SAMPLER_ERR);
02165 if (err != NULL) {
02166 *err = error;
02167 }
02168 }
02169
02170 Sampler(const Sampler& sampler) : detail::Wrapper<cl_type>(sampler) { }
02171
02172 Sampler& operator = (const Sampler& rhs)
02173 {
02174 if (this != &rhs) {
02175 detail::Wrapper<cl_type>::operator=(rhs);
02176 }
02177 return *this;
02178 }
02179
02180 template <typename T>
02181 cl_int getInfo(cl_sampler_info name, T* param) const
02182 {
02183 return detail::errHandler(
02184 detail::getInfo(&::clGetSamplerInfo, object_, name, param),
02185 __GET_SAMPLER_INFO_ERR);
02186 }
02187
02188 template <cl_int name> typename
02189 detail::param_traits<detail::cl_sampler_info, name>::param_type
02190 getInfo(cl_int* err = NULL) const
02191 {
02192 typename detail::param_traits<
02193 detail::cl_sampler_info, name>::param_type param;
02194 cl_int result = getInfo(name, ¶m);
02195 if (err != NULL) {
02196 *err = result;
02197 }
02198 return param;
02199 }
02200 };
02201
02202 __GET_INFO_HELPER_WITH_RETAIN(cl::Sampler)
02203
02204 class Program;
02205 class CommandQueue;
02206 class Kernel;
02207
02211 class NDRange
02212 {
02213 private:
02214 size_t<3> sizes_;
02215 cl_uint dimensions_;
02216
02217 public:
02218 NDRange()
02219 : dimensions_(0)
02220 { }
02221
02222 NDRange(::size_t size0)
02223 : dimensions_(1)
02224 {
02225 sizes_.push_back(size0);
02226 }
02227
02228 NDRange(::size_t size0, ::size_t size1)
02229 : dimensions_(2)
02230 {
02231 sizes_.push_back(size0);
02232 sizes_.push_back(size1);
02233 }
02234
02235 NDRange(::size_t size0, ::size_t size1, ::size_t size2)
02236 : dimensions_(3)
02237 {
02238 sizes_.push_back(size0);
02239 sizes_.push_back(size1);
02240 sizes_.push_back(size2);
02241 }
02242
02243 operator const ::size_t*() const { return (const ::size_t*) sizes_; }
02244 ::size_t dimensions() const { return dimensions_; }
02245 };
02246
02247 static const NDRange NullRange;
02248
02253 struct LocalSpaceArg
02254 {
02255 ::size_t size_;
02256 };
02257
02258 namespace detail {
02259
02260 template <typename T>
02261 struct KernelArgumentHandler
02262 {
02263 static ::size_t size(const T&) { return sizeof(T); }
02264 static T* ptr(T& value) { return &value; }
02265 };
02266
02267 template <>
02268 struct KernelArgumentHandler<LocalSpaceArg>
02269 {
02270 static ::size_t size(const LocalSpaceArg& value) { return value.size_; }
02271 static void* ptr(LocalSpaceArg&) { return NULL; }
02272 };
02273
02274 }
02276
02277 inline LocalSpaceArg
02278 __local(::size_t size)
02279 {
02280 LocalSpaceArg ret = { size };
02281 return ret;
02282 }
02283
02284 class KernelFunctor;
02285
02289 class Kernel : public detail::Wrapper<cl_kernel>
02290 {
02291 public:
02292 inline Kernel(const Program& program, const char* name, cl_int* err = NULL);
02293
02294 Kernel() { }
02295
02296 Kernel(const Kernel& kernel) : detail::Wrapper<cl_type>(kernel) { }
02297
02298 Kernel& operator = (const Kernel& rhs)
02299 {
02300 if (this != &rhs) {
02301 detail::Wrapper<cl_type>::operator=(rhs);
02302 }
02303 return *this;
02304 }
02305
02306 template <typename T>
02307 cl_int getInfo(cl_kernel_info name, T* param) const
02308 {
02309 return detail::errHandler(
02310 detail::getInfo(&::clGetKernelInfo, object_, name, param),
02311 __GET_KERNEL_INFO_ERR);
02312 }
02313
02314 template <cl_int name> typename
02315 detail::param_traits<detail::cl_kernel_info, name>::param_type
02316 getInfo(cl_int* err = NULL) const
02317 {
02318 typename detail::param_traits<
02319 detail::cl_kernel_info, name>::param_type param;
02320 cl_int result = getInfo(name, ¶m);
02321 if (err != NULL) {
02322 *err = result;
02323 }
02324 return param;
02325 }
02326
02327 template <typename T>
02328 cl_int getWorkGroupInfo(
02329 const Device& device, cl_kernel_work_group_info name, T* param) const
02330 {
02331 return detail::errHandler(
02332 detail::getInfo(
02333 &::clGetKernelWorkGroupInfo, object_, device(), name, param),
02334 __GET_KERNEL_WORK_GROUP_INFO_ERR);
02335 }
02336
02337 template <cl_int name> typename
02338 detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
02339 getWorkGroupInfo(const Device& device, cl_int* err = NULL) const
02340 {
02341 typename detail::param_traits<
02342 detail::cl_kernel_work_group_info, name>::param_type param;
02343 cl_int result = getWorkGroupInfo(device, name, ¶m);
02344 if (err != NULL) {
02345 *err = result;
02346 }
02347 return param;
02348 }
02349
02350 template <typename T>
02351 cl_int setArg(cl_uint index, T value)
02352 {
02353 return detail::errHandler(
02354 ::clSetKernelArg(
02355 object_,
02356 index,
02357 detail::KernelArgumentHandler<T>::size(value),
02358 detail::KernelArgumentHandler<T>::ptr(value)),
02359 __SET_KERNEL_ARGS_ERR);
02360 }
02361
02362 cl_int setArg(cl_uint index, ::size_t size, void* argPtr)
02363 {
02364 return detail::errHandler(
02365 ::clSetKernelArg(object_, index, size, argPtr),
02366 __SET_KERNEL_ARGS_ERR);
02367 }
02368
02369 KernelFunctor bind(
02370 const CommandQueue& queue,
02371 const NDRange& offset,
02372 const NDRange& global,
02373 const NDRange& local);
02374
02375 KernelFunctor bind(
02376 const CommandQueue& queue,
02377 const NDRange& global,
02378 const NDRange& local);
02379 };
02380
02381 __GET_INFO_HELPER_WITH_RETAIN(cl::Kernel)
02382
02383
02386 class Program : public detail::Wrapper<cl_program>
02387 {
02388 public:
02389 typedef VECTOR_CLASS<std::pair<const void*, ::size_t> > Binaries;
02390 typedef VECTOR_CLASS<std::pair<const char*, ::size_t> > Sources;
02391
02392 Program(
02393 const Context& context,
02394 const Sources& sources,
02395 cl_int* err = NULL)
02396 {
02397 cl_int error;
02398
02399 const ::size_t n = (::size_t)sources.size();
02400 ::size_t* lengths = (::size_t*) alloca(n * sizeof(::size_t));
02401 const char** strings = (const char**) alloca(n * sizeof(const char*));
02402
02403 for (::size_t i = 0; i < n; ++i) {
02404 strings[i] = sources[(int)i].first;
02405 lengths[i] = sources[(int)i].second;
02406 }
02407
02408 object_ = ::clCreateProgramWithSource(
02409 context(), (cl_uint)n, strings, lengths, &error);
02410
02411 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
02412 if (err != NULL) {
02413 *err = error;
02414 }
02415 }
02416
02417 Program(
02418 const Context& context,
02419 const VECTOR_CLASS<Device>& devices,
02420 const Binaries& binaries,
02421 VECTOR_CLASS<cl_int>* binaryStatus = NULL,
02422 cl_int* err = NULL)
02423 {
02424 cl_int error;
02425 const ::size_t n = binaries.size();
02426 ::size_t* lengths = (::size_t*) alloca(n * sizeof(::size_t));
02427 const unsigned char** images = (const unsigned char**) alloca(n * sizeof(const void*));
02428
02429 for (::size_t i = 0; i < n; ++i) {
02430 images[i] = (const unsigned char*)binaries[(int)i].first;
02431 lengths[i] = binaries[(int)i].second;
02432 }
02433
02434 object_ = ::clCreateProgramWithBinary(
02435 context(), (cl_uint) devices.size(),
02436 (cl_device_id*)&devices.front(),
02437 lengths, images, binaryStatus != NULL
02438 ? (cl_int*) &binaryStatus->front()
02439 : NULL, &error);
02440
02441 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
02442 if (err != NULL) {
02443 *err = error;
02444 }
02445 }
02446
02447 Program() { }
02448
02449 Program(const Program& program) : detail::Wrapper<cl_type>(program) { }
02450
02451 Program& operator = (const Program& rhs)
02452 {
02453 if (this != &rhs) {
02454 detail::Wrapper<cl_type>::operator=(rhs);
02455 }
02456 return *this;
02457 }
02458
02459 cl_int build(
02460 const VECTOR_CLASS<Device>& devices,
02461 const char* options = NULL,
02462 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
02463 void* data = NULL) const
02464 {
02465 return detail::errHandler(
02466 ::clBuildProgram(
02467 object_,
02468 (cl_uint)
02469 devices.size(),
02470 (cl_device_id*)&devices.front(),
02471 options,
02472 notifyFptr,
02473 data),
02474 __BUILD_PROGRAM_ERR);
02475 }
02476
02477 template <typename T>
02478 cl_int getInfo(cl_program_info name, T* param) const
02479 {
02480 return detail::errHandler(
02481 detail::getInfo(&::clGetProgramInfo, object_, name, param),
02482 __GET_PROGRAM_INFO_ERR);
02483 }
02484
02485 template <cl_int name> typename
02486 detail::param_traits<detail::cl_program_info, name>::param_type
02487 getInfo(cl_int* err = NULL) const
02488 {
02489 typename detail::param_traits<
02490 detail::cl_program_info, name>::param_type param;
02491 cl_int result = getInfo(name, ¶m);
02492 if (err != NULL) {
02493 *err = result;
02494 }
02495 return param;
02496 }
02497
02498 template <typename T>
02499 cl_int getBuildInfo(
02500 const Device& device, cl_program_build_info name, T* param) const
02501 {
02502 return detail::errHandler(
02503 detail::getInfo(
02504 &::clGetProgramBuildInfo, object_, device(), name, param),
02505 __GET_PROGRAM_BUILD_INFO_ERR);
02506 }
02507
02508 template <cl_int name> typename
02509 detail::param_traits<detail::cl_program_build_info, name>::param_type
02510 getBuildInfo(const Device& device, cl_int* err = NULL) const
02511 {
02512 typename detail::param_traits<
02513 detail::cl_program_build_info, name>::param_type param;
02514 cl_int result = getBuildInfo(device, name, ¶m);
02515 if (err != NULL) {
02516 *err = result;
02517 }
02518 return param;
02519 }
02520
02521 cl_int createKernels(VECTOR_CLASS<Kernel>* kernels)
02522 {
02523 cl_uint numKernels;
02524 cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
02525 if (err != CL_SUCCESS) {
02526 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
02527 }
02528
02529 Kernel* value = (Kernel*) alloca(numKernels * sizeof(Kernel));
02530 err = ::clCreateKernelsInProgram(
02531 object_, numKernels, (cl_kernel*) value, NULL);
02532 if (err != CL_SUCCESS) {
02533 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
02534 }
02535
02536 kernels->assign(&value[0], &value[numKernels]);
02537 return CL_SUCCESS;
02538 }
02539 };
02540
02541 __GET_INFO_HELPER_WITH_RETAIN(cl::Program)
02542
02543 inline Kernel::Kernel(const Program& program, const char* name, cl_int* err)
02544 {
02545 cl_int error;
02546
02547 object_ = ::clCreateKernel(program(), name, &error);
02548 detail::errHandler(error, __CREATE_KERNEL_ERR);
02549
02550 if (err != NULL) {
02551 *err = error;
02552 }
02553
02554 }
02555
02559 class CommandQueue : public detail::Wrapper<cl_command_queue>
02560 {
02561 public:
02562 CommandQueue(
02563 const Context& context,
02564 const Device& device,
02565 cl_command_queue_properties properties = 0,
02566 cl_int* err = NULL)
02567 {
02568 cl_int error;
02569 object_ = ::clCreateCommandQueue(
02570 context(), device(), properties, &error);
02571
02572 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
02573 if (err != NULL) {
02574 *err = error;
02575 }
02576 }
02577
02578 CommandQueue() { }
02579
02580 CommandQueue(const CommandQueue& commandQueue) : detail::Wrapper<cl_type>(commandQueue) { }
02581
02582 CommandQueue& operator = (const CommandQueue& rhs)
02583 {
02584 if (this != &rhs) {
02585 detail::Wrapper<cl_type>::operator=(rhs);
02586 }
02587 return *this;
02588 }
02589
02590 template <typename T>
02591 cl_int getInfo(cl_command_queue_info name, T* param) const
02592 {
02593 return detail::errHandler(
02594 detail::getInfo(
02595 &::clGetCommandQueueInfo, object_, name, param),
02596 __GET_COMMAND_QUEUE_INFO_ERR);
02597 }
02598
02599 template <cl_int name> typename
02600 detail::param_traits<detail::cl_command_queue_info, name>::param_type
02601 getInfo(cl_int* err = NULL) const
02602 {
02603 typename detail::param_traits<
02604 detail::cl_command_queue_info, name>::param_type param;
02605 cl_int result = getInfo(name, ¶m);
02606 if (err != NULL) {
02607 *err = result;
02608 }
02609 return param;
02610 }
02611
02612 cl_int enqueueReadBuffer(
02613 const Buffer& buffer,
02614 cl_bool blocking,
02615 ::size_t offset,
02616 ::size_t size,
02617 void* ptr,
02618 const VECTOR_CLASS<Event>* events = NULL,
02619 Event* event = NULL) const
02620 {
02621 return detail::errHandler(
02622 ::clEnqueueReadBuffer(
02623 object_, buffer(), blocking, offset, size,
02624 ptr,
02625 (events != NULL) ? (cl_uint) events->size() : 0,
02626 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
02627 (cl_event*) event),
02628 __ENQUEUE_READ_BUFFER_ERR);
02629 }
02630
02631 cl_int enqueueWriteBuffer(
02632 const Buffer& buffer,
02633 cl_bool blocking,
02634 ::size_t offset,
02635 ::size_t size,
02636 const void* ptr,
02637 const VECTOR_CLASS<Event>* events = NULL,
02638 Event* event = NULL) const
02639 {
02640 return detail::errHandler(
02641 ::clEnqueueWriteBuffer(
02642 object_, buffer(), blocking, offset, size,
02643 ptr,
02644 (events != NULL) ? (cl_uint) events->size() : 0,
02645 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
02646 (cl_event*) event),
02647 __ENQUEUE_WRITE_BUFFER_ERR);
02648 }
02649
02650 cl_int enqueueCopyBuffer(
02651 const Buffer& src,
02652 const Buffer& dst,
02653 ::size_t src_offset,
02654 ::size_t dst_offset,
02655 ::size_t size,
02656 const VECTOR_CLASS<Event>* events = NULL,
02657 Event* event = NULL) const
02658 {
02659 return detail::errHandler(
02660 ::clEnqueueCopyBuffer(
02661 object_, src(), dst(), src_offset, dst_offset, size,
02662 (events != NULL) ? (cl_uint) events->size() : 0,
02663 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
02664 (cl_event*) event),
02665 __ENQEUE_COPY_BUFFER_ERR);
02666 }
02667
02668 #if defined(CL_VERSION_1_1)
02669 cl_int enqueueReadBufferRect(
02670 const Buffer& buffer,
02671 cl_bool blocking,
02672 const size_t<3>& buffer_offset,
02673 const size_t<3>& host_offset,
02674 const size_t<3>& region,
02675 ::size_t buffer_row_pitch,
02676 ::size_t buffer_slice_pitch,
02677 ::size_t host_row_pitch,
02678 ::size_t host_slice_pitch,
02679 void *ptr,
02680 const VECTOR_CLASS<Event>* events = NULL,
02681 Event* event = NULL) const
02682 {
02683 return detail::errHandler(
02684 ::clEnqueueReadBufferRect(
02685 object_,
02686 buffer(),
02687 blocking,
02688 (const ::size_t *)buffer_offset,
02689 (const ::size_t *)host_offset,
02690 (const ::size_t *)region,
02691 buffer_row_pitch,
02692 buffer_slice_pitch,
02693 host_row_pitch,
02694 host_slice_pitch,
02695 ptr,
02696 (events != NULL) ? (cl_uint) events->size() : 0,
02697 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
02698 (cl_event*) event),
02699 __ENQUEUE_READ_BUFFER_RECT_ERR);
02700 }
02701
02702
02703 cl_int enqueueWriteBufferRect(
02704 const Buffer& buffer,
02705 cl_bool blocking,
02706 const size_t<3>& buffer_offset,
02707 const size_t<3>& host_offset,
02708 const size_t<3>& region,
02709 ::size_t buffer_row_pitch,
02710 ::size_t buffer_slice_pitch,
02711 ::size_t host_row_pitch,
02712 ::size_t host_slice_pitch,
02713 void *ptr,
02714 const VECTOR_CLASS<Event>* events = NULL,
02715 Event* event = NULL) const
02716 {
02717 return detail::errHandler(
02718 ::clEnqueueWriteBufferRect(
02719 object_,
02720 buffer(),
02721 blocking,
02722 (const ::size_t *)buffer_offset,
02723 (const ::size_t *)host_offset,
02724 (const ::size_t *)region,
02725 buffer_row_pitch,
02726 buffer_slice_pitch,
02727 host_row_pitch,
02728 host_slice_pitch,
02729 ptr,
02730 (events != NULL) ? (cl_uint) events->size() : 0,
02731 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
02732 (cl_event*) event),
02733 __ENQUEUE_WRITE_BUFFER_RECT_ERR);
02734 }
02735
02736 cl_int enqueueCopyBufferRect(
02737 const Buffer& src,
02738 const Buffer& dst,
02739 const size_t<3>& src_origin,
02740 const size_t<3>& dst_origin,
02741 const size_t<3>& region,
02742 ::size_t src_row_pitch,
02743 ::size_t src_slice_pitch,
02744 ::size_t dst_row_pitch,
02745 ::size_t dst_slice_pitch,
02746 const VECTOR_CLASS<Event>* events = NULL,
02747 Event* event = NULL) const
02748 {
02749 return detail::errHandler(
02750 ::clEnqueueCopyBufferRect(
02751 object_,
02752 src(),
02753 dst(),
02754 (const ::size_t *)src_origin,
02755 (const ::size_t *)dst_origin,
02756 (const ::size_t *)region,
02757 src_row_pitch,
02758 src_slice_pitch,
02759 dst_row_pitch,
02760 dst_slice_pitch,
02761 (events != NULL) ? (cl_uint) events->size() : 0,
02762 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
02763 (cl_event*) event),
02764 __ENQEUE_COPY_BUFFER_RECT_ERR);
02765 }
02766 #endif
02767
02768 cl_int enqueueReadImage(
02769 const Image& image,
02770 cl_bool blocking,
02771 const size_t<3>& origin,
02772 const size_t<3>& region,
02773 ::size_t row_pitch,
02774 ::size_t slice_pitch,
02775 void* ptr,
02776 const VECTOR_CLASS<Event>* events = NULL,
02777 Event* event = NULL) const
02778 {
02779 return detail::errHandler(
02780 ::clEnqueueReadImage(
02781 object_, image(), blocking, (const ::size_t *) origin,
02782 (const ::size_t *) region, row_pitch, slice_pitch, ptr,
02783 (events != NULL) ? (cl_uint) events->size() : 0,
02784 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
02785 (cl_event*) event),
02786 __ENQUEUE_READ_IMAGE_ERR);
02787 }
02788
02789 cl_int enqueueWriteImage(
02790 const Image& image,
02791 cl_bool blocking,
02792 const size_t<3>& origin,
02793 const size_t<3>& region,
02794 ::size_t row_pitch,
02795 ::size_t slice_pitch,
02796 void* ptr,
02797 const VECTOR_CLASS<Event>* events = NULL,
02798 Event* event = NULL) const
02799 {
02800 return detail::errHandler(
02801 ::clEnqueueWriteImage(
02802 object_, image(), blocking, (const ::size_t *) origin,
02803 (const ::size_t *) region, row_pitch, slice_pitch, ptr,
02804 (events != NULL) ? (cl_uint) events->size() : 0,
02805 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
02806 (cl_event*) event),
02807 __ENQUEUE_WRITE_IMAGE_ERR);
02808 }
02809
02810 cl_int enqueueCopyImage(
02811 const Image& src,
02812 const Image& dst,
02813 const size_t<3>& src_origin,
02814 const size_t<3>& dst_origin,
02815 const size_t<3>& region,
02816 const VECTOR_CLASS<Event>* events = NULL,
02817 Event* event = NULL) const
02818 {
02819 return detail::errHandler(
02820 ::clEnqueueCopyImage(
02821 object_, src(), dst(), (const ::size_t *) src_origin,
02822 (const ::size_t *)dst_origin, (const ::size_t *) region,
02823 (events != NULL) ? (cl_uint) events->size() : 0,
02824 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
02825 (cl_event*) event),
02826 __ENQUEUE_COPY_IMAGE_ERR);
02827 }
02828
02829 cl_int enqueueCopyImageToBuffer(
02830 const Image& src,
02831 const Buffer& dst,
02832 const size_t<3>& src_origin,
02833 const size_t<3>& region,
02834 ::size_t dst_offset,
02835 const VECTOR_CLASS<Event>* events = NULL,
02836 Event* event = NULL) const
02837 {
02838 return detail::errHandler(
02839 ::clEnqueueCopyImageToBuffer(
02840 object_, src(), dst(), (const ::size_t *) src_origin,
02841 (const ::size_t *) region, dst_offset,
02842 (events != NULL) ? (cl_uint) events->size() : 0,
02843 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
02844 (cl_event*) event),
02845 __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
02846 }
02847
02848 cl_int enqueueCopyBufferToImage(
02849 const Buffer& src,
02850 const Image& dst,
02851 ::size_t src_offset,
02852 const size_t<3>& dst_origin,
02853 const size_t<3>& region,
02854 const VECTOR_CLASS<Event>* events = NULL,
02855 Event* event = NULL) const
02856 {
02857 return detail::errHandler(
02858 ::clEnqueueCopyBufferToImage(
02859 object_, src(), dst(), src_offset,
02860 (const ::size_t *) dst_origin, (const ::size_t *) region,
02861 (events != NULL) ? (cl_uint) events->size() : 0,
02862 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
02863 (cl_event*) event),
02864 __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
02865 }
02866
02867 void* enqueueMapBuffer(
02868 const Buffer& buffer,
02869 cl_bool blocking,
02870 cl_map_flags flags,
02871 ::size_t offset,
02872 ::size_t size,
02873 const VECTOR_CLASS<Event>* events = NULL,
02874 Event* event = NULL,
02875 cl_int* err = NULL) const
02876 {
02877 cl_int error;
02878 void * result = ::clEnqueueMapBuffer(
02879 object_, buffer(), blocking, flags, offset, size,
02880 (events != NULL) ? (cl_uint) events->size() : 0,
02881 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
02882 (cl_event*) event,
02883 &error);
02884
02885 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
02886 if (err != NULL) {
02887 *err = error;
02888 }
02889 return result;
02890 }
02891
02892 void* enqueueMapImage(
02893 const Image& buffer,
02894 cl_bool blocking,
02895 cl_map_flags flags,
02896 const size_t<3>& origin,
02897 const size_t<3>& region,
02898 ::size_t * row_pitch,
02899 ::size_t * slice_pitch,
02900 const VECTOR_CLASS<Event>* events = NULL,
02901 Event* event = NULL,
02902 cl_int* err = NULL) const
02903 {
02904 cl_int error;
02905 void * result = ::clEnqueueMapImage(
02906 object_, buffer(), blocking, flags,
02907 (const ::size_t *) origin, (const ::size_t *) region,
02908 row_pitch, slice_pitch,
02909 (events != NULL) ? (cl_uint) events->size() : 0,
02910 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
02911 (cl_event*) event,
02912 &error);
02913
02914 detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
02915 if (err != NULL) {
02916 *err = error;
02917 }
02918 return result;
02919 }
02920
02921 cl_int enqueueUnmapMemObject(
02922 const Memory& memory,
02923 void* mapped_ptr,
02924 const VECTOR_CLASS<Event>* events = NULL,
02925 Event* event = NULL) const
02926 {
02927 return detail::errHandler(
02928 ::clEnqueueUnmapMemObject(
02929 object_, memory(), mapped_ptr,
02930 (events != NULL) ? (cl_uint) events->size() : 0,
02931 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
02932 (cl_event*) event),
02933 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
02934 }
02935
02936 cl_int enqueueNDRangeKernel(
02937 const Kernel& kernel,
02938 const NDRange& offset,
02939 const NDRange& global,
02940 const NDRange& local,
02941 const VECTOR_CLASS<Event>* events = NULL,
02942 Event* event = NULL) const
02943 {
02944 return detail::errHandler(
02945 ::clEnqueueNDRangeKernel(
02946 object_, kernel(), (cl_uint) global.dimensions(),
02947 offset.dimensions() != 0 ? (const ::size_t*) offset : NULL,
02948 (const ::size_t*) global,
02949 local.dimensions() != 0 ? (const ::size_t*) local : NULL,
02950 (events != NULL) ? (cl_uint) events->size() : 0,
02951 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
02952 (cl_event*) event),
02953 __ENQUEUE_NDRANGE_KERNEL_ERR);
02954 }
02955
02956 cl_int enqueueTask(
02957 const Kernel& kernel,
02958 const VECTOR_CLASS<Event>* events = NULL,
02959 Event* event = NULL) const
02960 {
02961 return detail::errHandler(
02962 ::clEnqueueTask(
02963 object_, kernel(),
02964 (events != NULL) ? (cl_uint) events->size() : 0,
02965 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
02966 (cl_event*) event),
02967 __ENQUEUE_TASK_ERR);
02968 }
02969
02970 cl_int enqueueNativeKernel(
02971 void (*userFptr)(void *),
02972 std::pair<void*, ::size_t> args,
02973 const VECTOR_CLASS<Memory>* mem_objects = NULL,
02974 const VECTOR_CLASS<const void*>* mem_locs = NULL,
02975 const VECTOR_CLASS<Event>* events = NULL,
02976 Event* event = NULL) const
02977 {
02978 cl_mem * mems = (mem_objects != NULL && mem_objects->size() > 0)
02979 ? (cl_mem*) alloca(mem_objects->size() * sizeof(cl_mem))
02980 : NULL;
02981
02982 if (mems != NULL) {
02983 for (unsigned int i = 0; i < mem_objects->size(); i++) {
02984 mems[i] = ((*mem_objects)[i])();
02985 }
02986 }
02987
02988 return detail::errHandler(
02989 ::clEnqueueNativeKernel(
02990 object_, userFptr, args.first, args.second,
02991 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
02992 mems,
02993 (mem_locs != NULL) ? (const void **) &mem_locs->front() : NULL,
02994 (events != NULL) ? (cl_uint) events->size() : 0,
02995 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
02996 (cl_event*) event),
02997 __ENQUEUE_NATIVE_KERNEL);
02998 }
02999
03000 cl_int enqueueMarker(Event* event = NULL) const
03001 {
03002 return detail::errHandler(
03003 ::clEnqueueMarker(object_, (cl_event*) event),
03004 __ENQUEUE_MARKER_ERR);
03005 }
03006
03007 cl_int enqueueWaitForEvents(const VECTOR_CLASS<Event>& events) const
03008 {
03009 return detail::errHandler(
03010 ::clEnqueueWaitForEvents(
03011 object_,
03012 (cl_uint) events.size(),
03013 (const cl_event*) &events.front()),
03014 __ENQUEUE_WAIT_FOR_EVENTS_ERR);
03015 }
03016
03017 cl_int enqueueAcquireGLObjects(
03018 const VECTOR_CLASS<Memory>* mem_objects = NULL,
03019 const VECTOR_CLASS<Event>* events = NULL,
03020 Event* event = NULL) const
03021 {
03022 return detail::errHandler(
03023 ::clEnqueueAcquireGLObjects(
03024 object_,
03025 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
03026 (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
03027 (events != NULL) ? (cl_uint) events->size() : 0,
03028 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
03029 (cl_event*) event),
03030 __ENQUEUE_ACQUIRE_GL_ERR);
03031 }
03032
03033 cl_int enqueueReleaseGLObjects(
03034 const VECTOR_CLASS<Memory>* mem_objects = NULL,
03035 const VECTOR_CLASS<Event>* events = NULL,
03036 Event* event = NULL) const
03037 {
03038 return detail::errHandler(
03039 ::clEnqueueReleaseGLObjects(
03040 object_,
03041 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
03042 (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
03043 (events != NULL) ? (cl_uint) events->size() : 0,
03044 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
03045 (cl_event*) event),
03046 __ENQUEUE_RELEASE_GL_ERR);
03047 }
03048
03049 #if defined (USE_DX_INTEROP)
03050 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
03051 cl_command_queue command_queue, cl_uint num_objects,
03052 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
03053 const cl_event* event_wait_list, cl_event* event);
03054 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
03055 cl_command_queue command_queue, cl_uint num_objects,
03056 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
03057 const cl_event* event_wait_list, cl_event* event);
03058
03059 cl_int enqueueAcquireD3D10Objects(
03060 const VECTOR_CLASS<Memory>* mem_objects = NULL,
03061 const VECTOR_CLASS<Event>* events = NULL,
03062 Event* event = NULL) const
03063 {
03064 static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
03065 __INIT_CL_EXT_FCN_PTR(clEnqueueAcquireD3D10ObjectsKHR);
03066
03067 return detail::errHandler(
03068 pfn_clEnqueueAcquireD3D10ObjectsKHR(
03069 object_,
03070 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
03071 (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
03072 (events != NULL) ? (cl_uint) events->size() : 0,
03073 (events != NULL) ? (cl_event*) &events->front() : NULL,
03074 (cl_event*) event),
03075 __ENQUEUE_ACQUIRE_GL_ERR);
03076 }
03077
03078 cl_int enqueueReleaseD3D10Objects(
03079 const VECTOR_CLASS<Memory>* mem_objects = NULL,
03080 const VECTOR_CLASS<Event>* events = NULL,
03081 Event* event = NULL) const
03082 {
03083 static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL;
03084 __INIT_CL_EXT_FCN_PTR(clEnqueueReleaseD3D10ObjectsKHR);
03085
03086 return detail::errHandler(
03087 pfn_clEnqueueReleaseD3D10ObjectsKHR(
03088 object_,
03089 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
03090 (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
03091 (events != NULL) ? (cl_uint) events->size() : 0,
03092 (events != NULL) ? (cl_event*) &events->front() : NULL,
03093 (cl_event*) event),
03094 __ENQUEUE_RELEASE_GL_ERR);
03095 }
03096 #endif
03097
03098 cl_int enqueueBarrier() const
03099 {
03100 return detail::errHandler(
03101 ::clEnqueueBarrier(object_),
03102 __ENQUEUE_BARRIER_ERR);
03103 }
03104
03105 cl_int flush() const
03106 {
03107 return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
03108 }
03109
03110 cl_int finish() const
03111 {
03112 return detail::errHandler(::clFinish(object_), __FINISH_ERR);
03113 }
03114 };
03115
03116 __GET_INFO_HELPER_WITH_RETAIN(cl::CommandQueue)
03117
03118
03125 class KernelFunctor
03126 {
03127 private:
03128 Kernel kernel_;
03129 CommandQueue queue_;
03130 NDRange offset_;
03131 NDRange global_;
03132 NDRange local_;
03133
03134 cl_int err_;
03135 public:
03136 KernelFunctor() { }
03137
03138 KernelFunctor(
03139 const Kernel& kernel,
03140 const CommandQueue& queue,
03141 const NDRange& offset,
03142 const NDRange& global,
03143 const NDRange& local) :
03144 kernel_(kernel),
03145 queue_(queue),
03146 offset_(offset),
03147 global_(global),
03148 local_(local),
03149 err_(CL_SUCCESS)
03150 {}
03151
03152 KernelFunctor& operator=(const KernelFunctor& rhs);
03153
03154 KernelFunctor(const KernelFunctor& rhs);
03155
03156 cl_int getError() { return err_; }
03157
03158 inline Event operator()(const VECTOR_CLASS<Event>* events = NULL);
03159
03160 template<typename A1>
03161 inline Event operator()(
03162 const A1& a1,
03163 const VECTOR_CLASS<Event>* events = NULL);
03164
03165 template<class A1, class A2>
03166 inline Event operator()(
03167 const A1& a1,
03168 const A2& a2,
03169 const VECTOR_CLASS<Event>* events = NULL);
03170
03171 template<class A1, class A2, class A3>
03172 inline Event operator()(
03173 const A1& a1,
03174 const A2& a2,
03175 const A3& a3,
03176 const VECTOR_CLASS<Event>* events = NULL);
03177
03178 template<class A1, class A2, class A3, class A4>
03179 inline Event operator()(
03180 const A1& a1,
03181 const A2& a2,
03182 const A3& a3,
03183 const A4& a4,
03184 const VECTOR_CLASS<Event>* events = NULL);
03185
03186 template<class A1, class A2, class A3, class A4, class A5>
03187 inline Event operator()(
03188 const A1& a1,
03189 const A2& a2,
03190 const A3& a3,
03191 const A4& a4,
03192 const A5& a5,
03193 const VECTOR_CLASS<Event>* events = NULL);
03194
03195 template<class A1, class A2, class A3, class A4, class A5, class A6>
03196 inline Event operator()(
03197 const A1& a1,
03198 const A2& a2,
03199 const A3& a3,
03200 const A4& a4,
03201 const A5& a5,
03202 const A6& a6,
03203 const VECTOR_CLASS<Event>* events = NULL);
03204
03205 template<class A1, class A2, class A3, class A4,
03206 class A5, class A6, class A7>
03207 inline Event operator()(
03208 const A1& a1,
03209 const A2& a2,
03210 const A3& a3,
03211 const A4& a4,
03212 const A5& a5,
03213 const A6& a6,
03214 const A7& a7,
03215 const VECTOR_CLASS<Event>* events = NULL);
03216
03217 template<class A1, class A2, class A3, class A4, class A5,
03218 class A6, class A7, class A8>
03219 inline Event operator()(
03220 const A1& a1,
03221 const A2& a2,
03222 const A3& a3,
03223 const A4& a4,
03224 const A5& a5,
03225 const A6& a6,
03226 const A7& a7,
03227 const A8& a8,
03228 const VECTOR_CLASS<Event>* events = NULL);
03229
03230 template<class A1, class A2, class A3, class A4, class A5,
03231 class A6, class A7, class A8, class A9>
03232 inline Event operator()(
03233 const A1& a1,
03234 const A2& a2,
03235 const A3& a3,
03236 const A4& a4,
03237 const A5& a5,
03238 const A6& a6,
03239 const A7& a7,
03240 const A8& a8,
03241 const A9& a9,
03242 const VECTOR_CLASS<Event>* events = NULL);
03243
03244 template<class A1, class A2, class A3, class A4, class A5,
03245 class A6, class A7, class A8, class A9, class A10>
03246 inline Event operator()(
03247 const A1& a1,
03248 const A2& a2,
03249 const A3& a3,
03250 const A4& a4,
03251 const A5& a5,
03252 const A6& a6,
03253 const A7& a7,
03254 const A8& a8,
03255 const A9& a9,
03256 const A10& a10,
03257 const VECTOR_CLASS<Event>* events = NULL);
03258
03259 template<class A1, class A2, class A3, class A4, class A5,
03260 class A6, class A7, class A8, class A9, class A10,
03261 class A11>
03262 inline Event operator()(
03263 const A1& a1,
03264 const A2& a2,
03265 const A3& a3,
03266 const A4& a4,
03267 const A5& a5,
03268 const A6& a6,
03269 const A7& a7,
03270 const A8& a8,
03271 const A9& a9,
03272 const A10& a10,
03273 const A11& a11,
03274 const VECTOR_CLASS<Event>* events = NULL);
03275
03276 template<class A1, class A2, class A3, class A4, class A5,
03277 class A6, class A7, class A8, class A9, class A10,
03278 class A11, class A12>
03279 inline Event operator()(
03280 const A1& a1,
03281 const A2& a2,
03282 const A3& a3,
03283 const A4& a4,
03284 const A5& a5,
03285 const A6& a6,
03286 const A7& a7,
03287 const A8& a8,
03288 const A9& a9,
03289 const A10& a10,
03290 const A11& a11,
03291 const A12& a12,
03292 const VECTOR_CLASS<Event>* events = NULL);
03293
03294 template<class A1, class A2, class A3, class A4, class A5,
03295 class A6, class A7, class A8, class A9, class A10,
03296 class A11, class A12, class A13>
03297 inline Event operator()(
03298 const A1& a1,
03299 const A2& a2,
03300 const A3& a3,
03301 const A4& a4,
03302 const A5& a5,
03303 const A6& a6,
03304 const A7& a7,
03305 const A8& a8,
03306 const A9& a9,
03307 const A10& a10,
03308 const A11& a11,
03309 const A12& a12,
03310 const A13& a13,
03311 const VECTOR_CLASS<Event>* events = NULL);
03312
03313 template<class A1, class A2, class A3, class A4, class A5,
03314 class A6, class A7, class A8, class A9, class A10,
03315 class A11, class A12, class A13, class A14>
03316 inline Event operator()(
03317 const A1& a1,
03318 const A2& a2,
03319 const A3& a3,
03320 const A4& a4,
03321 const A5& a5,
03322 const A6& a6,
03323 const A7& a7,
03324 const A8& a8,
03325 const A9& a9,
03326 const A10& a10,
03327 const A11& a11,
03328 const A12& a12,
03329 const A13& a13,
03330 const A14& a14,
03331 const VECTOR_CLASS<Event>* events = NULL);
03332
03333 template<class A1, class A2, class A3, class A4, class A5,
03334 class A6, class A7, class A8, class A9, class A10,
03335 class A11, class A12, class A13, class A14, class A15>
03336 inline Event operator()(
03337 const A1& a1,
03338 const A2& a2,
03339 const A3& a3,
03340 const A4& a4,
03341 const A5& a5,
03342 const A6& a6,
03343 const A7& a7,
03344 const A8& a8,
03345 const A9& a9,
03346 const A10& a10,
03347 const A11& a11,
03348 const A12& a12,
03349 const A13& a13,
03350 const A14& a14,
03351 const A15& a15,
03352 const VECTOR_CLASS<Event>* events = NULL);
03353 };
03354
03355 inline KernelFunctor Kernel::bind(
03356 const CommandQueue& queue,
03357 const NDRange& offset,
03358 const NDRange& global,
03359 const NDRange& local)
03360 {
03361 return KernelFunctor(*this,queue,offset,global,local);
03362 }
03363
03364 inline KernelFunctor Kernel::bind(
03365 const CommandQueue& queue,
03366 const NDRange& global,
03367 const NDRange& local)
03368 {
03369 return KernelFunctor(*this,queue,NullRange,global,local);
03370 }
03371
03372 inline KernelFunctor& KernelFunctor::operator=(const KernelFunctor& rhs)
03373 {
03374 if (this == &rhs) {
03375 return *this;
03376 }
03377
03378 kernel_ = rhs.kernel_;
03379 queue_ = rhs.queue_;
03380 offset_ = rhs.offset_;
03381 global_ = rhs.global_;
03382 local_ = rhs.local_;
03383
03384 return *this;
03385 }
03386
03387 inline KernelFunctor::KernelFunctor(const KernelFunctor& rhs) :
03388 kernel_(rhs.kernel_),
03389 queue_(rhs.queue_),
03390 offset_(rhs.offset_),
03391 global_(rhs.global_),
03392 local_(rhs.local_)
03393 {
03394 }
03395
03396 Event KernelFunctor::operator()(const VECTOR_CLASS<Event>* events)
03397 {
03398 Event event;
03399
03400 err_ = queue_.enqueueNDRangeKernel(
03401 kernel_,
03402 offset_,
03403 global_,
03404 local_,
03405 NULL,
03406 &event);
03407
03408 return event;
03409 }
03410
03411 template<typename A1>
03412 Event KernelFunctor::operator()(
03413 const A1& a1,
03414 const VECTOR_CLASS<Event>* events)
03415 {
03416 Event event;
03417
03418 kernel_.setArg(0,a1);
03419
03420 err_ = queue_.enqueueNDRangeKernel(
03421 kernel_,
03422 offset_,
03423 global_,
03424 local_,
03425 NULL,
03426 &event);
03427
03428 return event;
03429 }
03430
03431 template<typename A1, typename A2>
03432 Event KernelFunctor::operator()(
03433 const A1& a1,
03434 const A2& a2,
03435 const VECTOR_CLASS<Event>* events)
03436 {
03437 Event event;
03438
03439 kernel_.setArg(0,a1);
03440 kernel_.setArg(1,a2);
03441
03442 err_ = queue_.enqueueNDRangeKernel(
03443 kernel_,
03444 offset_,
03445 global_,
03446 local_,
03447 NULL,
03448 &event);
03449
03450 return event;
03451 }
03452
03453 template<typename A1, typename A2, typename A3>
03454 Event KernelFunctor::operator()(
03455 const A1& a1,
03456 const A2& a2,
03457 const A3& a3,
03458 const VECTOR_CLASS<Event>* events)
03459 {
03460 Event event;
03461
03462 kernel_.setArg(0,a1);
03463 kernel_.setArg(1,a2);
03464 kernel_.setArg(2,a3);
03465
03466 err_ = queue_.enqueueNDRangeKernel(
03467 kernel_,
03468 offset_,
03469 global_,
03470 local_,
03471 NULL,
03472 &event);
03473
03474 return event;
03475 }
03476
03477 template<typename A1, typename A2, typename A3, typename A4>
03478 Event KernelFunctor::operator()(
03479 const A1& a1,
03480 const A2& a2,
03481 const A3& a3,
03482 const A4& a4,
03483 const VECTOR_CLASS<Event>* events)
03484 {
03485 Event event;
03486
03487 kernel_.setArg(0,a1);
03488 kernel_.setArg(1,a2);
03489 kernel_.setArg(2,a3);
03490 kernel_.setArg(3,a4);
03491
03492 err_ = queue_.enqueueNDRangeKernel(
03493 kernel_,
03494 offset_,
03495 global_,
03496 local_,
03497 NULL,
03498 &event);
03499
03500 return event;
03501 }
03502
03503 template<typename A1, typename A2, typename A3, typename A4, typename A5>
03504 Event KernelFunctor::operator()(
03505 const A1& a1,
03506 const A2& a2,
03507 const A3& a3,
03508 const A4& a4,
03509 const A5& a5,
03510 const VECTOR_CLASS<Event>* events)
03511 {
03512 Event event;
03513
03514 kernel_.setArg(0,a1);
03515 kernel_.setArg(1,a2);
03516 kernel_.setArg(2,a3);
03517 kernel_.setArg(3,a4);
03518 kernel_.setArg(4,a5);
03519
03520 err_ = queue_.enqueueNDRangeKernel(
03521 kernel_,
03522 offset_,
03523 global_,
03524 local_,
03525 NULL,
03526 &event);
03527
03528 return event;
03529 }
03530
03531 template<typename A1, typename A2, typename A3, typename A4, typename A5,
03532 typename A6>
03533 Event KernelFunctor::operator()(
03534 const A1& a1,
03535 const A2& a2,
03536 const A3& a3,
03537 const A4& a4,
03538 const A5& a5,
03539 const A6& a6,
03540 const VECTOR_CLASS<Event>* events)
03541 {
03542 Event event;
03543
03544 kernel_.setArg(0,a1);
03545 kernel_.setArg(1,a2);
03546 kernel_.setArg(2,a3);
03547 kernel_.setArg(3,a4);
03548 kernel_.setArg(4,a5);
03549 kernel_.setArg(5,a6);
03550
03551 err_ = queue_.enqueueNDRangeKernel(
03552 kernel_,
03553 offset_,
03554 global_,
03555 local_,
03556 NULL,
03557 &event);
03558
03559 return event;
03560 }
03561
03562 template<typename A1, typename A2, typename A3, typename A4,
03563 typename A5, typename A6, typename A7>
03564 Event KernelFunctor::operator()(
03565 const A1& a1,
03566 const A2& a2,
03567 const A3& a3,
03568 const A4& a4,
03569 const A5& a5,
03570 const A6& a6,
03571 const A7& a7,
03572 const VECTOR_CLASS<Event>* events)
03573 {
03574 Event event;
03575
03576 kernel_.setArg(0,a1);
03577 kernel_.setArg(1,a2);
03578 kernel_.setArg(2,a3);
03579 kernel_.setArg(3,a4);
03580 kernel_.setArg(4,a5);
03581 kernel_.setArg(5,a6);
03582 kernel_.setArg(6,a7);
03583
03584 err_ = queue_.enqueueNDRangeKernel(
03585 kernel_,
03586 offset_,
03587 global_,
03588 local_,
03589 NULL,
03590 &event);
03591
03592 return event;
03593 }
03594
03595 template<typename A1, typename A2, typename A3, typename A4, typename A5,
03596 typename A6, typename A7, typename A8>
03597 Event KernelFunctor::operator()(
03598 const A1& a1,
03599 const A2& a2,
03600 const A3& a3,
03601 const A4& a4,
03602 const A5& a5,
03603 const A6& a6,
03604 const A7& a7,
03605 const A8& a8,
03606 const VECTOR_CLASS<Event>* events)
03607 {
03608 Event event;
03609
03610 kernel_.setArg(0,a1);
03611 kernel_.setArg(1,a2);
03612 kernel_.setArg(2,a3);
03613 kernel_.setArg(3,a4);
03614 kernel_.setArg(4,a5);
03615 kernel_.setArg(5,a6);
03616 kernel_.setArg(6,a7);
03617 kernel_.setArg(7,a8);
03618
03619 err_ = queue_.enqueueNDRangeKernel(
03620 kernel_,
03621 offset_,
03622 global_,
03623 local_,
03624 NULL,
03625 &event);
03626
03627 return event;
03628 }
03629
03630 template<typename A1, typename A2, typename A3, typename A4, typename A5,
03631 typename A6, typename A7, typename A8, typename A9>
03632 Event KernelFunctor::operator()(
03633 const A1& a1,
03634 const A2& a2,
03635 const A3& a3,
03636 const A4& a4,
03637 const A5& a5,
03638 const A6& a6,
03639 const A7& a7,
03640 const A8& a8,
03641 const A9& a9,
03642 const VECTOR_CLASS<Event>* events)
03643 {
03644 Event event;
03645
03646 kernel_.setArg(0,a1);
03647 kernel_.setArg(1,a2);
03648 kernel_.setArg(2,a3);
03649 kernel_.setArg(3,a4);
03650 kernel_.setArg(4,a5);
03651 kernel_.setArg(5,a6);
03652 kernel_.setArg(6,a7);
03653 kernel_.setArg(7,a8);
03654 kernel_.setArg(8,a9);
03655
03656 err_ = queue_.enqueueNDRangeKernel(
03657 kernel_,
03658 offset_,
03659 global_,
03660 local_,
03661 NULL,
03662 &event);
03663
03664 return event;
03665 }
03666
03667 template<typename A1, typename A2, typename A3, typename A4, typename A5,
03668 typename A6, typename A7, typename A8, typename A9, typename A10>
03669 Event KernelFunctor::operator()(
03670 const A1& a1,
03671 const A2& a2,
03672 const A3& a3,
03673 const A4& a4,
03674 const A5& a5,
03675 const A6& a6,
03676 const A7& a7,
03677 const A8& a8,
03678 const A9& a9,
03679 const A10& a10,
03680 const VECTOR_CLASS<Event>* events)
03681 {
03682 Event event;
03683
03684 kernel_.setArg(0,a1);
03685 kernel_.setArg(1,a2);
03686 kernel_.setArg(2,a3);
03687 kernel_.setArg(3,a4);
03688 kernel_.setArg(4,a5);
03689 kernel_.setArg(5,a6);
03690 kernel_.setArg(6,a7);
03691 kernel_.setArg(7,a8);
03692 kernel_.setArg(8,a9);
03693 kernel_.setArg(9,a10);
03694
03695 err_ = queue_.enqueueNDRangeKernel(
03696 kernel_,
03697 offset_,
03698 global_,
03699 local_,
03700 NULL,
03701 &event);
03702
03703 return event;
03704 }
03705
03706 template<class A1, class A2, class A3, class A4, class A5,
03707 class A6, class A7, class A8, class A9, class A10,
03708 class A11>
03709 Event KernelFunctor::operator()(
03710 const A1& a1,
03711 const A2& a2,
03712 const A3& a3,
03713 const A4& a4,
03714 const A5& a5,
03715 const A6& a6,
03716 const A7& a7,
03717 const A8& a8,
03718 const A9& a9,
03719 const A10& a10,
03720 const A11& a11,
03721 const VECTOR_CLASS<Event>* events)
03722 {
03723 Event event;
03724
03725 kernel_.setArg(0,a1);
03726 kernel_.setArg(1,a2);
03727 kernel_.setArg(2,a3);
03728 kernel_.setArg(3,a4);
03729 kernel_.setArg(4,a5);
03730 kernel_.setArg(5,a6);
03731 kernel_.setArg(6,a7);
03732 kernel_.setArg(7,a8);
03733 kernel_.setArg(8,a9);
03734 kernel_.setArg(9,a10);
03735 kernel_.setArg(10,a11);
03736
03737 err_ = queue_.enqueueNDRangeKernel(
03738 kernel_,
03739 offset_,
03740 global_,
03741 local_,
03742 NULL,
03743 &event);
03744
03745 return event;
03746 }
03747
03748 template<class A1, class A2, class A3, class A4, class A5,
03749 class A6, class A7, class A8, class A9, class A10,
03750 class A11, class A12>
03751 Event KernelFunctor::operator()(
03752 const A1& a1,
03753 const A2& a2,
03754 const A3& a3,
03755 const A4& a4,
03756 const A5& a5,
03757 const A6& a6,
03758 const A7& a7,
03759 const A8& a8,
03760 const A9& a9,
03761 const A10& a10,
03762 const A11& a11,
03763 const A12& a12,
03764 const VECTOR_CLASS<Event>* events)
03765 {
03766 Event event;
03767
03768 kernel_.setArg(0,a1);
03769 kernel_.setArg(1,a2);
03770 kernel_.setArg(2,a3);
03771 kernel_.setArg(3,a4);
03772 kernel_.setArg(4,a5);
03773 kernel_.setArg(5,a6);
03774 kernel_.setArg(6,a7);
03775 kernel_.setArg(7,a8);
03776 kernel_.setArg(8,a9);
03777 kernel_.setArg(9,a10);
03778 kernel_.setArg(10,a11);
03779 kernel_.setArg(11,a12);
03780
03781 err_ = queue_.enqueueNDRangeKernel(
03782 kernel_,
03783 offset_,
03784 global_,
03785 local_,
03786 NULL,
03787 &event);
03788
03789 return event;
03790 }
03791
03792 template<class A1, class A2, class A3, class A4, class A5,
03793 class A6, class A7, class A8, class A9, class A10,
03794 class A11, class A12, class A13>
03795 Event KernelFunctor::operator()(
03796 const A1& a1,
03797 const A2& a2,
03798 const A3& a3,
03799 const A4& a4,
03800 const A5& a5,
03801 const A6& a6,
03802 const A7& a7,
03803 const A8& a8,
03804 const A9& a9,
03805 const A10& a10,
03806 const A11& a11,
03807 const A12& a12,
03808 const A13& a13,
03809 const VECTOR_CLASS<Event>* events)
03810 {
03811 Event event;
03812
03813 kernel_.setArg(0,a1);
03814 kernel_.setArg(1,a2);
03815 kernel_.setArg(2,a3);
03816 kernel_.setArg(3,a4);
03817 kernel_.setArg(4,a5);
03818 kernel_.setArg(5,a6);
03819 kernel_.setArg(6,a7);
03820 kernel_.setArg(7,a8);
03821 kernel_.setArg(8,a9);
03822 kernel_.setArg(9,a10);
03823 kernel_.setArg(10,a11);
03824 kernel_.setArg(11,a12);
03825 kernel_.setArg(12,a13);
03826
03827 err_ = queue_.enqueueNDRangeKernel(
03828 kernel_,
03829 offset_,
03830 global_,
03831 local_,
03832 NULL,
03833 &event);
03834
03835 return event;
03836 }
03837
03838 template<class A1, class A2, class A3, class A4, class A5,
03839 class A6, class A7, class A8, class A9, class A10,
03840 class A11, class A12, class A13, class A14>
03841 Event KernelFunctor::operator()(
03842 const A1& a1,
03843 const A2& a2,
03844 const A3& a3,
03845 const A4& a4,
03846 const A5& a5,
03847 const A6& a6,
03848 const A7& a7,
03849 const A8& a8,
03850 const A9& a9,
03851 const A10& a10,
03852 const A11& a11,
03853 const A12& a12,
03854 const A13& a13,
03855 const A14& a14,
03856 const VECTOR_CLASS<Event>* events)
03857 {
03858 Event event;
03859
03860 kernel_.setArg(0,a1);
03861 kernel_.setArg(1,a2);
03862 kernel_.setArg(2,a3);
03863 kernel_.setArg(3,a4);
03864 kernel_.setArg(4,a5);
03865 kernel_.setArg(5,a6);
03866 kernel_.setArg(6,a7);
03867 kernel_.setArg(7,a8);
03868 kernel_.setArg(8,a9);
03869 kernel_.setArg(9,a10);
03870 kernel_.setArg(10,a11);
03871 kernel_.setArg(11,a12);
03872 kernel_.setArg(12,a13);
03873 kernel_.setArg(13,a14);
03874
03875 err_ = queue_.enqueueNDRangeKernel(
03876 kernel_,
03877 offset_,
03878 global_,
03879 local_,
03880 NULL,
03881 &event);
03882
03883 return event;
03884 }
03885
03886 template<class A1, class A2, class A3, class A4, class A5,
03887 class A6, class A7, class A8, class A9, class A10,
03888 class A11, class A12, class A13, class A14, class A15>
03889 Event KernelFunctor::operator()(
03890 const A1& a1,
03891 const A2& a2,
03892 const A3& a3,
03893 const A4& a4,
03894 const A5& a5,
03895 const A6& a6,
03896 const A7& a7,
03897 const A8& a8,
03898 const A9& a9,
03899 const A10& a10,
03900 const A11& a11,
03901 const A12& a12,
03902 const A13& a13,
03903 const A14& a14,
03904 const A15& a15,
03905 const VECTOR_CLASS<Event>* events)
03906 {
03907 Event event;
03908
03909 kernel_.setArg(0,a1);
03910 kernel_.setArg(1,a2);
03911 kernel_.setArg(2,a3);
03912 kernel_.setArg(3,a4);
03913 kernel_.setArg(4,a5);
03914 kernel_.setArg(5,a6);
03915 kernel_.setArg(6,a7);
03916 kernel_.setArg(7,a8);
03917 kernel_.setArg(8,a9);
03918 kernel_.setArg(9,a10);
03919 kernel_.setArg(10,a11);
03920 kernel_.setArg(11,a12);
03921 kernel_.setArg(12,a13);
03922 kernel_.setArg(13,a14);
03923 kernel_.setArg(14,a15);
03924
03925 err_ = queue_.enqueueNDRangeKernel(
03926 kernel_,
03927 offset_,
03928 global_,
03929 local_,
03930 NULL,
03931 &event);
03932
03933 return event;
03934 }
03935
03936 #undef __ERR_STR
03937 #if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
03938 #undef __GET_DEVICE_INFO_ERR
03939 #undef __GET_PLATFORM_INFO_ERR
03940 #undef __GET_DEVICE_IDS_ERR
03941 #undef __GET_CONTEXT_INFO_ERR
03942 #undef __GET_EVENT_INFO_ERR
03943 #undef __GET_EVENT_PROFILE_INFO_ERR
03944 #undef __GET_MEM_OBJECT_INFO_ERR
03945 #undef __GET_IMAGE_INFO_ERR
03946 #undef __GET_SAMPLER_INFO_ERR
03947 #undef __GET_KERNEL_INFO_ERR
03948 #undef __GET_KERNEL_WORK_GROUP_INFO_ERR
03949 #undef __GET_PROGRAM_INFO_ERR
03950 #undef __GET_PROGRAM_BUILD_INFO_ERR
03951 #undef __GET_COMMAND_QUEUE_INFO_ERR
03952
03953 #undef __CREATE_CONTEXT_FROM_TYPE_ERR
03954 #undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
03955
03956 #undef __CREATE_BUFFER_ERR
03957 #undef __CREATE_SUBBUFFER_ERR
03958 #undef __CREATE_IMAGE2D_ERR
03959 #undef __CREATE_IMAGE3D_ERR
03960 #undef __CREATE_SAMPLER_ERR
03961 #undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
03962
03963 #undef __CREATE_USER_EVENT_ERR
03964 #undef __SET_USER_EVENT_STATUS_ERR
03965 #undef __SET_EVENT_CALLBACK_ERR
03966
03967 #undef __WAIT_FOR_EVENTS_ERR
03968
03969 #undef __CREATE_KERNEL_ERR
03970 #undef __SET_KERNEL_ARGS_ERR
03971 #undef __CREATE_PROGRAM_WITH_SOURCE_ERR
03972 #undef __CREATE_PROGRAM_WITH_BINARY_ERR
03973 #undef __BUILD_PROGRAM_ERR
03974 #undef __CREATE_KERNELS_IN_PROGRAM_ERR
03975
03976 #undef __CREATE_COMMAND_QUEUE_ERR
03977 #undef __SET_COMMAND_QUEUE_PROPERTY_ERR
03978 #undef __ENQUEUE_READ_BUFFER_ERR
03979 #undef __ENQUEUE_WRITE_BUFFER_ERR
03980 #undef __ENQUEUE_READ_BUFFER_RECT_ERR
03981 #undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
03982 #undef __ENQEUE_COPY_BUFFER_ERR
03983 #undef __ENQEUE_COPY_BUFFER_RECT_ERR
03984 #undef __ENQUEUE_READ_IMAGE_ERR
03985 #undef __ENQUEUE_WRITE_IMAGE_ERR
03986 #undef __ENQUEUE_COPY_IMAGE_ERR
03987 #undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
03988 #undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
03989 #undef __ENQUEUE_MAP_BUFFER_ERR
03990 #undef __ENQUEUE_MAP_IMAGE_ERR
03991 #undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
03992 #undef __ENQUEUE_NDRANGE_KERNEL_ERR
03993 #undef __ENQUEUE_TASK_ERR
03994 #undef __ENQUEUE_NATIVE_KERNEL
03995
03996 #undef __UNLOAD_COMPILER_ERR
03997 #endif //__CL_USER_OVERRIDE_ERROR_STRINGS
03998
03999 #undef __GET_INFO_HELPER_WITH_RETAIN
04000
04001
04002 #undef __INIT_CL_EXT_FCN_PTR
04003 #undef __CREATE_SUB_DEVICES
04004
04005 #if defined(USE_CL_DEVICE_FISSION)
04006 #undef __PARAM_NAME_DEVICE_FISSION
04007 #endif // USE_CL_DEVICE_FISSION
04008
04009 }
04010
04011 #endif // CL_HPP_