1 /******************************************************************************* 2 * Copyright (c) 2008-2013 The Khronos Group Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and/or associated documentation files (the 6 * "Materials"), to deal in the Materials without restriction, including 7 * without limitation the rights to use, copy, modify, merge, publish, 8 * distribute, sublicense, and/or sell copies of the Materials, and to 9 * permit persons to whom the Materials are furnished to do so, subject to 10 * the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included 13 * in all copies or substantial portions of the Materials. 14 * 15 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 ******************************************************************************/ 23 24 /*! \file 25 * 26 * \brief C++ bindings for OpenCL 1.0 (rev 48), OpenCL 1.1 (rev 33) and 27 * OpenCL 1.2 (rev 15) 28 * \author Benedict R. Gaster, Laurent Morichetti and Lee Howes 29 * 30 * Additions and fixes from: 31 * Brian Cole, March 3rd 2010 and April 2012 32 * Matt Gruenke, April 2012. 33 * Bruce Merry, February 2013. 34 * 35 * \version 1.2.5 36 * \date June 2013 37 * 38 * Optional extension support 39 * 40 * cl 41 * cl_ext_device_fission 42 * #define USE_CL_DEVICE_FISSION 43 */ 44 45 /*! \mainpage 46 * \section intro Introduction 47 * For many large applications C++ is the language of choice and so it seems 48 * reasonable to define C++ bindings for OpenCL. 49 * 50 * 51 * The interface is contained with a single C++ header file \em cl.hpp and all 52 * definitions are contained within the namespace \em cl. There is no additional 53 * requirement to include \em cl.h and to use either the C++ or original C 54 * bindings it is enough to simply include \em cl.hpp. 55 * 56 * The bindings themselves are lightweight and correspond closely to the 57 * underlying C API. Using the C++ bindings introduces no additional execution 58 * overhead. 59 * 60 * For detail documentation on the bindings see: 61 * 62 * The OpenCL C++ Wrapper API 1.2 (revision 09) 63 * http://www.khronos.org/registry/cl/specs/opencl-cplusplus-1.2.pdf 64 * 65 * \section example Example 66 * 67 * The following example shows a general use case for the C++ 68 * bindings, including support for the optional exception feature and 69 * also the supplied vector and string classes, see following sections for 70 * decriptions of these features. 71 * 72 * \code 73 * #define __CL_ENABLE_EXCEPTIONS 74 * 75 * #if defined(__APPLE__) || defined(__MACOSX) 76 * #include <OpenCL/cl.hpp> 77 * #else 78 * #include <CL/cl.hpp> 79 * #endif 80 * #include <cstdio> 81 * #include <cstdlib> 82 * #include <iostream> 83 * 84 * const char * helloStr = "__kernel void " 85 * "hello(void) " 86 * "{ " 87 * " " 88 * "} "; 89 * 90 * int 91 * main(void) 92 * { 93 * cl_int err = CL_SUCCESS; 94 * try { 95 * 96 * std::vector<cl::Platform> platforms; 97 * cl::Platform::get(&platforms); 98 * if (platforms.size() == 0) { 99 * std::cout << "Platform size 0\n"; 100 * return -1; 101 * } 102 * 103 * cl_context_properties properties[] = 104 * { CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0}; 105 * cl::Context context(CL_DEVICE_TYPE_CPU, properties); 106 * 107 * std::vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>(); 108 * 109 * cl::Program::Sources source(1, 110 * std::make_pair(helloStr,strlen(helloStr))); 111 * cl::Program program_ = cl::Program(context, source); 112 * program_.build(devices); 113 * 114 * cl::Kernel kernel(program_, "hello", &err); 115 * 116 * cl::Event event; 117 * cl::CommandQueue queue(context, devices[0], 0, &err); 118 * queue.enqueueNDRangeKernel( 119 * kernel, 120 * cl::NullRange, 121 * cl::NDRange(4,4), 122 * cl::NullRange, 123 * NULL, 124 * &event); 125 * 126 * event.wait(); 127 * } 128 * catch (cl::Error err) { 129 * std::cerr 130 * << "ERROR: " 131 * << err.what() 132 * << "(" 133 * << err.err() 134 * << ")" 135 * << std::endl; 136 * } 137 * 138 * return EXIT_SUCCESS; 139 * } 140 * 141 * \endcode 142 * 143 */ 144 #ifndef CL_HPP_ 145 #define CL_HPP_ 146 147 #ifdef _WIN32 148 149 #include <windows.h> 150 #include <malloc.h> 151 #include <iterator> 152 #include <intrin.h> 153 154 #if defined(__CL_ENABLE_EXCEPTIONS) 155 #include <exception> 156 #endif // #if defined(__CL_ENABLE_EXCEPTIONS) 157 158 #pragma push_macro("max") 159 #undef max 160 #if defined(USE_DX_INTEROP) 161 #include <CL/cl_d3d10.h> 162 #include <CL/cl_dx9_media_sharing.h> 163 #endif 164 #endif // _WIN32 165 166 // 167 #if defined(USE_CL_DEVICE_FISSION) 168 #include <CL/cl_ext.h> 169 #endif 170 171 #if defined(__APPLE__) || defined(__MACOSX) 172 #include <OpenGL/OpenGL.h> 173 #include <OpenCL/opencl.h> 174 #include <libkern/OSAtomic.h> 175 #else 176 #include <GL/gl.h> 177 #include <CL/opencl.h> 178 #endif // !__APPLE__ 179 180 // To avoid accidentally taking ownership of core OpenCL types 181 // such as cl_kernel constructors are made explicit 182 // under OpenCL 1.2 183 #if defined(CL_VERSION_1_2) && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) 184 #define __CL_EXPLICIT_CONSTRUCTORS explicit 185 #else // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) 186 #define __CL_EXPLICIT_CONSTRUCTORS 187 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) 188 189 // Define deprecated prefixes and suffixes to ensure compilation 190 // in case they are not pre-defined 191 #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) 192 #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED 193 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) 194 #if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED) 195 #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED 196 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) 197 198 #if !defined(CL_CALLBACK) 199 #define CL_CALLBACK 200 #endif //CL_CALLBACK 201 202 #include <utility> 203 #include <limits> 204 205 #if !defined(__NO_STD_VECTOR) 206 #include <vector> 207 #endif 208 209 #if !defined(__NO_STD_STRING) 210 #include <string> 211 #endif 212 213 #if defined(__linux__) || defined(__APPLE__) || defined(__MACOSX) 214 #include <alloca.h> 215 216 #include <emmintrin.h> 217 #include <xmmintrin.h> 218 #endif // linux 219 220 #include <cstring> 221 222 223 /*! \namespace cl 224 * 225 * \brief The OpenCL C++ bindings are defined within this namespace. 226 * 227 */ 228 namespace cl { 229 230 class Memory; 231 232 /** 233 * Deprecated APIs for 1.2 234 */ 235 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) 236 #define __INIT_CL_EXT_FCN_PTR(name) \ 237 if(!pfn_##name) { \ 238 pfn_##name = (PFN_##name) \ 239 clGetExtensionFunctionAddress(#name); \ 240 if(!pfn_##name) { \ 241 } \ 242 } 243 #endif // #if defined(CL_VERSION_1_1) 244 245 #if defined(CL_VERSION_1_2) 246 #define __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, name) \ 247 if(!pfn_##name) { \ 248 pfn_##name = (PFN_##name) \ 249 clGetExtensionFunctionAddressForPlatform(platform, #name); \ 250 if(!pfn_##name) { \ 251 } \ 252 } 253 #endif // #if defined(CL_VERSION_1_1) 254 255 class Program; 256 class Device; 257 class Context; 258 class CommandQueue; 259 class Memory; 260 class Buffer; 261 262 #if defined(__CL_ENABLE_EXCEPTIONS) 263 /*! \brief Exception class 264 * 265 * This may be thrown by API functions when __CL_ENABLE_EXCEPTIONS is defined. 266 */ 267 class Error : public std::exception 268 { 269 private: 270 cl_int err_; 271 const char * errStr_; 272 public: 273 /*! \brief Create a new CL error exception for a given error code 274 * and corresponding message. 275 * 276 * \param err error code value. 277 * 278 * \param errStr a descriptive string that must remain in scope until 279 * handling of the exception has concluded. If set, it 280 * will be returned by what(). 281 */ 282 Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr) 283 {} 284 285 ~Error() throw() {} 286 287 /*! \brief Get error string associated with exception 288 * 289 * \return A memory pointer to the error message string. 290 */ 291 virtual const char * what() const throw () 292 { 293 if (errStr_ == NULL) { 294 return "empty"; 295 } 296 else { 297 return errStr_; 298 } 299 } 300 301 /*! \brief Get error code associated with exception 302 * 303 * \return The error code. 304 */ 305 cl_int err(void) const { return err_; } 306 }; 307 308 #define __ERR_STR(x) #x 309 #else 310 #define __ERR_STR(x) NULL 311 #endif // __CL_ENABLE_EXCEPTIONS 312 313 314 namespace detail 315 { 316 #if defined(__CL_ENABLE_EXCEPTIONS) 317 static inline cl_int errHandler ( 318 cl_int err, 319 const char * errStr = NULL) 320 { 321 if (err != CL_SUCCESS) { 322 throw Error(err, errStr); 323 } 324 return err; 325 } 326 #else 327 static inline cl_int errHandler (cl_int err, const char * errStr = NULL) 328 { 329 (void) errStr; // suppress unused variable warning 330 return err; 331 } 332 #endif // __CL_ENABLE_EXCEPTIONS 333 } 334 335 336 337 //! \cond DOXYGEN_DETAIL 338 #if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS) 339 #define __GET_DEVICE_INFO_ERR __ERR_STR(clGetDeviceInfo) 340 #define __GET_PLATFORM_INFO_ERR __ERR_STR(clGetPlatformInfo) 341 #define __GET_DEVICE_IDS_ERR __ERR_STR(clGetDeviceIDs) 342 #define __GET_PLATFORM_IDS_ERR __ERR_STR(clGetPlatformIDs) 343 #define __GET_CONTEXT_INFO_ERR __ERR_STR(clGetContextInfo) 344 #define __GET_EVENT_INFO_ERR __ERR_STR(clGetEventInfo) 345 #define __GET_EVENT_PROFILE_INFO_ERR __ERR_STR(clGetEventProfileInfo) 346 #define __GET_MEM_OBJECT_INFO_ERR __ERR_STR(clGetMemObjectInfo) 347 #define __GET_IMAGE_INFO_ERR __ERR_STR(clGetImageInfo) 348 #define __GET_SAMPLER_INFO_ERR __ERR_STR(clGetSamplerInfo) 349 #define __GET_KERNEL_INFO_ERR __ERR_STR(clGetKernelInfo) 350 #if defined(CL_VERSION_1_2) 351 #define __GET_KERNEL_ARG_INFO_ERR __ERR_STR(clGetKernelArgInfo) 352 #endif // #if defined(CL_VERSION_1_2) 353 #define __GET_KERNEL_WORK_GROUP_INFO_ERR __ERR_STR(clGetKernelWorkGroupInfo) 354 #define __GET_PROGRAM_INFO_ERR __ERR_STR(clGetProgramInfo) 355 #define __GET_PROGRAM_BUILD_INFO_ERR __ERR_STR(clGetProgramBuildInfo) 356 #define __GET_COMMAND_QUEUE_INFO_ERR __ERR_STR(clGetCommandQueueInfo) 357 358 #define __CREATE_CONTEXT_ERR __ERR_STR(clCreateContext) 359 #define __CREATE_CONTEXT_FROM_TYPE_ERR __ERR_STR(clCreateContextFromType) 360 #define __GET_SUPPORTED_IMAGE_FORMATS_ERR __ERR_STR(clGetSupportedImageFormats) 361 362 #define __CREATE_BUFFER_ERR __ERR_STR(clCreateBuffer) 363 #define __COPY_ERR __ERR_STR(cl::copy) 364 #define __CREATE_SUBBUFFER_ERR __ERR_STR(clCreateSubBuffer) 365 #define __CREATE_GL_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer) 366 #define __CREATE_GL_RENDER_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer) 367 #define __GET_GL_OBJECT_INFO_ERR __ERR_STR(clGetGLObjectInfo) 368 #if defined(CL_VERSION_1_2) 369 #define __CREATE_IMAGE_ERR __ERR_STR(clCreateImage) 370 #define __CREATE_GL_TEXTURE_ERR __ERR_STR(clCreateFromGLTexture) 371 #define __IMAGE_DIMENSION_ERR __ERR_STR(Incorrect image dimensions) 372 #endif // #if defined(CL_VERSION_1_2) 373 #define __CREATE_SAMPLER_ERR __ERR_STR(clCreateSampler) 374 #define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR __ERR_STR(clSetMemObjectDestructorCallback) 375 376 #define __CREATE_USER_EVENT_ERR __ERR_STR(clCreateUserEvent) 377 #define __SET_USER_EVENT_STATUS_ERR __ERR_STR(clSetUserEventStatus) 378 #define __SET_EVENT_CALLBACK_ERR __ERR_STR(clSetEventCallback) 379 #define __WAIT_FOR_EVENTS_ERR __ERR_STR(clWaitForEvents) 380 381 #define __CREATE_KERNEL_ERR __ERR_STR(clCreateKernel) 382 #define __SET_KERNEL_ARGS_ERR __ERR_STR(clSetKernelArg) 383 #define __CREATE_PROGRAM_WITH_SOURCE_ERR __ERR_STR(clCreateProgramWithSource) 384 #define __CREATE_PROGRAM_WITH_BINARY_ERR __ERR_STR(clCreateProgramWithBinary) 385 #if defined(CL_VERSION_1_2) 386 #define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR __ERR_STR(clCreateProgramWithBuiltInKernels) 387 #endif // #if defined(CL_VERSION_1_2) 388 #define __BUILD_PROGRAM_ERR __ERR_STR(clBuildProgram) 389 #if defined(CL_VERSION_1_2) 390 #define __COMPILE_PROGRAM_ERR __ERR_STR(clCompileProgram) 391 392 #endif // #if defined(CL_VERSION_1_2) 393 #define __CREATE_KERNELS_IN_PROGRAM_ERR __ERR_STR(clCreateKernelsInProgram) 394 395 #define __CREATE_COMMAND_QUEUE_ERR __ERR_STR(clCreateCommandQueue) 396 #define __SET_COMMAND_QUEUE_PROPERTY_ERR __ERR_STR(clSetCommandQueueProperty) 397 #define __ENQUEUE_READ_BUFFER_ERR __ERR_STR(clEnqueueReadBuffer) 398 #define __ENQUEUE_READ_BUFFER_RECT_ERR __ERR_STR(clEnqueueReadBufferRect) 399 #define __ENQUEUE_WRITE_BUFFER_ERR __ERR_STR(clEnqueueWriteBuffer) 400 #define __ENQUEUE_WRITE_BUFFER_RECT_ERR __ERR_STR(clEnqueueWriteBufferRect) 401 #define __ENQEUE_COPY_BUFFER_ERR __ERR_STR(clEnqueueCopyBuffer) 402 #define __ENQEUE_COPY_BUFFER_RECT_ERR __ERR_STR(clEnqueueCopyBufferRect) 403 #define __ENQUEUE_FILL_BUFFER_ERR __ERR_STR(clEnqueueFillBuffer) 404 #define __ENQUEUE_READ_IMAGE_ERR __ERR_STR(clEnqueueReadImage) 405 #define __ENQUEUE_WRITE_IMAGE_ERR __ERR_STR(clEnqueueWriteImage) 406 #define __ENQUEUE_COPY_IMAGE_ERR __ERR_STR(clEnqueueCopyImage) 407 #define __ENQUEUE_FILL_IMAGE_ERR __ERR_STR(clEnqueueFillImage) 408 #define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR __ERR_STR(clEnqueueCopyImageToBuffer) 409 #define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR __ERR_STR(clEnqueueCopyBufferToImage) 410 #define __ENQUEUE_MAP_BUFFER_ERR __ERR_STR(clEnqueueMapBuffer) 411 #define __ENQUEUE_MAP_IMAGE_ERR __ERR_STR(clEnqueueMapImage) 412 #define __ENQUEUE_UNMAP_MEM_OBJECT_ERR __ERR_STR(clEnqueueUnMapMemObject) 413 #define __ENQUEUE_NDRANGE_KERNEL_ERR __ERR_STR(clEnqueueNDRangeKernel) 414 #define __ENQUEUE_TASK_ERR __ERR_STR(clEnqueueTask) 415 #define __ENQUEUE_NATIVE_KERNEL __ERR_STR(clEnqueueNativeKernel) 416 #if defined(CL_VERSION_1_2) 417 #define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR __ERR_STR(clEnqueueMigrateMemObjects) 418 #endif // #if defined(CL_VERSION_1_2) 419 420 #define __ENQUEUE_ACQUIRE_GL_ERR __ERR_STR(clEnqueueAcquireGLObjects) 421 #define __ENQUEUE_RELEASE_GL_ERR __ERR_STR(clEnqueueReleaseGLObjects) 422 423 424 #define __RETAIN_ERR __ERR_STR(Retain Object) 425 #define __RELEASE_ERR __ERR_STR(Release Object) 426 #define __FLUSH_ERR __ERR_STR(clFlush) 427 #define __FINISH_ERR __ERR_STR(clFinish) 428 #define __VECTOR_CAPACITY_ERR __ERR_STR(Vector capacity error) 429 430 /** 431 * CL 1.2 version that uses device fission. 432 */ 433 #if defined(CL_VERSION_1_2) 434 #define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevices) 435 #else 436 #define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevicesEXT) 437 #endif // #if defined(CL_VERSION_1_2) 438 439 /** 440 * Deprecated APIs for 1.2 441 */ 442 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) 443 #define __ENQUEUE_MARKER_ERR __ERR_STR(clEnqueueMarker) 444 #define __ENQUEUE_WAIT_FOR_EVENTS_ERR __ERR_STR(clEnqueueWaitForEvents) 445 #define __ENQUEUE_BARRIER_ERR __ERR_STR(clEnqueueBarrier) 446 #define __UNLOAD_COMPILER_ERR __ERR_STR(clUnloadCompiler) 447 #define __CREATE_GL_TEXTURE_2D_ERR __ERR_STR(clCreateFromGLTexture2D) 448 #define __CREATE_GL_TEXTURE_3D_ERR __ERR_STR(clCreateFromGLTexture3D) 449 #define __CREATE_IMAGE2D_ERR __ERR_STR(clCreateImage2D) 450 #define __CREATE_IMAGE3D_ERR __ERR_STR(clCreateImage3D) 451 #endif // #if defined(CL_VERSION_1_1) 452 453 #endif // __CL_USER_OVERRIDE_ERROR_STRINGS 454 //! \endcond 455 456 /** 457 * CL 1.2 marker and barrier commands 458 */ 459 #if defined(CL_VERSION_1_2) 460 #define __ENQUEUE_MARKER_WAIT_LIST_ERR __ERR_STR(clEnqueueMarkerWithWaitList) 461 #define __ENQUEUE_BARRIER_WAIT_LIST_ERR __ERR_STR(clEnqueueBarrierWithWaitList) 462 #endif // #if defined(CL_VERSION_1_2) 463 464 #if !defined(__USE_DEV_STRING) && !defined(__NO_STD_STRING) 465 typedef std::string STRING_CLASS; 466 #elif !defined(__USE_DEV_STRING) 467 468 /*! \class string 469 * \brief Simple string class, that provides a limited subset of std::string 470 * functionality but avoids many of the issues that come with that class. 471 472 * \note Deprecated. Please use std::string as default or 473 * re-define the string class to match the std::string 474 * interface by defining STRING_CLASS 475 */ 476 class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED string CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED 477 { 478 private: 479 ::size_t size_; 480 char * str_; 481 public: 482 //! \brief Constructs an empty string, allocating no memory. 483 string(void) : size_(0), str_(NULL) 484 { 485 } 486 487 /*! \brief Constructs a string populated from an arbitrary value of 488 * specified size. 489 * 490 * An extra '\0' is added, in case none was contained in str. 491 * 492 * \param str the initial value of the string instance. Note that '\0' 493 * characters receive no special treatment. If NULL, 494 * the string is left empty, with a size of 0. 495 * 496 * \param size the number of characters to copy from str. 497 */ 498 string(const char * str, ::size_t size) : 499 size_(size), 500 str_(NULL) 501 { 502 if( size > 0 ) { 503 str_ = new char[size_+1]; 504 if (str_ != NULL) { 505 memcpy(str_, str, size_ * sizeof(char)); 506 str_[size_] = '\0'; 507 } 508 else { 509 size_ = 0; 510 } 511 } 512 } 513 514 /*! \brief Constructs a string populated from a null-terminated value. 515 * 516 * \param str the null-terminated initial value of the string instance. 517 * If NULL, the string is left empty, with a size of 0. 518 */ 519 string(const char * str) : 520 size_(0), 521 str_(NULL) 522 { 523 if( str ) { 524 size_= ::strlen(str); 525 } 526 if( size_ > 0 ) { 527 str_ = new char[size_ + 1]; 528 if (str_ != NULL) { 529 memcpy(str_, str, (size_ + 1) * sizeof(char)); 530 } 531 } 532 } 533 534 void resize( ::size_t n ) 535 { 536 if( size_ == n ) { 537 return; 538 } 539 if (n == 0) { 540 if( str_ ) { 541 delete [] str_; 542 } 543 str_ = NULL; 544 size_ = 0; 545 } 546 else { 547 char *newString = new char[n + 1]; 548 int copySize = n; 549 if( size_ < n ) { 550 copySize = size_; 551 } 552 size_ = n; 553 554 if(str_) { 555 memcpy(newString, str_, (copySize + 1) * sizeof(char)); 556 } 557 if( copySize < size_ ) { 558 memset(newString + copySize, 0, size_ - copySize); 559 } 560 newString[size_] = '\0'; 561 562 delete [] str_; 563 str_ = newString; 564 } 565 } 566 567 const char& operator[] ( ::size_t pos ) const 568 { 569 return str_[pos]; 570 } 571 572 char& operator[] ( ::size_t pos ) 573 { 574 return str_[pos]; 575 } 576 577 /*! \brief Copies the value of another string to this one. 578 * 579 * \param rhs the string to copy. 580 * 581 * \returns a reference to the modified instance. 582 */ 583 string& operator=(const string& rhs) 584 { 585 if (this == &rhs) { 586 return *this; 587 } 588 589 if( str_ != NULL ) { 590 delete [] str_; 591 str_ = NULL; 592 size_ = 0; 593 } 594 595 if (rhs.size_ == 0 || rhs.str_ == NULL) { 596 str_ = NULL; 597 size_ = 0; 598 } 599 else { 600 str_ = new char[rhs.size_ + 1]; 601 size_ = rhs.size_; 602 603 if (str_ != NULL) { 604 memcpy(str_, rhs.str_, (size_ + 1) * sizeof(char)); 605 } 606 else { 607 size_ = 0; 608 } 609 } 610 611 return *this; 612 } 613 614 /*! \brief Constructs a string by copying the value of another instance. 615 * 616 * \param rhs the string to copy. 617 */ 618 string(const string& rhs) : 619 size_(0), 620 str_(NULL) 621 { 622 *this = rhs; 623 } 624 625 //! \brief Destructor - frees memory used to hold the current value. 626 ~string() 627 { 628 delete[] str_; 629 str_ = NULL; 630 } 631 632 //! \brief Queries the length of the string, excluding any added '\0's. 633 ::size_t size(void) const { return size_; } 634 635 //! \brief Queries the length of the string, excluding any added '\0's. 636 ::size_t length(void) const { return size(); } 637 638 /*! \brief Returns a pointer to the private copy held by this instance, 639 * or "" if empty/unset. 640 */ 641 const char * c_str(void) const { return (str_) ? str_ : "";} 642 }; 643 typedef cl::string STRING_CLASS; 644 #endif // #elif !defined(__USE_DEV_STRING) 645 646 #if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR) 647 #define VECTOR_CLASS std::vector 648 #elif !defined(__USE_DEV_VECTOR) 649 #define VECTOR_CLASS cl::vector 650 651 #if !defined(__MAX_DEFAULT_VECTOR_SIZE) 652 #define __MAX_DEFAULT_VECTOR_SIZE 10 653 #endif 654 655 /*! \class vector 656 * \brief Fixed sized vector implementation that mirroring 657 * 658 * \note Deprecated. Please use std::vector as default or 659 * re-define the vector class to match the std::vector 660 * interface by defining VECTOR_CLASS 661 662 * \note Not recommended for use with custom objects as 663 * current implementation will construct N elements 664 * 665 * std::vector functionality. 666 * \brief Fixed sized vector compatible with std::vector. 667 * 668 * \note 669 * This differs from std::vector<> not just in memory allocation, 670 * but also in terms of when members are constructed, destroyed, 671 * and assigned instead of being copy constructed. 672 * 673 * \param T type of element contained in the vector. 674 * 675 * \param N maximum size of the vector. 676 */ 677 template <typename T, unsigned int N = __MAX_DEFAULT_VECTOR_SIZE> 678 class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED vector CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED 679 { 680 private: 681 T data_[N]; 682 unsigned int size_; 683 684 public: 685 //! \brief Constructs an empty vector with no memory allocated. 686 vector() : 687 size_(static_cast<unsigned int>(0)) 688 {} 689 690 //! \brief Deallocates the vector's memory and destroys all of its elements. 691 ~vector() 692 { 693 clear(); 694 } 695 696 //! \brief Returns the number of elements currently contained. 697 unsigned int size(void) const 698 { 699 return size_; 700 } 701 702 /*! \brief Empties the vector of all elements. 703 * \note 704 * This does not deallocate memory but will invoke destructors 705 * on contained elements. 706 */ 707 void clear() 708 { 709 while(!empty()) { 710 pop_back(); 711 } 712 } 713 714 /*! \brief Appends an element after the last valid element. 715 * Calling this on a vector that has reached capacity will throw an 716 * exception if exceptions are enabled. 717 */ 718 void push_back (const T& x) 719 { 720 if (size() < N) { 721 new (&data_[size_]) T(x); 722 size_++; 723 } else { 724 detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR); 725 } 726 } 727 728 /*! \brief Removes the last valid element from the vector. 729 * Calling this on an empty vector will throw an exception 730 * if exceptions are enabled. 731 */ 732 void pop_back(void) 733 { 734 if (size_ != 0) { 735 --size_; 736 data_[size_].~T(); 737 } else { 738 detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR); 739 } 740 } 741 742 /*! \brief Constructs with a value copied from another. 743 * 744 * \param vec the vector to copy. 745 */ 746 vector(const vector<T, N>& vec) : 747 size_(vec.size_) 748 { 749 if (size_ != 0) { 750 assign(vec.begin(), vec.end()); 751 } 752 } 753 754 /*! \brief Constructs with a specified number of initial elements. 755 * 756 * \param size number of initial elements. 757 * 758 * \param val value of initial elements. 759 */ 760 vector(unsigned int size, const T& val = T()) : 761 size_(0) 762 { 763 for (unsigned int i = 0; i < size; i++) { 764 push_back(val); 765 } 766 } 767 768 /*! \brief Overwrites the current content with that copied from another 769 * instance. 770 * 771 * \param rhs vector to copy. 772 * 773 * \returns a reference to this. 774 */ 775 vector<T, N>& operator=(const vector<T, N>& rhs) 776 { 777 if (this == &rhs) { 778 return *this; 779 } 780 781 if (rhs.size_ != 0) { 782 assign(rhs.begin(), rhs.end()); 783 } else { 784 clear(); 785 } 786 787 return *this; 788 } 789 790 /*! \brief Tests equality against another instance. 791 * 792 * \param vec the vector against which to compare. 793 */ 794 bool operator==(vector<T,N> &vec) 795 { 796 if (size() != vec.size()) { 797 return false; 798 } 799 800 for( unsigned int i = 0; i < size(); ++i ) { 801 if( operator[](i) != vec[i] ) { 802 return false; 803 } 804 } 805 return true; 806 } 807 808 //! \brief Conversion operator to T*. 809 operator T* () { return data_; } 810 811 //! \brief Conversion operator to const T*. 812 operator const T* () const { return data_; } 813 814 //! \brief Tests whether this instance has any elements. 815 bool empty (void) const 816 { 817 return size_==0; 818 } 819 820 //! \brief Returns the maximum number of elements this instance can hold. 821 unsigned int max_size (void) const 822 { 823 return N; 824 } 825 826 //! \brief Returns the maximum number of elements this instance can hold. 827 unsigned int capacity () const 828 { 829 return N; 830 } 831 832 /*! \brief Returns a reference to a given element. 833 * 834 * \param index which element to access. * 835 * \note 836 * The caller is responsible for ensuring index is >= 0 and < size(). 837 */ 838 T& operator[](int index) 839 { 840 return data_[index]; 841 } 842 843 /*! \brief Returns a const reference to a given element. 844 * 845 * \param index which element to access. 846 * 847 * \note 848 * The caller is responsible for ensuring index is >= 0 and < size(). 849 */ 850 const T& operator[](int index) const 851 { 852 return data_[index]; 853 } 854 855 /*! \brief Assigns elements of the vector based on a source iterator range. 856 * 857 * \param start Beginning iterator of source range 858 * \param end Enditerator of source range 859 * 860 * \note 861 * Will throw an exception if exceptions are enabled and size exceeded. 862 */ 863 template<class I> 864 void assign(I start, I end) 865 { 866 clear(); 867 while(start != end) { 868 push_back(*start); 869 start++; 870 } 871 } 872 873 /*! \class iterator 874 * \brief Const iterator class for vectors 875 */ 876 class iterator 877 { 878 private: 879 const vector<T,N> *vec_; 880 int index_; 881 882 /** 883 * Internal iterator constructor to capture reference 884 * to the vector it iterates over rather than taking 885 * the vector by copy. 886 */ 887 iterator (const vector<T,N> &vec, int index) : 888 vec_(&vec) 889 { 890 if( !vec.empty() ) { 891 index_ = index; 892 } else { 893 index_ = -1; 894 } 895 } 896 897 public: 898 iterator(void) : 899 index_(-1), 900 vec_(NULL) 901 { 902 } 903 904 iterator(const iterator& rhs) : 905 vec_(rhs.vec_), 906 index_(rhs.index_) 907 { 908 } 909 910 ~iterator(void) {} 911 912 static iterator begin(const cl::vector<T,N> &vec) 913 { 914 iterator i(vec, 0); 915 916 return i; 917 } 918 919 static iterator end(const cl::vector<T,N> &vec) 920 { 921 iterator i(vec, vec.size()); 922 923 return i; 924 } 925 926 bool operator==(iterator i) 927 { 928 return ((vec_ == i.vec_) && 929 (index_ == i.index_)); 930 } 931 932 bool operator!=(iterator i) 933 { 934 return (!(*this==i)); 935 } 936 937 iterator& operator++() 938 { 939 ++index_; 940 return *this; 941 } 942 943 iterator operator++(int) 944 { 945 iterator retVal(*this); 946 ++index_; 947 return retVal; 948 } 949 950 iterator& operator--() 951 { 952 --index_; 953 return *this; 954 } 955 956 iterator operator--(int) 957 { 958 iterator retVal(*this); 959 --index_; 960 return retVal; 961 } 962 963 const T& operator *() const 964 { 965 return (*vec_)[index_]; 966 } 967 }; 968 969 iterator begin(void) 970 { 971 return iterator::begin(*this); 972 } 973 974 iterator begin(void) const 975 { 976 return iterator::begin(*this); 977 } 978 979 iterator end(void) 980 { 981 return iterator::end(*this); 982 } 983 984 iterator end(void) const 985 { 986 return iterator::end(*this); 987 } 988 989 T& front(void) 990 { 991 return data_[0]; 992 } 993 994 T& back(void) 995 { 996 return data_[size_]; 997 } 998 999 const T& front(void) const 1000 { 1001 return data_[0]; 1002 } 1003 1004 const T& back(void) const 1005 { 1006 return data_[size_-1]; 1007 } 1008 }; 1009 #endif // #if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR) 1010 1011 1012 1013 1014 1015 namespace detail { 1016 #define __DEFAULT_NOT_INITIALIZED 1 1017 #define __DEFAULT_BEING_INITIALIZED 2 1018 #define __DEFAULT_INITIALIZED 4 1019 1020 /* 1021 * Compare and exchange primitives are needed for handling of defaults 1022 */ 1023 inline int compare_exchange(volatile int * dest, int exchange, int comparand) 1024 { 1025 #ifdef _WIN32 1026 return (int)(InterlockedCompareExchange( 1027 (volatile long*)dest, 1028 (long)exchange, 1029 (long)comparand)); 1030 #elif defined(__APPLE__) || defined(__MACOSX) 1031 return OSAtomicOr32Orig((uint32_t)exchange, (volatile uint32_t*)dest); 1032 #else // !_WIN32 || defined(__APPLE__) || defined(__MACOSX) 1033 return (__sync_val_compare_and_swap( 1034 dest, 1035 comparand, 1036 exchange)); 1037 #endif // !_WIN32 1038 } 1039 1040 inline void fence() { _mm_mfence(); } 1041 }; // namespace detail 1042 1043 1044 /*! \brief class used to interface between C++ and 1045 * OpenCL C calls that require arrays of size_t values, whose 1046 * size is known statically. 1047 */ 1048 template <int N> 1049 class size_t 1050 { 1051 private: 1052 ::size_t data_[N]; 1053 1054 public: 1055 //! \brief Initialize size_t to all 0s 1056 size_t() 1057 { 1058 for( int i = 0; i < N; ++i ) { 1059 data_[i] = 0; 1060 } 1061 } 1062 1063 ::size_t& operator[](int index) 1064 { 1065 return data_[index]; 1066 } 1067 1068 const ::size_t& operator[](int index) const 1069 { 1070 return data_[index]; 1071 } 1072 1073 //! \brief Conversion operator to T*. 1074 operator ::size_t* () { return data_; } 1075 1076 //! \brief Conversion operator to const T*. 1077 operator const ::size_t* () const { return data_; } 1078 }; 1079 1080 namespace detail { 1081 1082 // Generic getInfoHelper. The final parameter is used to guide overload 1083 // resolution: the actual parameter passed is an int, which makes this 1084 // a worse conversion sequence than a specialization that declares the 1085 // parameter as an int. 1086 template<typename Functor, typename T> 1087 inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long) 1088 { 1089 return f(name, sizeof(T), param, NULL); 1090 } 1091 1092 // Specialized getInfoHelper for VECTOR_CLASS params 1093 template <typename Func, typename T> 1094 inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS<T>* param, long) 1095 { 1096 ::size_t required; 1097 cl_int err = f(name, 0, NULL, &required); 1098 if (err != CL_SUCCESS) { 1099 return err; 1100 } 1101 1102 T* value = (T*) alloca(required); 1103 err = f(name, required, value, NULL); 1104 if (err != CL_SUCCESS) { 1105 return err; 1106 } 1107 1108 param->assign(&value[0], &value[required/sizeof(T)]); 1109 return CL_SUCCESS; 1110 } 1111 1112 /* Specialization for reference-counted types. This depends on the 1113 * existence of Wrapper<T>::cl_type, and none of the other types having the 1114 * cl_type member. Note that simplify specifying the parameter as Wrapper<T> 1115 * does not work, because when using a derived type (e.g. Context) the generic 1116 * template will provide a better match. 1117 */ 1118 template <typename Func, typename T> 1119 inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS<T>* param, int, typename T::cl_type = 0) 1120 { 1121 ::size_t required; 1122 cl_int err = f(name, 0, NULL, &required); 1123 if (err != CL_SUCCESS) { 1124 return err; 1125 } 1126 1127 typename T::cl_type * value = (typename T::cl_type *) alloca(required); 1128 err = f(name, required, value, NULL); 1129 if (err != CL_SUCCESS) { 1130 return err; 1131 } 1132 1133 ::size_t elements = required / sizeof(typename T::cl_type); 1134 param->assign(&value[0], &value[elements]); 1135 for (::size_t i = 0; i < elements; i++) 1136 { 1137 if (value[i] != NULL) 1138 { 1139 err = (*param)[i].retain(); 1140 if (err != CL_SUCCESS) { 1141 return err; 1142 } 1143 } 1144 } 1145 return CL_SUCCESS; 1146 } 1147 1148 // Specialized for getInfo<CL_PROGRAM_BINARIES> 1149 template <typename Func> 1150 inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS<char *>* param, int) 1151 { 1152 cl_int err = f(name, param->size() * sizeof(char *), &(*param)[0], NULL); 1153 1154 if (err != CL_SUCCESS) { 1155 return err; 1156 } 1157 1158 return CL_SUCCESS; 1159 } 1160 1161 // Specialized GetInfoHelper for STRING_CLASS params 1162 template <typename Func> 1163 inline cl_int getInfoHelper(Func f, cl_uint name, STRING_CLASS* param, long) 1164 { 1165 ::size_t required; 1166 cl_int err = f(name, 0, NULL, &required); 1167 if (err != CL_SUCCESS) { 1168 return err; 1169 } 1170 1171 char* value = (char*) alloca(required); 1172 err = f(name, required, value, NULL); 1173 if (err != CL_SUCCESS) { 1174 return err; 1175 } 1176 1177 *param = value; 1178 return CL_SUCCESS; 1179 } 1180 1181 // Specialized GetInfoHelper for cl::size_t params 1182 template <typename Func, ::size_t N> 1183 inline cl_int getInfoHelper(Func f, cl_uint name, size_t<N>* param, long) 1184 { 1185 ::size_t required; 1186 cl_int err = f(name, 0, NULL, &required); 1187 if (err != CL_SUCCESS) { 1188 return err; 1189 } 1190 1191 ::size_t* value = (::size_t*) alloca(required); 1192 err = f(name, required, value, NULL); 1193 if (err != CL_SUCCESS) { 1194 return err; 1195 } 1196 1197 for(int i = 0; i < N; ++i) { 1198 (*param)[i] = value[i]; 1199 } 1200 1201 return CL_SUCCESS; 1202 } 1203 1204 template<typename T> struct ReferenceHandler; 1205 1206 /* Specialization for reference-counted types. This depends on the 1207 * existence of Wrapper<T>::cl_type, and none of the other types having the 1208 * cl_type member. Note that simplify specifying the parameter as Wrapper<T> 1209 * does not work, because when using a derived type (e.g. Context) the generic 1210 * template will provide a better match. 1211 */ 1212 template<typename Func, typename T> 1213 inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0) 1214 { 1215 typename T::cl_type value; 1216 cl_int err = f(name, sizeof(value), &value, NULL); 1217 if (err != CL_SUCCESS) { 1218 return err; 1219 } 1220 *param = value; 1221 if (value != NULL) 1222 { 1223 err = param->retain(); 1224 if (err != CL_SUCCESS) { 1225 return err; 1226 } 1227 } 1228 return CL_SUCCESS; 1229 } 1230 1231 #define __PARAM_NAME_INFO_1_0(F) \ 1232 F(cl_platform_info, CL_PLATFORM_PROFILE, STRING_CLASS) \ 1233 F(cl_platform_info, CL_PLATFORM_VERSION, STRING_CLASS) \ 1234 F(cl_platform_info, CL_PLATFORM_NAME, STRING_CLASS) \ 1235 F(cl_platform_info, CL_PLATFORM_VENDOR, STRING_CLASS) \ 1236 F(cl_platform_info, CL_PLATFORM_EXTENSIONS, STRING_CLASS) \ 1237 \ 1238 F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \ 1239 F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \ 1240 F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \ 1241 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \ 1242 F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, ::size_t) \ 1243 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, VECTOR_CLASS< ::size_t>) \ 1244 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \ 1245 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \ 1246 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \ 1247 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \ 1248 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \ 1249 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \ 1250 F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \ 1251 F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \ 1252 F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \ 1253 F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \ 1254 F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \ 1255 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, ::size_t) \ 1256 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, ::size_t) \ 1257 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, ::size_t) \ 1258 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, ::size_t) \ 1259 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, ::size_t) \ 1260 F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \ 1261 F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, ::size_t) \ 1262 F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \ 1263 F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \ 1264 F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \ 1265 F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \ 1266 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \ 1267 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\ 1268 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \ 1269 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \ 1270 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \ 1271 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \ 1272 F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \ 1273 F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \ 1274 F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \ 1275 F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, ::size_t) \ 1276 F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \ 1277 F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \ 1278 F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \ 1279 F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \ 1280 F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties) \ 1281 F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \ 1282 F(cl_device_info, CL_DEVICE_NAME, STRING_CLASS) \ 1283 F(cl_device_info, CL_DEVICE_VENDOR, STRING_CLASS) \ 1284 F(cl_device_info, CL_DRIVER_VERSION, STRING_CLASS) \ 1285 F(cl_device_info, CL_DEVICE_PROFILE, STRING_CLASS) \ 1286 F(cl_device_info, CL_DEVICE_VERSION, STRING_CLASS) \ 1287 F(cl_device_info, CL_DEVICE_EXTENSIONS, STRING_CLASS) \ 1288 \ 1289 F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \ 1290 F(cl_context_info, CL_CONTEXT_DEVICES, VECTOR_CLASS<Device>) \ 1291 F(cl_context_info, CL_CONTEXT_PROPERTIES, VECTOR_CLASS<cl_context_properties>) \ 1292 \ 1293 F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \ 1294 F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \ 1295 F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \ 1296 F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_uint) \ 1297 \ 1298 F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \ 1299 F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \ 1300 F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \ 1301 F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \ 1302 \ 1303 F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \ 1304 F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \ 1305 F(cl_mem_info, CL_MEM_SIZE, ::size_t) \ 1306 F(cl_mem_info, CL_MEM_HOST_PTR, void*) \ 1307 F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \ 1308 F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \ 1309 F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \ 1310 \ 1311 F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \ 1312 F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, ::size_t) \ 1313 F(cl_image_info, CL_IMAGE_ROW_PITCH, ::size_t) \ 1314 F(cl_image_info, CL_IMAGE_SLICE_PITCH, ::size_t) \ 1315 F(cl_image_info, CL_IMAGE_WIDTH, ::size_t) \ 1316 F(cl_image_info, CL_IMAGE_HEIGHT, ::size_t) \ 1317 F(cl_image_info, CL_IMAGE_DEPTH, ::size_t) \ 1318 \ 1319 F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \ 1320 F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \ 1321 F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_addressing_mode) \ 1322 F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_filter_mode) \ 1323 F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_bool) \ 1324 \ 1325 F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \ 1326 F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \ 1327 F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \ 1328 F(cl_program_info, CL_PROGRAM_DEVICES, VECTOR_CLASS<Device>) \ 1329 F(cl_program_info, CL_PROGRAM_SOURCE, STRING_CLASS) \ 1330 F(cl_program_info, CL_PROGRAM_BINARY_SIZES, VECTOR_CLASS< ::size_t>) \ 1331 F(cl_program_info, CL_PROGRAM_BINARIES, VECTOR_CLASS<char *>) \ 1332 \ 1333 F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \ 1334 F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, STRING_CLASS) \ 1335 F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, STRING_CLASS) \ 1336 \ 1337 F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, STRING_CLASS) \ 1338 F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \ 1339 F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \ 1340 F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \ 1341 F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \ 1342 \ 1343 F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, ::size_t) \ 1344 F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::size_t<3>) \ 1345 F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \ 1346 \ 1347 F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \ 1348 F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \ 1349 F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \ 1350 F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties) 1351 1352 #if defined(CL_VERSION_1_1) 1353 #define __PARAM_NAME_INFO_1_1(F) \ 1354 F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\ 1355 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \ 1356 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \ 1357 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \ 1358 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \ 1359 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \ 1360 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \ 1361 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \ 1362 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \ 1363 F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \ 1364 F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \ 1365 F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) \ 1366 F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, STRING_CLASS) \ 1367 \ 1368 F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \ 1369 F(cl_mem_info, CL_MEM_OFFSET, ::size_t) \ 1370 \ 1371 F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, ::size_t) \ 1372 F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \ 1373 \ 1374 F(cl_event_info, CL_EVENT_CONTEXT, cl::Context) 1375 #endif // CL_VERSION_1_1 1376 1377 1378 #if defined(CL_VERSION_1_2) 1379 #define __PARAM_NAME_INFO_1_2(F) \ 1380 F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer) \ 1381 \ 1382 F(cl_program_info, CL_PROGRAM_NUM_KERNELS, ::size_t) \ 1383 F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, STRING_CLASS) \ 1384 \ 1385 F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \ 1386 \ 1387 F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, STRING_CLASS) \ 1388 \ 1389 F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \ 1390 F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \ 1391 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, STRING_CLASS) \ 1392 F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, STRING_CLASS) \ 1393 \ 1394 F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl_device_id) \ 1395 F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, VECTOR_CLASS<cl_device_partition_property>) \ 1396 F(cl_device_info, CL_DEVICE_PARTITION_TYPE, VECTOR_CLASS<cl_device_partition_property>) \ 1397 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \ 1398 F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, ::size_t) \ 1399 F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \ 1400 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, STRING_CLASS) 1401 #endif // #if defined(CL_VERSION_1_2) 1402 1403 #if defined(USE_CL_DEVICE_FISSION) 1404 #define __PARAM_NAME_DEVICE_FISSION(F) \ 1405 F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \ 1406 F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \ 1407 F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \ 1408 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \ 1409 F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) 1410 #endif // USE_CL_DEVICE_FISSION 1411 1412 template <typename enum_type, cl_int Name> 1413 struct param_traits {}; 1414 1415 #define __CL_DECLARE_PARAM_TRAITS(token, param_name, T) \ 1416 struct token; \ 1417 template<> \ 1418 struct param_traits<detail:: token,param_name> \ 1419 { \ 1420 enum { value = param_name }; \ 1421 typedef T param_type; \ 1422 }; 1423 1424 __PARAM_NAME_INFO_1_0(__CL_DECLARE_PARAM_TRAITS) 1425 #if defined(CL_VERSION_1_1) 1426 __PARAM_NAME_INFO_1_1(__CL_DECLARE_PARAM_TRAITS) 1427 #endif // CL_VERSION_1_1 1428 #if defined(CL_VERSION_1_2) 1429 __PARAM_NAME_INFO_1_2(__CL_DECLARE_PARAM_TRAITS) 1430 #endif // CL_VERSION_1_1 1431 1432 #if defined(USE_CL_DEVICE_FISSION) 1433 __PARAM_NAME_DEVICE_FISSION(__CL_DECLARE_PARAM_TRAITS); 1434 #endif // USE_CL_DEVICE_FISSION 1435 1436 #ifdef CL_PLATFORM_ICD_SUFFIX_KHR 1437 __CL_DECLARE_PARAM_TRAITS(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, STRING_CLASS) 1438 #endif 1439 1440 #ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD 1441 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong) 1442 #endif 1443 1444 #ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD 1445 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, VECTOR_CLASS< ::size_t>) 1446 #endif 1447 #ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD 1448 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint) 1449 #endif 1450 #ifdef CL_DEVICE_SIMD_WIDTH_AMD 1451 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint) 1452 #endif 1453 #ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD 1454 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint) 1455 #endif 1456 #ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD 1457 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint) 1458 #endif 1459 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD 1460 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint) 1461 #endif 1462 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD 1463 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint) 1464 #endif 1465 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD 1466 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint) 1467 #endif 1468 #ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD 1469 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint) 1470 #endif 1471 #ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD 1472 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint) 1473 #endif 1474 1475 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV 1476 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint) 1477 #endif 1478 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV 1479 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint) 1480 #endif 1481 #ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV 1482 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint) 1483 #endif 1484 #ifdef CL_DEVICE_WARP_SIZE_NV 1485 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint) 1486 #endif 1487 #ifdef CL_DEVICE_GPU_OVERLAP_NV 1488 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool) 1489 #endif 1490 #ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV 1491 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool) 1492 #endif 1493 #ifdef CL_DEVICE_INTEGRATED_MEMORY_NV 1494 __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool) 1495 #endif 1496 1497 // Convenience functions 1498 1499 template <typename Func, typename T> 1500 inline cl_int 1501 getInfo(Func f, cl_uint name, T* param) 1502 { 1503 return getInfoHelper(f, name, param, 0); 1504 } 1505 1506 template <typename Func, typename Arg0> 1507 struct GetInfoFunctor0 1508 { 1509 Func f_; const Arg0& arg0_; 1510 cl_int operator ()( 1511 cl_uint param, ::size_t size, void* value, ::size_t* size_ret) 1512 { return f_(arg0_, param, size, value, size_ret); } 1513 }; 1514 1515 template <typename Func, typename Arg0, typename Arg1> 1516 struct GetInfoFunctor1 1517 { 1518 Func f_; const Arg0& arg0_; const Arg1& arg1_; 1519 cl_int operator ()( 1520 cl_uint param, ::size_t size, void* value, ::size_t* size_ret) 1521 { return f_(arg0_, arg1_, param, size, value, size_ret); } 1522 }; 1523 1524 template <typename Func, typename Arg0, typename T> 1525 inline cl_int 1526 getInfo(Func f, const Arg0& arg0, cl_uint name, T* param) 1527 { 1528 GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 }; 1529 return getInfoHelper(f0, name, param, 0); 1530 } 1531 1532 template <typename Func, typename Arg0, typename Arg1, typename T> 1533 inline cl_int 1534 getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param) 1535 { 1536 GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 }; 1537 return getInfoHelper(f0, name, param, 0); 1538 } 1539 1540 template<typename T> 1541 struct ReferenceHandler 1542 { }; 1543 1544 #if defined(CL_VERSION_1_2) 1545 /** 1546 * OpenCL 1.2 devices do have retain/release. 1547 */ 1548 template <> 1549 struct ReferenceHandler<cl_device_id> 1550 { 1551 /** 1552 * Retain the device. 1553 * \param device A valid device created using createSubDevices 1554 * \return 1555 * CL_SUCCESS if the function executed successfully. 1556 * CL_INVALID_DEVICE if device was not a valid subdevice 1557 * CL_OUT_OF_RESOURCES 1558 * CL_OUT_OF_HOST_MEMORY 1559 */ 1560 static cl_int retain(cl_device_id device) 1561 { return ::clRetainDevice(device); } 1562 /** 1563 * Retain the device. 1564 * \param device A valid device created using createSubDevices 1565 * \return 1566 * CL_SUCCESS if the function executed successfully. 1567 * CL_INVALID_DEVICE if device was not a valid subdevice 1568 * CL_OUT_OF_RESOURCES 1569 * CL_OUT_OF_HOST_MEMORY 1570 */ 1571 static cl_int release(cl_device_id device) 1572 { return ::clReleaseDevice(device); } 1573 }; 1574 #else // #if defined(CL_VERSION_1_2) 1575 /** 1576 * OpenCL 1.1 devices do not have retain/release. 1577 */ 1578 template <> 1579 struct ReferenceHandler<cl_device_id> 1580 { 1581 // cl_device_id does not have retain(). 1582 static cl_int retain(cl_device_id) 1583 { return CL_SUCCESS; } 1584 // cl_device_id does not have release(). 1585 static cl_int release(cl_device_id) 1586 { return CL_SUCCESS; } 1587 }; 1588 #endif // #if defined(CL_VERSION_1_2) 1589 1590 template <> 1591 struct ReferenceHandler<cl_platform_id> 1592 { 1593 // cl_platform_id does not have retain(). 1594 static cl_int retain(cl_platform_id) 1595 { return CL_SUCCESS; } 1596 // cl_platform_id does not have release(). 1597 static cl_int release(cl_platform_id) 1598 { return CL_SUCCESS; } 1599 }; 1600 1601 template <> 1602 struct ReferenceHandler<cl_context> 1603 { 1604 static cl_int retain(cl_context context) 1605 { return ::clRetainContext(context); } 1606 static cl_int release(cl_context context) 1607 { return ::clReleaseContext(context); } 1608 }; 1609 1610 template <> 1611 struct ReferenceHandler<cl_command_queue> 1612 { 1613 static cl_int retain(cl_command_queue queue) 1614 { return ::clRetainCommandQueue(queue); } 1615 static cl_int release(cl_command_queue queue) 1616 { return ::clReleaseCommandQueue(queue); } 1617 }; 1618 1619 template <> 1620 struct ReferenceHandler<cl_mem> 1621 { 1622 static cl_int retain(cl_mem memory) 1623 { return ::clRetainMemObject(memory); } 1624 static cl_int release(cl_mem memory) 1625 { return ::clReleaseMemObject(memory); } 1626 }; 1627 1628 template <> 1629 struct ReferenceHandler<cl_sampler> 1630 { 1631 static cl_int retain(cl_sampler sampler) 1632 { return ::clRetainSampler(sampler); } 1633 static cl_int release(cl_sampler sampler) 1634 { return ::clReleaseSampler(sampler); } 1635 }; 1636 1637 template <> 1638 struct ReferenceHandler<cl_program> 1639 { 1640 static cl_int retain(cl_program program) 1641 { return ::clRetainProgram(program); } 1642 static cl_int release(cl_program program) 1643 { return ::clReleaseProgram(program); } 1644 }; 1645 1646 template <> 1647 struct ReferenceHandler<cl_kernel> 1648 { 1649 static cl_int retain(cl_kernel kernel) 1650 { return ::clRetainKernel(kernel); } 1651 static cl_int release(cl_kernel kernel) 1652 { return ::clReleaseKernel(kernel); } 1653 }; 1654 1655 template <> 1656 struct ReferenceHandler<cl_event> 1657 { 1658 static cl_int retain(cl_event event) 1659 { return ::clRetainEvent(event); } 1660 static cl_int release(cl_event event) 1661 { return ::clReleaseEvent(event); } 1662 }; 1663 1664 1665 // Extracts version number with major in the upper 16 bits, minor in the lower 16 1666 static cl_uint getVersion(const char *versionInfo) 1667 { 1668 int highVersion = 0; 1669 int lowVersion = 0; 1670 int index = 7; 1671 while(versionInfo[index] != '.' ) { 1672 highVersion *= 10; 1673 highVersion += versionInfo[index]-'0'; 1674 ++index; 1675 } 1676 ++index; 1677 while(versionInfo[index] != ' ' ) { 1678 lowVersion *= 10; 1679 lowVersion += versionInfo[index]-'0'; 1680 ++index; 1681 } 1682 return (highVersion << 16) | lowVersion; 1683 } 1684 1685 static cl_uint getPlatformVersion(cl_platform_id platform) 1686 { 1687 ::size_t size = 0; 1688 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size); 1689 char *versionInfo = (char *) alloca(size); 1690 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, &versionInfo[0], &size); 1691 return getVersion(versionInfo); 1692 } 1693 1694 static cl_uint getDevicePlatformVersion(cl_device_id device) 1695 { 1696 cl_platform_id platform; 1697 clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL); 1698 return getPlatformVersion(platform); 1699 } 1700 1701 #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) 1702 static cl_uint getContextPlatformVersion(cl_context context) 1703 { 1704 // The platform cannot be queried directly, so we first have to grab a 1705 // device and obtain its context 1706 ::size_t size = 0; 1707 clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size); 1708 if (size == 0) 1709 return 0; 1710 cl_device_id *devices = (cl_device_id *) alloca(size); 1711 clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices, NULL); 1712 return getDevicePlatformVersion(devices[0]); 1713 } 1714 #endif // #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) 1715 1716 template <typename T> 1717 class Wrapper 1718 { 1719 public: 1720 typedef T cl_type; 1721 1722 protected: 1723 cl_type object_; 1724 1725 public: 1726 Wrapper() : object_(NULL) { } 1727 1728 Wrapper(const cl_type &obj) : object_(obj) { } 1729 1730 ~Wrapper() 1731 { 1732 if (object_ != NULL) { release(); } 1733 } 1734 1735 Wrapper(const Wrapper<cl_type>& rhs) 1736 { 1737 object_ = rhs.object_; 1738 if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } 1739 } 1740 1741 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs) 1742 { 1743 if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } 1744 object_ = rhs.object_; 1745 if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } 1746 return *this; 1747 } 1748 1749 Wrapper<cl_type>& operator = (const cl_type &rhs) 1750 { 1751 if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } 1752 object_ = rhs; 1753 return *this; 1754 } 1755 1756 cl_type operator ()() const { return object_; } 1757 1758 cl_type& operator ()() { return object_; } 1759 1760 protected: 1761 template<typename Func, typename U> 1762 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type); 1763 1764 cl_int retain() const 1765 { 1766 return ReferenceHandler<cl_type>::retain(object_); 1767 } 1768 1769 cl_int release() const 1770 { 1771 return ReferenceHandler<cl_type>::release(object_); 1772 } 1773 }; 1774 1775 template <> 1776 class Wrapper<cl_device_id> 1777 { 1778 public: 1779 typedef cl_device_id cl_type; 1780 1781 protected: 1782 cl_type object_; 1783 bool referenceCountable_; 1784 1785 static bool isReferenceCountable(cl_device_id device) 1786 { 1787 bool retVal = false; 1788 if (device != NULL) { 1789 int version = getDevicePlatformVersion(device); 1790 if(version > ((1 << 16) + 1)) { 1791 retVal = true; 1792 } 1793 } 1794 return retVal; 1795 } 1796 1797 public: 1798 Wrapper() : object_(NULL), referenceCountable_(false) 1799 { 1800 } 1801 1802 Wrapper(const cl_type &obj) : object_(obj), referenceCountable_(false) 1803 { 1804 referenceCountable_ = isReferenceCountable(obj); 1805 } 1806 1807 ~Wrapper() 1808 { 1809 if (object_ != NULL) { release(); } 1810 } 1811 1812 Wrapper(const Wrapper<cl_type>& rhs) 1813 { 1814 object_ = rhs.object_; 1815 referenceCountable_ = isReferenceCountable(object_); 1816 if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } 1817 } 1818 1819 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs) 1820 { 1821 if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } 1822 object_ = rhs.object_; 1823 referenceCountable_ = rhs.referenceCountable_; 1824 if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } 1825 return *this; 1826 } 1827 1828 Wrapper<cl_type>& operator = (const cl_type &rhs) 1829 { 1830 if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } 1831 object_ = rhs; 1832 referenceCountable_ = isReferenceCountable(object_); 1833 return *this; 1834 } 1835 1836 cl_type operator ()() const { return object_; } 1837 1838 cl_type& operator ()() { return object_; } 1839 1840 protected: 1841 template<typename Func, typename U> 1842 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type); 1843 1844 template<typename Func, typename U> 1845 friend inline cl_int getInfoHelper(Func, cl_uint, VECTOR_CLASS<U>*, int, typename U::cl_type); 1846 1847 cl_int retain() const 1848 { 1849 if( referenceCountable_ ) { 1850 return ReferenceHandler<cl_type>::retain(object_); 1851 } 1852 else { 1853 return CL_SUCCESS; 1854 } 1855 } 1856 1857 cl_int release() const 1858 { 1859 if( referenceCountable_ ) { 1860 return ReferenceHandler<cl_type>::release(object_); 1861 } 1862 else { 1863 return CL_SUCCESS; 1864 } 1865 } 1866 }; 1867 1868 } // namespace detail 1869 //! \endcond 1870 1871 /*! \stuct ImageFormat 1872 * \brief Adds constructors and member functions for cl_image_format. 1873 * 1874 * \see cl_image_format 1875 */ 1876 struct ImageFormat : public cl_image_format 1877 { 1878 //! \brief Default constructor - performs no initialization. 1879 ImageFormat(){} 1880 1881 //! \brief Initializing constructor. 1882 ImageFormat(cl_channel_order order, cl_channel_type type) 1883 { 1884 image_channel_order = order; 1885 image_channel_data_type = type; 1886 } 1887 1888 //! \brief Assignment operator. 1889 ImageFormat& operator = (const ImageFormat& rhs) 1890 { 1891 if (this != &rhs) { 1892 this->image_channel_data_type = rhs.image_channel_data_type; 1893 this->image_channel_order = rhs.image_channel_order; 1894 } 1895 return *this; 1896 } 1897 }; 1898 1899 /*! \brief Class interface for cl_device_id. 1900 * 1901 * \note Copies of these objects are inexpensive, since they don't 'own' 1902 * any underlying resources or data structures. 1903 * 1904 * \see cl_device_id 1905 */ 1906 class Device : public detail::Wrapper<cl_device_id> 1907 { 1908 public: 1909 //! \brief Default constructor - initializes to NULL. 1910 Device() : detail::Wrapper<cl_type>() { } 1911 1912 /*! \brief Copy constructor. 1913 * 1914 * This simply copies the device ID value, which is an inexpensive operation. 1915 */ 1916 Device(const Device& device) : detail::Wrapper<cl_type>(device) { } 1917 1918 /*! \brief Constructor from cl_device_id. 1919 * 1920 * This simply copies the device ID value, which is an inexpensive operation. 1921 */ 1922 Device(const cl_device_id &device) : detail::Wrapper<cl_type>(device) { } 1923 1924 /*! \brief Returns the first device on the default context. 1925 * 1926 * \see Context::getDefault() 1927 */ 1928 static Device getDefault(cl_int * err = NULL); 1929 1930 /*! \brief Assignment operator from Device. 1931 * 1932 * This simply copies the device ID value, which is an inexpensive operation. 1933 */ 1934 Device& operator = (const Device& rhs) 1935 { 1936 if (this != &rhs) { 1937 detail::Wrapper<cl_type>::operator=(rhs); 1938 } 1939 return *this; 1940 } 1941 1942 /*! \brief Assignment operator from cl_device_id. 1943 * 1944 * This simply copies the device ID value, which is an inexpensive operation. 1945 */ 1946 Device& operator = (const cl_device_id& rhs) 1947 { 1948 detail::Wrapper<cl_type>::operator=(rhs); 1949 return *this; 1950 } 1951 1952 //! \brief Wrapper for clGetDeviceInfo(). 1953 template <typename T> 1954 cl_int getInfo(cl_device_info name, T* param) const 1955 { 1956 return detail::errHandler( 1957 detail::getInfo(&::clGetDeviceInfo, object_, name, param), 1958 __GET_DEVICE_INFO_ERR); 1959 } 1960 1961 //! \brief Wrapper for clGetDeviceInfo() that returns by value. 1962 template <cl_int name> typename 1963 detail::param_traits<detail::cl_device_info, name>::param_type 1964 getInfo(cl_int* err = NULL) const 1965 { 1966 typename detail::param_traits< 1967 detail::cl_device_info, name>::param_type param; 1968 cl_int result = getInfo(name, ¶m); 1969 if (err != NULL) { 1970 *err = result; 1971 } 1972 return param; 1973 } 1974 1975 /** 1976 * CL 1.2 version 1977 */ 1978 #if defined(CL_VERSION_1_2) 1979 //! \brief Wrapper for clCreateSubDevicesEXT(). 1980 cl_int createSubDevices( 1981 const cl_device_partition_property * properties, 1982 VECTOR_CLASS<Device>* devices) 1983 { 1984 cl_uint n = 0; 1985 cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n); 1986 if (err != CL_SUCCESS) { 1987 return detail::errHandler(err, __CREATE_SUB_DEVICES); 1988 } 1989 1990 cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); 1991 err = clCreateSubDevices(object_, properties, n, ids, NULL); 1992 if (err != CL_SUCCESS) { 1993 return detail::errHandler(err, __CREATE_SUB_DEVICES); 1994 } 1995 1996 devices->assign(&ids[0], &ids[n]); 1997 return CL_SUCCESS; 1998 } 1999 #endif // #if defined(CL_VERSION_1_2) 2000 2001 /** 2002 * CL 1.1 version that uses device fission. 2003 */ 2004 #if defined(CL_VERSION_1_1) 2005 #if defined(USE_CL_DEVICE_FISSION) 2006 cl_int createSubDevices( 2007 const cl_device_partition_property_ext * properties, 2008 VECTOR_CLASS<Device>* devices) 2009 { 2010 typedef CL_API_ENTRY cl_int 2011 ( CL_API_CALL * PFN_clCreateSubDevicesEXT)( 2012 cl_device_id /*in_device*/, 2013 const cl_device_partition_property_ext * /* properties */, 2014 cl_uint /*num_entries*/, 2015 cl_device_id * /*out_devices*/, 2016 cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; 2017 2018 static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL; 2019 __INIT_CL_EXT_FCN_PTR(clCreateSubDevicesEXT); 2020 2021 cl_uint n = 0; 2022 cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n); 2023 if (err != CL_SUCCESS) { 2024 return detail::errHandler(err, __CREATE_SUB_DEVICES); 2025 } 2026 2027 cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); 2028 err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids, NULL); 2029 if (err != CL_SUCCESS) { 2030 return detail::errHandler(err, __CREATE_SUB_DEVICES); 2031 } 2032 2033 devices->assign(&ids[0], &ids[n]); 2034 return CL_SUCCESS; 2035 } 2036 #endif // #if defined(USE_CL_DEVICE_FISSION) 2037 #endif // #if defined(CL_VERSION_1_1) 2038 }; 2039 2040 /*! \brief Class interface for cl_platform_id. 2041 * 2042 * \note Copies of these objects are inexpensive, since they don't 'own' 2043 * any underlying resources or data structures. 2044 * 2045 * \see cl_platform_id 2046 */ 2047 class Platform : public detail::Wrapper<cl_platform_id> 2048 { 2049 public: 2050 //! \brief Default constructor - initializes to NULL. 2051 Platform() : detail::Wrapper<cl_type>() { } 2052 2053 /*! \brief Copy constructor. 2054 * 2055 * This simply copies the platform ID value, which is an inexpensive operation. 2056 */ 2057 Platform(const Platform& platform) : detail::Wrapper<cl_type>(platform) { } 2058 2059 /*! \brief Constructor from cl_platform_id. 2060 * 2061 * This simply copies the platform ID value, which is an inexpensive operation. 2062 */ 2063 Platform(const cl_platform_id &platform) : detail::Wrapper<cl_type>(platform) { } 2064 2065 /*! \brief Assignment operator from Platform. 2066 * 2067 * This simply copies the platform ID value, which is an inexpensive operation. 2068 */ 2069 Platform& operator = (const Platform& rhs) 2070 { 2071 if (this != &rhs) { 2072 detail::Wrapper<cl_type>::operator=(rhs); 2073 } 2074 return *this; 2075 } 2076 2077 /*! \brief Assignment operator from cl_platform_id. 2078 * 2079 * This simply copies the platform ID value, which is an inexpensive operation. 2080 */ 2081 Platform& operator = (const cl_platform_id& rhs) 2082 { 2083 detail::Wrapper<cl_type>::operator=(rhs); 2084 return *this; 2085 } 2086 2087 //! \brief Wrapper for clGetPlatformInfo(). 2088 cl_int getInfo(cl_platform_info name, STRING_CLASS* param) const 2089 { 2090 return detail::errHandler( 2091 detail::getInfo(&::clGetPlatformInfo, object_, name, param), 2092 __GET_PLATFORM_INFO_ERR); 2093 } 2094 2095 //! \brief Wrapper for clGetPlatformInfo() that returns by value. 2096 template <cl_int name> typename 2097 detail::param_traits<detail::cl_platform_info, name>::param_type 2098 getInfo(cl_int* err = NULL) const 2099 { 2100 typename detail::param_traits< 2101 detail::cl_platform_info, name>::param_type param; 2102 cl_int result = getInfo(name, ¶m); 2103 if (err != NULL) { 2104 *err = result; 2105 } 2106 return param; 2107 } 2108 2109 /*! \brief Gets a list of devices for this platform. 2110 * 2111 * Wraps clGetDeviceIDs(). 2112 */ 2113 cl_int getDevices( 2114 cl_device_type type, 2115 VECTOR_CLASS<Device>* devices) const 2116 { 2117 cl_uint n = 0; 2118 if( devices == NULL ) { 2119 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); 2120 } 2121 cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n); 2122 if (err != CL_SUCCESS) { 2123 return detail::errHandler(err, __GET_DEVICE_IDS_ERR); 2124 } 2125 2126 cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); 2127 err = ::clGetDeviceIDs(object_, type, n, ids, NULL); 2128 if (err != CL_SUCCESS) { 2129 return detail::errHandler(err, __GET_DEVICE_IDS_ERR); 2130 } 2131 2132 devices->assign(&ids[0], &ids[n]); 2133 return CL_SUCCESS; 2134 } 2135 2136 #if defined(USE_DX_INTEROP) 2137 /*! \brief Get the list of available D3D10 devices. 2138 * 2139 * \param d3d_device_source. 2140 * 2141 * \param d3d_object. 2142 * 2143 * \param d3d_device_set. 2144 * 2145 * \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device 2146 * values returned in devices can be used to identify a specific OpenCL 2147 * device. If \a devices argument is NULL, this argument is ignored. 2148 * 2149 * \return One of the following values: 2150 * - CL_SUCCESS if the function is executed successfully. 2151 * 2152 * The application can query specific capabilities of the OpenCL device(s) 2153 * returned by cl::getDevices. This can be used by the application to 2154 * determine which device(s) to use. 2155 * 2156 * \note In the case that exceptions are enabled and a return value 2157 * other than CL_SUCCESS is generated, then cl::Error exception is 2158 * generated. 2159 */ 2160 cl_int getDevices( 2161 cl_d3d10_device_source_khr d3d_device_source, 2162 void * d3d_object, 2163 cl_d3d10_device_set_khr d3d_device_set, 2164 VECTOR_CLASS<Device>* devices) const 2165 { 2166 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)( 2167 cl_platform_id platform, 2168 cl_d3d10_device_source_khr d3d_device_source, 2169 void * d3d_object, 2170 cl_d3d10_device_set_khr d3d_device_set, 2171 cl_uint num_entries, 2172 cl_device_id * devices, 2173 cl_uint* num_devices); 2174 2175 if( devices == NULL ) { 2176 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); 2177 } 2178 2179 static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL; 2180 __INIT_CL_EXT_FCN_PTR_PLATFORM(object_, clGetDeviceIDsFromD3D10KHR); 2181 2182 cl_uint n = 0; 2183 cl_int err = pfn_clGetDeviceIDsFromD3D10KHR( 2184 object_, 2185 d3d_device_source, 2186 d3d_object, 2187 d3d_device_set, 2188 0, 2189 NULL, 2190 &n); 2191 if (err != CL_SUCCESS) { 2192 return detail::errHandler(err, __GET_DEVICE_IDS_ERR); 2193 } 2194 2195 cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); 2196 err = pfn_clGetDeviceIDsFromD3D10KHR( 2197 object_, 2198 d3d_device_source, 2199 d3d_object, 2200 d3d_device_set, 2201 n, 2202 ids, 2203 NULL); 2204 if (err != CL_SUCCESS) { 2205 return detail::errHandler(err, __GET_DEVICE_IDS_ERR); 2206 } 2207 2208 devices->assign(&ids[0], &ids[n]); 2209 return CL_SUCCESS; 2210 } 2211 #endif 2212 2213 /*! \brief Gets a list of available platforms. 2214 * 2215 * Wraps clGetPlatformIDs(). 2216 */ 2217 static cl_int get( 2218 VECTOR_CLASS<Platform>* platforms) 2219 { 2220 cl_uint n = 0; 2221 2222 if( platforms == NULL ) { 2223 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR); 2224 } 2225 2226 cl_int err = ::clGetPlatformIDs(0, NULL, &n); 2227 if (err != CL_SUCCESS) { 2228 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); 2229 } 2230 2231 cl_platform_id* ids = (cl_platform_id*) alloca( 2232 n * sizeof(cl_platform_id)); 2233 err = ::clGetPlatformIDs(n, ids, NULL); 2234 if (err != CL_SUCCESS) { 2235 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); 2236 } 2237 2238 platforms->assign(&ids[0], &ids[n]); 2239 return CL_SUCCESS; 2240 } 2241 2242 /*! \brief Gets the first available platform. 2243 * 2244 * Wraps clGetPlatformIDs(), returning the first result. 2245 */ 2246 static cl_int get( 2247 Platform * platform) 2248 { 2249 cl_uint n = 0; 2250 2251 if( platform == NULL ) { 2252 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR); 2253 } 2254 2255 cl_int err = ::clGetPlatformIDs(0, NULL, &n); 2256 if (err != CL_SUCCESS) { 2257 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); 2258 } 2259 2260 cl_platform_id* ids = (cl_platform_id*) alloca( 2261 n * sizeof(cl_platform_id)); 2262 err = ::clGetPlatformIDs(n, ids, NULL); 2263 if (err != CL_SUCCESS) { 2264 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); 2265 } 2266 2267 *platform = ids[0]; 2268 return CL_SUCCESS; 2269 } 2270 2271 /*! \brief Gets the first available platform, returning it by value. 2272 * 2273 * Wraps clGetPlatformIDs(), returning the first result. 2274 */ 2275 static Platform get( 2276 cl_int * errResult = NULL) 2277 { 2278 Platform platform; 2279 cl_uint n = 0; 2280 cl_int err = ::clGetPlatformIDs(0, NULL, &n); 2281 if (err != CL_SUCCESS) { 2282 detail::errHandler(err, __GET_PLATFORM_IDS_ERR); 2283 if (errResult != NULL) { 2284 *errResult = err; 2285 } 2286 } 2287 2288 cl_platform_id* ids = (cl_platform_id*) alloca( 2289 n * sizeof(cl_platform_id)); 2290 err = ::clGetPlatformIDs(n, ids, NULL); 2291 2292 if (err != CL_SUCCESS) { 2293 detail::errHandler(err, __GET_PLATFORM_IDS_ERR); 2294 } 2295 2296 if (errResult != NULL) { 2297 *errResult = err; 2298 } 2299 2300 return ids[0]; 2301 } 2302 2303 static Platform getDefault( 2304 cl_int *errResult = NULL ) 2305 { 2306 return get(errResult); 2307 } 2308 2309 2310 #if defined(CL_VERSION_1_2) 2311 //! \brief Wrapper for clUnloadCompiler(). 2312 cl_int 2313 unloadCompiler() 2314 { 2315 return ::clUnloadPlatformCompiler(object_); 2316 } 2317 #endif // #if defined(CL_VERSION_1_2) 2318 }; // class Platform 2319 2320 /** 2321 * Deprecated APIs for 1.2 2322 */ 2323 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) 2324 /** 2325 * Unload the OpenCL compiler. 2326 * \note Deprecated for OpenCL 1.2. Use Platform::unloadCompiler instead. 2327 */ 2328 inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int 2329 UnloadCompiler() CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; 2330 inline cl_int 2331 UnloadCompiler() 2332 { 2333 return ::clUnloadCompiler(); 2334 } 2335 #endif // #if defined(CL_VERSION_1_1) 2336 2337 /*! \brief Class interface for cl_context. 2338 * 2339 * \note Copies of these objects are shallow, meaning that the copy will refer 2340 * to the same underlying cl_context as the original. For details, see 2341 * clRetainContext() and clReleaseContext(). 2342 * 2343 * \see cl_context 2344 */ 2345 class Context 2346 : public detail::Wrapper<cl_context> 2347 { 2348 private: 2349 static volatile int default_initialized_; 2350 static Context default_; 2351 static volatile cl_int default_error_; 2352 public: 2353 /*! \brief Destructor. 2354 * 2355 * This calls clReleaseContext() on the value held by this instance. 2356 */ 2357 ~Context() { } 2358 2359 /*! \brief Constructs a context including a list of specified devices. 2360 * 2361 * Wraps clCreateContext(). 2362 */ 2363 Context( 2364 const VECTOR_CLASS<Device>& devices, 2365 cl_context_properties* properties = NULL, 2366 void (CL_CALLBACK * notifyFptr)( 2367 const char *, 2368 const void *, 2369 ::size_t, 2370 void *) = NULL, 2371 void* data = NULL, 2372 cl_int* err = NULL) 2373 { 2374 cl_int error; 2375 2376 ::size_t numDevices = devices.size(); 2377 cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); 2378 for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { 2379 deviceIDs[deviceIndex] = (devices[deviceIndex])(); 2380 } 2381 2382 object_ = ::clCreateContext( 2383 properties, (cl_uint) numDevices, 2384 deviceIDs, 2385 notifyFptr, data, &error); 2386 2387 detail::errHandler(error, __CREATE_CONTEXT_ERR); 2388 if (err != NULL) { 2389 *err = error; 2390 } 2391 } 2392 2393 Context( 2394 const Device& device, 2395 cl_context_properties* properties = NULL, 2396 void (CL_CALLBACK * notifyFptr)( 2397 const char *, 2398 const void *, 2399 ::size_t, 2400 void *) = NULL, 2401 void* data = NULL, 2402 cl_int* err = NULL) 2403 { 2404 cl_int error; 2405 2406 cl_device_id deviceID = device(); 2407 2408 object_ = ::clCreateContext( 2409 properties, 1, 2410 &deviceID, 2411 notifyFptr, data, &error); 2412 2413 detail::errHandler(error, __CREATE_CONTEXT_ERR); 2414 if (err != NULL) { 2415 *err = error; 2416 } 2417 } 2418 2419 /*! \brief Constructs a context including all devices of a specified type. 2420 * 2421 * Wraps clCreateContextFromType(). 2422 */ 2423 Context( 2424 cl_device_type type, 2425 cl_context_properties* properties = NULL, 2426 void (CL_CALLBACK * notifyFptr)( 2427 const char *, 2428 const void *, 2429 ::size_t, 2430 void *) = NULL, 2431 void* data = NULL, 2432 cl_int* err = NULL) 2433 { 2434 cl_int error; 2435 2436 #if !defined(__APPLE__) || !defined(__MACOS) 2437 cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 }; 2438 if (properties == NULL) { 2439 prop[1] = (cl_context_properties)Platform::get(&error)(); 2440 if (error != CL_SUCCESS) { 2441 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); 2442 if (err != NULL) { 2443 *err = error; 2444 return; 2445 } 2446 } 2447 2448 properties = &prop[0]; 2449 } 2450 #endif 2451 object_ = ::clCreateContextFromType( 2452 properties, type, notifyFptr, data, &error); 2453 2454 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); 2455 if (err != NULL) { 2456 *err = error; 2457 } 2458 } 2459 2460 /*! \brief Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT. 2461 * 2462 * \note All calls to this function return the same cl_context as the first. 2463 */ 2464 static Context getDefault(cl_int * err = NULL) 2465 { 2466 int state = detail::compare_exchange( 2467 &default_initialized_, 2468 __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED); 2469 2470 if (state & __DEFAULT_INITIALIZED) { 2471 if (err != NULL) { 2472 *err = default_error_; 2473 } 2474 return default_; 2475 } 2476 2477 if (state & __DEFAULT_BEING_INITIALIZED) { 2478 // Assume writes will propagate eventually... 2479 while(default_initialized_ != __DEFAULT_INITIALIZED) { 2480 detail::fence(); 2481 } 2482 2483 if (err != NULL) { 2484 *err = default_error_; 2485 } 2486 return default_; 2487 } 2488 2489 cl_int error; 2490 default_ = Context( 2491 CL_DEVICE_TYPE_DEFAULT, 2492 NULL, 2493 NULL, 2494 NULL, 2495 &error); 2496 2497 detail::fence(); 2498 2499 default_error_ = error; 2500 // Assume writes will propagate eventually... 2501 default_initialized_ = __DEFAULT_INITIALIZED; 2502 2503 detail::fence(); 2504 2505 if (err != NULL) { 2506 *err = default_error_; 2507 } 2508 return default_; 2509 2510 } 2511 2512 //! \brief Default constructor - initializes to NULL. 2513 Context() : detail::Wrapper<cl_type>() { } 2514 2515 /*! \brief Copy constructor. 2516 * 2517 * This calls clRetainContext() on the parameter's cl_context. 2518 */ 2519 Context(const Context& context) : detail::Wrapper<cl_type>(context) { } 2520 2521 /*! \brief Constructor from cl_context - takes ownership. 2522 * 2523 * This effectively transfers ownership of a refcount on the cl_context 2524 * into the new Context object. 2525 */ 2526 __CL_EXPLICIT_CONSTRUCTORS Context(const cl_context& context) : detail::Wrapper<cl_type>(context) { } 2527 2528 /*! \brief Assignment operator from Context. 2529 * 2530 * This calls clRetainContext() on the parameter and clReleaseContext() on 2531 * the previous value held by this instance. 2532 */ 2533 Context& operator = (const Context& rhs) 2534 { 2535 if (this != &rhs) { 2536 detail::Wrapper<cl_type>::operator=(rhs); 2537 } 2538 return *this; 2539 } 2540 2541 /*! \brief Assignment operator from cl_context - takes ownership. 2542 * 2543 * This effectively transfers ownership of a refcount on the rhs and calls 2544 * clReleaseContext() on the value previously held by this instance. 2545 */ 2546 Context& operator = (const cl_context& rhs) 2547 { 2548 detail::Wrapper<cl_type>::operator=(rhs); 2549 return *this; 2550 } 2551 2552 //! \brief Wrapper for clGetContextInfo(). 2553 template <typename T> 2554 cl_int getInfo(cl_context_info name, T* param) const 2555 { 2556 return detail::errHandler( 2557 detail::getInfo(&::clGetContextInfo, object_, name, param), 2558 __GET_CONTEXT_INFO_ERR); 2559 } 2560 2561 //! \brief Wrapper for clGetContextInfo() that returns by value. 2562 template <cl_int name> typename 2563 detail::param_traits<detail::cl_context_info, name>::param_type 2564 getInfo(cl_int* err = NULL) const 2565 { 2566 typename detail::param_traits< 2567 detail::cl_context_info, name>::param_type param; 2568 cl_int result = getInfo(name, ¶m); 2569 if (err != NULL) { 2570 *err = result; 2571 } 2572 return param; 2573 } 2574 2575 /*! \brief Gets a list of supported image formats. 2576 * 2577 * Wraps clGetSupportedImageFormats(). 2578 */ 2579 cl_int getSupportedImageFormats( 2580 cl_mem_flags flags, 2581 cl_mem_object_type type, 2582 VECTOR_CLASS<ImageFormat>* formats) const 2583 { 2584 cl_uint numEntries; 2585 cl_int err = ::clGetSupportedImageFormats( 2586 object_, 2587 flags, 2588 type, 2589 0, 2590 NULL, 2591 &numEntries); 2592 if (err != CL_SUCCESS) { 2593 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR); 2594 } 2595 2596 ImageFormat* value = (ImageFormat*) 2597 alloca(numEntries * sizeof(ImageFormat)); 2598 err = ::clGetSupportedImageFormats( 2599 object_, 2600 flags, 2601 type, 2602 numEntries, 2603 (cl_image_format*) value, 2604 NULL); 2605 if (err != CL_SUCCESS) { 2606 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR); 2607 } 2608 2609 formats->assign(&value[0], &value[numEntries]); 2610 return CL_SUCCESS; 2611 } 2612 }; 2613 2614 inline Device Device::getDefault(cl_int * err) 2615 { 2616 cl_int error; 2617 Device device; 2618 2619 Context context = Context::getDefault(&error); 2620 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); 2621 2622 if (error != CL_SUCCESS) { 2623 if (err != NULL) { 2624 *err = error; 2625 } 2626 } 2627 else { 2628 device = context.getInfo<CL_CONTEXT_DEVICES>()[0]; 2629 if (err != NULL) { 2630 *err = CL_SUCCESS; 2631 } 2632 } 2633 2634 return device; 2635 } 2636 2637 2638 #ifdef _WIN32 2639 __declspec(selectany) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED; 2640 __declspec(selectany) Context Context::default_; 2641 __declspec(selectany) volatile cl_int Context::default_error_ = CL_SUCCESS; 2642 #else 2643 __attribute__((weak)) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED; 2644 __attribute__((weak)) Context Context::default_; 2645 __attribute__((weak)) volatile cl_int Context::default_error_ = CL_SUCCESS; 2646 #endif 2647 2648 /*! \brief Class interface for cl_event. 2649 * 2650 * \note Copies of these objects are shallow, meaning that the copy will refer 2651 * to the same underlying cl_event as the original. For details, see 2652 * clRetainEvent() and clReleaseEvent(). 2653 * 2654 * \see cl_event 2655 */ 2656 class Event : public detail::Wrapper<cl_event> 2657 { 2658 public: 2659 /*! \brief Destructor. 2660 * 2661 * This calls clReleaseEvent() on the value held by this instance. 2662 */ 2663 ~Event() { } 2664 2665 //! \brief Default constructor - initializes to NULL. 2666 Event() : detail::Wrapper<cl_type>() { } 2667 2668 /*! \brief Copy constructor. 2669 * 2670 * This calls clRetainEvent() on the parameter's cl_event. 2671 */ 2672 Event(const Event& event) : detail::Wrapper<cl_type>(event) { } 2673 2674 /*! \brief Constructor from cl_event - takes ownership. 2675 * 2676 * This effectively transfers ownership of a refcount on the cl_event 2677 * into the new Event object. 2678 */ 2679 Event(const cl_event& event) : detail::Wrapper<cl_type>(event) { } 2680 2681 /*! \brief Assignment operator from cl_event - takes ownership. 2682 * 2683 * This effectively transfers ownership of a refcount on the rhs and calls 2684 * clReleaseEvent() on the value previously held by this instance. 2685 */ 2686 Event& operator = (const Event& rhs) 2687 { 2688 if (this != &rhs) { 2689 detail::Wrapper<cl_type>::operator=(rhs); 2690 } 2691 return *this; 2692 } 2693 2694 /*! \brief Assignment operator from cl_event. 2695 * 2696 * This calls clRetainEvent() on the parameter and clReleaseEvent() on 2697 * the previous value held by this instance. 2698 */ 2699 Event& operator = (const cl_event& rhs) 2700 { 2701 detail::Wrapper<cl_type>::operator=(rhs); 2702 return *this; 2703 } 2704 2705 //! \brief Wrapper for clGetEventInfo(). 2706 template <typename T> 2707 cl_int getInfo(cl_event_info name, T* param) const 2708 { 2709 return detail::errHandler( 2710 detail::getInfo(&::clGetEventInfo, object_, name, param), 2711 __GET_EVENT_INFO_ERR); 2712 } 2713 2714 //! \brief Wrapper for clGetEventInfo() that returns by value. 2715 template <cl_int name> typename 2716 detail::param_traits<detail::cl_event_info, name>::param_type 2717 getInfo(cl_int* err = NULL) const 2718 { 2719 typename detail::param_traits< 2720 detail::cl_event_info, name>::param_type param; 2721 cl_int result = getInfo(name, ¶m); 2722 if (err != NULL) { 2723 *err = result; 2724 } 2725 return param; 2726 } 2727 2728 //! \brief Wrapper for clGetEventProfilingInfo(). 2729 template <typename T> 2730 cl_int getProfilingInfo(cl_profiling_info name, T* param) const 2731 { 2732 return detail::errHandler(detail::getInfo( 2733 &::clGetEventProfilingInfo, object_, name, param), 2734 __GET_EVENT_PROFILE_INFO_ERR); 2735 } 2736 2737 //! \brief Wrapper for clGetEventProfilingInfo() that returns by value. 2738 template <cl_int name> typename 2739 detail::param_traits<detail::cl_profiling_info, name>::param_type 2740 getProfilingInfo(cl_int* err = NULL) const 2741 { 2742 typename detail::param_traits< 2743 detail::cl_profiling_info, name>::param_type param; 2744 cl_int result = getProfilingInfo(name, ¶m); 2745 if (err != NULL) { 2746 *err = result; 2747 } 2748 return param; 2749 } 2750 2751 /*! \brief Blocks the calling thread until this event completes. 2752 * 2753 * Wraps clWaitForEvents(). 2754 */ 2755 cl_int wait() const 2756 { 2757 return detail::errHandler( 2758 ::clWaitForEvents(1, &object_), 2759 __WAIT_FOR_EVENTS_ERR); 2760 } 2761 2762 #if defined(CL_VERSION_1_1) 2763 /*! \brief Registers a user callback function for a specific command execution status. 2764 * 2765 * Wraps clSetEventCallback(). 2766 */ 2767 cl_int setCallback( 2768 cl_int type, 2769 void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *), 2770 void * user_data = NULL) 2771 { 2772 return detail::errHandler( 2773 ::clSetEventCallback( 2774 object_, 2775 type, 2776 pfn_notify, 2777 user_data), 2778 __SET_EVENT_CALLBACK_ERR); 2779 } 2780 #endif 2781 2782 /*! \brief Blocks the calling thread until every event specified is complete. 2783 * 2784 * Wraps clWaitForEvents(). 2785 */ 2786 static cl_int 2787 waitForEvents(const VECTOR_CLASS<Event>& events) 2788 { 2789 return detail::errHandler( 2790 ::clWaitForEvents( 2791 (cl_uint) events.size(), (cl_event*)&events.front()), 2792 __WAIT_FOR_EVENTS_ERR); 2793 } 2794 }; 2795 2796 #if defined(CL_VERSION_1_1) 2797 /*! \brief Class interface for user events (a subset of cl_event's). 2798 * 2799 * See Event for details about copy semantics, etc. 2800 */ 2801 class UserEvent : public Event 2802 { 2803 public: 2804 /*! \brief Constructs a user event on a given context. 2805 * 2806 * Wraps clCreateUserEvent(). 2807 */ 2808 UserEvent( 2809 const Context& context, 2810 cl_int * err = NULL) 2811 { 2812 cl_int error; 2813 object_ = ::clCreateUserEvent( 2814 context(), 2815 &error); 2816 2817 detail::errHandler(error, __CREATE_USER_EVENT_ERR); 2818 if (err != NULL) { 2819 *err = error; 2820 } 2821 } 2822 2823 //! \brief Default constructor - initializes to NULL. 2824 UserEvent() : Event() { } 2825 2826 //! \brief Copy constructor - performs shallow copy. 2827 UserEvent(const UserEvent& event) : Event(event) { } 2828 2829 //! \brief Assignment Operator - performs shallow copy. 2830 UserEvent& operator = (const UserEvent& rhs) 2831 { 2832 if (this != &rhs) { 2833 Event::operator=(rhs); 2834 } 2835 return *this; 2836 } 2837 2838 /*! \brief Sets the execution status of a user event object. 2839 * 2840 * Wraps clSetUserEventStatus(). 2841 */ 2842 cl_int setStatus(cl_int status) 2843 { 2844 return detail::errHandler( 2845 ::clSetUserEventStatus(object_,status), 2846 __SET_USER_EVENT_STATUS_ERR); 2847 } 2848 }; 2849 #endif 2850 2851 /*! \brief Blocks the calling thread until every event specified is complete. 2852 * 2853 * Wraps clWaitForEvents(). 2854 */ 2855 inline static cl_int 2856 WaitForEvents(const VECTOR_CLASS<Event>& events) 2857 { 2858 return detail::errHandler( 2859 ::clWaitForEvents( 2860 (cl_uint) events.size(), (cl_event*)&events.front()), 2861 __WAIT_FOR_EVENTS_ERR); 2862 } 2863 2864 /*! \brief Class interface for cl_mem. 2865 * 2866 * \note Copies of these objects are shallow, meaning that the copy will refer 2867 * to the same underlying cl_mem as the original. For details, see 2868 * clRetainMemObject() and clReleaseMemObject(). 2869 * 2870 * \see cl_mem 2871 */ 2872 class Memory : public detail::Wrapper<cl_mem> 2873 { 2874 public: 2875 2876 /*! \brief Destructor. 2877 * 2878 * This calls clReleaseMemObject() on the value held by this instance. 2879 */ 2880 ~Memory() {} 2881 2882 //! \brief Default constructor - initializes to NULL. 2883 Memory() : detail::Wrapper<cl_type>() { } 2884 2885 /*! \brief Copy constructor - performs shallow copy. 2886 * 2887 * This calls clRetainMemObject() on the parameter's cl_mem. 2888 */ 2889 Memory(const Memory& memory) : detail::Wrapper<cl_type>(memory) { } 2890 2891 /*! \brief Constructor from cl_mem - takes ownership. 2892 * 2893 * This effectively transfers ownership of a refcount on the cl_mem 2894 * into the new Memory object. 2895 */ 2896 __CL_EXPLICIT_CONSTRUCTORS Memory(const cl_mem& memory) : detail::Wrapper<cl_type>(memory) { } 2897 2898 /*! \brief Assignment operator from Memory. 2899 * 2900 * This calls clRetainMemObject() on the parameter and clReleaseMemObject() 2901 * on the previous value held by this instance. 2902 */ 2903 Memory& operator = (const Memory& rhs) 2904 { 2905 if (this != &rhs) { 2906 detail::Wrapper<cl_type>::operator=(rhs); 2907 } 2908 return *this; 2909 } 2910 2911 /*! \brief Assignment operator from cl_mem - takes ownership. 2912 * 2913 * This effectively transfers ownership of a refcount on the rhs and calls 2914 * clReleaseMemObject() on the value previously held by this instance. 2915 */ 2916 Memory& operator = (const cl_mem& rhs) 2917 { 2918 detail::Wrapper<cl_type>::operator=(rhs); 2919 return *this; 2920 } 2921 2922 //! \brief Wrapper for clGetMemObjectInfo(). 2923 template <typename T> 2924 cl_int getInfo(cl_mem_info name, T* param) const 2925 { 2926 return detail::errHandler( 2927 detail::getInfo(&::clGetMemObjectInfo, object_, name, param), 2928 __GET_MEM_OBJECT_INFO_ERR); 2929 } 2930 2931 //! \brief Wrapper for clGetMemObjectInfo() that returns by value. 2932 template <cl_int name> typename 2933 detail::param_traits<detail::cl_mem_info, name>::param_type 2934 getInfo(cl_int* err = NULL) const 2935 { 2936 typename detail::param_traits< 2937 detail::cl_mem_info, name>::param_type param; 2938 cl_int result = getInfo(name, ¶m); 2939 if (err != NULL) { 2940 *err = result; 2941 } 2942 return param; 2943 } 2944 2945 #if defined(CL_VERSION_1_1) 2946 /*! \brief Registers a callback function to be called when the memory object 2947 * is no longer needed. 2948 * 2949 * Wraps clSetMemObjectDestructorCallback(). 2950 * 2951 * Repeated calls to this function, for a given cl_mem value, will append 2952 * to the list of functions called (in reverse order) when memory object's 2953 * resources are freed and the memory object is deleted. 2954 * 2955 * \note 2956 * The registered callbacks are associated with the underlying cl_mem 2957 * value - not the Memory class instance. 2958 */ 2959 cl_int setDestructorCallback( 2960 void (CL_CALLBACK * pfn_notify)(cl_mem, void *), 2961 void * user_data = NULL) 2962 { 2963 return detail::errHandler( 2964 ::clSetMemObjectDestructorCallback( 2965 object_, 2966 pfn_notify, 2967 user_data), 2968 __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR); 2969 } 2970 #endif 2971 2972 }; 2973 2974 // Pre-declare copy functions 2975 class Buffer; 2976 template< typename IteratorType > 2977 cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ); 2978 template< typename IteratorType > 2979 cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ); 2980 2981 /*! \brief Class interface for Buffer Memory Objects. 2982 * 2983 * See Memory for details about copy semantics, etc. 2984 * 2985 * \see Memory 2986 */ 2987 class Buffer : public Memory 2988 { 2989 public: 2990 2991 /*! \brief Constructs a Buffer in a specified context. 2992 * 2993 * Wraps clCreateBuffer(). 2994 * 2995 * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was 2996 * specified. Note alignment & exclusivity requirements. 2997 */ 2998 Buffer( 2999 const Context& context, 3000 cl_mem_flags flags, 3001 ::size_t size, 3002 void* host_ptr = NULL, 3003 cl_int* err = NULL) 3004 { 3005 cl_int error; 3006 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error); 3007 3008 detail::errHandler(error, __CREATE_BUFFER_ERR); 3009 if (err != NULL) { 3010 *err = error; 3011 } 3012 } 3013 3014 /*! \brief Constructs a Buffer in the default context. 3015 * 3016 * Wraps clCreateBuffer(). 3017 * 3018 * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was 3019 * specified. Note alignment & exclusivity requirements. 3020 * 3021 * \see Context::getDefault() 3022 */ 3023 Buffer( 3024 cl_mem_flags flags, 3025 ::size_t size, 3026 void* host_ptr = NULL, 3027 cl_int* err = NULL) 3028 { 3029 cl_int error; 3030 3031 Context context = Context::getDefault(err); 3032 3033 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error); 3034 3035 detail::errHandler(error, __CREATE_BUFFER_ERR); 3036 if (err != NULL) { 3037 *err = error; 3038 } 3039 } 3040 3041 /*! 3042 * \brief Construct a Buffer from a host container via iterators. 3043 * If useHostPtr is specified iterators must be random access. 3044 */ 3045 template< typename IteratorType > 3046 Buffer( 3047 IteratorType startIterator, 3048 IteratorType endIterator, 3049 bool readOnly, 3050 bool useHostPtr = false, 3051 cl_int* err = NULL) 3052 { 3053 typedef typename std::iterator_traits<IteratorType>::value_type DataType; 3054 cl_int error; 3055 3056 cl_mem_flags flags = 0; 3057 if( readOnly ) { 3058 flags |= CL_MEM_READ_ONLY; 3059 } 3060 else { 3061 flags |= CL_MEM_READ_WRITE; 3062 } 3063 if( useHostPtr ) { 3064 flags |= CL_MEM_USE_HOST_PTR; 3065 } 3066 3067 ::size_t size = sizeof(DataType)*(endIterator - startIterator); 3068 3069 Context context = Context::getDefault(err); 3070 3071 if( useHostPtr ) { 3072 object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error); 3073 } else { 3074 object_ = ::clCreateBuffer(context(), flags, size, 0, &error); 3075 } 3076 3077 detail::errHandler(error, __CREATE_BUFFER_ERR); 3078 if (err != NULL) { 3079 *err = error; 3080 } 3081 3082 if( !useHostPtr ) { 3083 error = cl::copy(startIterator, endIterator, *this); 3084 detail::errHandler(error, __CREATE_BUFFER_ERR); 3085 if (err != NULL) { 3086 *err = error; 3087 } 3088 } 3089 } 3090 3091 //! \brief Default constructor - initializes to NULL. 3092 Buffer() : Memory() { } 3093 3094 /*! \brief Copy constructor - performs shallow copy. 3095 * 3096 * See Memory for further details. 3097 */ 3098 Buffer(const Buffer& buffer) : Memory(buffer) { } 3099 3100 /*! \brief Constructor from cl_mem - takes ownership. 3101 * 3102 * See Memory for further details. 3103 */ 3104 __CL_EXPLICIT_CONSTRUCTORS Buffer(const cl_mem& buffer) : Memory(buffer) { } 3105 3106 /*! \brief Assignment from Buffer - performs shallow copy. 3107 * 3108 * See Memory for further details. 3109 */ 3110 Buffer& operator = (const Buffer& rhs) 3111 { 3112 if (this != &rhs) { 3113 Memory::operator=(rhs); 3114 } 3115 return *this; 3116 } 3117 3118 /*! \brief Assignment from cl_mem - performs shallow copy. 3119 * 3120 * See Memory for further details. 3121 */ 3122 Buffer& operator = (const cl_mem& rhs) 3123 { 3124 Memory::operator=(rhs); 3125 return *this; 3126 } 3127 3128 #if defined(CL_VERSION_1_1) 3129 /*! \brief Creates a new buffer object from this. 3130 * 3131 * Wraps clCreateSubBuffer(). 3132 */ 3133 Buffer createSubBuffer( 3134 cl_mem_flags flags, 3135 cl_buffer_create_type buffer_create_type, 3136 const void * buffer_create_info, 3137 cl_int * err = NULL) 3138 { 3139 Buffer result; 3140 cl_int error; 3141 result.object_ = ::clCreateSubBuffer( 3142 object_, 3143 flags, 3144 buffer_create_type, 3145 buffer_create_info, 3146 &error); 3147 3148 detail::errHandler(error, __CREATE_SUBBUFFER_ERR); 3149 if (err != NULL) { 3150 *err = error; 3151 } 3152 3153 return result; 3154 } 3155 #endif 3156 }; 3157 3158 #if defined (USE_DX_INTEROP) 3159 /*! \brief Class interface for creating OpenCL buffers from ID3D10Buffer's. 3160 * 3161 * This is provided to facilitate interoperability with Direct3D. 3162 * 3163 * See Memory for details about copy semantics, etc. 3164 * 3165 * \see Memory 3166 */ 3167 class BufferD3D10 : public Buffer 3168 { 3169 public: 3170 typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)( 3171 cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer, 3172 cl_int* errcode_ret); 3173 3174 /*! \brief Constructs a BufferD3D10, in a specified context, from a 3175 * given ID3D10Buffer. 3176 * 3177 * Wraps clCreateFromD3D10BufferKHR(). 3178 */ 3179 BufferD3D10( 3180 const Context& context, 3181 cl_mem_flags flags, 3182 ID3D10Buffer* bufobj, 3183 cl_int * err = NULL) 3184 { 3185 static PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR = NULL; 3186 3187 #if defined(CL_VERSION_1_2) 3188 vector<cl_context_properties> props = context.getInfo<CL_CONTEXT_PROPERTIES>(); 3189 cl_platform platform = -1; 3190 for( int i = 0; i < props.size(); ++i ) { 3191 if( props[i] == CL_CONTEXT_PLATFORM ) { 3192 platform = props[i+1]; 3193 } 3194 } 3195 __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clCreateFromD3D10BufferKHR); 3196 #endif 3197 #if defined(CL_VERSION_1_1) 3198 __INIT_CL_EXT_FCN_PTR(clCreateFromD3D10BufferKHR); 3199 #endif 3200 3201 cl_int error; 3202 object_ = pfn_clCreateFromD3D10BufferKHR( 3203 context(), 3204 flags, 3205 bufobj, 3206 &error); 3207 3208 detail::errHandler(error, __CREATE_GL_BUFFER_ERR); 3209 if (err != NULL) { 3210 *err = error; 3211 } 3212 } 3213 3214 //! \brief Default constructor - initializes to NULL. 3215 BufferD3D10() : Buffer() { } 3216 3217 /*! \brief Copy constructor - performs shallow copy. 3218 * 3219 * See Memory for further details. 3220 */ 3221 BufferD3D10(const BufferD3D10& buffer) : Buffer(buffer) { } 3222 3223 /*! \brief Constructor from cl_mem - takes ownership. 3224 * 3225 * See Memory for further details. 3226 */ 3227 __CL_EXPLICIT_CONSTRUCTORS BufferD3D10(const cl_mem& buffer) : Buffer(buffer) { } 3228 3229 /*! \brief Assignment from BufferD3D10 - performs shallow copy. 3230 * 3231 * See Memory for further details. 3232 */ 3233 BufferD3D10& operator = (const BufferD3D10& rhs) 3234 { 3235 if (this != &rhs) { 3236 Buffer::operator=(rhs); 3237 } 3238 return *this; 3239 } 3240 3241 /*! \brief Assignment from cl_mem - performs shallow copy. 3242 * 3243 * See Memory for further details. 3244 */ 3245 BufferD3D10& operator = (const cl_mem& rhs) 3246 { 3247 Buffer::operator=(rhs); 3248 return *this; 3249 } 3250 }; 3251 #endif 3252 3253 /*! \brief Class interface for GL Buffer Memory Objects. 3254 * 3255 * This is provided to facilitate interoperability with OpenGL. 3256 * 3257 * See Memory for details about copy semantics, etc. 3258 * 3259 * \see Memory 3260 */ 3261 class BufferGL : public Buffer 3262 { 3263 public: 3264 /*! \brief Constructs a BufferGL in a specified context, from a given 3265 * GL buffer. 3266 * 3267 * Wraps clCreateFromGLBuffer(). 3268 */ 3269 BufferGL( 3270 const Context& context, 3271 cl_mem_flags flags, 3272 GLuint bufobj, 3273 cl_int * err = NULL) 3274 { 3275 cl_int error; 3276 object_ = ::clCreateFromGLBuffer( 3277 context(), 3278 flags, 3279 bufobj, 3280 &error); 3281 3282 detail::errHandler(error, __CREATE_GL_BUFFER_ERR); 3283 if (err != NULL) { 3284 *err = error; 3285 } 3286 } 3287 3288 //! \brief Default constructor - initializes to NULL. 3289 BufferGL() : Buffer() { } 3290 3291 /*! \brief Copy constructor - performs shallow copy. 3292 * 3293 * See Memory for further details. 3294 */ 3295 BufferGL(const BufferGL& buffer) : Buffer(buffer) { } 3296 3297 /*! \brief Constructor from cl_mem - takes ownership. 3298 * 3299 * See Memory for further details. 3300 */ 3301 __CL_EXPLICIT_CONSTRUCTORS BufferGL(const cl_mem& buffer) : Buffer(buffer) { } 3302 3303 /*! \brief Assignment from BufferGL - performs shallow copy. 3304 * 3305 * See Memory for further details. 3306 */ 3307 BufferGL& operator = (const BufferGL& rhs) 3308 { 3309 if (this != &rhs) { 3310 Buffer::operator=(rhs); 3311 } 3312 return *this; 3313 } 3314 3315 /*! \brief Assignment from cl_mem - performs shallow copy. 3316 * 3317 * See Memory for further details. 3318 */ 3319 BufferGL& operator = (const cl_mem& rhs) 3320 { 3321 Buffer::operator=(rhs); 3322 return *this; 3323 } 3324 3325 //! \brief Wrapper for clGetGLObjectInfo(). 3326 cl_int getObjectInfo( 3327 cl_gl_object_type *type, 3328 GLuint * gl_object_name) 3329 { 3330 return detail::errHandler( 3331 ::clGetGLObjectInfo(object_,type,gl_object_name), 3332 __GET_GL_OBJECT_INFO_ERR); 3333 } 3334 }; 3335 3336 /*! \brief Class interface for GL Render Buffer Memory Objects. 3337 * 3338 * This is provided to facilitate interoperability with OpenGL. 3339 * 3340 * See Memory for details about copy semantics, etc. 3341 * 3342 * \see Memory 3343 */ 3344 class BufferRenderGL : public Buffer 3345 { 3346 public: 3347 /*! \brief Constructs a BufferRenderGL in a specified context, from a given 3348 * GL Renderbuffer. 3349 * 3350 * Wraps clCreateFromGLRenderbuffer(). 3351 */ 3352 BufferRenderGL( 3353 const Context& context, 3354 cl_mem_flags flags, 3355 GLuint bufobj, 3356 cl_int * err = NULL) 3357 { 3358 cl_int error; 3359 object_ = ::clCreateFromGLRenderbuffer( 3360 context(), 3361 flags, 3362 bufobj, 3363 &error); 3364 3365 detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR); 3366 if (err != NULL) { 3367 *err = error; 3368 } 3369 } 3370 3371 //! \brief Default constructor - initializes to NULL. 3372 BufferRenderGL() : Buffer() { } 3373 3374 /*! \brief Copy constructor - performs shallow copy. 3375 * 3376 * See Memory for further details. 3377 */ 3378 BufferRenderGL(const BufferGL& buffer) : Buffer(buffer) { } 3379 3380 /*! \brief Constructor from cl_mem - takes ownership. 3381 * 3382 * See Memory for further details. 3383 */ 3384 __CL_EXPLICIT_CONSTRUCTORS BufferRenderGL(const cl_mem& buffer) : Buffer(buffer) { } 3385 3386 /*! \brief Assignment from BufferGL - performs shallow copy. 3387 * 3388 * See Memory for further details. 3389 */ 3390 BufferRenderGL& operator = (const BufferRenderGL& rhs) 3391 { 3392 if (this != &rhs) { 3393 Buffer::operator=(rhs); 3394 } 3395 return *this; 3396 } 3397 3398 /*! \brief Assignment from cl_mem - performs shallow copy. 3399 * 3400 * See Memory for further details. 3401 */ 3402 BufferRenderGL& operator = (const cl_mem& rhs) 3403 { 3404 Buffer::operator=(rhs); 3405 return *this; 3406 } 3407 3408 //! \brief Wrapper for clGetGLObjectInfo(). 3409 cl_int getObjectInfo( 3410 cl_gl_object_type *type, 3411 GLuint * gl_object_name) 3412 { 3413 return detail::errHandler( 3414 ::clGetGLObjectInfo(object_,type,gl_object_name), 3415 __GET_GL_OBJECT_INFO_ERR); 3416 } 3417 }; 3418 3419 /*! \brief C++ base class for Image Memory objects. 3420 * 3421 * See Memory for details about copy semantics, etc. 3422 * 3423 * \see Memory 3424 */ 3425 class Image : public Memory 3426 { 3427 protected: 3428 //! \brief Default constructor - initializes to NULL. 3429 Image() : Memory() { } 3430 3431 /*! \brief Copy constructor - performs shallow copy. 3432 * 3433 * See Memory for further details. 3434 */ 3435 Image(const Image& image) : Memory(image) { } 3436 3437 /*! \brief Constructor from cl_mem - takes ownership. 3438 * 3439 * See Memory for further details. 3440 */ 3441 __CL_EXPLICIT_CONSTRUCTORS Image(const cl_mem& image) : Memory(image) { } 3442 3443 /*! \brief Assignment from Image - performs shallow copy. 3444 * 3445 * See Memory for further details. 3446 */ 3447 Image& operator = (const Image& rhs) 3448 { 3449 if (this != &rhs) { 3450 Memory::operator=(rhs); 3451 } 3452 return *this; 3453 } 3454 3455 /*! \brief Assignment from cl_mem - performs shallow copy. 3456 * 3457 * See Memory for further details. 3458 */ 3459 Image& operator = (const cl_mem& rhs) 3460 { 3461 Memory::operator=(rhs); 3462 return *this; 3463 } 3464 3465 public: 3466 //! \brief Wrapper for clGetImageInfo(). 3467 template <typename T> 3468 cl_int getImageInfo(cl_image_info name, T* param) const 3469 { 3470 return detail::errHandler( 3471 detail::getInfo(&::clGetImageInfo, object_, name, param), 3472 __GET_IMAGE_INFO_ERR); 3473 } 3474 3475 //! \brief Wrapper for clGetImageInfo() that returns by value. 3476 template <cl_int name> typename 3477 detail::param_traits<detail::cl_image_info, name>::param_type 3478 getImageInfo(cl_int* err = NULL) const 3479 { 3480 typename detail::param_traits< 3481 detail::cl_image_info, name>::param_type param; 3482 cl_int result = getImageInfo(name, ¶m); 3483 if (err != NULL) { 3484 *err = result; 3485 } 3486 return param; 3487 } 3488 }; 3489 3490 #if defined(CL_VERSION_1_2) 3491 /*! \brief Class interface for 1D Image Memory objects. 3492 * 3493 * See Memory for details about copy semantics, etc. 3494 * 3495 * \see Memory 3496 */ 3497 class Image1D : public Image 3498 { 3499 public: 3500 /*! \brief Constructs a 1D Image in a specified context. 3501 * 3502 * Wraps clCreateImage(). 3503 */ 3504 Image1D( 3505 const Context& context, 3506 cl_mem_flags flags, 3507 ImageFormat format, 3508 ::size_t width, 3509 void* host_ptr = NULL, 3510 cl_int* err = NULL) 3511 { 3512 cl_int error; 3513 cl_image_desc desc; 3514 desc.image_type = CL_MEM_OBJECT_IMAGE1D; 3515 desc.image_width = width; 3516 desc.image_row_pitch = 0; 3517 desc.num_mip_levels = 0; 3518 desc.num_samples = 0; 3519 desc.buffer = 0; 3520 object_ = ::clCreateImage( 3521 context(), 3522 flags, 3523 &format, 3524 &desc, 3525 host_ptr, 3526 &error); 3527 3528 detail::errHandler(error, __CREATE_IMAGE_ERR); 3529 if (err != NULL) { 3530 *err = error; 3531 } 3532 } 3533 3534 //! \brief Default constructor - initializes to NULL. 3535 Image1D() { } 3536 3537 /*! \brief Copy constructor - performs shallow copy. 3538 * 3539 * See Memory for further details. 3540 */ 3541 Image1D(const Image1D& image1D) : Image(image1D) { } 3542 3543 /*! \brief Constructor from cl_mem - takes ownership. 3544 * 3545 * See Memory for further details. 3546 */ 3547 __CL_EXPLICIT_CONSTRUCTORS Image1D(const cl_mem& image1D) : Image(image1D) { } 3548 3549 /*! \brief Assignment from Image1D - performs shallow copy. 3550 * 3551 * See Memory for further details. 3552 */ 3553 Image1D& operator = (const Image1D& rhs) 3554 { 3555 if (this != &rhs) { 3556 Image::operator=(rhs); 3557 } 3558 return *this; 3559 } 3560 3561 /*! \brief Assignment from cl_mem - performs shallow copy. 3562 * 3563 * See Memory for further details. 3564 */ 3565 Image1D& operator = (const cl_mem& rhs) 3566 { 3567 Image::operator=(rhs); 3568 return *this; 3569 } 3570 }; 3571 3572 /*! \class Image1DBuffer 3573 * \brief Image interface for 1D buffer images. 3574 */ 3575 class Image1DBuffer : public Image 3576 { 3577 public: 3578 Image1DBuffer( 3579 const Context& context, 3580 cl_mem_flags flags, 3581 ImageFormat format, 3582 ::size_t width, 3583 const Buffer &buffer, 3584 cl_int* err = NULL) 3585 { 3586 cl_int error; 3587 cl_image_desc desc; 3588 desc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER; 3589 desc.image_width = width; 3590 desc.image_row_pitch = 0; 3591 desc.num_mip_levels = 0; 3592 desc.num_samples = 0; 3593 desc.buffer = buffer(); 3594 object_ = ::clCreateImage( 3595 context(), 3596 flags, 3597 &format, 3598 &desc, 3599 NULL, 3600 &error); 3601 3602 detail::errHandler(error, __CREATE_IMAGE_ERR); 3603 if (err != NULL) { 3604 *err = error; 3605 } 3606 } 3607 3608 Image1DBuffer() { } 3609 3610 Image1DBuffer(const Image1DBuffer& image1D) : Image(image1D) { } 3611 3612 __CL_EXPLICIT_CONSTRUCTORS Image1DBuffer(const cl_mem& image1D) : Image(image1D) { } 3613 3614 Image1DBuffer& operator = (const Image1DBuffer& rhs) 3615 { 3616 if (this != &rhs) { 3617 Image::operator=(rhs); 3618 } 3619 return *this; 3620 } 3621 3622 Image1DBuffer& operator = (const cl_mem& rhs) 3623 { 3624 Image::operator=(rhs); 3625 return *this; 3626 } 3627 }; 3628 3629 /*! \class Image1DArray 3630 * \brief Image interface for arrays of 1D images. 3631 */ 3632 class Image1DArray : public Image 3633 { 3634 public: 3635 Image1DArray( 3636 const Context& context, 3637 cl_mem_flags flags, 3638 ImageFormat format, 3639 ::size_t arraySize, 3640 ::size_t width, 3641 ::size_t rowPitch, 3642 void* host_ptr = NULL, 3643 cl_int* err = NULL) 3644 { 3645 cl_int error; 3646 cl_image_desc desc; 3647 desc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY; 3648 desc.image_array_size = arraySize; 3649 desc.image_width = width; 3650 desc.image_row_pitch = rowPitch; 3651 desc.num_mip_levels = 0; 3652 desc.num_samples = 0; 3653 desc.buffer = 0; 3654 object_ = ::clCreateImage( 3655 context(), 3656 flags, 3657 &format, 3658 &desc, 3659 host_ptr, 3660 &error); 3661 3662 detail::errHandler(error, __CREATE_IMAGE_ERR); 3663 if (err != NULL) { 3664 *err = error; 3665 } 3666 } 3667 3668 Image1DArray() { } 3669 3670 Image1DArray(const Image1DArray& imageArray) : Image(imageArray) { } 3671 3672 __CL_EXPLICIT_CONSTRUCTORS Image1DArray(const cl_mem& imageArray) : Image(imageArray) { } 3673 3674 Image1DArray& operator = (const Image1DArray& rhs) 3675 { 3676 if (this != &rhs) { 3677 Image::operator=(rhs); 3678 } 3679 return *this; 3680 } 3681 3682 Image1DArray& operator = (const cl_mem& rhs) 3683 { 3684 Image::operator=(rhs); 3685 return *this; 3686 } 3687 }; 3688 #endif // #if defined(CL_VERSION_1_2) 3689 3690 3691 /*! \brief Class interface for 2D Image Memory objects. 3692 * 3693 * See Memory for details about copy semantics, etc. 3694 * 3695 * \see Memory 3696 */ 3697 class Image2D : public Image 3698 { 3699 public: 3700 /*! \brief Constructs a 1D Image in a specified context. 3701 * 3702 * Wraps clCreateImage(). 3703 */ 3704 Image2D( 3705 const Context& context, 3706 cl_mem_flags flags, 3707 ImageFormat format, 3708 ::size_t width, 3709 ::size_t height, 3710 ::size_t row_pitch = 0, 3711 void* host_ptr = NULL, 3712 cl_int* err = NULL) 3713 { 3714 cl_int error; 3715 bool useCreateImage; 3716 3717 #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) 3718 // Run-time decision based on the actual platform 3719 { 3720 cl_uint version = detail::getContextPlatformVersion(context()); 3721 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above 3722 } 3723 #elif defined(CL_VERSION_1_2) 3724 useCreateImage = true; 3725 #else 3726 useCreateImage = false; 3727 #endif 3728 3729 #if defined(CL_VERSION_1_2) 3730 if (useCreateImage) 3731 { 3732 cl_image_desc desc; 3733 desc.image_type = CL_MEM_OBJECT_IMAGE2D; 3734 desc.image_width = width; 3735 desc.image_height = height; 3736 desc.image_row_pitch = row_pitch; 3737 desc.num_mip_levels = 0; 3738 desc.num_samples = 0; 3739 desc.buffer = 0; 3740 object_ = ::clCreateImage( 3741 context(), 3742 flags, 3743 &format, 3744 &desc, 3745 host_ptr, 3746 &error); 3747 3748 detail::errHandler(error, __CREATE_IMAGE_ERR); 3749 if (err != NULL) { 3750 *err = error; 3751 } 3752 } 3753 #endif // #if defined(CL_VERSION_1_2) 3754 #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) 3755 if (!useCreateImage) 3756 { 3757 object_ = ::clCreateImage2D( 3758 context(), flags,&format, width, height, row_pitch, host_ptr, &error); 3759 3760 detail::errHandler(error, __CREATE_IMAGE2D_ERR); 3761 if (err != NULL) { 3762 *err = error; 3763 } 3764 } 3765 #endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) 3766 } 3767 3768 //! \brief Default constructor - initializes to NULL. 3769 Image2D() { } 3770 3771 /*! \brief Copy constructor - performs shallow copy. 3772 * 3773 * See Memory for further details. 3774 */ 3775 Image2D(const Image2D& image2D) : Image(image2D) { } 3776 3777 /*! \brief Constructor from cl_mem - takes ownership. 3778 * 3779 * See Memory for further details. 3780 */ 3781 __CL_EXPLICIT_CONSTRUCTORS Image2D(const cl_mem& image2D) : Image(image2D) { } 3782 3783 /*! \brief Assignment from Image2D - performs shallow copy. 3784 * 3785 * See Memory for further details. 3786 */ 3787 Image2D& operator = (const Image2D& rhs) 3788 { 3789 if (this != &rhs) { 3790 Image::operator=(rhs); 3791 } 3792 return *this; 3793 } 3794 3795 /*! \brief Assignment from cl_mem - performs shallow copy. 3796 * 3797 * See Memory for further details. 3798 */ 3799 Image2D& operator = (const cl_mem& rhs) 3800 { 3801 Image::operator=(rhs); 3802 return *this; 3803 } 3804 }; 3805 3806 3807 #if !defined(CL_VERSION_1_2) 3808 /*! \brief Class interface for GL 2D Image Memory objects. 3809 * 3810 * This is provided to facilitate interoperability with OpenGL. 3811 * 3812 * See Memory for details about copy semantics, etc. 3813 * 3814 * \see Memory 3815 * \note Deprecated for OpenCL 1.2. Please use ImageGL instead. 3816 */ 3817 class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED Image2DGL CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED : public Image2D 3818 { 3819 public: 3820 /*! \brief Constructs an Image2DGL in a specified context, from a given 3821 * GL Texture. 3822 * 3823 * Wraps clCreateFromGLTexture2D(). 3824 */ 3825 Image2DGL( 3826 const Context& context, 3827 cl_mem_flags flags, 3828 GLenum target, 3829 GLint miplevel, 3830 GLuint texobj, 3831 cl_int * err = NULL) 3832 { 3833 cl_int error; 3834 object_ = ::clCreateFromGLTexture2D( 3835 context(), 3836 flags, 3837 target, 3838 miplevel, 3839 texobj, 3840 &error); 3841 3842 detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR); 3843 if (err != NULL) { 3844 *err = error; 3845 } 3846 3847 } 3848 3849 //! \brief Default constructor - initializes to NULL. 3850 Image2DGL() : Image2D() { } 3851 3852 /*! \brief Copy constructor - performs shallow copy. 3853 * 3854 * See Memory for further details. 3855 */ 3856 Image2DGL(const Image2DGL& image) : Image2D(image) { } 3857 3858 /*! \brief Constructor from cl_mem - takes ownership. 3859 * 3860 * See Memory for further details. 3861 */ 3862 __CL_EXPLICIT_CONSTRUCTORS Image2DGL(const cl_mem& image) : Image2D(image) { } 3863 3864 /*! \brief Assignment from Image2DGL - performs shallow copy. 3865 * 3866 * See Memory for further details. 3867 */ 3868 Image2DGL& operator = (const Image2DGL& rhs) 3869 { 3870 if (this != &rhs) { 3871 Image2D::operator=(rhs); 3872 } 3873 return *this; 3874 } 3875 3876 /*! \brief Assignment from cl_mem - performs shallow copy. 3877 * 3878 * See Memory for further details. 3879 */ 3880 Image2DGL& operator = (const cl_mem& rhs) 3881 { 3882 Image2D::operator=(rhs); 3883 return *this; 3884 } 3885 }; 3886 #endif // #if !defined(CL_VERSION_1_2) 3887 3888 #if defined(CL_VERSION_1_2) 3889 /*! \class Image2DArray 3890 * \brief Image interface for arrays of 2D images. 3891 */ 3892 class Image2DArray : public Image 3893 { 3894 public: 3895 Image2DArray( 3896 const Context& context, 3897 cl_mem_flags flags, 3898 ImageFormat format, 3899 ::size_t arraySize, 3900 ::size_t width, 3901 ::size_t height, 3902 ::size_t rowPitch, 3903 ::size_t slicePitch, 3904 void* host_ptr = NULL, 3905 cl_int* err = NULL) 3906 { 3907 cl_int error; 3908 cl_image_desc desc; 3909 desc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY; 3910 desc.image_array_size = arraySize; 3911 desc.image_width = width; 3912 desc.image_height = height; 3913 desc.image_row_pitch = rowPitch; 3914 desc.image_slice_pitch = slicePitch; 3915 desc.num_mip_levels = 0; 3916 desc.num_samples = 0; 3917 desc.buffer = 0; 3918 object_ = ::clCreateImage( 3919 context(), 3920 flags, 3921 &format, 3922 &desc, 3923 host_ptr, 3924 &error); 3925 3926 detail::errHandler(error, __CREATE_IMAGE_ERR); 3927 if (err != NULL) { 3928 *err = error; 3929 } 3930 } 3931 3932 Image2DArray() { } 3933 3934 Image2DArray(const Image2DArray& imageArray) : Image(imageArray) { } 3935 3936 __CL_EXPLICIT_CONSTRUCTORS Image2DArray(const cl_mem& imageArray) : Image(imageArray) { } 3937 3938 Image2DArray& operator = (const Image2DArray& rhs) 3939 { 3940 if (this != &rhs) { 3941 Image::operator=(rhs); 3942 } 3943 return *this; 3944 } 3945 3946 Image2DArray& operator = (const cl_mem& rhs) 3947 { 3948 Image::operator=(rhs); 3949 return *this; 3950 } 3951 }; 3952 #endif // #if defined(CL_VERSION_1_2) 3953 3954 /*! \brief Class interface for 3D Image Memory objects. 3955 * 3956 * See Memory for details about copy semantics, etc. 3957 * 3958 * \see Memory 3959 */ 3960 class Image3D : public Image 3961 { 3962 public: 3963 /*! \brief Constructs a 3D Image in a specified context. 3964 * 3965 * Wraps clCreateImage(). 3966 */ 3967 Image3D( 3968 const Context& context, 3969 cl_mem_flags flags, 3970 ImageFormat format, 3971 ::size_t width, 3972 ::size_t height, 3973 ::size_t depth, 3974 ::size_t row_pitch = 0, 3975 ::size_t slice_pitch = 0, 3976 void* host_ptr = NULL, 3977 cl_int* err = NULL) 3978 { 3979 cl_int error; 3980 bool useCreateImage; 3981 3982 #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) 3983 // Run-time decision based on the actual platform 3984 { 3985 cl_uint version = detail::getContextPlatformVersion(context()); 3986 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above 3987 } 3988 #elif defined(CL_VERSION_1_2) 3989 useCreateImage = true; 3990 #else 3991 useCreateImage = false; 3992 #endif 3993 3994 #if defined(CL_VERSION_1_2) 3995 if (useCreateImage) 3996 { 3997 cl_image_desc desc; 3998 desc.image_type = CL_MEM_OBJECT_IMAGE3D; 3999 desc.image_width = width; 4000 desc.image_height = height; 4001 desc.image_depth = depth; 4002 desc.image_row_pitch = row_pitch; 4003 desc.image_slice_pitch = slice_pitch; 4004 desc.num_mip_levels = 0; 4005 desc.num_samples = 0; 4006 desc.buffer = 0; 4007 object_ = ::clCreateImage( 4008 context(), 4009 flags, 4010 &format, 4011 &desc, 4012 host_ptr, 4013 &error); 4014 4015 detail::errHandler(error, __CREATE_IMAGE_ERR); 4016 if (err != NULL) { 4017 *err = error; 4018 } 4019 } 4020 #endif // #if defined(CL_VERSION_1_2) 4021 #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) 4022 if (!useCreateImage) 4023 { 4024 object_ = ::clCreateImage3D( 4025 context(), flags, &format, width, height, depth, row_pitch, 4026 slice_pitch, host_ptr, &error); 4027 4028 detail::errHandler(error, __CREATE_IMAGE3D_ERR); 4029 if (err != NULL) { 4030 *err = error; 4031 } 4032 } 4033 #endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) 4034 } 4035 4036 //! \brief Default constructor - initializes to NULL. 4037 Image3D() { } 4038 4039 /*! \brief Copy constructor - performs shallow copy. 4040 * 4041 * See Memory for further details. 4042 */ 4043 Image3D(const Image3D& image3D) : Image(image3D) { } 4044 4045 /*! \brief Constructor from cl_mem - takes ownership. 4046 * 4047 * See Memory for further details. 4048 */ 4049 __CL_EXPLICIT_CONSTRUCTORS Image3D(const cl_mem& image3D) : Image(image3D) { } 4050 4051 /*! \brief Assignment from Image3D - performs shallow copy. 4052 * 4053 * See Memory for further details. 4054 */ 4055 Image3D& operator = (const Image3D& rhs) 4056 { 4057 if (this != &rhs) { 4058 Image::operator=(rhs); 4059 } 4060 return *this; 4061 } 4062 4063 /*! \brief Assignment from cl_mem - performs shallow copy. 4064 * 4065 * See Memory for further details. 4066 */ 4067 Image3D& operator = (const cl_mem& rhs) 4068 { 4069 Image::operator=(rhs); 4070 return *this; 4071 } 4072 }; 4073 4074 #if !defined(CL_VERSION_1_2) 4075 /*! \brief Class interface for GL 3D Image Memory objects. 4076 * 4077 * This is provided to facilitate interoperability with OpenGL. 4078 * 4079 * See Memory for details about copy semantics, etc. 4080 * 4081 * \see Memory 4082 */ 4083 class Image3DGL : public Image3D 4084 { 4085 public: 4086 /*! \brief Constructs an Image3DGL in a specified context, from a given 4087 * GL Texture. 4088 * 4089 * Wraps clCreateFromGLTexture3D(). 4090 */ 4091 Image3DGL( 4092 const Context& context, 4093 cl_mem_flags flags, 4094 GLenum target, 4095 GLint miplevel, 4096 GLuint texobj, 4097 cl_int * err = NULL) 4098 { 4099 cl_int error; 4100 object_ = ::clCreateFromGLTexture3D( 4101 context(), 4102 flags, 4103 target, 4104 miplevel, 4105 texobj, 4106 &error); 4107 4108 detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR); 4109 if (err != NULL) { 4110 *err = error; 4111 } 4112 } 4113 4114 //! \brief Default constructor - initializes to NULL. 4115 Image3DGL() : Image3D() { } 4116 4117 /*! \brief Copy constructor - performs shallow copy. 4118 * 4119 * See Memory for further details. 4120 */ 4121 Image3DGL(const Image3DGL& image) : Image3D(image) { } 4122 4123 /*! \brief Constructor from cl_mem - takes ownership. 4124 * 4125 * See Memory for further details. 4126 */ 4127 __CL_EXPLICIT_CONSTRUCTORS Image3DGL(const cl_mem& image) : Image3D(image) { } 4128 4129 /*! \brief Assignment from Image3DGL - performs shallow copy. 4130 * 4131 * See Memory for further details. 4132 */ 4133 Image3DGL& operator = (const Image3DGL& rhs) 4134 { 4135 if (this != &rhs) { 4136 Image3D::operator=(rhs); 4137 } 4138 return *this; 4139 } 4140 4141 /*! \brief Assignment from cl_mem - performs shallow copy. 4142 * 4143 * See Memory for further details. 4144 */ 4145 Image3DGL& operator = (const cl_mem& rhs) 4146 { 4147 Image3D::operator=(rhs); 4148 return *this; 4149 } 4150 }; 4151 #endif // #if !defined(CL_VERSION_1_2) 4152 4153 #if defined(CL_VERSION_1_2) 4154 /*! \class ImageGL 4155 * \brief general image interface for GL interop. 4156 * We abstract the 2D and 3D GL images into a single instance here 4157 * that wraps all GL sourced images on the grounds that setup information 4158 * was performed by OpenCL anyway. 4159 */ 4160 class ImageGL : public Image 4161 { 4162 public: 4163 ImageGL( 4164 const Context& context, 4165 cl_mem_flags flags, 4166 GLenum target, 4167 GLint miplevel, 4168 GLuint texobj, 4169 cl_int * err = NULL) 4170 { 4171 cl_int error; 4172 object_ = ::clCreateFromGLTexture( 4173 context(), 4174 flags, 4175 target, 4176 miplevel, 4177 texobj, 4178 &error); 4179 4180 detail::errHandler(error, __CREATE_GL_TEXTURE_ERR); 4181 if (err != NULL) { 4182 *err = error; 4183 } 4184 } 4185 4186 ImageGL() : Image() { } 4187 4188 ImageGL(const ImageGL& image) : Image(image) { } 4189 4190 __CL_EXPLICIT_CONSTRUCTORS ImageGL(const cl_mem& image) : Image(image) { } 4191 4192 ImageGL& operator = (const ImageGL& rhs) 4193 { 4194 if (this != &rhs) { 4195 Image::operator=(rhs); 4196 } 4197 return *this; 4198 } 4199 4200 ImageGL& operator = (const cl_mem& rhs) 4201 { 4202 Image::operator=(rhs); 4203 return *this; 4204 } 4205 }; 4206 #endif // #if defined(CL_VERSION_1_2) 4207 4208 /*! \brief Class interface for cl_sampler. 4209 * 4210 * \note Copies of these objects are shallow, meaning that the copy will refer 4211 * to the same underlying cl_sampler as the original. For details, see 4212 * clRetainSampler() and clReleaseSampler(). 4213 * 4214 * \see cl_sampler 4215 */ 4216 class Sampler : public detail::Wrapper<cl_sampler> 4217 { 4218 public: 4219 /*! \brief Destructor. 4220 * 4221 * This calls clReleaseSampler() on the value held by this instance. 4222 */ 4223 ~Sampler() { } 4224 4225 //! \brief Default constructor - initializes to NULL. 4226 Sampler() { } 4227 4228 /*! \brief Constructs a Sampler in a specified context. 4229 * 4230 * Wraps clCreateSampler(). 4231 */ 4232 Sampler( 4233 const Context& context, 4234 cl_bool normalized_coords, 4235 cl_addressing_mode addressing_mode, 4236 cl_filter_mode filter_mode, 4237 cl_int* err = NULL) 4238 { 4239 cl_int error; 4240 object_ = ::clCreateSampler( 4241 context(), 4242 normalized_coords, 4243 addressing_mode, 4244 filter_mode, 4245 &error); 4246 4247 detail::errHandler(error, __CREATE_SAMPLER_ERR); 4248 if (err != NULL) { 4249 *err = error; 4250 } 4251 } 4252 4253 /*! \brief Copy constructor - performs shallow copy. 4254 * 4255 * This calls clRetainSampler() on the parameter's cl_sampler. 4256 */ 4257 Sampler(const Sampler& sampler) : detail::Wrapper<cl_type>(sampler) { } 4258 4259 /*! \brief Constructor from cl_sampler - takes ownership. 4260 * 4261 * This effectively transfers ownership of a refcount on the cl_sampler 4262 * into the new Sampler object. 4263 */ 4264 Sampler(const cl_sampler& sampler) : detail::Wrapper<cl_type>(sampler) { } 4265 4266 /*! \brief Assignment operator from Sampler. 4267 * 4268 * This calls clRetainSampler() on the parameter and clReleaseSampler() 4269 * on the previous value held by this instance. 4270 */ 4271 Sampler& operator = (const Sampler& rhs) 4272 { 4273 if (this != &rhs) { 4274 detail::Wrapper<cl_type>::operator=(rhs); 4275 } 4276 return *this; 4277 } 4278 4279 /*! \brief Assignment operator from cl_sampler - takes ownership. 4280 * 4281 * This effectively transfers ownership of a refcount on the rhs and calls 4282 * clReleaseSampler() on the value previously held by this instance. 4283 */ 4284 Sampler& operator = (const cl_sampler& rhs) 4285 { 4286 detail::Wrapper<cl_type>::operator=(rhs); 4287 return *this; 4288 } 4289 4290 //! \brief Wrapper for clGetSamplerInfo(). 4291 template <typename T> 4292 cl_int getInfo(cl_sampler_info name, T* param) const 4293 { 4294 return detail::errHandler( 4295 detail::getInfo(&::clGetSamplerInfo, object_, name, param), 4296 __GET_SAMPLER_INFO_ERR); 4297 } 4298 4299 //! \brief Wrapper for clGetSamplerInfo() that returns by value. 4300 template <cl_int name> typename 4301 detail::param_traits<detail::cl_sampler_info, name>::param_type 4302 getInfo(cl_int* err = NULL) const 4303 { 4304 typename detail::param_traits< 4305 detail::cl_sampler_info, name>::param_type param; 4306 cl_int result = getInfo(name, ¶m); 4307 if (err != NULL) { 4308 *err = result; 4309 } 4310 return param; 4311 } 4312 }; 4313 4314 class Program; 4315 class CommandQueue; 4316 class Kernel; 4317 4318 //! \brief Class interface for specifying NDRange values. 4319 class NDRange 4320 { 4321 private: 4322 size_t<3> sizes_; 4323 cl_uint dimensions_; 4324 4325 public: 4326 //! \brief Default constructor - resulting range has zero dimensions. 4327 NDRange() 4328 : dimensions_(0) 4329 { } 4330 4331 //! \brief Constructs one-dimensional range. 4332 NDRange(::size_t size0) 4333 : dimensions_(1) 4334 { 4335 sizes_[0] = size0; 4336 } 4337 4338 //! \brief Constructs two-dimensional range. 4339 NDRange(::size_t size0, ::size_t size1) 4340 : dimensions_(2) 4341 { 4342 sizes_[0] = size0; 4343 sizes_[1] = size1; 4344 } 4345 4346 //! \brief Constructs three-dimensional range. 4347 NDRange(::size_t size0, ::size_t size1, ::size_t size2) 4348 : dimensions_(3) 4349 { 4350 sizes_[0] = size0; 4351 sizes_[1] = size1; 4352 sizes_[2] = size2; 4353 } 4354 4355 /*! \brief Conversion operator to const ::size_t *. 4356 * 4357 * \returns a pointer to the size of the first dimension. 4358 */ 4359 operator const ::size_t*() const { 4360 return (const ::size_t*) sizes_; 4361 } 4362 4363 //! \brief Queries the number of dimensions in the range. 4364 ::size_t dimensions() const { return dimensions_; } 4365 }; 4366 4367 //! \brief A zero-dimensional range. 4368 static const NDRange NullRange; 4369 4370 //! \brief Local address wrapper for use with Kernel::setArg 4371 struct LocalSpaceArg 4372 { 4373 ::size_t size_; 4374 }; 4375 4376 namespace detail { 4377 4378 template <typename T> 4379 struct KernelArgumentHandler 4380 { 4381 static ::size_t size(const T&) { return sizeof(T); } 4382 static T* ptr(T& value) { return &value; } 4383 }; 4384 4385 template <> 4386 struct KernelArgumentHandler<LocalSpaceArg> 4387 { 4388 static ::size_t size(const LocalSpaceArg& value) { return value.size_; } 4389 static void* ptr(LocalSpaceArg&) { return NULL; } 4390 }; 4391 4392 } 4393 //! \endcond 4394 4395 /*! __local 4396 * \brief Helper function for generating LocalSpaceArg objects. 4397 * Deprecated. Replaced with Local. 4398 */ 4399 inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED LocalSpaceArg 4400 __local(::size_t size) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; 4401 inline LocalSpaceArg 4402 __local(::size_t size) 4403 { 4404 LocalSpaceArg ret = { size }; 4405 return ret; 4406 } 4407 4408 /*! Local 4409 * \brief Helper function for generating LocalSpaceArg objects. 4410 */ 4411 inline LocalSpaceArg 4412 Local(::size_t size) 4413 { 4414 LocalSpaceArg ret = { size }; 4415 return ret; 4416 } 4417 4418 //class KernelFunctor; 4419 4420 /*! \brief Class interface for cl_kernel. 4421 * 4422 * \note Copies of these objects are shallow, meaning that the copy will refer 4423 * to the same underlying cl_kernel as the original. For details, see 4424 * clRetainKernel() and clReleaseKernel(). 4425 * 4426 * \see cl_kernel 4427 */ 4428 class Kernel : public detail::Wrapper<cl_kernel> 4429 { 4430 public: 4431 inline Kernel(const Program& program, const char* name, cl_int* err = NULL); 4432 4433 /*! \brief Destructor. 4434 * 4435 * This calls clReleaseKernel() on the value held by this instance. 4436 */ 4437 ~Kernel() { } 4438 4439 //! \brief Default constructor - initializes to NULL. 4440 Kernel() { } 4441 4442 /*! \brief Copy constructor - performs shallow copy. 4443 * 4444 * This calls clRetainKernel() on the parameter's cl_kernel. 4445 */ 4446 Kernel(const Kernel& kernel) : detail::Wrapper<cl_type>(kernel) { } 4447 4448 /*! \brief Constructor from cl_kernel - takes ownership. 4449 * 4450 * This effectively transfers ownership of a refcount on the cl_kernel 4451 * into the new Kernel object. 4452 */ 4453 __CL_EXPLICIT_CONSTRUCTORS Kernel(const cl_kernel& kernel) : detail::Wrapper<cl_type>(kernel) { } 4454 4455 /*! \brief Assignment operator from Kernel. 4456 * 4457 * This calls clRetainKernel() on the parameter and clReleaseKernel() 4458 * on the previous value held by this instance. 4459 */ 4460 Kernel& operator = (const Kernel& rhs) 4461 { 4462 if (this != &rhs) { 4463 detail::Wrapper<cl_type>::operator=(rhs); 4464 } 4465 return *this; 4466 } 4467 4468 /*! \brief Assignment operator from cl_kernel - takes ownership. 4469 * 4470 * This effectively transfers ownership of a refcount on the rhs and calls 4471 * clReleaseKernel() on the value previously held by this instance. 4472 */ 4473 Kernel& operator = (const cl_kernel& rhs) 4474 { 4475 detail::Wrapper<cl_type>::operator=(rhs); 4476 return *this; 4477 } 4478 4479 template <typename T> 4480 cl_int getInfo(cl_kernel_info name, T* param) const 4481 { 4482 return detail::errHandler( 4483 detail::getInfo(&::clGetKernelInfo, object_, name, param), 4484 __GET_KERNEL_INFO_ERR); 4485 } 4486 4487 template <cl_int name> typename 4488 detail::param_traits<detail::cl_kernel_info, name>::param_type 4489 getInfo(cl_int* err = NULL) const 4490 { 4491 typename detail::param_traits< 4492 detail::cl_kernel_info, name>::param_type param; 4493 cl_int result = getInfo(name, ¶m); 4494 if (err != NULL) { 4495 *err = result; 4496 } 4497 return param; 4498 } 4499 4500 #if defined(CL_VERSION_1_2) 4501 template <typename T> 4502 cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const 4503 { 4504 return detail::errHandler( 4505 detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param), 4506 __GET_KERNEL_ARG_INFO_ERR); 4507 } 4508 4509 template <cl_int name> typename 4510 detail::param_traits<detail::cl_kernel_arg_info, name>::param_type 4511 getArgInfo(cl_uint argIndex, cl_int* err = NULL) const 4512 { 4513 typename detail::param_traits< 4514 detail::cl_kernel_arg_info, name>::param_type param; 4515 cl_int result = getArgInfo(argIndex, name, ¶m); 4516 if (err != NULL) { 4517 *err = result; 4518 } 4519 return param; 4520 } 4521 #endif // #if defined(CL_VERSION_1_2) 4522 4523 template <typename T> 4524 cl_int getWorkGroupInfo( 4525 const Device& device, cl_kernel_work_group_info name, T* param) const 4526 { 4527 return detail::errHandler( 4528 detail::getInfo( 4529 &::clGetKernelWorkGroupInfo, object_, device(), name, param), 4530 __GET_KERNEL_WORK_GROUP_INFO_ERR); 4531 } 4532 4533 template <cl_int name> typename 4534 detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type 4535 getWorkGroupInfo(const Device& device, cl_int* err = NULL) const 4536 { 4537 typename detail::param_traits< 4538 detail::cl_kernel_work_group_info, name>::param_type param; 4539 cl_int result = getWorkGroupInfo(device, name, ¶m); 4540 if (err != NULL) { 4541 *err = result; 4542 } 4543 return param; 4544 } 4545 4546 template <typename T> 4547 cl_int setArg(cl_uint index, T value) 4548 { 4549 return detail::errHandler( 4550 ::clSetKernelArg( 4551 object_, 4552 index, 4553 detail::KernelArgumentHandler<T>::size(value), 4554 detail::KernelArgumentHandler<T>::ptr(value)), 4555 __SET_KERNEL_ARGS_ERR); 4556 } 4557 4558 cl_int setArg(cl_uint index, ::size_t size, void* argPtr) 4559 { 4560 return detail::errHandler( 4561 ::clSetKernelArg(object_, index, size, argPtr), 4562 __SET_KERNEL_ARGS_ERR); 4563 } 4564 }; 4565 4566 /*! \class Program 4567 * \brief Program interface that implements cl_program. 4568 */ 4569 class Program : public detail::Wrapper<cl_program> 4570 { 4571 public: 4572 typedef VECTOR_CLASS<std::pair<const void*, ::size_t> > Binaries; 4573 typedef VECTOR_CLASS<std::pair<const char*, ::size_t> > Sources; 4574 4575 Program( 4576 const STRING_CLASS& source, 4577 cl_int* err = NULL) 4578 { 4579 cl_int error; 4580 4581 const char * strings = source.c_str(); 4582 const ::size_t length = source.size(); 4583 4584 Context context = Context::getDefault(err); 4585 4586 object_ = ::clCreateProgramWithSource( 4587 context(), (cl_uint)1, &strings, &length, &error); 4588 4589 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); 4590 4591 if (error == CL_SUCCESS) { 4592 4593 error = ::clBuildProgram( 4594 object_, 4595 0, 4596 NULL, 4597 "", 4598 NULL, 4599 NULL); 4600 4601 detail::errHandler(error, __BUILD_PROGRAM_ERR); 4602 } 4603 4604 if (err != NULL) { 4605 *err = error; 4606 } 4607 } 4608 4609 Program( 4610 const STRING_CLASS& source, 4611 bool build, 4612 cl_int* err = NULL) 4613 { 4614 cl_int error; 4615 4616 const char * strings = source.c_str(); 4617 const ::size_t length = source.size(); 4618 4619 Context context = Context::getDefault(err); 4620 4621 object_ = ::clCreateProgramWithSource( 4622 context(), (cl_uint)1, &strings, &length, &error); 4623 4624 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); 4625 4626 if (error == CL_SUCCESS && build) { 4627 4628 error = ::clBuildProgram( 4629 object_, 4630 0, 4631 NULL, 4632 "", 4633 NULL, 4634 NULL); 4635 4636 detail::errHandler(error, __BUILD_PROGRAM_ERR); 4637 } 4638 4639 if (err != NULL) { 4640 *err = error; 4641 } 4642 } 4643 4644 Program( 4645 const Context& context, 4646 const STRING_CLASS& source, 4647 bool build = false, 4648 cl_int* err = NULL) 4649 { 4650 cl_int error; 4651 4652 const char * strings = source.c_str(); 4653 const ::size_t length = source.size(); 4654 4655 object_ = ::clCreateProgramWithSource( 4656 context(), (cl_uint)1, &strings, &length, &error); 4657 4658 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); 4659 4660 if (error == CL_SUCCESS && build) { 4661 4662 error = ::clBuildProgram( 4663 object_, 4664 0, 4665 NULL, 4666 "", 4667 NULL, 4668 NULL); 4669 4670 detail::errHandler(error, __BUILD_PROGRAM_ERR); 4671 } 4672 4673 if (err != NULL) { 4674 *err = error; 4675 } 4676 } 4677 4678 Program( 4679 const Context& context, 4680 const Sources& sources, 4681 cl_int* err = NULL) 4682 { 4683 cl_int error; 4684 4685 const ::size_t n = (::size_t)sources.size(); 4686 ::size_t* lengths = (::size_t*) alloca(n * sizeof(::size_t)); 4687 const char** strings = (const char**) alloca(n * sizeof(const char*)); 4688 4689 for (::size_t i = 0; i < n; ++i) { 4690 strings[i] = sources[(int)i].first; 4691 lengths[i] = sources[(int)i].second; 4692 } 4693 4694 object_ = ::clCreateProgramWithSource( 4695 context(), (cl_uint)n, strings, lengths, &error); 4696 4697 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); 4698 if (err != NULL) { 4699 *err = error; 4700 } 4701 } 4702 4703 /** 4704 * Construct a program object from a list of devices and a per-device list of binaries. 4705 * \param context A valid OpenCL context in which to construct the program. 4706 * \param devices A vector of OpenCL device objects for which the program will be created. 4707 * \param binaries A vector of pairs of a pointer to a binary object and its length. 4708 * \param binaryStatus An optional vector that on completion will be resized to 4709 * match the size of binaries and filled with values to specify if each binary 4710 * was successfully loaded. 4711 * Set to CL_SUCCESS if the binary was successfully loaded. 4712 * Set to CL_INVALID_VALUE if the length is 0 or the binary pointer is NULL. 4713 * Set to CL_INVALID_BINARY if the binary provided is not valid for the matching device. 4714 * \param err if non-NULL will be set to CL_SUCCESS on successful operation or one of the following errors: 4715 * CL_INVALID_CONTEXT if context is not a valid context. 4716 * CL_INVALID_VALUE if the length of devices is zero; or if the length of binaries does not match the length of devices; 4717 * or if any entry in binaries is NULL or has length 0. 4718 * CL_INVALID_DEVICE if OpenCL devices listed in devices are not in the list of devices associated with context. 4719 * CL_INVALID_BINARY if an invalid program binary was encountered for any device. binaryStatus will return specific status for each device. 4720 * CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host. 4721 */ 4722 Program( 4723 const Context& context, 4724 const VECTOR_CLASS<Device>& devices, 4725 const Binaries& binaries, 4726 VECTOR_CLASS<cl_int>* binaryStatus = NULL, 4727 cl_int* err = NULL) 4728 { 4729 cl_int error; 4730 4731 const ::size_t numDevices = devices.size(); 4732 4733 // Catch size mismatch early and return 4734 if(binaries.size() != numDevices) { 4735 error = CL_INVALID_VALUE; 4736 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR); 4737 if (err != NULL) { 4738 *err = error; 4739 } 4740 return; 4741 } 4742 4743 ::size_t* lengths = (::size_t*) alloca(numDevices * sizeof(::size_t)); 4744 const unsigned char** images = (const unsigned char**) alloca(numDevices * sizeof(const unsigned char**)); 4745 4746 for (::size_t i = 0; i < numDevices; ++i) { 4747 images[i] = (const unsigned char*)binaries[i].first; 4748 lengths[i] = binaries[(int)i].second; 4749 } 4750 4751 cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); 4752 for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { 4753 deviceIDs[deviceIndex] = (devices[deviceIndex])(); 4754 } 4755 4756 if(binaryStatus) { 4757 binaryStatus->resize(numDevices); 4758 } 4759 4760 object_ = ::clCreateProgramWithBinary( 4761 context(), (cl_uint) devices.size(), 4762 deviceIDs, 4763 lengths, images, binaryStatus != NULL 4764 ? &binaryStatus->front() 4765 : NULL, &error); 4766 4767 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR); 4768 if (err != NULL) { 4769 *err = error; 4770 } 4771 } 4772 4773 4774 #if defined(CL_VERSION_1_2) 4775 /** 4776 * Create program using builtin kernels. 4777 * \param kernelNames Semi-colon separated list of builtin kernel names 4778 */ 4779 Program( 4780 const Context& context, 4781 const VECTOR_CLASS<Device>& devices, 4782 const STRING_CLASS& kernelNames, 4783 cl_int* err = NULL) 4784 { 4785 cl_int error; 4786 4787 4788 ::size_t numDevices = devices.size(); 4789 cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); 4790 for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { 4791 deviceIDs[deviceIndex] = (devices[deviceIndex])(); 4792 } 4793 4794 object_ = ::clCreateProgramWithBuiltInKernels( 4795 context(), 4796 (cl_uint) devices.size(), 4797 deviceIDs, 4798 kernelNames.c_str(), 4799 &error); 4800 4801 detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR); 4802 if (err != NULL) { 4803 *err = error; 4804 } 4805 } 4806 #endif // #if defined(CL_VERSION_1_2) 4807 4808 Program() { } 4809 4810 Program(const Program& program) : detail::Wrapper<cl_type>(program) { } 4811 4812 __CL_EXPLICIT_CONSTRUCTORS Program(const cl_program& program) : detail::Wrapper<cl_type>(program) { } 4813 4814 Program& operator = (const Program& rhs) 4815 { 4816 if (this != &rhs) { 4817 detail::Wrapper<cl_type>::operator=(rhs); 4818 } 4819 return *this; 4820 } 4821 4822 Program& operator = (const cl_program& rhs) 4823 { 4824 detail::Wrapper<cl_type>::operator=(rhs); 4825 return *this; 4826 } 4827 4828 cl_int build( 4829 const VECTOR_CLASS<Device>& devices, 4830 const char* options = NULL, 4831 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, 4832 void* data = NULL) const 4833 { 4834 ::size_t numDevices = devices.size(); 4835 cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); 4836 for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { 4837 deviceIDs[deviceIndex] = (devices[deviceIndex])(); 4838 } 4839 4840 return detail::errHandler( 4841 ::clBuildProgram( 4842 object_, 4843 (cl_uint) 4844 devices.size(), 4845 deviceIDs, 4846 options, 4847 notifyFptr, 4848 data), 4849 __BUILD_PROGRAM_ERR); 4850 } 4851 4852 cl_int build( 4853 const char* options = NULL, 4854 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, 4855 void* data = NULL) const 4856 { 4857 return detail::errHandler( 4858 ::clBuildProgram( 4859 object_, 4860 0, 4861 NULL, 4862 options, 4863 notifyFptr, 4864 data), 4865 __BUILD_PROGRAM_ERR); 4866 } 4867 4868 #if defined(CL_VERSION_1_2) 4869 cl_int compile( 4870 const char* options = NULL, 4871 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, 4872 void* data = NULL) const 4873 { 4874 return detail::errHandler( 4875 ::clCompileProgram( 4876 object_, 4877 0, 4878 NULL, 4879 options, 4880 0, 4881 NULL, 4882 NULL, 4883 notifyFptr, 4884 data), 4885 __COMPILE_PROGRAM_ERR); 4886 } 4887 #endif 4888 4889 template <typename T> 4890 cl_int getInfo(cl_program_info name, T* param) const 4891 { 4892 return detail::errHandler( 4893 detail::getInfo(&::clGetProgramInfo, object_, name, param), 4894 __GET_PROGRAM_INFO_ERR); 4895 } 4896 4897 template <cl_int name> typename 4898 detail::param_traits<detail::cl_program_info, name>::param_type 4899 getInfo(cl_int* err = NULL) const 4900 { 4901 typename detail::param_traits< 4902 detail::cl_program_info, name>::param_type param; 4903 cl_int result = getInfo(name, ¶m); 4904 if (err != NULL) { 4905 *err = result; 4906 } 4907 return param; 4908 } 4909 4910 template <typename T> 4911 cl_int getBuildInfo( 4912 const Device& device, cl_program_build_info name, T* param) const 4913 { 4914 return detail::errHandler( 4915 detail::getInfo( 4916 &::clGetProgramBuildInfo, object_, device(), name, param), 4917 __GET_PROGRAM_BUILD_INFO_ERR); 4918 } 4919 4920 template <cl_int name> typename 4921 detail::param_traits<detail::cl_program_build_info, name>::param_type 4922 getBuildInfo(const Device& device, cl_int* err = NULL) const 4923 { 4924 typename detail::param_traits< 4925 detail::cl_program_build_info, name>::param_type param; 4926 cl_int result = getBuildInfo(device, name, ¶m); 4927 if (err != NULL) { 4928 *err = result; 4929 } 4930 return param; 4931 } 4932 4933 cl_int createKernels(VECTOR_CLASS<Kernel>* kernels) 4934 { 4935 cl_uint numKernels; 4936 cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels); 4937 if (err != CL_SUCCESS) { 4938 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR); 4939 } 4940 4941 Kernel* value = (Kernel*) alloca(numKernels * sizeof(Kernel)); 4942 err = ::clCreateKernelsInProgram( 4943 object_, numKernels, (cl_kernel*) value, NULL); 4944 if (err != CL_SUCCESS) { 4945 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR); 4946 } 4947 4948 kernels->assign(&value[0], &value[numKernels]); 4949 return CL_SUCCESS; 4950 } 4951 }; 4952 4953 #if defined(CL_VERSION_1_2) 4954 inline Program linkProgram( 4955 Program input1, 4956 Program input2, 4957 const char* options = NULL, 4958 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, 4959 void* data = NULL, 4960 cl_int* err = NULL) 4961 { 4962 cl_int err_local = CL_SUCCESS; 4963 4964 cl_program programs[2] = { input1(), input2() }; 4965 4966 Context ctx = input1.getInfo<CL_PROGRAM_CONTEXT>(); 4967 4968 cl_program prog = ::clLinkProgram( 4969 ctx(), 4970 0, 4971 NULL, 4972 options, 4973 2, 4974 programs, 4975 notifyFptr, 4976 data, 4977 &err_local); 4978 4979 detail::errHandler(err_local,__COMPILE_PROGRAM_ERR); 4980 if (err != NULL) { 4981 *err = err_local; 4982 } 4983 4984 return Program(prog); 4985 } 4986 4987 inline Program linkProgram( 4988 VECTOR_CLASS<Program> inputPrograms, 4989 const char* options = NULL, 4990 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, 4991 void* data = NULL, 4992 cl_int* err = NULL) 4993 { 4994 cl_int err_local = CL_SUCCESS; 4995 4996 cl_program * programs = (cl_program*) alloca(inputPrograms.size() * sizeof(cl_program)); 4997 4998 if (programs != NULL) { 4999 for (unsigned int i = 0; i < inputPrograms.size(); i++) { 5000 programs[i] = inputPrograms[i](); 5001 } 5002 } 5003 5004 cl_program prog = ::clLinkProgram( 5005 Context::getDefault()(), 5006 0, 5007 NULL, 5008 options, 5009 (cl_uint)inputPrograms.size(), 5010 programs, 5011 notifyFptr, 5012 data, 5013 &err_local); 5014 5015 detail::errHandler(err_local,__COMPILE_PROGRAM_ERR); 5016 if (err != NULL) { 5017 *err = err_local; 5018 } 5019 5020 return Program(prog); 5021 } 5022 #endif 5023 5024 template<> 5025 inline VECTOR_CLASS<char *> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err) const 5026 { 5027 VECTOR_CLASS< ::size_t> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>(); 5028 VECTOR_CLASS<char *> binaries; 5029 for (VECTOR_CLASS< ::size_t>::iterator s = sizes.begin(); s != sizes.end(); ++s) 5030 { 5031 char *ptr = NULL; 5032 if (*s != 0) 5033 ptr = new char[*s]; 5034 binaries.push_back(ptr); 5035 } 5036 5037 cl_int result = getInfo(CL_PROGRAM_BINARIES, &binaries); 5038 if (err != NULL) { 5039 *err = result; 5040 } 5041 return binaries; 5042 } 5043 5044 inline Kernel::Kernel(const Program& program, const char* name, cl_int* err) 5045 { 5046 cl_int error; 5047 5048 object_ = ::clCreateKernel(program(), name, &error); 5049 detail::errHandler(error, __CREATE_KERNEL_ERR); 5050 5051 if (err != NULL) { 5052 *err = error; 5053 } 5054 5055 } 5056 5057 /*! \class CommandQueue 5058 * \brief CommandQueue interface for cl_command_queue. 5059 */ 5060 class CommandQueue : public detail::Wrapper<cl_command_queue> 5061 { 5062 private: 5063 static volatile int default_initialized_; 5064 static CommandQueue default_; 5065 static volatile cl_int default_error_; 5066 public: 5067 CommandQueue( 5068 cl_command_queue_properties properties, 5069 cl_int* err = NULL) 5070 { 5071 cl_int error; 5072 5073 Context context = Context::getDefault(&error); 5074 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); 5075 5076 if (error != CL_SUCCESS) { 5077 if (err != NULL) { 5078 *err = error; 5079 } 5080 } 5081 else { 5082 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0]; 5083 5084 object_ = ::clCreateCommandQueue( 5085 context(), device(), properties, &error); 5086 5087 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); 5088 if (err != NULL) { 5089 *err = error; 5090 } 5091 } 5092 } 5093 5094 CommandQueue( 5095 const Context& context, 5096 const Device& device, 5097 cl_command_queue_properties properties = 0, 5098 cl_int* err = NULL) 5099 { 5100 cl_int error; 5101 object_ = ::clCreateCommandQueue( 5102 context(), device(), properties, &error); 5103 5104 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); 5105 if (err != NULL) { 5106 *err = error; 5107 } 5108 } 5109 5110 static CommandQueue getDefault(cl_int * err = NULL) 5111 { 5112 int state = detail::compare_exchange( 5113 &default_initialized_, 5114 __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED); 5115 5116 if (state & __DEFAULT_INITIALIZED) { 5117 if (err != NULL) { 5118 *err = default_error_; 5119 } 5120 return default_; 5121 } 5122 5123 if (state & __DEFAULT_BEING_INITIALIZED) { 5124 // Assume writes will propagate eventually... 5125 while(default_initialized_ != __DEFAULT_INITIALIZED) { 5126 detail::fence(); 5127 } 5128 5129 if (err != NULL) { 5130 *err = default_error_; 5131 } 5132 return default_; 5133 } 5134 5135 cl_int error; 5136 5137 Context context = Context::getDefault(&error); 5138 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); 5139 5140 if (error != CL_SUCCESS) { 5141 if (err != NULL) { 5142 *err = error; 5143 } 5144 } 5145 else { 5146 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0]; 5147 5148 default_ = CommandQueue(context, device, 0, &error); 5149 5150 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); 5151 if (err != NULL) { 5152 *err = error; 5153 } 5154 } 5155 5156 detail::fence(); 5157 5158 default_error_ = error; 5159 // Assume writes will propagate eventually... 5160 default_initialized_ = __DEFAULT_INITIALIZED; 5161 5162 detail::fence(); 5163 5164 if (err != NULL) { 5165 *err = default_error_; 5166 } 5167 return default_; 5168 5169 } 5170 5171 CommandQueue() { } 5172 5173 CommandQueue(const CommandQueue& commandQueue) : detail::Wrapper<cl_type>(commandQueue) { } 5174 5175 CommandQueue(const cl_command_queue& commandQueue) : detail::Wrapper<cl_type>(commandQueue) { } 5176 5177 CommandQueue& operator = (const CommandQueue& rhs) 5178 { 5179 if (this != &rhs) { 5180 detail::Wrapper<cl_type>::operator=(rhs); 5181 } 5182 return *this; 5183 } 5184 5185 CommandQueue& operator = (const cl_command_queue& rhs) 5186 { 5187 detail::Wrapper<cl_type>::operator=(rhs); 5188 return *this; 5189 } 5190 5191 template <typename T> 5192 cl_int getInfo(cl_command_queue_info name, T* param) const 5193 { 5194 return detail::errHandler( 5195 detail::getInfo( 5196 &::clGetCommandQueueInfo, object_, name, param), 5197 __GET_COMMAND_QUEUE_INFO_ERR); 5198 } 5199 5200 template <cl_int name> typename 5201 detail::param_traits<detail::cl_command_queue_info, name>::param_type 5202 getInfo(cl_int* err = NULL) const 5203 { 5204 typename detail::param_traits< 5205 detail::cl_command_queue_info, name>::param_type param; 5206 cl_int result = getInfo(name, ¶m); 5207 if (err != NULL) { 5208 *err = result; 5209 } 5210 return param; 5211 } 5212 5213 cl_int enqueueReadBuffer( 5214 const Buffer& buffer, 5215 cl_bool blocking, 5216 ::size_t offset, 5217 ::size_t size, 5218 void* ptr, 5219 const VECTOR_CLASS<Event>* events = NULL, 5220 Event* event = NULL) const 5221 { 5222 cl_event tmp; 5223 cl_int err = detail::errHandler( 5224 ::clEnqueueReadBuffer( 5225 object_, buffer(), blocking, offset, size, 5226 ptr, 5227 (events != NULL) ? (cl_uint) events->size() : 0, 5228 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5229 (event != NULL) ? &tmp : NULL), 5230 __ENQUEUE_READ_BUFFER_ERR); 5231 5232 if (event != NULL && err == CL_SUCCESS) 5233 *event = tmp; 5234 5235 return err; 5236 } 5237 5238 cl_int enqueueWriteBuffer( 5239 const Buffer& buffer, 5240 cl_bool blocking, 5241 ::size_t offset, 5242 ::size_t size, 5243 const void* ptr, 5244 const VECTOR_CLASS<Event>* events = NULL, 5245 Event* event = NULL) const 5246 { 5247 cl_event tmp; 5248 cl_int err = detail::errHandler( 5249 ::clEnqueueWriteBuffer( 5250 object_, buffer(), blocking, offset, size, 5251 ptr, 5252 (events != NULL) ? (cl_uint) events->size() : 0, 5253 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5254 (event != NULL) ? &tmp : NULL), 5255 __ENQUEUE_WRITE_BUFFER_ERR); 5256 5257 if (event != NULL && err == CL_SUCCESS) 5258 *event = tmp; 5259 5260 return err; 5261 } 5262 5263 cl_int enqueueCopyBuffer( 5264 const Buffer& src, 5265 const Buffer& dst, 5266 ::size_t src_offset, 5267 ::size_t dst_offset, 5268 ::size_t size, 5269 const VECTOR_CLASS<Event>* events = NULL, 5270 Event* event = NULL) const 5271 { 5272 cl_event tmp; 5273 cl_int err = detail::errHandler( 5274 ::clEnqueueCopyBuffer( 5275 object_, src(), dst(), src_offset, dst_offset, size, 5276 (events != NULL) ? (cl_uint) events->size() : 0, 5277 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5278 (event != NULL) ? &tmp : NULL), 5279 __ENQEUE_COPY_BUFFER_ERR); 5280 5281 if (event != NULL && err == CL_SUCCESS) 5282 *event = tmp; 5283 5284 return err; 5285 } 5286 5287 cl_int enqueueReadBufferRect( 5288 const Buffer& buffer, 5289 cl_bool blocking, 5290 const size_t<3>& buffer_offset, 5291 const size_t<3>& host_offset, 5292 const size_t<3>& region, 5293 ::size_t buffer_row_pitch, 5294 ::size_t buffer_slice_pitch, 5295 ::size_t host_row_pitch, 5296 ::size_t host_slice_pitch, 5297 void *ptr, 5298 const VECTOR_CLASS<Event>* events = NULL, 5299 Event* event = NULL) const 5300 { 5301 cl_event tmp; 5302 cl_int err = detail::errHandler( 5303 ::clEnqueueReadBufferRect( 5304 object_, 5305 buffer(), 5306 blocking, 5307 (const ::size_t *)buffer_offset, 5308 (const ::size_t *)host_offset, 5309 (const ::size_t *)region, 5310 buffer_row_pitch, 5311 buffer_slice_pitch, 5312 host_row_pitch, 5313 host_slice_pitch, 5314 ptr, 5315 (events != NULL) ? (cl_uint) events->size() : 0, 5316 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5317 (event != NULL) ? &tmp : NULL), 5318 __ENQUEUE_READ_BUFFER_RECT_ERR); 5319 5320 if (event != NULL && err == CL_SUCCESS) 5321 *event = tmp; 5322 5323 return err; 5324 } 5325 5326 cl_int enqueueWriteBufferRect( 5327 const Buffer& buffer, 5328 cl_bool blocking, 5329 const size_t<3>& buffer_offset, 5330 const size_t<3>& host_offset, 5331 const size_t<3>& region, 5332 ::size_t buffer_row_pitch, 5333 ::size_t buffer_slice_pitch, 5334 ::size_t host_row_pitch, 5335 ::size_t host_slice_pitch, 5336 void *ptr, 5337 const VECTOR_CLASS<Event>* events = NULL, 5338 Event* event = NULL) const 5339 { 5340 cl_event tmp; 5341 cl_int err = detail::errHandler( 5342 ::clEnqueueWriteBufferRect( 5343 object_, 5344 buffer(), 5345 blocking, 5346 (const ::size_t *)buffer_offset, 5347 (const ::size_t *)host_offset, 5348 (const ::size_t *)region, 5349 buffer_row_pitch, 5350 buffer_slice_pitch, 5351 host_row_pitch, 5352 host_slice_pitch, 5353 ptr, 5354 (events != NULL) ? (cl_uint) events->size() : 0, 5355 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5356 (event != NULL) ? &tmp : NULL), 5357 __ENQUEUE_WRITE_BUFFER_RECT_ERR); 5358 5359 if (event != NULL && err == CL_SUCCESS) 5360 *event = tmp; 5361 5362 return err; 5363 } 5364 5365 cl_int enqueueCopyBufferRect( 5366 const Buffer& src, 5367 const Buffer& dst, 5368 const size_t<3>& src_origin, 5369 const size_t<3>& dst_origin, 5370 const size_t<3>& region, 5371 ::size_t src_row_pitch, 5372 ::size_t src_slice_pitch, 5373 ::size_t dst_row_pitch, 5374 ::size_t dst_slice_pitch, 5375 const VECTOR_CLASS<Event>* events = NULL, 5376 Event* event = NULL) const 5377 { 5378 cl_event tmp; 5379 cl_int err = detail::errHandler( 5380 ::clEnqueueCopyBufferRect( 5381 object_, 5382 src(), 5383 dst(), 5384 (const ::size_t *)src_origin, 5385 (const ::size_t *)dst_origin, 5386 (const ::size_t *)region, 5387 src_row_pitch, 5388 src_slice_pitch, 5389 dst_row_pitch, 5390 dst_slice_pitch, 5391 (events != NULL) ? (cl_uint) events->size() : 0, 5392 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5393 (event != NULL) ? &tmp : NULL), 5394 __ENQEUE_COPY_BUFFER_RECT_ERR); 5395 5396 if (event != NULL && err == CL_SUCCESS) 5397 *event = tmp; 5398 5399 return err; 5400 } 5401 5402 #if defined(CL_VERSION_1_2) 5403 /** 5404 * Enqueue a command to fill a buffer object with a pattern 5405 * of a given size. The pattern is specified a as vector. 5406 * \tparam PatternType The datatype of the pattern field. 5407 * The pattern type must be an accepted OpenCL data type. 5408 */ 5409 template<typename PatternType> 5410 cl_int enqueueFillBuffer( 5411 const Buffer& buffer, 5412 PatternType pattern, 5413 ::size_t offset, 5414 ::size_t size, 5415 const VECTOR_CLASS<Event>* events = NULL, 5416 Event* event = NULL) const 5417 { 5418 cl_event tmp; 5419 cl_int err = detail::errHandler( 5420 ::clEnqueueFillBuffer( 5421 object_, 5422 buffer(), 5423 static_cast<void*>(&pattern), 5424 sizeof(PatternType), 5425 offset, 5426 size, 5427 (events != NULL) ? (cl_uint) events->size() : 0, 5428 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5429 (event != NULL) ? &tmp : NULL), 5430 __ENQUEUE_FILL_BUFFER_ERR); 5431 5432 if (event != NULL && err == CL_SUCCESS) 5433 *event = tmp; 5434 5435 return err; 5436 } 5437 #endif // #if defined(CL_VERSION_1_2) 5438 5439 cl_int enqueueReadImage( 5440 const Image& image, 5441 cl_bool blocking, 5442 const size_t<3>& origin, 5443 const size_t<3>& region, 5444 ::size_t row_pitch, 5445 ::size_t slice_pitch, 5446 void* ptr, 5447 const VECTOR_CLASS<Event>* events = NULL, 5448 Event* event = NULL) const 5449 { 5450 cl_event tmp; 5451 cl_int err = detail::errHandler( 5452 ::clEnqueueReadImage( 5453 object_, image(), blocking, (const ::size_t *) origin, 5454 (const ::size_t *) region, row_pitch, slice_pitch, ptr, 5455 (events != NULL) ? (cl_uint) events->size() : 0, 5456 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5457 (event != NULL) ? &tmp : NULL), 5458 __ENQUEUE_READ_IMAGE_ERR); 5459 5460 if (event != NULL && err == CL_SUCCESS) 5461 *event = tmp; 5462 5463 return err; 5464 } 5465 5466 cl_int enqueueWriteImage( 5467 const Image& image, 5468 cl_bool blocking, 5469 const size_t<3>& origin, 5470 const size_t<3>& region, 5471 ::size_t row_pitch, 5472 ::size_t slice_pitch, 5473 void* ptr, 5474 const VECTOR_CLASS<Event>* events = NULL, 5475 Event* event = NULL) const 5476 { 5477 cl_event tmp; 5478 cl_int err = detail::errHandler( 5479 ::clEnqueueWriteImage( 5480 object_, image(), blocking, (const ::size_t *) origin, 5481 (const ::size_t *) region, row_pitch, slice_pitch, ptr, 5482 (events != NULL) ? (cl_uint) events->size() : 0, 5483 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5484 (event != NULL) ? &tmp : NULL), 5485 __ENQUEUE_WRITE_IMAGE_ERR); 5486 5487 if (event != NULL && err == CL_SUCCESS) 5488 *event = tmp; 5489 5490 return err; 5491 } 5492 5493 cl_int enqueueCopyImage( 5494 const Image& src, 5495 const Image& dst, 5496 const size_t<3>& src_origin, 5497 const size_t<3>& dst_origin, 5498 const size_t<3>& region, 5499 const VECTOR_CLASS<Event>* events = NULL, 5500 Event* event = NULL) const 5501 { 5502 cl_event tmp; 5503 cl_int err = detail::errHandler( 5504 ::clEnqueueCopyImage( 5505 object_, src(), dst(), (const ::size_t *) src_origin, 5506 (const ::size_t *)dst_origin, (const ::size_t *) region, 5507 (events != NULL) ? (cl_uint) events->size() : 0, 5508 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5509 (event != NULL) ? &tmp : NULL), 5510 __ENQUEUE_COPY_IMAGE_ERR); 5511 5512 if (event != NULL && err == CL_SUCCESS) 5513 *event = tmp; 5514 5515 return err; 5516 } 5517 5518 #if defined(CL_VERSION_1_2) 5519 /** 5520 * Enqueue a command to fill an image object with a specified color. 5521 * \param fillColor is the color to use to fill the image. 5522 * This is a four component RGBA floating-point color value if 5523 * the image channel data type is not an unnormalized signed or 5524 * unsigned data type. 5525 */ 5526 cl_int enqueueFillImage( 5527 const Image& image, 5528 cl_float4 fillColor, 5529 const size_t<3>& origin, 5530 const size_t<3>& region, 5531 const VECTOR_CLASS<Event>* events = NULL, 5532 Event* event = NULL) const 5533 { 5534 cl_event tmp; 5535 cl_int err = detail::errHandler( 5536 ::clEnqueueFillImage( 5537 object_, 5538 image(), 5539 static_cast<void*>(&fillColor), 5540 (const ::size_t *) origin, 5541 (const ::size_t *) region, 5542 (events != NULL) ? (cl_uint) events->size() : 0, 5543 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5544 (event != NULL) ? &tmp : NULL), 5545 __ENQUEUE_FILL_IMAGE_ERR); 5546 5547 if (event != NULL && err == CL_SUCCESS) 5548 *event = tmp; 5549 5550 return err; 5551 } 5552 5553 /** 5554 * Enqueue a command to fill an image object with a specified color. 5555 * \param fillColor is the color to use to fill the image. 5556 * This is a four component RGBA signed integer color value if 5557 * the image channel data type is an unnormalized signed integer 5558 * type. 5559 */ 5560 cl_int enqueueFillImage( 5561 const Image& image, 5562 cl_int4 fillColor, 5563 const size_t<3>& origin, 5564 const size_t<3>& region, 5565 const VECTOR_CLASS<Event>* events = NULL, 5566 Event* event = NULL) const 5567 { 5568 cl_event tmp; 5569 cl_int err = detail::errHandler( 5570 ::clEnqueueFillImage( 5571 object_, 5572 image(), 5573 static_cast<void*>(&fillColor), 5574 (const ::size_t *) origin, 5575 (const ::size_t *) region, 5576 (events != NULL) ? (cl_uint) events->size() : 0, 5577 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5578 (event != NULL) ? &tmp : NULL), 5579 __ENQUEUE_FILL_IMAGE_ERR); 5580 5581 if (event != NULL && err == CL_SUCCESS) 5582 *event = tmp; 5583 5584 return err; 5585 } 5586 5587 /** 5588 * Enqueue a command to fill an image object with a specified color. 5589 * \param fillColor is the color to use to fill the image. 5590 * This is a four component RGBA unsigned integer color value if 5591 * the image channel data type is an unnormalized unsigned integer 5592 * type. 5593 */ 5594 cl_int enqueueFillImage( 5595 const Image& image, 5596 cl_uint4 fillColor, 5597 const size_t<3>& origin, 5598 const size_t<3>& region, 5599 const VECTOR_CLASS<Event>* events = NULL, 5600 Event* event = NULL) const 5601 { 5602 cl_event tmp; 5603 cl_int err = detail::errHandler( 5604 ::clEnqueueFillImage( 5605 object_, 5606 image(), 5607 static_cast<void*>(&fillColor), 5608 (const ::size_t *) origin, 5609 (const ::size_t *) region, 5610 (events != NULL) ? (cl_uint) events->size() : 0, 5611 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5612 (event != NULL) ? &tmp : NULL), 5613 __ENQUEUE_FILL_IMAGE_ERR); 5614 5615 if (event != NULL && err == CL_SUCCESS) 5616 *event = tmp; 5617 5618 return err; 5619 } 5620 #endif // #if defined(CL_VERSION_1_2) 5621 5622 cl_int enqueueCopyImageToBuffer( 5623 const Image& src, 5624 const Buffer& dst, 5625 const size_t<3>& src_origin, 5626 const size_t<3>& region, 5627 ::size_t dst_offset, 5628 const VECTOR_CLASS<Event>* events = NULL, 5629 Event* event = NULL) const 5630 { 5631 cl_event tmp; 5632 cl_int err = detail::errHandler( 5633 ::clEnqueueCopyImageToBuffer( 5634 object_, src(), dst(), (const ::size_t *) src_origin, 5635 (const ::size_t *) region, dst_offset, 5636 (events != NULL) ? (cl_uint) events->size() : 0, 5637 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5638 (event != NULL) ? &tmp : NULL), 5639 __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR); 5640 5641 if (event != NULL && err == CL_SUCCESS) 5642 *event = tmp; 5643 5644 return err; 5645 } 5646 5647 cl_int enqueueCopyBufferToImage( 5648 const Buffer& src, 5649 const Image& dst, 5650 ::size_t src_offset, 5651 const size_t<3>& dst_origin, 5652 const size_t<3>& region, 5653 const VECTOR_CLASS<Event>* events = NULL, 5654 Event* event = NULL) const 5655 { 5656 cl_event tmp; 5657 cl_int err = detail::errHandler( 5658 ::clEnqueueCopyBufferToImage( 5659 object_, src(), dst(), src_offset, 5660 (const ::size_t *) dst_origin, (const ::size_t *) region, 5661 (events != NULL) ? (cl_uint) events->size() : 0, 5662 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5663 (event != NULL) ? &tmp : NULL), 5664 __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR); 5665 5666 if (event != NULL && err == CL_SUCCESS) 5667 *event = tmp; 5668 5669 return err; 5670 } 5671 5672 void* enqueueMapBuffer( 5673 const Buffer& buffer, 5674 cl_bool blocking, 5675 cl_map_flags flags, 5676 ::size_t offset, 5677 ::size_t size, 5678 const VECTOR_CLASS<Event>* events = NULL, 5679 Event* event = NULL, 5680 cl_int* err = NULL) const 5681 { 5682 cl_int error; 5683 void * result = ::clEnqueueMapBuffer( 5684 object_, buffer(), blocking, flags, offset, size, 5685 (events != NULL) ? (cl_uint) events->size() : 0, 5686 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5687 (cl_event*) event, 5688 &error); 5689 5690 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); 5691 if (err != NULL) { 5692 *err = error; 5693 } 5694 return result; 5695 } 5696 5697 void* enqueueMapImage( 5698 const Image& buffer, 5699 cl_bool blocking, 5700 cl_map_flags flags, 5701 const size_t<3>& origin, 5702 const size_t<3>& region, 5703 ::size_t * row_pitch, 5704 ::size_t * slice_pitch, 5705 const VECTOR_CLASS<Event>* events = NULL, 5706 Event* event = NULL, 5707 cl_int* err = NULL) const 5708 { 5709 cl_int error; 5710 void * result = ::clEnqueueMapImage( 5711 object_, buffer(), blocking, flags, 5712 (const ::size_t *) origin, (const ::size_t *) region, 5713 row_pitch, slice_pitch, 5714 (events != NULL) ? (cl_uint) events->size() : 0, 5715 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5716 (cl_event*) event, 5717 &error); 5718 5719 detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR); 5720 if (err != NULL) { 5721 *err = error; 5722 } 5723 return result; 5724 } 5725 5726 cl_int enqueueUnmapMemObject( 5727 const Memory& memory, 5728 void* mapped_ptr, 5729 const VECTOR_CLASS<Event>* events = NULL, 5730 Event* event = NULL) const 5731 { 5732 cl_event tmp; 5733 cl_int err = detail::errHandler( 5734 ::clEnqueueUnmapMemObject( 5735 object_, memory(), mapped_ptr, 5736 (events != NULL) ? (cl_uint) events->size() : 0, 5737 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5738 (event != NULL) ? &tmp : NULL), 5739 __ENQUEUE_UNMAP_MEM_OBJECT_ERR); 5740 5741 if (event != NULL && err == CL_SUCCESS) 5742 *event = tmp; 5743 5744 return err; 5745 } 5746 5747 #if defined(CL_VERSION_1_2) 5748 /** 5749 * Enqueues a marker command which waits for either a list of events to complete, 5750 * or all previously enqueued commands to complete. 5751 * 5752 * Enqueues a marker command which waits for either a list of events to complete, 5753 * or if the list is empty it waits for all commands previously enqueued in command_queue 5754 * to complete before it completes. This command returns an event which can be waited on, 5755 * i.e. this event can be waited on to insure that all events either in the event_wait_list 5756 * or all previously enqueued commands, queued before this command to command_queue, 5757 * have completed. 5758 */ 5759 cl_int enqueueMarkerWithWaitList( 5760 const VECTOR_CLASS<Event> *events = 0, 5761 Event *event = 0) 5762 { 5763 cl_event tmp; 5764 cl_int err = detail::errHandler( 5765 ::clEnqueueMarkerWithWaitList( 5766 object_, 5767 (events != NULL) ? (cl_uint) events->size() : 0, 5768 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5769 (event != NULL) ? &tmp : NULL), 5770 __ENQUEUE_MARKER_WAIT_LIST_ERR); 5771 5772 if (event != NULL && err == CL_SUCCESS) 5773 *event = tmp; 5774 5775 return err; 5776 } 5777 5778 /** 5779 * A synchronization point that enqueues a barrier operation. 5780 * 5781 * Enqueues a barrier command which waits for either a list of events to complete, 5782 * or if the list is empty it waits for all commands previously enqueued in command_queue 5783 * to complete before it completes. This command blocks command execution, that is, any 5784 * following commands enqueued after it do not execute until it completes. This command 5785 * returns an event which can be waited on, i.e. this event can be waited on to insure that 5786 * all events either in the event_wait_list or all previously enqueued commands, queued 5787 * before this command to command_queue, have completed. 5788 */ 5789 cl_int enqueueBarrierWithWaitList( 5790 const VECTOR_CLASS<Event> *events = 0, 5791 Event *event = 0) 5792 { 5793 cl_event tmp; 5794 cl_int err = detail::errHandler( 5795 ::clEnqueueBarrierWithWaitList( 5796 object_, 5797 (events != NULL) ? (cl_uint) events->size() : 0, 5798 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5799 (event != NULL) ? &tmp : NULL), 5800 __ENQUEUE_BARRIER_WAIT_LIST_ERR); 5801 5802 if (event != NULL && err == CL_SUCCESS) 5803 *event = tmp; 5804 5805 return err; 5806 } 5807 5808 /** 5809 * Enqueues a command to indicate with which device a set of memory objects 5810 * should be associated. 5811 */ 5812 cl_int enqueueMigrateMemObjects( 5813 const VECTOR_CLASS<Memory> &memObjects, 5814 cl_mem_migration_flags flags, 5815 const VECTOR_CLASS<Event>* events = NULL, 5816 Event* event = NULL 5817 ) 5818 { 5819 cl_event tmp; 5820 5821 cl_mem* localMemObjects = static_cast<cl_mem*>(alloca(memObjects.size() * sizeof(cl_mem))); 5822 for( int i = 0; i < (int)memObjects.size(); ++i ) { 5823 localMemObjects[i] = memObjects[i](); 5824 } 5825 5826 5827 cl_int err = detail::errHandler( 5828 ::clEnqueueMigrateMemObjects( 5829 object_, 5830 (cl_uint)memObjects.size(), 5831 static_cast<const cl_mem*>(localMemObjects), 5832 flags, 5833 (events != NULL) ? (cl_uint) events->size() : 0, 5834 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5835 (event != NULL) ? &tmp : NULL), 5836 __ENQUEUE_UNMAP_MEM_OBJECT_ERR); 5837 5838 if (event != NULL && err == CL_SUCCESS) 5839 *event = tmp; 5840 5841 return err; 5842 } 5843 #endif // #if defined(CL_VERSION_1_2) 5844 5845 cl_int enqueueNDRangeKernel( 5846 const Kernel& kernel, 5847 const NDRange& offset, 5848 const NDRange& global, 5849 const NDRange& local = NullRange, 5850 const VECTOR_CLASS<Event>* events = NULL, 5851 Event* event = NULL) const 5852 { 5853 cl_event tmp; 5854 cl_int err = detail::errHandler( 5855 ::clEnqueueNDRangeKernel( 5856 object_, kernel(), (cl_uint) global.dimensions(), 5857 offset.dimensions() != 0 ? (const ::size_t*) offset : NULL, 5858 (const ::size_t*) global, 5859 local.dimensions() != 0 ? (const ::size_t*) local : NULL, 5860 (events != NULL) ? (cl_uint) events->size() : 0, 5861 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5862 (event != NULL) ? &tmp : NULL), 5863 __ENQUEUE_NDRANGE_KERNEL_ERR); 5864 5865 if (event != NULL && err == CL_SUCCESS) 5866 *event = tmp; 5867 5868 return err; 5869 } 5870 5871 cl_int enqueueTask( 5872 const Kernel& kernel, 5873 const VECTOR_CLASS<Event>* events = NULL, 5874 Event* event = NULL) const 5875 { 5876 cl_event tmp; 5877 cl_int err = detail::errHandler( 5878 ::clEnqueueTask( 5879 object_, kernel(), 5880 (events != NULL) ? (cl_uint) events->size() : 0, 5881 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5882 (event != NULL) ? &tmp : NULL), 5883 __ENQUEUE_TASK_ERR); 5884 5885 if (event != NULL && err == CL_SUCCESS) 5886 *event = tmp; 5887 5888 return err; 5889 } 5890 5891 cl_int enqueueNativeKernel( 5892 void (CL_CALLBACK *userFptr)(void *), 5893 std::pair<void*, ::size_t> args, 5894 const VECTOR_CLASS<Memory>* mem_objects = NULL, 5895 const VECTOR_CLASS<const void*>* mem_locs = NULL, 5896 const VECTOR_CLASS<Event>* events = NULL, 5897 Event* event = NULL) const 5898 { 5899 cl_mem * mems = (mem_objects != NULL && mem_objects->size() > 0) 5900 ? (cl_mem*) alloca(mem_objects->size() * sizeof(cl_mem)) 5901 : NULL; 5902 5903 if (mems != NULL) { 5904 for (unsigned int i = 0; i < mem_objects->size(); i++) { 5905 mems[i] = ((*mem_objects)[i])(); 5906 } 5907 } 5908 5909 cl_event tmp; 5910 cl_int err = detail::errHandler( 5911 ::clEnqueueNativeKernel( 5912 object_, userFptr, args.first, args.second, 5913 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, 5914 mems, 5915 (mem_locs != NULL) ? (const void **) &mem_locs->front() : NULL, 5916 (events != NULL) ? (cl_uint) events->size() : 0, 5917 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5918 (event != NULL) ? &tmp : NULL), 5919 __ENQUEUE_NATIVE_KERNEL); 5920 5921 if (event != NULL && err == CL_SUCCESS) 5922 *event = tmp; 5923 5924 return err; 5925 } 5926 5927 /** 5928 * Deprecated APIs for 1.2 5929 */ 5930 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) 5931 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED 5932 cl_int enqueueMarker(Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED 5933 { 5934 return detail::errHandler( 5935 ::clEnqueueMarker(object_, (cl_event*) event), 5936 __ENQUEUE_MARKER_ERR); 5937 } 5938 5939 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED 5940 cl_int enqueueWaitForEvents(const VECTOR_CLASS<Event>& events) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED 5941 { 5942 return detail::errHandler( 5943 ::clEnqueueWaitForEvents( 5944 object_, 5945 (cl_uint) events.size(), 5946 (const cl_event*) &events.front()), 5947 __ENQUEUE_WAIT_FOR_EVENTS_ERR); 5948 } 5949 #endif // #if defined(CL_VERSION_1_1) 5950 5951 cl_int enqueueAcquireGLObjects( 5952 const VECTOR_CLASS<Memory>* mem_objects = NULL, 5953 const VECTOR_CLASS<Event>* events = NULL, 5954 Event* event = NULL) const 5955 { 5956 cl_event tmp; 5957 cl_int err = detail::errHandler( 5958 ::clEnqueueAcquireGLObjects( 5959 object_, 5960 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, 5961 (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL, 5962 (events != NULL) ? (cl_uint) events->size() : 0, 5963 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5964 (event != NULL) ? &tmp : NULL), 5965 __ENQUEUE_ACQUIRE_GL_ERR); 5966 5967 if (event != NULL && err == CL_SUCCESS) 5968 *event = tmp; 5969 5970 return err; 5971 } 5972 5973 cl_int enqueueReleaseGLObjects( 5974 const VECTOR_CLASS<Memory>* mem_objects = NULL, 5975 const VECTOR_CLASS<Event>* events = NULL, 5976 Event* event = NULL) const 5977 { 5978 cl_event tmp; 5979 cl_int err = detail::errHandler( 5980 ::clEnqueueReleaseGLObjects( 5981 object_, 5982 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, 5983 (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL, 5984 (events != NULL) ? (cl_uint) events->size() : 0, 5985 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 5986 (event != NULL) ? &tmp : NULL), 5987 __ENQUEUE_RELEASE_GL_ERR); 5988 5989 if (event != NULL && err == CL_SUCCESS) 5990 *event = tmp; 5991 5992 return err; 5993 } 5994 5995 #if defined (USE_DX_INTEROP) 5996 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)( 5997 cl_command_queue command_queue, cl_uint num_objects, 5998 const cl_mem* mem_objects, cl_uint num_events_in_wait_list, 5999 const cl_event* event_wait_list, cl_event* event); 6000 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)( 6001 cl_command_queue command_queue, cl_uint num_objects, 6002 const cl_mem* mem_objects, cl_uint num_events_in_wait_list, 6003 const cl_event* event_wait_list, cl_event* event); 6004 6005 cl_int enqueueAcquireD3D10Objects( 6006 const VECTOR_CLASS<Memory>* mem_objects = NULL, 6007 const VECTOR_CLASS<Event>* events = NULL, 6008 Event* event = NULL) const 6009 { 6010 static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL; 6011 #if defined(CL_VERSION_1_2) 6012 cl_context context = getInfo<CL_QUEUE_CONTEXT>(); 6013 cl::Device device(getInfo<CL_QUEUE_DEVICE>()); 6014 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>(); 6015 __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueAcquireD3D10ObjectsKHR); 6016 #endif 6017 #if defined(CL_VERSION_1_1) 6018 __INIT_CL_EXT_FCN_PTR(clEnqueueAcquireD3D10ObjectsKHR); 6019 #endif 6020 6021 cl_event tmp; 6022 cl_int err = detail::errHandler( 6023 pfn_clEnqueueAcquireD3D10ObjectsKHR( 6024 object_, 6025 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, 6026 (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL, 6027 (events != NULL) ? (cl_uint) events->size() : 0, 6028 (events != NULL) ? (cl_event*) &events->front() : NULL, 6029 (event != NULL) ? &tmp : NULL), 6030 __ENQUEUE_ACQUIRE_GL_ERR); 6031 6032 if (event != NULL && err == CL_SUCCESS) 6033 *event = tmp; 6034 6035 return err; 6036 } 6037 6038 cl_int enqueueReleaseD3D10Objects( 6039 const VECTOR_CLASS<Memory>* mem_objects = NULL, 6040 const VECTOR_CLASS<Event>* events = NULL, 6041 Event* event = NULL) const 6042 { 6043 static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL; 6044 #if defined(CL_VERSION_1_2) 6045 cl_context context = getInfo<CL_QUEUE_CONTEXT>(); 6046 cl::Device device(getInfo<CL_QUEUE_DEVICE>()); 6047 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>(); 6048 __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueReleaseD3D10ObjectsKHR); 6049 #endif // #if defined(CL_VERSION_1_2) 6050 #if defined(CL_VERSION_1_1) 6051 __INIT_CL_EXT_FCN_PTR(clEnqueueReleaseD3D10ObjectsKHR); 6052 #endif // #if defined(CL_VERSION_1_1) 6053 6054 cl_event tmp; 6055 cl_int err = detail::errHandler( 6056 pfn_clEnqueueReleaseD3D10ObjectsKHR( 6057 object_, 6058 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, 6059 (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL, 6060 (events != NULL) ? (cl_uint) events->size() : 0, 6061 (events != NULL) ? (cl_event*) &events->front() : NULL, 6062 (event != NULL) ? &tmp : NULL), 6063 __ENQUEUE_RELEASE_GL_ERR); 6064 6065 if (event != NULL && err == CL_SUCCESS) 6066 *event = tmp; 6067 6068 return err; 6069 } 6070 #endif 6071 6072 /** 6073 * Deprecated APIs for 1.2 6074 */ 6075 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) 6076 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED 6077 cl_int enqueueBarrier() const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED 6078 { 6079 return detail::errHandler( 6080 ::clEnqueueBarrier(object_), 6081 __ENQUEUE_BARRIER_ERR); 6082 } 6083 #endif // #if defined(CL_VERSION_1_1) 6084 6085 cl_int flush() const 6086 { 6087 return detail::errHandler(::clFlush(object_), __FLUSH_ERR); 6088 } 6089 6090 cl_int finish() const 6091 { 6092 return detail::errHandler(::clFinish(object_), __FINISH_ERR); 6093 } 6094 }; 6095 6096 #ifdef _WIN32 6097 __declspec(selectany) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED; 6098 __declspec(selectany) CommandQueue CommandQueue::default_; 6099 __declspec(selectany) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS; 6100 #else 6101 __attribute__((weak)) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED; 6102 __attribute__((weak)) CommandQueue CommandQueue::default_; 6103 __attribute__((weak)) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS; 6104 #endif 6105 6106 inline cl_int enqueueReadBuffer( 6107 const Buffer& buffer, 6108 cl_bool blocking, 6109 ::size_t offset, 6110 ::size_t size, 6111 void* ptr, 6112 const VECTOR_CLASS<Event>* events = NULL, 6113 Event* event = NULL) 6114 { 6115 cl_int error; 6116 CommandQueue queue = CommandQueue::getDefault(&error); 6117 6118 if (error != CL_SUCCESS) { 6119 return error; 6120 } 6121 6122 return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event); 6123 } 6124 6125 inline cl_int enqueueWriteBuffer( 6126 const Buffer& buffer, 6127 cl_bool blocking, 6128 ::size_t offset, 6129 ::size_t size, 6130 const void* ptr, 6131 const VECTOR_CLASS<Event>* events = NULL, 6132 Event* event = NULL) 6133 { 6134 cl_int error; 6135 CommandQueue queue = CommandQueue::getDefault(&error); 6136 6137 if (error != CL_SUCCESS) { 6138 return error; 6139 } 6140 6141 return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event); 6142 } 6143 6144 inline void* enqueueMapBuffer( 6145 const Buffer& buffer, 6146 cl_bool blocking, 6147 cl_map_flags flags, 6148 ::size_t offset, 6149 ::size_t size, 6150 const VECTOR_CLASS<Event>* events = NULL, 6151 Event* event = NULL, 6152 cl_int* err = NULL) 6153 { 6154 cl_int error; 6155 CommandQueue queue = CommandQueue::getDefault(&error); 6156 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); 6157 if (err != NULL) { 6158 *err = error; 6159 } 6160 6161 void * result = ::clEnqueueMapBuffer( 6162 queue(), buffer(), blocking, flags, offset, size, 6163 (events != NULL) ? (cl_uint) events->size() : 0, 6164 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 6165 (cl_event*) event, 6166 &error); 6167 6168 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); 6169 if (err != NULL) { 6170 *err = error; 6171 } 6172 return result; 6173 } 6174 6175 inline cl_int enqueueUnmapMemObject( 6176 const Memory& memory, 6177 void* mapped_ptr, 6178 const VECTOR_CLASS<Event>* events = NULL, 6179 Event* event = NULL) 6180 { 6181 cl_int error; 6182 CommandQueue queue = CommandQueue::getDefault(&error); 6183 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); 6184 if (error != CL_SUCCESS) { 6185 return error; 6186 } 6187 6188 cl_event tmp; 6189 cl_int err = detail::errHandler( 6190 ::clEnqueueUnmapMemObject( 6191 queue(), memory(), mapped_ptr, 6192 (events != NULL) ? (cl_uint) events->size() : 0, 6193 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, 6194 (event != NULL) ? &tmp : NULL), 6195 __ENQUEUE_UNMAP_MEM_OBJECT_ERR); 6196 6197 if (event != NULL && err == CL_SUCCESS) 6198 *event = tmp; 6199 6200 return err; 6201 } 6202 6203 inline cl_int enqueueCopyBuffer( 6204 const Buffer& src, 6205 const Buffer& dst, 6206 ::size_t src_offset, 6207 ::size_t dst_offset, 6208 ::size_t size, 6209 const VECTOR_CLASS<Event>* events = NULL, 6210 Event* event = NULL) 6211 { 6212 cl_int error; 6213 CommandQueue queue = CommandQueue::getDefault(&error); 6214 6215 if (error != CL_SUCCESS) { 6216 return error; 6217 } 6218 6219 return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event); 6220 } 6221 6222 /** 6223 * Blocking copy operation between iterators and a buffer. 6224 */ 6225 template< typename IteratorType > 6226 inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ) 6227 { 6228 typedef typename std::iterator_traits<IteratorType>::value_type DataType; 6229 cl_int error; 6230 6231 ::size_t length = endIterator-startIterator; 6232 ::size_t byteLength = length*sizeof(DataType); 6233 6234 DataType *pointer = 6235 static_cast<DataType*>(enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error)); 6236 // if exceptions enabled, enqueueMapBuffer will throw 6237 if( error != CL_SUCCESS ) { 6238 return error; 6239 } 6240 #if defined(_MSC_VER) 6241 std::copy( 6242 startIterator, 6243 endIterator, 6244 stdext::checked_array_iterator<DataType*>( 6245 pointer, length)); 6246 #else 6247 std::copy(startIterator, endIterator, pointer); 6248 #endif 6249 Event endEvent; 6250 error = enqueueUnmapMemObject(buffer, pointer, 0, &endEvent); 6251 // if exceptions enabled, enqueueUnmapMemObject will throw 6252 if( error != CL_SUCCESS ) { 6253 return error; 6254 } 6255 endEvent.wait(); 6256 return CL_SUCCESS; 6257 } 6258 6259 /** 6260 * Blocking copy operation between iterators and a buffer. 6261 */ 6262 template< typename IteratorType > 6263 inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ) 6264 { 6265 typedef typename std::iterator_traits<IteratorType>::value_type DataType; 6266 cl_int error; 6267 6268 ::size_t length = endIterator-startIterator; 6269 ::size_t byteLength = length*sizeof(DataType); 6270 6271 DataType *pointer = 6272 static_cast<DataType*>(enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error)); 6273 // if exceptions enabled, enqueueMapBuffer will throw 6274 if( error != CL_SUCCESS ) { 6275 return error; 6276 } 6277 std::copy(pointer, pointer + length, startIterator); 6278 Event endEvent; 6279 error = enqueueUnmapMemObject(buffer, pointer, 0, &endEvent); 6280 // if exceptions enabled, enqueueUnmapMemObject will throw 6281 if( error != CL_SUCCESS ) { 6282 return error; 6283 } 6284 endEvent.wait(); 6285 return CL_SUCCESS; 6286 } 6287 6288 #if defined(CL_VERSION_1_1) 6289 inline cl_int enqueueReadBufferRect( 6290 const Buffer& buffer, 6291 cl_bool blocking, 6292 const size_t<3>& buffer_offset, 6293 const size_t<3>& host_offset, 6294 const size_t<3>& region, 6295 ::size_t buffer_row_pitch, 6296 ::size_t buffer_slice_pitch, 6297 ::size_t host_row_pitch, 6298 ::size_t host_slice_pitch, 6299 void *ptr, 6300 const VECTOR_CLASS<Event>* events = NULL, 6301 Event* event = NULL) 6302 { 6303 cl_int error; 6304 CommandQueue queue = CommandQueue::getDefault(&error); 6305 6306 if (error != CL_SUCCESS) { 6307 return error; 6308 } 6309 6310 return queue.enqueueReadBufferRect( 6311 buffer, 6312 blocking, 6313 buffer_offset, 6314 host_offset, 6315 region, 6316 buffer_row_pitch, 6317 buffer_slice_pitch, 6318 host_row_pitch, 6319 host_slice_pitch, 6320 ptr, 6321 events, 6322 event); 6323 } 6324 6325 inline cl_int enqueueWriteBufferRect( 6326 const Buffer& buffer, 6327 cl_bool blocking, 6328 const size_t<3>& buffer_offset, 6329 const size_t<3>& host_offset, 6330 const size_t<3>& region, 6331 ::size_t buffer_row_pitch, 6332 ::size_t buffer_slice_pitch, 6333 ::size_t host_row_pitch, 6334 ::size_t host_slice_pitch, 6335 void *ptr, 6336 const VECTOR_CLASS<Event>* events = NULL, 6337 Event* event = NULL) 6338 { 6339 cl_int error; 6340 CommandQueue queue = CommandQueue::getDefault(&error); 6341 6342 if (error != CL_SUCCESS) { 6343 return error; 6344 } 6345 6346 return queue.enqueueWriteBufferRect( 6347 buffer, 6348 blocking, 6349 buffer_offset, 6350 host_offset, 6351 region, 6352 buffer_row_pitch, 6353 buffer_slice_pitch, 6354 host_row_pitch, 6355 host_slice_pitch, 6356 ptr, 6357 events, 6358 event); 6359 } 6360 6361 inline cl_int enqueueCopyBufferRect( 6362 const Buffer& src, 6363 const Buffer& dst, 6364 const size_t<3>& src_origin, 6365 const size_t<3>& dst_origin, 6366 const size_t<3>& region, 6367 ::size_t src_row_pitch, 6368 ::size_t src_slice_pitch, 6369 ::size_t dst_row_pitch, 6370 ::size_t dst_slice_pitch, 6371 const VECTOR_CLASS<Event>* events = NULL, 6372 Event* event = NULL) 6373 { 6374 cl_int error; 6375 CommandQueue queue = CommandQueue::getDefault(&error); 6376 6377 if (error != CL_SUCCESS) { 6378 return error; 6379 } 6380 6381 return queue.enqueueCopyBufferRect( 6382 src, 6383 dst, 6384 src_origin, 6385 dst_origin, 6386 region, 6387 src_row_pitch, 6388 src_slice_pitch, 6389 dst_row_pitch, 6390 dst_slice_pitch, 6391 events, 6392 event); 6393 } 6394 #endif 6395 6396 inline cl_int enqueueReadImage( 6397 const Image& image, 6398 cl_bool blocking, 6399 const size_t<3>& origin, 6400 const size_t<3>& region, 6401 ::size_t row_pitch, 6402 ::size_t slice_pitch, 6403 void* ptr, 6404 const VECTOR_CLASS<Event>* events = NULL, 6405 Event* event = NULL) 6406 { 6407 cl_int error; 6408 CommandQueue queue = CommandQueue::getDefault(&error); 6409 6410 if (error != CL_SUCCESS) { 6411 return error; 6412 } 6413 6414 return queue.enqueueReadImage( 6415 image, 6416 blocking, 6417 origin, 6418 region, 6419 row_pitch, 6420 slice_pitch, 6421 ptr, 6422 events, 6423 event); 6424 } 6425 6426 inline cl_int enqueueWriteImage( 6427 const Image& image, 6428 cl_bool blocking, 6429 const size_t<3>& origin, 6430 const size_t<3>& region, 6431 ::size_t row_pitch, 6432 ::size_t slice_pitch, 6433 void* ptr, 6434 const VECTOR_CLASS<Event>* events = NULL, 6435 Event* event = NULL) 6436 { 6437 cl_int error; 6438 CommandQueue queue = CommandQueue::getDefault(&error); 6439 6440 if (error != CL_SUCCESS) { 6441 return error; 6442 } 6443 6444 return queue.enqueueWriteImage( 6445 image, 6446 blocking, 6447 origin, 6448 region, 6449 row_pitch, 6450 slice_pitch, 6451 ptr, 6452 events, 6453 event); 6454 } 6455 6456 inline cl_int enqueueCopyImage( 6457 const Image& src, 6458 const Image& dst, 6459 const size_t<3>& src_origin, 6460 const size_t<3>& dst_origin, 6461 const size_t<3>& region, 6462 const VECTOR_CLASS<Event>* events = NULL, 6463 Event* event = NULL) 6464 { 6465 cl_int error; 6466 CommandQueue queue = CommandQueue::getDefault(&error); 6467 6468 if (error != CL_SUCCESS) { 6469 return error; 6470 } 6471 6472 return queue.enqueueCopyImage( 6473 src, 6474 dst, 6475 src_origin, 6476 dst_origin, 6477 region, 6478 events, 6479 event); 6480 } 6481 6482 inline cl_int enqueueCopyImageToBuffer( 6483 const Image& src, 6484 const Buffer& dst, 6485 const size_t<3>& src_origin, 6486 const size_t<3>& region, 6487 ::size_t dst_offset, 6488 const VECTOR_CLASS<Event>* events = NULL, 6489 Event* event = NULL) 6490 { 6491 cl_int error; 6492 CommandQueue queue = CommandQueue::getDefault(&error); 6493 6494 if (error != CL_SUCCESS) { 6495 return error; 6496 } 6497 6498 return queue.enqueueCopyImageToBuffer( 6499 src, 6500 dst, 6501 src_origin, 6502 region, 6503 dst_offset, 6504 events, 6505 event); 6506 } 6507 6508 inline cl_int enqueueCopyBufferToImage( 6509 const Buffer& src, 6510 const Image& dst, 6511 ::size_t src_offset, 6512 const size_t<3>& dst_origin, 6513 const size_t<3>& region, 6514 const VECTOR_CLASS<Event>* events = NULL, 6515 Event* event = NULL) 6516 { 6517 cl_int error; 6518 CommandQueue queue = CommandQueue::getDefault(&error); 6519 6520 if (error != CL_SUCCESS) { 6521 return error; 6522 } 6523 6524 return queue.enqueueCopyBufferToImage( 6525 src, 6526 dst, 6527 src_offset, 6528 dst_origin, 6529 region, 6530 events, 6531 event); 6532 } 6533 6534 6535 inline cl_int flush(void) 6536 { 6537 cl_int error; 6538 CommandQueue queue = CommandQueue::getDefault(&error); 6539 6540 if (error != CL_SUCCESS) { 6541 return error; 6542 } 6543 6544 return queue.flush(); 6545 } 6546 6547 inline cl_int finish(void) 6548 { 6549 cl_int error; 6550 CommandQueue queue = CommandQueue::getDefault(&error); 6551 6552 if (error != CL_SUCCESS) { 6553 return error; 6554 } 6555 6556 6557 return queue.finish(); 6558 } 6559 6560 // Kernel Functor support 6561 // New interface as of September 2011 6562 // Requires the C++11 std::tr1::function (note do not support TR1) 6563 // Visual Studio 2010 and GCC 4.2 6564 6565 struct EnqueueArgs 6566 { 6567 CommandQueue queue_; 6568 const NDRange offset_; 6569 const NDRange global_; 6570 const NDRange local_; 6571 VECTOR_CLASS<Event> events_; 6572 6573 EnqueueArgs(NDRange global) : 6574 queue_(CommandQueue::getDefault()), 6575 offset_(NullRange), 6576 global_(global), 6577 local_(NullRange) 6578 { 6579 6580 } 6581 6582 EnqueueArgs(NDRange global, NDRange local) : 6583 queue_(CommandQueue::getDefault()), 6584 offset_(NullRange), 6585 global_(global), 6586 local_(local) 6587 { 6588 6589 } 6590 6591 EnqueueArgs(NDRange offset, NDRange global, NDRange local) : 6592 queue_(CommandQueue::getDefault()), 6593 offset_(offset), 6594 global_(global), 6595 local_(local) 6596 { 6597 6598 } 6599 6600 EnqueueArgs(Event e, NDRange global) : 6601 queue_(CommandQueue::getDefault()), 6602 offset_(NullRange), 6603 global_(global), 6604 local_(NullRange) 6605 { 6606 events_.push_back(e); 6607 } 6608 6609 EnqueueArgs(Event e, NDRange global, NDRange local) : 6610 queue_(CommandQueue::getDefault()), 6611 offset_(NullRange), 6612 global_(global), 6613 local_(local) 6614 { 6615 events_.push_back(e); 6616 } 6617 6618 EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) : 6619 queue_(CommandQueue::getDefault()), 6620 offset_(offset), 6621 global_(global), 6622 local_(local) 6623 { 6624 events_.push_back(e); 6625 } 6626 6627 EnqueueArgs(const VECTOR_CLASS<Event> &events, NDRange global) : 6628 queue_(CommandQueue::getDefault()), 6629 offset_(NullRange), 6630 global_(global), 6631 local_(NullRange), 6632 events_(events) 6633 { 6634 6635 } 6636 6637 EnqueueArgs(const VECTOR_CLASS<Event> &events, NDRange global, NDRange local) : 6638 queue_(CommandQueue::getDefault()), 6639 offset_(NullRange), 6640 global_(global), 6641 local_(local), 6642 events_(events) 6643 { 6644 6645 } 6646 6647 EnqueueArgs(const VECTOR_CLASS<Event> &events, NDRange offset, NDRange global, NDRange local) : 6648 queue_(CommandQueue::getDefault()), 6649 offset_(offset), 6650 global_(global), 6651 local_(local), 6652 events_(events) 6653 { 6654 6655 } 6656 6657 EnqueueArgs(CommandQueue &queue, NDRange global) : 6658 queue_(queue), 6659 offset_(NullRange), 6660 global_(global), 6661 local_(NullRange) 6662 { 6663 6664 } 6665 6666 EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) : 6667 queue_(queue), 6668 offset_(NullRange), 6669 global_(global), 6670 local_(local) 6671 { 6672 6673 } 6674 6675 EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) : 6676 queue_(queue), 6677 offset_(offset), 6678 global_(global), 6679 local_(local) 6680 { 6681 6682 } 6683 6684 EnqueueArgs(CommandQueue &queue, Event e, NDRange global) : 6685 queue_(queue), 6686 offset_(NullRange), 6687 global_(global), 6688 local_(NullRange) 6689 { 6690 events_.push_back(e); 6691 } 6692 6693 EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) : 6694 queue_(queue), 6695 offset_(NullRange), 6696 global_(global), 6697 local_(local) 6698 { 6699 events_.push_back(e); 6700 } 6701 6702 EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) : 6703 queue_(queue), 6704 offset_(offset), 6705 global_(global), 6706 local_(local) 6707 { 6708 events_.push_back(e); 6709 } 6710 6711 EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS<Event> &events, NDRange global) : 6712 queue_(queue), 6713 offset_(NullRange), 6714 global_(global), 6715 local_(NullRange), 6716 events_(events) 6717 { 6718 6719 } 6720 6721 EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS<Event> &events, NDRange global, NDRange local) : 6722 queue_(queue), 6723 offset_(NullRange), 6724 global_(global), 6725 local_(local), 6726 events_(events) 6727 { 6728 6729 } 6730 6731 EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS<Event> &events, NDRange offset, NDRange global, NDRange local) : 6732 queue_(queue), 6733 offset_(offset), 6734 global_(global), 6735 local_(local), 6736 events_(events) 6737 { 6738 6739 } 6740 }; 6741 6742 namespace detail { 6743 6744 class NullType {}; 6745 6746 template<int index, typename T0> 6747 struct SetArg 6748 { 6749 static void set (Kernel kernel, T0 arg) 6750 { 6751 kernel.setArg(index, arg); 6752 } 6753 }; 6754 6755 template<int index> 6756 struct SetArg<index, NullType> 6757 { 6758 static void set (Kernel, NullType) 6759 { 6760 } 6761 }; 6762 6763 template < 6764 typename T0, typename T1, typename T2, typename T3, 6765 typename T4, typename T5, typename T6, typename T7, 6766 typename T8, typename T9, typename T10, typename T11, 6767 typename T12, typename T13, typename T14, typename T15, 6768 typename T16, typename T17, typename T18, typename T19, 6769 typename T20, typename T21, typename T22, typename T23, 6770 typename T24, typename T25, typename T26, typename T27, 6771 typename T28, typename T29, typename T30, typename T31 6772 > 6773 class KernelFunctorGlobal 6774 { 6775 private: 6776 Kernel kernel_; 6777 6778 public: 6779 KernelFunctorGlobal( 6780 Kernel kernel) : 6781 kernel_(kernel) 6782 {} 6783 6784 KernelFunctorGlobal( 6785 const Program& program, 6786 const STRING_CLASS name, 6787 cl_int * err = NULL) : 6788 kernel_(program, name.c_str(), err) 6789 {} 6790 6791 Event operator() ( 6792 const EnqueueArgs& args, 6793 T0 t0, 6794 T1 t1 = NullType(), 6795 T2 t2 = NullType(), 6796 T3 t3 = NullType(), 6797 T4 t4 = NullType(), 6798 T5 t5 = NullType(), 6799 T6 t6 = NullType(), 6800 T7 t7 = NullType(), 6801 T8 t8 = NullType(), 6802 T9 t9 = NullType(), 6803 T10 t10 = NullType(), 6804 T11 t11 = NullType(), 6805 T12 t12 = NullType(), 6806 T13 t13 = NullType(), 6807 T14 t14 = NullType(), 6808 T15 t15 = NullType(), 6809 T16 t16 = NullType(), 6810 T17 t17 = NullType(), 6811 T18 t18 = NullType(), 6812 T19 t19 = NullType(), 6813 T20 t20 = NullType(), 6814 T21 t21 = NullType(), 6815 T22 t22 = NullType(), 6816 T23 t23 = NullType(), 6817 T24 t24 = NullType(), 6818 T25 t25 = NullType(), 6819 T26 t26 = NullType(), 6820 T27 t27 = NullType(), 6821 T28 t28 = NullType(), 6822 T29 t29 = NullType(), 6823 T30 t30 = NullType(), 6824 T31 t31 = NullType() 6825 ) 6826 { 6827 Event event; 6828 SetArg<0, T0>::set(kernel_, t0); 6829 SetArg<1, T1>::set(kernel_, t1); 6830 SetArg<2, T2>::set(kernel_, t2); 6831 SetArg<3, T3>::set(kernel_, t3); 6832 SetArg<4, T4>::set(kernel_, t4); 6833 SetArg<5, T5>::set(kernel_, t5); 6834 SetArg<6, T6>::set(kernel_, t6); 6835 SetArg<7, T7>::set(kernel_, t7); 6836 SetArg<8, T8>::set(kernel_, t8); 6837 SetArg<9, T9>::set(kernel_, t9); 6838 SetArg<10, T10>::set(kernel_, t10); 6839 SetArg<11, T11>::set(kernel_, t11); 6840 SetArg<12, T12>::set(kernel_, t12); 6841 SetArg<13, T13>::set(kernel_, t13); 6842 SetArg<14, T14>::set(kernel_, t14); 6843 SetArg<15, T15>::set(kernel_, t15); 6844 SetArg<16, T16>::set(kernel_, t16); 6845 SetArg<17, T17>::set(kernel_, t17); 6846 SetArg<18, T18>::set(kernel_, t18); 6847 SetArg<19, T19>::set(kernel_, t19); 6848 SetArg<20, T20>::set(kernel_, t20); 6849 SetArg<21, T21>::set(kernel_, t21); 6850 SetArg<22, T22>::set(kernel_, t22); 6851 SetArg<23, T23>::set(kernel_, t23); 6852 SetArg<24, T24>::set(kernel_, t24); 6853 SetArg<25, T25>::set(kernel_, t25); 6854 SetArg<26, T26>::set(kernel_, t26); 6855 SetArg<27, T27>::set(kernel_, t27); 6856 SetArg<28, T28>::set(kernel_, t28); 6857 SetArg<29, T29>::set(kernel_, t29); 6858 SetArg<30, T30>::set(kernel_, t30); 6859 SetArg<31, T31>::set(kernel_, t31); 6860 6861 args.queue_.enqueueNDRangeKernel( 6862 kernel_, 6863 args.offset_, 6864 args.global_, 6865 args.local_, 6866 &args.events_, 6867 &event); 6868 6869 return event; 6870 } 6871 6872 }; 6873 6874 //------------------------------------------------------------------------------------------------------ 6875 6876 6877 template< 6878 typename T0, 6879 typename T1, 6880 typename T2, 6881 typename T3, 6882 typename T4, 6883 typename T5, 6884 typename T6, 6885 typename T7, 6886 typename T8, 6887 typename T9, 6888 typename T10, 6889 typename T11, 6890 typename T12, 6891 typename T13, 6892 typename T14, 6893 typename T15, 6894 typename T16, 6895 typename T17, 6896 typename T18, 6897 typename T19, 6898 typename T20, 6899 typename T21, 6900 typename T22, 6901 typename T23, 6902 typename T24, 6903 typename T25, 6904 typename T26, 6905 typename T27, 6906 typename T28, 6907 typename T29, 6908 typename T30, 6909 typename T31> 6910 struct functionImplementation_ 6911 { 6912 typedef detail::KernelFunctorGlobal< 6913 T0, 6914 T1, 6915 T2, 6916 T3, 6917 T4, 6918 T5, 6919 T6, 6920 T7, 6921 T8, 6922 T9, 6923 T10, 6924 T11, 6925 T12, 6926 T13, 6927 T14, 6928 T15, 6929 T16, 6930 T17, 6931 T18, 6932 T19, 6933 T20, 6934 T21, 6935 T22, 6936 T23, 6937 T24, 6938 T25, 6939 T26, 6940 T27, 6941 T28, 6942 T29, 6943 T30, 6944 T31> FunctorType; 6945 6946 FunctorType functor_; 6947 6948 functionImplementation_(const FunctorType &functor) : 6949 functor_(functor) 6950 { 6951 6952 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 32)) 6953 // Fail variadic expansion for dev11 6954 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 6955 #endif 6956 6957 } 6958 6959 //! \brief Return type of the functor 6960 typedef Event result_type; 6961 6962 //! \brief Function signature of kernel functor with no event dependency. 6963 typedef Event type_( 6964 const EnqueueArgs&, 6965 T0, 6966 T1, 6967 T2, 6968 T3, 6969 T4, 6970 T5, 6971 T6, 6972 T7, 6973 T8, 6974 T9, 6975 T10, 6976 T11, 6977 T12, 6978 T13, 6979 T14, 6980 T15, 6981 T16, 6982 T17, 6983 T18, 6984 T19, 6985 T20, 6986 T21, 6987 T22, 6988 T23, 6989 T24, 6990 T25, 6991 T26, 6992 T27, 6993 T28, 6994 T29, 6995 T30, 6996 T31); 6997 6998 Event operator()( 6999 const EnqueueArgs& enqueueArgs, 7000 T0 arg0, 7001 T1 arg1, 7002 T2 arg2, 7003 T3 arg3, 7004 T4 arg4, 7005 T5 arg5, 7006 T6 arg6, 7007 T7 arg7, 7008 T8 arg8, 7009 T9 arg9, 7010 T10 arg10, 7011 T11 arg11, 7012 T12 arg12, 7013 T13 arg13, 7014 T14 arg14, 7015 T15 arg15, 7016 T16 arg16, 7017 T17 arg17, 7018 T18 arg18, 7019 T19 arg19, 7020 T20 arg20, 7021 T21 arg21, 7022 T22 arg22, 7023 T23 arg23, 7024 T24 arg24, 7025 T25 arg25, 7026 T26 arg26, 7027 T27 arg27, 7028 T28 arg28, 7029 T29 arg29, 7030 T30 arg30, 7031 T31 arg31) 7032 { 7033 return functor_( 7034 enqueueArgs, 7035 arg0, 7036 arg1, 7037 arg2, 7038 arg3, 7039 arg4, 7040 arg5, 7041 arg6, 7042 arg7, 7043 arg8, 7044 arg9, 7045 arg10, 7046 arg11, 7047 arg12, 7048 arg13, 7049 arg14, 7050 arg15, 7051 arg16, 7052 arg17, 7053 arg18, 7054 arg19, 7055 arg20, 7056 arg21, 7057 arg22, 7058 arg23, 7059 arg24, 7060 arg25, 7061 arg26, 7062 arg27, 7063 arg28, 7064 arg29, 7065 arg30, 7066 arg31); 7067 } 7068 7069 7070 }; 7071 7072 template< 7073 typename T0, 7074 typename T1, 7075 typename T2, 7076 typename T3, 7077 typename T4, 7078 typename T5, 7079 typename T6, 7080 typename T7, 7081 typename T8, 7082 typename T9, 7083 typename T10, 7084 typename T11, 7085 typename T12, 7086 typename T13, 7087 typename T14, 7088 typename T15, 7089 typename T16, 7090 typename T17, 7091 typename T18, 7092 typename T19, 7093 typename T20, 7094 typename T21, 7095 typename T22, 7096 typename T23, 7097 typename T24, 7098 typename T25, 7099 typename T26, 7100 typename T27, 7101 typename T28, 7102 typename T29, 7103 typename T30> 7104 struct functionImplementation_ 7105 < T0, 7106 T1, 7107 T2, 7108 T3, 7109 T4, 7110 T5, 7111 T6, 7112 T7, 7113 T8, 7114 T9, 7115 T10, 7116 T11, 7117 T12, 7118 T13, 7119 T14, 7120 T15, 7121 T16, 7122 T17, 7123 T18, 7124 T19, 7125 T20, 7126 T21, 7127 T22, 7128 T23, 7129 T24, 7130 T25, 7131 T26, 7132 T27, 7133 T28, 7134 T29, 7135 T30, 7136 NullType> 7137 { 7138 typedef detail::KernelFunctorGlobal< 7139 T0, 7140 T1, 7141 T2, 7142 T3, 7143 T4, 7144 T5, 7145 T6, 7146 T7, 7147 T8, 7148 T9, 7149 T10, 7150 T11, 7151 T12, 7152 T13, 7153 T14, 7154 T15, 7155 T16, 7156 T17, 7157 T18, 7158 T19, 7159 T20, 7160 T21, 7161 T22, 7162 T23, 7163 T24, 7164 T25, 7165 T26, 7166 T27, 7167 T28, 7168 T29, 7169 T30, 7170 NullType> FunctorType; 7171 7172 FunctorType functor_; 7173 7174 functionImplementation_(const FunctorType &functor) : 7175 functor_(functor) 7176 { 7177 7178 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 31)) 7179 // Fail variadic expansion for dev11 7180 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 7181 #endif 7182 7183 } 7184 7185 //! \brief Return type of the functor 7186 typedef Event result_type; 7187 7188 //! \brief Function signature of kernel functor with no event dependency. 7189 typedef Event type_( 7190 const EnqueueArgs&, 7191 T0, 7192 T1, 7193 T2, 7194 T3, 7195 T4, 7196 T5, 7197 T6, 7198 T7, 7199 T8, 7200 T9, 7201 T10, 7202 T11, 7203 T12, 7204 T13, 7205 T14, 7206 T15, 7207 T16, 7208 T17, 7209 T18, 7210 T19, 7211 T20, 7212 T21, 7213 T22, 7214 T23, 7215 T24, 7216 T25, 7217 T26, 7218 T27, 7219 T28, 7220 T29, 7221 T30); 7222 7223 Event operator()( 7224 const EnqueueArgs& enqueueArgs, 7225 T0 arg0, 7226 T1 arg1, 7227 T2 arg2, 7228 T3 arg3, 7229 T4 arg4, 7230 T5 arg5, 7231 T6 arg6, 7232 T7 arg7, 7233 T8 arg8, 7234 T9 arg9, 7235 T10 arg10, 7236 T11 arg11, 7237 T12 arg12, 7238 T13 arg13, 7239 T14 arg14, 7240 T15 arg15, 7241 T16 arg16, 7242 T17 arg17, 7243 T18 arg18, 7244 T19 arg19, 7245 T20 arg20, 7246 T21 arg21, 7247 T22 arg22, 7248 T23 arg23, 7249 T24 arg24, 7250 T25 arg25, 7251 T26 arg26, 7252 T27 arg27, 7253 T28 arg28, 7254 T29 arg29, 7255 T30 arg30) 7256 { 7257 return functor_( 7258 enqueueArgs, 7259 arg0, 7260 arg1, 7261 arg2, 7262 arg3, 7263 arg4, 7264 arg5, 7265 arg6, 7266 arg7, 7267 arg8, 7268 arg9, 7269 arg10, 7270 arg11, 7271 arg12, 7272 arg13, 7273 arg14, 7274 arg15, 7275 arg16, 7276 arg17, 7277 arg18, 7278 arg19, 7279 arg20, 7280 arg21, 7281 arg22, 7282 arg23, 7283 arg24, 7284 arg25, 7285 arg26, 7286 arg27, 7287 arg28, 7288 arg29, 7289 arg30); 7290 } 7291 7292 7293 }; 7294 7295 template< 7296 typename T0, 7297 typename T1, 7298 typename T2, 7299 typename T3, 7300 typename T4, 7301 typename T5, 7302 typename T6, 7303 typename T7, 7304 typename T8, 7305 typename T9, 7306 typename T10, 7307 typename T11, 7308 typename T12, 7309 typename T13, 7310 typename T14, 7311 typename T15, 7312 typename T16, 7313 typename T17, 7314 typename T18, 7315 typename T19, 7316 typename T20, 7317 typename T21, 7318 typename T22, 7319 typename T23, 7320 typename T24, 7321 typename T25, 7322 typename T26, 7323 typename T27, 7324 typename T28, 7325 typename T29> 7326 struct functionImplementation_ 7327 < T0, 7328 T1, 7329 T2, 7330 T3, 7331 T4, 7332 T5, 7333 T6, 7334 T7, 7335 T8, 7336 T9, 7337 T10, 7338 T11, 7339 T12, 7340 T13, 7341 T14, 7342 T15, 7343 T16, 7344 T17, 7345 T18, 7346 T19, 7347 T20, 7348 T21, 7349 T22, 7350 T23, 7351 T24, 7352 T25, 7353 T26, 7354 T27, 7355 T28, 7356 T29, 7357 NullType, 7358 NullType> 7359 { 7360 typedef detail::KernelFunctorGlobal< 7361 T0, 7362 T1, 7363 T2, 7364 T3, 7365 T4, 7366 T5, 7367 T6, 7368 T7, 7369 T8, 7370 T9, 7371 T10, 7372 T11, 7373 T12, 7374 T13, 7375 T14, 7376 T15, 7377 T16, 7378 T17, 7379 T18, 7380 T19, 7381 T20, 7382 T21, 7383 T22, 7384 T23, 7385 T24, 7386 T25, 7387 T26, 7388 T27, 7389 T28, 7390 T29, 7391 NullType, 7392 NullType> FunctorType; 7393 7394 FunctorType functor_; 7395 7396 functionImplementation_(const FunctorType &functor) : 7397 functor_(functor) 7398 { 7399 7400 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 30)) 7401 // Fail variadic expansion for dev11 7402 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 7403 #endif 7404 7405 } 7406 7407 //! \brief Return type of the functor 7408 typedef Event result_type; 7409 7410 //! \brief Function signature of kernel functor with no event dependency. 7411 typedef Event type_( 7412 const EnqueueArgs&, 7413 T0, 7414 T1, 7415 T2, 7416 T3, 7417 T4, 7418 T5, 7419 T6, 7420 T7, 7421 T8, 7422 T9, 7423 T10, 7424 T11, 7425 T12, 7426 T13, 7427 T14, 7428 T15, 7429 T16, 7430 T17, 7431 T18, 7432 T19, 7433 T20, 7434 T21, 7435 T22, 7436 T23, 7437 T24, 7438 T25, 7439 T26, 7440 T27, 7441 T28, 7442 T29); 7443 7444 Event operator()( 7445 const EnqueueArgs& enqueueArgs, 7446 T0 arg0, 7447 T1 arg1, 7448 T2 arg2, 7449 T3 arg3, 7450 T4 arg4, 7451 T5 arg5, 7452 T6 arg6, 7453 T7 arg7, 7454 T8 arg8, 7455 T9 arg9, 7456 T10 arg10, 7457 T11 arg11, 7458 T12 arg12, 7459 T13 arg13, 7460 T14 arg14, 7461 T15 arg15, 7462 T16 arg16, 7463 T17 arg17, 7464 T18 arg18, 7465 T19 arg19, 7466 T20 arg20, 7467 T21 arg21, 7468 T22 arg22, 7469 T23 arg23, 7470 T24 arg24, 7471 T25 arg25, 7472 T26 arg26, 7473 T27 arg27, 7474 T28 arg28, 7475 T29 arg29) 7476 { 7477 return functor_( 7478 enqueueArgs, 7479 arg0, 7480 arg1, 7481 arg2, 7482 arg3, 7483 arg4, 7484 arg5, 7485 arg6, 7486 arg7, 7487 arg8, 7488 arg9, 7489 arg10, 7490 arg11, 7491 arg12, 7492 arg13, 7493 arg14, 7494 arg15, 7495 arg16, 7496 arg17, 7497 arg18, 7498 arg19, 7499 arg20, 7500 arg21, 7501 arg22, 7502 arg23, 7503 arg24, 7504 arg25, 7505 arg26, 7506 arg27, 7507 arg28, 7508 arg29); 7509 } 7510 7511 7512 }; 7513 7514 template< 7515 typename T0, 7516 typename T1, 7517 typename T2, 7518 typename T3, 7519 typename T4, 7520 typename T5, 7521 typename T6, 7522 typename T7, 7523 typename T8, 7524 typename T9, 7525 typename T10, 7526 typename T11, 7527 typename T12, 7528 typename T13, 7529 typename T14, 7530 typename T15, 7531 typename T16, 7532 typename T17, 7533 typename T18, 7534 typename T19, 7535 typename T20, 7536 typename T21, 7537 typename T22, 7538 typename T23, 7539 typename T24, 7540 typename T25, 7541 typename T26, 7542 typename T27, 7543 typename T28> 7544 struct functionImplementation_ 7545 < T0, 7546 T1, 7547 T2, 7548 T3, 7549 T4, 7550 T5, 7551 T6, 7552 T7, 7553 T8, 7554 T9, 7555 T10, 7556 T11, 7557 T12, 7558 T13, 7559 T14, 7560 T15, 7561 T16, 7562 T17, 7563 T18, 7564 T19, 7565 T20, 7566 T21, 7567 T22, 7568 T23, 7569 T24, 7570 T25, 7571 T26, 7572 T27, 7573 T28, 7574 NullType, 7575 NullType, 7576 NullType> 7577 { 7578 typedef detail::KernelFunctorGlobal< 7579 T0, 7580 T1, 7581 T2, 7582 T3, 7583 T4, 7584 T5, 7585 T6, 7586 T7, 7587 T8, 7588 T9, 7589 T10, 7590 T11, 7591 T12, 7592 T13, 7593 T14, 7594 T15, 7595 T16, 7596 T17, 7597 T18, 7598 T19, 7599 T20, 7600 T21, 7601 T22, 7602 T23, 7603 T24, 7604 T25, 7605 T26, 7606 T27, 7607 T28, 7608 NullType, 7609 NullType, 7610 NullType> FunctorType; 7611 7612 FunctorType functor_; 7613 7614 functionImplementation_(const FunctorType &functor) : 7615 functor_(functor) 7616 { 7617 7618 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 29)) 7619 // Fail variadic expansion for dev11 7620 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 7621 #endif 7622 7623 } 7624 7625 //! \brief Return type of the functor 7626 typedef Event result_type; 7627 7628 //! \brief Function signature of kernel functor with no event dependency. 7629 typedef Event type_( 7630 const EnqueueArgs&, 7631 T0, 7632 T1, 7633 T2, 7634 T3, 7635 T4, 7636 T5, 7637 T6, 7638 T7, 7639 T8, 7640 T9, 7641 T10, 7642 T11, 7643 T12, 7644 T13, 7645 T14, 7646 T15, 7647 T16, 7648 T17, 7649 T18, 7650 T19, 7651 T20, 7652 T21, 7653 T22, 7654 T23, 7655 T24, 7656 T25, 7657 T26, 7658 T27, 7659 T28); 7660 7661 Event operator()( 7662 const EnqueueArgs& enqueueArgs, 7663 T0 arg0, 7664 T1 arg1, 7665 T2 arg2, 7666 T3 arg3, 7667 T4 arg4, 7668 T5 arg5, 7669 T6 arg6, 7670 T7 arg7, 7671 T8 arg8, 7672 T9 arg9, 7673 T10 arg10, 7674 T11 arg11, 7675 T12 arg12, 7676 T13 arg13, 7677 T14 arg14, 7678 T15 arg15, 7679 T16 arg16, 7680 T17 arg17, 7681 T18 arg18, 7682 T19 arg19, 7683 T20 arg20, 7684 T21 arg21, 7685 T22 arg22, 7686 T23 arg23, 7687 T24 arg24, 7688 T25 arg25, 7689 T26 arg26, 7690 T27 arg27, 7691 T28 arg28) 7692 { 7693 return functor_( 7694 enqueueArgs, 7695 arg0, 7696 arg1, 7697 arg2, 7698 arg3, 7699 arg4, 7700 arg5, 7701 arg6, 7702 arg7, 7703 arg8, 7704 arg9, 7705 arg10, 7706 arg11, 7707 arg12, 7708 arg13, 7709 arg14, 7710 arg15, 7711 arg16, 7712 arg17, 7713 arg18, 7714 arg19, 7715 arg20, 7716 arg21, 7717 arg22, 7718 arg23, 7719 arg24, 7720 arg25, 7721 arg26, 7722 arg27, 7723 arg28); 7724 } 7725 7726 7727 }; 7728 7729 template< 7730 typename T0, 7731 typename T1, 7732 typename T2, 7733 typename T3, 7734 typename T4, 7735 typename T5, 7736 typename T6, 7737 typename T7, 7738 typename T8, 7739 typename T9, 7740 typename T10, 7741 typename T11, 7742 typename T12, 7743 typename T13, 7744 typename T14, 7745 typename T15, 7746 typename T16, 7747 typename T17, 7748 typename T18, 7749 typename T19, 7750 typename T20, 7751 typename T21, 7752 typename T22, 7753 typename T23, 7754 typename T24, 7755 typename T25, 7756 typename T26, 7757 typename T27> 7758 struct functionImplementation_ 7759 < T0, 7760 T1, 7761 T2, 7762 T3, 7763 T4, 7764 T5, 7765 T6, 7766 T7, 7767 T8, 7768 T9, 7769 T10, 7770 T11, 7771 T12, 7772 T13, 7773 T14, 7774 T15, 7775 T16, 7776 T17, 7777 T18, 7778 T19, 7779 T20, 7780 T21, 7781 T22, 7782 T23, 7783 T24, 7784 T25, 7785 T26, 7786 T27, 7787 NullType, 7788 NullType, 7789 NullType, 7790 NullType> 7791 { 7792 typedef detail::KernelFunctorGlobal< 7793 T0, 7794 T1, 7795 T2, 7796 T3, 7797 T4, 7798 T5, 7799 T6, 7800 T7, 7801 T8, 7802 T9, 7803 T10, 7804 T11, 7805 T12, 7806 T13, 7807 T14, 7808 T15, 7809 T16, 7810 T17, 7811 T18, 7812 T19, 7813 T20, 7814 T21, 7815 T22, 7816 T23, 7817 T24, 7818 T25, 7819 T26, 7820 T27, 7821 NullType, 7822 NullType, 7823 NullType, 7824 NullType> FunctorType; 7825 7826 FunctorType functor_; 7827 7828 functionImplementation_(const FunctorType &functor) : 7829 functor_(functor) 7830 { 7831 7832 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 28)) 7833 // Fail variadic expansion for dev11 7834 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 7835 #endif 7836 7837 } 7838 7839 //! \brief Return type of the functor 7840 typedef Event result_type; 7841 7842 //! \brief Function signature of kernel functor with no event dependency. 7843 typedef Event type_( 7844 const EnqueueArgs&, 7845 T0, 7846 T1, 7847 T2, 7848 T3, 7849 T4, 7850 T5, 7851 T6, 7852 T7, 7853 T8, 7854 T9, 7855 T10, 7856 T11, 7857 T12, 7858 T13, 7859 T14, 7860 T15, 7861 T16, 7862 T17, 7863 T18, 7864 T19, 7865 T20, 7866 T21, 7867 T22, 7868 T23, 7869 T24, 7870 T25, 7871 T26, 7872 T27); 7873 7874 Event operator()( 7875 const EnqueueArgs& enqueueArgs, 7876 T0 arg0, 7877 T1 arg1, 7878 T2 arg2, 7879 T3 arg3, 7880 T4 arg4, 7881 T5 arg5, 7882 T6 arg6, 7883 T7 arg7, 7884 T8 arg8, 7885 T9 arg9, 7886 T10 arg10, 7887 T11 arg11, 7888 T12 arg12, 7889 T13 arg13, 7890 T14 arg14, 7891 T15 arg15, 7892 T16 arg16, 7893 T17 arg17, 7894 T18 arg18, 7895 T19 arg19, 7896 T20 arg20, 7897 T21 arg21, 7898 T22 arg22, 7899 T23 arg23, 7900 T24 arg24, 7901 T25 arg25, 7902 T26 arg26, 7903 T27 arg27) 7904 { 7905 return functor_( 7906 enqueueArgs, 7907 arg0, 7908 arg1, 7909 arg2, 7910 arg3, 7911 arg4, 7912 arg5, 7913 arg6, 7914 arg7, 7915 arg8, 7916 arg9, 7917 arg10, 7918 arg11, 7919 arg12, 7920 arg13, 7921 arg14, 7922 arg15, 7923 arg16, 7924 arg17, 7925 arg18, 7926 arg19, 7927 arg20, 7928 arg21, 7929 arg22, 7930 arg23, 7931 arg24, 7932 arg25, 7933 arg26, 7934 arg27); 7935 } 7936 7937 7938 }; 7939 7940 template< 7941 typename T0, 7942 typename T1, 7943 typename T2, 7944 typename T3, 7945 typename T4, 7946 typename T5, 7947 typename T6, 7948 typename T7, 7949 typename T8, 7950 typename T9, 7951 typename T10, 7952 typename T11, 7953 typename T12, 7954 typename T13, 7955 typename T14, 7956 typename T15, 7957 typename T16, 7958 typename T17, 7959 typename T18, 7960 typename T19, 7961 typename T20, 7962 typename T21, 7963 typename T22, 7964 typename T23, 7965 typename T24, 7966 typename T25, 7967 typename T26> 7968 struct functionImplementation_ 7969 < T0, 7970 T1, 7971 T2, 7972 T3, 7973 T4, 7974 T5, 7975 T6, 7976 T7, 7977 T8, 7978 T9, 7979 T10, 7980 T11, 7981 T12, 7982 T13, 7983 T14, 7984 T15, 7985 T16, 7986 T17, 7987 T18, 7988 T19, 7989 T20, 7990 T21, 7991 T22, 7992 T23, 7993 T24, 7994 T25, 7995 T26, 7996 NullType, 7997 NullType, 7998 NullType, 7999 NullType, 8000 NullType> 8001 { 8002 typedef detail::KernelFunctorGlobal< 8003 T0, 8004 T1, 8005 T2, 8006 T3, 8007 T4, 8008 T5, 8009 T6, 8010 T7, 8011 T8, 8012 T9, 8013 T10, 8014 T11, 8015 T12, 8016 T13, 8017 T14, 8018 T15, 8019 T16, 8020 T17, 8021 T18, 8022 T19, 8023 T20, 8024 T21, 8025 T22, 8026 T23, 8027 T24, 8028 T25, 8029 T26, 8030 NullType, 8031 NullType, 8032 NullType, 8033 NullType, 8034 NullType> FunctorType; 8035 8036 FunctorType functor_; 8037 8038 functionImplementation_(const FunctorType &functor) : 8039 functor_(functor) 8040 { 8041 8042 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 27)) 8043 // Fail variadic expansion for dev11 8044 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 8045 #endif 8046 8047 } 8048 8049 //! \brief Return type of the functor 8050 typedef Event result_type; 8051 8052 //! \brief Function signature of kernel functor with no event dependency. 8053 typedef Event type_( 8054 const EnqueueArgs&, 8055 T0, 8056 T1, 8057 T2, 8058 T3, 8059 T4, 8060 T5, 8061 T6, 8062 T7, 8063 T8, 8064 T9, 8065 T10, 8066 T11, 8067 T12, 8068 T13, 8069 T14, 8070 T15, 8071 T16, 8072 T17, 8073 T18, 8074 T19, 8075 T20, 8076 T21, 8077 T22, 8078 T23, 8079 T24, 8080 T25, 8081 T26); 8082 8083 Event operator()( 8084 const EnqueueArgs& enqueueArgs, 8085 T0 arg0, 8086 T1 arg1, 8087 T2 arg2, 8088 T3 arg3, 8089 T4 arg4, 8090 T5 arg5, 8091 T6 arg6, 8092 T7 arg7, 8093 T8 arg8, 8094 T9 arg9, 8095 T10 arg10, 8096 T11 arg11, 8097 T12 arg12, 8098 T13 arg13, 8099 T14 arg14, 8100 T15 arg15, 8101 T16 arg16, 8102 T17 arg17, 8103 T18 arg18, 8104 T19 arg19, 8105 T20 arg20, 8106 T21 arg21, 8107 T22 arg22, 8108 T23 arg23, 8109 T24 arg24, 8110 T25 arg25, 8111 T26 arg26) 8112 { 8113 return functor_( 8114 enqueueArgs, 8115 arg0, 8116 arg1, 8117 arg2, 8118 arg3, 8119 arg4, 8120 arg5, 8121 arg6, 8122 arg7, 8123 arg8, 8124 arg9, 8125 arg10, 8126 arg11, 8127 arg12, 8128 arg13, 8129 arg14, 8130 arg15, 8131 arg16, 8132 arg17, 8133 arg18, 8134 arg19, 8135 arg20, 8136 arg21, 8137 arg22, 8138 arg23, 8139 arg24, 8140 arg25, 8141 arg26); 8142 } 8143 8144 8145 }; 8146 8147 template< 8148 typename T0, 8149 typename T1, 8150 typename T2, 8151 typename T3, 8152 typename T4, 8153 typename T5, 8154 typename T6, 8155 typename T7, 8156 typename T8, 8157 typename T9, 8158 typename T10, 8159 typename T11, 8160 typename T12, 8161 typename T13, 8162 typename T14, 8163 typename T15, 8164 typename T16, 8165 typename T17, 8166 typename T18, 8167 typename T19, 8168 typename T20, 8169 typename T21, 8170 typename T22, 8171 typename T23, 8172 typename T24, 8173 typename T25> 8174 struct functionImplementation_ 8175 < T0, 8176 T1, 8177 T2, 8178 T3, 8179 T4, 8180 T5, 8181 T6, 8182 T7, 8183 T8, 8184 T9, 8185 T10, 8186 T11, 8187 T12, 8188 T13, 8189 T14, 8190 T15, 8191 T16, 8192 T17, 8193 T18, 8194 T19, 8195 T20, 8196 T21, 8197 T22, 8198 T23, 8199 T24, 8200 T25, 8201 NullType, 8202 NullType, 8203 NullType, 8204 NullType, 8205 NullType, 8206 NullType> 8207 { 8208 typedef detail::KernelFunctorGlobal< 8209 T0, 8210 T1, 8211 T2, 8212 T3, 8213 T4, 8214 T5, 8215 T6, 8216 T7, 8217 T8, 8218 T9, 8219 T10, 8220 T11, 8221 T12, 8222 T13, 8223 T14, 8224 T15, 8225 T16, 8226 T17, 8227 T18, 8228 T19, 8229 T20, 8230 T21, 8231 T22, 8232 T23, 8233 T24, 8234 T25, 8235 NullType, 8236 NullType, 8237 NullType, 8238 NullType, 8239 NullType, 8240 NullType> FunctorType; 8241 8242 FunctorType functor_; 8243 8244 functionImplementation_(const FunctorType &functor) : 8245 functor_(functor) 8246 { 8247 8248 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 26)) 8249 // Fail variadic expansion for dev11 8250 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 8251 #endif 8252 8253 } 8254 8255 //! \brief Return type of the functor 8256 typedef Event result_type; 8257 8258 //! \brief Function signature of kernel functor with no event dependency. 8259 typedef Event type_( 8260 const EnqueueArgs&, 8261 T0, 8262 T1, 8263 T2, 8264 T3, 8265 T4, 8266 T5, 8267 T6, 8268 T7, 8269 T8, 8270 T9, 8271 T10, 8272 T11, 8273 T12, 8274 T13, 8275 T14, 8276 T15, 8277 T16, 8278 T17, 8279 T18, 8280 T19, 8281 T20, 8282 T21, 8283 T22, 8284 T23, 8285 T24, 8286 T25); 8287 8288 Event operator()( 8289 const EnqueueArgs& enqueueArgs, 8290 T0 arg0, 8291 T1 arg1, 8292 T2 arg2, 8293 T3 arg3, 8294 T4 arg4, 8295 T5 arg5, 8296 T6 arg6, 8297 T7 arg7, 8298 T8 arg8, 8299 T9 arg9, 8300 T10 arg10, 8301 T11 arg11, 8302 T12 arg12, 8303 T13 arg13, 8304 T14 arg14, 8305 T15 arg15, 8306 T16 arg16, 8307 T17 arg17, 8308 T18 arg18, 8309 T19 arg19, 8310 T20 arg20, 8311 T21 arg21, 8312 T22 arg22, 8313 T23 arg23, 8314 T24 arg24, 8315 T25 arg25) 8316 { 8317 return functor_( 8318 enqueueArgs, 8319 arg0, 8320 arg1, 8321 arg2, 8322 arg3, 8323 arg4, 8324 arg5, 8325 arg6, 8326 arg7, 8327 arg8, 8328 arg9, 8329 arg10, 8330 arg11, 8331 arg12, 8332 arg13, 8333 arg14, 8334 arg15, 8335 arg16, 8336 arg17, 8337 arg18, 8338 arg19, 8339 arg20, 8340 arg21, 8341 arg22, 8342 arg23, 8343 arg24, 8344 arg25); 8345 } 8346 8347 8348 }; 8349 8350 template< 8351 typename T0, 8352 typename T1, 8353 typename T2, 8354 typename T3, 8355 typename T4, 8356 typename T5, 8357 typename T6, 8358 typename T7, 8359 typename T8, 8360 typename T9, 8361 typename T10, 8362 typename T11, 8363 typename T12, 8364 typename T13, 8365 typename T14, 8366 typename T15, 8367 typename T16, 8368 typename T17, 8369 typename T18, 8370 typename T19, 8371 typename T20, 8372 typename T21, 8373 typename T22, 8374 typename T23, 8375 typename T24> 8376 struct functionImplementation_ 8377 < T0, 8378 T1, 8379 T2, 8380 T3, 8381 T4, 8382 T5, 8383 T6, 8384 T7, 8385 T8, 8386 T9, 8387 T10, 8388 T11, 8389 T12, 8390 T13, 8391 T14, 8392 T15, 8393 T16, 8394 T17, 8395 T18, 8396 T19, 8397 T20, 8398 T21, 8399 T22, 8400 T23, 8401 T24, 8402 NullType, 8403 NullType, 8404 NullType, 8405 NullType, 8406 NullType, 8407 NullType, 8408 NullType> 8409 { 8410 typedef detail::KernelFunctorGlobal< 8411 T0, 8412 T1, 8413 T2, 8414 T3, 8415 T4, 8416 T5, 8417 T6, 8418 T7, 8419 T8, 8420 T9, 8421 T10, 8422 T11, 8423 T12, 8424 T13, 8425 T14, 8426 T15, 8427 T16, 8428 T17, 8429 T18, 8430 T19, 8431 T20, 8432 T21, 8433 T22, 8434 T23, 8435 T24, 8436 NullType, 8437 NullType, 8438 NullType, 8439 NullType, 8440 NullType, 8441 NullType, 8442 NullType> FunctorType; 8443 8444 FunctorType functor_; 8445 8446 functionImplementation_(const FunctorType &functor) : 8447 functor_(functor) 8448 { 8449 8450 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 25)) 8451 // Fail variadic expansion for dev11 8452 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 8453 #endif 8454 8455 } 8456 8457 //! \brief Return type of the functor 8458 typedef Event result_type; 8459 8460 //! \brief Function signature of kernel functor with no event dependency. 8461 typedef Event type_( 8462 const EnqueueArgs&, 8463 T0, 8464 T1, 8465 T2, 8466 T3, 8467 T4, 8468 T5, 8469 T6, 8470 T7, 8471 T8, 8472 T9, 8473 T10, 8474 T11, 8475 T12, 8476 T13, 8477 T14, 8478 T15, 8479 T16, 8480 T17, 8481 T18, 8482 T19, 8483 T20, 8484 T21, 8485 T22, 8486 T23, 8487 T24); 8488 8489 Event operator()( 8490 const EnqueueArgs& enqueueArgs, 8491 T0 arg0, 8492 T1 arg1, 8493 T2 arg2, 8494 T3 arg3, 8495 T4 arg4, 8496 T5 arg5, 8497 T6 arg6, 8498 T7 arg7, 8499 T8 arg8, 8500 T9 arg9, 8501 T10 arg10, 8502 T11 arg11, 8503 T12 arg12, 8504 T13 arg13, 8505 T14 arg14, 8506 T15 arg15, 8507 T16 arg16, 8508 T17 arg17, 8509 T18 arg18, 8510 T19 arg19, 8511 T20 arg20, 8512 T21 arg21, 8513 T22 arg22, 8514 T23 arg23, 8515 T24 arg24) 8516 { 8517 return functor_( 8518 enqueueArgs, 8519 arg0, 8520 arg1, 8521 arg2, 8522 arg3, 8523 arg4, 8524 arg5, 8525 arg6, 8526 arg7, 8527 arg8, 8528 arg9, 8529 arg10, 8530 arg11, 8531 arg12, 8532 arg13, 8533 arg14, 8534 arg15, 8535 arg16, 8536 arg17, 8537 arg18, 8538 arg19, 8539 arg20, 8540 arg21, 8541 arg22, 8542 arg23, 8543 arg24); 8544 } 8545 8546 8547 }; 8548 8549 template< 8550 typename T0, 8551 typename T1, 8552 typename T2, 8553 typename T3, 8554 typename T4, 8555 typename T5, 8556 typename T6, 8557 typename T7, 8558 typename T8, 8559 typename T9, 8560 typename T10, 8561 typename T11, 8562 typename T12, 8563 typename T13, 8564 typename T14, 8565 typename T15, 8566 typename T16, 8567 typename T17, 8568 typename T18, 8569 typename T19, 8570 typename T20, 8571 typename T21, 8572 typename T22, 8573 typename T23> 8574 struct functionImplementation_ 8575 < T0, 8576 T1, 8577 T2, 8578 T3, 8579 T4, 8580 T5, 8581 T6, 8582 T7, 8583 T8, 8584 T9, 8585 T10, 8586 T11, 8587 T12, 8588 T13, 8589 T14, 8590 T15, 8591 T16, 8592 T17, 8593 T18, 8594 T19, 8595 T20, 8596 T21, 8597 T22, 8598 T23, 8599 NullType, 8600 NullType, 8601 NullType, 8602 NullType, 8603 NullType, 8604 NullType, 8605 NullType, 8606 NullType> 8607 { 8608 typedef detail::KernelFunctorGlobal< 8609 T0, 8610 T1, 8611 T2, 8612 T3, 8613 T4, 8614 T5, 8615 T6, 8616 T7, 8617 T8, 8618 T9, 8619 T10, 8620 T11, 8621 T12, 8622 T13, 8623 T14, 8624 T15, 8625 T16, 8626 T17, 8627 T18, 8628 T19, 8629 T20, 8630 T21, 8631 T22, 8632 T23, 8633 NullType, 8634 NullType, 8635 NullType, 8636 NullType, 8637 NullType, 8638 NullType, 8639 NullType, 8640 NullType> FunctorType; 8641 8642 FunctorType functor_; 8643 8644 functionImplementation_(const FunctorType &functor) : 8645 functor_(functor) 8646 { 8647 8648 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 24)) 8649 // Fail variadic expansion for dev11 8650 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 8651 #endif 8652 8653 } 8654 8655 //! \brief Return type of the functor 8656 typedef Event result_type; 8657 8658 //! \brief Function signature of kernel functor with no event dependency. 8659 typedef Event type_( 8660 const EnqueueArgs&, 8661 T0, 8662 T1, 8663 T2, 8664 T3, 8665 T4, 8666 T5, 8667 T6, 8668 T7, 8669 T8, 8670 T9, 8671 T10, 8672 T11, 8673 T12, 8674 T13, 8675 T14, 8676 T15, 8677 T16, 8678 T17, 8679 T18, 8680 T19, 8681 T20, 8682 T21, 8683 T22, 8684 T23); 8685 8686 Event operator()( 8687 const EnqueueArgs& enqueueArgs, 8688 T0 arg0, 8689 T1 arg1, 8690 T2 arg2, 8691 T3 arg3, 8692 T4 arg4, 8693 T5 arg5, 8694 T6 arg6, 8695 T7 arg7, 8696 T8 arg8, 8697 T9 arg9, 8698 T10 arg10, 8699 T11 arg11, 8700 T12 arg12, 8701 T13 arg13, 8702 T14 arg14, 8703 T15 arg15, 8704 T16 arg16, 8705 T17 arg17, 8706 T18 arg18, 8707 T19 arg19, 8708 T20 arg20, 8709 T21 arg21, 8710 T22 arg22, 8711 T23 arg23) 8712 { 8713 return functor_( 8714 enqueueArgs, 8715 arg0, 8716 arg1, 8717 arg2, 8718 arg3, 8719 arg4, 8720 arg5, 8721 arg6, 8722 arg7, 8723 arg8, 8724 arg9, 8725 arg10, 8726 arg11, 8727 arg12, 8728 arg13, 8729 arg14, 8730 arg15, 8731 arg16, 8732 arg17, 8733 arg18, 8734 arg19, 8735 arg20, 8736 arg21, 8737 arg22, 8738 arg23); 8739 } 8740 8741 8742 }; 8743 8744 template< 8745 typename T0, 8746 typename T1, 8747 typename T2, 8748 typename T3, 8749 typename T4, 8750 typename T5, 8751 typename T6, 8752 typename T7, 8753 typename T8, 8754 typename T9, 8755 typename T10, 8756 typename T11, 8757 typename T12, 8758 typename T13, 8759 typename T14, 8760 typename T15, 8761 typename T16, 8762 typename T17, 8763 typename T18, 8764 typename T19, 8765 typename T20, 8766 typename T21, 8767 typename T22> 8768 struct functionImplementation_ 8769 < T0, 8770 T1, 8771 T2, 8772 T3, 8773 T4, 8774 T5, 8775 T6, 8776 T7, 8777 T8, 8778 T9, 8779 T10, 8780 T11, 8781 T12, 8782 T13, 8783 T14, 8784 T15, 8785 T16, 8786 T17, 8787 T18, 8788 T19, 8789 T20, 8790 T21, 8791 T22, 8792 NullType, 8793 NullType, 8794 NullType, 8795 NullType, 8796 NullType, 8797 NullType, 8798 NullType, 8799 NullType, 8800 NullType> 8801 { 8802 typedef detail::KernelFunctorGlobal< 8803 T0, 8804 T1, 8805 T2, 8806 T3, 8807 T4, 8808 T5, 8809 T6, 8810 T7, 8811 T8, 8812 T9, 8813 T10, 8814 T11, 8815 T12, 8816 T13, 8817 T14, 8818 T15, 8819 T16, 8820 T17, 8821 T18, 8822 T19, 8823 T20, 8824 T21, 8825 T22, 8826 NullType, 8827 NullType, 8828 NullType, 8829 NullType, 8830 NullType, 8831 NullType, 8832 NullType, 8833 NullType, 8834 NullType> FunctorType; 8835 8836 FunctorType functor_; 8837 8838 functionImplementation_(const FunctorType &functor) : 8839 functor_(functor) 8840 { 8841 8842 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 23)) 8843 // Fail variadic expansion for dev11 8844 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 8845 #endif 8846 8847 } 8848 8849 //! \brief Return type of the functor 8850 typedef Event result_type; 8851 8852 //! \brief Function signature of kernel functor with no event dependency. 8853 typedef Event type_( 8854 const EnqueueArgs&, 8855 T0, 8856 T1, 8857 T2, 8858 T3, 8859 T4, 8860 T5, 8861 T6, 8862 T7, 8863 T8, 8864 T9, 8865 T10, 8866 T11, 8867 T12, 8868 T13, 8869 T14, 8870 T15, 8871 T16, 8872 T17, 8873 T18, 8874 T19, 8875 T20, 8876 T21, 8877 T22); 8878 8879 Event operator()( 8880 const EnqueueArgs& enqueueArgs, 8881 T0 arg0, 8882 T1 arg1, 8883 T2 arg2, 8884 T3 arg3, 8885 T4 arg4, 8886 T5 arg5, 8887 T6 arg6, 8888 T7 arg7, 8889 T8 arg8, 8890 T9 arg9, 8891 T10 arg10, 8892 T11 arg11, 8893 T12 arg12, 8894 T13 arg13, 8895 T14 arg14, 8896 T15 arg15, 8897 T16 arg16, 8898 T17 arg17, 8899 T18 arg18, 8900 T19 arg19, 8901 T20 arg20, 8902 T21 arg21, 8903 T22 arg22) 8904 { 8905 return functor_( 8906 enqueueArgs, 8907 arg0, 8908 arg1, 8909 arg2, 8910 arg3, 8911 arg4, 8912 arg5, 8913 arg6, 8914 arg7, 8915 arg8, 8916 arg9, 8917 arg10, 8918 arg11, 8919 arg12, 8920 arg13, 8921 arg14, 8922 arg15, 8923 arg16, 8924 arg17, 8925 arg18, 8926 arg19, 8927 arg20, 8928 arg21, 8929 arg22); 8930 } 8931 8932 8933 }; 8934 8935 template< 8936 typename T0, 8937 typename T1, 8938 typename T2, 8939 typename T3, 8940 typename T4, 8941 typename T5, 8942 typename T6, 8943 typename T7, 8944 typename T8, 8945 typename T9, 8946 typename T10, 8947 typename T11, 8948 typename T12, 8949 typename T13, 8950 typename T14, 8951 typename T15, 8952 typename T16, 8953 typename T17, 8954 typename T18, 8955 typename T19, 8956 typename T20, 8957 typename T21> 8958 struct functionImplementation_ 8959 < T0, 8960 T1, 8961 T2, 8962 T3, 8963 T4, 8964 T5, 8965 T6, 8966 T7, 8967 T8, 8968 T9, 8969 T10, 8970 T11, 8971 T12, 8972 T13, 8973 T14, 8974 T15, 8975 T16, 8976 T17, 8977 T18, 8978 T19, 8979 T20, 8980 T21, 8981 NullType, 8982 NullType, 8983 NullType, 8984 NullType, 8985 NullType, 8986 NullType, 8987 NullType, 8988 NullType, 8989 NullType, 8990 NullType> 8991 { 8992 typedef detail::KernelFunctorGlobal< 8993 T0, 8994 T1, 8995 T2, 8996 T3, 8997 T4, 8998 T5, 8999 T6, 9000 T7, 9001 T8, 9002 T9, 9003 T10, 9004 T11, 9005 T12, 9006 T13, 9007 T14, 9008 T15, 9009 T16, 9010 T17, 9011 T18, 9012 T19, 9013 T20, 9014 T21, 9015 NullType, 9016 NullType, 9017 NullType, 9018 NullType, 9019 NullType, 9020 NullType, 9021 NullType, 9022 NullType, 9023 NullType, 9024 NullType> FunctorType; 9025 9026 FunctorType functor_; 9027 9028 functionImplementation_(const FunctorType &functor) : 9029 functor_(functor) 9030 { 9031 9032 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 22)) 9033 // Fail variadic expansion for dev11 9034 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 9035 #endif 9036 9037 } 9038 9039 //! \brief Return type of the functor 9040 typedef Event result_type; 9041 9042 //! \brief Function signature of kernel functor with no event dependency. 9043 typedef Event type_( 9044 const EnqueueArgs&, 9045 T0, 9046 T1, 9047 T2, 9048 T3, 9049 T4, 9050 T5, 9051 T6, 9052 T7, 9053 T8, 9054 T9, 9055 T10, 9056 T11, 9057 T12, 9058 T13, 9059 T14, 9060 T15, 9061 T16, 9062 T17, 9063 T18, 9064 T19, 9065 T20, 9066 T21); 9067 9068 Event operator()( 9069 const EnqueueArgs& enqueueArgs, 9070 T0 arg0, 9071 T1 arg1, 9072 T2 arg2, 9073 T3 arg3, 9074 T4 arg4, 9075 T5 arg5, 9076 T6 arg6, 9077 T7 arg7, 9078 T8 arg8, 9079 T9 arg9, 9080 T10 arg10, 9081 T11 arg11, 9082 T12 arg12, 9083 T13 arg13, 9084 T14 arg14, 9085 T15 arg15, 9086 T16 arg16, 9087 T17 arg17, 9088 T18 arg18, 9089 T19 arg19, 9090 T20 arg20, 9091 T21 arg21) 9092 { 9093 return functor_( 9094 enqueueArgs, 9095 arg0, 9096 arg1, 9097 arg2, 9098 arg3, 9099 arg4, 9100 arg5, 9101 arg6, 9102 arg7, 9103 arg8, 9104 arg9, 9105 arg10, 9106 arg11, 9107 arg12, 9108 arg13, 9109 arg14, 9110 arg15, 9111 arg16, 9112 arg17, 9113 arg18, 9114 arg19, 9115 arg20, 9116 arg21); 9117 } 9118 9119 9120 }; 9121 9122 template< 9123 typename T0, 9124 typename T1, 9125 typename T2, 9126 typename T3, 9127 typename T4, 9128 typename T5, 9129 typename T6, 9130 typename T7, 9131 typename T8, 9132 typename T9, 9133 typename T10, 9134 typename T11, 9135 typename T12, 9136 typename T13, 9137 typename T14, 9138 typename T15, 9139 typename T16, 9140 typename T17, 9141 typename T18, 9142 typename T19, 9143 typename T20> 9144 struct functionImplementation_ 9145 < T0, 9146 T1, 9147 T2, 9148 T3, 9149 T4, 9150 T5, 9151 T6, 9152 T7, 9153 T8, 9154 T9, 9155 T10, 9156 T11, 9157 T12, 9158 T13, 9159 T14, 9160 T15, 9161 T16, 9162 T17, 9163 T18, 9164 T19, 9165 T20, 9166 NullType, 9167 NullType, 9168 NullType, 9169 NullType, 9170 NullType, 9171 NullType, 9172 NullType, 9173 NullType, 9174 NullType, 9175 NullType, 9176 NullType> 9177 { 9178 typedef detail::KernelFunctorGlobal< 9179 T0, 9180 T1, 9181 T2, 9182 T3, 9183 T4, 9184 T5, 9185 T6, 9186 T7, 9187 T8, 9188 T9, 9189 T10, 9190 T11, 9191 T12, 9192 T13, 9193 T14, 9194 T15, 9195 T16, 9196 T17, 9197 T18, 9198 T19, 9199 T20, 9200 NullType, 9201 NullType, 9202 NullType, 9203 NullType, 9204 NullType, 9205 NullType, 9206 NullType, 9207 NullType, 9208 NullType, 9209 NullType, 9210 NullType> FunctorType; 9211 9212 FunctorType functor_; 9213 9214 functionImplementation_(const FunctorType &functor) : 9215 functor_(functor) 9216 { 9217 9218 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 21)) 9219 // Fail variadic expansion for dev11 9220 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 9221 #endif 9222 9223 } 9224 9225 //! \brief Return type of the functor 9226 typedef Event result_type; 9227 9228 //! \brief Function signature of kernel functor with no event dependency. 9229 typedef Event type_( 9230 const EnqueueArgs&, 9231 T0, 9232 T1, 9233 T2, 9234 T3, 9235 T4, 9236 T5, 9237 T6, 9238 T7, 9239 T8, 9240 T9, 9241 T10, 9242 T11, 9243 T12, 9244 T13, 9245 T14, 9246 T15, 9247 T16, 9248 T17, 9249 T18, 9250 T19, 9251 T20); 9252 9253 Event operator()( 9254 const EnqueueArgs& enqueueArgs, 9255 T0 arg0, 9256 T1 arg1, 9257 T2 arg2, 9258 T3 arg3, 9259 T4 arg4, 9260 T5 arg5, 9261 T6 arg6, 9262 T7 arg7, 9263 T8 arg8, 9264 T9 arg9, 9265 T10 arg10, 9266 T11 arg11, 9267 T12 arg12, 9268 T13 arg13, 9269 T14 arg14, 9270 T15 arg15, 9271 T16 arg16, 9272 T17 arg17, 9273 T18 arg18, 9274 T19 arg19, 9275 T20 arg20) 9276 { 9277 return functor_( 9278 enqueueArgs, 9279 arg0, 9280 arg1, 9281 arg2, 9282 arg3, 9283 arg4, 9284 arg5, 9285 arg6, 9286 arg7, 9287 arg8, 9288 arg9, 9289 arg10, 9290 arg11, 9291 arg12, 9292 arg13, 9293 arg14, 9294 arg15, 9295 arg16, 9296 arg17, 9297 arg18, 9298 arg19, 9299 arg20); 9300 } 9301 9302 9303 }; 9304 9305 template< 9306 typename T0, 9307 typename T1, 9308 typename T2, 9309 typename T3, 9310 typename T4, 9311 typename T5, 9312 typename T6, 9313 typename T7, 9314 typename T8, 9315 typename T9, 9316 typename T10, 9317 typename T11, 9318 typename T12, 9319 typename T13, 9320 typename T14, 9321 typename T15, 9322 typename T16, 9323 typename T17, 9324 typename T18, 9325 typename T19> 9326 struct functionImplementation_ 9327 < T0, 9328 T1, 9329 T2, 9330 T3, 9331 T4, 9332 T5, 9333 T6, 9334 T7, 9335 T8, 9336 T9, 9337 T10, 9338 T11, 9339 T12, 9340 T13, 9341 T14, 9342 T15, 9343 T16, 9344 T17, 9345 T18, 9346 T19, 9347 NullType, 9348 NullType, 9349 NullType, 9350 NullType, 9351 NullType, 9352 NullType, 9353 NullType, 9354 NullType, 9355 NullType, 9356 NullType, 9357 NullType, 9358 NullType> 9359 { 9360 typedef detail::KernelFunctorGlobal< 9361 T0, 9362 T1, 9363 T2, 9364 T3, 9365 T4, 9366 T5, 9367 T6, 9368 T7, 9369 T8, 9370 T9, 9371 T10, 9372 T11, 9373 T12, 9374 T13, 9375 T14, 9376 T15, 9377 T16, 9378 T17, 9379 T18, 9380 T19, 9381 NullType, 9382 NullType, 9383 NullType, 9384 NullType, 9385 NullType, 9386 NullType, 9387 NullType, 9388 NullType, 9389 NullType, 9390 NullType, 9391 NullType, 9392 NullType> FunctorType; 9393 9394 FunctorType functor_; 9395 9396 functionImplementation_(const FunctorType &functor) : 9397 functor_(functor) 9398 { 9399 9400 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 20)) 9401 // Fail variadic expansion for dev11 9402 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 9403 #endif 9404 9405 } 9406 9407 //! \brief Return type of the functor 9408 typedef Event result_type; 9409 9410 //! \brief Function signature of kernel functor with no event dependency. 9411 typedef Event type_( 9412 const EnqueueArgs&, 9413 T0, 9414 T1, 9415 T2, 9416 T3, 9417 T4, 9418 T5, 9419 T6, 9420 T7, 9421 T8, 9422 T9, 9423 T10, 9424 T11, 9425 T12, 9426 T13, 9427 T14, 9428 T15, 9429 T16, 9430 T17, 9431 T18, 9432 T19); 9433 9434 Event operator()( 9435 const EnqueueArgs& enqueueArgs, 9436 T0 arg0, 9437 T1 arg1, 9438 T2 arg2, 9439 T3 arg3, 9440 T4 arg4, 9441 T5 arg5, 9442 T6 arg6, 9443 T7 arg7, 9444 T8 arg8, 9445 T9 arg9, 9446 T10 arg10, 9447 T11 arg11, 9448 T12 arg12, 9449 T13 arg13, 9450 T14 arg14, 9451 T15 arg15, 9452 T16 arg16, 9453 T17 arg17, 9454 T18 arg18, 9455 T19 arg19) 9456 { 9457 return functor_( 9458 enqueueArgs, 9459 arg0, 9460 arg1, 9461 arg2, 9462 arg3, 9463 arg4, 9464 arg5, 9465 arg6, 9466 arg7, 9467 arg8, 9468 arg9, 9469 arg10, 9470 arg11, 9471 arg12, 9472 arg13, 9473 arg14, 9474 arg15, 9475 arg16, 9476 arg17, 9477 arg18, 9478 arg19); 9479 } 9480 9481 9482 }; 9483 9484 template< 9485 typename T0, 9486 typename T1, 9487 typename T2, 9488 typename T3, 9489 typename T4, 9490 typename T5, 9491 typename T6, 9492 typename T7, 9493 typename T8, 9494 typename T9, 9495 typename T10, 9496 typename T11, 9497 typename T12, 9498 typename T13, 9499 typename T14, 9500 typename T15, 9501 typename T16, 9502 typename T17, 9503 typename T18> 9504 struct functionImplementation_ 9505 < T0, 9506 T1, 9507 T2, 9508 T3, 9509 T4, 9510 T5, 9511 T6, 9512 T7, 9513 T8, 9514 T9, 9515 T10, 9516 T11, 9517 T12, 9518 T13, 9519 T14, 9520 T15, 9521 T16, 9522 T17, 9523 T18, 9524 NullType, 9525 NullType, 9526 NullType, 9527 NullType, 9528 NullType, 9529 NullType, 9530 NullType, 9531 NullType, 9532 NullType, 9533 NullType, 9534 NullType, 9535 NullType, 9536 NullType> 9537 { 9538 typedef detail::KernelFunctorGlobal< 9539 T0, 9540 T1, 9541 T2, 9542 T3, 9543 T4, 9544 T5, 9545 T6, 9546 T7, 9547 T8, 9548 T9, 9549 T10, 9550 T11, 9551 T12, 9552 T13, 9553 T14, 9554 T15, 9555 T16, 9556 T17, 9557 T18, 9558 NullType, 9559 NullType, 9560 NullType, 9561 NullType, 9562 NullType, 9563 NullType, 9564 NullType, 9565 NullType, 9566 NullType, 9567 NullType, 9568 NullType, 9569 NullType, 9570 NullType> FunctorType; 9571 9572 FunctorType functor_; 9573 9574 functionImplementation_(const FunctorType &functor) : 9575 functor_(functor) 9576 { 9577 9578 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 19)) 9579 // Fail variadic expansion for dev11 9580 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 9581 #endif 9582 9583 } 9584 9585 //! \brief Return type of the functor 9586 typedef Event result_type; 9587 9588 //! \brief Function signature of kernel functor with no event dependency. 9589 typedef Event type_( 9590 const EnqueueArgs&, 9591 T0, 9592 T1, 9593 T2, 9594 T3, 9595 T4, 9596 T5, 9597 T6, 9598 T7, 9599 T8, 9600 T9, 9601 T10, 9602 T11, 9603 T12, 9604 T13, 9605 T14, 9606 T15, 9607 T16, 9608 T17, 9609 T18); 9610 9611 Event operator()( 9612 const EnqueueArgs& enqueueArgs, 9613 T0 arg0, 9614 T1 arg1, 9615 T2 arg2, 9616 T3 arg3, 9617 T4 arg4, 9618 T5 arg5, 9619 T6 arg6, 9620 T7 arg7, 9621 T8 arg8, 9622 T9 arg9, 9623 T10 arg10, 9624 T11 arg11, 9625 T12 arg12, 9626 T13 arg13, 9627 T14 arg14, 9628 T15 arg15, 9629 T16 arg16, 9630 T17 arg17, 9631 T18 arg18) 9632 { 9633 return functor_( 9634 enqueueArgs, 9635 arg0, 9636 arg1, 9637 arg2, 9638 arg3, 9639 arg4, 9640 arg5, 9641 arg6, 9642 arg7, 9643 arg8, 9644 arg9, 9645 arg10, 9646 arg11, 9647 arg12, 9648 arg13, 9649 arg14, 9650 arg15, 9651 arg16, 9652 arg17, 9653 arg18); 9654 } 9655 9656 9657 }; 9658 9659 template< 9660 typename T0, 9661 typename T1, 9662 typename T2, 9663 typename T3, 9664 typename T4, 9665 typename T5, 9666 typename T6, 9667 typename T7, 9668 typename T8, 9669 typename T9, 9670 typename T10, 9671 typename T11, 9672 typename T12, 9673 typename T13, 9674 typename T14, 9675 typename T15, 9676 typename T16, 9677 typename T17> 9678 struct functionImplementation_ 9679 < T0, 9680 T1, 9681 T2, 9682 T3, 9683 T4, 9684 T5, 9685 T6, 9686 T7, 9687 T8, 9688 T9, 9689 T10, 9690 T11, 9691 T12, 9692 T13, 9693 T14, 9694 T15, 9695 T16, 9696 T17, 9697 NullType, 9698 NullType, 9699 NullType, 9700 NullType, 9701 NullType, 9702 NullType, 9703 NullType, 9704 NullType, 9705 NullType, 9706 NullType, 9707 NullType, 9708 NullType, 9709 NullType, 9710 NullType> 9711 { 9712 typedef detail::KernelFunctorGlobal< 9713 T0, 9714 T1, 9715 T2, 9716 T3, 9717 T4, 9718 T5, 9719 T6, 9720 T7, 9721 T8, 9722 T9, 9723 T10, 9724 T11, 9725 T12, 9726 T13, 9727 T14, 9728 T15, 9729 T16, 9730 T17, 9731 NullType, 9732 NullType, 9733 NullType, 9734 NullType, 9735 NullType, 9736 NullType, 9737 NullType, 9738 NullType, 9739 NullType, 9740 NullType, 9741 NullType, 9742 NullType, 9743 NullType, 9744 NullType> FunctorType; 9745 9746 FunctorType functor_; 9747 9748 functionImplementation_(const FunctorType &functor) : 9749 functor_(functor) 9750 { 9751 9752 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 18)) 9753 // Fail variadic expansion for dev11 9754 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 9755 #endif 9756 9757 } 9758 9759 //! \brief Return type of the functor 9760 typedef Event result_type; 9761 9762 //! \brief Function signature of kernel functor with no event dependency. 9763 typedef Event type_( 9764 const EnqueueArgs&, 9765 T0, 9766 T1, 9767 T2, 9768 T3, 9769 T4, 9770 T5, 9771 T6, 9772 T7, 9773 T8, 9774 T9, 9775 T10, 9776 T11, 9777 T12, 9778 T13, 9779 T14, 9780 T15, 9781 T16, 9782 T17); 9783 9784 Event operator()( 9785 const EnqueueArgs& enqueueArgs, 9786 T0 arg0, 9787 T1 arg1, 9788 T2 arg2, 9789 T3 arg3, 9790 T4 arg4, 9791 T5 arg5, 9792 T6 arg6, 9793 T7 arg7, 9794 T8 arg8, 9795 T9 arg9, 9796 T10 arg10, 9797 T11 arg11, 9798 T12 arg12, 9799 T13 arg13, 9800 T14 arg14, 9801 T15 arg15, 9802 T16 arg16, 9803 T17 arg17) 9804 { 9805 return functor_( 9806 enqueueArgs, 9807 arg0, 9808 arg1, 9809 arg2, 9810 arg3, 9811 arg4, 9812 arg5, 9813 arg6, 9814 arg7, 9815 arg8, 9816 arg9, 9817 arg10, 9818 arg11, 9819 arg12, 9820 arg13, 9821 arg14, 9822 arg15, 9823 arg16, 9824 arg17); 9825 } 9826 9827 9828 }; 9829 9830 template< 9831 typename T0, 9832 typename T1, 9833 typename T2, 9834 typename T3, 9835 typename T4, 9836 typename T5, 9837 typename T6, 9838 typename T7, 9839 typename T8, 9840 typename T9, 9841 typename T10, 9842 typename T11, 9843 typename T12, 9844 typename T13, 9845 typename T14, 9846 typename T15, 9847 typename T16> 9848 struct functionImplementation_ 9849 < T0, 9850 T1, 9851 T2, 9852 T3, 9853 T4, 9854 T5, 9855 T6, 9856 T7, 9857 T8, 9858 T9, 9859 T10, 9860 T11, 9861 T12, 9862 T13, 9863 T14, 9864 T15, 9865 T16, 9866 NullType, 9867 NullType, 9868 NullType, 9869 NullType, 9870 NullType, 9871 NullType, 9872 NullType, 9873 NullType, 9874 NullType, 9875 NullType, 9876 NullType, 9877 NullType, 9878 NullType, 9879 NullType, 9880 NullType> 9881 { 9882 typedef detail::KernelFunctorGlobal< 9883 T0, 9884 T1, 9885 T2, 9886 T3, 9887 T4, 9888 T5, 9889 T6, 9890 T7, 9891 T8, 9892 T9, 9893 T10, 9894 T11, 9895 T12, 9896 T13, 9897 T14, 9898 T15, 9899 T16, 9900 NullType, 9901 NullType, 9902 NullType, 9903 NullType, 9904 NullType, 9905 NullType, 9906 NullType, 9907 NullType, 9908 NullType, 9909 NullType, 9910 NullType, 9911 NullType, 9912 NullType, 9913 NullType, 9914 NullType> FunctorType; 9915 9916 FunctorType functor_; 9917 9918 functionImplementation_(const FunctorType &functor) : 9919 functor_(functor) 9920 { 9921 9922 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 17)) 9923 // Fail variadic expansion for dev11 9924 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 9925 #endif 9926 9927 } 9928 9929 //! \brief Return type of the functor 9930 typedef Event result_type; 9931 9932 //! \brief Function signature of kernel functor with no event dependency. 9933 typedef Event type_( 9934 const EnqueueArgs&, 9935 T0, 9936 T1, 9937 T2, 9938 T3, 9939 T4, 9940 T5, 9941 T6, 9942 T7, 9943 T8, 9944 T9, 9945 T10, 9946 T11, 9947 T12, 9948 T13, 9949 T14, 9950 T15, 9951 T16); 9952 9953 Event operator()( 9954 const EnqueueArgs& enqueueArgs, 9955 T0 arg0, 9956 T1 arg1, 9957 T2 arg2, 9958 T3 arg3, 9959 T4 arg4, 9960 T5 arg5, 9961 T6 arg6, 9962 T7 arg7, 9963 T8 arg8, 9964 T9 arg9, 9965 T10 arg10, 9966 T11 arg11, 9967 T12 arg12, 9968 T13 arg13, 9969 T14 arg14, 9970 T15 arg15, 9971 T16 arg16) 9972 { 9973 return functor_( 9974 enqueueArgs, 9975 arg0, 9976 arg1, 9977 arg2, 9978 arg3, 9979 arg4, 9980 arg5, 9981 arg6, 9982 arg7, 9983 arg8, 9984 arg9, 9985 arg10, 9986 arg11, 9987 arg12, 9988 arg13, 9989 arg14, 9990 arg15, 9991 arg16); 9992 } 9993 9994 9995 }; 9996 9997 template< 9998 typename T0, 9999 typename T1, 10000 typename T2, 10001 typename T3, 10002 typename T4, 10003 typename T5, 10004 typename T6, 10005 typename T7, 10006 typename T8, 10007 typename T9, 10008 typename T10, 10009 typename T11, 10010 typename T12, 10011 typename T13, 10012 typename T14, 10013 typename T15> 10014 struct functionImplementation_ 10015 < T0, 10016 T1, 10017 T2, 10018 T3, 10019 T4, 10020 T5, 10021 T6, 10022 T7, 10023 T8, 10024 T9, 10025 T10, 10026 T11, 10027 T12, 10028 T13, 10029 T14, 10030 T15, 10031 NullType, 10032 NullType, 10033 NullType, 10034 NullType, 10035 NullType, 10036 NullType, 10037 NullType, 10038 NullType, 10039 NullType, 10040 NullType, 10041 NullType, 10042 NullType, 10043 NullType, 10044 NullType, 10045 NullType, 10046 NullType> 10047 { 10048 typedef detail::KernelFunctorGlobal< 10049 T0, 10050 T1, 10051 T2, 10052 T3, 10053 T4, 10054 T5, 10055 T6, 10056 T7, 10057 T8, 10058 T9, 10059 T10, 10060 T11, 10061 T12, 10062 T13, 10063 T14, 10064 T15, 10065 NullType, 10066 NullType, 10067 NullType, 10068 NullType, 10069 NullType, 10070 NullType, 10071 NullType, 10072 NullType, 10073 NullType, 10074 NullType, 10075 NullType, 10076 NullType, 10077 NullType, 10078 NullType, 10079 NullType, 10080 NullType> FunctorType; 10081 10082 FunctorType functor_; 10083 10084 functionImplementation_(const FunctorType &functor) : 10085 functor_(functor) 10086 { 10087 10088 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 16)) 10089 // Fail variadic expansion for dev11 10090 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 10091 #endif 10092 10093 } 10094 10095 //! \brief Return type of the functor 10096 typedef Event result_type; 10097 10098 //! \brief Function signature of kernel functor with no event dependency. 10099 typedef Event type_( 10100 const EnqueueArgs&, 10101 T0, 10102 T1, 10103 T2, 10104 T3, 10105 T4, 10106 T5, 10107 T6, 10108 T7, 10109 T8, 10110 T9, 10111 T10, 10112 T11, 10113 T12, 10114 T13, 10115 T14, 10116 T15); 10117 10118 Event operator()( 10119 const EnqueueArgs& enqueueArgs, 10120 T0 arg0, 10121 T1 arg1, 10122 T2 arg2, 10123 T3 arg3, 10124 T4 arg4, 10125 T5 arg5, 10126 T6 arg6, 10127 T7 arg7, 10128 T8 arg8, 10129 T9 arg9, 10130 T10 arg10, 10131 T11 arg11, 10132 T12 arg12, 10133 T13 arg13, 10134 T14 arg14, 10135 T15 arg15) 10136 { 10137 return functor_( 10138 enqueueArgs, 10139 arg0, 10140 arg1, 10141 arg2, 10142 arg3, 10143 arg4, 10144 arg5, 10145 arg6, 10146 arg7, 10147 arg8, 10148 arg9, 10149 arg10, 10150 arg11, 10151 arg12, 10152 arg13, 10153 arg14, 10154 arg15); 10155 } 10156 10157 10158 }; 10159 10160 template< 10161 typename T0, 10162 typename T1, 10163 typename T2, 10164 typename T3, 10165 typename T4, 10166 typename T5, 10167 typename T6, 10168 typename T7, 10169 typename T8, 10170 typename T9, 10171 typename T10, 10172 typename T11, 10173 typename T12, 10174 typename T13, 10175 typename T14> 10176 struct functionImplementation_ 10177 < T0, 10178 T1, 10179 T2, 10180 T3, 10181 T4, 10182 T5, 10183 T6, 10184 T7, 10185 T8, 10186 T9, 10187 T10, 10188 T11, 10189 T12, 10190 T13, 10191 T14, 10192 NullType, 10193 NullType, 10194 NullType, 10195 NullType, 10196 NullType, 10197 NullType, 10198 NullType, 10199 NullType, 10200 NullType, 10201 NullType, 10202 NullType, 10203 NullType, 10204 NullType, 10205 NullType, 10206 NullType, 10207 NullType, 10208 NullType> 10209 { 10210 typedef detail::KernelFunctorGlobal< 10211 T0, 10212 T1, 10213 T2, 10214 T3, 10215 T4, 10216 T5, 10217 T6, 10218 T7, 10219 T8, 10220 T9, 10221 T10, 10222 T11, 10223 T12, 10224 T13, 10225 T14, 10226 NullType, 10227 NullType, 10228 NullType, 10229 NullType, 10230 NullType, 10231 NullType, 10232 NullType, 10233 NullType, 10234 NullType, 10235 NullType, 10236 NullType, 10237 NullType, 10238 NullType, 10239 NullType, 10240 NullType, 10241 NullType, 10242 NullType> FunctorType; 10243 10244 FunctorType functor_; 10245 10246 functionImplementation_(const FunctorType &functor) : 10247 functor_(functor) 10248 { 10249 10250 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 15)) 10251 // Fail variadic expansion for dev11 10252 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 10253 #endif 10254 10255 } 10256 10257 //! \brief Return type of the functor 10258 typedef Event result_type; 10259 10260 //! \brief Function signature of kernel functor with no event dependency. 10261 typedef Event type_( 10262 const EnqueueArgs&, 10263 T0, 10264 T1, 10265 T2, 10266 T3, 10267 T4, 10268 T5, 10269 T6, 10270 T7, 10271 T8, 10272 T9, 10273 T10, 10274 T11, 10275 T12, 10276 T13, 10277 T14); 10278 10279 Event operator()( 10280 const EnqueueArgs& enqueueArgs, 10281 T0 arg0, 10282 T1 arg1, 10283 T2 arg2, 10284 T3 arg3, 10285 T4 arg4, 10286 T5 arg5, 10287 T6 arg6, 10288 T7 arg7, 10289 T8 arg8, 10290 T9 arg9, 10291 T10 arg10, 10292 T11 arg11, 10293 T12 arg12, 10294 T13 arg13, 10295 T14 arg14) 10296 { 10297 return functor_( 10298 enqueueArgs, 10299 arg0, 10300 arg1, 10301 arg2, 10302 arg3, 10303 arg4, 10304 arg5, 10305 arg6, 10306 arg7, 10307 arg8, 10308 arg9, 10309 arg10, 10310 arg11, 10311 arg12, 10312 arg13, 10313 arg14); 10314 } 10315 10316 10317 }; 10318 10319 template< 10320 typename T0, 10321 typename T1, 10322 typename T2, 10323 typename T3, 10324 typename T4, 10325 typename T5, 10326 typename T6, 10327 typename T7, 10328 typename T8, 10329 typename T9, 10330 typename T10, 10331 typename T11, 10332 typename T12, 10333 typename T13> 10334 struct functionImplementation_ 10335 < T0, 10336 T1, 10337 T2, 10338 T3, 10339 T4, 10340 T5, 10341 T6, 10342 T7, 10343 T8, 10344 T9, 10345 T10, 10346 T11, 10347 T12, 10348 T13, 10349 NullType, 10350 NullType, 10351 NullType, 10352 NullType, 10353 NullType, 10354 NullType, 10355 NullType, 10356 NullType, 10357 NullType, 10358 NullType, 10359 NullType, 10360 NullType, 10361 NullType, 10362 NullType, 10363 NullType, 10364 NullType, 10365 NullType, 10366 NullType> 10367 { 10368 typedef detail::KernelFunctorGlobal< 10369 T0, 10370 T1, 10371 T2, 10372 T3, 10373 T4, 10374 T5, 10375 T6, 10376 T7, 10377 T8, 10378 T9, 10379 T10, 10380 T11, 10381 T12, 10382 T13, 10383 NullType, 10384 NullType, 10385 NullType, 10386 NullType, 10387 NullType, 10388 NullType, 10389 NullType, 10390 NullType, 10391 NullType, 10392 NullType, 10393 NullType, 10394 NullType, 10395 NullType, 10396 NullType, 10397 NullType, 10398 NullType, 10399 NullType, 10400 NullType> FunctorType; 10401 10402 FunctorType functor_; 10403 10404 functionImplementation_(const FunctorType &functor) : 10405 functor_(functor) 10406 { 10407 10408 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 14)) 10409 // Fail variadic expansion for dev11 10410 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 10411 #endif 10412 10413 } 10414 10415 //! \brief Return type of the functor 10416 typedef Event result_type; 10417 10418 //! \brief Function signature of kernel functor with no event dependency. 10419 typedef Event type_( 10420 const EnqueueArgs&, 10421 T0, 10422 T1, 10423 T2, 10424 T3, 10425 T4, 10426 T5, 10427 T6, 10428 T7, 10429 T8, 10430 T9, 10431 T10, 10432 T11, 10433 T12, 10434 T13); 10435 10436 Event operator()( 10437 const EnqueueArgs& enqueueArgs, 10438 T0 arg0, 10439 T1 arg1, 10440 T2 arg2, 10441 T3 arg3, 10442 T4 arg4, 10443 T5 arg5, 10444 T6 arg6, 10445 T7 arg7, 10446 T8 arg8, 10447 T9 arg9, 10448 T10 arg10, 10449 T11 arg11, 10450 T12 arg12, 10451 T13 arg13) 10452 { 10453 return functor_( 10454 enqueueArgs, 10455 arg0, 10456 arg1, 10457 arg2, 10458 arg3, 10459 arg4, 10460 arg5, 10461 arg6, 10462 arg7, 10463 arg8, 10464 arg9, 10465 arg10, 10466 arg11, 10467 arg12, 10468 arg13); 10469 } 10470 10471 10472 }; 10473 10474 template< 10475 typename T0, 10476 typename T1, 10477 typename T2, 10478 typename T3, 10479 typename T4, 10480 typename T5, 10481 typename T6, 10482 typename T7, 10483 typename T8, 10484 typename T9, 10485 typename T10, 10486 typename T11, 10487 typename T12> 10488 struct functionImplementation_ 10489 < T0, 10490 T1, 10491 T2, 10492 T3, 10493 T4, 10494 T5, 10495 T6, 10496 T7, 10497 T8, 10498 T9, 10499 T10, 10500 T11, 10501 T12, 10502 NullType, 10503 NullType, 10504 NullType, 10505 NullType, 10506 NullType, 10507 NullType, 10508 NullType, 10509 NullType, 10510 NullType, 10511 NullType, 10512 NullType, 10513 NullType, 10514 NullType, 10515 NullType, 10516 NullType, 10517 NullType, 10518 NullType, 10519 NullType, 10520 NullType> 10521 { 10522 typedef detail::KernelFunctorGlobal< 10523 T0, 10524 T1, 10525 T2, 10526 T3, 10527 T4, 10528 T5, 10529 T6, 10530 T7, 10531 T8, 10532 T9, 10533 T10, 10534 T11, 10535 T12, 10536 NullType, 10537 NullType, 10538 NullType, 10539 NullType, 10540 NullType, 10541 NullType, 10542 NullType, 10543 NullType, 10544 NullType, 10545 NullType, 10546 NullType, 10547 NullType, 10548 NullType, 10549 NullType, 10550 NullType, 10551 NullType, 10552 NullType, 10553 NullType, 10554 NullType> FunctorType; 10555 10556 FunctorType functor_; 10557 10558 functionImplementation_(const FunctorType &functor) : 10559 functor_(functor) 10560 { 10561 10562 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 13)) 10563 // Fail variadic expansion for dev11 10564 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 10565 #endif 10566 10567 } 10568 10569 //! \brief Return type of the functor 10570 typedef Event result_type; 10571 10572 //! \brief Function signature of kernel functor with no event dependency. 10573 typedef Event type_( 10574 const EnqueueArgs&, 10575 T0, 10576 T1, 10577 T2, 10578 T3, 10579 T4, 10580 T5, 10581 T6, 10582 T7, 10583 T8, 10584 T9, 10585 T10, 10586 T11, 10587 T12); 10588 10589 Event operator()( 10590 const EnqueueArgs& enqueueArgs, 10591 T0 arg0, 10592 T1 arg1, 10593 T2 arg2, 10594 T3 arg3, 10595 T4 arg4, 10596 T5 arg5, 10597 T6 arg6, 10598 T7 arg7, 10599 T8 arg8, 10600 T9 arg9, 10601 T10 arg10, 10602 T11 arg11, 10603 T12 arg12) 10604 { 10605 return functor_( 10606 enqueueArgs, 10607 arg0, 10608 arg1, 10609 arg2, 10610 arg3, 10611 arg4, 10612 arg5, 10613 arg6, 10614 arg7, 10615 arg8, 10616 arg9, 10617 arg10, 10618 arg11, 10619 arg12); 10620 } 10621 10622 10623 }; 10624 10625 template< 10626 typename T0, 10627 typename T1, 10628 typename T2, 10629 typename T3, 10630 typename T4, 10631 typename T5, 10632 typename T6, 10633 typename T7, 10634 typename T8, 10635 typename T9, 10636 typename T10, 10637 typename T11> 10638 struct functionImplementation_ 10639 < T0, 10640 T1, 10641 T2, 10642 T3, 10643 T4, 10644 T5, 10645 T6, 10646 T7, 10647 T8, 10648 T9, 10649 T10, 10650 T11, 10651 NullType, 10652 NullType, 10653 NullType, 10654 NullType, 10655 NullType, 10656 NullType, 10657 NullType, 10658 NullType, 10659 NullType, 10660 NullType, 10661 NullType, 10662 NullType, 10663 NullType, 10664 NullType, 10665 NullType, 10666 NullType, 10667 NullType, 10668 NullType, 10669 NullType, 10670 NullType> 10671 { 10672 typedef detail::KernelFunctorGlobal< 10673 T0, 10674 T1, 10675 T2, 10676 T3, 10677 T4, 10678 T5, 10679 T6, 10680 T7, 10681 T8, 10682 T9, 10683 T10, 10684 T11, 10685 NullType, 10686 NullType, 10687 NullType, 10688 NullType, 10689 NullType, 10690 NullType, 10691 NullType, 10692 NullType, 10693 NullType, 10694 NullType, 10695 NullType, 10696 NullType, 10697 NullType, 10698 NullType, 10699 NullType, 10700 NullType, 10701 NullType, 10702 NullType, 10703 NullType, 10704 NullType> FunctorType; 10705 10706 FunctorType functor_; 10707 10708 functionImplementation_(const FunctorType &functor) : 10709 functor_(functor) 10710 { 10711 10712 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 12)) 10713 // Fail variadic expansion for dev11 10714 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 10715 #endif 10716 10717 } 10718 10719 //! \brief Return type of the functor 10720 typedef Event result_type; 10721 10722 //! \brief Function signature of kernel functor with no event dependency. 10723 typedef Event type_( 10724 const EnqueueArgs&, 10725 T0, 10726 T1, 10727 T2, 10728 T3, 10729 T4, 10730 T5, 10731 T6, 10732 T7, 10733 T8, 10734 T9, 10735 T10, 10736 T11); 10737 10738 Event operator()( 10739 const EnqueueArgs& enqueueArgs, 10740 T0 arg0, 10741 T1 arg1, 10742 T2 arg2, 10743 T3 arg3, 10744 T4 arg4, 10745 T5 arg5, 10746 T6 arg6, 10747 T7 arg7, 10748 T8 arg8, 10749 T9 arg9, 10750 T10 arg10, 10751 T11 arg11) 10752 { 10753 return functor_( 10754 enqueueArgs, 10755 arg0, 10756 arg1, 10757 arg2, 10758 arg3, 10759 arg4, 10760 arg5, 10761 arg6, 10762 arg7, 10763 arg8, 10764 arg9, 10765 arg10, 10766 arg11); 10767 } 10768 10769 10770 }; 10771 10772 template< 10773 typename T0, 10774 typename T1, 10775 typename T2, 10776 typename T3, 10777 typename T4, 10778 typename T5, 10779 typename T6, 10780 typename T7, 10781 typename T8, 10782 typename T9, 10783 typename T10> 10784 struct functionImplementation_ 10785 < T0, 10786 T1, 10787 T2, 10788 T3, 10789 T4, 10790 T5, 10791 T6, 10792 T7, 10793 T8, 10794 T9, 10795 T10, 10796 NullType, 10797 NullType, 10798 NullType, 10799 NullType, 10800 NullType, 10801 NullType, 10802 NullType, 10803 NullType, 10804 NullType, 10805 NullType, 10806 NullType, 10807 NullType, 10808 NullType, 10809 NullType, 10810 NullType, 10811 NullType, 10812 NullType, 10813 NullType, 10814 NullType, 10815 NullType, 10816 NullType> 10817 { 10818 typedef detail::KernelFunctorGlobal< 10819 T0, 10820 T1, 10821 T2, 10822 T3, 10823 T4, 10824 T5, 10825 T6, 10826 T7, 10827 T8, 10828 T9, 10829 T10, 10830 NullType, 10831 NullType, 10832 NullType, 10833 NullType, 10834 NullType, 10835 NullType, 10836 NullType, 10837 NullType, 10838 NullType, 10839 NullType, 10840 NullType, 10841 NullType, 10842 NullType, 10843 NullType, 10844 NullType, 10845 NullType, 10846 NullType, 10847 NullType, 10848 NullType, 10849 NullType, 10850 NullType> FunctorType; 10851 10852 FunctorType functor_; 10853 10854 functionImplementation_(const FunctorType &functor) : 10855 functor_(functor) 10856 { 10857 10858 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 11)) 10859 // Fail variadic expansion for dev11 10860 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 10861 #endif 10862 10863 } 10864 10865 //! \brief Return type of the functor 10866 typedef Event result_type; 10867 10868 //! \brief Function signature of kernel functor with no event dependency. 10869 typedef Event type_( 10870 const EnqueueArgs&, 10871 T0, 10872 T1, 10873 T2, 10874 T3, 10875 T4, 10876 T5, 10877 T6, 10878 T7, 10879 T8, 10880 T9, 10881 T10); 10882 10883 Event operator()( 10884 const EnqueueArgs& enqueueArgs, 10885 T0 arg0, 10886 T1 arg1, 10887 T2 arg2, 10888 T3 arg3, 10889 T4 arg4, 10890 T5 arg5, 10891 T6 arg6, 10892 T7 arg7, 10893 T8 arg8, 10894 T9 arg9, 10895 T10 arg10) 10896 { 10897 return functor_( 10898 enqueueArgs, 10899 arg0, 10900 arg1, 10901 arg2, 10902 arg3, 10903 arg4, 10904 arg5, 10905 arg6, 10906 arg7, 10907 arg8, 10908 arg9, 10909 arg10); 10910 } 10911 10912 10913 }; 10914 10915 template< 10916 typename T0, 10917 typename T1, 10918 typename T2, 10919 typename T3, 10920 typename T4, 10921 typename T5, 10922 typename T6, 10923 typename T7, 10924 typename T8, 10925 typename T9> 10926 struct functionImplementation_ 10927 < T0, 10928 T1, 10929 T2, 10930 T3, 10931 T4, 10932 T5, 10933 T6, 10934 T7, 10935 T8, 10936 T9, 10937 NullType, 10938 NullType, 10939 NullType, 10940 NullType, 10941 NullType, 10942 NullType, 10943 NullType, 10944 NullType, 10945 NullType, 10946 NullType, 10947 NullType, 10948 NullType, 10949 NullType, 10950 NullType, 10951 NullType, 10952 NullType, 10953 NullType, 10954 NullType, 10955 NullType, 10956 NullType, 10957 NullType, 10958 NullType> 10959 { 10960 typedef detail::KernelFunctorGlobal< 10961 T0, 10962 T1, 10963 T2, 10964 T3, 10965 T4, 10966 T5, 10967 T6, 10968 T7, 10969 T8, 10970 T9, 10971 NullType, 10972 NullType, 10973 NullType, 10974 NullType, 10975 NullType, 10976 NullType, 10977 NullType, 10978 NullType, 10979 NullType, 10980 NullType, 10981 NullType, 10982 NullType, 10983 NullType, 10984 NullType, 10985 NullType, 10986 NullType, 10987 NullType, 10988 NullType, 10989 NullType, 10990 NullType, 10991 NullType, 10992 NullType> FunctorType; 10993 10994 FunctorType functor_; 10995 10996 functionImplementation_(const FunctorType &functor) : 10997 functor_(functor) 10998 { 10999 11000 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 10)) 11001 // Fail variadic expansion for dev11 11002 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 11003 #endif 11004 11005 } 11006 11007 //! \brief Return type of the functor 11008 typedef Event result_type; 11009 11010 //! \brief Function signature of kernel functor with no event dependency. 11011 typedef Event type_( 11012 const EnqueueArgs&, 11013 T0, 11014 T1, 11015 T2, 11016 T3, 11017 T4, 11018 T5, 11019 T6, 11020 T7, 11021 T8, 11022 T9); 11023 11024 Event operator()( 11025 const EnqueueArgs& enqueueArgs, 11026 T0 arg0, 11027 T1 arg1, 11028 T2 arg2, 11029 T3 arg3, 11030 T4 arg4, 11031 T5 arg5, 11032 T6 arg6, 11033 T7 arg7, 11034 T8 arg8, 11035 T9 arg9) 11036 { 11037 return functor_( 11038 enqueueArgs, 11039 arg0, 11040 arg1, 11041 arg2, 11042 arg3, 11043 arg4, 11044 arg5, 11045 arg6, 11046 arg7, 11047 arg8, 11048 arg9); 11049 } 11050 11051 11052 }; 11053 11054 template< 11055 typename T0, 11056 typename T1, 11057 typename T2, 11058 typename T3, 11059 typename T4, 11060 typename T5, 11061 typename T6, 11062 typename T7, 11063 typename T8> 11064 struct functionImplementation_ 11065 < T0, 11066 T1, 11067 T2, 11068 T3, 11069 T4, 11070 T5, 11071 T6, 11072 T7, 11073 T8, 11074 NullType, 11075 NullType, 11076 NullType, 11077 NullType, 11078 NullType, 11079 NullType, 11080 NullType, 11081 NullType, 11082 NullType, 11083 NullType, 11084 NullType, 11085 NullType, 11086 NullType, 11087 NullType, 11088 NullType, 11089 NullType, 11090 NullType, 11091 NullType, 11092 NullType, 11093 NullType, 11094 NullType, 11095 NullType, 11096 NullType> 11097 { 11098 typedef detail::KernelFunctorGlobal< 11099 T0, 11100 T1, 11101 T2, 11102 T3, 11103 T4, 11104 T5, 11105 T6, 11106 T7, 11107 T8, 11108 NullType, 11109 NullType, 11110 NullType, 11111 NullType, 11112 NullType, 11113 NullType, 11114 NullType, 11115 NullType, 11116 NullType, 11117 NullType, 11118 NullType, 11119 NullType, 11120 NullType, 11121 NullType, 11122 NullType, 11123 NullType, 11124 NullType, 11125 NullType, 11126 NullType, 11127 NullType, 11128 NullType, 11129 NullType, 11130 NullType> FunctorType; 11131 11132 FunctorType functor_; 11133 11134 functionImplementation_(const FunctorType &functor) : 11135 functor_(functor) 11136 { 11137 11138 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 9)) 11139 // Fail variadic expansion for dev11 11140 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 11141 #endif 11142 11143 } 11144 11145 //! \brief Return type of the functor 11146 typedef Event result_type; 11147 11148 //! \brief Function signature of kernel functor with no event dependency. 11149 typedef Event type_( 11150 const EnqueueArgs&, 11151 T0, 11152 T1, 11153 T2, 11154 T3, 11155 T4, 11156 T5, 11157 T6, 11158 T7, 11159 T8); 11160 11161 Event operator()( 11162 const EnqueueArgs& enqueueArgs, 11163 T0 arg0, 11164 T1 arg1, 11165 T2 arg2, 11166 T3 arg3, 11167 T4 arg4, 11168 T5 arg5, 11169 T6 arg6, 11170 T7 arg7, 11171 T8 arg8) 11172 { 11173 return functor_( 11174 enqueueArgs, 11175 arg0, 11176 arg1, 11177 arg2, 11178 arg3, 11179 arg4, 11180 arg5, 11181 arg6, 11182 arg7, 11183 arg8); 11184 } 11185 11186 11187 }; 11188 11189 template< 11190 typename T0, 11191 typename T1, 11192 typename T2, 11193 typename T3, 11194 typename T4, 11195 typename T5, 11196 typename T6, 11197 typename T7> 11198 struct functionImplementation_ 11199 < T0, 11200 T1, 11201 T2, 11202 T3, 11203 T4, 11204 T5, 11205 T6, 11206 T7, 11207 NullType, 11208 NullType, 11209 NullType, 11210 NullType, 11211 NullType, 11212 NullType, 11213 NullType, 11214 NullType, 11215 NullType, 11216 NullType, 11217 NullType, 11218 NullType, 11219 NullType, 11220 NullType, 11221 NullType, 11222 NullType, 11223 NullType, 11224 NullType, 11225 NullType, 11226 NullType, 11227 NullType, 11228 NullType, 11229 NullType, 11230 NullType> 11231 { 11232 typedef detail::KernelFunctorGlobal< 11233 T0, 11234 T1, 11235 T2, 11236 T3, 11237 T4, 11238 T5, 11239 T6, 11240 T7, 11241 NullType, 11242 NullType, 11243 NullType, 11244 NullType, 11245 NullType, 11246 NullType, 11247 NullType, 11248 NullType, 11249 NullType, 11250 NullType, 11251 NullType, 11252 NullType, 11253 NullType, 11254 NullType, 11255 NullType, 11256 NullType, 11257 NullType, 11258 NullType, 11259 NullType, 11260 NullType, 11261 NullType, 11262 NullType, 11263 NullType, 11264 NullType> FunctorType; 11265 11266 FunctorType functor_; 11267 11268 functionImplementation_(const FunctorType &functor) : 11269 functor_(functor) 11270 { 11271 11272 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 8)) 11273 // Fail variadic expansion for dev11 11274 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 11275 #endif 11276 11277 } 11278 11279 //! \brief Return type of the functor 11280 typedef Event result_type; 11281 11282 //! \brief Function signature of kernel functor with no event dependency. 11283 typedef Event type_( 11284 const EnqueueArgs&, 11285 T0, 11286 T1, 11287 T2, 11288 T3, 11289 T4, 11290 T5, 11291 T6, 11292 T7); 11293 11294 Event operator()( 11295 const EnqueueArgs& enqueueArgs, 11296 T0 arg0, 11297 T1 arg1, 11298 T2 arg2, 11299 T3 arg3, 11300 T4 arg4, 11301 T5 arg5, 11302 T6 arg6, 11303 T7 arg7) 11304 { 11305 return functor_( 11306 enqueueArgs, 11307 arg0, 11308 arg1, 11309 arg2, 11310 arg3, 11311 arg4, 11312 arg5, 11313 arg6, 11314 arg7); 11315 } 11316 11317 11318 }; 11319 11320 template< 11321 typename T0, 11322 typename T1, 11323 typename T2, 11324 typename T3, 11325 typename T4, 11326 typename T5, 11327 typename T6> 11328 struct functionImplementation_ 11329 < T0, 11330 T1, 11331 T2, 11332 T3, 11333 T4, 11334 T5, 11335 T6, 11336 NullType, 11337 NullType, 11338 NullType, 11339 NullType, 11340 NullType, 11341 NullType, 11342 NullType, 11343 NullType, 11344 NullType, 11345 NullType, 11346 NullType, 11347 NullType, 11348 NullType, 11349 NullType, 11350 NullType, 11351 NullType, 11352 NullType, 11353 NullType, 11354 NullType, 11355 NullType, 11356 NullType, 11357 NullType, 11358 NullType, 11359 NullType, 11360 NullType> 11361 { 11362 typedef detail::KernelFunctorGlobal< 11363 T0, 11364 T1, 11365 T2, 11366 T3, 11367 T4, 11368 T5, 11369 T6, 11370 NullType, 11371 NullType, 11372 NullType, 11373 NullType, 11374 NullType, 11375 NullType, 11376 NullType, 11377 NullType, 11378 NullType, 11379 NullType, 11380 NullType, 11381 NullType, 11382 NullType, 11383 NullType, 11384 NullType, 11385 NullType, 11386 NullType, 11387 NullType, 11388 NullType, 11389 NullType, 11390 NullType, 11391 NullType, 11392 NullType, 11393 NullType, 11394 NullType> FunctorType; 11395 11396 FunctorType functor_; 11397 11398 functionImplementation_(const FunctorType &functor) : 11399 functor_(functor) 11400 { 11401 11402 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 7)) 11403 // Fail variadic expansion for dev11 11404 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 11405 #endif 11406 11407 } 11408 11409 //! \brief Return type of the functor 11410 typedef Event result_type; 11411 11412 //! \brief Function signature of kernel functor with no event dependency. 11413 typedef Event type_( 11414 const EnqueueArgs&, 11415 T0, 11416 T1, 11417 T2, 11418 T3, 11419 T4, 11420 T5, 11421 T6); 11422 11423 Event operator()( 11424 const EnqueueArgs& enqueueArgs, 11425 T0 arg0, 11426 T1 arg1, 11427 T2 arg2, 11428 T3 arg3, 11429 T4 arg4, 11430 T5 arg5, 11431 T6 arg6) 11432 { 11433 return functor_( 11434 enqueueArgs, 11435 arg0, 11436 arg1, 11437 arg2, 11438 arg3, 11439 arg4, 11440 arg5, 11441 arg6); 11442 } 11443 11444 11445 }; 11446 11447 template< 11448 typename T0, 11449 typename T1, 11450 typename T2, 11451 typename T3, 11452 typename T4, 11453 typename T5> 11454 struct functionImplementation_ 11455 < T0, 11456 T1, 11457 T2, 11458 T3, 11459 T4, 11460 T5, 11461 NullType, 11462 NullType, 11463 NullType, 11464 NullType, 11465 NullType, 11466 NullType, 11467 NullType, 11468 NullType, 11469 NullType, 11470 NullType, 11471 NullType, 11472 NullType, 11473 NullType, 11474 NullType, 11475 NullType, 11476 NullType, 11477 NullType, 11478 NullType, 11479 NullType, 11480 NullType, 11481 NullType, 11482 NullType, 11483 NullType, 11484 NullType, 11485 NullType, 11486 NullType> 11487 { 11488 typedef detail::KernelFunctorGlobal< 11489 T0, 11490 T1, 11491 T2, 11492 T3, 11493 T4, 11494 T5, 11495 NullType, 11496 NullType, 11497 NullType, 11498 NullType, 11499 NullType, 11500 NullType, 11501 NullType, 11502 NullType, 11503 NullType, 11504 NullType, 11505 NullType, 11506 NullType, 11507 NullType, 11508 NullType, 11509 NullType, 11510 NullType, 11511 NullType, 11512 NullType, 11513 NullType, 11514 NullType, 11515 NullType, 11516 NullType, 11517 NullType, 11518 NullType, 11519 NullType, 11520 NullType> FunctorType; 11521 11522 FunctorType functor_; 11523 11524 functionImplementation_(const FunctorType &functor) : 11525 functor_(functor) 11526 { 11527 11528 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 6)) 11529 // Fail variadic expansion for dev11 11530 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 11531 #endif 11532 11533 } 11534 11535 //! \brief Return type of the functor 11536 typedef Event result_type; 11537 11538 //! \brief Function signature of kernel functor with no event dependency. 11539 typedef Event type_( 11540 const EnqueueArgs&, 11541 T0, 11542 T1, 11543 T2, 11544 T3, 11545 T4, 11546 T5); 11547 11548 Event operator()( 11549 const EnqueueArgs& enqueueArgs, 11550 T0 arg0, 11551 T1 arg1, 11552 T2 arg2, 11553 T3 arg3, 11554 T4 arg4, 11555 T5 arg5) 11556 { 11557 return functor_( 11558 enqueueArgs, 11559 arg0, 11560 arg1, 11561 arg2, 11562 arg3, 11563 arg4, 11564 arg5); 11565 } 11566 11567 11568 }; 11569 11570 template< 11571 typename T0, 11572 typename T1, 11573 typename T2, 11574 typename T3, 11575 typename T4> 11576 struct functionImplementation_ 11577 < T0, 11578 T1, 11579 T2, 11580 T3, 11581 T4, 11582 NullType, 11583 NullType, 11584 NullType, 11585 NullType, 11586 NullType, 11587 NullType, 11588 NullType, 11589 NullType, 11590 NullType, 11591 NullType, 11592 NullType, 11593 NullType, 11594 NullType, 11595 NullType, 11596 NullType, 11597 NullType, 11598 NullType, 11599 NullType, 11600 NullType, 11601 NullType, 11602 NullType, 11603 NullType, 11604 NullType, 11605 NullType, 11606 NullType, 11607 NullType, 11608 NullType> 11609 { 11610 typedef detail::KernelFunctorGlobal< 11611 T0, 11612 T1, 11613 T2, 11614 T3, 11615 T4, 11616 NullType, 11617 NullType, 11618 NullType, 11619 NullType, 11620 NullType, 11621 NullType, 11622 NullType, 11623 NullType, 11624 NullType, 11625 NullType, 11626 NullType, 11627 NullType, 11628 NullType, 11629 NullType, 11630 NullType, 11631 NullType, 11632 NullType, 11633 NullType, 11634 NullType, 11635 NullType, 11636 NullType, 11637 NullType, 11638 NullType, 11639 NullType, 11640 NullType, 11641 NullType, 11642 NullType> FunctorType; 11643 11644 FunctorType functor_; 11645 11646 functionImplementation_(const FunctorType &functor) : 11647 functor_(functor) 11648 { 11649 11650 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 5)) 11651 // Fail variadic expansion for dev11 11652 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 11653 #endif 11654 11655 } 11656 11657 //! \brief Return type of the functor 11658 typedef Event result_type; 11659 11660 //! \brief Function signature of kernel functor with no event dependency. 11661 typedef Event type_( 11662 const EnqueueArgs&, 11663 T0, 11664 T1, 11665 T2, 11666 T3, 11667 T4); 11668 11669 Event operator()( 11670 const EnqueueArgs& enqueueArgs, 11671 T0 arg0, 11672 T1 arg1, 11673 T2 arg2, 11674 T3 arg3, 11675 T4 arg4) 11676 { 11677 return functor_( 11678 enqueueArgs, 11679 arg0, 11680 arg1, 11681 arg2, 11682 arg3, 11683 arg4); 11684 } 11685 11686 11687 }; 11688 11689 template< 11690 typename T0, 11691 typename T1, 11692 typename T2, 11693 typename T3> 11694 struct functionImplementation_ 11695 < T0, 11696 T1, 11697 T2, 11698 T3, 11699 NullType, 11700 NullType, 11701 NullType, 11702 NullType, 11703 NullType, 11704 NullType, 11705 NullType, 11706 NullType, 11707 NullType, 11708 NullType, 11709 NullType, 11710 NullType, 11711 NullType, 11712 NullType, 11713 NullType, 11714 NullType, 11715 NullType, 11716 NullType, 11717 NullType, 11718 NullType, 11719 NullType, 11720 NullType, 11721 NullType, 11722 NullType, 11723 NullType, 11724 NullType, 11725 NullType, 11726 NullType> 11727 { 11728 typedef detail::KernelFunctorGlobal< 11729 T0, 11730 T1, 11731 T2, 11732 T3, 11733 NullType, 11734 NullType, 11735 NullType, 11736 NullType, 11737 NullType, 11738 NullType, 11739 NullType, 11740 NullType, 11741 NullType, 11742 NullType, 11743 NullType, 11744 NullType, 11745 NullType, 11746 NullType, 11747 NullType, 11748 NullType, 11749 NullType, 11750 NullType, 11751 NullType, 11752 NullType, 11753 NullType, 11754 NullType, 11755 NullType, 11756 NullType, 11757 NullType, 11758 NullType, 11759 NullType, 11760 NullType> FunctorType; 11761 11762 FunctorType functor_; 11763 11764 functionImplementation_(const FunctorType &functor) : 11765 functor_(functor) 11766 { 11767 11768 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 4)) 11769 // Fail variadic expansion for dev11 11770 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 11771 #endif 11772 11773 } 11774 11775 //! \brief Return type of the functor 11776 typedef Event result_type; 11777 11778 //! \brief Function signature of kernel functor with no event dependency. 11779 typedef Event type_( 11780 const EnqueueArgs&, 11781 T0, 11782 T1, 11783 T2, 11784 T3); 11785 11786 Event operator()( 11787 const EnqueueArgs& enqueueArgs, 11788 T0 arg0, 11789 T1 arg1, 11790 T2 arg2, 11791 T3 arg3) 11792 { 11793 return functor_( 11794 enqueueArgs, 11795 arg0, 11796 arg1, 11797 arg2, 11798 arg3); 11799 } 11800 11801 11802 }; 11803 11804 template< 11805 typename T0, 11806 typename T1, 11807 typename T2> 11808 struct functionImplementation_ 11809 < T0, 11810 T1, 11811 T2, 11812 NullType, 11813 NullType, 11814 NullType, 11815 NullType, 11816 NullType, 11817 NullType, 11818 NullType, 11819 NullType, 11820 NullType, 11821 NullType, 11822 NullType, 11823 NullType, 11824 NullType, 11825 NullType, 11826 NullType, 11827 NullType, 11828 NullType, 11829 NullType, 11830 NullType, 11831 NullType, 11832 NullType, 11833 NullType, 11834 NullType, 11835 NullType, 11836 NullType, 11837 NullType, 11838 NullType, 11839 NullType, 11840 NullType> 11841 { 11842 typedef detail::KernelFunctorGlobal< 11843 T0, 11844 T1, 11845 T2, 11846 NullType, 11847 NullType, 11848 NullType, 11849 NullType, 11850 NullType, 11851 NullType, 11852 NullType, 11853 NullType, 11854 NullType, 11855 NullType, 11856 NullType, 11857 NullType, 11858 NullType, 11859 NullType, 11860 NullType, 11861 NullType, 11862 NullType, 11863 NullType, 11864 NullType, 11865 NullType, 11866 NullType, 11867 NullType, 11868 NullType, 11869 NullType, 11870 NullType, 11871 NullType, 11872 NullType, 11873 NullType, 11874 NullType> FunctorType; 11875 11876 FunctorType functor_; 11877 11878 functionImplementation_(const FunctorType &functor) : 11879 functor_(functor) 11880 { 11881 11882 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 3)) 11883 // Fail variadic expansion for dev11 11884 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 11885 #endif 11886 11887 } 11888 11889 //! \brief Return type of the functor 11890 typedef Event result_type; 11891 11892 //! \brief Function signature of kernel functor with no event dependency. 11893 typedef Event type_( 11894 const EnqueueArgs&, 11895 T0, 11896 T1, 11897 T2); 11898 11899 Event operator()( 11900 const EnqueueArgs& enqueueArgs, 11901 T0 arg0, 11902 T1 arg1, 11903 T2 arg2) 11904 { 11905 return functor_( 11906 enqueueArgs, 11907 arg0, 11908 arg1, 11909 arg2); 11910 } 11911 11912 11913 }; 11914 11915 template< 11916 typename T0, 11917 typename T1> 11918 struct functionImplementation_ 11919 < T0, 11920 T1, 11921 NullType, 11922 NullType, 11923 NullType, 11924 NullType, 11925 NullType, 11926 NullType, 11927 NullType, 11928 NullType, 11929 NullType, 11930 NullType, 11931 NullType, 11932 NullType, 11933 NullType, 11934 NullType, 11935 NullType, 11936 NullType, 11937 NullType, 11938 NullType, 11939 NullType, 11940 NullType, 11941 NullType, 11942 NullType, 11943 NullType, 11944 NullType, 11945 NullType, 11946 NullType, 11947 NullType, 11948 NullType, 11949 NullType, 11950 NullType> 11951 { 11952 typedef detail::KernelFunctorGlobal< 11953 T0, 11954 T1, 11955 NullType, 11956 NullType, 11957 NullType, 11958 NullType, 11959 NullType, 11960 NullType, 11961 NullType, 11962 NullType, 11963 NullType, 11964 NullType, 11965 NullType, 11966 NullType, 11967 NullType, 11968 NullType, 11969 NullType, 11970 NullType, 11971 NullType, 11972 NullType, 11973 NullType, 11974 NullType, 11975 NullType, 11976 NullType, 11977 NullType, 11978 NullType, 11979 NullType, 11980 NullType, 11981 NullType, 11982 NullType, 11983 NullType, 11984 NullType> FunctorType; 11985 11986 FunctorType functor_; 11987 11988 functionImplementation_(const FunctorType &functor) : 11989 functor_(functor) 11990 { 11991 11992 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 2)) 11993 // Fail variadic expansion for dev11 11994 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 11995 #endif 11996 11997 } 11998 11999 //! \brief Return type of the functor 12000 typedef Event result_type; 12001 12002 //! \brief Function signature of kernel functor with no event dependency. 12003 typedef Event type_( 12004 const EnqueueArgs&, 12005 T0, 12006 T1); 12007 12008 Event operator()( 12009 const EnqueueArgs& enqueueArgs, 12010 T0 arg0, 12011 T1 arg1) 12012 { 12013 return functor_( 12014 enqueueArgs, 12015 arg0, 12016 arg1); 12017 } 12018 12019 12020 }; 12021 12022 template< 12023 typename T0> 12024 struct functionImplementation_ 12025 < T0, 12026 NullType, 12027 NullType, 12028 NullType, 12029 NullType, 12030 NullType, 12031 NullType, 12032 NullType, 12033 NullType, 12034 NullType, 12035 NullType, 12036 NullType, 12037 NullType, 12038 NullType, 12039 NullType, 12040 NullType, 12041 NullType, 12042 NullType, 12043 NullType, 12044 NullType, 12045 NullType, 12046 NullType, 12047 NullType, 12048 NullType, 12049 NullType, 12050 NullType, 12051 NullType, 12052 NullType, 12053 NullType, 12054 NullType, 12055 NullType, 12056 NullType> 12057 { 12058 typedef detail::KernelFunctorGlobal< 12059 T0, 12060 NullType, 12061 NullType, 12062 NullType, 12063 NullType, 12064 NullType, 12065 NullType, 12066 NullType, 12067 NullType, 12068 NullType, 12069 NullType, 12070 NullType, 12071 NullType, 12072 NullType, 12073 NullType, 12074 NullType, 12075 NullType, 12076 NullType, 12077 NullType, 12078 NullType, 12079 NullType, 12080 NullType, 12081 NullType, 12082 NullType, 12083 NullType, 12084 NullType, 12085 NullType, 12086 NullType, 12087 NullType, 12088 NullType, 12089 NullType, 12090 NullType> FunctorType; 12091 12092 FunctorType functor_; 12093 12094 functionImplementation_(const FunctorType &functor) : 12095 functor_(functor) 12096 { 12097 12098 #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 1)) 12099 // Fail variadic expansion for dev11 12100 static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); 12101 #endif 12102 12103 } 12104 12105 //! \brief Return type of the functor 12106 typedef Event result_type; 12107 12108 //! \brief Function signature of kernel functor with no event dependency. 12109 typedef Event type_( 12110 const EnqueueArgs&, 12111 T0); 12112 12113 Event operator()( 12114 const EnqueueArgs& enqueueArgs, 12115 T0 arg0) 12116 { 12117 return functor_( 12118 enqueueArgs, 12119 arg0); 12120 } 12121 12122 12123 }; 12124 12125 12126 12127 12128 12129 } // namespace detail 12130 12131 //---------------------------------------------------------------------------------------------- 12132 12133 template < 12134 typename T0, typename T1 = detail::NullType, typename T2 = detail::NullType, 12135 typename T3 = detail::NullType, typename T4 = detail::NullType, 12136 typename T5 = detail::NullType, typename T6 = detail::NullType, 12137 typename T7 = detail::NullType, typename T8 = detail::NullType, 12138 typename T9 = detail::NullType, typename T10 = detail::NullType, 12139 typename T11 = detail::NullType, typename T12 = detail::NullType, 12140 typename T13 = detail::NullType, typename T14 = detail::NullType, 12141 typename T15 = detail::NullType, typename T16 = detail::NullType, 12142 typename T17 = detail::NullType, typename T18 = detail::NullType, 12143 typename T19 = detail::NullType, typename T20 = detail::NullType, 12144 typename T21 = detail::NullType, typename T22 = detail::NullType, 12145 typename T23 = detail::NullType, typename T24 = detail::NullType, 12146 typename T25 = detail::NullType, typename T26 = detail::NullType, 12147 typename T27 = detail::NullType, typename T28 = detail::NullType, 12148 typename T29 = detail::NullType, typename T30 = detail::NullType, 12149 typename T31 = detail::NullType 12150 > 12151 struct make_kernel : 12152 public detail::functionImplementation_< 12153 T0, T1, T2, T3, 12154 T4, T5, T6, T7, 12155 T8, T9, T10, T11, 12156 T12, T13, T14, T15, 12157 T16, T17, T18, T19, 12158 T20, T21, T22, T23, 12159 T24, T25, T26, T27, 12160 T28, T29, T30, T31 12161 > 12162 { 12163 public: 12164 typedef detail::KernelFunctorGlobal< 12165 T0, T1, T2, T3, 12166 T4, T5, T6, T7, 12167 T8, T9, T10, T11, 12168 T12, T13, T14, T15, 12169 T16, T17, T18, T19, 12170 T20, T21, T22, T23, 12171 T24, T25, T26, T27, 12172 T28, T29, T30, T31 12173 > FunctorType; 12174 12175 make_kernel( 12176 const Program& program, 12177 const STRING_CLASS name, 12178 cl_int * err = NULL) : 12179 detail::functionImplementation_< 12180 T0, T1, T2, T3, 12181 T4, T5, T6, T7, 12182 T8, T9, T10, T11, 12183 T12, T13, T14, T15, 12184 T16, T17, T18, T19, 12185 T20, T21, T22, T23, 12186 T24, T25, T26, T27, 12187 T28, T29, T30, T31 12188 >( 12189 FunctorType(program, name, err)) 12190 {} 12191 12192 make_kernel( 12193 const Kernel kernel) : 12194 detail::functionImplementation_< 12195 T0, T1, T2, T3, 12196 T4, T5, T6, T7, 12197 T8, T9, T10, T11, 12198 T12, T13, T14, T15, 12199 T16, T17, T18, T19, 12200 T20, T21, T22, T23, 12201 T24, T25, T26, T27, 12202 T28, T29, T30, T31 12203 >( 12204 FunctorType(kernel)) 12205 {} 12206 }; 12207 12208 12209 //---------------------------------------------------------------------------------------------------------------------- 12210 12211 #undef __ERR_STR 12212 #if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS) 12213 #undef __GET_DEVICE_INFO_ERR 12214 #undef __GET_PLATFORM_INFO_ERR 12215 #undef __GET_DEVICE_IDS_ERR 12216 #undef __GET_CONTEXT_INFO_ERR 12217 #undef __GET_EVENT_INFO_ERR 12218 #undef __GET_EVENT_PROFILE_INFO_ERR 12219 #undef __GET_MEM_OBJECT_INFO_ERR 12220 #undef __GET_IMAGE_INFO_ERR 12221 #undef __GET_SAMPLER_INFO_ERR 12222 #undef __GET_KERNEL_INFO_ERR 12223 #undef __GET_KERNEL_ARG_INFO_ERR 12224 #undef __GET_KERNEL_WORK_GROUP_INFO_ERR 12225 #undef __GET_PROGRAM_INFO_ERR 12226 #undef __GET_PROGRAM_BUILD_INFO_ERR 12227 #undef __GET_COMMAND_QUEUE_INFO_ERR 12228 12229 #undef __CREATE_CONTEXT_ERR 12230 #undef __CREATE_CONTEXT_FROM_TYPE_ERR 12231 #undef __GET_SUPPORTED_IMAGE_FORMATS_ERR 12232 12233 #undef __CREATE_BUFFER_ERR 12234 #undef __CREATE_SUBBUFFER_ERR 12235 #undef __CREATE_IMAGE2D_ERR 12236 #undef __CREATE_IMAGE3D_ERR 12237 #undef __CREATE_SAMPLER_ERR 12238 #undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR 12239 12240 #undef __CREATE_USER_EVENT_ERR 12241 #undef __SET_USER_EVENT_STATUS_ERR 12242 #undef __SET_EVENT_CALLBACK_ERR 12243 #undef __SET_PRINTF_CALLBACK_ERR 12244 12245 #undef __WAIT_FOR_EVENTS_ERR 12246 12247 #undef __CREATE_KERNEL_ERR 12248 #undef __SET_KERNEL_ARGS_ERR 12249 #undef __CREATE_PROGRAM_WITH_SOURCE_ERR 12250 #undef __CREATE_PROGRAM_WITH_BINARY_ERR 12251 #undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR 12252 #undef __BUILD_PROGRAM_ERR 12253 #undef __CREATE_KERNELS_IN_PROGRAM_ERR 12254 12255 #undef __CREATE_COMMAND_QUEUE_ERR 12256 #undef __SET_COMMAND_QUEUE_PROPERTY_ERR 12257 #undef __ENQUEUE_READ_BUFFER_ERR 12258 #undef __ENQUEUE_WRITE_BUFFER_ERR 12259 #undef __ENQUEUE_READ_BUFFER_RECT_ERR 12260 #undef __ENQUEUE_WRITE_BUFFER_RECT_ERR 12261 #undef __ENQEUE_COPY_BUFFER_ERR 12262 #undef __ENQEUE_COPY_BUFFER_RECT_ERR 12263 #undef __ENQUEUE_READ_IMAGE_ERR 12264 #undef __ENQUEUE_WRITE_IMAGE_ERR 12265 #undef __ENQUEUE_COPY_IMAGE_ERR 12266 #undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR 12267 #undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR 12268 #undef __ENQUEUE_MAP_BUFFER_ERR 12269 #undef __ENQUEUE_MAP_IMAGE_ERR 12270 #undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR 12271 #undef __ENQUEUE_NDRANGE_KERNEL_ERR 12272 #undef __ENQUEUE_TASK_ERR 12273 #undef __ENQUEUE_NATIVE_KERNEL 12274 12275 #undef __CL_EXPLICIT_CONSTRUCTORS 12276 12277 #undef __UNLOAD_COMPILER_ERR 12278 #endif //__CL_USER_OVERRIDE_ERROR_STRINGS 12279 12280 #undef __CL_FUNCTION_TYPE 12281 12282 // Extensions 12283 /** 12284 * Deprecated APIs for 1.2 12285 */ 12286 #if defined(CL_VERSION_1_1) 12287 #undef __INIT_CL_EXT_FCN_PTR 12288 #endif // #if defined(CL_VERSION_1_1) 12289 #undef __CREATE_SUB_DEVICES 12290 12291 #if defined(USE_CL_DEVICE_FISSION) 12292 #undef __PARAM_NAME_DEVICE_FISSION 12293 #endif // USE_CL_DEVICE_FISSION 12294 12295 #undef __DEFAULT_NOT_INITIALIZED 12296 #undef __DEFAULT_BEING_INITIALIZED 12297 #undef __DEFAULT_INITIALIZED 12298 12299 } // namespace cl 12300 12301 #ifdef _WIN32 12302 #pragma pop_macro("max") 12303 #endif // _WIN32 12304 12305 #endif // CL_HPP_ 12306