OpenCL C++ Bindings: opencl.hpp Source File

OpenCL C++ Bindings

opencl.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2008-2020 The Khronos Group Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
311
324
388 #ifndef CL_HPP_
389 #define CL_HPP_
390
391 /* Handle deprecated preprocessor definitions. In each case, we only check for
392 * the old name if the new name is not defined, so that user code can define
393 * both and hence work with either version of the bindings.
394 */
395 #if !defined(CL_HPP_USE_DX_INTEROP) && defined(USE_DX_INTEROP)
396 # pragma message("opencl.hpp: USE_DX_INTEROP is deprecated. Define CL_HPP_USE_DX_INTEROP instead")
397 # define CL_HPP_USE_DX_INTEROP
398 #endif
399 #if !defined(CL_HPP_USE_CL_DEVICE_FISSION) && defined(USE_CL_DEVICE_FISSION)
400 # pragma message("opencl.hpp: USE_CL_DEVICE_FISSION is deprecated. Define CL_HPP_USE_CL_DEVICE_FISSION instead")
401 # define CL_HPP_USE_CL_DEVICE_FISSION
402 #endif
403 #if !defined(CL_HPP_ENABLE_EXCEPTIONS) && defined(__CL_ENABLE_EXCEPTIONS)
404 # pragma message("opencl.hpp: __CL_ENABLE_EXCEPTIONS is deprecated. Define CL_HPP_ENABLE_EXCEPTIONS instead")
405 # define CL_HPP_ENABLE_EXCEPTIONS
406 #endif
407 #if !defined(CL_HPP_NO_STD_VECTOR) && defined(__NO_STD_VECTOR)
408 # pragma message("opencl.hpp: __NO_STD_VECTOR is deprecated. Define CL_HPP_NO_STD_VECTOR instead")
409 # define CL_HPP_NO_STD_VECTOR
410 #endif
411 #if !defined(CL_HPP_NO_STD_STRING) && defined(__NO_STD_STRING)
412 # pragma message("opencl.hpp: __NO_STD_STRING is deprecated. Define CL_HPP_NO_STD_STRING instead")
413 # define CL_HPP_NO_STD_STRING
414 #endif
415 #if defined(VECTOR_CLASS)
416 # pragma message("opencl.hpp: VECTOR_CLASS is deprecated. Alias cl::vector instead")
417 #endif
418 #if defined(STRING_CLASS)
419 # pragma message("opencl.hpp: STRING_CLASS is deprecated. Alias cl::string instead.")
420 #endif
421 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) && defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
422 # pragma message("opencl.hpp: __CL_USER_OVERRIDE_ERROR_STRINGS is deprecated. Define CL_HPP_USER_OVERRIDE_ERROR_STRINGS instead")
423 # define CL_HPP_USER_OVERRIDE_ERROR_STRINGS
424 #endif
425
426 /* Warn about features that are no longer supported
427 */
428 #if defined(__USE_DEV_VECTOR)
429 # pragma message("opencl.hpp: __USE_DEV_VECTOR is no longer supported. Expect compilation errors")
430 #endif
431 #if defined(__USE_DEV_STRING)
432 # pragma message("opencl.hpp: __USE_DEV_STRING is no longer supported. Expect compilation errors")
433 #endif
434
435 /* Detect which version to target */
436 #if !defined(CL_HPP_TARGET_OPENCL_VERSION)
437 # pragma message("opencl.hpp: CL_HPP_TARGET_OPENCL_VERSION is not defined. It will default to 300 (OpenCL 3.0)")
438 # define CL_HPP_TARGET_OPENCL_VERSION 300
439 #endif
440 #if CL_HPP_TARGET_OPENCL_VERSION != 100 && \
441 CL_HPP_TARGET_OPENCL_VERSION != 110 && \
442 CL_HPP_TARGET_OPENCL_VERSION != 120 && \
443 CL_HPP_TARGET_OPENCL_VERSION != 200 && \
444 CL_HPP_TARGET_OPENCL_VERSION != 210 && \
445 CL_HPP_TARGET_OPENCL_VERSION != 220 && \
446 CL_HPP_TARGET_OPENCL_VERSION != 300
447 # pragma message("opencl.hpp: CL_HPP_TARGET_OPENCL_VERSION is not a valid value (100, 110, 120, 200, 210, 220 or 300). It will be set to 300 (OpenCL 3.0).")
448 # undef CL_HPP_TARGET_OPENCL_VERSION
449 # define CL_HPP_TARGET_OPENCL_VERSION 300
450 #endif
451
452 /* Forward target OpenCL version to C headers if necessary */
453 #if defined(CL_TARGET_OPENCL_VERSION)
454 /* Warn if prior definition of CL_TARGET_OPENCL_VERSION is lower than
455 * requested C++ bindings version */
456 #if CL_TARGET_OPENCL_VERSION < CL_HPP_TARGET_OPENCL_VERSION
457 # pragma message("CL_TARGET_OPENCL_VERSION is already defined as is lower than CL_HPP_TARGET_OPENCL_VERSION")
458 #endif
459 #else
460 # define CL_TARGET_OPENCL_VERSION CL_HPP_TARGET_OPENCL_VERSION
461 #endif
462
463 #if !defined(CL_HPP_MINIMUM_OPENCL_VERSION)
464 # define CL_HPP_MINIMUM_OPENCL_VERSION 200
465 #endif
466 #if CL_HPP_MINIMUM_OPENCL_VERSION != 100 && \
467 CL_HPP_MINIMUM_OPENCL_VERSION != 110 && \
468 CL_HPP_MINIMUM_OPENCL_VERSION != 120 && \
469 CL_HPP_MINIMUM_OPENCL_VERSION != 200 && \
470 CL_HPP_MINIMUM_OPENCL_VERSION != 210 && \
471 CL_HPP_MINIMUM_OPENCL_VERSION != 220 && \
472 CL_HPP_MINIMUM_OPENCL_VERSION != 300
473 # pragma message("opencl.hpp: CL_HPP_MINIMUM_OPENCL_VERSION is not a valid value (100, 110, 120, 200, 210, 220 or 300). It will be set to 100")
474 # undef CL_HPP_MINIMUM_OPENCL_VERSION
475 # define CL_HPP_MINIMUM_OPENCL_VERSION 100
476 #endif
477 #if CL_HPP_MINIMUM_OPENCL_VERSION > CL_HPP_TARGET_OPENCL_VERSION
478 # error "CL_HPP_MINIMUM_OPENCL_VERSION must not be greater than CL_HPP_TARGET_OPENCL_VERSION"
479 #endif
480
481 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 100 && !defined(CL_USE_DEPRECATED_OPENCL_1_0_APIS)
482 # define CL_USE_DEPRECATED_OPENCL_1_0_APIS
483 #endif
484 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 110 && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
485 # define CL_USE_DEPRECATED_OPENCL_1_1_APIS
486 #endif
487 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 120 && !defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
488 # define CL_USE_DEPRECATED_OPENCL_1_2_APIS
489 #endif
490 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 200 && !defined(CL_USE_DEPRECATED_OPENCL_2_0_APIS)
491 # define CL_USE_DEPRECATED_OPENCL_2_0_APIS
492 #endif
493 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 210 && !defined(CL_USE_DEPRECATED_OPENCL_2_1_APIS)
494 # define CL_USE_DEPRECATED_OPENCL_2_1_APIS
495 #endif
496 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 220 && !defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
497 # define CL_USE_DEPRECATED_OPENCL_2_2_APIS
498 #endif
499
500 #ifdef _WIN32
501
502 #include <malloc.h>
503
504 #if defined(CL_HPP_USE_DX_INTEROP)
505 #include <CL/cl_d3d10.h>
506 #include <CL/cl_dx9_media_sharing.h>
507 #endif
508 #endif // _WIN32
509
510 #if defined(_MSC_VER)
511 #include <intrin.h>
512 #endif // _MSC_VER
513
514 // Check for a valid C++ version
515
516 // Need to do both tests here because for some reason __cplusplus is not
517 // updated in visual studio
518 #if (!defined(_MSC_VER) && __cplusplus < 201103L) || (defined(_MSC_VER) && _MSC_VER < 1700)
519 #error Visual studio 2013 or another C++11-supporting compiler required
520 #endif
521
522 //
523 #if defined(CL_HPP_USE_CL_DEVICE_FISSION) || defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)
524 #include <CL/cl_ext.h>
525 #endif
526
527 #if defined(__APPLE__) || defined(__MACOSX)
528 #include <OpenCL/opencl.h>
529 #else
530 #include <CL/opencl.h>
531 #endif // !__APPLE__
532
533 #if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L )
534 #define CL_HPP_NOEXCEPT_ noexcept
535 #else
536 #define CL_HPP_NOEXCEPT_
537 #endif
538
539 #if __cplusplus >= 201703L
540 # define CL_HPP_DEFINE_STATIC_MEMBER_ inline
541 #elif defined(_MSC_VER)
542 # define CL_HPP_DEFINE_STATIC_MEMBER_ __declspec(selectany)
543 #elif defined(__MINGW32__)
544 # define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((selectany))
545 #else
546 # define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((weak))
547 #endif // !_MSC_VER
548
549 // Define deprecated prefixes and suffixes to ensure compilation
550 // in case they are not pre-defined
551 #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
552 #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
553 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
554 #if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED)
555 #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
556 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
557
558 #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED)
559 #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED
560 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED)
561 #if !defined(CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED)
562 #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED
563 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED)
564
565 #if !defined(CL_CALLBACK)
566 #define CL_CALLBACK
567 #endif //CL_CALLBACK
568
569 #include <utility>
570 #include <limits>
571 #include <iterator>
572 #include <mutex>
573 #include <cstring>
574 #include <functional>
575
576
577 // Define a size_type to represent a correctly resolved size_t
578 #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
579 namespace cl {
580 using size_type = ::size_t;
581 } // namespace cl
582 #else // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
583 namespace cl {
584 using size_type = size_t;
585 } // namespace cl
586 #endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
587
588
589 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
590 #include <exception>
591 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
592
593 #if !defined(CL_HPP_NO_STD_VECTOR)
594 #include <vector>
595 namespace cl {
596 template < class T, class Alloc = std::allocator<T> >
597 using vector = std::vector<T, Alloc>;
598 } // namespace cl
599 #endif // #if !defined(CL_HPP_NO_STD_VECTOR)
600
601 #if !defined(CL_HPP_NO_STD_STRING)
602 #include <string>
603 namespace cl {
604 using string = std::string;
605 } // namespace cl
606 #endif // #if !defined(CL_HPP_NO_STD_STRING)
607
608 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
609
610 #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
611 #include <memory>
612 namespace cl {
613 // Replace unique_ptr and allocate_pointer for internal use
614 // to allow user to replace them
615 template<class T, class D>
616 using pointer = std::unique_ptr<T, D>;
617 } // namespace cl
618 #endif
619 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
620 #if !defined(CL_HPP_NO_STD_ARRAY)
621 #include <array>
622 namespace cl {
623 template < class T, size_type N >
624 using array = std::array<T, N>;
625 } // namespace cl
626 #endif // #if !defined(CL_HPP_NO_STD_ARRAY)
627
628 // Define size_type appropriately to allow backward-compatibility
629 // use of the old size_t interface class
630 #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
631 namespace cl {
632 namespace compatibility {
637 template <int N>
638 class size_t
639 {
640 private:
641 size_type data_[N];
642
643 public:
645 size_t()
646 {
647 for (int i = 0; i < N; ++i) {
648 data_[i] = 0;
649 }
650 }
651
652 size_t(const array<size_type, N> &rhs)
653 {
654 for (int i = 0; i < N; ++i) {
655 data_[i] = rhs[i];
656 }
657 }
658
659 size_type& operator[](int index)
660 {
661 return data_[index];
662 }
663
664 const size_type& operator[](int index) const
665 {
666 return data_[index];
667 }
668
670 operator size_type* () { return data_; }
671
673 operator const size_type* () const { return data_; }
674
675 operator array<size_type, N>() const
676 {
677 array<size_type, N> ret;
678
679 for (int i = 0; i < N; ++i) {
680 ret[i] = data_[i];
681 }
682 return ret;
683 }
684 };
685 } // namespace compatibility
686
687 template<int N>
688 using size_t = compatibility::size_t<N>;
689 } // namespace cl
690 #endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
691
692 // Helper alias to avoid confusing the macros
693 namespace cl {
694 namespace detail {
695 using size_t_array = array<size_type, 3>;
696 } // namespace detail
697 } // namespace cl
698
699
705 namespace cl {
706 class Memory;
707
708 #define CL_HPP_INIT_CL_EXT_FCN_PTR_(name) \
709 if (!pfn_##name) { \
710 pfn_##name = (PFN_##name) \
711 clGetExtensionFunctionAddress(#name); \
712 if (!pfn_##name) { \
713 } \
714 }
715
716 #define CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, name) \
717 if (!pfn_##name) { \
718 pfn_##name = (PFN_##name) \
719 clGetExtensionFunctionAddressForPlatform(platform, #name); \
720 if (!pfn_##name) { \
721 } \
722 }
723
724 class Program;
725 class Device;
726 class Context;
727 class CommandQueue;
728 class DeviceCommandQueue;
729 class Memory;
730 class Buffer;
731 class Pipe;
732
733 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
734
738 class Error : public std::exception
739 {
740 private:
741 cl_int err_;
742 const char * errStr_;
743 public:
753 Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr)
754 {}
755
756 ~Error() throw() {}
757
762 virtual const char * what() const throw ()
763 {
764 if (errStr_ == NULL) {
765 return "empty";
766 }
767 else {
768 return errStr_;
769 }
770 }
771
776 cl_int err(void) const { return err_; }
777 };
778 #define CL_HPP_ERR_STR_(x) #x
779 #else
780 #define CL_HPP_ERR_STR_(x) NULL
781 #endif // CL_HPP_ENABLE_EXCEPTIONS
782
783
784 namespace detail
785 {
786 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
787 static inline cl_int errHandler (
788 cl_int err,
789 const char * errStr = NULL)
790 {
791 if (err != CL_SUCCESS) {
792 throw Error(err, errStr);
793 }
794 return err;
795 }
796 #else
797 static inline cl_int errHandler (cl_int err, const char * errStr = NULL)
798 {
799 (void) errStr; // suppress unused variable warning
800 return err;
801 }
802 #endif // CL_HPP_ENABLE_EXCEPTIONS
803 }
804
805
806
808 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
809 #define __GET_DEVICE_INFO_ERR CL_HPP_ERR_STR_(clGetDeviceInfo)
810 #define __GET_PLATFORM_INFO_ERR CL_HPP_ERR_STR_(clGetPlatformInfo)
811 #define __GET_DEVICE_IDS_ERR CL_HPP_ERR_STR_(clGetDeviceIDs)
812 #define __GET_PLATFORM_IDS_ERR CL_HPP_ERR_STR_(clGetPlatformIDs)
813 #define __GET_CONTEXT_INFO_ERR CL_HPP_ERR_STR_(clGetContextInfo)
814 #define __GET_EVENT_INFO_ERR CL_HPP_ERR_STR_(clGetEventInfo)
815 #define __GET_EVENT_PROFILE_INFO_ERR CL_HPP_ERR_STR_(clGetEventProfileInfo)
816 #define __GET_MEM_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetMemObjectInfo)
817 #define __GET_IMAGE_INFO_ERR CL_HPP_ERR_STR_(clGetImageInfo)
818 #define __GET_SAMPLER_INFO_ERR CL_HPP_ERR_STR_(clGetSamplerInfo)
819 #define __GET_KERNEL_INFO_ERR CL_HPP_ERR_STR_(clGetKernelInfo)
820 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
821 #define __GET_KERNEL_ARG_INFO_ERR CL_HPP_ERR_STR_(clGetKernelArgInfo)
822 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
823 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
824 #define __GET_KERNEL_SUB_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelSubGroupInfo)
825 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
826 #define __GET_KERNEL_WORK_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelWorkGroupInfo)
827 #define __GET_PROGRAM_INFO_ERR CL_HPP_ERR_STR_(clGetProgramInfo)
828 #define __GET_PROGRAM_BUILD_INFO_ERR CL_HPP_ERR_STR_(clGetProgramBuildInfo)
829 #define __GET_COMMAND_QUEUE_INFO_ERR CL_HPP_ERR_STR_(clGetCommandQueueInfo)
830
831 #define __CREATE_CONTEXT_ERR CL_HPP_ERR_STR_(clCreateContext)
832 #define __CREATE_CONTEXT_FROM_TYPE_ERR CL_HPP_ERR_STR_(clCreateContextFromType)
833 #define __GET_SUPPORTED_IMAGE_FORMATS_ERR CL_HPP_ERR_STR_(clGetSupportedImageFormats)
834
835 #define __CREATE_BUFFER_ERR CL_HPP_ERR_STR_(clCreateBuffer)
836 #define __COPY_ERR CL_HPP_ERR_STR_(cl::copy)
837 #define __CREATE_SUBBUFFER_ERR CL_HPP_ERR_STR_(clCreateSubBuffer)
838 #define __CREATE_GL_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
839 #define __CREATE_GL_RENDER_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
840 #define __GET_GL_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetGLObjectInfo)
841 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
842 #define __CREATE_IMAGE_ERR CL_HPP_ERR_STR_(clCreateImage)
843 #define __CREATE_GL_TEXTURE_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture)
844 #define __IMAGE_DIMENSION_ERR CL_HPP_ERR_STR_(Incorrect image dimensions)
845 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
846 #define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR CL_HPP_ERR_STR_(clSetMemObjectDestructorCallback)
847
848 #define __CREATE_USER_EVENT_ERR CL_HPP_ERR_STR_(clCreateUserEvent)
849 #define __SET_USER_EVENT_STATUS_ERR CL_HPP_ERR_STR_(clSetUserEventStatus)
850 #define __SET_EVENT_CALLBACK_ERR CL_HPP_ERR_STR_(clSetEventCallback)
851 #define __WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clWaitForEvents)
852
853 #define __CREATE_KERNEL_ERR CL_HPP_ERR_STR_(clCreateKernel)
854 #define __SET_KERNEL_ARGS_ERR CL_HPP_ERR_STR_(clSetKernelArg)
855 #define __CREATE_PROGRAM_WITH_SOURCE_ERR CL_HPP_ERR_STR_(clCreateProgramWithSource)
856 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
857 #define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
858 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
859 #define __CREATE_PROGRAM_WITH_BINARY_ERR CL_HPP_ERR_STR_(clCreateProgramWithBinary)
860 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
861 #define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
862 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
863 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
864 #define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR CL_HPP_ERR_STR_(clCreateProgramWithBuiltInKernels)
865 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
866 #define __BUILD_PROGRAM_ERR CL_HPP_ERR_STR_(clBuildProgram)
867 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
868 #define __COMPILE_PROGRAM_ERR CL_HPP_ERR_STR_(clCompileProgram)
869 #define __LINK_PROGRAM_ERR CL_HPP_ERR_STR_(clLinkProgram)
870 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
871 #define __CREATE_KERNELS_IN_PROGRAM_ERR CL_HPP_ERR_STR_(clCreateKernelsInProgram)
872
873 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
874 #define __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateCommandQueueWithProperties)
875 #define __CREATE_SAMPLER_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateSamplerWithProperties)
876 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
877 #define __SET_COMMAND_QUEUE_PROPERTY_ERR CL_HPP_ERR_STR_(clSetCommandQueueProperty)
878 #define __ENQUEUE_READ_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueReadBuffer)
879 #define __ENQUEUE_READ_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueReadBufferRect)
880 #define __ENQUEUE_WRITE_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueWriteBuffer)
881 #define __ENQUEUE_WRITE_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueWriteBufferRect)
882 #define __ENQEUE_COPY_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyBuffer)
883 #define __ENQEUE_COPY_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferRect)
884 #define __ENQUEUE_FILL_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueFillBuffer)
885 #define __ENQUEUE_READ_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueReadImage)
886 #define __ENQUEUE_WRITE_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueWriteImage)
887 #define __ENQUEUE_COPY_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyImage)
888 #define __ENQUEUE_FILL_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueFillImage)
889 #define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyImageToBuffer)
890 #define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferToImage)
891 #define __ENQUEUE_MAP_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueMapBuffer)
892 #define __ENQUEUE_MAP_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueMapImage)
893 #define __ENQUEUE_UNMAP_MEM_OBJECT_ERR CL_HPP_ERR_STR_(clEnqueueUnMapMemObject)
894 #define __ENQUEUE_NDRANGE_KERNEL_ERR CL_HPP_ERR_STR_(clEnqueueNDRangeKernel)
895 #define __ENQUEUE_NATIVE_KERNEL CL_HPP_ERR_STR_(clEnqueueNativeKernel)
896 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
897 #define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR CL_HPP_ERR_STR_(clEnqueueMigrateMemObjects)
898 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
899 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
900 #define __ENQUEUE_MIGRATE_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMMigrateMem)
901 #define __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clSetDefaultDeviceCommandQueue)
902 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
903
904
905 #define __ENQUEUE_ACQUIRE_GL_ERR CL_HPP_ERR_STR_(clEnqueueAcquireGLObjects)
906 #define __ENQUEUE_RELEASE_GL_ERR CL_HPP_ERR_STR_(clEnqueueReleaseGLObjects)
907
908 #define __CREATE_PIPE_ERR CL_HPP_ERR_STR_(clCreatePipe)
909 #define __GET_PIPE_INFO_ERR CL_HPP_ERR_STR_(clGetPipeInfo)
910
911
912 #define __RETAIN_ERR CL_HPP_ERR_STR_(Retain Object)
913 #define __RELEASE_ERR CL_HPP_ERR_STR_(Release Object)
914 #define __FLUSH_ERR CL_HPP_ERR_STR_(clFlush)
915 #define __FINISH_ERR CL_HPP_ERR_STR_(clFinish)
916 #define __VECTOR_CAPACITY_ERR CL_HPP_ERR_STR_(Vector capacity error)
917
918 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
919 #define __GET_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetHostTimer)
920 #define __GET_DEVICE_AND_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetDeviceAndHostTimer)
921 #endif
922 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
923 #define __SET_PROGRAM_RELEASE_CALLBACK_ERR CL_HPP_ERR_STR_(clSetProgramReleaseCallback)
924 #define __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR CL_HPP_ERR_STR_(clSetProgramSpecializationConstant)
925 #endif
926
927
931 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
932 #define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevices)
933 #else
934 #define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevicesEXT)
935 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
936
940 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
941 #define __ENQUEUE_MARKER_ERR CL_HPP_ERR_STR_(clEnqueueMarker)
942 #define __ENQUEUE_WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clEnqueueWaitForEvents)
943 #define __ENQUEUE_BARRIER_ERR CL_HPP_ERR_STR_(clEnqueueBarrier)
944 #define __UNLOAD_COMPILER_ERR CL_HPP_ERR_STR_(clUnloadCompiler)
945 #define __CREATE_GL_TEXTURE_2D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture2D)
946 #define __CREATE_GL_TEXTURE_3D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture3D)
947 #define __CREATE_IMAGE2D_ERR CL_HPP_ERR_STR_(clCreateImage2D)
948 #define __CREATE_IMAGE3D_ERR CL_HPP_ERR_STR_(clCreateImage3D)
949 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
950
954 #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
955 #define __CREATE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clCreateCommandQueue)
956 #define __ENQUEUE_TASK_ERR CL_HPP_ERR_STR_(clEnqueueTask)
957 #define __CREATE_SAMPLER_ERR CL_HPP_ERR_STR_(clCreateSampler)
958 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
959
963 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
964 #define __ENQUEUE_MARKER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueMarkerWithWaitList)
965 #define __ENQUEUE_BARRIER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueBarrierWithWaitList)
966 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
967
968 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
969 #define __CLONE_KERNEL_ERR CL_HPP_ERR_STR_(clCloneKernel)
970 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
971
972 #endif // CL_HPP_USER_OVERRIDE_ERROR_STRINGS
973
975
976 namespace detail {
977
978 // Generic getInfoHelper. The final parameter is used to guide overload
979 // resolution: the actual parameter passed is an int, which makes this
980 // a worse conversion sequence than a specialization that declares the
981 // parameter as an int.
982 template<typename Functor, typename T>
983 inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long)
984 {
985 return f(name, sizeof(T), param, NULL);
986 }
987
988 // Specialized for getInfo<CL_PROGRAM_BINARIES>
989 // Assumes that the output vector was correctly resized on the way in
990 template <typename Func>
991 inline cl_int getInfoHelper(Func f, cl_uint name, vector<vector<unsigned char>>* param, int)
992 {
993 if (name != CL_PROGRAM_BINARIES) {
994 return CL_INVALID_VALUE;
995 }
996 if (param) {
997 // Create array of pointers, calculate total size and pass pointer array in
998 size_type numBinaries = param->size();
999 vector<unsigned char*> binariesPointers(numBinaries);
1000
1001 for (size_type i = 0; i < numBinaries; ++i)
1002 {
1003 binariesPointers[i] = (*param)[i].data();
1004 }
1005
1006 cl_int err = f(name, numBinaries * sizeof(unsigned char*), binariesPointers.data(), NULL);
1007
1008 if (err != CL_SUCCESS) {
1009 return err;
1010 }
1011 }
1012
1013
1014 return CL_SUCCESS;
1015 }
1016
1017 // Specialized getInfoHelper for vector params
1018 template <typename Func, typename T>
1019 inline cl_int getInfoHelper(Func f, cl_uint name, vector<T>* param, long)
1020 {
1021 size_type required;
1022 cl_int err = f(name, 0, NULL, &required);
1023 if (err != CL_SUCCESS) {
1024 return err;
1025 }
1026 const size_type elements = required / sizeof(T);
1027
1028 // Temporary to avoid changing param on an error
1029 vector<T> localData(elements);
1030 err = f(name, required, localData.data(), NULL);
1031 if (err != CL_SUCCESS) {
1032 return err;
1033 }
1034 if (param) {
1035 *param = std::move(localData);
1036 }
1037
1038 return CL_SUCCESS;
1039 }
1040
1041 /* Specialization for reference-counted types. This depends on the
1042 * existence of Wrapper<T>::cl_type, and none of the other types having the
1043 * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1044 * does not work, because when using a derived type (e.g. Context) the generic
1045 * template will provide a better match.
1046 */
1047 template <typename Func, typename T>
1048 inline cl_int getInfoHelper(
1049 Func f, cl_uint name, vector<T>* param, int, typename T::cl_type = 0)
1050 {
1051 size_type required;
1052 cl_int err = f(name, 0, NULL, &required);
1053 if (err != CL_SUCCESS) {
1054 return err;
1055 }
1056
1057 const size_type elements = required / sizeof(typename T::cl_type);
1058
1059 vector<typename T::cl_type> value(elements);
1060 err = f(name, required, value.data(), NULL);
1061 if (err != CL_SUCCESS) {
1062 return err;
1063 }
1064
1065 if (param) {
1066 // Assign to convert CL type to T for each element
1067 param->resize(elements);
1068
1069 // Assign to param, constructing with retain behaviour
1070 // to correctly capture each underlying CL object
1071 for (size_type i = 0; i < elements; i++) {
1072 (*param)[i] = T(value[i], true);
1073 }
1074 }
1075 return CL_SUCCESS;
1076 }
1077
1078 // Specialized GetInfoHelper for string params
1079 template <typename Func>
1080 inline cl_int getInfoHelper(Func f, cl_uint name, string* param, long)
1081 {
1082 size_type required;
1083 cl_int err = f(name, 0, NULL, &required);
1084 if (err != CL_SUCCESS) {
1085 return err;
1086 }
1087
1088 // std::string has a constant data member
1089 // a char vector does not
1090 if (required > 0) {
1091 vector<char> value(required);
1092 err = f(name, required, value.data(), NULL);
1093 if (err != CL_SUCCESS) {
1094 return err;
1095 }
1096 if (param) {
1097 param->assign(begin(value), prev(end(value)));
1098 }
1099 }
1100 else if (param) {
1101 param->assign("");
1102 }
1103 return CL_SUCCESS;
1104 }
1105
1106 // Specialized GetInfoHelper for clsize_t params
1107 template <typename Func, size_type N>
1108 inline cl_int getInfoHelper(Func f, cl_uint name, array<size_type, N>* param, long)
1109 {
1110 size_type required;
1111 cl_int err = f(name, 0, NULL, &required);
1112 if (err != CL_SUCCESS) {
1113 return err;
1114 }
1115
1116 size_type elements = required / sizeof(size_type);
1117 vector<size_type> value(elements, 0);
1118
1119 err = f(name, required, value.data(), NULL);
1120 if (err != CL_SUCCESS) {
1121 return err;
1122 }
1123
1124 // Bound the copy with N to prevent overruns
1125 // if passed N > than the amount copied
1126 if (elements > N) {
1127 elements = N;
1128 }
1129 for (size_type i = 0; i < elements; ++i) {
1130 (*param)[i] = value[i];
1131 }
1132
1133 return CL_SUCCESS;
1134 }
1135
1136 template<typename T> struct ReferenceHandler;
1137
1138 /* Specialization for reference-counted types. This depends on the
1139 * existence of Wrapper<T>::cl_type, and none of the other types having the
1140 * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1141 * does not work, because when using a derived type (e.g. Context) the generic
1142 * template will provide a better match.
1143 */
1144 template<typename Func, typename T>
1145 inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0)
1146 {
1147 typename T::cl_type value;
1148 cl_int err = f(name, sizeof(value), &value, NULL);
1149 if (err != CL_SUCCESS) {
1150 return err;
1151 }
1152 *param = value;
1153 if (value != NULL)
1154 {
1155 err = param->retain();
1156 if (err != CL_SUCCESS) {
1157 return err;
1158 }
1159 }
1160 return CL_SUCCESS;
1161 }
1162
1163 #define CL_HPP_PARAM_NAME_INFO_1_0_(F) \
1164 F(cl_platform_info, CL_PLATFORM_PROFILE, string) \
1165 F(cl_platform_info, CL_PLATFORM_VERSION, string) \
1166 F(cl_platform_info, CL_PLATFORM_NAME, string) \
1167 F(cl_platform_info, CL_PLATFORM_VENDOR, string) \
1168 F(cl_platform_info, CL_PLATFORM_EXTENSIONS, string) \
1169 \
1170 F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
1171 F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
1172 F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
1173 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
1174 F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, size_type) \
1175 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, cl::vector<size_type>) \
1176 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
1177 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
1178 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
1179 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
1180 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
1181 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
1182 F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
1183 F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \
1184 F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
1185 F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
1186 F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
1187 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, size_type) \
1188 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, size_type) \
1189 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, size_type) \
1190 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, size_type) \
1191 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, size_type) \
1192 F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \
1193 F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, size_type) \
1194 F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
1195 F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
1196 F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
1197 F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
1198 F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
1199 F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
1200 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
1201 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
1202 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
1203 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
1204 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
1205 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
1206 F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
1207 F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
1208 F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
1209 F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, size_type) \
1210 F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
1211 F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
1212 F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
1213 F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
1214 F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
1215 F(cl_device_info, CL_DEVICE_NAME, string) \
1216 F(cl_device_info, CL_DEVICE_VENDOR, string) \
1217 F(cl_device_info, CL_DRIVER_VERSION, string) \
1218 F(cl_device_info, CL_DEVICE_PROFILE, string) \
1219 F(cl_device_info, CL_DEVICE_VERSION, string) \
1220 F(cl_device_info, CL_DEVICE_EXTENSIONS, string) \
1221 \
1222 F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
1223 F(cl_context_info, CL_CONTEXT_DEVICES, cl::vector<Device>) \
1224 F(cl_context_info, CL_CONTEXT_PROPERTIES, cl::vector<cl_context_properties>) \
1225 \
1226 F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
1227 F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
1228 F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
1229 F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \
1230 \
1231 F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
1232 F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
1233 F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
1234 F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
1235 \
1236 F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
1237 F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
1238 F(cl_mem_info, CL_MEM_SIZE, size_type) \
1239 F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
1240 F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
1241 F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
1242 F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
1243 \
1244 F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
1245 F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, size_type) \
1246 F(cl_image_info, CL_IMAGE_ROW_PITCH, size_type) \
1247 F(cl_image_info, CL_IMAGE_SLICE_PITCH, size_type) \
1248 F(cl_image_info, CL_IMAGE_WIDTH, size_type) \
1249 F(cl_image_info, CL_IMAGE_HEIGHT, size_type) \
1250 F(cl_image_info, CL_IMAGE_DEPTH, size_type) \
1251 \
1252 F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
1253 F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
1254 F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \
1255 F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \
1256 F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \
1257 \
1258 F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
1259 F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
1260 F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
1261 F(cl_program_info, CL_PROGRAM_DEVICES, cl::vector<Device>) \
1262 F(cl_program_info, CL_PROGRAM_SOURCE, string) \
1263 F(cl_program_info, CL_PROGRAM_BINARY_SIZES, cl::vector<size_type>) \
1264 F(cl_program_info, CL_PROGRAM_BINARIES, cl::vector<cl::vector<unsigned char>>) \
1265 \
1266 F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
1267 F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, string) \
1268 F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, string) \
1269 \
1270 F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, string) \
1271 F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
1272 F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
1273 F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
1274 F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
1275 \
1276 F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, size_type) \
1277 F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::detail::size_t_array) \
1278 F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
1279 \
1280 F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
1281 F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
1282 F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
1283 F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
1284
1285
1286 #define CL_HPP_PARAM_NAME_INFO_1_1_(F) \
1287 F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
1288 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
1289 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
1290 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
1291 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
1292 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
1293 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
1294 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
1295 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
1296 F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, string) \
1297 \
1298 F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
1299 F(cl_mem_info, CL_MEM_OFFSET, size_type) \
1300 \
1301 F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1302 F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
1303 \
1304 F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
1305
1306 #define CL_HPP_PARAM_NAME_INFO_1_2_(F) \
1307 F(cl_program_info, CL_PROGRAM_NUM_KERNELS, size_type) \
1308 F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, string) \
1309 \
1310 F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \
1311 \
1312 F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, string) \
1313 \
1314 F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \
1315 F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \
1316 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, string) \
1317 F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, string) \
1318 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \
1319 \
1320 F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl::Device) \
1321 F(cl_device_info, CL_DEVICE_PARTITION_MAX_SUB_DEVICES, cl_uint) \
1322 F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, cl::vector<cl_device_partition_property>) \
1323 F(cl_device_info, CL_DEVICE_PARTITION_TYPE, cl::vector<cl_device_partition_property>) \
1324 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \
1325 F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, size_type) \
1326 F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \
1327 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, string) \
1328 \
1329 F(cl_image_info, CL_IMAGE_ARRAY_SIZE, size_type) \
1330 F(cl_image_info, CL_IMAGE_NUM_MIP_LEVELS, cl_uint) \
1331 F(cl_image_info, CL_IMAGE_NUM_SAMPLES, cl_uint)
1332
1333 #define CL_HPP_PARAM_NAME_INFO_2_0_(F) \
1334 F(cl_device_info, CL_DEVICE_QUEUE_ON_HOST_PROPERTIES, cl_command_queue_properties) \
1335 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES, cl_command_queue_properties) \
1336 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, cl_uint) \
1337 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, cl_uint) \
1338 F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_QUEUES, cl_uint) \
1339 F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_EVENTS, cl_uint) \
1340 F(cl_device_info, CL_DEVICE_MAX_PIPE_ARGS, cl_uint) \
1341 F(cl_device_info, CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS, cl_uint) \
1342 F(cl_device_info, CL_DEVICE_PIPE_MAX_PACKET_SIZE, cl_uint) \
1343 F(cl_device_info, CL_DEVICE_SVM_CAPABILITIES, cl_device_svm_capabilities) \
1344 F(cl_device_info, CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT, cl_uint) \
1345 F(cl_device_info, CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT, cl_uint) \
1346 F(cl_device_info, CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT, cl_uint) \
1347 F(cl_profiling_info, CL_PROFILING_COMMAND_COMPLETE, cl_ulong) \
1348 F(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM, cl_bool) \
1349 F(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_SVM_PTRS, void**) \
1350 F(cl_command_queue_info, CL_QUEUE_SIZE, cl_uint) \
1351 F(cl_mem_info, CL_MEM_USES_SVM_POINTER, cl_bool) \
1352 F(cl_program_build_info, CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, size_type) \
1353 F(cl_pipe_info, CL_PIPE_PACKET_SIZE, cl_uint) \
1354 F(cl_pipe_info, CL_PIPE_MAX_PACKETS, cl_uint)
1355
1356 #define CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(F) \
1357 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR, size_type) \
1358 F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR, size_type)
1359
1360 #define CL_HPP_PARAM_NAME_INFO_IL_KHR_(F) \
1361 F(cl_device_info, CL_DEVICE_IL_VERSION_KHR, string) \
1362 F(cl_program_info, CL_PROGRAM_IL_KHR, cl::vector<unsigned char>)
1363
1364 #define CL_HPP_PARAM_NAME_INFO_2_1_(F) \
1365 F(cl_platform_info, CL_PLATFORM_HOST_TIMER_RESOLUTION, size_type) \
1366 F(cl_program_info, CL_PROGRAM_IL, cl::vector<unsigned char>) \
1367 F(cl_kernel_info, CL_KERNEL_MAX_NUM_SUB_GROUPS, size_type) \
1368 F(cl_kernel_info, CL_KERNEL_COMPILE_NUM_SUB_GROUPS, size_type) \
1369 F(cl_device_info, CL_DEVICE_MAX_NUM_SUB_GROUPS, cl_uint) \
1370 F(cl_device_info, CL_DEVICE_IL_VERSION, string) \
1371 F(cl_device_info, CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS, cl_bool) \
1372 F(cl_command_queue_info, CL_QUEUE_DEVICE_DEFAULT, cl::DeviceCommandQueue) \
1373 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE, size_type) \
1374 F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE, size_type) \
1375 F(cl_kernel_sub_group_info, CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT, cl::detail::size_t_array)
1376
1377 #define CL_HPP_PARAM_NAME_INFO_2_2_(F) \
1378 F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_CTORS_PRESENT, cl_bool) \
1379 F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_DTORS_PRESENT, cl_bool)
1380
1381 #define CL_HPP_PARAM_NAME_DEVICE_FISSION_(F) \
1382 F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
1383 F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, cl::vector<cl_device_partition_property_ext>) \
1384 F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, cl::vector<cl_device_partition_property_ext>) \
1385 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
1386 F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, cl::vector<cl_device_partition_property_ext>)
1387
1388 #define CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_CL3_SHARED_(F) \
1389 F(cl_platform_info, CL_PLATFORM_NUMERIC_VERSION_KHR, cl_version_khr) \
1390 F(cl_platform_info, CL_PLATFORM_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1391 \
1392 F(cl_device_info, CL_DEVICE_NUMERIC_VERSION_KHR, cl_version_khr) \
1393 F(cl_device_info, CL_DEVICE_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1394 F(cl_device_info, CL_DEVICE_ILS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1395 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>)
1396
1397 #define CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_KHRONLY_(F) \
1398 F(cl_device_info, CL_DEVICE_OPENCL_C_NUMERIC_VERSION_KHR, cl_version_khr)
1399
1400 #define CL_HPP_PARAM_NAME_INFO_3_0_(F) \
1401 F(cl_platform_info, CL_PLATFORM_NUMERIC_VERSION, cl_version) \
1402 F(cl_platform_info, CL_PLATFORM_EXTENSIONS_WITH_VERSION, cl::vector<cl_name_version>) \
1403 \
1404 F(cl_device_info, CL_DEVICE_NUMERIC_VERSION, cl_version) \
1405 F(cl_device_info, CL_DEVICE_EXTENSIONS_WITH_VERSION, cl::vector<cl_name_version>) \
1406 F(cl_device_info, CL_DEVICE_ILS_WITH_VERSION, cl::vector<cl_name_version>) \
1407 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION, cl::vector<cl_name_version>) \
1408 F(cl_device_info, CL_DEVICE_ATOMIC_MEMORY_CAPABILITIES, cl_device_atomic_capabilities) \
1409 F(cl_device_info, CL_DEVICE_ATOMIC_FENCE_CAPABILITIES, cl_device_atomic_capabilities) \
1410 F(cl_device_info, CL_DEVICE_NON_UNIFORM_WORK_GROUP_SUPPORT, cl_bool) \
1411 F(cl_device_info, CL_DEVICE_OPENCL_C_ALL_VERSIONS, cl::vector<cl_name_version>) \
1412 F(cl_device_info, CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1413 F(cl_device_info, CL_DEVICE_WORK_GROUP_COLLECTIVE_FUNCTIONS_SUPPORT, cl_bool) \
1414 F(cl_device_info, CL_DEVICE_GENERIC_ADDRESS_SPACE_SUPPORT, cl_bool) \
1415 F(cl_device_info, CL_DEVICE_OPENCL_C_FEATURES, cl::vector<cl_name_version>) \
1416 F(cl_device_info, CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES, cl_device_device_enqueue_capabilities) \
1417 F(cl_device_info, CL_DEVICE_PIPE_SUPPORT, cl_bool) \
1418 F(cl_device_info, CL_DEVICE_LATEST_CONFORMANCE_VERSION_PASSED, string) \
1419 \
1420 F(cl_command_queue_info, CL_QUEUE_PROPERTIES_ARRAY, cl::vector<cl_queue_properties>) \
1421 F(cl_mem_info, CL_MEM_PROPERTIES, cl::vector<cl_mem_properties>) \
1422 F(cl_pipe_info, CL_PIPE_PROPERTIES, cl::vector<cl_pipe_properties>) \
1423 F(cl_sampler_info, CL_SAMPLER_PROPERTIES, cl::vector<cl_sampler_properties>)
1424
1425 template <typename enum_type, cl_int Name>
1426 struct param_traits {};
1427
1428 #define CL_HPP_DECLARE_PARAM_TRAITS_(token, param_name, T) \
1429 struct token; \
1430 template<> \
1431 struct param_traits<detail:: token,param_name> \
1432 { \
1433 enum { value = param_name }; \
1434 typedef T param_type; \
1435 };
1436
1437 CL_HPP_PARAM_NAME_INFO_1_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1438 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
1439 CL_HPP_PARAM_NAME_INFO_1_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1440 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
1441 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1442 CL_HPP_PARAM_NAME_INFO_1_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1443 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1444 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
1445 CL_HPP_PARAM_NAME_INFO_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1446 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
1447 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
1448 CL_HPP_PARAM_NAME_INFO_2_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1449 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
1450 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
1451 CL_HPP_PARAM_NAME_INFO_2_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1452 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
1453 #if CL_HPP_TARGET_OPENCL_VERSION >= 300
1454 CL_HPP_PARAM_NAME_INFO_3_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1455 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
1456
1457 #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1458 CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1459 #endif // #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1460
1461 #if defined(CL_HPP_USE_IL_KHR)
1462 CL_HPP_PARAM_NAME_INFO_IL_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1463 #endif // #if defined(CL_HPP_USE_IL_KHR)
1464
1465
1466 // Flags deprecated in OpenCL 2.0
1467 #define CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(F) \
1468 F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties)
1469
1470 #define CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(F) \
1471 F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool)
1472
1473 #define CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(F) \
1474 F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer)
1475
1476 // Include deprecated query flags based on versions
1477 // Only include deprecated 1.0 flags if 2.0 not active as there is an enum clash
1478 #if CL_HPP_TARGET_OPENCL_VERSION > 100 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 && CL_HPP_TARGET_OPENCL_VERSION < 200
1479 CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1480 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 110
1481 #if CL_HPP_TARGET_OPENCL_VERSION > 110 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1482 CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1483 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1484 #if CL_HPP_TARGET_OPENCL_VERSION > 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1485 CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1486 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
1487
1488 #if defined(CL_HPP_USE_CL_DEVICE_FISSION)
1489 CL_HPP_PARAM_NAME_DEVICE_FISSION_(CL_HPP_DECLARE_PARAM_TRAITS_);
1490 #endif // CL_HPP_USE_CL_DEVICE_FISSION
1491
1492 #if defined(cl_khr_extended_versioning)
1493 #if CL_HPP_TARGET_OPENCL_VERSION < 300
1494 CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_CL3_SHARED_(CL_HPP_DECLARE_PARAM_TRAITS_);
1495 #endif // CL_HPP_TARGET_OPENCL_VERSION < 300
1496 CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_KHRONLY_(CL_HPP_DECLARE_PARAM_TRAITS_);
1497 #endif // cl_khr_extended_versioning
1498
1499 #ifdef CL_PLATFORM_ICD_SUFFIX_KHR
1500 CL_HPP_DECLARE_PARAM_TRAITS_(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, string)
1501 #endif
1502
1503 #ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
1504 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong)
1505 #endif
1506
1507 #ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
1508 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, vector<size_type>)
1509 #endif
1510 #ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
1511 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint)
1512 #endif
1513 #ifdef CL_DEVICE_SIMD_WIDTH_AMD
1514 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint)
1515 #endif
1516 #ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD
1517 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint)
1518 #endif
1519 #ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD
1520 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint)
1521 #endif
1522 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
1523 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint)
1524 #endif
1525 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
1526 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint)
1527 #endif
1528 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
1529 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint)
1530 #endif
1531 #ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
1532 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint)
1533 #endif
1534 #ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
1535 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint)
1536 #endif
1537
1538 #ifdef CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM
1539 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM, cl_ulong)
1540 #endif
1541 #ifdef CL_DEVICE_JOB_SLOTS_ARM
1542 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_JOB_SLOTS_ARM, cl_uint)
1543 #endif
1544 #ifdef CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM
1545 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM, cl_bitfield)
1546 #endif
1547 #ifdef CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_ARM
1548 CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_ARM, cl_uint)
1549 #endif
1550 #ifdef CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM
1551 CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM, cl_int)
1552 #endif
1553
1554 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
1555 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint)
1556 #endif
1557 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV
1558 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint)
1559 #endif
1560 #ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV
1561 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint)
1562 #endif
1563 #ifdef CL_DEVICE_WARP_SIZE_NV
1564 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint)
1565 #endif
1566 #ifdef CL_DEVICE_GPU_OVERLAP_NV
1567 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool)
1568 #endif
1569 #ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV
1570 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool)
1571 #endif
1572 #ifdef CL_DEVICE_INTEGRATED_MEMORY_NV
1573 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool)
1574 #endif
1575
1576 // Convenience functions
1577
1578 template <typename Func, typename T>
1579 inline cl_int
1580 getInfo(Func f, cl_uint name, T* param)
1581 {
1582 return getInfoHelper(f, name, param, 0);
1583 }
1584
1585 template <typename Func, typename Arg0>
1586 struct GetInfoFunctor0
1587 {
1588 Func f_; const Arg0& arg0_;
1589 cl_int operator ()(
1590 cl_uint param, size_type size, void* value, size_type* size_ret)
1591 { return f_(arg0_, param, size, value, size_ret); }
1592 };
1593
1594 template <typename Func, typename Arg0, typename Arg1>
1595 struct GetInfoFunctor1
1596 {
1597 Func f_; const Arg0& arg0_; const Arg1& arg1_;
1598 cl_int operator ()(
1599 cl_uint param, size_type size, void* value, size_type* size_ret)
1600 { return f_(arg0_, arg1_, param, size, value, size_ret); }
1601 };
1602
1603 template <typename Func, typename Arg0, typename T>
1604 inline cl_int
1605 getInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
1606 {
1607 GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
1608 return getInfoHelper(f0, name, param, 0);
1609 }
1610
1611 template <typename Func, typename Arg0, typename Arg1, typename T>
1612 inline cl_int
1613 getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
1614 {
1615 GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
1616 return getInfoHelper(f0, name, param, 0);
1617 }
1618
1619
1620 template<typename T>
1621 struct ReferenceHandler
1622 { };
1623
1624 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1625
1628 template <>
1629 struct ReferenceHandler<cl_device_id>
1630 {
1640 static cl_int retain(cl_device_id device)
1641 { return ::clRetainDevice(device); }
1651 static cl_int release(cl_device_id device)
1652 { return ::clReleaseDevice(device); }
1653 };
1654 #else // CL_HPP_TARGET_OPENCL_VERSION >= 120
1655
1658 template <>
1659 struct ReferenceHandler<cl_device_id>
1660 {
1661 // cl_device_id does not have retain().
1662 static cl_int retain(cl_device_id)
1663 { return CL_SUCCESS; }
1664 // cl_device_id does not have release().
1665 static cl_int release(cl_device_id)
1666 { return CL_SUCCESS; }
1667 };
1668 #endif // ! (CL_HPP_TARGET_OPENCL_VERSION >= 120)
1669
1670 template <>
1671 struct ReferenceHandler<cl_platform_id>
1672 {
1673 // cl_platform_id does not have retain().
1674 static cl_int retain(cl_platform_id)
1675 { return CL_SUCCESS; }
1676 // cl_platform_id does not have release().
1677 static cl_int release(cl_platform_id)
1678 { return CL_SUCCESS; }
1679 };
1680
1681 template <>
1682 struct ReferenceHandler<cl_context>
1683 {
1684 static cl_int retain(cl_context context)
1685 { return ::clRetainContext(context); }
1686 static cl_int release(cl_context context)
1687 { return ::clReleaseContext(context); }
1688 };
1689
1690 template <>
1691 struct ReferenceHandler<cl_command_queue>
1692 {
1693 static cl_int retain(cl_command_queue queue)
1694 { return ::clRetainCommandQueue(queue); }
1695 static cl_int release(cl_command_queue queue)
1696 { return ::clReleaseCommandQueue(queue); }
1697 };
1698
1699 template <>
1700 struct ReferenceHandler<cl_mem>
1701 {
1702 static cl_int retain(cl_mem memory)
1703 { return ::clRetainMemObject(memory); }
1704 static cl_int release(cl_mem memory)
1705 { return ::clReleaseMemObject(memory); }
1706 };
1707
1708 template <>
1709 struct ReferenceHandler<cl_sampler>
1710 {
1711 static cl_int retain(cl_sampler sampler)
1712 { return ::clRetainSampler(sampler); }
1713 static cl_int release(cl_sampler sampler)
1714 { return ::clReleaseSampler(sampler); }
1715 };
1716
1717 template <>
1718 struct ReferenceHandler<cl_program>
1719 {
1720 static cl_int retain(cl_program program)
1721 { return ::clRetainProgram(program); }
1722 static cl_int release(cl_program program)
1723 { return ::clReleaseProgram(program); }
1724 };
1725
1726 template <>
1727 struct ReferenceHandler<cl_kernel>
1728 {
1729 static cl_int retain(cl_kernel kernel)
1730 { return ::clRetainKernel(kernel); }
1731 static cl_int release(cl_kernel kernel)
1732 { return ::clReleaseKernel(kernel); }
1733 };
1734
1735 template <>
1736 struct ReferenceHandler<cl_event>
1737 {
1738 static cl_int retain(cl_event event)
1739 { return ::clRetainEvent(event); }
1740 static cl_int release(cl_event event)
1741 { return ::clReleaseEvent(event); }
1742 };
1743
1744
1745 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1746 // Extracts version number with major in the upper 16 bits, minor in the lower 16
1747 static cl_uint getVersion(const vector<char> &versionInfo)
1748 {
1749 int highVersion = 0;
1750 int lowVersion = 0;
1751 int index = 7;
1752 while(versionInfo[index] != '.' ) {
1753 highVersion *= 10;
1754 highVersion += versionInfo[index]-'0';
1755 ++index;
1756 }
1757 ++index;
1758 while(versionInfo[index] != ' ' && versionInfo[index] != '\0') {
1759 lowVersion *= 10;
1760 lowVersion += versionInfo[index]-'0';
1761 ++index;
1762 }
1763 return (highVersion << 16) | lowVersion;
1764 }
1765
1766 static cl_uint getPlatformVersion(cl_platform_id platform)
1767 {
1768 size_type size = 0;
1769 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size);
1770
1771 vector<char> versionInfo(size);
1772 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, versionInfo.data(), &size);
1773 return getVersion(versionInfo);
1774 }
1775
1776 static cl_uint getDevicePlatformVersion(cl_device_id device)
1777 {
1778 cl_platform_id platform;
1779 clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL);
1780 return getPlatformVersion(platform);
1781 }
1782
1783 static cl_uint getContextPlatformVersion(cl_context context)
1784 {
1785 // The platform cannot be queried directly, so we first have to grab a
1786 // device and obtain its context
1787 size_type size = 0;
1788 clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size);
1789 if (size == 0)
1790 return 0;
1791 vector<cl_device_id> devices(size/sizeof(cl_device_id));
1792 clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices.data(), NULL);
1793 return getDevicePlatformVersion(devices[0]);
1794 }
1795 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1796
1797 template <typename T>
1798 class Wrapper
1799 {
1800 public:
1801 typedef T cl_type;
1802
1803 protected:
1804 cl_type object_;
1805
1806 public:
1807 Wrapper() : object_(NULL) { }
1808
1809 Wrapper(const cl_type &obj, bool retainObject) : object_(obj)
1810 {
1811 if (retainObject) {
1812 detail::errHandler(retain(), __RETAIN_ERR);
1813 }
1814 }
1815
1816 ~Wrapper()
1817 {
1818 if (object_ != NULL) { release(); }
1819 }
1820
1821 Wrapper(const Wrapper<cl_type>& rhs)
1822 {
1823 object_ = rhs.object_;
1824 detail::errHandler(retain(), __RETAIN_ERR);
1825 }
1826
1827 Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT_
1828 {
1829 object_ = rhs.object_;
1830 rhs.object_ = NULL;
1831 }
1832
1833 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
1834 {
1835 if (this != &rhs) {
1836 detail::errHandler(release(), __RELEASE_ERR);
1837 object_ = rhs.object_;
1838 detail::errHandler(retain(), __RETAIN_ERR);
1839 }
1840 return *this;
1841 }
1842
1843 Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
1844 {
1845 if (this != &rhs) {
1846 detail::errHandler(release(), __RELEASE_ERR);
1847 object_ = rhs.object_;
1848 rhs.object_ = NULL;
1849 }
1850 return *this;
1851 }
1852
1853 Wrapper<cl_type>& operator = (const cl_type &rhs)
1854 {
1855 detail::errHandler(release(), __RELEASE_ERR);
1856 object_ = rhs;
1857 return *this;
1858 }
1859
1860 const cl_type& operator ()() const { return object_; }
1861
1862 cl_type& operator ()() { return object_; }
1863
1864 cl_type get() const { return object_; }
1865
1866 protected:
1867 template<typename Func, typename U>
1868 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
1869
1870 cl_int retain() const
1871 {
1872 if (object_ != nullptr) {
1873 return ReferenceHandler<cl_type>::retain(object_);
1874 }
1875 else {
1876 return CL_SUCCESS;
1877 }
1878 }
1879
1880 cl_int release() const
1881 {
1882 if (object_ != nullptr) {
1883 return ReferenceHandler<cl_type>::release(object_);
1884 }
1885 else {
1886 return CL_SUCCESS;
1887 }
1888 }
1889 };
1890
1891 template <>
1892 class Wrapper<cl_device_id>
1893 {
1894 public:
1895 typedef cl_device_id cl_type;
1896
1897 protected:
1898 cl_type object_;
1899 bool referenceCountable_;
1900
1901 static bool isReferenceCountable(cl_device_id device)
1902 {
1903 bool retVal = false;
1904 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1905 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
1906 if (device != NULL) {
1907 int version = getDevicePlatformVersion(device);
1908 if(version > ((1 << 16) + 1)) {
1909 retVal = true;
1910 }
1911 }
1912 #else // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1913 retVal = true;
1914 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1915 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1916 return retVal;
1917 }
1918
1919 public:
1920 Wrapper() : object_(NULL), referenceCountable_(false)
1921 {
1922 }
1923
1924 Wrapper(const cl_type &obj, bool retainObject) :
1925 object_(obj),
1926 referenceCountable_(false)
1927 {
1928 referenceCountable_ = isReferenceCountable(obj);
1929
1930 if (retainObject) {
1931 detail::errHandler(retain(), __RETAIN_ERR);
1932 }
1933 }
1934
1935 ~Wrapper()
1936 {
1937 release();
1938 }
1939
1940 Wrapper(const Wrapper<cl_type>& rhs)
1941 {
1942 object_ = rhs.object_;
1943 referenceCountable_ = isReferenceCountable(object_);
1944 detail::errHandler(retain(), __RETAIN_ERR);
1945 }
1946
1947 Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT_
1948 {
1949 object_ = rhs.object_;
1950 referenceCountable_ = rhs.referenceCountable_;
1951 rhs.object_ = NULL;
1952 rhs.referenceCountable_ = false;
1953 }
1954
1955 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
1956 {
1957 if (this != &rhs) {
1958 detail::errHandler(release(), __RELEASE_ERR);
1959 object_ = rhs.object_;
1960 referenceCountable_ = rhs.referenceCountable_;
1961 detail::errHandler(retain(), __RETAIN_ERR);
1962 }
1963 return *this;
1964 }
1965
1966 Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
1967 {
1968 if (this != &rhs) {
1969 detail::errHandler(release(), __RELEASE_ERR);
1970 object_ = rhs.object_;
1971 referenceCountable_ = rhs.referenceCountable_;
1972 rhs.object_ = NULL;
1973 rhs.referenceCountable_ = false;
1974 }
1975 return *this;
1976 }
1977
1978 Wrapper<cl_type>& operator = (const cl_type &rhs)
1979 {
1980 detail::errHandler(release(), __RELEASE_ERR);
1981 object_ = rhs;
1982 referenceCountable_ = isReferenceCountable(object_);
1983 return *this;
1984 }
1985
1986 const cl_type& operator ()() const { return object_; }
1987
1988 cl_type& operator ()() { return object_; }
1989
1990 cl_type get() const { return object_; }
1991
1992 protected:
1993 template<typename Func, typename U>
1994 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
1995
1996 template<typename Func, typename U>
1997 friend inline cl_int getInfoHelper(Func, cl_uint, vector<U>*, int, typename U::cl_type);
1998
1999 cl_int retain() const
2000 {
2001 if( object_ != nullptr && referenceCountable_ ) {
2002 return ReferenceHandler<cl_type>::retain(object_);
2003 }
2004 else {
2005 return CL_SUCCESS;
2006 }
2007 }
2008
2009 cl_int release() const
2010 {
2011 if (object_ != nullptr && referenceCountable_) {
2012 return ReferenceHandler<cl_type>::release(object_);
2013 }
2014 else {
2015 return CL_SUCCESS;
2016 }
2017 }
2018 };
2019
2020 template <typename T>
2021 inline bool operator==(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
2022 {
2023 return lhs() == rhs();
2024 }
2025
2026 template <typename T>
2027 inline bool operator!=(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
2028 {
2029 return !operator==(lhs, rhs);
2030 }
2031
2032 } // namespace detail
2034
2035
2036 using BuildLogType = vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, CL_PROGRAM_BUILD_LOG>::param_type>>;
2037 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2038
2041 class BuildError : public Error
2042 {
2043 private:
2044 BuildLogType buildLogs;
2045 public:
2046 BuildError(cl_int err, const char * errStr, const BuildLogType &vec) : Error(err, errStr), buildLogs(vec)
2047 {
2048 }
2049
2050 BuildLogType getBuildLog() const
2051 {
2052 return buildLogs;
2053 }
2054 };
2055 namespace detail {
2056 static inline cl_int buildErrHandler(
2057 cl_int err,
2058 const char * errStr,
2059 const BuildLogType &buildLogs)
2060 {
2061 if (err != CL_SUCCESS) {
2062 throw BuildError(err, errStr, buildLogs);
2063 }
2064 return err;
2065 }
2066 } // namespace detail
2067
2068 #else
2069 namespace detail {
2070 static inline cl_int buildErrHandler(
2071 cl_int err,
2072 const char * errStr,
2073 const BuildLogType &buildLogs)
2074 {
2075 (void)buildLogs; // suppress unused variable warning
2076 (void)errStr;
2077 return err;
2078 }
2079 } // namespace detail
2080 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2081
2082
2088 struct ImageFormat : public cl_image_format
2089 {
2091 ImageFormat(){}
2092
2094 ImageFormat(cl_channel_order order, cl_channel_type type)
2095 {
2096 image_channel_order = order;
2097 image_channel_data_type = type;
2098 }
2099
2101 ImageFormat& operator = (const ImageFormat& rhs)
2102 {
2103 if (this != &rhs) {
2104 this->image_channel_data_type = rhs.image_channel_data_type;
2105 this->image_channel_order = rhs.image_channel_order;
2106 }
2107 return *this;
2108 }
2109 };
2110
2118 class Device : public detail::Wrapper<cl_device_id>
2119 {
2120 private:
2121 static std::once_flag default_initialized_;
2122 static Device default_;
2123 static cl_int default_error_;
2124
2130 static void makeDefault();
2131
2137 static void makeDefaultProvided(const Device &p) {
2138 default_ = p;
2139 }
2140
2141 public:
2142 #ifdef CL_HPP_UNIT_TEST_ENABLE
2143
2149 static void unitTestClearDefault() {
2150 default_ = Device();
2151 }
2152 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2153
2155 Device() : detail::Wrapper<cl_type>() { }
2156
2161 explicit Device(const cl_device_id &device, bool retainObject = false) :
2162 detail::Wrapper<cl_type>(device, retainObject) { }
2163
2168 static Device getDefault(
2169 cl_int *errResult = NULL)
2170 {
2171 std::call_once(default_initialized_, makeDefault);
2172 detail::errHandler(default_error_);
2173 if (errResult != NULL) {
2174 *errResult = default_error_;
2175 }
2176 return default_;
2177 }
2178
2186 static Device setDefault(const Device &default_device)
2187 {
2188 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_device));
2189 detail::errHandler(default_error_);
2190 return default_;
2191 }
2192
2197 Device& operator = (const cl_device_id& rhs)
2198 {
2199 detail::Wrapper<cl_type>::operator=(rhs);
2200 return *this;
2201 }
2202
2206 Device(const Device& dev) : detail::Wrapper<cl_type>(dev) {}
2207
2211 Device& operator = (const Device &dev)
2212 {
2213 detail::Wrapper<cl_type>::operator=(dev);
2214 return *this;
2215 }
2216
2220 Device(Device&& dev) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(dev)) {}
2221
2225 Device& operator = (Device &&dev)
2226 {
2227 detail::Wrapper<cl_type>::operator=(std::move(dev));
2228 return *this;
2229 }
2230
2232 template <typename T>
2233 cl_int getInfo(cl_device_info name, T* param) const
2234 {
2235 return detail::errHandler(
2236 detail::getInfo(&::clGetDeviceInfo, object_, name, param),
2237 __GET_DEVICE_INFO_ERR);
2238 }
2239
2241 template <cl_device_info name> typename
2242 detail::param_traits<detail::cl_device_info, name>::param_type
2243 getInfo(cl_int* err = NULL) const
2244 {
2245 typename detail::param_traits<
2246 detail::cl_device_info, name>::param_type param;
2247 cl_int result = getInfo(name, &param);
2248 if (err != NULL) {
2249 *err = result;
2250 }
2251 return param;
2252 }
2253
2254
2255 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2256
2262 cl_ulong getHostTimer(cl_int *error = nullptr)
2263 {
2264 cl_ulong retVal = 0;
2265 cl_int err =
2266 clGetHostTimer(this->get(), &retVal);
2267 detail::errHandler(
2268 err,
2269 __GET_HOST_TIMER_ERR);
2270 if (error) {
2271 *error = err;
2272 }
2273 return retVal;
2274 }
2275
2286 std::pair<cl_ulong, cl_ulong> getDeviceAndHostTimer(cl_int *error = nullptr)
2287 {
2288 std::pair<cl_ulong, cl_ulong> retVal;
2289 cl_int err =
2290 clGetDeviceAndHostTimer(this->get(), &(retVal.first), &(retVal.second));
2291 detail::errHandler(
2292 err,
2293 __GET_DEVICE_AND_HOST_TIMER_ERR);
2294 if (error) {
2295 *error = err;
2296 }
2297 return retVal;
2298 }
2299 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2300
2304 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
2305 cl_int createSubDevices(
2307 const cl_device_partition_property * properties,
2308 vector<Device>* devices)
2309 {
2310 cl_uint n = 0;
2311 cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n);
2312 if (err != CL_SUCCESS) {
2313 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2314 }
2315
2316 vector<cl_device_id> ids(n);
2317 err = clCreateSubDevices(object_, properties, n, ids.data(), NULL);
2318 if (err != CL_SUCCESS) {
2319 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2320 }
2321
2322 // Cannot trivially assign because we need to capture intermediates
2323 // with safe construction
2324 if (devices) {
2325 devices->resize(ids.size());
2326
2327 // Assign to param, constructing with retain behaviour
2328 // to correctly capture each underlying CL object
2329 for (size_type i = 0; i < ids.size(); i++) {
2330 // We do not need to retain because this device is being created
2331 // by the runtime
2332 (*devices)[i] = Device(ids[i], false);
2333 }
2334 }
2335
2336 return CL_SUCCESS;
2337 }
2338 #elif defined(CL_HPP_USE_CL_DEVICE_FISSION)
2339
2343 cl_int createSubDevices(
2344 const cl_device_partition_property_ext * properties,
2345 vector<Device>* devices)
2346 {
2347 typedef CL_API_ENTRY cl_int
2348 ( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
2349 cl_device_id /*in_device*/,
2350 const cl_device_partition_property_ext * /* properties */,
2351 cl_uint /*num_entries*/,
2352 cl_device_id * /*out_devices*/,
2353 cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1;
2354
2355 static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
2356 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSubDevicesEXT);
2357
2358 cl_uint n = 0;
2359 cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
2360 if (err != CL_SUCCESS) {
2361 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2362 }
2363
2364 vector<cl_device_id> ids(n);
2365 err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids.data(), NULL);
2366 if (err != CL_SUCCESS) {
2367 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2368 }
2369 // Cannot trivially assign because we need to capture intermediates
2370 // with safe construction
2371 if (devices) {
2372 devices->resize(ids.size());
2373
2374 // Assign to param, constructing with retain behaviour
2375 // to correctly capture each underlying CL object
2376 for (size_type i = 0; i < ids.size(); i++) {
2377 // We do not need to retain because this device is being created
2378 // by the runtime
2379 (*devices)[i] = Device(ids[i], false);
2380 }
2381 }
2382 return CL_SUCCESS;
2383 }
2384 #endif // defined(CL_HPP_USE_CL_DEVICE_FISSION)
2385 };
2386
2387 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Device::default_initialized_;
2388 CL_HPP_DEFINE_STATIC_MEMBER_ Device Device::default_;
2389 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Device::default_error_ = CL_SUCCESS;
2390
2398 class Platform : public detail::Wrapper<cl_platform_id>
2399 {
2400 private:
2401 static std::once_flag default_initialized_;
2402 static Platform default_;
2403 static cl_int default_error_;
2404
2410 static void makeDefault() {
2411 /* Throwing an exception from a call_once invocation does not do
2412 * what we wish, so we catch it and save the error.
2413 */
2414 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2415 try
2416 #endif
2417 {
2418 // If default wasn't passed ,generate one
2419 // Otherwise set it
2420 cl_uint n = 0;
2421
2422 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2423 if (err != CL_SUCCESS) {
2424 default_error_ = err;
2425 return;
2426 }
2427 if (n == 0) {
2428 default_error_ = CL_INVALID_PLATFORM;
2429 return;
2430 }
2431
2432 vector<cl_platform_id> ids(n);
2433 err = ::clGetPlatformIDs(n, ids.data(), NULL);
2434 if (err != CL_SUCCESS) {
2435 default_error_ = err;
2436 return;
2437 }
2438
2439 default_ = Platform(ids[0]);
2440 }
2441 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2442 catch (cl::Error &e) {
2443 default_error_ = e.err();
2444 }
2445 #endif
2446 }
2447
2453 static void makeDefaultProvided(const Platform &p) {
2454 default_ = p;
2455 }
2456
2457 public:
2458 #ifdef CL_HPP_UNIT_TEST_ENABLE
2459
2465 static void unitTestClearDefault() {
2466 default_ = Platform();
2467 }
2468 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2469
2471 Platform() : detail::Wrapper<cl_type>() { }
2472
2480 explicit Platform(const cl_platform_id &platform, bool retainObject = false) :
2481 detail::Wrapper<cl_type>(platform, retainObject) { }
2482
2487 Platform& operator = (const cl_platform_id& rhs)
2488 {
2489 detail::Wrapper<cl_type>::operator=(rhs);
2490 return *this;
2491 }
2492
2493 static Platform getDefault(
2494 cl_int *errResult = NULL)
2495 {
2496 std::call_once(default_initialized_, makeDefault);
2497 detail::errHandler(default_error_);
2498 if (errResult != NULL) {
2499 *errResult = default_error_;
2500 }
2501 return default_;
2502 }
2503
2511 static Platform setDefault(const Platform &default_platform)
2512 {
2513 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_platform));
2514 detail::errHandler(default_error_);
2515 return default_;
2516 }
2517
2519 template <typename T>
2520 cl_int getInfo(cl_platform_info name, T* param) const
2521 {
2522 return detail::errHandler(
2523 detail::getInfo(&::clGetPlatformInfo, object_, name, param),
2524 __GET_PLATFORM_INFO_ERR);
2525 }
2526
2528 template <cl_platform_info name> typename
2529 detail::param_traits<detail::cl_platform_info, name>::param_type
2530 getInfo(cl_int* err = NULL) const
2531 {
2532 typename detail::param_traits<
2533 detail::cl_platform_info, name>::param_type param;
2534 cl_int result = getInfo(name, &param);
2535 if (err != NULL) {
2536 *err = result;
2537 }
2538 return param;
2539 }
2540
2545 cl_int getDevices(
2546 cl_device_type type,
2547 vector<Device>* devices) const
2548 {
2549 cl_uint n = 0;
2550 if( devices == NULL ) {
2551 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2552 }
2553 cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
2554 if (err != CL_SUCCESS && err != CL_DEVICE_NOT_FOUND) {
2555 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2556 }
2557
2558 vector<cl_device_id> ids(n);
2559 if (n>0) {
2560 err = ::clGetDeviceIDs(object_, type, n, ids.data(), NULL);
2561 if (err != CL_SUCCESS) {
2562 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2563 }
2564 }
2565
2566 // Cannot trivially assign because we need to capture intermediates
2567 // with safe construction
2568 // We must retain things we obtain from the API to avoid releasing
2569 // API-owned objects.
2570 if (devices) {
2571 devices->resize(ids.size());
2572
2573 // Assign to param, constructing with retain behaviour
2574 // to correctly capture each underlying CL object
2575 for (size_type i = 0; i < ids.size(); i++) {
2576 (*devices)[i] = Device(ids[i], true);
2577 }
2578 }
2579 return CL_SUCCESS;
2580 }
2581
2582 #if defined(CL_HPP_USE_DX_INTEROP)
2583
2606 cl_int getDevices(
2607 cl_d3d10_device_source_khr d3d_device_source,
2608 void * d3d_object,
2609 cl_d3d10_device_set_khr d3d_device_set,
2610 vector<Device>* devices) const
2611 {
2612 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
2613 cl_platform_id platform,
2614 cl_d3d10_device_source_khr d3d_device_source,
2615 void * d3d_object,
2616 cl_d3d10_device_set_khr d3d_device_set,
2617 cl_uint num_entries,
2618 cl_device_id * devices,
2619 cl_uint* num_devices);
2620
2621 if( devices == NULL ) {
2622 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2623 }
2624
2625 static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
2626 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(object_, clGetDeviceIDsFromD3D10KHR);
2627
2628 cl_uint n = 0;
2629 cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
2630 object_,
2631 d3d_device_source,
2632 d3d_object,
2633 d3d_device_set,
2634 0,
2635 NULL,
2636 &n);
2637 if (err != CL_SUCCESS) {
2638 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2639 }
2640
2641 vector<cl_device_id> ids(n);
2642 err = pfn_clGetDeviceIDsFromD3D10KHR(
2643 object_,
2644 d3d_device_source,
2645 d3d_object,
2646 d3d_device_set,
2647 n,
2648 ids.data(),
2649 NULL);
2650 if (err != CL_SUCCESS) {
2651 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2652 }
2653
2654 // Cannot trivially assign because we need to capture intermediates
2655 // with safe construction
2656 // We must retain things we obtain from the API to avoid releasing
2657 // API-owned objects.
2658 if (devices) {
2659 devices->resize(ids.size());
2660
2661 // Assign to param, constructing with retain behaviour
2662 // to correctly capture each underlying CL object
2663 for (size_type i = 0; i < ids.size(); i++) {
2664 (*devices)[i] = Device(ids[i], true);
2665 }
2666 }
2667 return CL_SUCCESS;
2668 }
2669 #endif
2670
2675 static cl_int get(
2676 vector<Platform>* platforms)
2677 {
2678 cl_uint n = 0;
2679
2680 if( platforms == NULL ) {
2681 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
2682 }
2683
2684 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2685 if (err != CL_SUCCESS) {
2686 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2687 }
2688
2689 vector<cl_platform_id> ids(n);
2690 err = ::clGetPlatformIDs(n, ids.data(), NULL);
2691 if (err != CL_SUCCESS) {
2692 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2693 }
2694
2695 if (platforms) {
2696 platforms->resize(ids.size());
2697
2698 // Platforms don't reference count
2699 for (size_type i = 0; i < ids.size(); i++) {
2700 (*platforms)[i] = Platform(ids[i]);
2701 }
2702 }
2703 return CL_SUCCESS;
2704 }
2705
2710 static cl_int get(
2711 Platform * platform)
2712 {
2713 cl_int err;
2714 Platform default_platform = Platform::getDefault(&err);
2715 if (platform) {
2716 *platform = default_platform;
2717 }
2718 return err;
2719 }
2720
2729 static Platform get(
2730 cl_int * errResult = NULL)
2731 {
2732 cl_int err;
2733 Platform default_platform = Platform::getDefault(&err);
2734 if (errResult) {
2735 *errResult = err;
2736 }
2737 return default_platform;
2738 }
2739
2740 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
2741 cl_int
2743 unloadCompiler()
2744 {
2745 return ::clUnloadPlatformCompiler(object_);
2746 }
2747 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
2748 }; // class Platform
2749
2750 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Platform::default_initialized_;
2751 CL_HPP_DEFINE_STATIC_MEMBER_ Platform Platform::default_;
2752 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Platform::default_error_ = CL_SUCCESS;
2753
2754
2758 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2759
2763 inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int
2764 UnloadCompiler() CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
2765 inline cl_int
2766 UnloadCompiler()
2767 {
2768 return ::clUnloadCompiler();
2769 }
2770 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2771
2780 class Context
2781 : public detail::Wrapper<cl_context>
2782 {
2783 private:
2784 static std::once_flag default_initialized_;
2785 static Context default_;
2786 static cl_int default_error_;
2787
2793 static void makeDefault() {
2794 /* Throwing an exception from a call_once invocation does not do
2795 * what we wish, so we catch it and save the error.
2796 */
2797 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2798 try
2799 #endif
2800 {
2801 #if !defined(__APPLE__) && !defined(__MACOS)
2802 const Platform &p = Platform::getDefault();
2803 cl_platform_id defaultPlatform = p();
2804 cl_context_properties properties[3] = {
2805 CL_CONTEXT_PLATFORM, (cl_context_properties)defaultPlatform, 0
2806 };
2807 #else // #if !defined(__APPLE__) && !defined(__MACOS)
2808 cl_context_properties *properties = nullptr;
2809 #endif // #if !defined(__APPLE__) && !defined(__MACOS)
2810
2811 default_ = Context(
2812 CL_DEVICE_TYPE_DEFAULT,
2813 properties,
2814 NULL,
2815 NULL,
2816 &default_error_);
2817 }
2818 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2819 catch (cl::Error &e) {
2820 default_error_ = e.err();
2821 }
2822 #endif
2823 }
2824
2825
2831 static void makeDefaultProvided(const Context &c) {
2832 default_ = c;
2833 }
2834
2835 public:
2836 #ifdef CL_HPP_UNIT_TEST_ENABLE
2837
2843 static void unitTestClearDefault() {
2844 default_ = Context();
2845 }
2846 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2847
2852 Context(
2853 const vector<Device>& devices,
2854 cl_context_properties* properties = NULL,
2855 void (CL_CALLBACK * notifyFptr)(
2856 const char *,
2857 const void *,
2858 size_type,
2859 void *) = NULL,
2860 void* data = NULL,
2861 cl_int* err = NULL)
2862 {
2863 cl_int error;
2864
2865 size_type numDevices = devices.size();
2866 vector<cl_device_id> deviceIDs(numDevices);
2867
2868 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
2869 deviceIDs[deviceIndex] = (devices[deviceIndex])();
2870 }
2871
2872 object_ = ::clCreateContext(
2873 properties, (cl_uint) numDevices,
2874 deviceIDs.data(),
2875 notifyFptr, data, &error);
2876
2877 detail::errHandler(error, __CREATE_CONTEXT_ERR);
2878 if (err != NULL) {
2879 *err = error;
2880 }
2881 }
2882
2887 Context(
2888 const Device& device,
2889 cl_context_properties* properties = NULL,
2890 void (CL_CALLBACK * notifyFptr)(
2891 const char *,
2892 const void *,
2893 size_type,
2894 void *) = NULL,
2895 void* data = NULL,
2896 cl_int* err = NULL)
2897 {
2898 cl_int error;
2899
2900 cl_device_id deviceID = device();
2901
2902 object_ = ::clCreateContext(
2903 properties, 1,
2904 &deviceID,
2905 notifyFptr, data, &error);
2906
2907 detail::errHandler(error, __CREATE_CONTEXT_ERR);
2908 if (err != NULL) {
2909 *err = error;
2910 }
2911 }
2912
2917 Context(
2918 cl_device_type type,
2919 cl_context_properties* properties = NULL,
2920 void (CL_CALLBACK * notifyFptr)(
2921 const char *,
2922 const void *,
2923 size_type,
2924 void *) = NULL,
2925 void* data = NULL,
2926 cl_int* err = NULL)
2927 {
2928 cl_int error;
2929
2930 #if !defined(__APPLE__) && !defined(__MACOS)
2931 cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 };
2932
2933 if (properties == NULL) {
2934 // Get a valid platform ID as we cannot send in a blank one
2935 vector<Platform> platforms;
2936 error = Platform::get(&platforms);
2937 if (error != CL_SUCCESS) {
2938 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2939 if (err != NULL) {
2940 *err = error;
2941 }
2942 return;
2943 }
2944
2945 // Check the platforms we found for a device of our specified type
2946 cl_context_properties platform_id = 0;
2947 for (unsigned int i = 0; i < platforms.size(); i++) {
2948
2949 vector<Device> devices;
2950
2951 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2952 try {
2953 #endif
2954
2955 error = platforms[i].getDevices(type, &devices);
2956
2957 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2958 } catch (cl::Error& e) {
2959 error = e.err();
2960 }
2961 // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type
2962 // We do error checking next anyway, and can throw there if needed
2963 #endif
2964
2965 // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND
2966 if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) {
2967 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2968 if (err != NULL) {
2969 *err = error;
2970 }
2971 }
2972
2973 if (devices.size() > 0) {
2974 platform_id = (cl_context_properties)platforms[i]();
2975 break;
2976 }
2977 }
2978
2979 if (platform_id == 0) {
2980 detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR);
2981 if (err != NULL) {
2982 *err = CL_DEVICE_NOT_FOUND;
2983 }
2984 return;
2985 }
2986
2987 prop[1] = platform_id;
2988 properties = &prop[0];
2989 }
2990 #endif
2991 object_ = ::clCreateContextFromType(
2992 properties, type, notifyFptr, data, &error);
2993
2994 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2995 if (err != NULL) {
2996 *err = error;
2997 }
2998 }
2999
3003 Context(const Context& ctx) : detail::Wrapper<cl_type>(ctx) {}
3004
3008 Context& operator = (const Context &ctx)
3009 {
3010 detail::Wrapper<cl_type>::operator=(ctx);
3011 return *this;
3012 }
3013
3017 Context(Context&& ctx) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(ctx)) {}
3018
3022 Context& operator = (Context &&ctx)
3023 {
3024 detail::Wrapper<cl_type>::operator=(std::move(ctx));
3025 return *this;
3026 }
3027
3028
3033 static Context getDefault(cl_int * err = NULL)
3034 {
3035 std::call_once(default_initialized_, makeDefault);
3036 detail::errHandler(default_error_);
3037 if (err != NULL) {
3038 *err = default_error_;
3039 }
3040 return default_;
3041 }
3042
3050 static Context setDefault(const Context &default_context)
3051 {
3052 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_context));
3053 detail::errHandler(default_error_);
3054 return default_;
3055 }
3056
3058 Context() : detail::Wrapper<cl_type>() { }
3059
3065 explicit Context(const cl_context& context, bool retainObject = false) :
3066 detail::Wrapper<cl_type>(context, retainObject) { }
3067
3073 Context& operator = (const cl_context& rhs)
3074 {
3075 detail::Wrapper<cl_type>::operator=(rhs);
3076 return *this;
3077 }
3078
3080 template <typename T>
3081 cl_int getInfo(cl_context_info name, T* param) const
3082 {
3083 return detail::errHandler(
3084 detail::getInfo(&::clGetContextInfo, object_, name, param),
3085 __GET_CONTEXT_INFO_ERR);
3086 }
3087
3089 template <cl_context_info name> typename
3090 detail::param_traits<detail::cl_context_info, name>::param_type
3091 getInfo(cl_int* err = NULL) const
3092 {
3093 typename detail::param_traits<
3094 detail::cl_context_info, name>::param_type param;
3095 cl_int result = getInfo(name, &param);
3096 if (err != NULL) {
3097 *err = result;
3098 }
3099 return param;
3100 }
3101
3106 cl_int getSupportedImageFormats(
3107 cl_mem_flags flags,
3108 cl_mem_object_type type,
3109 vector<ImageFormat>* formats) const
3110 {
3111 cl_uint numEntries;
3112
3113 if (!formats) {
3114 return CL_SUCCESS;
3115 }
3116
3117 cl_int err = ::clGetSupportedImageFormats(
3118 object_,
3119 flags,
3120 type,
3121 0,
3122 NULL,
3123 &numEntries);
3124 if (err != CL_SUCCESS) {
3125 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3126 }
3127
3128 if (numEntries > 0) {
3129 vector<ImageFormat> value(numEntries);
3130 err = ::clGetSupportedImageFormats(
3131 object_,
3132 flags,
3133 type,
3134 numEntries,
3135 (cl_image_format*)value.data(),
3136 NULL);
3137 if (err != CL_SUCCESS) {
3138 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3139 }
3140
3141 formats->assign(begin(value), end(value));
3142 }
3143 else {
3144 // If no values are being returned, ensure an empty vector comes back
3145 formats->clear();
3146 }
3147
3148 return CL_SUCCESS;
3149 }
3150 };
3151
3152 inline void Device::makeDefault()
3153 {
3154 /* Throwing an exception from a call_once invocation does not do
3155 * what we wish, so we catch it and save the error.
3156 */
3157 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3158 try
3159 #endif
3160 {
3161 cl_int error = 0;
3162
3163 Context context = Context::getDefault(&error);
3164 detail::errHandler(error, __CREATE_CONTEXT_ERR);
3165
3166 if (error != CL_SUCCESS) {
3167 default_error_ = error;
3168 }
3169 else {
3170 default_ = context.getInfo<CL_CONTEXT_DEVICES>()[0];
3171 default_error_ = CL_SUCCESS;
3172 }
3173 }
3174 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3175 catch (cl::Error &e) {
3176 default_error_ = e.err();
3177 }
3178 #endif
3179 }
3180
3181 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Context::default_initialized_;
3182 CL_HPP_DEFINE_STATIC_MEMBER_ Context Context::default_;
3183 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Context::default_error_ = CL_SUCCESS;
3184
3193 class Event : public detail::Wrapper<cl_event>
3194 {
3195 public:
3197 Event() : detail::Wrapper<cl_type>() { }
3198
3207 explicit Event(const cl_event& event, bool retainObject = false) :
3208 detail::Wrapper<cl_type>(event, retainObject) { }
3209
3215 Event& operator = (const cl_event& rhs)
3216 {
3217 detail::Wrapper<cl_type>::operator=(rhs);
3218 return *this;
3219 }
3220
3222 template <typename T>
3223 cl_int getInfo(cl_event_info name, T* param) const
3224 {
3225 return detail::errHandler(
3226 detail::getInfo(&::clGetEventInfo, object_, name, param),
3227 __GET_EVENT_INFO_ERR);
3228 }
3229
3231 template <cl_event_info name> typename
3232 detail::param_traits<detail::cl_event_info, name>::param_type
3233 getInfo(cl_int* err = NULL) const
3234 {
3235 typename detail::param_traits<
3236 detail::cl_event_info, name>::param_type param;
3237 cl_int result = getInfo(name, &param);
3238 if (err != NULL) {
3239 *err = result;
3240 }
3241 return param;
3242 }
3243
3245 template <typename T>
3246 cl_int getProfilingInfo(cl_profiling_info name, T* param) const
3247 {
3248 return detail::errHandler(detail::getInfo(
3249 &::clGetEventProfilingInfo, object_, name, param),
3250 __GET_EVENT_PROFILE_INFO_ERR);
3251 }
3252
3254 template <cl_profiling_info name> typename
3255 detail::param_traits<detail::cl_profiling_info, name>::param_type
3256 getProfilingInfo(cl_int* err = NULL) const
3257 {
3258 typename detail::param_traits<
3259 detail::cl_profiling_info, name>::param_type param;
3260 cl_int result = getProfilingInfo(name, &param);
3261 if (err != NULL) {
3262 *err = result;
3263 }
3264 return param;
3265 }
3266
3271 cl_int wait() const
3272 {
3273 return detail::errHandler(
3274 ::clWaitForEvents(1, &object_),
3275 __WAIT_FOR_EVENTS_ERR);
3276 }
3277
3278 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3279
3283 cl_int setCallback(
3284 cl_int type,
3285 void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
3286 void * user_data = NULL)
3287 {
3288 return detail::errHandler(
3289 ::clSetEventCallback(
3290 object_,
3291 type,
3292 pfn_notify,
3293 user_data),
3294 __SET_EVENT_CALLBACK_ERR);
3295 }
3296 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3297
3302 static cl_int
3303 waitForEvents(const vector<Event>& events)
3304 {
3305 return detail::errHandler(
3306 ::clWaitForEvents(
3307 (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3308 __WAIT_FOR_EVENTS_ERR);
3309 }
3310 };
3311
3312 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3313
3317 class UserEvent : public Event
3318 {
3319 public:
3324 UserEvent(
3325 const Context& context,
3326 cl_int * err = NULL)
3327 {
3328 cl_int error;
3329 object_ = ::clCreateUserEvent(
3330 context(),
3331 &error);
3332
3333 detail::errHandler(error, __CREATE_USER_EVENT_ERR);
3334 if (err != NULL) {
3335 *err = error;
3336 }
3337 }
3338
3340 UserEvent() : Event() { }
3341
3346 cl_int setStatus(cl_int status)
3347 {
3348 return detail::errHandler(
3349 ::clSetUserEventStatus(object_,status),
3350 __SET_USER_EVENT_STATUS_ERR);
3351 }
3352 };
3353 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3354
3359 inline static cl_int
3360 WaitForEvents(const vector<Event>& events)
3361 {
3362 return detail::errHandler(
3363 ::clWaitForEvents(
3364 (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3365 __WAIT_FOR_EVENTS_ERR);
3366 }
3367
3376 class Memory : public detail::Wrapper<cl_mem>
3377 {
3378 public:
3380 Memory() : detail::Wrapper<cl_type>() { }
3381
3393 explicit Memory(const cl_mem& memory, bool retainObject) :
3394 detail::Wrapper<cl_type>(memory, retainObject) { }
3395
3401 Memory& operator = (const cl_mem& rhs)
3402 {
3403 detail::Wrapper<cl_type>::operator=(rhs);
3404 return *this;
3405 }
3406
3410 Memory(const Memory& mem) : detail::Wrapper<cl_type>(mem) {}
3411
3415 Memory& operator = (const Memory &mem)
3416 {
3417 detail::Wrapper<cl_type>::operator=(mem);
3418 return *this;
3419 }
3420
3424 Memory(Memory&& mem) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(mem)) {}
3425
3429 Memory& operator = (Memory &&mem)
3430 {
3431 detail::Wrapper<cl_type>::operator=(std::move(mem));
3432 return *this;
3433 }
3434
3435
3437 template <typename T>
3438 cl_int getInfo(cl_mem_info name, T* param) const
3439 {
3440 return detail::errHandler(
3441 detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
3442 __GET_MEM_OBJECT_INFO_ERR);
3443 }
3444
3446 template <cl_mem_info name> typename
3447 detail::param_traits<detail::cl_mem_info, name>::param_type
3448 getInfo(cl_int* err = NULL) const
3449 {
3450 typename detail::param_traits<
3451 detail::cl_mem_info, name>::param_type param;
3452 cl_int result = getInfo(name, &param);
3453 if (err != NULL) {
3454 *err = result;
3455 }
3456 return param;
3457 }
3458
3459 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3460
3473 cl_int setDestructorCallback(
3474 void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
3475 void * user_data = NULL)
3476 {
3477 return detail::errHandler(
3478 ::clSetMemObjectDestructorCallback(
3479 object_,
3480 pfn_notify,
3481 user_data),
3482 __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
3483 }
3484 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3485
3486 };
3487
3488 // Pre-declare copy functions
3489 class Buffer;
3490 template< typename IteratorType >
3491 cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3492 template< typename IteratorType >
3493 cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3494 template< typename IteratorType >
3495 cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3496 template< typename IteratorType >
3497 cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3498
3499
3500 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
3501 namespace detail
3502 {
3503 class SVMTraitNull
3504 {
3505 public:
3506 static cl_svm_mem_flags getSVMMemFlags()
3507 {
3508 return 0;
3509 }
3510 };
3511 } // namespace detail
3512
3513 template<class Trait = detail::SVMTraitNull>
3514 class SVMTraitReadWrite
3515 {
3516 public:
3517 static cl_svm_mem_flags getSVMMemFlags()
3518 {
3519 return CL_MEM_READ_WRITE |
3520 Trait::getSVMMemFlags();
3521 }
3522 };
3523
3524 template<class Trait = detail::SVMTraitNull>
3525 class SVMTraitReadOnly
3526 {
3527 public:
3528 static cl_svm_mem_flags getSVMMemFlags()
3529 {
3530 return CL_MEM_READ_ONLY |
3531 Trait::getSVMMemFlags();
3532 }
3533 };
3534
3535 template<class Trait = detail::SVMTraitNull>
3536 class SVMTraitWriteOnly
3537 {
3538 public:
3539 static cl_svm_mem_flags getSVMMemFlags()
3540 {
3541 return CL_MEM_WRITE_ONLY |
3542 Trait::getSVMMemFlags();
3543 }
3544 };
3545
3546 template<class Trait = SVMTraitReadWrite<>>
3547 class SVMTraitCoarse
3548 {
3549 public:
3550 static cl_svm_mem_flags getSVMMemFlags()
3551 {
3552 return Trait::getSVMMemFlags();
3553 }
3554 };
3555
3556 template<class Trait = SVMTraitReadWrite<>>
3557 class SVMTraitFine
3558 {
3559 public:
3560 static cl_svm_mem_flags getSVMMemFlags()
3561 {
3562 return CL_MEM_SVM_FINE_GRAIN_BUFFER |
3563 Trait::getSVMMemFlags();
3564 }
3565 };
3566
3567 template<class Trait = SVMTraitReadWrite<>>
3568 class SVMTraitAtomic
3569 {
3570 public:
3571 static cl_svm_mem_flags getSVMMemFlags()
3572 {
3573 return
3574 CL_MEM_SVM_FINE_GRAIN_BUFFER |
3575 CL_MEM_SVM_ATOMICS |
3576 Trait::getSVMMemFlags();
3577 }
3578 };
3579
3580 // Pre-declare SVM map function
3581 template<typename T>
3582 inline cl_int enqueueMapSVM(
3583 T* ptr,
3584 cl_bool blocking,
3585 cl_map_flags flags,
3586 size_type size,
3587 const vector<Event>* events = NULL,
3588 Event* event = NULL);
3589
3601 template<typename T, class SVMTrait>
3602 class SVMAllocator {
3603 private:
3604 Context context_;
3605
3606 public:
3607 typedef T value_type;
3608 typedef value_type* pointer;
3609 typedef const value_type* const_pointer;
3610 typedef value_type& reference;
3611 typedef const value_type& const_reference;
3612 typedef std::size_t size_type;
3613 typedef std::ptrdiff_t difference_type;
3614
3615 template<typename U>
3616 struct rebind
3617 {
3618 typedef SVMAllocator<U, SVMTrait> other;
3619 };
3620
3621 template<typename U, typename V>
3622 friend class SVMAllocator;
3623
3624 SVMAllocator() :
3625 context_(Context::getDefault())
3626 {
3627 }
3628
3629 explicit SVMAllocator(cl::Context context) :
3630 context_(context)
3631 {
3632 }
3633
3634
3635 SVMAllocator(const SVMAllocator &other) :
3636 context_(other.context_)
3637 {
3638 }
3639
3640 template<typename U>
3641 SVMAllocator(const SVMAllocator<U, SVMTrait> &other) :
3642 context_(other.context_)
3643 {
3644 }
3645
3646 ~SVMAllocator()
3647 {
3648 }
3649
3650 pointer address(reference r) CL_HPP_NOEXCEPT_
3651 {
3652 return std::addressof(r);
3653 }
3654
3655 const_pointer address(const_reference r) CL_HPP_NOEXCEPT_
3656 {
3657 return std::addressof(r);
3658 }
3659
3666 pointer allocate(
3667 size_type size,
3668 typename cl::SVMAllocator<void, SVMTrait>::const_pointer = 0)
3669 {
3670 // Allocate memory with default alignment matching the size of the type
3671 void* voidPointer =
3672 clSVMAlloc(
3673 context_(),
3674 SVMTrait::getSVMMemFlags(),
3675 size*sizeof(T),
3676 0);
3677 pointer retValue = reinterpret_cast<pointer>(
3678 voidPointer);
3679 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3680 if (!retValue) {
3681 std::bad_alloc excep;
3682 throw excep;
3683 }
3684 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3685
3686 // If allocation was coarse-grained then map it
3687 if (!(SVMTrait::getSVMMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) {
3688 cl_int err = enqueueMapSVM(retValue, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, size*sizeof(T));
3689 if (err != CL_SUCCESS) {
3690 std::bad_alloc excep;
3691 throw excep;
3692 }
3693 }
3694
3695 // If exceptions disabled, return null pointer from allocator
3696 return retValue;
3697 }
3698
3699 void deallocate(pointer p, size_type)
3700 {
3701 clSVMFree(context_(), p);
3702 }
3703
3708 size_type max_size() const CL_HPP_NOEXCEPT_
3709 {
3710 size_type maxSize = std::numeric_limits<size_type>::max() / sizeof(T);
3711
3712 for (const Device &d : context_.getInfo<CL_CONTEXT_DEVICES>()) {
3713 maxSize = std::min(
3714 maxSize,
3715 static_cast<size_type>(d.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>()));
3716 }
3717
3718 return maxSize;
3719 }
3720
3721 template< class U, class... Args >
3722 void construct(U* p, Args&&... args)
3723 {
3724 new(p)T(args...);
3725 }
3726
3727 template< class U >
3728 void destroy(U* p)
3729 {
3730 p->~U();
3731 }
3732
3736 inline bool operator==(SVMAllocator const& rhs)
3737 {
3738 return (context_==rhs.context_);
3739 }
3740
3741 inline bool operator!=(SVMAllocator const& a)
3742 {
3743 return !operator==(a);
3744 }
3745 }; // class SVMAllocator return cl::pointer<T>(tmp, detail::Deleter<T, Alloc>{alloc, copies});
3746
3747
3748 template<class SVMTrait>
3749 class SVMAllocator<void, SVMTrait> {
3750 public:
3751 typedef void value_type;
3752 typedef value_type* pointer;
3753 typedef const value_type* const_pointer;
3754
3755 template<typename U>
3756 struct rebind
3757 {
3758 typedef SVMAllocator<U, SVMTrait> other;
3759 };
3760
3761 template<typename U, typename V>
3762 friend class SVMAllocator;
3763 };
3764
3765 #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3766 namespace detail
3767 {
3768 template<class Alloc>
3769 class Deleter {
3770 private:
3771 Alloc alloc_;
3772 size_type copies_;
3773
3774 public:
3775 typedef typename std::allocator_traits<Alloc>::pointer pointer;
3776
3777 Deleter(const Alloc &alloc, size_type copies) : alloc_{ alloc }, copies_{ copies }
3778 {
3779 }
3780
3781 void operator()(pointer ptr) const {
3782 Alloc tmpAlloc{ alloc_ };
3783 std::allocator_traits<Alloc>::destroy(tmpAlloc, std::addressof(*ptr));
3784 std::allocator_traits<Alloc>::deallocate(tmpAlloc, ptr, copies_);
3785 }
3786 };
3787 } // namespace detail
3788
3795 template <class T, class Alloc, class... Args>
3796 cl::pointer<T, detail::Deleter<Alloc>> allocate_pointer(const Alloc &alloc_, Args&&... args)
3797 {
3798 Alloc alloc(alloc_);
3799 static const size_type copies = 1;
3800
3801 // Ensure that creation of the management block and the
3802 // object are dealt with separately such that we only provide a deleter
3803
3804 T* tmp = std::allocator_traits<Alloc>::allocate(alloc, copies);
3805 if (!tmp) {
3806 std::bad_alloc excep;
3807 throw excep;
3808 }
3809 try {
3810 std::allocator_traits<Alloc>::construct(
3811 alloc,
3812 std::addressof(*tmp),
3813 std::forward<Args>(args)...);
3814
3815 return cl::pointer<T, detail::Deleter<Alloc>>(tmp, detail::Deleter<Alloc>{alloc, copies});
3816 }
3817 catch (std::bad_alloc& b)
3818 {
3819 std::allocator_traits<Alloc>::deallocate(alloc, tmp, copies);
3820 throw;
3821 }
3822 }
3823
3824 template< class T, class SVMTrait, class... Args >
3825 cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(Args... args)
3826 {
3827 SVMAllocator<T, SVMTrait> alloc;
3828 return cl::allocate_pointer<T>(alloc, args...);
3829 }
3830
3831 template< class T, class SVMTrait, class... Args >
3832 cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(const cl::Context &c, Args... args)
3833 {
3834 SVMAllocator<T, SVMTrait> alloc(c);
3835 return cl::allocate_pointer<T>(alloc, args...);
3836 }
3837 #endif // #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3838
3842 template < class T >
3843 using coarse_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>>;
3844
3848 template < class T >
3849 using fine_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitFine<>>>;
3850
3854 template < class T >
3855 using atomic_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitAtomic<>>>;
3856
3857 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
3858
3859
3866 class Buffer : public Memory
3867 {
3868 public:
3869
3877 Buffer(
3878 const Context& context,
3879 cl_mem_flags flags,
3880 size_type size,
3881 void* host_ptr = NULL,
3882 cl_int* err = NULL)
3883 {
3884 cl_int error;
3885 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3886
3887 detail::errHandler(error, __CREATE_BUFFER_ERR);
3888 if (err != NULL) {
3889 *err = error;
3890 }
3891 }
3892
3902 Buffer(
3903 cl_mem_flags flags,
3904 size_type size,
3905 void* host_ptr = NULL,
3906 cl_int* err = NULL)
3907 {
3908 cl_int error;
3909
3910 Context context = Context::getDefault(err);
3911
3912 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3913
3914 detail::errHandler(error, __CREATE_BUFFER_ERR);
3915 if (err != NULL) {
3916 *err = error;
3917 }
3918 }
3919
3925 template< typename IteratorType >
3926 Buffer(
3927 IteratorType startIterator,
3928 IteratorType endIterator,
3929 bool readOnly,
3930 bool useHostPtr = false,
3931 cl_int* err = NULL)
3932 {
3933 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
3934 cl_int error;
3935
3936 cl_mem_flags flags = 0;
3937 if( readOnly ) {
3938 flags |= CL_MEM_READ_ONLY;
3939 }
3940 else {
3941 flags |= CL_MEM_READ_WRITE;
3942 }
3943 if( useHostPtr ) {
3944 flags |= CL_MEM_USE_HOST_PTR;
3945 }
3946
3947 size_type size = sizeof(DataType)*(endIterator - startIterator);
3948
3949 Context context = Context::getDefault(err);
3950
3951 if( useHostPtr ) {
3952 object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
3953 } else {
3954 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
3955 }
3956
3957 detail::errHandler(error, __CREATE_BUFFER_ERR);
3958 if (err != NULL) {
3959 *err = error;
3960 }
3961
3962 if( !useHostPtr ) {
3963 error = cl::copy(startIterator, endIterator, *this);
3964 detail::errHandler(error, __CREATE_BUFFER_ERR);
3965 if (err != NULL) {
3966 *err = error;
3967 }
3968 }
3969 }
3970
3976 template< typename IteratorType >
3977 Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator,
3978 bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
3979
3984 template< typename IteratorType >
3985 Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator,
3986 bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
3987
3989 Buffer() : Memory() { }
3990
3998 explicit Buffer(const cl_mem& buffer, bool retainObject = false) :
3999 Memory(buffer, retainObject) { }
4000
4005 Buffer& operator = (const cl_mem& rhs)
4006 {
4007 Memory::operator=(rhs);
4008 return *this;
4009 }
4010
4014 Buffer(const Buffer& buf) : Memory(buf) {}
4015
4019 Buffer& operator = (const Buffer &buf)
4020 {
4021 Memory::operator=(buf);
4022 return *this;
4023 }
4024
4028 Buffer(Buffer&& buf) CL_HPP_NOEXCEPT_ : Memory(std::move(buf)) {}
4029
4033 Buffer& operator = (Buffer &&buf)
4034 {
4035 Memory::operator=(std::move(buf));
4036 return *this;
4037 }
4038
4039 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
4040
4044 Buffer createSubBuffer(
4045 cl_mem_flags flags,
4046 cl_buffer_create_type buffer_create_type,
4047 const void * buffer_create_info,
4048 cl_int * err = NULL)
4049 {
4050 Buffer result;
4051 cl_int error;
4052 result.object_ = ::clCreateSubBuffer(
4053 object_,
4054 flags,
4055 buffer_create_type,
4056 buffer_create_info,
4057 &error);
4058
4059 detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
4060 if (err != NULL) {
4061 *err = error;
4062 }
4063
4064 return result;
4065 }
4066 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
4067 };
4068
4069 #if defined (CL_HPP_USE_DX_INTEROP)
4070
4078 class BufferD3D10 : public Buffer
4079 {
4080 public:
4081
4082
4088 BufferD3D10(
4089 const Context& context,
4090 cl_mem_flags flags,
4091 ID3D10Buffer* bufobj,
4092 cl_int * err = NULL) : pfn_clCreateFromD3D10BufferKHR(nullptr)
4093 {
4094 typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
4095 cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
4096 cl_int* errcode_ret);
4097 PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR;
4098 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4099 vector<cl_context_properties> props = context.getInfo<CL_CONTEXT_PROPERTIES>();
4100 cl_platform platform = -1;
4101 for( int i = 0; i < props.size(); ++i ) {
4102 if( props[i] == CL_CONTEXT_PLATFORM ) {
4103 platform = props[i+1];
4104 }
4105 }
4106 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateFromD3D10BufferKHR);
4107 #elif CL_HPP_TARGET_OPENCL_VERSION >= 110
4108 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateFromD3D10BufferKHR);
4109 #endif
4110
4111 cl_int error;
4112 object_ = pfn_clCreateFromD3D10BufferKHR(
4113 context(),
4114 flags,
4115 bufobj,
4116 &error);
4117
4118 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4119 if (err != NULL) {
4120 *err = error;
4121 }
4122 }
4123
4125 BufferD3D10() : Buffer() { }
4126
4134 explicit BufferD3D10(const cl_mem& buffer, bool retainObject = false) :
4135 Buffer(buffer, retainObject) { }
4136
4141 BufferD3D10& operator = (const cl_mem& rhs)
4142 {
4143 Buffer::operator=(rhs);
4144 return *this;
4145 }
4146
4150 BufferD3D10(const BufferD3D10& buf) :
4151 Buffer(buf) {}
4152
4156 BufferD3D10& operator = (const BufferD3D10 &buf)
4157 {
4158 Buffer::operator=(buf);
4159 return *this;
4160 }
4161
4165 BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4166
4170 BufferD3D10& operator = (BufferD3D10 &&buf)
4171 {
4172 Buffer::operator=(std::move(buf));
4173 return *this;
4174 }
4175 };
4176 #endif
4177
4186 class BufferGL : public Buffer
4187 {
4188 public:
4194 BufferGL(
4195 const Context& context,
4196 cl_mem_flags flags,
4197 cl_GLuint bufobj,
4198 cl_int * err = NULL)
4199 {
4200 cl_int error;
4201 object_ = ::clCreateFromGLBuffer(
4202 context(),
4203 flags,
4204 bufobj,
4205 &error);
4206
4207 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4208 if (err != NULL) {
4209 *err = error;
4210 }
4211 }
4212
4214 BufferGL() : Buffer() { }
4215
4223 explicit BufferGL(const cl_mem& buffer, bool retainObject = false) :
4224 Buffer(buffer, retainObject) { }
4225
4230 BufferGL& operator = (const cl_mem& rhs)
4231 {
4232 Buffer::operator=(rhs);
4233 return *this;
4234 }
4235
4239 BufferGL(const BufferGL& buf) : Buffer(buf) {}
4240
4244 BufferGL& operator = (const BufferGL &buf)
4245 {
4246 Buffer::operator=(buf);
4247 return *this;
4248 }
4249
4253 BufferGL(BufferGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4254
4258 BufferGL& operator = (BufferGL &&buf)
4259 {
4260 Buffer::operator=(std::move(buf));
4261 return *this;
4262 }
4263
4265 cl_int getObjectInfo(
4266 cl_gl_object_type *type,
4267 cl_GLuint * gl_object_name)
4268 {
4269 return detail::errHandler(
4270 ::clGetGLObjectInfo(object_,type,gl_object_name),
4271 __GET_GL_OBJECT_INFO_ERR);
4272 }
4273 };
4274
4283 class BufferRenderGL : public Buffer
4284 {
4285 public:
4291 BufferRenderGL(
4292 const Context& context,
4293 cl_mem_flags flags,
4294 cl_GLuint bufobj,
4295 cl_int * err = NULL)
4296 {
4297 cl_int error;
4298 object_ = ::clCreateFromGLRenderbuffer(
4299 context(),
4300 flags,
4301 bufobj,
4302 &error);
4303
4304 detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR);
4305 if (err != NULL) {
4306 *err = error;
4307 }
4308 }
4309
4311 BufferRenderGL() : Buffer() { }
4312
4320 explicit BufferRenderGL(const cl_mem& buffer, bool retainObject = false) :
4321 Buffer(buffer, retainObject) { }
4322
4327 BufferRenderGL& operator = (const cl_mem& rhs)
4328 {
4329 Buffer::operator=(rhs);
4330 return *this;
4331 }
4332
4336 BufferRenderGL(const BufferRenderGL& buf) : Buffer(buf) {}
4337
4341 BufferRenderGL& operator = (const BufferRenderGL &buf)
4342 {
4343 Buffer::operator=(buf);
4344 return *this;
4345 }
4346
4350 BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4351
4355 BufferRenderGL& operator = (BufferRenderGL &&buf)
4356 {
4357 Buffer::operator=(std::move(buf));
4358 return *this;
4359 }
4360
4362 cl_int getObjectInfo(
4363 cl_gl_object_type *type,
4364 cl_GLuint * gl_object_name)
4365 {
4366 return detail::errHandler(
4367 ::clGetGLObjectInfo(object_,type,gl_object_name),
4368 __GET_GL_OBJECT_INFO_ERR);
4369 }
4370 };
4371
4378 class Image : public Memory
4379 {
4380 protected:
4382 Image() : Memory() { }
4383
4391 explicit Image(const cl_mem& image, bool retainObject = false) :
4392 Memory(image, retainObject) { }
4393
4398 Image& operator = (const cl_mem& rhs)
4399 {
4400 Memory::operator=(rhs);
4401 return *this;
4402 }
4403
4407 Image(const Image& img) : Memory(img) {}
4408
4412 Image& operator = (const Image &img)
4413 {
4414 Memory::operator=(img);
4415 return *this;
4416 }
4417
4421 Image(Image&& img) CL_HPP_NOEXCEPT_ : Memory(std::move(img)) {}
4422
4426 Image& operator = (Image &&img)
4427 {
4428 Memory::operator=(std::move(img));
4429 return *this;
4430 }
4431
4432
4433 public:
4435 template <typename T>
4436 cl_int getImageInfo(cl_image_info name, T* param) const
4437 {
4438 return detail::errHandler(
4439 detail::getInfo(&::clGetImageInfo, object_, name, param),
4440 __GET_IMAGE_INFO_ERR);
4441 }
4442
4444 template <cl_image_info name> typename
4445 detail::param_traits<detail::cl_image_info, name>::param_type
4446 getImageInfo(cl_int* err = NULL) const
4447 {
4448 typename detail::param_traits<
4449 detail::cl_image_info, name>::param_type param;
4450 cl_int result = getImageInfo(name, &param);
4451 if (err != NULL) {
4452 *err = result;
4453 }
4454 return param;
4455 }
4456 };
4457
4458 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4459
4465 class Image1D : public Image
4466 {
4467 public:
4472 Image1D(
4473 const Context& context,
4474 cl_mem_flags flags,
4475 ImageFormat format,
4476 size_type width,
4477 void* host_ptr = NULL,
4478 cl_int* err = NULL)
4479 {
4480 cl_int error;
4481 cl_image_desc desc =
4482 {
4483 CL_MEM_OBJECT_IMAGE1D,
4484 width,
4485 0, 0, 0, 0, 0, 0, 0, 0
4486 };
4487 object_ = ::clCreateImage(
4488 context(),
4489 flags,
4490 &format,
4491 &desc,
4492 host_ptr,
4493 &error);
4494
4495 detail::errHandler(error, __CREATE_IMAGE_ERR);
4496 if (err != NULL) {
4497 *err = error;
4498 }
4499 }
4500
4502 Image1D() { }
4503
4511 explicit Image1D(const cl_mem& image1D, bool retainObject = false) :
4512 Image(image1D, retainObject) { }
4513
4518 Image1D& operator = (const cl_mem& rhs)
4519 {
4520 Image::operator=(rhs);
4521 return *this;
4522 }
4523
4527 Image1D(const Image1D& img) : Image(img) {}
4528
4532 Image1D& operator = (const Image1D &img)
4533 {
4534 Image::operator=(img);
4535 return *this;
4536 }
4537
4541 Image1D(Image1D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4542
4546 Image1D& operator = (Image1D &&img)
4547 {
4548 Image::operator=(std::move(img));
4549 return *this;
4550 }
4551
4552 };
4553
4557 class Image1DBuffer : public Image
4558 {
4559 public:
4560 Image1DBuffer(
4561 const Context& context,
4562 cl_mem_flags flags,
4563 ImageFormat format,
4564 size_type width,
4565 const Buffer &buffer,
4566 cl_int* err = NULL)
4567 {
4568 cl_int error;
4569 cl_image_desc desc =
4570 {
4571 CL_MEM_OBJECT_IMAGE1D_BUFFER,
4572 width,
4573 0, 0, 0, 0, 0, 0, 0,
4574 buffer()
4575 };
4576 object_ = ::clCreateImage(
4577 context(),
4578 flags,
4579 &format,
4580 &desc,
4581 NULL,
4582 &error);
4583
4584 detail::errHandler(error, __CREATE_IMAGE_ERR);
4585 if (err != NULL) {
4586 *err = error;
4587 }
4588 }
4589
4590 Image1DBuffer() { }
4591
4599 explicit Image1DBuffer(const cl_mem& image1D, bool retainObject = false) :
4600 Image(image1D, retainObject) { }
4601
4602 Image1DBuffer& operator = (const cl_mem& rhs)
4603 {
4604 Image::operator=(rhs);
4605 return *this;
4606 }
4607
4611 Image1DBuffer(const Image1DBuffer& img) : Image(img) {}
4612
4616 Image1DBuffer& operator = (const Image1DBuffer &img)
4617 {
4618 Image::operator=(img);
4619 return *this;
4620 }
4621
4625 Image1DBuffer(Image1DBuffer&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4626
4630 Image1DBuffer& operator = (Image1DBuffer &&img)
4631 {
4632 Image::operator=(std::move(img));
4633 return *this;
4634 }
4635
4636 };
4637
4641 class Image1DArray : public Image
4642 {
4643 public:
4644 Image1DArray(
4645 const Context& context,
4646 cl_mem_flags flags,
4647 ImageFormat format,
4648 size_type arraySize,
4649 size_type width,
4650 size_type rowPitch,
4651 void* host_ptr = NULL,
4652 cl_int* err = NULL)
4653 {
4654 cl_int error;
4655 cl_image_desc desc =
4656 {
4657 CL_MEM_OBJECT_IMAGE1D_ARRAY,
4658 width,
4659 0, 0, // height, depth (unused)
4660 arraySize,
4661 rowPitch,
4662 0, 0, 0, 0
4663 };
4664 object_ = ::clCreateImage(
4665 context(),
4666 flags,
4667 &format,
4668 &desc,
4669 host_ptr,
4670 &error);
4671
4672 detail::errHandler(error, __CREATE_IMAGE_ERR);
4673 if (err != NULL) {
4674 *err = error;
4675 }
4676 }
4677
4678 Image1DArray() { }
4679
4687 explicit Image1DArray(const cl_mem& imageArray, bool retainObject = false) :
4688 Image(imageArray, retainObject) { }
4689
4690
4691 Image1DArray& operator = (const cl_mem& rhs)
4692 {
4693 Image::operator=(rhs);
4694 return *this;
4695 }
4696
4700 Image1DArray(const Image1DArray& img) : Image(img) {}
4701
4705 Image1DArray& operator = (const Image1DArray &img)
4706 {
4707 Image::operator=(img);
4708 return *this;
4709 }
4710
4714 Image1DArray(Image1DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4715
4719 Image1DArray& operator = (Image1DArray &&img)
4720 {
4721 Image::operator=(std::move(img));
4722 return *this;
4723 }
4724
4725 };
4726 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4727
4728
4735 class Image2D : public Image
4736 {
4737 public:
4742 Image2D(
4743 const Context& context,
4744 cl_mem_flags flags,
4745 ImageFormat format,
4746 size_type width,
4747 size_type height,
4748 size_type row_pitch = 0,
4749 void* host_ptr = NULL,
4750 cl_int* err = NULL)
4751 {
4752 cl_int error;
4753 bool useCreateImage;
4754
4755 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
4756 // Run-time decision based on the actual platform
4757 {
4758 cl_uint version = detail::getContextPlatformVersion(context());
4759 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
4760 }
4761 #elif CL_HPP_TARGET_OPENCL_VERSION >= 120
4762 useCreateImage = true;
4763 #else
4764 useCreateImage = false;
4765 #endif
4766
4767 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4768 if (useCreateImage)
4769 {
4770 cl_image_desc desc =
4771 {
4772 CL_MEM_OBJECT_IMAGE2D,
4773 width,
4774 height,
4775 0, 0, // depth, array size (unused)
4776 row_pitch,
4777 0, 0, 0, 0
4778 };
4779 object_ = ::clCreateImage(
4780 context(),
4781 flags,
4782 &format,
4783 &desc,
4784 host_ptr,
4785 &error);
4786
4787 detail::errHandler(error, __CREATE_IMAGE_ERR);
4788 if (err != NULL) {
4789 *err = error;
4790 }
4791 }
4792 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
4793 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
4794 if (!useCreateImage)
4795 {
4796 object_ = ::clCreateImage2D(
4797 context(), flags,&format, width, height, row_pitch, host_ptr, &error);
4798
4799 detail::errHandler(error, __CREATE_IMAGE2D_ERR);
4800 if (err != NULL) {
4801 *err = error;
4802 }
4803 }
4804 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
4805 }
4806
4807 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4808
4813 Image2D(
4814 const Context& context,
4815 ImageFormat format,
4816 const Buffer &sourceBuffer,
4817 size_type width,
4818 size_type height,
4819 size_type row_pitch = 0,
4820 cl_int* err = nullptr)
4821 {
4822 cl_int error;
4823
4824 cl_image_desc desc =
4825 {
4826 CL_MEM_OBJECT_IMAGE2D,
4827 width,
4828 height,
4829 0, 0, // depth, array size (unused)
4830 row_pitch,
4831 0, 0, 0,
4832 // Use buffer as input to image
4833 sourceBuffer()
4834 };
4835 object_ = ::clCreateImage(
4836 context(),
4837 0, // flags inherited from buffer
4838 &format,
4839 &desc,
4840 nullptr,
4841 &error);
4842
4843 detail::errHandler(error, __CREATE_IMAGE_ERR);
4844 if (err != nullptr) {
4845 *err = error;
4846 }
4847 }
4848 #endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4849
4850 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
4851
4863 Image2D(
4864 const Context& context,
4865 cl_channel_order order,
4866 const Image &sourceImage,
4867 cl_int* err = nullptr)
4868 {
4869 cl_int error;
4870
4871 // Descriptor fields have to match source image
4872 size_type sourceWidth =
4873 sourceImage.getImageInfo<CL_IMAGE_WIDTH>();
4874 size_type sourceHeight =
4875 sourceImage.getImageInfo<CL_IMAGE_HEIGHT>();
4876 size_type sourceRowPitch =
4877 sourceImage.getImageInfo<CL_IMAGE_ROW_PITCH>();
4878 cl_uint sourceNumMIPLevels =
4879 sourceImage.getImageInfo<CL_IMAGE_NUM_MIP_LEVELS>();
4880 cl_uint sourceNumSamples =
4881 sourceImage.getImageInfo<CL_IMAGE_NUM_SAMPLES>();
4882 cl_image_format sourceFormat =
4883 sourceImage.getImageInfo<CL_IMAGE_FORMAT>();
4884
4885 // Update only the channel order.
4886 // Channel format inherited from source.
4887 sourceFormat.image_channel_order = order;
4888 cl_image_desc desc =
4889 {
4890 CL_MEM_OBJECT_IMAGE2D,
4891 sourceWidth,
4892 sourceHeight,
4893 0, 0, // depth (unused), array size (unused)
4894 sourceRowPitch,
4895 0, // slice pitch (unused)
4896 sourceNumMIPLevels,
4897 sourceNumSamples,
4898 // Use buffer as input to image
4899 sourceImage()
4900 };
4901 object_ = ::clCreateImage(
4902 context(),
4903 0, // flags should be inherited from mem_object
4904 &sourceFormat,
4905 &desc,
4906 nullptr,
4907 &error);
4908
4909 detail::errHandler(error, __CREATE_IMAGE_ERR);
4910 if (err != nullptr) {
4911 *err = error;
4912 }
4913 }
4914 #endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200
4915
4917 Image2D() { }
4918
4926 explicit Image2D(const cl_mem& image2D, bool retainObject = false) :
4927 Image(image2D, retainObject) { }
4928
4933 Image2D& operator = (const cl_mem& rhs)
4934 {
4935 Image::operator=(rhs);
4936 return *this;
4937 }
4938
4942 Image2D(const Image2D& img) : Image(img) {}
4943
4947 Image2D& operator = (const Image2D &img)
4948 {
4949 Image::operator=(img);
4950 return *this;
4951 }
4952
4956 Image2D(Image2D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4957
4961 Image2D& operator = (Image2D &&img)
4962 {
4963 Image::operator=(std::move(img));
4964 return *this;
4965 }
4966
4967 };
4968
4969
4970 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
4971
4980 class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED Image2DGL : public Image2D
4981 {
4982 public:
4988 Image2DGL(
4989 const Context& context,
4990 cl_mem_flags flags,
4991 cl_GLenum target,
4992 cl_GLint miplevel,
4993 cl_GLuint texobj,
4994 cl_int * err = NULL)
4995 {
4996 cl_int error;
4997 object_ = ::clCreateFromGLTexture2D(
4998 context(),
4999 flags,
5000 target,
5001 miplevel,
5002 texobj,
5003 &error);
5004
5005 detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR);
5006 if (err != NULL) {
5007 *err = error;
5008 }
5009
5010 }
5011
5013 Image2DGL() : Image2D() { }
5014
5022 explicit Image2DGL(const cl_mem& image, bool retainObject = false) :
5023 Image2D(image, retainObject) { }
5024
5029 Image2DGL& operator = (const cl_mem& rhs)
5030 {
5031 Image2D::operator=(rhs);
5032 return *this;
5033 }
5034
5038 Image2DGL(const Image2DGL& img) : Image2D(img) {}
5039
5043 Image2DGL& operator = (const Image2DGL &img)
5044 {
5045 Image2D::operator=(img);
5046 return *this;
5047 }
5048
5052 Image2DGL(Image2DGL&& img) CL_HPP_NOEXCEPT_ : Image2D(std::move(img)) {}
5053
5057 Image2DGL& operator = (Image2DGL &&img)
5058 {
5059 Image2D::operator=(std::move(img));
5060 return *this;
5061 }
5062
5063 } CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
5064 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5065
5066 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5067
5070 class Image2DArray : public Image
5071 {
5072 public:
5073 Image2DArray(
5074 const Context& context,
5075 cl_mem_flags flags,
5076 ImageFormat format,
5077 size_type arraySize,
5078 size_type width,
5079 size_type height,
5080 size_type rowPitch,
5081 size_type slicePitch,
5082 void* host_ptr = NULL,
5083 cl_int* err = NULL)
5084 {
5085 cl_int error;
5086 cl_image_desc desc =
5087 {
5088 CL_MEM_OBJECT_IMAGE2D_ARRAY,
5089 width,
5090 height,
5091 0, // depth (unused)
5092 arraySize,
5093 rowPitch,
5094 slicePitch,
5095 0, 0, 0
5096 };
5097 object_ = ::clCreateImage(
5098 context(),
5099 flags,
5100 &format,
5101 &desc,
5102 host_ptr,
5103 &error);
5104
5105 detail::errHandler(error, __CREATE_IMAGE_ERR);
5106 if (err != NULL) {
5107 *err = error;
5108 }
5109 }
5110
5111 Image2DArray() { }
5112
5120 explicit Image2DArray(const cl_mem& imageArray, bool retainObject = false) : Image(imageArray, retainObject) { }
5121
5122 Image2DArray& operator = (const cl_mem& rhs)
5123 {
5124 Image::operator=(rhs);
5125 return *this;
5126 }
5127
5131 Image2DArray(const Image2DArray& img) : Image(img) {}
5132
5136 Image2DArray& operator = (const Image2DArray &img)
5137 {
5138 Image::operator=(img);
5139 return *this;
5140 }
5141
5145 Image2DArray(Image2DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5146
5150 Image2DArray& operator = (Image2DArray &&img)
5151 {
5152 Image::operator=(std::move(img));
5153 return *this;
5154 }
5155 };
5156 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5157
5164 class Image3D : public Image
5165 {
5166 public:
5171 Image3D(
5172 const Context& context,
5173 cl_mem_flags flags,
5174 ImageFormat format,
5175 size_type width,
5176 size_type height,
5177 size_type depth,
5178 size_type row_pitch = 0,
5179 size_type slice_pitch = 0,
5180 void* host_ptr = NULL,
5181 cl_int* err = NULL)
5182 {
5183 cl_int error;
5184 bool useCreateImage;
5185
5186 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
5187 // Run-time decision based on the actual platform
5188 {
5189 cl_uint version = detail::getContextPlatformVersion(context());
5190 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
5191 }
5192 #elif CL_HPP_TARGET_OPENCL_VERSION >= 120
5193 useCreateImage = true;
5194 #else
5195 useCreateImage = false;
5196 #endif
5197
5198 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5199 if (useCreateImage)
5200 {
5201 cl_image_desc desc =
5202 {
5203 CL_MEM_OBJECT_IMAGE3D,
5204 width,
5205 height,
5206 depth,
5207 0, // array size (unused)
5208 row_pitch,
5209 slice_pitch,
5210 0, 0, 0
5211 };
5212 object_ = ::clCreateImage(
5213 context(),
5214 flags,
5215 &format,
5216 &desc,
5217 host_ptr,
5218 &error);
5219
5220 detail::errHandler(error, __CREATE_IMAGE_ERR);
5221 if (err != NULL) {
5222 *err = error;
5223 }
5224 }
5225 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5226 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
5227 if (!useCreateImage)
5228 {
5229 object_ = ::clCreateImage3D(
5230 context(), flags, &format, width, height, depth, row_pitch,
5231 slice_pitch, host_ptr, &error);
5232
5233 detail::errHandler(error, __CREATE_IMAGE3D_ERR);
5234 if (err != NULL) {
5235 *err = error;
5236 }
5237 }
5238 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
5239 }
5240
5242 Image3D() : Image() { }
5243
5251 explicit Image3D(const cl_mem& image3D, bool retainObject = false) :
5252 Image(image3D, retainObject) { }
5253
5258 Image3D& operator = (const cl_mem& rhs)
5259 {
5260 Image::operator=(rhs);
5261 return *this;
5262 }
5263
5267 Image3D(const Image3D& img) : Image(img) {}
5268
5272 Image3D& operator = (const Image3D &img)
5273 {
5274 Image::operator=(img);
5275 return *this;
5276 }
5277
5281 Image3D(Image3D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5282
5286 Image3D& operator = (Image3D &&img)
5287 {
5288 Image::operator=(std::move(img));
5289 return *this;
5290 }
5291 };
5292
5293 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
5294
5302 class Image3DGL : public Image3D
5303 {
5304 public:
5310 Image3DGL(
5311 const Context& context,
5312 cl_mem_flags flags,
5313 cl_GLenum target,
5314 cl_GLint miplevel,
5315 cl_GLuint texobj,
5316 cl_int * err = NULL)
5317 {
5318 cl_int error;
5319 object_ = ::clCreateFromGLTexture3D(
5320 context(),
5321 flags,
5322 target,
5323 miplevel,
5324 texobj,
5325 &error);
5326
5327 detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR);
5328 if (err != NULL) {
5329 *err = error;
5330 }
5331 }
5332
5334 Image3DGL() : Image3D() { }
5335
5343 explicit Image3DGL(const cl_mem& image, bool retainObject = false) :
5344 Image3D(image, retainObject) { }
5345
5350 Image3DGL& operator = (const cl_mem& rhs)
5351 {
5352 Image3D::operator=(rhs);
5353 return *this;
5354 }
5355
5359 Image3DGL(const Image3DGL& img) : Image3D(img) {}
5360
5364 Image3DGL& operator = (const Image3DGL &img)
5365 {
5366 Image3D::operator=(img);
5367 return *this;
5368 }
5369
5373 Image3DGL(Image3DGL&& img) CL_HPP_NOEXCEPT_ : Image3D(std::move(img)) {}
5374
5378 Image3DGL& operator = (Image3DGL &&img)
5379 {
5380 Image3D::operator=(std::move(img));
5381 return *this;
5382 }
5383 };
5384 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5385
5386 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5387
5393 class ImageGL : public Image
5394 {
5395 public:
5396 ImageGL(
5397 const Context& context,
5398 cl_mem_flags flags,
5399 cl_GLenum target,
5400 cl_GLint miplevel,
5401 cl_GLuint texobj,
5402 cl_int * err = NULL)
5403 {
5404 cl_int error;
5405 object_ = ::clCreateFromGLTexture(
5406 context(),
5407 flags,
5408 target,
5409 miplevel,
5410 texobj,
5411 &error);
5412
5413 detail::errHandler(error, __CREATE_GL_TEXTURE_ERR);
5414 if (err != NULL) {
5415 *err = error;
5416 }
5417 }
5418
5419 ImageGL() : Image() { }
5420
5428 explicit ImageGL(const cl_mem& image, bool retainObject = false) :
5429 Image(image, retainObject) { }
5430
5431 ImageGL& operator = (const cl_mem& rhs)
5432 {
5433 Image::operator=(rhs);
5434 return *this;
5435 }
5436
5440 ImageGL(const ImageGL& img) : Image(img) {}
5441
5445 ImageGL& operator = (const ImageGL &img)
5446 {
5447 Image::operator=(img);
5448 return *this;
5449 }
5450
5454 ImageGL(ImageGL&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5455
5459 ImageGL& operator = (ImageGL &&img)
5460 {
5461 Image::operator=(std::move(img));
5462 return *this;
5463 }
5464 };
5465 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5466
5467
5468
5469 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5470
5476 class Pipe : public Memory
5477 {
5478 public:
5479
5489 Pipe(
5490 const Context& context,
5491 cl_uint packet_size,
5492 cl_uint max_packets,
5493 cl_int* err = NULL)
5494 {
5495 cl_int error;
5496
5497 cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5498 object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error);
5499
5500 detail::errHandler(error, __CREATE_PIPE_ERR);
5501 if (err != NULL) {
5502 *err = error;
5503 }
5504 }
5505
5514 Pipe(
5515 cl_uint packet_size,
5516 cl_uint max_packets,
5517 cl_int* err = NULL)
5518 {
5519 cl_int error;
5520
5521 Context context = Context::getDefault(err);
5522
5523 cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5524 object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error);
5525
5526 detail::errHandler(error, __CREATE_PIPE_ERR);
5527 if (err != NULL) {
5528 *err = error;
5529 }
5530 }
5531
5533 Pipe() : Memory() { }
5534
5542 explicit Pipe(const cl_mem& pipe, bool retainObject = false) :
5543 Memory(pipe, retainObject) { }
5544
5549 Pipe& operator = (const cl_mem& rhs)
5550 {
5551 Memory::operator=(rhs);
5552 return *this;
5553 }
5554
5558 Pipe(const Pipe& pipe) : Memory(pipe) {}
5559
5563 Pipe& operator = (const Pipe &pipe)
5564 {
5565 Memory::operator=(pipe);
5566 return *this;
5567 }
5568
5572 Pipe(Pipe&& pipe) CL_HPP_NOEXCEPT_ : Memory(std::move(pipe)) {}
5573
5577 Pipe& operator = (Pipe &&pipe)
5578 {
5579 Memory::operator=(std::move(pipe));
5580 return *this;
5581 }
5582
5584 template <typename T>
5585 cl_int getInfo(cl_pipe_info name, T* param) const
5586 {
5587 return detail::errHandler(
5588 detail::getInfo(&::clGetPipeInfo, object_, name, param),
5589 __GET_PIPE_INFO_ERR);
5590 }
5591
5593 template <cl_pipe_info name> typename
5594 detail::param_traits<detail::cl_pipe_info, name>::param_type
5595 getInfo(cl_int* err = NULL) const
5596 {
5597 typename detail::param_traits<
5598 detail::cl_pipe_info, name>::param_type param;
5599 cl_int result = getInfo(name, &param);
5600 if (err != NULL) {
5601 *err = result;
5602 }
5603 return param;
5604 }
5605 }; // class Pipe
5606 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
5607
5608
5617 class Sampler : public detail::Wrapper<cl_sampler>
5618 {
5619 public:
5621 Sampler() { }
5622
5627 Sampler(
5628 const Context& context,
5629 cl_bool normalized_coords,
5630 cl_addressing_mode addressing_mode,
5631 cl_filter_mode filter_mode,
5632 cl_int* err = NULL)
5633 {
5634 cl_int error;
5635
5636 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5637 cl_sampler_properties sampler_properties[] = {
5638 CL_SAMPLER_NORMALIZED_COORDS, normalized_coords,
5639 CL_SAMPLER_ADDRESSING_MODE, addressing_mode,
5640 CL_SAMPLER_FILTER_MODE, filter_mode,
5641 0 };
5642 object_ = ::clCreateSamplerWithProperties(
5643 context(),
5644 sampler_properties,
5645 &error);
5646
5647 detail::errHandler(error, __CREATE_SAMPLER_WITH_PROPERTIES_ERR);
5648 if (err != NULL) {
5649 *err = error;
5650 }
5651 #else
5652 object_ = ::clCreateSampler(
5653 context(),
5654 normalized_coords,
5655 addressing_mode,
5656 filter_mode,
5657 &error);
5658
5659 detail::errHandler(error, __CREATE_SAMPLER_ERR);
5660 if (err != NULL) {
5661 *err = error;
5662 }
5663 #endif
5664 }
5665
5674 explicit Sampler(const cl_sampler& sampler, bool retainObject = false) :
5675 detail::Wrapper<cl_type>(sampler, retainObject) { }
5676
5682 Sampler& operator = (const cl_sampler& rhs)
5683 {
5684 detail::Wrapper<cl_type>::operator=(rhs);
5685 return *this;
5686 }
5687
5691 Sampler(const Sampler& sam) : detail::Wrapper<cl_type>(sam) {}
5692
5696 Sampler& operator = (const Sampler &sam)
5697 {
5698 detail::Wrapper<cl_type>::operator=(sam);
5699 return *this;
5700 }
5701
5705 Sampler(Sampler&& sam) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(sam)) {}
5706
5710 Sampler& operator = (Sampler &&sam)
5711 {
5712 detail::Wrapper<cl_type>::operator=(std::move(sam));
5713 return *this;
5714 }
5715
5717 template <typename T>
5718 cl_int getInfo(cl_sampler_info name, T* param) const
5719 {
5720 return detail::errHandler(
5721 detail::getInfo(&::clGetSamplerInfo, object_, name, param),
5722 __GET_SAMPLER_INFO_ERR);
5723 }
5724
5726 template <cl_sampler_info name> typename
5727 detail::param_traits<detail::cl_sampler_info, name>::param_type
5728 getInfo(cl_int* err = NULL) const
5729 {
5730 typename detail::param_traits<
5731 detail::cl_sampler_info, name>::param_type param;
5732 cl_int result = getInfo(name, &param);
5733 if (err != NULL) {
5734 *err = result;
5735 }
5736 return param;
5737 }
5738 };
5739
5740 class Program;
5741 class CommandQueue;
5742 class DeviceCommandQueue;
5743 class Kernel;
5744
5746 class NDRange
5747 {
5748 private:
5749 size_type sizes_[3];
5750 cl_uint dimensions_;
5751
5752 public:
5754 NDRange()
5755 : dimensions_(0)
5756 {
5757 sizes_[0] = 0;
5758 sizes_[1] = 0;
5759 sizes_[2] = 0;
5760 }
5761
5763 NDRange(size_type size0)
5764 : dimensions_(1)
5765 {
5766 sizes_[0] = size0;
5767 sizes_[1] = 1;
5768 sizes_[2] = 1;
5769 }
5770
5772 NDRange(size_type size0, size_type size1)
5773 : dimensions_(2)
5774 {
5775 sizes_[0] = size0;
5776 sizes_[1] = size1;
5777 sizes_[2] = 1;
5778 }
5779
5781 NDRange(size_type size0, size_type size1, size_type size2)
5782 : dimensions_(3)
5783 {
5784 sizes_[0] = size0;
5785 sizes_[1] = size1;
5786 sizes_[2] = size2;
5787 }
5788
5793 operator const size_type*() const {
5794 return sizes_;
5795 }
5796
5798 size_type dimensions() const
5799 {
5800 return dimensions_;
5801 }
5802
5804 // runtime number of dimensions
5805 size_type size() const
5806 {
5807 return dimensions_*sizeof(size_type);
5808 }
5809
5810 size_type* get()
5811 {
5812 return sizes_;
5813 }
5814
5815 const size_type* get() const
5816 {
5817 return sizes_;
5818 }
5819 };
5820
5822 static const NDRange NullRange;
5823
5825 struct LocalSpaceArg
5826 {
5827 size_type size_;
5828 };
5829
5830 namespace detail {
5831
5832 template <typename T, class Enable = void>
5833 struct KernelArgumentHandler;
5834
5835 // Enable for objects that are not subclasses of memory
5836 // Pointers, constants etc
5837 template <typename T>
5838 struct KernelArgumentHandler<T, typename std::enable_if<!std::is_base_of<cl::Memory, T>::value>::type>
5839 {
5840 static size_type size(const T&) { return sizeof(T); }
5841 static const T* ptr(const T& value) { return &value; }
5842 };
5843
5844 // Enable for subclasses of memory where we want to get a reference to the cl_mem out
5845 // and pass that in for safety
5846 template <typename T>
5847 struct KernelArgumentHandler<T, typename std::enable_if<std::is_base_of<cl::Memory, T>::value>::type>
5848 {
5849 static size_type size(const T&) { return sizeof(cl_mem); }
5850 static const cl_mem* ptr(const T& value) { return &(value()); }
5851 };
5852
5853 // Specialization for DeviceCommandQueue defined later
5854
5855 template <>
5856 struct KernelArgumentHandler<LocalSpaceArg, void>
5857 {
5858 static size_type size(const LocalSpaceArg& value) { return value.size_; }
5859 static const void* ptr(const LocalSpaceArg&) { return NULL; }
5860 };
5861
5862 }
5864
5868 inline LocalSpaceArg
5869 Local(size_type size)
5870 {
5871 LocalSpaceArg ret = { size };
5872 return ret;
5873 }
5874
5883 class Kernel : public detail::Wrapper<cl_kernel>
5884 {
5885 public:
5886 inline Kernel(const Program& program, const char* name, cl_int* err = NULL);
5887
5889 Kernel() { }
5890
5899 explicit Kernel(const cl_kernel& kernel, bool retainObject = false) :
5900 detail::Wrapper<cl_type>(kernel, retainObject) { }
5901
5907 Kernel& operator = (const cl_kernel& rhs)
5908 {
5909 detail::Wrapper<cl_type>::operator=(rhs);
5910 return *this;
5911 }
5912
5916 Kernel(const Kernel& kernel) : detail::Wrapper<cl_type>(kernel) {}
5917
5921 Kernel& operator = (const Kernel &kernel)
5922 {
5923 detail::Wrapper<cl_type>::operator=(kernel);
5924 return *this;
5925 }
5926
5930 Kernel(Kernel&& kernel) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(kernel)) {}
5931
5935 Kernel& operator = (Kernel &&kernel)
5936 {
5937 detail::Wrapper<cl_type>::operator=(std::move(kernel));
5938 return *this;
5939 }
5940
5941 template <typename T>
5942 cl_int getInfo(cl_kernel_info name, T* param) const
5943 {
5944 return detail::errHandler(
5945 detail::getInfo(&::clGetKernelInfo, object_, name, param),
5946 __GET_KERNEL_INFO_ERR);
5947 }
5948
5949 template <cl_kernel_info name> typename
5950 detail::param_traits<detail::cl_kernel_info, name>::param_type
5951 getInfo(cl_int* err = NULL) const
5952 {
5953 typename detail::param_traits<
5954 detail::cl_kernel_info, name>::param_type param;
5955 cl_int result = getInfo(name, &param);
5956 if (err != NULL) {
5957 *err = result;
5958 }
5959 return param;
5960 }
5961
5962 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5963 template <typename T>
5964 cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const
5965 {
5966 return detail::errHandler(
5967 detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param),
5968 __GET_KERNEL_ARG_INFO_ERR);
5969 }
5970
5971 template <cl_kernel_arg_info name> typename
5972 detail::param_traits<detail::cl_kernel_arg_info, name>::param_type
5973 getArgInfo(cl_uint argIndex, cl_int* err = NULL) const
5974 {
5975 typename detail::param_traits<
5976 detail::cl_kernel_arg_info, name>::param_type param;
5977 cl_int result = getArgInfo(argIndex, name, &param);
5978 if (err != NULL) {
5979 *err = result;
5980 }
5981 return param;
5982 }
5983 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5984
5985 template <typename T>
5986 cl_int getWorkGroupInfo(
5987 const Device& device, cl_kernel_work_group_info name, T* param) const
5988 {
5989 return detail::errHandler(
5990 detail::getInfo(
5991 &::clGetKernelWorkGroupInfo, object_, device(), name, param),
5992 __GET_KERNEL_WORK_GROUP_INFO_ERR);
5993 }
5994
5995 template <cl_kernel_work_group_info name> typename
5996 detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
5997 getWorkGroupInfo(const Device& device, cl_int* err = NULL) const
5998 {
5999 typename detail::param_traits<
6000 detail::cl_kernel_work_group_info, name>::param_type param;
6001 cl_int result = getWorkGroupInfo(device, name, &param);
6002 if (err != NULL) {
6003 *err = result;
6004 }
6005 return param;
6006 }
6007
6008 #if (CL_HPP_TARGET_OPENCL_VERSION >= 200 && defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)) || CL_HPP_TARGET_OPENCL_VERSION >= 210
6009 cl_int getSubGroupInfo(const cl::Device &dev, cl_kernel_sub_group_info name, const cl::NDRange &range, size_type* param) const
6010 {
6011 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6012
6013 return detail::errHandler(
6014 clGetKernelSubGroupInfo(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
6015 __GET_KERNEL_SUB_GROUP_INFO_ERR);
6016
6017 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6018
6019 typedef clGetKernelSubGroupInfoKHR_fn PFN_clGetKernelSubGroupInfoKHR;
6020 static PFN_clGetKernelSubGroupInfoKHR pfn_clGetKernelSubGroupInfoKHR = NULL;
6021 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetKernelSubGroupInfoKHR);
6022
6023 return detail::errHandler(
6024 pfn_clGetKernelSubGroupInfoKHR(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
6025 __GET_KERNEL_SUB_GROUP_INFO_ERR);
6026
6027 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6028 }
6029
6030 template <cl_kernel_sub_group_info name>
6031 size_type getSubGroupInfo(const cl::Device &dev, const cl::NDRange &range, cl_int* err = NULL) const
6032 {
6033 size_type param;
6034 cl_int result = getSubGroupInfo(dev, name, range, &param);
6035 if (err != NULL) {
6036 *err = result;
6037 }
6038 return param;
6039 }
6040 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6041
6042 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6043
6045 template<typename T, class D>
6046 cl_int setArg(cl_uint index, const cl::pointer<T, D> &argPtr)
6047 {
6048 return detail::errHandler(
6049 ::clSetKernelArgSVMPointer(object_, index, argPtr.get()),
6050 __SET_KERNEL_ARGS_ERR);
6051 }
6052
6055 template<typename T, class Alloc>
6056 cl_int setArg(cl_uint index, const cl::vector<T, Alloc> &argPtr)
6057 {
6058 return detail::errHandler(
6059 ::clSetKernelArgSVMPointer(object_, index, argPtr.data()),
6060 __SET_KERNEL_ARGS_ERR);
6061 }
6062
6065 template<typename T>
6066 typename std::enable_if<std::is_pointer<T>::value, cl_int>::type
6067 setArg(cl_uint index, const T argPtr)
6068 {
6069 return detail::errHandler(
6070 ::clSetKernelArgSVMPointer(object_, index, argPtr),
6071 __SET_KERNEL_ARGS_ERR);
6072 }
6073 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6074
6077 template <typename T>
6078 typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6079 setArg(cl_uint index, const T &value)
6080 {
6081 return detail::errHandler(
6082 ::clSetKernelArg(
6083 object_,
6084 index,
6085 detail::KernelArgumentHandler<T>::size(value),
6086 detail::KernelArgumentHandler<T>::ptr(value)),
6087 __SET_KERNEL_ARGS_ERR);
6088 }
6089
6090 cl_int setArg(cl_uint index, size_type size, const void* argPtr)
6091 {
6092 return detail::errHandler(
6093 ::clSetKernelArg(object_, index, size, argPtr),
6094 __SET_KERNEL_ARGS_ERR);
6095 }
6096
6097 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6098
6102 cl_int setSVMPointers(const vector<void*> &pointerList)
6103 {
6104 return detail::errHandler(
6105 ::clSetKernelExecInfo(
6106 object_,
6107 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6108 sizeof(void*)*pointerList.size(),
6109 pointerList.data()));
6110 }
6111
6116 template<int ArrayLength>
6117 cl_int setSVMPointers(const std::array<void*, ArrayLength> &pointerList)
6118 {
6119 return detail::errHandler(
6120 ::clSetKernelExecInfo(
6121 object_,
6122 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6123 sizeof(void*)*pointerList.size(),
6124 pointerList.data()));
6125 }
6126
6138 cl_int enableFineGrainedSystemSVM(bool svmEnabled)
6139 {
6140 cl_bool svmEnabled_ = svmEnabled ? CL_TRUE : CL_FALSE;
6141 return detail::errHandler(
6142 ::clSetKernelExecInfo(
6143 object_,
6144 CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM,
6145 sizeof(cl_bool),
6146 &svmEnabled_
6147 )
6148 );
6149 }
6150
6151 template<int index, int ArrayLength, class D, typename T0, typename T1, typename... Ts>
6152 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0, const pointer<T1, D> &t1, Ts & ... ts)
6153 {
6154 pointerList[index] = static_cast<void*>(t0.get());
6155 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6156 }
6157
6158 template<int index, int ArrayLength, typename T0, typename T1, typename... Ts>
6159 typename std::enable_if<std::is_pointer<T0>::value, void>::type
6160 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0, T1 t1, Ts... ts)
6161 {
6162 pointerList[index] = static_cast<void*>(t0);
6163 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6164 }
6165
6166 template<int index, int ArrayLength, typename T0, class D>
6167 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0)
6168 {
6169 pointerList[index] = static_cast<void*>(t0.get());
6170 }
6171
6172
6173 template<int index, int ArrayLength, typename T0>
6174 typename std::enable_if<std::is_pointer<T0>::value, void>::type
6175 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0)
6176 {
6177 pointerList[index] = static_cast<void*>(t0);
6178 }
6179
6180 template<typename T0, typename... Ts>
6181 cl_int setSVMPointers(const T0 &t0, Ts & ... ts)
6182 {
6183 std::array<void*, 1 + sizeof...(Ts)> pointerList;
6184
6185 setSVMPointersHelper<0, 1 + sizeof...(Ts)>(pointerList, t0, ts...);
6186 return detail::errHandler(
6187 ::clSetKernelExecInfo(
6188 object_,
6189 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6190 sizeof(void*)*(1 + sizeof...(Ts)),
6191 pointerList.data()));
6192 }
6193
6194 template<typename T>
6195 cl_int setExecInfo(cl_kernel_exec_info param_name, const T& val)
6196 {
6197 return detail::errHandler(
6198 ::clSetKernelExecInfo(
6199 object_,
6200 param_name,
6201 sizeof(T),
6202 &val));
6203 }
6204
6205 template<cl_kernel_exec_info name>
6206 cl_int setExecInfo(typename detail::param_traits<detail::cl_kernel_exec_info, name>::param_type& val)
6207 {
6208 return setExecInfo(name, val);
6209 }
6210 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6211
6212 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6213
6218 Kernel clone()
6219 {
6220 cl_int error;
6221 Kernel retValue(clCloneKernel(this->get(), &error));
6222
6223 detail::errHandler(error, __CLONE_KERNEL_ERR);
6224 return retValue;
6225 }
6226 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6227 };
6228
6232 class Program : public detail::Wrapper<cl_program>
6233 {
6234 public:
6235 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6236 typedef vector<vector<unsigned char>> Binaries;
6237 typedef vector<string> Sources;
6238 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6239 typedef vector<std::pair<const void*, size_type> > Binaries;
6240 typedef vector<std::pair<const char*, size_type> > Sources;
6241 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6242
6243 Program(
6244 const string& source,
6245 bool build = false,
6246 cl_int* err = NULL)
6247 {
6248 cl_int error;
6249
6250 const char * strings = source.c_str();
6251 const size_type length = source.size();
6252
6253 Context context = Context::getDefault(err);
6254
6255 object_ = ::clCreateProgramWithSource(
6256 context(), (cl_uint)1, &strings, &length, &error);
6257
6258 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6259
6260 if (error == CL_SUCCESS && build) {
6261
6262 error = ::clBuildProgram(
6263 object_,
6264 0,
6265 NULL,
6266 #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6267 "-cl-std=CL2.0",
6268 #else
6269 "",
6270 #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6271 NULL,
6272 NULL);
6273
6274 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6275 }
6276
6277 if (err != NULL) {
6278 *err = error;
6279 }
6280 }
6281
6282 Program(
6283 const Context& context,
6284 const string& source,
6285 bool build = false,
6286 cl_int* err = NULL)
6287 {
6288 cl_int error;
6289
6290 const char * strings = source.c_str();
6291 const size_type length = source.size();
6292
6293 object_ = ::clCreateProgramWithSource(
6294 context(), (cl_uint)1, &strings, &length, &error);
6295
6296 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6297
6298 if (error == CL_SUCCESS && build) {
6299 error = ::clBuildProgram(
6300 object_,
6301 0,
6302 NULL,
6303 #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6304 "-cl-std=CL2.0",
6305 #else
6306 "",
6307 #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6308 NULL,
6309 NULL);
6310
6311 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6312 }
6313
6314 if (err != NULL) {
6315 *err = error;
6316 }
6317 }
6318
6323 Program(
6324 const Sources& sources,
6325 cl_int* err = NULL)
6326 {
6327 cl_int error;
6328 Context context = Context::getDefault(err);
6329
6330 const size_type n = (size_type)sources.size();
6331
6332 vector<size_type> lengths(n);
6333 vector<const char*> strings(n);
6334
6335 for (size_type i = 0; i < n; ++i) {
6336 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6337 strings[i] = sources[(int)i].data();
6338 lengths[i] = sources[(int)i].length();
6339 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6340 strings[i] = sources[(int)i].first;
6341 lengths[i] = sources[(int)i].second;
6342 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6343 }
6344
6345 object_ = ::clCreateProgramWithSource(
6346 context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6347
6348 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6349 if (err != NULL) {
6350 *err = error;
6351 }
6352 }
6353
6358 Program(
6359 const Context& context,
6360 const Sources& sources,
6361 cl_int* err = NULL)
6362 {
6363 cl_int error;
6364
6365 const size_type n = (size_type)sources.size();
6366
6367 vector<size_type> lengths(n);
6368 vector<const char*> strings(n);
6369
6370 for (size_type i = 0; i < n; ++i) {
6371 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6372 strings[i] = sources[(int)i].data();
6373 lengths[i] = sources[(int)i].length();
6374 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6375 strings[i] = sources[(int)i].first;
6376 lengths[i] = sources[(int)i].second;
6377 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6378 }
6379
6380 object_ = ::clCreateProgramWithSource(
6381 context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6382
6383 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6384 if (err != NULL) {
6385 *err = error;
6386 }
6387 }
6388
6389
6390 #if CL_HPP_TARGET_OPENCL_VERSION >= 210 || (CL_HPP_TARGET_OPENCL_VERSION==200 && defined(CL_HPP_USE_IL_KHR))
6391
6395 Program(
6396 const vector<char>& IL,
6397 bool build = false,
6398 cl_int* err = NULL)
6399 {
6400 cl_int error;
6401
6402 Context context = Context::getDefault(err);
6403
6404 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6405
6406 object_ = ::clCreateProgramWithIL(
6407 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6408
6409 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6410
6411 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6412 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6413 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6414
6415 return detail::errHandler(
6416 pfn_clCreateProgramWithILKHR(
6417 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6418
6419 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6420
6421 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6422
6423 if (error == CL_SUCCESS && build) {
6424
6425 error = ::clBuildProgram(
6426 object_,
6427 0,
6428 NULL,
6429 #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6430 "-cl-std=CL2.0",
6431 #else
6432 "",
6433 #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6434 NULL,
6435 NULL);
6436
6437 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6438 }
6439
6440 if (err != NULL) {
6441 *err = error;
6442 }
6443 }
6444
6450 Program(
6451 const Context& context,
6452 const vector<char>& IL,
6453 bool build = false,
6454 cl_int* err = NULL)
6455 {
6456 cl_int error;
6457
6458 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6459
6460 object_ = ::clCreateProgramWithIL(
6461 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6462
6463 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6464
6465 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6466 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6467 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6468
6469 return detail::errHandler(
6470 pfn_clCreateProgramWithILKHR(
6471 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6472
6473 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6474
6475 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6476
6477 if (error == CL_SUCCESS && build) {
6478 error = ::clBuildProgram(
6479 object_,
6480 0,
6481 NULL,
6482 #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6483 "-cl-std=CL2.0",
6484 #else
6485 "",
6486 #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6487 NULL,
6488 NULL);
6489
6490 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6491 }
6492
6493 if (err != NULL) {
6494 *err = error;
6495 }
6496 }
6497 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6498
6518 Program(
6519 const Context& context,
6520 const vector<Device>& devices,
6521 const Binaries& binaries,
6522 vector<cl_int>* binaryStatus = NULL,
6523 cl_int* err = NULL)
6524 {
6525 cl_int error;
6526
6527 const size_type numDevices = devices.size();
6528
6529 // Catch size mismatch early and return
6530 if(binaries.size() != numDevices) {
6531 error = CL_INVALID_VALUE;
6532 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6533 if (err != NULL) {
6534 *err = error;
6535 }
6536 return;
6537 }
6538
6539
6540 vector<size_type> lengths(numDevices);
6541 vector<const unsigned char*> images(numDevices);
6542 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6543 for (size_type i = 0; i < numDevices; ++i) {
6544 images[i] = binaries[i].data();
6545 lengths[i] = binaries[(int)i].size();
6546 }
6547 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6548 for (size_type i = 0; i < numDevices; ++i) {
6549 images[i] = (const unsigned char*)binaries[i].first;
6550 lengths[i] = binaries[(int)i].second;
6551 }
6552 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6553
6554 vector<cl_device_id> deviceIDs(numDevices);
6555 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6556 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6557 }
6558
6559 if(binaryStatus) {
6560 binaryStatus->resize(numDevices);
6561 }
6562
6563 object_ = ::clCreateProgramWithBinary(
6564 context(), (cl_uint) devices.size(),
6565 deviceIDs.data(),
6566 lengths.data(), images.data(), (binaryStatus != NULL && numDevices > 0)
6567 ? &binaryStatus->front()
6568 : NULL, &error);
6569
6570 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6571 if (err != NULL) {
6572 *err = error;
6573 }
6574 }
6575
6576
6577 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6578
6582 Program(
6583 const Context& context,
6584 const vector<Device>& devices,
6585 const string& kernelNames,
6586 cl_int* err = NULL)
6587 {
6588 cl_int error;
6589
6590
6591 size_type numDevices = devices.size();
6592 vector<cl_device_id> deviceIDs(numDevices);
6593 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6594 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6595 }
6596
6597 object_ = ::clCreateProgramWithBuiltInKernels(
6598 context(),
6599 (cl_uint) devices.size(),
6600 deviceIDs.data(),
6601 kernelNames.c_str(),
6602 &error);
6603
6604 detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR);
6605 if (err != NULL) {
6606 *err = error;
6607 }
6608 }
6609 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6610
6611 Program() { }
6612
6613
6620 explicit Program(const cl_program& program, bool retainObject = false) :
6621 detail::Wrapper<cl_type>(program, retainObject) { }
6622
6623 Program& operator = (const cl_program& rhs)
6624 {
6625 detail::Wrapper<cl_type>::operator=(rhs);
6626 return *this;
6627 }
6628
6632 Program(const Program& program) : detail::Wrapper<cl_type>(program) {}
6633
6637 Program& operator = (const Program &program)
6638 {
6639 detail::Wrapper<cl_type>::operator=(program);
6640 return *this;
6641 }
6642
6646 Program(Program&& program) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(program)) {}
6647
6651 Program& operator = (Program &&program)
6652 {
6653 detail::Wrapper<cl_type>::operator=(std::move(program));
6654 return *this;
6655 }
6656
6657 cl_int build(
6658 const vector<Device>& devices,
6659 const char* options = NULL,
6660 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6661 void* data = NULL) const
6662 {
6663 size_type numDevices = devices.size();
6664 vector<cl_device_id> deviceIDs(numDevices);
6665
6666 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6667 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6668 }
6669
6670 cl_int buildError = ::clBuildProgram(
6671 object_,
6672 (cl_uint)
6673 devices.size(),
6674 deviceIDs.data(),
6675 options,
6676 notifyFptr,
6677 data);
6678
6679 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6680 }
6681
6682 cl_int build(
6683 const Device& device,
6684 const char* options = NULL,
6685 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6686 void* data = NULL) const
6687 {
6688 cl_device_id deviceID = device();
6689
6690 cl_int buildError = ::clBuildProgram(
6691 object_,
6692 1,
6693 &deviceID,
6694 options,
6695 notifyFptr,
6696 data);
6697
6698 BuildLogType buildLog(1);
6699 buildLog.push_back(std::make_pair(device, getBuildInfo<CL_PROGRAM_BUILD_LOG>(device)));
6700 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, buildLog);
6701 }
6702
6703 cl_int build(
6704 const char* options = NULL,
6705 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6706 void* data = NULL) const
6707 {
6708 cl_int buildError = ::clBuildProgram(
6709 object_,
6710 0,
6711 NULL,
6712 options,
6713 notifyFptr,
6714 data);
6715
6716 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6717 }
6718
6719 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6720 cl_int compile(
6721 const char* options = NULL,
6722 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6723 void* data = NULL) const
6724 {
6725 cl_int error = ::clCompileProgram(
6726 object_,
6727 0,
6728 NULL,
6729 options,
6730 0,
6731 NULL,
6732 NULL,
6733 notifyFptr,
6734 data);
6735 return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6736 }
6737 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6738
6739 template <typename T>
6740 cl_int getInfo(cl_program_info name, T* param) const
6741 {
6742 return detail::errHandler(
6743 detail::getInfo(&::clGetProgramInfo, object_, name, param),
6744 __GET_PROGRAM_INFO_ERR);
6745 }
6746
6747 template <cl_program_info name> typename
6748 detail::param_traits<detail::cl_program_info, name>::param_type
6749 getInfo(cl_int* err = NULL) const
6750 {
6751 typename detail::param_traits<
6752 detail::cl_program_info, name>::param_type param;
6753 cl_int result = getInfo(name, &param);
6754 if (err != NULL) {
6755 *err = result;
6756 }
6757 return param;
6758 }
6759
6760 template <typename T>
6761 cl_int getBuildInfo(
6762 const Device& device, cl_program_build_info name, T* param) const
6763 {
6764 return detail::errHandler(
6765 detail::getInfo(
6766 &::clGetProgramBuildInfo, object_, device(), name, param),
6767 __GET_PROGRAM_BUILD_INFO_ERR);
6768 }
6769
6770 template <cl_program_build_info name> typename
6771 detail::param_traits<detail::cl_program_build_info, name>::param_type
6772 getBuildInfo(const Device& device, cl_int* err = NULL) const
6773 {
6774 typename detail::param_traits<
6775 detail::cl_program_build_info, name>::param_type param;
6776 cl_int result = getBuildInfo(device, name, &param);
6777 if (err != NULL) {
6778 *err = result;
6779 }
6780 return param;
6781 }
6782
6788 template <cl_program_build_info name>
6789 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6790 getBuildInfo(cl_int *err = NULL) const
6791 {
6792 cl_int result = CL_SUCCESS;
6793
6794 auto devs = getInfo<CL_PROGRAM_DEVICES>(&result);
6795 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6796 devInfo;
6797
6798 // If there was an initial error from getInfo return the error
6799 if (result != CL_SUCCESS) {
6800 if (err != NULL) {
6801 *err = result;
6802 }
6803 return devInfo;
6804 }
6805
6806 for (const cl::Device &d : devs) {
6807 typename detail::param_traits<
6808 detail::cl_program_build_info, name>::param_type param;
6809 result = getBuildInfo(d, name, &param);
6810 devInfo.push_back(
6811 std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>
6812 (d, param));
6813 if (result != CL_SUCCESS) {
6814 // On error, leave the loop and return the error code
6815 break;
6816 }
6817 }
6818 if (err != NULL) {
6819 *err = result;
6820 }
6821 if (result != CL_SUCCESS) {
6822 devInfo.clear();
6823 }
6824 return devInfo;
6825 }
6826
6827 cl_int createKernels(vector<Kernel>* kernels)
6828 {
6829 cl_uint numKernels;
6830 cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
6831 if (err != CL_SUCCESS) {
6832 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6833 }
6834
6835 vector<cl_kernel> value(numKernels);
6836
6837 err = ::clCreateKernelsInProgram(
6838 object_, numKernels, value.data(), NULL);
6839 if (err != CL_SUCCESS) {
6840 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6841 }
6842
6843 if (kernels) {
6844 kernels->resize(value.size());
6845
6846 // Assign to param, constructing with retain behaviour
6847 // to correctly capture each underlying CL object
6848 for (size_type i = 0; i < value.size(); i++) {
6849 // We do not need to retain because this kernel is being created
6850 // by the runtime
6851 (*kernels)[i] = Kernel(value[i], false);
6852 }
6853 }
6854 return CL_SUCCESS;
6855 }
6856
6857 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
6858 #if defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
6859
6869 CL_EXT_PREFIX__VERSION_2_2_DEPRECATED cl_int setReleaseCallback(
6870 void (CL_CALLBACK * pfn_notify)(cl_program program, void * user_data),
6871 void * user_data = NULL) CL_EXT_SUFFIX__VERSION_2_2_DEPRECATED
6872 {
6873 return detail::errHandler(
6874 ::clSetProgramReleaseCallback(
6875 object_,
6876 pfn_notify,
6877 user_data),
6878 __SET_PROGRAM_RELEASE_CALLBACK_ERR);
6879 }
6880 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
6881
6886 template <typename T>
6887 typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6888 setSpecializationConstant(cl_uint index, const T &value)
6889 {
6890 return detail::errHandler(
6891 ::clSetProgramSpecializationConstant(
6892 object_,
6893 index,
6894 sizeof(value),
6895 &value),
6896 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6897 }
6898
6903 cl_int setSpecializationConstant(cl_uint index, size_type size, const void* value)
6904 {
6905 return detail::errHandler(
6906 ::clSetProgramSpecializationConstant(
6907 object_,
6908 index,
6909 size,
6910 value),
6911 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6912 }
6913 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
6914 };
6915
6916 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6917 inline Program linkProgram(
6918 Program input1,
6919 Program input2,
6920 const char* options = NULL,
6921 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6922 void* data = NULL,
6923 cl_int* err = NULL)
6924 {
6925 cl_int error_local = CL_SUCCESS;
6926
6927 cl_program programs[2] = { input1(), input2() };
6928
6929 Context ctx = input1.getInfo<CL_PROGRAM_CONTEXT>(&error_local);
6930 if(error_local!=CL_SUCCESS) {
6931 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
6932 }
6933
6934 cl_program prog = ::clLinkProgram(
6935 ctx(),
6936 0,
6937 NULL,
6938 options,
6939 2,
6940 programs,
6941 notifyFptr,
6942 data,
6943 &error_local);
6944
6945 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
6946 if (err != NULL) {
6947 *err = error_local;
6948 }
6949
6950 return Program(prog);
6951 }
6952
6953 inline Program linkProgram(
6954 vector<Program> inputPrograms,
6955 const char* options = NULL,
6956 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6957 void* data = NULL,
6958 cl_int* err = NULL)
6959 {
6960 cl_int error_local = CL_SUCCESS;
6961
6962 vector<cl_program> programs(inputPrograms.size());
6963
6964 for (unsigned int i = 0; i < inputPrograms.size(); i++) {
6965 programs[i] = inputPrograms[i]();
6966 }
6967
6968 Context ctx;
6969 if(inputPrograms.size() > 0) {
6970 ctx = inputPrograms[0].getInfo<CL_PROGRAM_CONTEXT>(&error_local);
6971 if(error_local!=CL_SUCCESS) {
6972 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
6973 }
6974 }
6975 cl_program prog = ::clLinkProgram(
6976 ctx(),
6977 0,
6978 NULL,
6979 options,
6980 (cl_uint)inputPrograms.size(),
6981 programs.data(),
6982 notifyFptr,
6983 data,
6984 &error_local);
6985
6986 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
6987 if (err != NULL) {
6988 *err = error_local;
6989 }
6990
6991 return Program(prog, false);
6992 }
6993 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6994
6995 // Template specialization for CL_PROGRAM_BINARIES
6996 template <>
6997 inline cl_int cl::Program::getInfo(cl_program_info name, vector<vector<unsigned char>>* param) const
6998 {
6999 if (name != CL_PROGRAM_BINARIES) {
7000 return CL_INVALID_VALUE;
7001 }
7002 if (param) {
7003 // Resize the parameter array appropriately for each allocation
7004 // and pass down to the helper
7005
7006 vector<size_type> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>();
7007 size_type numBinaries = sizes.size();
7008
7009 // Resize the parameter array and constituent arrays
7010 param->resize(numBinaries);
7011 for (size_type i = 0; i < numBinaries; ++i) {
7012 (*param)[i].resize(sizes[i]);
7013 }
7014
7015 return detail::errHandler(
7016 detail::getInfo(&::clGetProgramInfo, object_, name, param),
7017 __GET_PROGRAM_INFO_ERR);
7018 }
7019
7020 return CL_SUCCESS;
7021 }
7022
7023 template<>
7024 inline vector<vector<unsigned char>> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err) const
7025 {
7026 vector<vector<unsigned char>> binariesVectors;
7027
7028 cl_int result = getInfo(CL_PROGRAM_BINARIES, &binariesVectors);
7029 if (err != NULL) {
7030 *err = result;
7031 }
7032 return binariesVectors;
7033 }
7034
7035 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
7036 // Template specialization for clSetProgramSpecializationConstant
7037 template <>
7038 inline cl_int cl::Program::setSpecializationConstant(cl_uint index, const bool &value)
7039 {
7040 cl_uchar ucValue = value ? CL_UCHAR_MAX : 0;
7041 return detail::errHandler(
7042 ::clSetProgramSpecializationConstant(
7043 object_,
7044 index,
7045 sizeof(ucValue),
7046 &ucValue),
7047 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
7048 }
7049 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
7050
7051 inline Kernel::Kernel(const Program& program, const char* name, cl_int* err)
7052 {
7053 cl_int error;
7054
7055 object_ = ::clCreateKernel(program(), name, &error);
7056 detail::errHandler(error, __CREATE_KERNEL_ERR);
7057
7058 if (err != NULL) {
7059 *err = error;
7060 }
7061
7062 }
7063
7064 enum class QueueProperties : cl_command_queue_properties
7065 {
7066 None = 0,
7067 Profiling = CL_QUEUE_PROFILING_ENABLE,
7068 OutOfOrder = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,
7069 };
7070
7071 inline QueueProperties operator|(QueueProperties lhs, QueueProperties rhs)
7072 {
7073 return static_cast<QueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
7074 }
7075
7079 class CommandQueue : public detail::Wrapper<cl_command_queue>
7080 {
7081 private:
7082 static std::once_flag default_initialized_;
7083 static CommandQueue default_;
7084 static cl_int default_error_;
7085
7091 static void makeDefault()
7092 {
7093 /* We don't want to throw an error from this function, so we have to
7094 * catch and set the error flag.
7095 */
7096 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
7097 try
7098 #endif
7099 {
7100 int error;
7101 Context context = Context::getDefault(&error);
7102
7103 if (error != CL_SUCCESS) {
7104 default_error_ = error;
7105 }
7106 else {
7107 Device device = Device::getDefault();
7108 default_ = CommandQueue(context, device, 0, &default_error_);
7109 }
7110 }
7111 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
7112 catch (cl::Error &e) {
7113 default_error_ = e.err();
7114 }
7115 #endif
7116 }
7117
7123 static void makeDefaultProvided(const CommandQueue &c) {
7124 default_ = c;
7125 }
7126
7127 public:
7128 #ifdef CL_HPP_UNIT_TEST_ENABLE
7129
7135 static void unitTestClearDefault() {
7136 default_ = CommandQueue();
7137 }
7138 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
7139
7140
7145 CommandQueue(
7146 cl_command_queue_properties properties,
7147 cl_int* err = NULL)
7148 {
7149 cl_int error;
7150
7151 Context context = Context::getDefault(&error);
7152 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7153
7154 if (error != CL_SUCCESS) {
7155 if (err != NULL) {
7156 *err = error;
7157 }
7158 }
7159 else {
7160 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7161 bool useWithProperties;
7162
7163 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7164 // Run-time decision based on the actual platform
7165 {
7166 cl_uint version = detail::getContextPlatformVersion(context());
7167 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7168 }
7169 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7170 useWithProperties = true;
7171 #else
7172 useWithProperties = false;
7173 #endif
7174
7175 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7176 if (useWithProperties) {
7177 cl_queue_properties queue_properties[] = {
7178 CL_QUEUE_PROPERTIES, properties, 0 };
7179 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7180 object_ = ::clCreateCommandQueueWithProperties(
7181 context(), device(), queue_properties, &error);
7182 }
7183 else {
7184 error = CL_INVALID_QUEUE_PROPERTIES;
7185 }
7186
7187 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7188 if (err != NULL) {
7189 *err = error;
7190 }
7191 }
7192 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7193 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7194 if (!useWithProperties) {
7195 object_ = ::clCreateCommandQueue(
7196 context(), device(), properties, &error);
7197
7198 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7199 if (err != NULL) {
7200 *err = error;
7201 }
7202 }
7203 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7204 }
7205 }
7206
7211 CommandQueue(
7212 QueueProperties properties,
7213 cl_int* err = NULL)
7214 {
7215 cl_int error;
7216
7217 Context context = Context::getDefault(&error);
7218 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7219
7220 if (error != CL_SUCCESS) {
7221 if (err != NULL) {
7222 *err = error;
7223 }
7224 }
7225 else {
7226 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7227 bool useWithProperties;
7228
7229 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7230 // Run-time decision based on the actual platform
7231 {
7232 cl_uint version = detail::getContextPlatformVersion(context());
7233 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7234 }
7235 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7236 useWithProperties = true;
7237 #else
7238 useWithProperties = false;
7239 #endif
7240
7241 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7242 if (useWithProperties) {
7243 cl_queue_properties queue_properties[] = {
7244 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7245
7246 object_ = ::clCreateCommandQueueWithProperties(
7247 context(), device(), queue_properties, &error);
7248
7249 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7250 if (err != NULL) {
7251 *err = error;
7252 }
7253 }
7254 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7255 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7256 if (!useWithProperties) {
7257 object_ = ::clCreateCommandQueue(
7258 context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
7259
7260 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7261 if (err != NULL) {
7262 *err = error;
7263 }
7264 }
7265 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7266
7267 }
7268 }
7269
7274 explicit CommandQueue(
7275 const Context& context,
7276 cl_command_queue_properties properties = 0,
7277 cl_int* err = NULL)
7278 {
7279 cl_int error;
7280 bool useWithProperties;
7281 vector<cl::Device> devices;
7282 error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7283
7284 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7285
7286 if (error != CL_SUCCESS)
7287 {
7288 if (err != NULL) {
7289 *err = error;
7290 }
7291 return;
7292 }
7293
7294 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7295 // Run-time decision based on the actual platform
7296 {
7297 cl_uint version = detail::getContextPlatformVersion(context());
7298 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7299 }
7300 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7301 useWithProperties = true;
7302 #else
7303 useWithProperties = false;
7304 #endif
7305
7306 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7307 if (useWithProperties) {
7308 cl_queue_properties queue_properties[] = {
7309 CL_QUEUE_PROPERTIES, properties, 0 };
7310 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7311 object_ = ::clCreateCommandQueueWithProperties(
7312 context(), devices[0](), queue_properties, &error);
7313 }
7314 else {
7315 error = CL_INVALID_QUEUE_PROPERTIES;
7316 }
7317
7318 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7319 if (err != NULL) {
7320 *err = error;
7321 }
7322 }
7323 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7324 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7325 if (!useWithProperties) {
7326 object_ = ::clCreateCommandQueue(
7327 context(), devices[0](), properties, &error);
7328
7329 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7330 if (err != NULL) {
7331 *err = error;
7332 }
7333 }
7334 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7335 }
7336
7341 explicit CommandQueue(
7342 const Context& context,
7343 QueueProperties properties,
7344 cl_int* err = NULL)
7345 {
7346 cl_int error;
7347 bool useWithProperties;
7348 vector<cl::Device> devices;
7349 error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7350
7351 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7352
7353 if (error != CL_SUCCESS)
7354 {
7355 if (err != NULL) {
7356 *err = error;
7357 }
7358 return;
7359 }
7360
7361 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7362 // Run-time decision based on the actual platform
7363 {
7364 cl_uint version = detail::getContextPlatformVersion(context());
7365 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7366 }
7367 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7368 useWithProperties = true;
7369 #else
7370 useWithProperties = false;
7371 #endif
7372
7373 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7374 if (useWithProperties) {
7375 cl_queue_properties queue_properties[] = {
7376 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7377 object_ = ::clCreateCommandQueueWithProperties(
7378 context(), devices[0](), queue_properties, &error);
7379
7380 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7381 if (err != NULL) {
7382 *err = error;
7383 }
7384 }
7385 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7386 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7387 if (!useWithProperties) {
7388 object_ = ::clCreateCommandQueue(
7389 context(), devices[0](), static_cast<cl_command_queue_properties>(properties), &error);
7390
7391 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7392 if (err != NULL) {
7393 *err = error;
7394 }
7395 }
7396 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7397 }
7398
7403 CommandQueue(
7404 const Context& context,
7405 const Device& device,
7406 cl_command_queue_properties properties = 0,
7407 cl_int* err = NULL)
7408 {
7409 cl_int error;
7410 bool useWithProperties;
7411
7412 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7413 // Run-time decision based on the actual platform
7414 {
7415 cl_uint version = detail::getContextPlatformVersion(context());
7416 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7417 }
7418 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7419 useWithProperties = true;
7420 #else
7421 useWithProperties = false;
7422 #endif
7423
7424 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7425 if (useWithProperties) {
7426 cl_queue_properties queue_properties[] = {
7427 CL_QUEUE_PROPERTIES, properties, 0 };
7428 object_ = ::clCreateCommandQueueWithProperties(
7429 context(), device(), queue_properties, &error);
7430
7431 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7432 if (err != NULL) {
7433 *err = error;
7434 }
7435 }
7436 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7437 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7438 if (!useWithProperties) {
7439 object_ = ::clCreateCommandQueue(
7440 context(), device(), properties, &error);
7441
7442 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7443 if (err != NULL) {
7444 *err = error;
7445 }
7446 }
7447 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7448 }
7449
7454 CommandQueue(
7455 const Context& context,
7456 const Device& device,
7457 QueueProperties properties,
7458 cl_int* err = NULL)
7459 {
7460 cl_int error;
7461 bool useWithProperties;
7462
7463 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7464 // Run-time decision based on the actual platform
7465 {
7466 cl_uint version = detail::getContextPlatformVersion(context());
7467 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7468 }
7469 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7470 useWithProperties = true;
7471 #else
7472 useWithProperties = false;
7473 #endif
7474
7475 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7476 if (useWithProperties) {
7477 cl_queue_properties queue_properties[] = {
7478 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7479 object_ = ::clCreateCommandQueueWithProperties(
7480 context(), device(), queue_properties, &error);
7481
7482 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7483 if (err != NULL) {
7484 *err = error;
7485 }
7486 }
7487 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7488 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7489 if (!useWithProperties) {
7490 object_ = ::clCreateCommandQueue(
7491 context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
7492
7493 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7494 if (err != NULL) {
7495 *err = error;
7496 }
7497 }
7498 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7499 }
7500
7501 static CommandQueue getDefault(cl_int * err = NULL)
7502 {
7503 std::call_once(default_initialized_, makeDefault);
7504 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7505 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7506 #else // CL_HPP_TARGET_OPENCL_VERSION >= 200
7507 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_ERR);
7508 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7509 if (err != NULL) {
7510 *err = default_error_;
7511 }
7512 return default_;
7513 }
7514
7522 static CommandQueue setDefault(const CommandQueue &default_queue)
7523 {
7524 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_queue));
7525 detail::errHandler(default_error_);
7526 return default_;
7527 }
7528
7529 CommandQueue() { }
7530
7531
7538 explicit CommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
7539 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
7540
7541 CommandQueue& operator = (const cl_command_queue& rhs)
7542 {
7543 detail::Wrapper<cl_type>::operator=(rhs);
7544 return *this;
7545 }
7546
7550 CommandQueue(const CommandQueue& queue) : detail::Wrapper<cl_type>(queue) {}
7551
7555 CommandQueue& operator = (const CommandQueue &queue)
7556 {
7557 detail::Wrapper<cl_type>::operator=(queue);
7558 return *this;
7559 }
7560
7564 CommandQueue(CommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(queue)) {}
7565
7569 CommandQueue& operator = (CommandQueue &&queue)
7570 {
7571 detail::Wrapper<cl_type>::operator=(std::move(queue));
7572 return *this;
7573 }
7574
7575 template <typename T>
7576 cl_int getInfo(cl_command_queue_info name, T* param) const
7577 {
7578 return detail::errHandler(
7579 detail::getInfo(
7580 &::clGetCommandQueueInfo, object_, name, param),
7581 __GET_COMMAND_QUEUE_INFO_ERR);
7582 }
7583
7584 template <cl_command_queue_info name> typename
7585 detail::param_traits<detail::cl_command_queue_info, name>::param_type
7586 getInfo(cl_int* err = NULL) const
7587 {
7588 typename detail::param_traits<
7589 detail::cl_command_queue_info, name>::param_type param;
7590 cl_int result = getInfo(name, &param);
7591 if (err != NULL) {
7592 *err = result;
7593 }
7594 return param;
7595 }
7596
7597 cl_int enqueueReadBuffer(
7598 const Buffer& buffer,
7599 cl_bool blocking,
7600 size_type offset,
7601 size_type size,
7602 void* ptr,
7603 const vector<Event>* events = NULL,
7604 Event* event = NULL) const
7605 {
7606 cl_event tmp;
7607 cl_int err = detail::errHandler(
7608 ::clEnqueueReadBuffer(
7609 object_, buffer(), blocking, offset, size,
7610 ptr,
7611 (events != NULL) ? (cl_uint) events->size() : 0,
7612 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7613 (event != NULL) ? &tmp : NULL),
7614 __ENQUEUE_READ_BUFFER_ERR);
7615
7616 if (event != NULL && err == CL_SUCCESS)
7617 *event = tmp;
7618
7619 return err;
7620 }
7621
7622 cl_int enqueueWriteBuffer(
7623 const Buffer& buffer,
7624 cl_bool blocking,
7625 size_type offset,
7626 size_type size,
7627 const void* ptr,
7628 const vector<Event>* events = NULL,
7629 Event* event = NULL) const
7630 {
7631 cl_event tmp;
7632 cl_int err = detail::errHandler(
7633 ::clEnqueueWriteBuffer(
7634 object_, buffer(), blocking, offset, size,
7635 ptr,
7636 (events != NULL) ? (cl_uint) events->size() : 0,
7637 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7638 (event != NULL) ? &tmp : NULL),
7639 __ENQUEUE_WRITE_BUFFER_ERR);
7640
7641 if (event != NULL && err == CL_SUCCESS)
7642 *event = tmp;
7643
7644 return err;
7645 }
7646
7647 cl_int enqueueCopyBuffer(
7648 const Buffer& src,
7649 const Buffer& dst,
7650 size_type src_offset,
7651 size_type dst_offset,
7652 size_type size,
7653 const vector<Event>* events = NULL,
7654 Event* event = NULL) const
7655 {
7656 cl_event tmp;
7657 cl_int err = detail::errHandler(
7658 ::clEnqueueCopyBuffer(
7659 object_, src(), dst(), src_offset, dst_offset, size,
7660 (events != NULL) ? (cl_uint) events->size() : 0,
7661 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7662 (event != NULL) ? &tmp : NULL),
7663 __ENQEUE_COPY_BUFFER_ERR);
7664
7665 if (event != NULL && err == CL_SUCCESS)
7666 *event = tmp;
7667
7668 return err;
7669 }
7670 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
7671 cl_int enqueueReadBufferRect(
7672 const Buffer& buffer,
7673 cl_bool blocking,
7674 const array<size_type, 3>& buffer_offset,
7675 const array<size_type, 3>& host_offset,
7676 const array<size_type, 3>& region,
7677 size_type buffer_row_pitch,
7678 size_type buffer_slice_pitch,
7679 size_type host_row_pitch,
7680 size_type host_slice_pitch,
7681 void *ptr,
7682 const vector<Event>* events = NULL,
7683 Event* event = NULL) const
7684 {
7685 cl_event tmp;
7686 cl_int err = detail::errHandler(
7687 ::clEnqueueReadBufferRect(
7688 object_,
7689 buffer(),
7690 blocking,
7691 buffer_offset.data(),
7692 host_offset.data(),
7693 region.data(),
7694 buffer_row_pitch,
7695 buffer_slice_pitch,
7696 host_row_pitch,
7697 host_slice_pitch,
7698 ptr,
7699 (events != NULL) ? (cl_uint) events->size() : 0,
7700 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7701 (event != NULL) ? &tmp : NULL),
7702 __ENQUEUE_READ_BUFFER_RECT_ERR);
7703
7704 if (event != NULL && err == CL_SUCCESS)
7705 *event = tmp;
7706
7707 return err;
7708 }
7709
7710 cl_int enqueueWriteBufferRect(
7711 const Buffer& buffer,
7712 cl_bool blocking,
7713 const array<size_type, 3>& buffer_offset,
7714 const array<size_type, 3>& host_offset,
7715 const array<size_type, 3>& region,
7716 size_type buffer_row_pitch,
7717 size_type buffer_slice_pitch,
7718 size_type host_row_pitch,
7719 size_type host_slice_pitch,
7720 const void *ptr,
7721 const vector<Event>* events = NULL,
7722 Event* event = NULL) const
7723 {
7724 cl_event tmp;
7725 cl_int err = detail::errHandler(
7726 ::clEnqueueWriteBufferRect(
7727 object_,
7728 buffer(),
7729 blocking,
7730 buffer_offset.data(),
7731 host_offset.data(),
7732 region.data(),
7733 buffer_row_pitch,
7734 buffer_slice_pitch,
7735 host_row_pitch,
7736 host_slice_pitch,
7737 ptr,
7738 (events != NULL) ? (cl_uint) events->size() : 0,
7739 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7740 (event != NULL) ? &tmp : NULL),
7741 __ENQUEUE_WRITE_BUFFER_RECT_ERR);
7742
7743 if (event != NULL && err == CL_SUCCESS)
7744 *event = tmp;
7745
7746 return err;
7747 }
7748
7749 cl_int enqueueCopyBufferRect(
7750 const Buffer& src,
7751 const Buffer& dst,
7752 const array<size_type, 3>& src_origin,
7753 const array<size_type, 3>& dst_origin,
7754 const array<size_type, 3>& region,
7755 size_type src_row_pitch,
7756 size_type src_slice_pitch,
7757 size_type dst_row_pitch,
7758 size_type dst_slice_pitch,
7759 const vector<Event>* events = NULL,
7760 Event* event = NULL) const
7761 {
7762 cl_event tmp;
7763 cl_int err = detail::errHandler(
7764 ::clEnqueueCopyBufferRect(
7765 object_,
7766 src(),
7767 dst(),
7768 src_origin.data(),
7769 dst_origin.data(),
7770 region.data(),
7771 src_row_pitch,
7772 src_slice_pitch,
7773 dst_row_pitch,
7774 dst_slice_pitch,
7775 (events != NULL) ? (cl_uint) events->size() : 0,
7776 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7777 (event != NULL) ? &tmp : NULL),
7778 __ENQEUE_COPY_BUFFER_RECT_ERR);
7779
7780 if (event != NULL && err == CL_SUCCESS)
7781 *event = tmp;
7782
7783 return err;
7784 }
7785 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
7786 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
7787
7798 template<typename PatternType>
7799 cl_int enqueueFillBuffer(
7800 const Buffer& buffer,
7801 PatternType pattern,
7802 size_type offset,
7803 size_type size,
7804 const vector<Event>* events = NULL,
7805 Event* event = NULL) const
7806 {
7807 cl_event tmp;
7808 cl_int err = detail::errHandler(
7809 ::clEnqueueFillBuffer(
7810 object_,
7811 buffer(),
7812 static_cast<void*>(&pattern),
7813 sizeof(PatternType),
7814 offset,
7815 size,
7816 (events != NULL) ? (cl_uint) events->size() : 0,
7817 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7818 (event != NULL) ? &tmp : NULL),
7819 __ENQUEUE_FILL_BUFFER_ERR);
7820
7821 if (event != NULL && err == CL_SUCCESS)
7822 *event = tmp;
7823
7824 return err;
7825 }
7826 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7827
7828 cl_int enqueueReadImage(
7829 const Image& image,
7830 cl_bool blocking,
7831 const array<size_type, 3>& origin,
7832 const array<size_type, 3>& region,
7833 size_type row_pitch,
7834 size_type slice_pitch,
7835 void* ptr,
7836 const vector<Event>* events = NULL,
7837 Event* event = NULL) const
7838 {
7839 cl_event tmp;
7840 cl_int err = detail::errHandler(
7841 ::clEnqueueReadImage(
7842 object_,
7843 image(),
7844 blocking,
7845 origin.data(),
7846 region.data(),
7847 row_pitch,
7848 slice_pitch,
7849 ptr,
7850 (events != NULL) ? (cl_uint) events->size() : 0,
7851 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7852 (event != NULL) ? &tmp : NULL),
7853 __ENQUEUE_READ_IMAGE_ERR);
7854
7855 if (event != NULL && err == CL_SUCCESS)
7856 *event = tmp;
7857
7858 return err;
7859 }
7860
7861 cl_int enqueueWriteImage(
7862 const Image& image,
7863 cl_bool blocking,
7864 const array<size_type, 3>& origin,
7865 const array<size_type, 3>& region,
7866 size_type row_pitch,
7867 size_type slice_pitch,
7868 const void* ptr,
7869 const vector<Event>* events = NULL,
7870 Event* event = NULL) const
7871 {
7872 cl_event tmp;
7873 cl_int err = detail::errHandler(
7874 ::clEnqueueWriteImage(
7875 object_,
7876 image(),
7877 blocking,
7878 origin.data(),
7879 region.data(),
7880 row_pitch,
7881 slice_pitch,
7882 ptr,
7883 (events != NULL) ? (cl_uint) events->size() : 0,
7884 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7885 (event != NULL) ? &tmp : NULL),
7886 __ENQUEUE_WRITE_IMAGE_ERR);
7887
7888 if (event != NULL && err == CL_SUCCESS)
7889 *event = tmp;
7890
7891 return err;
7892 }
7893
7894 cl_int enqueueCopyImage(
7895 const Image& src,
7896 const Image& dst,
7897 const array<size_type, 3>& src_origin,
7898 const array<size_type, 3>& dst_origin,
7899 const array<size_type, 3>& region,
7900 const vector<Event>* events = NULL,
7901 Event* event = NULL) const
7902 {
7903 cl_event tmp;
7904 cl_int err = detail::errHandler(
7905 ::clEnqueueCopyImage(
7906 object_,
7907 src(),
7908 dst(),
7909 src_origin.data(),
7910 dst_origin.data(),
7911 region.data(),
7912 (events != NULL) ? (cl_uint) events->size() : 0,
7913 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7914 (event != NULL) ? &tmp : NULL),
7915 __ENQUEUE_COPY_IMAGE_ERR);
7916
7917 if (event != NULL && err == CL_SUCCESS)
7918 *event = tmp;
7919
7920 return err;
7921 }
7922
7923 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
7924
7931 cl_int enqueueFillImage(
7932 const Image& image,
7933 cl_float4 fillColor,
7934 const array<size_type, 3>& origin,
7935 const array<size_type, 3>& region,
7936 const vector<Event>* events = NULL,
7937 Event* event = NULL) const
7938 {
7939 cl_event tmp;
7940 cl_int err = detail::errHandler(
7941 ::clEnqueueFillImage(
7942 object_,
7943 image(),
7944 static_cast<void*>(&fillColor),
7945 origin.data(),
7946 region.data(),
7947 (events != NULL) ? (cl_uint) events->size() : 0,
7948 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7949 (event != NULL) ? &tmp : NULL),
7950 __ENQUEUE_FILL_IMAGE_ERR);
7951
7952 if (event != NULL && err == CL_SUCCESS)
7953 *event = tmp;
7954
7955 return err;
7956 }
7957
7965 cl_int enqueueFillImage(
7966 const Image& image,
7967 cl_int4 fillColor,
7968 const array<size_type, 3>& origin,
7969 const array<size_type, 3>& region,
7970 const vector<Event>* events = NULL,
7971 Event* event = NULL) const
7972 {
7973 cl_event tmp;
7974 cl_int err = detail::errHandler(
7975 ::clEnqueueFillImage(
7976 object_,
7977 image(),
7978 static_cast<void*>(&fillColor),
7979 origin.data(),
7980 region.data(),
7981 (events != NULL) ? (cl_uint) events->size() : 0,
7982 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7983 (event != NULL) ? &tmp : NULL),
7984 __ENQUEUE_FILL_IMAGE_ERR);
7985
7986 if (event != NULL && err == CL_SUCCESS)
7987 *event = tmp;
7988
7989 return err;
7990 }
7991
7999 cl_int enqueueFillImage(
8000 const Image& image,
8001 cl_uint4 fillColor,
8002 const array<size_type, 3>& origin,
8003 const array<size_type, 3>& region,
8004 const vector<Event>* events = NULL,
8005 Event* event = NULL) const
8006 {
8007 cl_event tmp;
8008 cl_int err = detail::errHandler(
8009 ::clEnqueueFillImage(
8010 object_,
8011 image(),
8012 static_cast<void*>(&fillColor),
8013 origin.data(),
8014 region.data(),
8015 (events != NULL) ? (cl_uint) events->size() : 0,
8016 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8017 (event != NULL) ? &tmp : NULL),
8018 __ENQUEUE_FILL_IMAGE_ERR);
8019
8020 if (event != NULL && err == CL_SUCCESS)
8021 *event = tmp;
8022
8023 return err;
8024 }
8025 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8026
8027 cl_int enqueueCopyImageToBuffer(
8028 const Image& src,
8029 const Buffer& dst,
8030 const array<size_type, 3>& src_origin,
8031 const array<size_type, 3>& region,
8032 size_type dst_offset,
8033 const vector<Event>* events = NULL,
8034 Event* event = NULL) const
8035 {
8036 cl_event tmp;
8037 cl_int err = detail::errHandler(
8038 ::clEnqueueCopyImageToBuffer(
8039 object_,
8040 src(),
8041 dst(),
8042 src_origin.data(),
8043 region.data(),
8044 dst_offset,
8045 (events != NULL) ? (cl_uint) events->size() : 0,
8046 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8047 (event != NULL) ? &tmp : NULL),
8048 __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
8049
8050 if (event != NULL && err == CL_SUCCESS)
8051 *event = tmp;
8052
8053 return err;
8054 }
8055
8056 cl_int enqueueCopyBufferToImage(
8057 const Buffer& src,
8058 const Image& dst,
8059 size_type src_offset,
8060 const array<size_type, 3>& dst_origin,
8061 const array<size_type, 3>& region,
8062 const vector<Event>* events = NULL,
8063 Event* event = NULL) const
8064 {
8065 cl_event tmp;
8066 cl_int err = detail::errHandler(
8067 ::clEnqueueCopyBufferToImage(
8068 object_,
8069 src(),
8070 dst(),
8071 src_offset,
8072 dst_origin.data(),
8073 region.data(),
8074 (events != NULL) ? (cl_uint) events->size() : 0,
8075 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8076 (event != NULL) ? &tmp : NULL),
8077 __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
8078
8079 if (event != NULL && err == CL_SUCCESS)
8080 *event = tmp;
8081
8082 return err;
8083 }
8084
8085 void* enqueueMapBuffer(
8086 const Buffer& buffer,
8087 cl_bool blocking,
8088 cl_map_flags flags,
8089 size_type offset,
8090 size_type size,
8091 const vector<Event>* events = NULL,
8092 Event* event = NULL,
8093 cl_int* err = NULL) const
8094 {
8095 cl_event tmp;
8096 cl_int error;
8097 void * result = ::clEnqueueMapBuffer(
8098 object_, buffer(), blocking, flags, offset, size,
8099 (events != NULL) ? (cl_uint) events->size() : 0,
8100 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8101 (event != NULL) ? &tmp : NULL,
8102 &error);
8103
8104 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
8105 if (err != NULL) {
8106 *err = error;
8107 }
8108 if (event != NULL && error == CL_SUCCESS)
8109 *event = tmp;
8110
8111 return result;
8112 }
8113
8114 void* enqueueMapImage(
8115 const Image& buffer,
8116 cl_bool blocking,
8117 cl_map_flags flags,
8118 const array<size_type, 3>& origin,
8119 const array<size_type, 3>& region,
8120 size_type * row_pitch,
8121 size_type * slice_pitch,
8122 const vector<Event>* events = NULL,
8123 Event* event = NULL,
8124 cl_int* err = NULL) const
8125 {
8126 cl_event tmp;
8127 cl_int error;
8128 void * result = ::clEnqueueMapImage(
8129 object_, buffer(), blocking, flags,
8130 origin.data(),
8131 region.data(),
8132 row_pitch, slice_pitch,
8133 (events != NULL) ? (cl_uint) events->size() : 0,
8134 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8135 (event != NULL) ? &tmp : NULL,
8136 &error);
8137
8138 detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
8139 if (err != NULL) {
8140 *err = error;
8141 }
8142 if (event != NULL && error == CL_SUCCESS)
8143 *event = tmp;
8144 return result;
8145 }
8146
8147 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8148
8152 template<typename T>
8153 cl_int enqueueMapSVM(
8154 T* ptr,
8155 cl_bool blocking,
8156 cl_map_flags flags,
8157 size_type size,
8158 const vector<Event>* events = NULL,
8159 Event* event = NULL) const
8160 {
8161 cl_event tmp;
8162 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8163 object_, blocking, flags, static_cast<void*>(ptr), size,
8164 (events != NULL) ? (cl_uint)events->size() : 0,
8165 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8166 (event != NULL) ? &tmp : NULL),
8167 __ENQUEUE_MAP_BUFFER_ERR);
8168
8169 if (event != NULL && err == CL_SUCCESS)
8170 *event = tmp;
8171
8172 return err;
8173 }
8174
8175
8180 template<typename T, class D>
8181 cl_int enqueueMapSVM(
8182 cl::pointer<T, D> &ptr,
8183 cl_bool blocking,
8184 cl_map_flags flags,
8185 size_type size,
8186 const vector<Event>* events = NULL,
8187 Event* event = NULL) const
8188 {
8189 cl_event tmp;
8190 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8191 object_, blocking, flags, static_cast<void*>(ptr.get()), size,
8192 (events != NULL) ? (cl_uint)events->size() : 0,
8193 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8194 (event != NULL) ? &tmp : NULL),
8195 __ENQUEUE_MAP_BUFFER_ERR);
8196
8197 if (event != NULL && err == CL_SUCCESS)
8198 *event = tmp;
8199
8200 return err;
8201 }
8202
8207 template<typename T, class Alloc>
8208 cl_int enqueueMapSVM(
8209 cl::vector<T, Alloc> &container,
8210 cl_bool blocking,
8211 cl_map_flags flags,
8212 const vector<Event>* events = NULL,
8213 Event* event = NULL) const
8214 {
8215 cl_event tmp;
8216 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8217 object_, blocking, flags, static_cast<void*>(container.data()), container.size()*sizeof(T),
8218 (events != NULL) ? (cl_uint)events->size() : 0,
8219 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8220 (event != NULL) ? &tmp : NULL),
8221 __ENQUEUE_MAP_BUFFER_ERR);
8222
8223 if (event != NULL && err == CL_SUCCESS)
8224 *event = tmp;
8225
8226 return err;
8227 }
8228 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8229
8230 cl_int enqueueUnmapMemObject(
8231 const Memory& memory,
8232 void* mapped_ptr,
8233 const vector<Event>* events = NULL,
8234 Event* event = NULL) const
8235 {
8236 cl_event tmp;
8237 cl_int err = detail::errHandler(
8238 ::clEnqueueUnmapMemObject(
8239 object_, memory(), mapped_ptr,
8240 (events != NULL) ? (cl_uint) events->size() : 0,
8241 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8242 (event != NULL) ? &tmp : NULL),
8243 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8244
8245 if (event != NULL && err == CL_SUCCESS)
8246 *event = tmp;
8247
8248 return err;
8249 }
8250
8251
8252 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8253
8257 template<typename T>
8258 cl_int enqueueUnmapSVM(
8259 T* ptr,
8260 const vector<Event>* events = NULL,
8261 Event* event = NULL) const
8262 {
8263 cl_event tmp;
8264 cl_int err = detail::errHandler(
8265 ::clEnqueueSVMUnmap(
8266 object_, static_cast<void*>(ptr),
8267 (events != NULL) ? (cl_uint)events->size() : 0,
8268 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8269 (event != NULL) ? &tmp : NULL),
8270 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8271
8272 if (event != NULL && err == CL_SUCCESS)
8273 *event = tmp;
8274
8275 return err;
8276 }
8277
8282 template<typename T, class D>
8283 cl_int enqueueUnmapSVM(
8284 cl::pointer<T, D> &ptr,
8285 const vector<Event>* events = NULL,
8286 Event* event = NULL) const
8287 {
8288 cl_event tmp;
8289 cl_int err = detail::errHandler(
8290 ::clEnqueueSVMUnmap(
8291 object_, static_cast<void*>(ptr.get()),
8292 (events != NULL) ? (cl_uint)events->size() : 0,
8293 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8294 (event != NULL) ? &tmp : NULL),
8295 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8296
8297 if (event != NULL && err == CL_SUCCESS)
8298 *event = tmp;
8299
8300 return err;
8301 }
8302
8307 template<typename T, class Alloc>
8308 cl_int enqueueUnmapSVM(
8309 cl::vector<T, Alloc> &container,
8310 const vector<Event>* events = NULL,
8311 Event* event = NULL) const
8312 {
8313 cl_event tmp;
8314 cl_int err = detail::errHandler(
8315 ::clEnqueueSVMUnmap(
8316 object_, static_cast<void*>(container.data()),
8317 (events != NULL) ? (cl_uint)events->size() : 0,
8318 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8319 (event != NULL) ? &tmp : NULL),
8320 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8321
8322 if (event != NULL && err == CL_SUCCESS)
8323 *event = tmp;
8324
8325 return err;
8326 }
8327 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8328
8329 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8330
8341 cl_int enqueueMarkerWithWaitList(
8342 const vector<Event> *events = 0,
8343 Event *event = 0) const
8344 {
8345 cl_event tmp;
8346 cl_int err = detail::errHandler(
8347 ::clEnqueueMarkerWithWaitList(
8348 object_,
8349 (events != NULL) ? (cl_uint) events->size() : 0,
8350 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8351 (event != NULL) ? &tmp : NULL),
8352 __ENQUEUE_MARKER_WAIT_LIST_ERR);
8353
8354 if (event != NULL && err == CL_SUCCESS)
8355 *event = tmp;
8356
8357 return err;
8358 }
8359
8371 cl_int enqueueBarrierWithWaitList(
8372 const vector<Event> *events = 0,
8373 Event *event = 0) const
8374 {
8375 cl_event tmp;
8376 cl_int err = detail::errHandler(
8377 ::clEnqueueBarrierWithWaitList(
8378 object_,
8379 (events != NULL) ? (cl_uint) events->size() : 0,
8380 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8381 (event != NULL) ? &tmp : NULL),
8382 __ENQUEUE_BARRIER_WAIT_LIST_ERR);
8383
8384 if (event != NULL && err == CL_SUCCESS)
8385 *event = tmp;
8386
8387 return err;
8388 }
8389
8394 cl_int enqueueMigrateMemObjects(
8395 const vector<Memory> &memObjects,
8396 cl_mem_migration_flags flags,
8397 const vector<Event>* events = NULL,
8398 Event* event = NULL
8399 ) const
8400 {
8401 cl_event tmp;
8402
8403 vector<cl_mem> localMemObjects(memObjects.size());
8404
8405 for( int i = 0; i < (int)memObjects.size(); ++i ) {
8406 localMemObjects[i] = memObjects[i]();
8407 }
8408
8409 cl_int err = detail::errHandler(
8410 ::clEnqueueMigrateMemObjects(
8411 object_,
8412 (cl_uint)memObjects.size(),
8413 localMemObjects.data(),
8414 flags,
8415 (events != NULL) ? (cl_uint) events->size() : 0,
8416 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8417 (event != NULL) ? &tmp : NULL),
8418 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8419
8420 if (event != NULL && err == CL_SUCCESS)
8421 *event = tmp;
8422
8423 return err;
8424 }
8425 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8426
8427
8428 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8429
8434 template<typename T>
8435 cl_int enqueueMigrateSVM(
8436 const cl::vector<T*> &svmRawPointers,
8437 const cl::vector<size_type> &sizes,
8438 cl_mem_migration_flags flags = 0,
8439 const vector<Event>* events = NULL,
8440 Event* event = NULL) const
8441 {
8442 cl_event tmp;
8443 cl_int err = detail::errHandler(::clEnqueueSVMMigrateMem(
8444 object_,
8445 svmRawPointers.size(), static_cast<void**>(svmRawPointers.data()),
8446 sizes.data(), // array of sizes not passed
8447 flags,
8448 (events != NULL) ? (cl_uint)events->size() : 0,
8449 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8450 (event != NULL) ? &tmp : NULL),
8451 __ENQUEUE_MIGRATE_SVM_ERR);
8452
8453 if (event != NULL && err == CL_SUCCESS)
8454 *event = tmp;
8455
8456 return err;
8457 }
8458
8463 template<typename T>
8464 cl_int enqueueMigrateSVM(
8465 const cl::vector<T*> &svmRawPointers,
8466 cl_mem_migration_flags flags = 0,
8467 const vector<Event>* events = NULL,
8468 Event* event = NULL) const
8469 {
8470 return enqueueMigrateSVM(svmRawPointers, cl::vector<size_type>(svmRawPointers.size()), flags, events, event);
8471 }
8472
8473
8479 template<typename T, class D>
8480 cl_int enqueueMigrateSVM(
8481 const cl::vector<cl::pointer<T, D>> &svmPointers,
8482 const cl::vector<size_type> &sizes,
8483 cl_mem_migration_flags flags = 0,
8484 const vector<Event>* events = NULL,
8485 Event* event = NULL) const
8486 {
8487 cl::vector<void*> svmRawPointers;
8488 svmRawPointers.reserve(svmPointers.size());
8489 for (auto p : svmPointers) {
8490 svmRawPointers.push_back(static_cast<void*>(p.get()));
8491 }
8492
8493 return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
8494 }
8495
8496
8501 template<typename T, class D>
8502 cl_int enqueueMigrateSVM(
8503 const cl::vector<cl::pointer<T, D>> &svmPointers,
8504 cl_mem_migration_flags flags = 0,
8505 const vector<Event>* events = NULL,
8506 Event* event = NULL) const
8507 {
8508 return enqueueMigrateSVM(svmPointers, cl::vector<size_type>(svmPointers.size()), flags, events, event);
8509 }
8510
8516 template<typename T, class Alloc>
8517 cl_int enqueueMigrateSVM(
8518 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8519 const cl::vector<size_type> &sizes,
8520 cl_mem_migration_flags flags = 0,
8521 const vector<Event>* events = NULL,
8522 Event* event = NULL) const
8523 {
8524 cl::vector<void*> svmRawPointers;
8525 svmRawPointers.reserve(svmContainers.size());
8526 for (auto p : svmContainers) {
8527 svmRawPointers.push_back(static_cast<void*>(p.data()));
8528 }
8529
8530 return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
8531 }
8532
8537 template<typename T, class Alloc>
8538 cl_int enqueueMigrateSVM(
8539 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8540 cl_mem_migration_flags flags = 0,
8541 const vector<Event>* events = NULL,
8542 Event* event = NULL) const
8543 {
8544 return enqueueMigrateSVM(svmContainers, cl::vector<size_type>(svmContainers.size()), flags, events, event);
8545 }
8546
8547 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8548
8549 cl_int enqueueNDRangeKernel(
8550 const Kernel& kernel,
8551 const NDRange& offset,
8552 const NDRange& global,
8553 const NDRange& local = NullRange,
8554 const vector<Event>* events = NULL,
8555 Event* event = NULL) const
8556 {
8557 cl_event tmp;
8558 cl_int err = detail::errHandler(
8559 ::clEnqueueNDRangeKernel(
8560 object_, kernel(), (cl_uint) global.dimensions(),
8561 offset.dimensions() != 0 ? (const size_type*) offset : NULL,
8562 (const size_type*) global,
8563 local.dimensions() != 0 ? (const size_type*) local : NULL,
8564 (events != NULL) ? (cl_uint) events->size() : 0,
8565 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8566 (event != NULL) ? &tmp : NULL),
8567 __ENQUEUE_NDRANGE_KERNEL_ERR);
8568
8569 if (event != NULL && err == CL_SUCCESS)
8570 *event = tmp;
8571
8572 return err;
8573 }
8574
8575 #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8576 CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_int enqueueTask(
8577 const Kernel& kernel,
8578 const vector<Event>* events = NULL,
8579 Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED
8580 {
8581 cl_event tmp;
8582 cl_int err = detail::errHandler(
8583 ::clEnqueueTask(
8584 object_, kernel(),
8585 (events != NULL) ? (cl_uint) events->size() : 0,
8586 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8587 (event != NULL) ? &tmp : NULL),
8588 __ENQUEUE_TASK_ERR);
8589
8590 if (event != NULL && err == CL_SUCCESS)
8591 *event = tmp;
8592
8593 return err;
8594 }
8595 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8596
8597 cl_int enqueueNativeKernel(
8598 void (CL_CALLBACK *userFptr)(void *),
8599 std::pair<void*, size_type> args,
8600 const vector<Memory>* mem_objects = NULL,
8601 const vector<const void*>* mem_locs = NULL,
8602 const vector<Event>* events = NULL,
8603 Event* event = NULL) const
8604 {
8605 size_type elements = 0;
8606 if (mem_objects != NULL) {
8607 elements = mem_objects->size();
8608 }
8609 vector<cl_mem> mems(elements);
8610 for (unsigned int i = 0; i < elements; i++) {
8611 mems[i] = ((*mem_objects)[i])();
8612 }
8613
8614 cl_event tmp;
8615 cl_int err = detail::errHandler(
8616 ::clEnqueueNativeKernel(
8617 object_, userFptr, args.first, args.second,
8618 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8619 mems.data(),
8620 (mem_locs != NULL && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : NULL,
8621 (events != NULL) ? (cl_uint) events->size() : 0,
8622 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8623 (event != NULL) ? &tmp : NULL),
8624 __ENQUEUE_NATIVE_KERNEL);
8625
8626 if (event != NULL && err == CL_SUCCESS)
8627 *event = tmp;
8628
8629 return err;
8630 }
8631
8635 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8636 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
8637 cl_int enqueueMarker(Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
8638 {
8639 cl_event tmp;
8640 cl_int err = detail::errHandler(
8641 ::clEnqueueMarker(
8642 object_,
8643 (event != NULL) ? &tmp : NULL),
8644 __ENQUEUE_MARKER_ERR);
8645
8646 if (event != NULL && err == CL_SUCCESS)
8647 *event = tmp;
8648
8649 return err;
8650 }
8651
8652 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
8653 cl_int enqueueWaitForEvents(const vector<Event>& events) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
8654 {
8655 return detail::errHandler(
8656 ::clEnqueueWaitForEvents(
8657 object_,
8658 (cl_uint) events.size(),
8659 events.size() > 0 ? (const cl_event*) &events.front() : NULL),
8660 __ENQUEUE_WAIT_FOR_EVENTS_ERR);
8661 }
8662 #endif // defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8663
8664 cl_int enqueueAcquireGLObjects(
8665 const vector<Memory>* mem_objects = NULL,
8666 const vector<Event>* events = NULL,
8667 Event* event = NULL) const
8668 {
8669 cl_event tmp;
8670 cl_int err = detail::errHandler(
8671 ::clEnqueueAcquireGLObjects(
8672 object_,
8673 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8674 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8675 (events != NULL) ? (cl_uint) events->size() : 0,
8676 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8677 (event != NULL) ? &tmp : NULL),
8678 __ENQUEUE_ACQUIRE_GL_ERR);
8679
8680 if (event != NULL && err == CL_SUCCESS)
8681 *event = tmp;
8682
8683 return err;
8684 }
8685
8686 cl_int enqueueReleaseGLObjects(
8687 const vector<Memory>* mem_objects = NULL,
8688 const vector<Event>* events = NULL,
8689 Event* event = NULL) const
8690 {
8691 cl_event tmp;
8692 cl_int err = detail::errHandler(
8693 ::clEnqueueReleaseGLObjects(
8694 object_,
8695 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8696 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8697 (events != NULL) ? (cl_uint) events->size() : 0,
8698 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8699 (event != NULL) ? &tmp : NULL),
8700 __ENQUEUE_RELEASE_GL_ERR);
8701
8702 if (event != NULL && err == CL_SUCCESS)
8703 *event = tmp;
8704
8705 return err;
8706 }
8707
8708 #if defined (CL_HPP_USE_DX_INTEROP)
8709 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
8710 cl_command_queue command_queue, cl_uint num_objects,
8711 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8712 const cl_event* event_wait_list, cl_event* event);
8713 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
8714 cl_command_queue command_queue, cl_uint num_objects,
8715 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8716 const cl_event* event_wait_list, cl_event* event);
8717
8718 cl_int enqueueAcquireD3D10Objects(
8719 const vector<Memory>* mem_objects = NULL,
8720 const vector<Event>* events = NULL,
8721 Event* event = NULL) const
8722 {
8723 static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
8724 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8725 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8726 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8727 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8728 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireD3D10ObjectsKHR);
8729 #endif
8730 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
8731 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueAcquireD3D10ObjectsKHR);
8732 #endif
8733
8734 cl_event tmp;
8735 cl_int err = detail::errHandler(
8736 pfn_clEnqueueAcquireD3D10ObjectsKHR(
8737 object_,
8738 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8739 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8740 (events != NULL) ? (cl_uint) events->size() : 0,
8741 (events != NULL) ? (cl_event*) &events->front() : NULL,
8742 (event != NULL) ? &tmp : NULL),
8743 __ENQUEUE_ACQUIRE_GL_ERR);
8744
8745 if (event != NULL && err == CL_SUCCESS)
8746 *event = tmp;
8747
8748 return err;
8749 }
8750
8751 cl_int enqueueReleaseD3D10Objects(
8752 const vector<Memory>* mem_objects = NULL,
8753 const vector<Event>* events = NULL,
8754 Event* event = NULL) const
8755 {
8756 static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL;
8757 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8758 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8759 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8760 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8761 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseD3D10ObjectsKHR);
8762 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8763 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
8764 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueReleaseD3D10ObjectsKHR);
8765 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
8766
8767 cl_event tmp;
8768 cl_int err = detail::errHandler(
8769 pfn_clEnqueueReleaseD3D10ObjectsKHR(
8770 object_,
8771 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8772 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8773 (events != NULL) ? (cl_uint) events->size() : 0,
8774 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8775 (event != NULL) ? &tmp : NULL),
8776 __ENQUEUE_RELEASE_GL_ERR);
8777
8778 if (event != NULL && err == CL_SUCCESS)
8779 *event = tmp;
8780
8781 return err;
8782 }
8783 #endif
8784
8788 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8789 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
8790 cl_int enqueueBarrier() const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
8791 {
8792 return detail::errHandler(
8793 ::clEnqueueBarrier(object_),
8794 __ENQUEUE_BARRIER_ERR);
8795 }
8796 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
8797
8798 cl_int flush() const
8799 {
8800 return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
8801 }
8802
8803 cl_int finish() const
8804 {
8805 return detail::errHandler(::clFinish(object_), __FINISH_ERR);
8806 }
8807 }; // CommandQueue
8808
8809 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::default_initialized_;
8810 CL_HPP_DEFINE_STATIC_MEMBER_ CommandQueue CommandQueue::default_;
8811 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int CommandQueue::default_error_ = CL_SUCCESS;
8812
8813
8814 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8815 enum class DeviceQueueProperties : cl_command_queue_properties
8816 {
8817 None = 0,
8818 Profiling = CL_QUEUE_PROFILING_ENABLE,
8819 };
8820
8821 inline DeviceQueueProperties operator|(DeviceQueueProperties lhs, DeviceQueueProperties rhs)
8822 {
8823 return static_cast<DeviceQueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
8824 }
8825
8829 class DeviceCommandQueue : public detail::Wrapper<cl_command_queue>
8830 {
8831 public:
8832
8836 DeviceCommandQueue() { }
8837
8841 DeviceCommandQueue(DeviceQueueProperties properties, cl_int* err = NULL)
8842 {
8843 cl_int error;
8844 cl::Context context = cl::Context::getDefault();
8845 cl::Device device = cl::Device::getDefault();
8846
8847 cl_command_queue_properties mergedProperties =
8848 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8849
8850 cl_queue_properties queue_properties[] = {
8851 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8852 object_ = ::clCreateCommandQueueWithProperties(
8853 context(), device(), queue_properties, &error);
8854
8855 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8856 if (err != NULL) {
8857 *err = error;
8858 }
8859 }
8860
8864 DeviceCommandQueue(
8865 const Context& context,
8866 const Device& device,
8867 DeviceQueueProperties properties = DeviceQueueProperties::None,
8868 cl_int* err = NULL)
8869 {
8870 cl_int error;
8871
8872 cl_command_queue_properties mergedProperties =
8873 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8874 cl_queue_properties queue_properties[] = {
8875 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8876 object_ = ::clCreateCommandQueueWithProperties(
8877 context(), device(), queue_properties, &error);
8878
8879 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8880 if (err != NULL) {
8881 *err = error;
8882 }
8883 }
8884
8888 DeviceCommandQueue(
8889 const Context& context,
8890 const Device& device,
8891 cl_uint queueSize,
8892 DeviceQueueProperties properties = DeviceQueueProperties::None,
8893 cl_int* err = NULL)
8894 {
8895 cl_int error;
8896
8897 cl_command_queue_properties mergedProperties =
8898 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8899 cl_queue_properties queue_properties[] = {
8900 CL_QUEUE_PROPERTIES, mergedProperties,
8901 CL_QUEUE_SIZE, queueSize,
8902 0 };
8903 object_ = ::clCreateCommandQueueWithProperties(
8904 context(), device(), queue_properties, &error);
8905
8906 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8907 if (err != NULL) {
8908 *err = error;
8909 }
8910 }
8911
8918 explicit DeviceCommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
8919 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
8920
8921 DeviceCommandQueue& operator = (const cl_command_queue& rhs)
8922 {
8923 detail::Wrapper<cl_type>::operator=(rhs);
8924 return *this;
8925 }
8926
8930 DeviceCommandQueue(const DeviceCommandQueue& queue) : detail::Wrapper<cl_type>(queue) {}
8931
8935 DeviceCommandQueue& operator = (const DeviceCommandQueue &queue)
8936 {
8937 detail::Wrapper<cl_type>::operator=(queue);
8938 return *this;
8939 }
8940
8944 DeviceCommandQueue(DeviceCommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(queue)) {}
8945
8949 DeviceCommandQueue& operator = (DeviceCommandQueue &&queue)
8950 {
8951 detail::Wrapper<cl_type>::operator=(std::move(queue));
8952 return *this;
8953 }
8954
8955 template <typename T>
8956 cl_int getInfo(cl_command_queue_info name, T* param) const
8957 {
8958 return detail::errHandler(
8959 detail::getInfo(
8960 &::clGetCommandQueueInfo, object_, name, param),
8961 __GET_COMMAND_QUEUE_INFO_ERR);
8962 }
8963
8964 template <cl_command_queue_info name> typename
8965 detail::param_traits<detail::cl_command_queue_info, name>::param_type
8966 getInfo(cl_int* err = NULL) const
8967 {
8968 typename detail::param_traits<
8969 detail::cl_command_queue_info, name>::param_type param;
8970 cl_int result = getInfo(name, &param);
8971 if (err != NULL) {
8972 *err = result;
8973 }
8974 return param;
8975 }
8976
8983 static DeviceCommandQueue makeDefault(
8984 cl_int *err = nullptr)
8985 {
8986 cl_int error;
8987 cl::Context context = cl::Context::getDefault();
8988 cl::Device device = cl::Device::getDefault();
8989
8990 cl_command_queue_properties properties =
8991 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
8992 cl_queue_properties queue_properties[] = {
8993 CL_QUEUE_PROPERTIES, properties,
8994 0 };
8995 DeviceCommandQueue deviceQueue(
8996 ::clCreateCommandQueueWithProperties(
8997 context(), device(), queue_properties, &error));
8998
8999 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9000 if (err != NULL) {
9001 *err = error;
9002 }
9003
9004 return deviceQueue;
9005 }
9006
9013 static DeviceCommandQueue makeDefault(
9014 const Context &context, const Device &device, cl_int *err = nullptr)
9015 {
9016 cl_int error;
9017
9018 cl_command_queue_properties properties =
9019 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9020 cl_queue_properties queue_properties[] = {
9021 CL_QUEUE_PROPERTIES, properties,
9022 0 };
9023 DeviceCommandQueue deviceQueue(
9024 ::clCreateCommandQueueWithProperties(
9025 context(), device(), queue_properties, &error));
9026
9027 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9028 if (err != NULL) {
9029 *err = error;
9030 }
9031
9032 return deviceQueue;
9033 }
9034
9041 static DeviceCommandQueue makeDefault(
9042 const Context &context, const Device &device, cl_uint queueSize, cl_int *err = nullptr)
9043 {
9044 cl_int error;
9045
9046 cl_command_queue_properties properties =
9047 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9048 cl_queue_properties queue_properties[] = {
9049 CL_QUEUE_PROPERTIES, properties,
9050 CL_QUEUE_SIZE, queueSize,
9051 0 };
9052 DeviceCommandQueue deviceQueue(
9053 ::clCreateCommandQueueWithProperties(
9054 context(), device(), queue_properties, &error));
9055
9056 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9057 if (err != NULL) {
9058 *err = error;
9059 }
9060
9061 return deviceQueue;
9062 }
9063
9064
9065
9066 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
9067
9073 static DeviceCommandQueue updateDefault(const Context &context, const Device &device, const DeviceCommandQueue &default_queue, cl_int *err = nullptr)
9074 {
9075 cl_int error;
9076 error = clSetDefaultDeviceCommandQueue(context.get(), device.get(), default_queue.get());
9077
9078 detail::errHandler(error, __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR);
9079 if (err != NULL) {
9080 *err = error;
9081 }
9082 return default_queue;
9083 }
9084
9088 static DeviceCommandQueue getDefault(const CommandQueue &queue, cl_int * err = NULL)
9089 {
9090 return queue.getInfo<CL_QUEUE_DEVICE_DEFAULT>(err);
9091 }
9092
9093 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
9094 }; // DeviceCommandQueue
9095
9096 namespace detail
9097 {
9098 // Specialization for device command queue
9099 template <>
9100 struct KernelArgumentHandler<cl::DeviceCommandQueue, void>
9101 {
9102 static size_type size(const cl::DeviceCommandQueue&) { return sizeof(cl_command_queue); }
9103 static const cl_command_queue* ptr(const cl::DeviceCommandQueue& value) { return &(value()); }
9104 };
9105 } // namespace detail
9106
9107 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9108
9109
9110 template< typename IteratorType >
9111 Buffer::Buffer(
9112 const Context &context,
9113 IteratorType startIterator,
9114 IteratorType endIterator,
9115 bool readOnly,
9116 bool useHostPtr,
9117 cl_int* err)
9118 {
9119 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9120 cl_int error;
9121
9122 cl_mem_flags flags = 0;
9123 if( readOnly ) {
9124 flags |= CL_MEM_READ_ONLY;
9125 }
9126 else {
9127 flags |= CL_MEM_READ_WRITE;
9128 }
9129 if( useHostPtr ) {
9130 flags |= CL_MEM_USE_HOST_PTR;
9131 }
9132
9133 size_type size = sizeof(DataType)*(endIterator - startIterator);
9134
9135 if( useHostPtr ) {
9136 object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
9137 } else {
9138 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9139 }
9140
9141 detail::errHandler(error, __CREATE_BUFFER_ERR);
9142 if (err != NULL) {
9143 *err = error;
9144 }
9145
9146 if( !useHostPtr ) {
9147 CommandQueue queue(context, 0, &error);
9148 detail::errHandler(error, __CREATE_BUFFER_ERR);
9149 if (err != NULL) {
9150 *err = error;
9151 }
9152
9153 error = cl::copy(queue, startIterator, endIterator, *this);
9154 detail::errHandler(error, __CREATE_BUFFER_ERR);
9155 if (err != NULL) {
9156 *err = error;
9157 }
9158 }
9159 }
9160
9161 template< typename IteratorType >
9162 Buffer::Buffer(
9163 const CommandQueue &queue,
9164 IteratorType startIterator,
9165 IteratorType endIterator,
9166 bool readOnly,
9167 bool useHostPtr,
9168 cl_int* err)
9169 {
9170 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9171 cl_int error;
9172
9173 cl_mem_flags flags = 0;
9174 if (readOnly) {
9175 flags |= CL_MEM_READ_ONLY;
9176 }
9177 else {
9178 flags |= CL_MEM_READ_WRITE;
9179 }
9180 if (useHostPtr) {
9181 flags |= CL_MEM_USE_HOST_PTR;
9182 }
9183
9184 size_type size = sizeof(DataType)*(endIterator - startIterator);
9185
9186 Context context = queue.getInfo<CL_QUEUE_CONTEXT>();
9187
9188 if (useHostPtr) {
9189 object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
9190 }
9191 else {
9192 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9193 }
9194
9195 detail::errHandler(error, __CREATE_BUFFER_ERR);
9196 if (err != NULL) {
9197 *err = error;
9198 }
9199
9200 if (!useHostPtr) {
9201 error = cl::copy(queue, startIterator, endIterator, *this);
9202 detail::errHandler(error, __CREATE_BUFFER_ERR);
9203 if (err != NULL) {
9204 *err = error;
9205 }
9206 }
9207 }
9208
9209 inline cl_int enqueueReadBuffer(
9210 const Buffer& buffer,
9211 cl_bool blocking,
9212 size_type offset,
9213 size_type size,
9214 void* ptr,
9215 const vector<Event>* events = NULL,
9216 Event* event = NULL)
9217 {
9218 cl_int error;
9219 CommandQueue queue = CommandQueue::getDefault(&error);
9220
9221 if (error != CL_SUCCESS) {
9222 return error;
9223 }
9224
9225 return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event);
9226 }
9227
9228 inline cl_int enqueueWriteBuffer(
9229 const Buffer& buffer,
9230 cl_bool blocking,
9231 size_type offset,
9232 size_type size,
9233 const void* ptr,
9234 const vector<Event>* events = NULL,
9235 Event* event = NULL)
9236 {
9237 cl_int error;
9238 CommandQueue queue = CommandQueue::getDefault(&error);
9239
9240 if (error != CL_SUCCESS) {
9241 return error;
9242 }
9243
9244 return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event);
9245 }
9246
9247 inline void* enqueueMapBuffer(
9248 const Buffer& buffer,
9249 cl_bool blocking,
9250 cl_map_flags flags,
9251 size_type offset,
9252 size_type size,
9253 const vector<Event>* events = NULL,
9254 Event* event = NULL,
9255 cl_int* err = NULL)
9256 {
9257 cl_int error;
9258 CommandQueue queue = CommandQueue::getDefault(&error);
9259 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9260 if (err != NULL) {
9261 *err = error;
9262 }
9263
9264 void * result = ::clEnqueueMapBuffer(
9265 queue(), buffer(), blocking, flags, offset, size,
9266 (events != NULL) ? (cl_uint) events->size() : 0,
9267 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
9268 (cl_event*) event,
9269 &error);
9270
9271 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9272 if (err != NULL) {
9273 *err = error;
9274 }
9275 return result;
9276 }
9277
9278
9279 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9280
9285 template<typename T>
9286 inline cl_int enqueueMapSVM(
9287 T* ptr,
9288 cl_bool blocking,
9289 cl_map_flags flags,
9290 size_type size,
9291 const vector<Event>* events,
9292 Event* event)
9293 {
9294 cl_int error;
9295 CommandQueue queue = CommandQueue::getDefault(&error);
9296 if (error != CL_SUCCESS) {
9297 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9298 }
9299
9300 return queue.enqueueMapSVM(
9301 ptr, blocking, flags, size, events, event);
9302 }
9303
9309 template<typename T, class D>
9310 inline cl_int enqueueMapSVM(
9311 cl::pointer<T, D> ptr,
9312 cl_bool blocking,
9313 cl_map_flags flags,
9314 size_type size,
9315 const vector<Event>* events = NULL,
9316 Event* event = NULL)
9317 {
9318 cl_int error;
9319 CommandQueue queue = CommandQueue::getDefault(&error);
9320 if (error != CL_SUCCESS) {
9321 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9322 }
9323
9324 return queue.enqueueMapSVM(
9325 ptr, blocking, flags, size, events, event);
9326 }
9327
9333 template<typename T, class Alloc>
9334 inline cl_int enqueueMapSVM(
9335 cl::vector<T, Alloc> container,
9336 cl_bool blocking,
9337 cl_map_flags flags,
9338 const vector<Event>* events = NULL,
9339 Event* event = NULL)
9340 {
9341 cl_int error;
9342 CommandQueue queue = CommandQueue::getDefault(&error);
9343 if (error != CL_SUCCESS) {
9344 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9345 }
9346
9347 return queue.enqueueMapSVM(
9348 container, blocking, flags, events, event);
9349 }
9350
9351 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9352
9353 inline cl_int enqueueUnmapMemObject(
9354 const Memory& memory,
9355 void* mapped_ptr,
9356 const vector<Event>* events = NULL,
9357 Event* event = NULL)
9358 {
9359 cl_int error;
9360 CommandQueue queue = CommandQueue::getDefault(&error);
9361 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9362 if (error != CL_SUCCESS) {
9363 return error;
9364 }
9365
9366 cl_event tmp;
9367 cl_int err = detail::errHandler(
9368 ::clEnqueueUnmapMemObject(
9369 queue(), memory(), mapped_ptr,
9370 (events != NULL) ? (cl_uint)events->size() : 0,
9371 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
9372 (event != NULL) ? &tmp : NULL),
9373 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9374
9375 if (event != NULL && err == CL_SUCCESS)
9376 *event = tmp;
9377
9378 return err;
9379 }
9380
9381 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9382
9387 template<typename T>
9388 inline cl_int enqueueUnmapSVM(
9389 T* ptr,
9390 const vector<Event>* events = NULL,
9391 Event* event = NULL)
9392 {
9393 cl_int error;
9394 CommandQueue queue = CommandQueue::getDefault(&error);
9395 if (error != CL_SUCCESS) {
9396 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9397 }
9398
9399 return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
9400 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9401
9402 }
9403
9409 template<typename T, class D>
9410 inline cl_int enqueueUnmapSVM(
9411 cl::pointer<T, D> &ptr,
9412 const vector<Event>* events = NULL,
9413 Event* event = NULL)
9414 {
9415 cl_int error;
9416 CommandQueue queue = CommandQueue::getDefault(&error);
9417 if (error != CL_SUCCESS) {
9418 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9419 }
9420
9421 return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
9422 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9423 }
9424
9430 template<typename T, class Alloc>
9431 inline cl_int enqueueUnmapSVM(
9432 cl::vector<T, Alloc> &container,
9433 const vector<Event>* events = NULL,
9434 Event* event = NULL)
9435 {
9436 cl_int error;
9437 CommandQueue queue = CommandQueue::getDefault(&error);
9438 if (error != CL_SUCCESS) {
9439 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9440 }
9441
9442 return detail::errHandler(queue.enqueueUnmapSVM(container, events, event),
9443 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9444 }
9445
9446 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9447
9448 inline cl_int enqueueCopyBuffer(
9449 const Buffer& src,
9450 const Buffer& dst,
9451 size_type src_offset,
9452 size_type dst_offset,
9453 size_type size,
9454 const vector<Event>* events = NULL,
9455 Event* event = NULL)
9456 {
9457 cl_int error;
9458 CommandQueue queue = CommandQueue::getDefault(&error);
9459
9460 if (error != CL_SUCCESS) {
9461 return error;
9462 }
9463
9464 return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event);
9465 }
9466
9472 template< typename IteratorType >
9473 inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
9474 {
9475 cl_int error;
9476 CommandQueue queue = CommandQueue::getDefault(&error);
9477 if (error != CL_SUCCESS)
9478 return error;
9479
9480 return cl::copy(queue, startIterator, endIterator, buffer);
9481 }
9482
9488 template< typename IteratorType >
9489 inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
9490 {
9491 cl_int error;
9492 CommandQueue queue = CommandQueue::getDefault(&error);
9493 if (error != CL_SUCCESS)
9494 return error;
9495
9496 return cl::copy(queue, buffer, startIterator, endIterator);
9497 }
9498
9504 template< typename IteratorType >
9505 inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
9506 {
9507 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9508 cl_int error;
9509
9510 size_type length = endIterator-startIterator;
9511 size_type byteLength = length*sizeof(DataType);
9512
9513 DataType *pointer =
9514 static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error));
9515 // if exceptions enabled, enqueueMapBuffer will throw
9516 if( error != CL_SUCCESS ) {
9517 return error;
9518 }
9519 #if defined(_MSC_VER)
9520 std::copy(
9521 startIterator,
9522 endIterator,
9523 stdext::checked_array_iterator<DataType*>(
9524 pointer, length));
9525 #else
9526 std::copy(startIterator, endIterator, pointer);
9527 #endif
9528 Event endEvent;
9529 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9530 // if exceptions enabled, enqueueUnmapMemObject will throw
9531 if( error != CL_SUCCESS ) {
9532 return error;
9533 }
9534 endEvent.wait();
9535 return CL_SUCCESS;
9536 }
9537
9543 template< typename IteratorType >
9544 inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
9545 {
9546 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9547 cl_int error;
9548
9549 size_type length = endIterator-startIterator;
9550 size_type byteLength = length*sizeof(DataType);
9551
9552 DataType *pointer =
9553 static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error));
9554 // if exceptions enabled, enqueueMapBuffer will throw
9555 if( error != CL_SUCCESS ) {
9556 return error;
9557 }
9558 std::copy(pointer, pointer + length, startIterator);
9559 Event endEvent;
9560 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9561 // if exceptions enabled, enqueueUnmapMemObject will throw
9562 if( error != CL_SUCCESS ) {
9563 return error;
9564 }
9565 endEvent.wait();
9566 return CL_SUCCESS;
9567 }
9568
9569
9570 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9571
9574 template<typename T, class Alloc>
9575 inline cl_int mapSVM(cl::vector<T, Alloc> &container)
9576 {
9577 return enqueueMapSVM(container, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE);
9578 }
9579
9583 template<typename T, class Alloc>
9584 inline cl_int unmapSVM(cl::vector<T, Alloc> &container)
9585 {
9586 return enqueueUnmapSVM(container);
9587 }
9588
9589 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9590
9591 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
9592 inline cl_int enqueueReadBufferRect(
9593 const Buffer& buffer,
9594 cl_bool blocking,
9595 const array<size_type, 3>& buffer_offset,
9596 const array<size_type, 3>& host_offset,
9597 const array<size_type, 3>& region,
9598 size_type buffer_row_pitch,
9599 size_type buffer_slice_pitch,
9600 size_type host_row_pitch,
9601 size_type host_slice_pitch,
9602 void *ptr,
9603 const vector<Event>* events = NULL,
9604 Event* event = NULL)
9605 {
9606 cl_int error;
9607 CommandQueue queue = CommandQueue::getDefault(&error);
9608
9609 if (error != CL_SUCCESS) {
9610 return error;
9611 }
9612
9613 return queue.enqueueReadBufferRect(
9614 buffer,
9615 blocking,
9616 buffer_offset,
9617 host_offset,
9618 region,
9619 buffer_row_pitch,
9620 buffer_slice_pitch,
9621 host_row_pitch,
9622 host_slice_pitch,
9623 ptr,
9624 events,
9625 event);
9626 }
9627
9628 inline cl_int enqueueWriteBufferRect(
9629 const Buffer& buffer,
9630 cl_bool blocking,
9631 const array<size_type, 3>& buffer_offset,
9632 const array<size_type, 3>& host_offset,
9633 const array<size_type, 3>& region,
9634 size_type buffer_row_pitch,
9635 size_type buffer_slice_pitch,
9636 size_type host_row_pitch,
9637 size_type host_slice_pitch,
9638 const void *ptr,
9639 const vector<Event>* events = NULL,
9640 Event* event = NULL)
9641 {
9642 cl_int error;
9643 CommandQueue queue = CommandQueue::getDefault(&error);
9644
9645 if (error != CL_SUCCESS) {
9646 return error;
9647 }
9648
9649 return queue.enqueueWriteBufferRect(
9650 buffer,
9651 blocking,
9652 buffer_offset,
9653 host_offset,
9654 region,
9655 buffer_row_pitch,
9656 buffer_slice_pitch,
9657 host_row_pitch,
9658 host_slice_pitch,
9659 ptr,
9660 events,
9661 event);
9662 }
9663
9664 inline cl_int enqueueCopyBufferRect(
9665 const Buffer& src,
9666 const Buffer& dst,
9667 const array<size_type, 3>& src_origin,
9668 const array<size_type, 3>& dst_origin,
9669 const array<size_type, 3>& region,
9670 size_type src_row_pitch,
9671 size_type src_slice_pitch,
9672 size_type dst_row_pitch,
9673 size_type dst_slice_pitch,
9674 const vector<Event>* events = NULL,
9675 Event* event = NULL)
9676 {
9677 cl_int error;
9678 CommandQueue queue = CommandQueue::getDefault(&error);
9679
9680 if (error != CL_SUCCESS) {
9681 return error;
9682 }
9683
9684 return queue.enqueueCopyBufferRect(
9685 src,
9686 dst,
9687 src_origin,
9688 dst_origin,
9689 region,
9690 src_row_pitch,
9691 src_slice_pitch,
9692 dst_row_pitch,
9693 dst_slice_pitch,
9694 events,
9695 event);
9696 }
9697 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
9698
9699 inline cl_int enqueueReadImage(
9700 const Image& image,
9701 cl_bool blocking,
9702 const array<size_type, 3>& origin,
9703 const array<size_type, 3>& region,
9704 size_type row_pitch,
9705 size_type slice_pitch,
9706 void* ptr,
9707 const vector<Event>* events = NULL,
9708 Event* event = NULL)
9709 {
9710 cl_int error;
9711 CommandQueue queue = CommandQueue::getDefault(&error);
9712
9713 if (error != CL_SUCCESS) {
9714 return error;
9715 }
9716
9717 return queue.enqueueReadImage(
9718 image,
9719 blocking,
9720 origin,
9721 region,
9722 row_pitch,
9723 slice_pitch,
9724 ptr,
9725 events,
9726 event);
9727 }
9728
9729 inline cl_int enqueueWriteImage(
9730 const Image& image,
9731 cl_bool blocking,
9732 const array<size_type, 3>& origin,
9733 const array<size_type, 3>& region,
9734 size_type row_pitch,
9735 size_type slice_pitch,
9736 const void* ptr,
9737 const vector<Event>* events = NULL,
9738 Event* event = NULL)
9739 {
9740 cl_int error;
9741 CommandQueue queue = CommandQueue::getDefault(&error);
9742
9743 if (error != CL_SUCCESS) {
9744 return error;
9745 }
9746
9747 return queue.enqueueWriteImage(
9748 image,
9749 blocking,
9750 origin,
9751 region,
9752 row_pitch,
9753 slice_pitch,
9754 ptr,
9755 events,
9756 event);
9757 }
9758
9759 inline cl_int enqueueCopyImage(
9760 const Image& src,
9761 const Image& dst,
9762 const array<size_type, 3>& src_origin,
9763 const array<size_type, 3>& dst_origin,
9764 const array<size_type, 3>& region,
9765 const vector<Event>* events = NULL,
9766 Event* event = NULL)
9767 {
9768 cl_int error;
9769 CommandQueue queue = CommandQueue::getDefault(&error);
9770
9771 if (error != CL_SUCCESS) {
9772 return error;
9773 }
9774
9775 return queue.enqueueCopyImage(
9776 src,
9777 dst,
9778 src_origin,
9779 dst_origin,
9780 region,
9781 events,
9782 event);
9783 }
9784
9785 inline cl_int enqueueCopyImageToBuffer(
9786 const Image& src,
9787 const Buffer& dst,
9788 const array<size_type, 3>& src_origin,
9789 const array<size_type, 3>& region,
9790 size_type dst_offset,
9791 const vector<Event>* events = NULL,
9792 Event* event = NULL)
9793 {
9794 cl_int error;
9795 CommandQueue queue = CommandQueue::getDefault(&error);
9796
9797 if (error != CL_SUCCESS) {
9798 return error;
9799 }
9800
9801 return queue.enqueueCopyImageToBuffer(
9802 src,
9803 dst,
9804 src_origin,
9805 region,
9806 dst_offset,
9807 events,
9808 event);
9809 }
9810
9811 inline cl_int enqueueCopyBufferToImage(
9812 const Buffer& src,
9813 const Image& dst,
9814 size_type src_offset,
9815 const array<size_type, 3>& dst_origin,
9816 const array<size_type, 3>& region,
9817 const vector<Event>* events = NULL,
9818 Event* event = NULL)
9819 {
9820 cl_int error;
9821 CommandQueue queue = CommandQueue::getDefault(&error);
9822
9823 if (error != CL_SUCCESS) {
9824 return error;
9825 }
9826
9827 return queue.enqueueCopyBufferToImage(
9828 src,
9829 dst,
9830 src_offset,
9831 dst_origin,
9832 region,
9833 events,
9834 event);
9835 }
9836
9837
9838 inline cl_int flush(void)
9839 {
9840 cl_int error;
9841 CommandQueue queue = CommandQueue::getDefault(&error);
9842
9843 if (error != CL_SUCCESS) {
9844 return error;
9845 }
9846
9847 return queue.flush();
9848 }
9849
9850 inline cl_int finish(void)
9851 {
9852 cl_int error;
9853 CommandQueue queue = CommandQueue::getDefault(&error);
9854
9855 if (error != CL_SUCCESS) {
9856 return error;
9857 }
9858
9859
9860 return queue.finish();
9861 }
9862
9863 class EnqueueArgs
9864 {
9865 private:
9866 CommandQueue queue_;
9867 const NDRange offset_;
9868 const NDRange global_;
9869 const NDRange local_;
9870 vector<Event> events_;
9871
9872 template<typename... Ts>
9873 friend class KernelFunctor;
9874
9875 public:
9876 EnqueueArgs(NDRange global) :
9877 queue_(CommandQueue::getDefault()),
9878 offset_(NullRange),
9879 global_(global),
9880 local_(NullRange)
9881 {
9882
9883 }
9884
9885 EnqueueArgs(NDRange global, NDRange local) :
9886 queue_(CommandQueue::getDefault()),
9887 offset_(NullRange),
9888 global_(global),
9889 local_(local)
9890 {
9891
9892 }
9893
9894 EnqueueArgs(NDRange offset, NDRange global, NDRange local) :
9895 queue_(CommandQueue::getDefault()),
9896 offset_(offset),
9897 global_(global),
9898 local_(local)
9899 {
9900
9901 }
9902
9903 EnqueueArgs(Event e, NDRange global) :
9904 queue_(CommandQueue::getDefault()),
9905 offset_(NullRange),
9906 global_(global),
9907 local_(NullRange)
9908 {
9909 events_.push_back(e);
9910 }
9911
9912 EnqueueArgs(Event e, NDRange global, NDRange local) :
9913 queue_(CommandQueue::getDefault()),
9914 offset_(NullRange),
9915 global_(global),
9916 local_(local)
9917 {
9918 events_.push_back(e);
9919 }
9920
9921 EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) :
9922 queue_(CommandQueue::getDefault()),
9923 offset_(offset),
9924 global_(global),
9925 local_(local)
9926 {
9927 events_.push_back(e);
9928 }
9929
9930 EnqueueArgs(const vector<Event> &events, NDRange global) :
9931 queue_(CommandQueue::getDefault()),
9932 offset_(NullRange),
9933 global_(global),
9934 local_(NullRange),
9935 events_(events)
9936 {
9937
9938 }
9939
9940 EnqueueArgs(const vector<Event> &events, NDRange global, NDRange local) :
9941 queue_(CommandQueue::getDefault()),
9942 offset_(NullRange),
9943 global_(global),
9944 local_(local),
9945 events_(events)
9946 {
9947
9948 }
9949
9950 EnqueueArgs(const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
9951 queue_(CommandQueue::getDefault()),
9952 offset_(offset),
9953 global_(global),
9954 local_(local),
9955 events_(events)
9956 {
9957
9958 }
9959
9960 EnqueueArgs(CommandQueue &queue, NDRange global) :
9961 queue_(queue),
9962 offset_(NullRange),
9963 global_(global),
9964 local_(NullRange)
9965 {
9966
9967 }
9968
9969 EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) :
9970 queue_(queue),
9971 offset_(NullRange),
9972 global_(global),
9973 local_(local)
9974 {
9975
9976 }
9977
9978 EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) :
9979 queue_(queue),
9980 offset_(offset),
9981 global_(global),
9982 local_(local)
9983 {
9984
9985 }
9986
9987 EnqueueArgs(CommandQueue &queue, Event e, NDRange global) :
9988 queue_(queue),
9989 offset_(NullRange),
9990 global_(global),
9991 local_(NullRange)
9992 {
9993 events_.push_back(e);
9994 }
9995
9996 EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) :
9997 queue_(queue),
9998 offset_(NullRange),
9999 global_(global),
10000 local_(local)
10001 {
10002 events_.push_back(e);
10003 }
10004
10005 EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) :
10006 queue_(queue),
10007 offset_(offset),
10008 global_(global),
10009 local_(local)
10010 {
10011 events_.push_back(e);
10012 }
10013
10014 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global) :
10015 queue_(queue),
10016 offset_(NullRange),
10017 global_(global),
10018 local_(NullRange),
10019 events_(events)
10020 {
10021
10022 }
10023
10024 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global, NDRange local) :
10025 queue_(queue),
10026 offset_(NullRange),
10027 global_(global),
10028 local_(local),
10029 events_(events)
10030 {
10031
10032 }
10033
10034 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
10035 queue_(queue),
10036 offset_(offset),
10037 global_(global),
10038 local_(local),
10039 events_(events)
10040 {
10041
10042 }
10043 };
10044
10045
10046 //----------------------------------------------------------------------------------------------
10047
10048
10053 template<typename... Ts>
10054 class KernelFunctor
10055 {
10056 private:
10057 Kernel kernel_;
10058
10059 template<int index, typename T0, typename... T1s>
10060 void setArgs(T0&& t0, T1s&&... t1s)
10061 {
10062 kernel_.setArg(index, t0);
10063 setArgs<index + 1, T1s...>(std::forward<T1s>(t1s)...);
10064 }
10065
10066 template<int index, typename T0>
10067 void setArgs(T0&& t0)
10068 {
10069 kernel_.setArg(index, t0);
10070 }
10071
10072 template<int index>
10073 void setArgs()
10074 {
10075 }
10076
10077
10078 public:
10079 KernelFunctor(Kernel kernel) : kernel_(kernel)
10080 {}
10081
10082 KernelFunctor(
10083 const Program& program,
10084 const string name,
10085 cl_int * err = NULL) :
10086 kernel_(program, name.c_str(), err)
10087 {}
10088
10090 typedef Event result_type;
10091
10097 Event operator() (
10098 const EnqueueArgs& args,
10099 Ts... ts)
10100 {
10101 Event event;
10102 setArgs<0>(std::forward<Ts>(ts)...);
10103
10104 args.queue_.enqueueNDRangeKernel(
10105 kernel_,
10106 args.offset_,
10107 args.global_,
10108 args.local_,
10109 &args.events_,
10110 &event);
10111
10112 return event;
10113 }
10114
10121 Event operator() (
10122 const EnqueueArgs& args,
10123 Ts... ts,
10124 cl_int &error)
10125 {
10126 Event event;
10127 setArgs<0>(std::forward<Ts>(ts)...);
10128
10129 error = args.queue_.enqueueNDRangeKernel(
10130 kernel_,
10131 args.offset_,
10132 args.global_,
10133 args.local_,
10134 &args.events_,
10135 &event);
10136
10137 return event;
10138 }
10139
10140 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10141 cl_int setSVMPointers(const vector<void*> &pointerList)
10142 {
10143 return kernel_.setSVMPointers(pointerList);
10144 }
10145
10146 template<typename T0, typename... T1s>
10147 cl_int setSVMPointers(const T0 &t0, T1s &... ts)
10148 {
10149 return kernel_.setSVMPointers(t0, ts...);
10150 }
10151 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10152
10153 Kernel getKernel()
10154 {
10155 return kernel_;
10156 }
10157 };
10158
10159 namespace compatibility {
10164 template<typename... Ts>
10165 struct make_kernel
10166 {
10167 typedef KernelFunctor<Ts...> FunctorType;
10168
10169 FunctorType functor_;
10170
10171 make_kernel(
10172 const Program& program,
10173 const string name,
10174 cl_int * err = NULL) :
10175 functor_(FunctorType(program, name, err))
10176 {}
10177
10178 make_kernel(
10179 const Kernel kernel) :
10180 functor_(FunctorType(kernel))
10181 {}
10182
10184 typedef Event result_type;
10185
10187 typedef Event type_(
10188 const EnqueueArgs&,
10189 Ts...);
10190
10191 Event operator()(
10192 const EnqueueArgs& enqueueArgs,
10193 Ts... args)
10194 {
10195 return functor_(
10196 enqueueArgs, args...);
10197 }
10198 };
10199 } // namespace compatibility
10200
10201
10202 //----------------------------------------------------------------------------------------------------------------------
10203
10204 #undef CL_HPP_ERR_STR_
10205 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
10206 #undef __GET_DEVICE_INFO_ERR
10207 #undef __GET_PLATFORM_INFO_ERR
10208 #undef __GET_DEVICE_IDS_ERR
10209 #undef __GET_PLATFORM_IDS_ERR
10210 #undef __GET_CONTEXT_INFO_ERR
10211 #undef __GET_EVENT_INFO_ERR
10212 #undef __GET_EVENT_PROFILE_INFO_ERR
10213 #undef __GET_MEM_OBJECT_INFO_ERR
10214 #undef __GET_IMAGE_INFO_ERR
10215 #undef __GET_SAMPLER_INFO_ERR
10216 #undef __GET_KERNEL_INFO_ERR
10217 #undef __GET_KERNEL_ARG_INFO_ERR
10218 #undef __GET_KERNEL_SUB_GROUP_INFO_ERR
10219 #undef __GET_KERNEL_WORK_GROUP_INFO_ERR
10220 #undef __GET_PROGRAM_INFO_ERR
10221 #undef __GET_PROGRAM_BUILD_INFO_ERR
10222 #undef __GET_COMMAND_QUEUE_INFO_ERR
10223 #undef __CREATE_CONTEXT_ERR
10224 #undef __CREATE_CONTEXT_FROM_TYPE_ERR
10225 #undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
10226 #undef __CREATE_BUFFER_ERR
10227 #undef __COPY_ERR
10228 #undef __CREATE_SUBBUFFER_ERR
10229 #undef __CREATE_GL_BUFFER_ERR
10230 #undef __CREATE_GL_RENDER_BUFFER_ERR
10231 #undef __GET_GL_OBJECT_INFO_ERR
10232 #undef __CREATE_IMAGE_ERR
10233 #undef __CREATE_GL_TEXTURE_ERR
10234 #undef __IMAGE_DIMENSION_ERR
10235 #undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
10236 #undef __CREATE_USER_EVENT_ERR
10237 #undef __SET_USER_EVENT_STATUS_ERR
10238 #undef __SET_EVENT_CALLBACK_ERR
10239 #undef __WAIT_FOR_EVENTS_ERR
10240 #undef __CREATE_KERNEL_ERR
10241 #undef __SET_KERNEL_ARGS_ERR
10242 #undef __CREATE_PROGRAM_WITH_SOURCE_ERR
10243 #undef __CREATE_PROGRAM_WITH_IL_ERR
10244 #undef __CREATE_PROGRAM_WITH_BINARY_ERR
10245 #undef __CREATE_PROGRAM_WITH_IL_ERR
10246 #undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR
10247 #undef __BUILD_PROGRAM_ERR
10248 #undef __COMPILE_PROGRAM_ERR
10249 #undef __LINK_PROGRAM_ERR
10250 #undef __CREATE_KERNELS_IN_PROGRAM_ERR
10251 #undef __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR
10252 #undef __CREATE_SAMPLER_WITH_PROPERTIES_ERR
10253 #undef __SET_COMMAND_QUEUE_PROPERTY_ERR
10254 #undef __ENQUEUE_READ_BUFFER_ERR
10255 #undef __ENQUEUE_READ_BUFFER_RECT_ERR
10256 #undef __ENQUEUE_WRITE_BUFFER_ERR
10257 #undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
10258 #undef __ENQEUE_COPY_BUFFER_ERR
10259 #undef __ENQEUE_COPY_BUFFER_RECT_ERR
10260 #undef __ENQUEUE_FILL_BUFFER_ERR
10261 #undef __ENQUEUE_READ_IMAGE_ERR
10262 #undef __ENQUEUE_WRITE_IMAGE_ERR
10263 #undef __ENQUEUE_COPY_IMAGE_ERR
10264 #undef __ENQUEUE_FILL_IMAGE_ERR
10265 #undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
10266 #undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
10267 #undef __ENQUEUE_MAP_BUFFER_ERR
10268 #undef __ENQUEUE_MAP_IMAGE_ERR
10269 #undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
10270 #undef __ENQUEUE_NDRANGE_KERNEL_ERR
10271 #undef __ENQUEUE_NATIVE_KERNEL
10272 #undef __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR
10273 #undef __ENQUEUE_MIGRATE_SVM_ERR
10274 #undef __ENQUEUE_ACQUIRE_GL_ERR
10275 #undef __ENQUEUE_RELEASE_GL_ERR
10276 #undef __CREATE_PIPE_ERR
10277 #undef __GET_PIPE_INFO_ERR
10278 #undef __RETAIN_ERR
10279 #undef __RELEASE_ERR
10280 #undef __FLUSH_ERR
10281 #undef __FINISH_ERR
10282 #undef __VECTOR_CAPACITY_ERR
10283 #undef __CREATE_SUB_DEVICES_ERR
10284 #undef __CREATE_SUB_DEVICES_ERR
10285 #undef __ENQUEUE_MARKER_ERR
10286 #undef __ENQUEUE_WAIT_FOR_EVENTS_ERR
10287 #undef __ENQUEUE_BARRIER_ERR
10288 #undef __UNLOAD_COMPILER_ERR
10289 #undef __CREATE_GL_TEXTURE_2D_ERR
10290 #undef __CREATE_GL_TEXTURE_3D_ERR
10291 #undef __CREATE_IMAGE2D_ERR
10292 #undef __CREATE_IMAGE3D_ERR
10293 #undef __CREATE_COMMAND_QUEUE_ERR
10294 #undef __ENQUEUE_TASK_ERR
10295 #undef __CREATE_SAMPLER_ERR
10296 #undef __ENQUEUE_MARKER_WAIT_LIST_ERR
10297 #undef __ENQUEUE_BARRIER_WAIT_LIST_ERR
10298 #undef __CLONE_KERNEL_ERR
10299 #undef __GET_HOST_TIMER_ERR
10300 #undef __GET_DEVICE_AND_HOST_TIMER_ERR
10301
10302 #endif //CL_HPP_USER_OVERRIDE_ERROR_STRINGS
10303
10304 // Extensions
10305 #undef CL_HPP_INIT_CL_EXT_FCN_PTR_
10306 #undef CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_
10307
10308 #if defined(CL_HPP_USE_CL_DEVICE_FISSION)
10309 #undef CL_HPP_PARAM_NAME_DEVICE_FISSION_
10310 #endif // CL_HPP_USE_CL_DEVICE_FISSION
10311
10312 #undef CL_HPP_NOEXCEPT_
10313 #undef CL_HPP_DEFINE_STATIC_MEMBER_
10314
10315 } // namespace cl
10316
10317 #endif // CL_HPP_
cl::compatibility::make_kernel::result_type
Event result_type
Return type of the functor.
Definition: opencl.hpp:10184
cl::SVMTraitCoarse
Definition: opencl.hpp:3548
cl::Image2D::Image2D
Image2D(const Context &context, ImageFormat format, const Buffer &sourceBuffer, size_type width, size_type height, size_type row_pitch=0, cl_int *err=nullptr)
Constructs a 2D Image from a buffer.
Definition: opencl.hpp:4813
cl::Image3DGL::Image3DGL
Image3DGL(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5343
cl::copy
cl_int copy(IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer)
Definition: opencl.hpp:9473
cl::Image1DArray::Image1DArray
Image1DArray(const Image1DArray &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4700
cl::CommandQueue::enqueueMigrateSVM
cl_int enqueueMigrateSVM(const cl::vector< cl::pointer< T, D >> &svmPointers, const cl::vector< size_type > &sizes, cl_mem_migration_flags flags=0, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8480
cl::Device::getDeviceAndHostTimer
std::pair< cl_ulong, cl_ulong > getDeviceAndHostTimer(cl_int *error=nullptr)
Definition: opencl.hpp:2286
cl::DeviceCommandQueue::DeviceCommandQueue
DeviceCommandQueue(const cl_command_queue &commandQueue, bool retainObject=false)
Constructor from cl_command_queue - takes ownership.
Definition: opencl.hpp:8918
cl::Pipe::getInfo
cl_int getInfo(cl_pipe_info name, T *param) const
Wrapper for clGetMemObjectInfo().
Definition: opencl.hpp:5585
cl::CommandQueue::CommandQueue
CommandQueue(const CommandQueue &queue)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:7550
cl::Device::getInfo
detail::param_traits< detail::cl_device_info, name >::param_type getInfo(cl_int *err=NULL) const
Wrapper for clGetDeviceInfo() that returns by value.
Definition: opencl.hpp:2243
cl::Event::getProfilingInfo
detail::param_traits< detail::cl_profiling_info, name >::param_type getProfilingInfo(cl_int *err=NULL) const
Wrapper for clGetEventProfilingInfo() that returns by value.
Definition: opencl.hpp:3256
cl::SVMAllocator::rebind
Definition: opencl.hpp:3617
cl::Program
Program interface that implements cl_program.
Definition: opencl.hpp:6233
cl::Pipe
Class interface for Pipe Memory Objects.
Definition: opencl.hpp:5477
cl::Sampler
Class interface for cl_sampler.
Definition: opencl.hpp:5618
cl::NDRange::size
size_type size() const
Returns the size of the object in bytes based on the.
Definition: opencl.hpp:5805
cl::BufferGL::BufferGL
BufferGL(const Context &context, cl_mem_flags flags, cl_GLuint bufobj, cl_int *err=NULL)
Constructs a BufferGL in a specified context, from a given GL buffer.
Definition: opencl.hpp:4194
cl::BufferRenderGL::BufferRenderGL
BufferRenderGL(const Context &context, cl_mem_flags flags, cl_GLuint bufobj, cl_int *err=NULL)
Constructs a BufferRenderGL in a specified context, from a given GL Renderbuffer.
Definition: opencl.hpp:4291
cl::Image2D::Image2D
Image2D(Image2D &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4956
cl::Event::setCallback
cl_int setCallback(cl_int type, void(CL_CALLBACK *pfn_notify)(cl_event, cl_int, void *), void *user_data=NULL)
Registers a user callback function for a specific command execution status.
Definition: opencl.hpp:3283
cl::Image1D::Image1D
Image1D(Image1D &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4541
cl::Platform::unloadCompiler
cl_int unloadCompiler()
Wrapper for clUnloadCompiler().
Definition: opencl.hpp:2743
cl::Kernel::setArg
std::enable_if< std::is_pointer< T >::value, cl_int >::type setArg(cl_uint index, const T argPtr)
setArg overload taking a pointer type
Definition: opencl.hpp:6067
cl::Context::getDefault
static Context getDefault(cl_int *err=NULL)
Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT.
Definition: opencl.hpp:3033
cl::Program::Program
Program(const cl_program &program, bool retainObject=false)
Constructor from cl_program - takes ownership.
Definition: opencl.hpp:6620
cl::detail::ReferenceHandler< cl_device_id >::retain
static cl_int retain(cl_device_id device)
Definition: opencl.hpp:1640
cl::Memory::Memory
Memory(const cl_mem &memory, bool retainObject)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:3393
cl::Image1D::Image1D
Image1D(const Image1D &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4527
cl::Image2DGL::Image2DGL
Image2DGL(Image2DGL &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5052
cl::CommandQueue::enqueueFillImage
cl_int enqueueFillImage(const Image &image, cl_uint4 fillColor, const array< size_type, 3 > &origin, const array< size_type, 3 > &region, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:7999
cl::CommandQueue::enqueueFillImage
cl_int enqueueFillImage(const Image &image, cl_int4 fillColor, const array< size_type, 3 > &origin, const array< size_type, 3 > &region, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:7965
cl::Buffer::Buffer
Buffer(const Buffer &buf)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4014
cl::Platform::Platform
Platform()
Default constructor - initializes to NULL.
Definition: opencl.hpp:2471
cl::DeviceCommandQueue::getDefault
static DeviceCommandQueue getDefault(const CommandQueue &queue, cl_int *err=NULL)
Definition: opencl.hpp:9088
cl::CommandQueue::enqueueMigrateSVM
cl_int enqueueMigrateSVM(const cl::vector< cl::vector< T, Alloc >> &svmContainers, cl_mem_migration_flags flags=0, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8538
cl::Image2D::Image2D
Image2D()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4917
cl::SVMTraitAtomic
Definition: opencl.hpp:3569
cl::Image3D::Image3D
Image3D()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5242
cl::Context::Context
Context(Context &&ctx) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3017
cl::UserEvent
Class interface for user events (a subset of cl_event's).
Definition: opencl.hpp:3318
cl::Platform::get
static cl_int get(vector< Platform > *platforms)
Gets a list of available platforms.
Definition: opencl.hpp:2675
cl::Sampler::Sampler
Sampler()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5621
cl::Event::Event
Event(const cl_event &event, bool retainObject=false)
Constructor from cl_event - takes ownership.
Definition: opencl.hpp:3207
cl::Image3D::Image3D
Image3D(Image3D &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5281
cl::DeviceCommandQueue::DeviceCommandQueue
DeviceCommandQueue(const Context &context, const Device &device, DeviceQueueProperties properties=DeviceQueueProperties::None, cl_int *err=NULL)
Definition: opencl.hpp:8864
cl::fine_svm_vector
vector< T, cl::SVMAllocator< int, cl::SVMTraitFine<> >> fine_svm_vector
Vector alias to simplify contruction of fine-grained SVM containers.
Definition: opencl.hpp:3849
cl::Image3DGL::operator=
Image3DGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:5350
cl::Buffer
Class interface for Buffer Memory Objects.
Definition: opencl.hpp:3867
cl::Pipe::Pipe
Pipe(cl_uint packet_size, cl_uint max_packets, cl_int *err=NULL)
Constructs a Pipe in a the default context.
Definition: opencl.hpp:5514
cl::CommandQueue::CommandQueue
CommandQueue(const cl_command_queue &commandQueue, bool retainObject=false)
Constructor from cl_command_queue - takes ownership.
Definition: opencl.hpp:7538
cl::Pipe::getInfo
detail::param_traits< detail::cl_pipe_info, name >::param_type getInfo(cl_int *err=NULL) const
Wrapper for clGetMemObjectInfo() that returns by value.
Definition: opencl.hpp:5595
cl::Image3DGL::Image3DGL
Image3DGL(const Image3DGL &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5359
cl::Program::Program
Program(const Context &context, const vector< Device > &devices, const string &kernelNames, cl_int *err=NULL)
Definition: opencl.hpp:6582
cl::Image3D::operator=
Image3D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:5258
cl::Image2D::operator=
Image2D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4933
cl::DeviceCommandQueue::DeviceCommandQueue
DeviceCommandQueue(const DeviceCommandQueue &queue)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:8930
cl::Kernel::clone
Kernel clone()
Definition: opencl.hpp:6218
cl::Image1DBuffer
Image interface for 1D buffer images.
Definition: opencl.hpp:4558
cl::BufferRenderGL::BufferRenderGL
BufferRenderGL(const BufferRenderGL &buf)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4336
cl::NDRange::dimensions
size_type dimensions() const
Queries the number of dimensions in the range.
Definition: opencl.hpp:5798
cl::DeviceCommandQueue::makeDefault
static DeviceCommandQueue makeDefault(cl_int *err=nullptr)
Definition: opencl.hpp:8983
cl::Program::Program
Program(const Sources &sources, cl_int *err=NULL)
Definition: opencl.hpp:6323
cl::Device::Device
Device(Device &&dev) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:2220
cl::Sampler::Sampler
Sampler(const Sampler &sam)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5691
cl::CommandQueue::enqueueMigrateSVM
cl_int enqueueMigrateSVM(const cl::vector< cl::pointer< T, D >> &svmPointers, cl_mem_migration_flags flags=0, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8502
cl::enqueueUnmapSVM
cl_int enqueueUnmapSVM(T *ptr, const vector< Event > *events=NULL, Event *event=NULL)
Definition: opencl.hpp:9388
cl::Kernel::setSVMPointers
cl_int setSVMPointers(const vector< void * > &pointerList)
Definition: opencl.hpp:6102
cl::LocalSpaceArg
Local address wrapper for use with Kernel::setArg.
Definition: opencl.hpp:5826
cl::Memory::Memory
Memory(const Memory &mem)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3410
cl::Context::Context
Context(const Device &device, cl_context_properties *properties=NULL, void(CL_CALLBACK *notifyFptr)(const char *, const void *, size_type, void *)=NULL, void *data=NULL, cl_int *err=NULL)
Constructs a context including a specific device.
Definition: opencl.hpp:2887
cl::Context
Class interface for cl_context.
Definition: opencl.hpp:2782
cl::mapSVM
cl_int mapSVM(cl::vector< T, Alloc > &container)
Definition: opencl.hpp:9575
cl::Image::Image
Image(const Image &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4407
cl::Program::Program
Program(Program &&program) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:6646
cl::SVMTraitFine
Definition: opencl.hpp:3558
cl::Buffer::Buffer
Buffer(Buffer &&buf) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4028
cl::Pipe::operator=
Pipe & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:5549
cl::Buffer::Buffer
Buffer(const Context &context, cl_mem_flags flags, size_type size, void *host_ptr=NULL, cl_int *err=NULL)
Constructs a Buffer in a specified context.
Definition: opencl.hpp:3877
cl::ImageFormat
Adds constructors and member functions for cl_image_format.
Definition: opencl.hpp:2089
cl::Image::Image
Image(Image &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4421
cl::Program::Program
Program(const Context &context, const vector< char > &IL, bool build=false, cl_int *err=NULL)
Definition: opencl.hpp:6450
cl::Context::getInfo
detail::param_traits< detail::cl_context_info, name >::param_type getInfo(cl_int *err=NULL) const
Wrapper for clGetContextInfo() that returns by value.
Definition: opencl.hpp:3091
cl::Buffer::Buffer
Buffer()
Default constructor - initializes to NULL.
Definition: opencl.hpp:3989
cl::Image1D::Image1D
Image1D(const cl_mem &image1D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4511
cl::CommandQueue::enqueueBarrierWithWaitList
cl_int enqueueBarrierWithWaitList(const vector< Event > *events=0, Event *event=0) const
Definition: opencl.hpp:8371
cl::Image2DGL::Image2DGL
Image2DGL(const Context &context, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texobj, cl_int *err=NULL)
Constructs an Image2DGL in a specified context, from a given GL Texture.
Definition: opencl.hpp:4988
cl::Memory
Class interface for cl_mem.
Definition: opencl.hpp:3377
cl::Program::setSpecializationConstant
cl_int setSpecializationConstant(cl_uint index, size_type size, const void *value)
Sets a SPIR-V specialization constant.
Definition: opencl.hpp:6903
cl::Sampler::Sampler
Sampler(const cl_sampler &sampler, bool retainObject=false)
Constructor from cl_sampler - takes ownership.
Definition: opencl.hpp:5674
cl::Image2DGL::Image2DGL
Image2DGL(const Image2DGL &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5038
cl::ImageGL::ImageGL
ImageGL(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5428
cl::Device::Device
Device(const Device &dev)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:2206
cl::Image2DArray::Image2DArray
Image2DArray(const cl_mem &imageArray, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5120
cl::Event::waitForEvents
static cl_int waitForEvents(const vector< Event > &events)
Blocks the calling thread until every event specified is complete.
Definition: opencl.hpp:3303
cl::NDRange::NDRange
NDRange(size_type size0, size_type size1)
Constructs two-dimensional range.
Definition: opencl.hpp:5772
cl::CommandQueue::CommandQueue
CommandQueue(const Context &context, cl_command_queue_properties properties=0, cl_int *err=NULL)
Constructs a CommandQueue for an implementation defined device in the given context Will return an CL...
Definition: opencl.hpp:7274
cl::NDRange::NDRange
NDRange()
Default constructor - resulting range has zero dimensions.
Definition: opencl.hpp:5754
cl::CommandQueue::enqueueFillBuffer
cl_int enqueueFillBuffer(const Buffer &buffer, PatternType pattern, size_type offset, size_type size, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:7799
cl::Buffer::Buffer
Buffer(const cl_mem &buffer, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:3998
cl::DeviceCommandQueue
DeviceCommandQueue interface for device cl_command_queues.
Definition: opencl.hpp:8830
cl::Image2D::Image2D
Image2D(const Context &context, cl_mem_flags flags, ImageFormat format, size_type width, size_type height, size_type row_pitch=0, void *host_ptr=NULL, cl_int *err=NULL)
Constructs a 2D Image in a specified context.
Definition: opencl.hpp:4742
cl::SVMTraitReadOnly
Definition: opencl.hpp:3526
cl::Image2DArray::Image2DArray
Image2DArray(const Image2DArray &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5131
cl::Pipe::Pipe
Pipe()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5533
cl::NDRange::NDRange
NDRange(size_type size0)
Constructs one-dimensional range.
Definition: opencl.hpp:5763
cl::Buffer::Buffer
Buffer(cl_mem_flags flags, size_type size, void *host_ptr=NULL, cl_int *err=NULL)
Constructs a Buffer in the default context.
Definition: opencl.hpp:3902
cl::Image2DGL::Image2DGL
Image2DGL(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5022
cl::UnloadCompiler
CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int UnloadCompiler() CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
Definition: opencl.hpp:2766
cl::Platform::getInfo
detail::param_traits< detail::cl_platform_info, name >::param_type getInfo(cl_int *err=NULL) const
Wrapper for clGetPlatformInfo() that returns by value.
Definition: opencl.hpp:2530
cl::Sampler::getInfo
cl_int getInfo(cl_sampler_info name, T *param) const
Wrapper for clGetSamplerInfo().
Definition: opencl.hpp:5718
cl::Kernel::Kernel
Kernel()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5889
cl::Memory::operator=
Memory & operator=(const cl_mem &rhs)
Assignment operator from cl_mem - takes ownership.
Definition: opencl.hpp:3401
cl::Memory::setDestructorCallback
cl_int setDestructorCallback(void(CL_CALLBACK *pfn_notify)(cl_mem, void *), void *user_data=NULL)
Registers a callback function to be called when the memory object is no longer needed.
Definition: opencl.hpp:3473
cl::CommandQueue::enqueueMigrateSVM
cl_int enqueueMigrateSVM(const cl::vector< cl::vector< T, Alloc >> &svmContainers, const cl::vector< size_type > &sizes, cl_mem_migration_flags flags=0, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8517
cl::Device::operator=
Device & operator=(const cl_device_id &rhs)
Assignment operator from cl_device_id.
Definition: opencl.hpp:2197
cl::Image3DGL::Image3DGL
Image3DGL(const Context &context, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texobj, cl_int *err=NULL)
Constructs an Image3DGL in a specified context, from a given GL Texture.
Definition: opencl.hpp:5310
cl::Event::getProfilingInfo
cl_int getProfilingInfo(cl_profiling_info name, T *param) const
Wrapper for clGetEventProfilingInfo().
Definition: opencl.hpp:3246
cl::BufferRenderGL::BufferRenderGL
BufferRenderGL()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4311
cl::Kernel::setArg
std::enable_if<!std::is_pointer< T >::value, cl_int >::type setArg(cl_uint index, const T &value)
setArg overload taking a POD type
Definition: opencl.hpp:6079
cl::Sampler::operator=
Sampler & operator=(const cl_sampler &rhs)
Assignment operator from cl_sampler - takes ownership.
Definition: opencl.hpp:5682
cl::Context::Context
Context(cl_device_type type, cl_context_properties *properties=NULL, void(CL_CALLBACK *notifyFptr)(const char *, const void *, size_type, void *)=NULL, void *data=NULL, cl_int *err=NULL)
Constructs a context including all or a subset of devices of a specified type.
Definition: opencl.hpp:2917
cl::Sampler::Sampler
Sampler(const Context &context, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode, cl_int *err=NULL)
Constructs a Sampler in a specified context.
Definition: opencl.hpp:5627
cl::SVMAllocator
Definition: opencl.hpp:3602
cl::ImageFormat::ImageFormat
ImageFormat(cl_channel_order order, cl_channel_type type)
Initializing constructor.
Definition: opencl.hpp:2094
cl::Image::getImageInfo
cl_int getImageInfo(cl_image_info name, T *param) const
Wrapper for clGetImageInfo().
Definition: opencl.hpp:4436
cl::CommandQueue::CommandQueue
CommandQueue(const Context &context, const Device &device, cl_command_queue_properties properties=0, cl_int *err=NULL)
Constructs a CommandQueue for a passed device and context Will return an CL_INVALID_QUEUE_PROPERTIES ...
Definition: opencl.hpp:7403
cl::Platform::get
static Platform get(cl_int *errResult=NULL)
Gets the first available platform, returning it by value.
Definition: opencl.hpp:2729
cl::Kernel
Class interface for cl_kernel.
Definition: opencl.hpp:5884
cl::CommandQueue::enqueueMapSVM
cl_int enqueueMapSVM(cl::pointer< T, D > &ptr, cl_bool blocking, cl_map_flags flags, size_type size, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8181
cl::SVMAllocator::operator==
bool operator==(SVMAllocator const &rhs)
Definition: opencl.hpp:3736
cl::Program::Program
Program(const Context &context, const vector< Device > &devices, const Binaries &binaries, vector< cl_int > *binaryStatus=NULL, cl_int *err=NULL)
Definition: opencl.hpp:6518
cl::CommandQueue::enqueueMarker
CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int enqueueMarker(Event *event=NULL) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
Definition: opencl.hpp:8637
cl::BufferRenderGL::getObjectInfo
cl_int getObjectInfo(cl_gl_object_type *type, cl_GLuint *gl_object_name)
Wrapper for clGetGLObjectInfo().
Definition: opencl.hpp:4362
cl::Kernel::enableFineGrainedSystemSVM
cl_int enableFineGrainedSystemSVM(bool svmEnabled)
Enable fine-grained system SVM.
Definition: opencl.hpp:6138
cl::Image1DBuffer::Image1DBuffer
Image1DBuffer(const cl_mem &image1D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4599
cl::Pipe::Pipe
Pipe(const Context &context, cl_uint packet_size, cl_uint max_packets, cl_int *err=NULL)
Constructs a Pipe in a specified context.
Definition: opencl.hpp:5489
cl::Context::operator=
Context & operator=(const Context &ctx)
Copy assignment to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3008
cl::ImageFormat::ImageFormat
ImageFormat()
Default constructor - performs no initialization.
Definition: opencl.hpp:2091
cl::CommandQueue::enqueueUnmapSVM
cl_int enqueueUnmapSVM(T *ptr, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8258
cl::Kernel::setArg
cl_int setArg(cl_uint index, const cl::pointer< T, D > &argPtr)
setArg overload taking a shared_ptr type
Definition: opencl.hpp:6046
cl::Platform::operator=
Platform & operator=(const cl_platform_id &rhs)
Assignment operator from cl_platform_id.
Definition: opencl.hpp:2487
cl::BufferGL::getObjectInfo
cl_int getObjectInfo(cl_gl_object_type *type, cl_GLuint *gl_object_name)
Wrapper for clGetGLObjectInfo().
Definition: opencl.hpp:4265
cl::Event::wait
cl_int wait() const
Blocks the calling thread until this event completes.
Definition: opencl.hpp:3271
cl::Sampler::Sampler
Sampler(Sampler &&sam) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5705
cl::Context::getSupportedImageFormats
cl_int getSupportedImageFormats(cl_mem_flags flags, cl_mem_object_type type, vector< ImageFormat > *formats) const
Gets a list of supported image formats.
Definition: opencl.hpp:3106
cl::BufferGL::BufferGL
BufferGL(const BufferGL &buf)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4239
cl::Kernel::setArg
cl_int setArg(cl_uint index, const cl::vector< T, Alloc > &argPtr)
setArg overload taking a vector type.
Definition: opencl.hpp:6056
cl::Memory::Memory
Memory()
Default constructor - initializes to NULL.
Definition: opencl.hpp:3380
cl::compatibility::make_kernel::type_
Event type_(const EnqueueArgs &, Ts...)
Function signature of kernel functor with no event dependency.
Definition: opencl.hpp:10187
cl::Image
C++ base class for Image Memory objects.
Definition: opencl.hpp:4379
cl::atomic_svm_vector
vector< T, cl::SVMAllocator< int, cl::SVMTraitAtomic<> >> atomic_svm_vector
Vector alias to simplify contruction of fine-grained SVM containers that support platform atomics.
Definition: opencl.hpp:3855
cl::Context::Context
Context(const vector< Device > &devices, cl_context_properties *properties=NULL, void(CL_CALLBACK *notifyFptr)(const char *, const void *, size_type, void *)=NULL, void *data=NULL, cl_int *err=NULL)
Constructs a context including a list of specified devices.
Definition: opencl.hpp:2852
cl::Pipe::Pipe
Pipe(Pipe &&pipe) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5572
cl
The OpenCL C++ bindings are defined within this namespace.
Definition: opencl.hpp:583
cl::BufferRenderGL
Class interface for GL Render Buffer Memory Objects.
Definition: opencl.hpp:4284
cl::SVMTraitReadWrite
Definition: opencl.hpp:3515
cl::Device
Class interface for cl_device_id.
Definition: opencl.hpp:2119
cl::Device::Device
Device()
Default constructor - initializes to NULL.
Definition: opencl.hpp:2155
cl::ImageFormat::operator=
ImageFormat & operator=(const ImageFormat &rhs)
Assignment operator.
Definition: opencl.hpp:2101
cl::KernelFunctor::result_type
Event result_type
Return type of the functor.
Definition: opencl.hpp:10090
cl::ImageGL
general image interface for GL interop. We abstract the 2D and 3D GL images into a single instance he...
Definition: opencl.hpp:5394
cl::CommandQueue::CommandQueue
CommandQueue(const Context &context, QueueProperties properties, cl_int *err=NULL)
Constructs a CommandQueue for an implementation defined device in the given context Will return an CL...
Definition: opencl.hpp:7341
cl::Event::operator=
Event & operator=(const cl_event &rhs)
Assignment operator from cl_event - takes ownership.
Definition: opencl.hpp:3215
cl::Image1DBuffer::Image1DBuffer
Image1DBuffer(Image1DBuffer &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4625
cl::Platform::setDefault
static Platform setDefault(const Platform &default_platform)
Definition: opencl.hpp:2511
cl::Image3D::Image3D
Image3D(const Image3D &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5267
cl::Program::setReleaseCallback
CL_EXT_PREFIX__VERSION_2_2_DEPRECATED cl_int setReleaseCallback(void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data), void *user_data=NULL) CL_EXT_SUFFIX__VERSION_2_2_DEPRECATED
Registers a callback function to be called when destructors for program scope global variables are co...
Definition: opencl.hpp:6869
cl::Image::Image
Image()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4382
cl::Program::Program
Program(const vector< char > &IL, bool build=false, cl_int *err=NULL)
Definition: opencl.hpp:6395
cl::Image3D
Class interface for 3D Image Memory objects.
Definition: opencl.hpp:5165
cl::Platform::Platform
Platform(const cl_platform_id &platform, bool retainObject=false)
Constructor from cl_platform_id.
Definition: opencl.hpp:2480
cl::Platform::get
static cl_int get(Platform *platform)
Gets the first available platform.
Definition: opencl.hpp:2710
cl::Kernel::operator=
Kernel & operator=(const cl_kernel &rhs)
Assignment operator from cl_kernel - takes ownership.
Definition: opencl.hpp:5907
cl::BufferRenderGL::BufferRenderGL
BufferRenderGL(BufferRenderGL &&buf) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4350
cl::Image::Image
Image(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4391
cl::Platform::getDevices
cl_int getDevices(cl_device_type type, vector< Device > *devices) const
Gets a list of devices for this platform.
Definition: opencl.hpp:2545
cl::CommandQueue::enqueueMigrateSVM
cl_int enqueueMigrateSVM(const cl::vector< T * > &svmRawPointers, cl_mem_migration_flags flags=0, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8464
cl::Pipe::Pipe
Pipe(const Pipe &pipe)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5558
cl::KernelFunctor
Definition: opencl.hpp:10055
cl::unmapSVM
cl_int unmapSVM(cl::vector< T, Alloc > &container)
Definition: opencl.hpp:9584
cl::Context::Context
Context(const cl_context &context, bool retainObject=false)
Constructor from cl_context - takes ownership.
Definition: opencl.hpp:3065
cl::Image2D
Class interface for 2D Image Memory objects.
Definition: opencl.hpp:4736
cl::Image1D
Class interface for 1D Image Memory objects.
Definition: opencl.hpp:4466
cl::DeviceCommandQueue::makeDefault
static DeviceCommandQueue makeDefault(const Context &context, const Device &device, cl_int *err=nullptr)
Definition: opencl.hpp:9013
cl::Image3DGL::Image3DGL
Image3DGL(Image3DGL &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5373
cl::Platform::getInfo
cl_int getInfo(cl_platform_info name, T *param) const
Wrapper for clGetPlatformInfo().
Definition: opencl.hpp:2520
cl::CommandQueue::enqueueUnmapSVM
cl_int enqueueUnmapSVM(cl::pointer< T, D > &ptr, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8283
cl::detail::GetInfoFunctor1
Definition: opencl.hpp:1596
cl::Image2DGL::Image2DGL
Image2DGL()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5013
cl::Device::setDefault
static Device setDefault(const Device &default_device)
Definition: opencl.hpp:2186
cl::Memory::Memory
Memory(Memory &&mem) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3424
cl::detail::Deleter
Definition: opencl.hpp:3769
cl::detail::ReferenceHandler
Definition: opencl.hpp:1622
cl::CommandQueue::CommandQueue
CommandQueue(CommandQueue &&queue) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:7564
cl::Context::Context
Context(const Context &ctx)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3003
cl::CommandQueue::setDefault
static CommandQueue setDefault(const CommandQueue &default_queue)
Definition: opencl.hpp:7522
cl::KernelFunctor::operator()
Event operator()(const EnqueueArgs &args, Ts... ts)
Definition: opencl.hpp:10097
cl::SVMTraitWriteOnly
Definition: opencl.hpp:3537
cl::Image1DArray::Image1DArray
Image1DArray(Image1DArray &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4714
cl::Buffer::Buffer
Buffer(IteratorType startIterator, IteratorType endIterator, bool readOnly, bool useHostPtr=false, cl_int *err=NULL)
Construct a Buffer from a host container via iterators. IteratorType must be random access....
Definition: opencl.hpp:3926
cl::BufferGL::BufferGL
BufferGL(BufferGL &&buf) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4253
cl::Device::getDefault
static Device getDefault(cl_int *errResult=NULL)
Returns the first device on the default context.
Definition: opencl.hpp:2168
cl::CommandQueue::enqueueUnmapSVM
cl_int enqueueUnmapSVM(cl::vector< T, Alloc > &container, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8308
cl::Sampler::getInfo
detail::param_traits< detail::cl_sampler_info, name >::param_type getInfo(cl_int *err=NULL) const
Wrapper for clGetSamplerInfo() that returns by value.
Definition: opencl.hpp:5728
cl::Image2DArray::Image2DArray
Image2DArray(Image2DArray &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5145
cl::Event::Event
Event()
Default constructor - initializes to NULL.
Definition: opencl.hpp:3197
cl::Kernel::setSVMPointers
cl_int setSVMPointers(const std::array< void *, ArrayLength > &pointerList)
Definition: opencl.hpp:6117
cl::Image1DArray::Image1DArray
Image1DArray(const cl_mem &imageArray, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4687
cl::Platform
Class interface for cl_platform_id.
Definition: opencl.hpp:2399
cl::Image3D::Image3D
Image3D(const cl_mem &image3D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5251
cl::detail::SVMTraitNull
Definition: opencl.hpp:3504
cl::CommandQueue::enqueueMigrateMemObjects
cl_int enqueueMigrateMemObjects(const vector< Memory > &memObjects, cl_mem_migration_flags flags, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8394
cl::Image3DGL
Class interface for GL 3D Image Memory objects.
Definition: opencl.hpp:5303
cl::enqueueMapSVM
cl_int enqueueMapSVM(T *ptr, cl_bool blocking, cl_map_flags flags, size_type size, const vector< Event > *events=NULL, Event *event=NULL)
Definition: opencl.hpp:9286
cl::DeviceCommandQueue::makeDefault
static DeviceCommandQueue makeDefault(const Context &context, const Device &device, cl_uint queueSize, cl_int *err=nullptr)
Definition: opencl.hpp:9041
cl::CommandQueue::enqueueMapSVM
cl_int enqueueMapSVM(cl::vector< T, Alloc > &container, cl_bool blocking, cl_map_flags flags, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8208
cl::DeviceCommandQueue::DeviceCommandQueue
DeviceCommandQueue(DeviceQueueProperties properties, cl_int *err=NULL)
Definition: opencl.hpp:8841
cl::Image3DGL::Image3DGL
Image3DGL()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5334
cl::Context::getInfo
cl_int getInfo(cl_context_info name, T *param) const
Wrapper for clGetContextInfo().
Definition: opencl.hpp:3081
cl::coarse_svm_vector
vector< T, cl::SVMAllocator< int, cl::SVMTraitCoarse<> >> coarse_svm_vector
Vector alias to simplify contruction of coarse-grained SVM containers.
Definition: opencl.hpp:3843
cl::CommandQueue::enqueueMigrateSVM
cl_int enqueueMigrateSVM(const cl::vector< T * > &svmRawPointers, const cl::vector< size_type > &sizes, cl_mem_migration_flags flags=0, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8435
cl::ImageGL::ImageGL
ImageGL(const ImageGL &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5440
cl::Event
Class interface for cl_event.
Definition: opencl.hpp:3194
cl::EnqueueArgs
Definition: opencl.hpp:9864
cl::Kernel::Kernel
Kernel(const cl_kernel &kernel, bool retainObject=false)
Constructor from cl_kernel - takes ownership.
Definition: opencl.hpp:5899
cl::Local
LocalSpaceArg Local(size_type size)
Helper function for generating LocalSpaceArg objects.
Definition: opencl.hpp:5869
cl::Kernel::Kernel
Kernel(Kernel &&kernel) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5930
cl::Pipe::Pipe
Pipe(const cl_mem &pipe, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5542
cl::CommandQueue::CommandQueue
CommandQueue(const Context &context, const Device &device, QueueProperties properties, cl_int *err=NULL)
Constructs a CommandQueue for a passed device and context Will return an CL_INVALID_QUEUE_PROPERTIES ...
Definition: opencl.hpp:7454
cl::Image::getImageInfo
detail::param_traits< detail::cl_image_info, name >::param_type getImageInfo(cl_int *err=NULL) const
Wrapper for clGetImageInfo() that returns by value.
Definition: opencl.hpp:4446
cl::CommandQueue::enqueueMapSVM
cl_int enqueueMapSVM(T *ptr, cl_bool blocking, cl_map_flags flags, size_type size, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8153
cl::Program::getBuildInfo
vector< std::pair< cl::Device, typename detail::param_traits< detail::cl_program_build_info, name >::param_type > > getBuildInfo(cl_int *err=NULL) const
Definition: opencl.hpp:6790
cl::SVMAllocator::allocate
pointer allocate(size_type size, typename cl::SVMAllocator< void, SVMTrait >::const_pointer=0)
Definition: opencl.hpp:3666
cl::detail::param_traits
Definition: opencl.hpp:1426
cl::UserEvent::UserEvent
UserEvent()
Default constructor - initializes to NULL.
Definition: opencl.hpp:3340
cl::Memory::getInfo
cl_int getInfo(cl_mem_info name, T *param) const
Wrapper for clGetMemObjectInfo().
Definition: opencl.hpp:3438
cl::DeviceCommandQueue::DeviceCommandQueue
DeviceCommandQueue(DeviceCommandQueue &&queue) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:8944
cl::BufferGL::BufferGL
BufferGL(const cl_mem &buffer, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4223
cl::Program::setSpecializationConstant
std::enable_if<!std::is_pointer< T >::value, cl_int >::type setSpecializationConstant(cl_uint index, const T &value)
Sets a SPIR-V specialization constant.
Definition: opencl.hpp:6888
cl::DeviceCommandQueue::DeviceCommandQueue
DeviceCommandQueue()
Definition: opencl.hpp:8836
cl::NDRange::NDRange
NDRange(size_type size0, size_type size1, size_type size2)
Constructs three-dimensional range.
Definition: opencl.hpp:5781
cl::detail::Wrapper
Definition: opencl.hpp:1799
cl::BufferGL
Class interface for GL Buffer Memory Objects.
Definition: opencl.hpp:4187
cl::Event::getInfo
cl_int getInfo(cl_event_info name, T *param) const
Wrapper for clGetEventInfo().
Definition: opencl.hpp:3223
cl::detail::GetInfoFunctor0
Definition: opencl.hpp:1587
cl::Buffer::createSubBuffer
Buffer createSubBuffer(cl_mem_flags flags, cl_buffer_create_type buffer_create_type, const void *buffer_create_info, cl_int *err=NULL)
Creates a new buffer object from this.
Definition: opencl.hpp:4044
cl::Memory::getInfo
detail::param_traits< detail::cl_mem_info, name >::param_type getInfo(cl_int *err=NULL) const
Wrapper for clGetMemObjectInfo() that returns by value.
Definition: opencl.hpp:3448
cl::CommandQueue::enqueueFillImage
cl_int enqueueFillImage(const Image &image, cl_float4 fillColor, const array< size_type, 3 > &origin, const array< size_type, 3 > &region, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:7931
cl::CommandQueue::enqueueBarrier
CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int enqueueBarrier() const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
Definition: opencl.hpp:8790
cl::Image2D::Image2D
Image2D(const cl_mem &image2D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4926
cl::allocate_pointer
cl::pointer< T, detail::Deleter< Alloc > > allocate_pointer(const Alloc &alloc_, Args &&... args)
Definition: opencl.hpp:3796
cl::Device::Device
Device(const cl_device_id &device, bool retainObject=false)
Constructor from cl_device_id.
Definition: opencl.hpp:2161
cl::Image2DArray
Image interface for arrays of 2D images.
Definition: opencl.hpp:5071
cl::Image1DArray
Image interface for arrays of 1D images.
Definition: opencl.hpp:4642
cl::Kernel::Kernel
Kernel(const Kernel &kernel)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5916
cl::BufferRenderGL::BufferRenderGL
BufferRenderGL(const cl_mem &buffer, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4320
cl::DeviceCommandQueue::updateDefault
static DeviceCommandQueue updateDefault(const Context &context, const Device &device, const DeviceCommandQueue &default_queue, cl_int *err=nullptr)
Definition: opencl.hpp:9073
cl::NDRange
Class interface for specifying NDRange values.
Definition: opencl.hpp:5747
cl::UserEvent::UserEvent
UserEvent(const Context &context, cl_int *err=NULL)
Constructs a user event on a given context.
Definition: opencl.hpp:3324
cl::Device::createSubDevices
cl_int createSubDevices(const cl_device_partition_property *properties, vector< Device > *devices)
Wrapper for clCreateSubDevices().
Definition: opencl.hpp:2306
cl::Event::getInfo
detail::param_traits< detail::cl_event_info, name >::param_type getInfo(cl_int *err=NULL) const
Wrapper for clGetEventInfo() that returns by value.
Definition: opencl.hpp:3233
cl::ImageGL::ImageGL
ImageGL(ImageGL &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5454
cl::detail::ReferenceHandler< cl_device_id >::release
static cl_int release(cl_device_id device)
Definition: opencl.hpp:1651
cl::CommandQueue
CommandQueue interface for cl_command_queue.
Definition: opencl.hpp:7080
cl::Image::operator=
Image & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4398
cl::compatibility::make_kernel
Definition: opencl.hpp:10166
cl::UserEvent::setStatus
cl_int setStatus(cl_int status)
Sets the execution status of a user event object.
Definition: opencl.hpp:3346
cl::copy
cl_int copy(const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator)
Definition: opencl.hpp:9544
cl::Buffer::operator=
Buffer & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4005
cl::BufferGL::operator=
BufferGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4230
cl::BufferGL::BufferGL
BufferGL()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4214
cl::CommandQueue::enqueueMarkerWithWaitList
cl_int enqueueMarkerWithWaitList(const vector< Event > *events=0, Event *event=0) const
Definition: opencl.hpp:8341
cl::CommandQueue::CommandQueue
CommandQueue(QueueProperties properties, cl_int *err=NULL)
Constructs a CommandQueue based on passed properties. Will return an CL_INVALID_QUEUE_PROPERTIES erro...
Definition: opencl.hpp:7211
cl::Image1D::operator=
Image1D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4518
cl::Image1D::Image1D
Image1D()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4502
cl::BufferRenderGL::operator=
BufferRenderGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4327
cl::CommandQueue::CommandQueue
CommandQueue(cl_command_queue_properties properties, cl_int *err=NULL)
Constructs a CommandQueue based on passed properties. Will return an CL_INVALID_QUEUE_PROPERTIES erro...
Definition: opencl.hpp:7145
cl::Context::Context
Context()
Default constructor - initializes to NULL.
Definition: opencl.hpp:3058
cl::Device::getInfo
cl_int getInfo(cl_device_info name, T *param) const
Wrapper for clGetDeviceInfo().
Definition: opencl.hpp:2233
cl::DeviceCommandQueue::DeviceCommandQueue
DeviceCommandQueue(const Context &context, const Device &device, cl_uint queueSize, DeviceQueueProperties properties=DeviceQueueProperties::None, cl_int *err=NULL)
Definition: opencl.hpp:8888
cl::Image1D::Image1D
Image1D(const Context &context, cl_mem_flags flags, ImageFormat format, size_type width, void *host_ptr=NULL, cl_int *err=NULL)
Constructs a 1D Image in a specified context.
Definition: opencl.hpp:4472
cl::Image2D::Image2D
Image2D(const Context &context, cl_channel_order order, const Image &sourceImage, cl_int *err=nullptr)
Constructs a 2D Image from an image.
Definition: opencl.hpp:4863
cl::Image3D::Image3D
Image3D(const Context &context, cl_mem_flags flags, ImageFormat format, size_type width, size_type height, size_type depth, size_type row_pitch=0, size_type slice_pitch=0, void *host_ptr=NULL, cl_int *err=NULL)
Constructs a 3D Image in a specified context.
Definition: opencl.hpp:5171
cl::Program::Program
Program(const Program &program)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:6632
cl::Image2DGL
Class interface for GL 2D Image Memory objects.
Definition: opencl.hpp:4981
cl::Image2D::Image2D
Image2D(const Image2D &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4942
cl::Device::getHostTimer
cl_ulong getHostTimer(cl_int *error=nullptr)
Definition: opencl.hpp:2262
cl::detail::KernelArgumentHandler
Definition: opencl.hpp:5833
cl::Program::Program
Program(const Context &context, const Sources &sources, cl_int *err=NULL)
Definition: opencl.hpp:6358
cl::Image1DBuffer::Image1DBuffer
Image1DBuffer(const Image1DBuffer &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4611
cl::SVMAllocator::max_size
size_type max_size() const CL_HPP_NOEXCEPT_
Definition: opencl.hpp:3708
cl::Context::setDefault
static Context setDefault(const Context &default_context)
Definition: opencl.hpp:3050