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
328
340
396#ifndef CL_HPP_
397#define CL_HPP_
398
399/* Handle deprecated preprocessor definitions. In each case, we only check for
400 * the old name if the new name is not defined, so that user code can define
401 * both and hence work with either version of the bindings.
402 */
403#if !defined(CL_HPP_USE_DX_INTEROP) && defined(USE_DX_INTEROP)
404# pragma message("opencl.hpp: USE_DX_INTEROP is deprecated. Define CL_HPP_USE_DX_INTEROP instead")
405# define CL_HPP_USE_DX_INTEROP
406#endif
407#if !defined(CL_HPP_USE_CL_DEVICE_FISSION) && defined(USE_CL_DEVICE_FISSION)
408# pragma message("opencl.hpp: USE_CL_DEVICE_FISSION is deprecated. Define CL_HPP_USE_CL_DEVICE_FISSION instead")
409# define CL_HPP_USE_CL_DEVICE_FISSION
410#endif
411#if !defined(CL_HPP_ENABLE_EXCEPTIONS) && defined(__CL_ENABLE_EXCEPTIONS)
412# pragma message("opencl.hpp: __CL_ENABLE_EXCEPTIONS is deprecated. Define CL_HPP_ENABLE_EXCEPTIONS instead")
413# define CL_HPP_ENABLE_EXCEPTIONS
414#endif
415#if !defined(CL_HPP_NO_STD_VECTOR) && defined(__NO_STD_VECTOR)
416# pragma message("opencl.hpp: __NO_STD_VECTOR is deprecated. Define CL_HPP_NO_STD_VECTOR instead")
417# define CL_HPP_NO_STD_VECTOR
418#endif
419#if !defined(CL_HPP_NO_STD_STRING) && defined(__NO_STD_STRING)
420# pragma message("opencl.hpp: __NO_STD_STRING is deprecated. Define CL_HPP_NO_STD_STRING instead")
421# define CL_HPP_NO_STD_STRING
422#endif
423#if defined(VECTOR_CLASS)
424# pragma message("opencl.hpp: VECTOR_CLASS is deprecated. Alias cl::vector instead")
425#endif
426#if defined(STRING_CLASS)
427# pragma message("opencl.hpp: STRING_CLASS is deprecated. Alias cl::string instead.")
428#endif
429#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) && defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
430# pragma message("opencl.hpp: __CL_USER_OVERRIDE_ERROR_STRINGS is deprecated. Define CL_HPP_USER_OVERRIDE_ERROR_STRINGS instead")
431# define CL_HPP_USER_OVERRIDE_ERROR_STRINGS
432#endif
433
434/* Warn about features that are no longer supported
435 */
436#if defined(__USE_DEV_VECTOR)
437# pragma message("opencl.hpp: __USE_DEV_VECTOR is no longer supported. Expect compilation errors")
438#endif
439#if defined(__USE_DEV_STRING)
440# pragma message("opencl.hpp: __USE_DEV_STRING is no longer supported. Expect compilation errors")
441#endif
442
443/* Detect which version to target */
444#if !defined(CL_HPP_TARGET_OPENCL_VERSION)
445# pragma message("opencl.hpp: CL_HPP_TARGET_OPENCL_VERSION is not defined. It will default to 300 (OpenCL 3.0)")
446# define CL_HPP_TARGET_OPENCL_VERSION 300
447#endif
448#if CL_HPP_TARGET_OPENCL_VERSION != 100 && \
449 CL_HPP_TARGET_OPENCL_VERSION != 110 && \
450 CL_HPP_TARGET_OPENCL_VERSION != 120 && \
451 CL_HPP_TARGET_OPENCL_VERSION != 200 && \
452 CL_HPP_TARGET_OPENCL_VERSION != 210 && \
453 CL_HPP_TARGET_OPENCL_VERSION != 220 && \
454 CL_HPP_TARGET_OPENCL_VERSION != 300
455# 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).")
456# undef CL_HPP_TARGET_OPENCL_VERSION
457# define CL_HPP_TARGET_OPENCL_VERSION 300
458#endif
459
460/* Forward target OpenCL version to C headers if necessary */
461#if defined(CL_TARGET_OPENCL_VERSION)
462/* Warn if prior definition of CL_TARGET_OPENCL_VERSION is lower than
463 * requested C++ bindings version */
464#if CL_TARGET_OPENCL_VERSION < CL_HPP_TARGET_OPENCL_VERSION
465# pragma message("CL_TARGET_OPENCL_VERSION is already defined as is lower than CL_HPP_TARGET_OPENCL_VERSION")
466#endif
467#else
468# define CL_TARGET_OPENCL_VERSION CL_HPP_TARGET_OPENCL_VERSION
469#endif
470
471#if !defined(CL_HPP_MINIMUM_OPENCL_VERSION)
472# define CL_HPP_MINIMUM_OPENCL_VERSION 200
473#endif
474#if CL_HPP_MINIMUM_OPENCL_VERSION != 100 && \
475 CL_HPP_MINIMUM_OPENCL_VERSION != 110 && \
476 CL_HPP_MINIMUM_OPENCL_VERSION != 120 && \
477 CL_HPP_MINIMUM_OPENCL_VERSION != 200 && \
478 CL_HPP_MINIMUM_OPENCL_VERSION != 210 && \
479 CL_HPP_MINIMUM_OPENCL_VERSION != 220 && \
480 CL_HPP_MINIMUM_OPENCL_VERSION != 300
481# 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")
482# undef CL_HPP_MINIMUM_OPENCL_VERSION
483# define CL_HPP_MINIMUM_OPENCL_VERSION 100
484#endif
485#if CL_HPP_MINIMUM_OPENCL_VERSION > CL_HPP_TARGET_OPENCL_VERSION
486# error "CL_HPP_MINIMUM_OPENCL_VERSION must not be greater than CL_HPP_TARGET_OPENCL_VERSION"
487#endif
488
489#if CL_HPP_MINIMUM_OPENCL_VERSION <= 100 && !defined(CL_USE_DEPRECATED_OPENCL_1_0_APIS)
490# define CL_USE_DEPRECATED_OPENCL_1_0_APIS
491#endif
492#if CL_HPP_MINIMUM_OPENCL_VERSION <= 110 && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
493# define CL_USE_DEPRECATED_OPENCL_1_1_APIS
494#endif
495#if CL_HPP_MINIMUM_OPENCL_VERSION <= 120 && !defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
496# define CL_USE_DEPRECATED_OPENCL_1_2_APIS
497#endif
498#if CL_HPP_MINIMUM_OPENCL_VERSION <= 200 && !defined(CL_USE_DEPRECATED_OPENCL_2_0_APIS)
499# define CL_USE_DEPRECATED_OPENCL_2_0_APIS
500#endif
501#if CL_HPP_MINIMUM_OPENCL_VERSION <= 210 && !defined(CL_USE_DEPRECATED_OPENCL_2_1_APIS)
502# define CL_USE_DEPRECATED_OPENCL_2_1_APIS
503#endif
504#if CL_HPP_MINIMUM_OPENCL_VERSION <= 220 && !defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
505# define CL_USE_DEPRECATED_OPENCL_2_2_APIS
506#endif
507
508#ifdef _WIN32
509
510#include <malloc.h>
511
512#if defined(CL_HPP_USE_DX_INTEROP)
513#include <CL/cl_d3d10.h>
514#include <CL/cl_dx9_media_sharing.h>
515#endif
516#endif // _WIN32
517
518#if defined(_MSC_VER)
519#include <intrin.h>
520#endif // _MSC_VER
521
522 // Check for a valid C++ version
523
524// Need to do both tests here because for some reason __cplusplus is not
525// updated in visual studio
526#if (!defined(_MSC_VER) && __cplusplus < 201103L) || (defined(_MSC_VER) && _MSC_VER < 1700)
527#error Visual studio 2013 or another C++11-supporting compiler required
528#endif
529
530//
531#if defined(CL_HPP_USE_CL_DEVICE_FISSION) || defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)
532#include <CL/cl_ext.h>
533#endif
534
535#if defined(__APPLE__) || defined(__MACOSX)
536#include <OpenCL/opencl.h>
537#else
538#include <CL/opencl.h>
539#endif // !__APPLE__
540
541#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L )
542#define CL_HPP_NOEXCEPT_ noexcept
543#else
544#define CL_HPP_NOEXCEPT_
545#endif
546
547#if __cplusplus >= 201703L
548# define CL_HPP_DEFINE_STATIC_MEMBER_ inline
549#elif defined(_MSC_VER)
550# define CL_HPP_DEFINE_STATIC_MEMBER_ __declspec(selectany)
551#elif defined(__MINGW32__)
552# define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((selectany))
553#else
554# define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((weak))
555#endif // !_MSC_VER
556
557// Define deprecated prefixes and suffixes to ensure compilation
558// in case they are not pre-defined
559#if !defined(CL_API_PREFIX__VERSION_1_1_DEPRECATED)
560#define CL_API_PREFIX__VERSION_1_1_DEPRECATED
561#endif // #if !defined(CL_API_PREFIX__VERSION_1_1_DEPRECATED)
562#if !defined(CL_API_SUFFIX__VERSION_1_1_DEPRECATED)
563#define CL_API_SUFFIX__VERSION_1_1_DEPRECATED
564#endif // #if !defined(CL_API_SUFFIX__VERSION_1_1_DEPRECATED)
565
566#if !defined(CL_API_PREFIX__VERSION_1_2_DEPRECATED)
567#define CL_API_PREFIX__VERSION_1_2_DEPRECATED
568#endif // #if !defined(CL_API_PREFIX__VERSION_1_2_DEPRECATED)
569#if !defined(CL_API_SUFFIX__VERSION_1_2_DEPRECATED)
570#define CL_API_SUFFIX__VERSION_1_2_DEPRECATED
571#endif // #if !defined(CL_API_SUFFIX__VERSION_1_2_DEPRECATED)
572
573#if !defined(CL_API_PREFIX__VERSION_2_2_DEPRECATED)
574#define CL_API_PREFIX__VERSION_2_2_DEPRECATED
575#endif // #if !defined(CL_API_PREFIX__VERSION_2_2_DEPRECATED)
576#if !defined(CL_API_SUFFIX__VERSION_2_2_DEPRECATED)
577#define CL_API_SUFFIX__VERSION_2_2_DEPRECATED
578#endif // #if !defined(CL_API_SUFFIX__VERSION_2_2_DEPRECATED)
579
580#if !defined(CL_CALLBACK)
581#define CL_CALLBACK
582#endif //CL_CALLBACK
583
584#include <utility>
585#include <limits>
586#include <iterator>
587#include <mutex>
588#include <cstring>
589#include <functional>
590
591
592// Define a size_type to represent a correctly resolved size_t
593#if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
594namespace cl {
595 using size_type = ::size_t;
596} // namespace cl
597#else // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
598namespace cl {
599 using size_type = size_t;
600} // namespace cl
601#endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
602
603
604#if defined(CL_HPP_ENABLE_EXCEPTIONS)
605#include <exception>
606#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
607
608#if !defined(CL_HPP_NO_STD_VECTOR)
609#include <vector>
610namespace cl {
611 template < class T, class Alloc = std::allocator<T> >
612 using vector = std::vector<T, Alloc>;
613} // namespace cl
614#endif // #if !defined(CL_HPP_NO_STD_VECTOR)
615
616#if !defined(CL_HPP_NO_STD_STRING)
617#include <string>
618namespace cl {
619 using string = std::string;
620} // namespace cl
621#endif // #if !defined(CL_HPP_NO_STD_STRING)
622
623#if CL_HPP_TARGET_OPENCL_VERSION >= 200
624
625#if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
626#include <memory>
627namespace cl {
628 // Replace unique_ptr and allocate_pointer for internal use
629 // to allow user to replace them
630 template<class T, class D>
631 using pointer = std::unique_ptr<T, D>;
632} // namespace cl
633#endif
634#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
635#if !defined(CL_HPP_NO_STD_ARRAY)
636#include <array>
637namespace cl {
638 template < class T, size_type N >
639 using array = std::array<T, N>;
640} // namespace cl
641#endif // #if !defined(CL_HPP_NO_STD_ARRAY)
642
643// Define size_type appropriately to allow backward-compatibility
644// use of the old size_t interface class
645#if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
646namespace cl {
647 namespace compatibility {
652 template <int N>
653 class size_t
654 {
655 private:
656 size_type data_[N];
657
658 public:
660 size_t()
661 {
662 for (int i = 0; i < N; ++i) {
663 data_[i] = 0;
664 }
665 }
666
667 size_t(const array<size_type, N> &rhs)
668 {
669 for (int i = 0; i < N; ++i) {
670 data_[i] = rhs[i];
671 }
672 }
673
674 size_type& operator[](int index)
675 {
676 return data_[index];
677 }
678
679 const size_type& operator[](int index) const
680 {
681 return data_[index];
682 }
683
685 operator size_type* () { return data_; }
686
688 operator const size_type* () const { return data_; }
689
690 operator array<size_type, N>() const
691 {
692 array<size_type, N> ret;
693
694 for (int i = 0; i < N; ++i) {
695 ret[i] = data_[i];
696 }
697 return ret;
698 }
699 };
700 } // namespace compatibility
701
702 template<int N>
703 using size_t = compatibility::size_t<N>;
704} // namespace cl
705#endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
706
707// Helper alias to avoid confusing the macros
708namespace cl {
709 namespace detail {
710 using size_t_array = array<size_type, 3>;
711 } // namespace detail
712} // namespace cl
713
714
720namespace cl {
721 class Memory;
722
723#define CL_HPP_INIT_CL_EXT_FCN_PTR_(name) \
724 if (!pfn_##name) { \
725 pfn_##name = (PFN_##name) \
726 clGetExtensionFunctionAddress(#name); \
727 if (!pfn_##name) { \
728 } \
729 }
730
731#define CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, name) \
732 if (!pfn_##name) { \
733 pfn_##name = (PFN_##name) \
734 clGetExtensionFunctionAddressForPlatform(platform, #name); \
735 if (!pfn_##name) { \
736 } \
737 }
738
739 class Program;
740 class Device;
741 class Context;
742 class CommandQueue;
743 class DeviceCommandQueue;
744 class Memory;
745 class Buffer;
746 class Pipe;
747
748#if defined(CL_HPP_ENABLE_EXCEPTIONS)
753 class Error : public std::exception
754 {
755 private:
756 cl_int err_;
757 const char * errStr_;
758 public:
768 Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr)
769 {}
770
771 ~Error() throw() {}
772
777 virtual const char * what() const throw ()
778 {
779 if (errStr_ == NULL) {
780 return "empty";
781 }
782 else {
783 return errStr_;
784 }
785 }
786
791 cl_int err(void) const { return err_; }
792 };
793#define CL_HPP_ERR_STR_(x) #x
794#else
795#define CL_HPP_ERR_STR_(x) NULL
796#endif // CL_HPP_ENABLE_EXCEPTIONS
797
798
799namespace detail
800{
801#if defined(CL_HPP_ENABLE_EXCEPTIONS)
802static inline cl_int errHandler (
803 cl_int err,
804 const char * errStr = NULL)
805{
806 if (err != CL_SUCCESS) {
807 throw Error(err, errStr);
808 }
809 return err;
810}
811#else
812static inline cl_int errHandler (cl_int err, const char * errStr = NULL)
813{
814 (void) errStr; // suppress unused variable warning
815 return err;
816}
817#endif // CL_HPP_ENABLE_EXCEPTIONS
818}
819
820
821
823#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
824#define __GET_DEVICE_INFO_ERR CL_HPP_ERR_STR_(clGetDeviceInfo)
825#define __GET_PLATFORM_INFO_ERR CL_HPP_ERR_STR_(clGetPlatformInfo)
826#define __GET_DEVICE_IDS_ERR CL_HPP_ERR_STR_(clGetDeviceIDs)
827#define __GET_PLATFORM_IDS_ERR CL_HPP_ERR_STR_(clGetPlatformIDs)
828#define __GET_CONTEXT_INFO_ERR CL_HPP_ERR_STR_(clGetContextInfo)
829#define __GET_EVENT_INFO_ERR CL_HPP_ERR_STR_(clGetEventInfo)
830#define __GET_EVENT_PROFILE_INFO_ERR CL_HPP_ERR_STR_(clGetEventProfileInfo)
831#define __GET_MEM_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetMemObjectInfo)
832#define __GET_IMAGE_INFO_ERR CL_HPP_ERR_STR_(clGetImageInfo)
833#define __GET_SAMPLER_INFO_ERR CL_HPP_ERR_STR_(clGetSamplerInfo)
834#define __GET_KERNEL_INFO_ERR CL_HPP_ERR_STR_(clGetKernelInfo)
835#if CL_HPP_TARGET_OPENCL_VERSION >= 120
836#define __GET_KERNEL_ARG_INFO_ERR CL_HPP_ERR_STR_(clGetKernelArgInfo)
837#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
838#if CL_HPP_TARGET_OPENCL_VERSION >= 200
839#define __GET_KERNEL_SUB_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelSubGroupInfo)
840#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
841#define __GET_KERNEL_WORK_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelWorkGroupInfo)
842#define __GET_PROGRAM_INFO_ERR CL_HPP_ERR_STR_(clGetProgramInfo)
843#define __GET_PROGRAM_BUILD_INFO_ERR CL_HPP_ERR_STR_(clGetProgramBuildInfo)
844#define __GET_COMMAND_QUEUE_INFO_ERR CL_HPP_ERR_STR_(clGetCommandQueueInfo)
845
846#define __CREATE_CONTEXT_ERR CL_HPP_ERR_STR_(clCreateContext)
847#define __CREATE_CONTEXT_FROM_TYPE_ERR CL_HPP_ERR_STR_(clCreateContextFromType)
848#define __GET_SUPPORTED_IMAGE_FORMATS_ERR CL_HPP_ERR_STR_(clGetSupportedImageFormats)
849
850#define __CREATE_BUFFER_ERR CL_HPP_ERR_STR_(clCreateBuffer)
851#define __COPY_ERR CL_HPP_ERR_STR_(cl::copy)
852#define __CREATE_SUBBUFFER_ERR CL_HPP_ERR_STR_(clCreateSubBuffer)
853#define __CREATE_GL_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
854#define __CREATE_GL_RENDER_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
855#define __GET_GL_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetGLObjectInfo)
856#if CL_HPP_TARGET_OPENCL_VERSION >= 120
857#define __CREATE_IMAGE_ERR CL_HPP_ERR_STR_(clCreateImage)
858#define __CREATE_GL_TEXTURE_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture)
859#define __IMAGE_DIMENSION_ERR CL_HPP_ERR_STR_(Incorrect image dimensions)
860#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
861#define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR CL_HPP_ERR_STR_(clSetMemObjectDestructorCallback)
862
863#define __CREATE_USER_EVENT_ERR CL_HPP_ERR_STR_(clCreateUserEvent)
864#define __SET_USER_EVENT_STATUS_ERR CL_HPP_ERR_STR_(clSetUserEventStatus)
865#define __SET_EVENT_CALLBACK_ERR CL_HPP_ERR_STR_(clSetEventCallback)
866#define __WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clWaitForEvents)
867
868#define __CREATE_KERNEL_ERR CL_HPP_ERR_STR_(clCreateKernel)
869#define __SET_KERNEL_ARGS_ERR CL_HPP_ERR_STR_(clSetKernelArg)
870#define __CREATE_PROGRAM_WITH_SOURCE_ERR CL_HPP_ERR_STR_(clCreateProgramWithSource)
871#if CL_HPP_TARGET_OPENCL_VERSION >= 200
872#define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
873#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
874#define __CREATE_PROGRAM_WITH_BINARY_ERR CL_HPP_ERR_STR_(clCreateProgramWithBinary)
875#if CL_HPP_TARGET_OPENCL_VERSION >= 210
876#define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
877#endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
878#if CL_HPP_TARGET_OPENCL_VERSION >= 120
879#define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR CL_HPP_ERR_STR_(clCreateProgramWithBuiltInKernels)
880#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
881#define __BUILD_PROGRAM_ERR CL_HPP_ERR_STR_(clBuildProgram)
882#if CL_HPP_TARGET_OPENCL_VERSION >= 120
883#define __COMPILE_PROGRAM_ERR CL_HPP_ERR_STR_(clCompileProgram)
884#define __LINK_PROGRAM_ERR CL_HPP_ERR_STR_(clLinkProgram)
885#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
886#define __CREATE_KERNELS_IN_PROGRAM_ERR CL_HPP_ERR_STR_(clCreateKernelsInProgram)
887
888#if CL_HPP_TARGET_OPENCL_VERSION >= 200
889#define __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateCommandQueueWithProperties)
890#define __CREATE_SAMPLER_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateSamplerWithProperties)
891#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
892#define __SET_COMMAND_QUEUE_PROPERTY_ERR CL_HPP_ERR_STR_(clSetCommandQueueProperty)
893#define __ENQUEUE_READ_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueReadBuffer)
894#define __ENQUEUE_READ_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueReadBufferRect)
895#define __ENQUEUE_WRITE_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueWriteBuffer)
896#define __ENQUEUE_WRITE_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueWriteBufferRect)
897#define __ENQEUE_COPY_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyBuffer)
898#define __ENQEUE_COPY_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferRect)
899#define __ENQUEUE_FILL_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueFillBuffer)
900#define __ENQUEUE_READ_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueReadImage)
901#define __ENQUEUE_WRITE_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueWriteImage)
902#define __ENQUEUE_COPY_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyImage)
903#define __ENQUEUE_FILL_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueFillImage)
904#define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyImageToBuffer)
905#define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferToImage)
906#define __ENQUEUE_MAP_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueMapBuffer)
907#define __ENQUEUE_MAP_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueMapImage)
908#define __ENQUEUE_UNMAP_MEM_OBJECT_ERR CL_HPP_ERR_STR_(clEnqueueUnMapMemObject)
909#define __ENQUEUE_NDRANGE_KERNEL_ERR CL_HPP_ERR_STR_(clEnqueueNDRangeKernel)
910#define __ENQUEUE_NATIVE_KERNEL CL_HPP_ERR_STR_(clEnqueueNativeKernel)
911#if CL_HPP_TARGET_OPENCL_VERSION >= 120
912#define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR CL_HPP_ERR_STR_(clEnqueueMigrateMemObjects)
913#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
914#if CL_HPP_TARGET_OPENCL_VERSION >= 210
915#define __ENQUEUE_MIGRATE_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMMigrateMem)
916#define __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clSetDefaultDeviceCommandQueue)
917#endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
918
919
920#define __ENQUEUE_ACQUIRE_GL_ERR CL_HPP_ERR_STR_(clEnqueueAcquireGLObjects)
921#define __ENQUEUE_RELEASE_GL_ERR CL_HPP_ERR_STR_(clEnqueueReleaseGLObjects)
922
923#define __CREATE_PIPE_ERR CL_HPP_ERR_STR_(clCreatePipe)
924#define __GET_PIPE_INFO_ERR CL_HPP_ERR_STR_(clGetPipeInfo)
925
926
927#define __RETAIN_ERR CL_HPP_ERR_STR_(Retain Object)
928#define __RELEASE_ERR CL_HPP_ERR_STR_(Release Object)
929#define __FLUSH_ERR CL_HPP_ERR_STR_(clFlush)
930#define __FINISH_ERR CL_HPP_ERR_STR_(clFinish)
931#define __VECTOR_CAPACITY_ERR CL_HPP_ERR_STR_(Vector capacity error)
932
933#if CL_HPP_TARGET_OPENCL_VERSION >= 210
934#define __GET_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetHostTimer)
935#define __GET_DEVICE_AND_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetDeviceAndHostTimer)
936#endif
937#if CL_HPP_TARGET_OPENCL_VERSION >= 220
938#define __SET_PROGRAM_RELEASE_CALLBACK_ERR CL_HPP_ERR_STR_(clSetProgramReleaseCallback)
939#define __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR CL_HPP_ERR_STR_(clSetProgramSpecializationConstant)
940#endif
941
942
946#if CL_HPP_TARGET_OPENCL_VERSION >= 120
947#define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevices)
948#else
949#define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevicesEXT)
950#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
951
955#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
956#define __ENQUEUE_MARKER_ERR CL_HPP_ERR_STR_(clEnqueueMarker)
957#define __ENQUEUE_WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clEnqueueWaitForEvents)
958#define __ENQUEUE_BARRIER_ERR CL_HPP_ERR_STR_(clEnqueueBarrier)
959#define __UNLOAD_COMPILER_ERR CL_HPP_ERR_STR_(clUnloadCompiler)
960#define __CREATE_GL_TEXTURE_2D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture2D)
961#define __CREATE_GL_TEXTURE_3D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture3D)
962#define __CREATE_IMAGE2D_ERR CL_HPP_ERR_STR_(clCreateImage2D)
963#define __CREATE_IMAGE3D_ERR CL_HPP_ERR_STR_(clCreateImage3D)
964#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
965
969#if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
970#define __CREATE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clCreateCommandQueue)
971#define __ENQUEUE_TASK_ERR CL_HPP_ERR_STR_(clEnqueueTask)
972#define __CREATE_SAMPLER_ERR CL_HPP_ERR_STR_(clCreateSampler)
973#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
974
978#if CL_HPP_TARGET_OPENCL_VERSION >= 120
979#define __ENQUEUE_MARKER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueMarkerWithWaitList)
980#define __ENQUEUE_BARRIER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueBarrierWithWaitList)
981#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
982
983#if CL_HPP_TARGET_OPENCL_VERSION >= 210
984#define __CLONE_KERNEL_ERR CL_HPP_ERR_STR_(clCloneKernel)
985#endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
986
987#endif // CL_HPP_USER_OVERRIDE_ERROR_STRINGS
989
990
991namespace detail {
992
993// Generic getInfoHelper. The final parameter is used to guide overload
994// resolution: the actual parameter passed is an int, which makes this
995// a worse conversion sequence than a specialization that declares the
996// parameter as an int.
997template<typename Functor, typename T>
998inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long)
999{
1000 return f(name, sizeof(T), param, NULL);
1001}
1002
1003// Specialized for getInfo<CL_PROGRAM_BINARIES>
1004// Assumes that the output vector was correctly resized on the way in
1005template <typename Func>
1006inline cl_int getInfoHelper(Func f, cl_uint name, vector<vector<unsigned char>>* param, int)
1007{
1008 if (name != CL_PROGRAM_BINARIES) {
1009 return CL_INVALID_VALUE;
1010 }
1011 if (param) {
1012 // Create array of pointers, calculate total size and pass pointer array in
1013 size_type numBinaries = param->size();
1014 vector<unsigned char*> binariesPointers(numBinaries);
1015
1016 for (size_type i = 0; i < numBinaries; ++i)
1017 {
1018 binariesPointers[i] = (*param)[i].data();
1019 }
1020
1021 cl_int err = f(name, numBinaries * sizeof(unsigned char*), binariesPointers.data(), NULL);
1022
1023 if (err != CL_SUCCESS) {
1024 return err;
1025 }
1026 }
1027
1028
1029 return CL_SUCCESS;
1030}
1031
1032// Specialized getInfoHelper for vector params
1033template <typename Func, typename T>
1034inline cl_int getInfoHelper(Func f, cl_uint name, vector<T>* param, long)
1035{
1036 size_type required;
1037 cl_int err = f(name, 0, NULL, &required);
1038 if (err != CL_SUCCESS) {
1039 return err;
1040 }
1041 const size_type elements = required / sizeof(T);
1042
1043 // Temporary to avoid changing param on an error
1044 vector<T> localData(elements);
1045 err = f(name, required, localData.data(), NULL);
1046 if (err != CL_SUCCESS) {
1047 return err;
1048 }
1049 if (param) {
1050 *param = std::move(localData);
1051 }
1052
1053 return CL_SUCCESS;
1054}
1055
1056/* Specialization for reference-counted types. This depends on the
1057 * existence of Wrapper<T>::cl_type, and none of the other types having the
1058 * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1059 * does not work, because when using a derived type (e.g. Context) the generic
1060 * template will provide a better match.
1061 */
1062template <typename Func, typename T>
1063inline cl_int getInfoHelper(
1064 Func f, cl_uint name, vector<T>* param, int, typename T::cl_type = 0)
1065{
1066 size_type required;
1067 cl_int err = f(name, 0, NULL, &required);
1068 if (err != CL_SUCCESS) {
1069 return err;
1070 }
1071
1072 const size_type elements = required / sizeof(typename T::cl_type);
1073
1074 vector<typename T::cl_type> value(elements);
1075 err = f(name, required, value.data(), NULL);
1076 if (err != CL_SUCCESS) {
1077 return err;
1078 }
1079
1080 if (param) {
1081 // Assign to convert CL type to T for each element
1082 param->resize(elements);
1083
1084 // Assign to param, constructing with retain behaviour
1085 // to correctly capture each underlying CL object
1086 for (size_type i = 0; i < elements; i++) {
1087 (*param)[i] = T(value[i], true);
1088 }
1089 }
1090 return CL_SUCCESS;
1091}
1092
1093// Specialized GetInfoHelper for string params
1094template <typename Func>
1095inline cl_int getInfoHelper(Func f, cl_uint name, string* param, long)
1096{
1097 size_type required;
1098 cl_int err = f(name, 0, NULL, &required);
1099 if (err != CL_SUCCESS) {
1100 return err;
1101 }
1102
1103 // std::string has a constant data member
1104 // a char vector does not
1105 if (required > 0) {
1106 vector<char> value(required);
1107 err = f(name, required, value.data(), NULL);
1108 if (err != CL_SUCCESS) {
1109 return err;
1110 }
1111 if (param) {
1112 param->assign(begin(value), prev(end(value)));
1113 }
1114 }
1115 else if (param) {
1116 param->assign("");
1117 }
1118 return CL_SUCCESS;
1119}
1120
1121// Specialized GetInfoHelper for clsize_t params
1122template <typename Func, size_type N>
1123inline cl_int getInfoHelper(Func f, cl_uint name, array<size_type, N>* param, long)
1124{
1125 size_type required;
1126 cl_int err = f(name, 0, NULL, &required);
1127 if (err != CL_SUCCESS) {
1128 return err;
1129 }
1130
1131 size_type elements = required / sizeof(size_type);
1132 vector<size_type> value(elements, 0);
1133
1134 err = f(name, required, value.data(), NULL);
1135 if (err != CL_SUCCESS) {
1136 return err;
1137 }
1138
1139 // Bound the copy with N to prevent overruns
1140 // if passed N > than the amount copied
1141 if (elements > N) {
1142 elements = N;
1143 }
1144 for (size_type i = 0; i < elements; ++i) {
1145 (*param)[i] = value[i];
1146 }
1147
1148 return CL_SUCCESS;
1149}
1150
1151template<typename T> struct ReferenceHandler;
1152
1153/* Specialization for reference-counted types. This depends on the
1154 * existence of Wrapper<T>::cl_type, and none of the other types having the
1155 * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1156 * does not work, because when using a derived type (e.g. Context) the generic
1157 * template will provide a better match.
1158 */
1159template<typename Func, typename T>
1160inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0)
1161{
1162 typename T::cl_type value;
1163 cl_int err = f(name, sizeof(value), &value, NULL);
1164 if (err != CL_SUCCESS) {
1165 return err;
1166 }
1167 *param = value;
1168 if (value != NULL)
1169 {
1170 err = param->retain();
1171 if (err != CL_SUCCESS) {
1172 return err;
1173 }
1174 }
1175 return CL_SUCCESS;
1176}
1177
1178#define CL_HPP_PARAM_NAME_INFO_1_0_(F) \
1179 F(cl_platform_info, CL_PLATFORM_PROFILE, string) \
1180 F(cl_platform_info, CL_PLATFORM_VERSION, string) \
1181 F(cl_platform_info, CL_PLATFORM_NAME, string) \
1182 F(cl_platform_info, CL_PLATFORM_VENDOR, string) \
1183 F(cl_platform_info, CL_PLATFORM_EXTENSIONS, string) \
1184 \
1185 F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
1186 F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
1187 F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
1188 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
1189 F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, size_type) \
1190 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, cl::vector<size_type>) \
1191 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
1192 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
1193 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
1194 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
1195 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
1196 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
1197 F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
1198 F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \
1199 F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
1200 F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
1201 F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
1202 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, size_type) \
1203 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, size_type) \
1204 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, size_type) \
1205 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, size_type) \
1206 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, size_type) \
1207 F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \
1208 F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, size_type) \
1209 F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
1210 F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
1211 F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
1212 F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
1213 F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
1214 F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
1215 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
1216 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
1217 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
1218 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
1219 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
1220 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
1221 F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
1222 F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
1223 F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
1224 F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, size_type) \
1225 F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
1226 F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
1227 F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
1228 F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
1229 F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
1230 F(cl_device_info, CL_DEVICE_NAME, string) \
1231 F(cl_device_info, CL_DEVICE_VENDOR, string) \
1232 F(cl_device_info, CL_DRIVER_VERSION, string) \
1233 F(cl_device_info, CL_DEVICE_PROFILE, string) \
1234 F(cl_device_info, CL_DEVICE_VERSION, string) \
1235 F(cl_device_info, CL_DEVICE_EXTENSIONS, string) \
1236 \
1237 F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
1238 F(cl_context_info, CL_CONTEXT_DEVICES, cl::vector<Device>) \
1239 F(cl_context_info, CL_CONTEXT_PROPERTIES, cl::vector<cl_context_properties>) \
1240 \
1241 F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
1242 F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
1243 F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
1244 F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \
1245 \
1246 F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
1247 F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
1248 F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
1249 F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
1250 \
1251 F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
1252 F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
1253 F(cl_mem_info, CL_MEM_SIZE, size_type) \
1254 F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
1255 F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
1256 F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
1257 F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
1258 \
1259 F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
1260 F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, size_type) \
1261 F(cl_image_info, CL_IMAGE_ROW_PITCH, size_type) \
1262 F(cl_image_info, CL_IMAGE_SLICE_PITCH, size_type) \
1263 F(cl_image_info, CL_IMAGE_WIDTH, size_type) \
1264 F(cl_image_info, CL_IMAGE_HEIGHT, size_type) \
1265 F(cl_image_info, CL_IMAGE_DEPTH, size_type) \
1266 \
1267 F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
1268 F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
1269 F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \
1270 F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \
1271 F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \
1272 \
1273 F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
1274 F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
1275 F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
1276 F(cl_program_info, CL_PROGRAM_DEVICES, cl::vector<Device>) \
1277 F(cl_program_info, CL_PROGRAM_SOURCE, string) \
1278 F(cl_program_info, CL_PROGRAM_BINARY_SIZES, cl::vector<size_type>) \
1279 F(cl_program_info, CL_PROGRAM_BINARIES, cl::vector<cl::vector<unsigned char>>) \
1280 \
1281 F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
1282 F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, string) \
1283 F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, string) \
1284 \
1285 F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, string) \
1286 F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
1287 F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
1288 F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
1289 F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
1290 \
1291 F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, size_type) \
1292 F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::detail::size_t_array) \
1293 F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
1294 \
1295 F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
1296 F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
1297 F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
1298 F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
1299
1300
1301#define CL_HPP_PARAM_NAME_INFO_1_1_(F) \
1302 F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
1303 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
1304 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
1305 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
1306 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
1307 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
1308 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
1309 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
1310 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
1311 F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, string) \
1312 \
1313 F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
1314 F(cl_mem_info, CL_MEM_OFFSET, size_type) \
1315 \
1316 F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1317 F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
1318 \
1319 F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
1320
1321#define CL_HPP_PARAM_NAME_INFO_1_2_(F) \
1322 F(cl_program_info, CL_PROGRAM_NUM_KERNELS, size_type) \
1323 F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, string) \
1324 \
1325 F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \
1326 \
1327 F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, string) \
1328 \
1329 F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \
1330 F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \
1331 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, string) \
1332 F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, string) \
1333 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \
1334 \
1335 F(cl_kernel_work_group_info, CL_KERNEL_GLOBAL_WORK_SIZE, cl::detail::size_t_array) \
1336 \
1337 F(cl_device_info, CL_DEVICE_LINKER_AVAILABLE, cl_bool) \
1338 F(cl_device_info, CL_DEVICE_IMAGE_MAX_BUFFER_SIZE, size_type) \
1339 F(cl_device_info, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, size_type) \
1340 F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl::Device) \
1341 F(cl_device_info, CL_DEVICE_PARTITION_MAX_SUB_DEVICES, cl_uint) \
1342 F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, cl::vector<cl_device_partition_property>) \
1343 F(cl_device_info, CL_DEVICE_PARTITION_TYPE, cl::vector<cl_device_partition_property>) \
1344 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \
1345 F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, cl_bool) \
1346 F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \
1347 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, string) \
1348 F(cl_device_info, CL_DEVICE_PRINTF_BUFFER_SIZE, size_type) \
1349 \
1350 F(cl_image_info, CL_IMAGE_ARRAY_SIZE, size_type) \
1351 F(cl_image_info, CL_IMAGE_NUM_MIP_LEVELS, cl_uint) \
1352 F(cl_image_info, CL_IMAGE_NUM_SAMPLES, cl_uint)
1353
1354#define CL_HPP_PARAM_NAME_INFO_2_0_(F) \
1355 F(cl_device_info, CL_DEVICE_QUEUE_ON_HOST_PROPERTIES, cl_command_queue_properties) \
1356 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES, cl_command_queue_properties) \
1357 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, cl_uint) \
1358 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, cl_uint) \
1359 F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_QUEUES, cl_uint) \
1360 F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_EVENTS, cl_uint) \
1361 F(cl_device_info, CL_DEVICE_MAX_PIPE_ARGS, cl_uint) \
1362 F(cl_device_info, CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS, cl_uint) \
1363 F(cl_device_info, CL_DEVICE_PIPE_MAX_PACKET_SIZE, cl_uint) \
1364 F(cl_device_info, CL_DEVICE_SVM_CAPABILITIES, cl_device_svm_capabilities) \
1365 F(cl_device_info, CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT, cl_uint) \
1366 F(cl_device_info, CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT, cl_uint) \
1367 F(cl_device_info, CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT, cl_uint) \
1368 F(cl_device_info, CL_DEVICE_IMAGE_PITCH_ALIGNMENT, cl_uint) \
1369 F(cl_device_info, CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT, cl_uint) \
1370 F(cl_device_info, CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS, cl_uint ) \
1371 F(cl_device_info, CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE, size_type ) \
1372 F(cl_device_info, CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE, size_type ) \
1373 F(cl_profiling_info, CL_PROFILING_COMMAND_COMPLETE, cl_ulong) \
1374 F(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM, cl_bool) \
1375 F(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_SVM_PTRS, void**) \
1376 F(cl_command_queue_info, CL_QUEUE_SIZE, cl_uint) \
1377 F(cl_mem_info, CL_MEM_USES_SVM_POINTER, cl_bool) \
1378 F(cl_program_build_info, CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, size_type) \
1379 F(cl_pipe_info, CL_PIPE_PACKET_SIZE, cl_uint) \
1380 F(cl_pipe_info, CL_PIPE_MAX_PACKETS, cl_uint)
1381
1382#define CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(F) \
1383 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR, size_type) \
1384 F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR, size_type)
1385
1386#define CL_HPP_PARAM_NAME_INFO_IL_KHR_(F) \
1387 F(cl_device_info, CL_DEVICE_IL_VERSION_KHR, string) \
1388 F(cl_program_info, CL_PROGRAM_IL_KHR, cl::vector<unsigned char>)
1389
1390#define CL_HPP_PARAM_NAME_INFO_2_1_(F) \
1391 F(cl_platform_info, CL_PLATFORM_HOST_TIMER_RESOLUTION, cl_ulong) \
1392 F(cl_program_info, CL_PROGRAM_IL, cl::vector<unsigned char>) \
1393 F(cl_device_info, CL_DEVICE_MAX_NUM_SUB_GROUPS, cl_uint) \
1394 F(cl_device_info, CL_DEVICE_IL_VERSION, string) \
1395 F(cl_device_info, CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS, cl_bool) \
1396 F(cl_command_queue_info, CL_QUEUE_DEVICE_DEFAULT, cl::DeviceCommandQueue) \
1397 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE, size_type) \
1398 F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE, size_type) \
1399 F(cl_kernel_sub_group_info, CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT, cl::detail::size_t_array) \
1400 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_NUM_SUB_GROUPS, size_type) \
1401 F(cl_kernel_sub_group_info, CL_KERNEL_COMPILE_NUM_SUB_GROUPS, size_type)
1402
1403#define CL_HPP_PARAM_NAME_INFO_2_2_(F) \
1404 F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_CTORS_PRESENT, cl_bool) \
1405 F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_DTORS_PRESENT, cl_bool)
1406
1407#define CL_HPP_PARAM_NAME_DEVICE_FISSION_(F) \
1408 F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
1409 F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, cl::vector<cl_device_partition_property_ext>) \
1410 F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, cl::vector<cl_device_partition_property_ext>) \
1411 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
1412 F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, cl::vector<cl_device_partition_property_ext>)
1413
1414#define CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_CL3_SHARED_(F) \
1415 F(cl_platform_info, CL_PLATFORM_NUMERIC_VERSION_KHR, cl_version_khr) \
1416 F(cl_platform_info, CL_PLATFORM_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1417 \
1418 F(cl_device_info, CL_DEVICE_NUMERIC_VERSION_KHR, cl_version_khr) \
1419 F(cl_device_info, CL_DEVICE_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1420 F(cl_device_info, CL_DEVICE_ILS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1421 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>)
1422
1423#define CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_KHRONLY_(F) \
1424 F(cl_device_info, CL_DEVICE_OPENCL_C_NUMERIC_VERSION_KHR, cl_version_khr)
1425
1426#define CL_HPP_PARAM_NAME_INFO_3_0_(F) \
1427 F(cl_platform_info, CL_PLATFORM_NUMERIC_VERSION, cl_version) \
1428 F(cl_platform_info, CL_PLATFORM_EXTENSIONS_WITH_VERSION, cl::vector<cl_name_version>) \
1429 \
1430 F(cl_device_info, CL_DEVICE_NUMERIC_VERSION, cl_version) \
1431 F(cl_device_info, CL_DEVICE_EXTENSIONS_WITH_VERSION, cl::vector<cl_name_version>) \
1432 F(cl_device_info, CL_DEVICE_ILS_WITH_VERSION, cl::vector<cl_name_version>) \
1433 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION, cl::vector<cl_name_version>) \
1434 F(cl_device_info, CL_DEVICE_ATOMIC_MEMORY_CAPABILITIES, cl_device_atomic_capabilities) \
1435 F(cl_device_info, CL_DEVICE_ATOMIC_FENCE_CAPABILITIES, cl_device_atomic_capabilities) \
1436 F(cl_device_info, CL_DEVICE_NON_UNIFORM_WORK_GROUP_SUPPORT, cl_bool) \
1437 F(cl_device_info, CL_DEVICE_OPENCL_C_ALL_VERSIONS, cl::vector<cl_name_version>) \
1438 F(cl_device_info, CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1439 F(cl_device_info, CL_DEVICE_WORK_GROUP_COLLECTIVE_FUNCTIONS_SUPPORT, cl_bool) \
1440 F(cl_device_info, CL_DEVICE_GENERIC_ADDRESS_SPACE_SUPPORT, cl_bool) \
1441 F(cl_device_info, CL_DEVICE_OPENCL_C_FEATURES, cl::vector<cl_name_version>) \
1442 F(cl_device_info, CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES, cl_device_device_enqueue_capabilities) \
1443 F(cl_device_info, CL_DEVICE_PIPE_SUPPORT, cl_bool) \
1444 F(cl_device_info, CL_DEVICE_LATEST_CONFORMANCE_VERSION_PASSED, string) \
1445 \
1446 F(cl_command_queue_info, CL_QUEUE_PROPERTIES_ARRAY, cl::vector<cl_queue_properties>) \
1447 F(cl_mem_info, CL_MEM_PROPERTIES, cl::vector<cl_mem_properties>) \
1448 F(cl_pipe_info, CL_PIPE_PROPERTIES, cl::vector<cl_pipe_properties>) \
1449 F(cl_sampler_info, CL_SAMPLER_PROPERTIES, cl::vector<cl_sampler_properties>)
1450
1451template <typename enum_type, cl_int Name>
1453
1454#define CL_HPP_DECLARE_PARAM_TRAITS_(token, param_name, T) \
1455struct token; \
1456template<> \
1457struct param_traits<detail:: token,param_name> \
1458{ \
1459 enum { value = param_name }; \
1460 typedef T param_type; \
1461};
1462
1463CL_HPP_PARAM_NAME_INFO_1_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1464#if CL_HPP_TARGET_OPENCL_VERSION >= 110
1465CL_HPP_PARAM_NAME_INFO_1_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1466#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
1467#if CL_HPP_TARGET_OPENCL_VERSION >= 120
1468CL_HPP_PARAM_NAME_INFO_1_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1469#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1470#if CL_HPP_TARGET_OPENCL_VERSION >= 200
1471CL_HPP_PARAM_NAME_INFO_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1472#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
1473#if CL_HPP_TARGET_OPENCL_VERSION >= 210
1474CL_HPP_PARAM_NAME_INFO_2_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1475#endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
1476#if CL_HPP_TARGET_OPENCL_VERSION >= 220
1477CL_HPP_PARAM_NAME_INFO_2_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1478#endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
1479#if CL_HPP_TARGET_OPENCL_VERSION >= 300
1480CL_HPP_PARAM_NAME_INFO_3_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1481#endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
1482
1483#if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1484CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1485#endif // #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1486
1487#if defined(CL_HPP_USE_IL_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1488CL_HPP_PARAM_NAME_INFO_IL_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1489#endif // #if defined(CL_HPP_USE_IL_KHR)
1490
1491
1492// Flags deprecated in OpenCL 2.0
1493#define CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(F) \
1494 F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties)
1495
1496#define CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(F) \
1497 F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool)
1498
1499#define CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(F) \
1500 F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer)
1501
1502// Include deprecated query flags based on versions
1503// Only include deprecated 1.0 flags if 2.0 not active as there is an enum clash
1504#if CL_HPP_TARGET_OPENCL_VERSION > 100 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 && CL_HPP_TARGET_OPENCL_VERSION < 200
1505CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1506#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 110
1507#if CL_HPP_TARGET_OPENCL_VERSION > 110 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1508CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1509#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1510#if CL_HPP_TARGET_OPENCL_VERSION > 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1511CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1512#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
1513
1514#if defined(CL_HPP_USE_CL_DEVICE_FISSION)
1515CL_HPP_PARAM_NAME_DEVICE_FISSION_(CL_HPP_DECLARE_PARAM_TRAITS_);
1516#endif // CL_HPP_USE_CL_DEVICE_FISSION
1517
1518#if defined(cl_khr_extended_versioning)
1519#if CL_HPP_TARGET_OPENCL_VERSION < 300
1520CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_CL3_SHARED_(CL_HPP_DECLARE_PARAM_TRAITS_)
1521#endif // CL_HPP_TARGET_OPENCL_VERSION < 300
1522CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_KHRONLY_(CL_HPP_DECLARE_PARAM_TRAITS_)
1523#endif // cl_khr_extended_versioning
1524
1525#if defined(cl_khr_device_uuid)
1526using uuid_array = array<cl_uchar, CL_UUID_SIZE_KHR>;
1527using luid_array = array<cl_uchar, CL_LUID_SIZE_KHR>;
1528CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_UUID_KHR, uuid_array)
1529CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DRIVER_UUID_KHR, uuid_array)
1530CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LUID_VALID_KHR, cl_bool)
1531CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LUID_KHR, luid_array)
1532CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_NODE_MASK_KHR, cl_uint)
1533#endif
1534
1535#if defined(cl_khr_pci_bus_info)
1536CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PCI_BUS_INFO_KHR, cl_device_pci_bus_info_khr)
1537#endif
1538
1539#if defined(cl_khr_integer_dot_product)
1540CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGER_DOT_PRODUCT_CAPABILITIES_KHR, cl_device_integer_dot_product_capabilities_khr)
1541#if defined(CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_8BIT_KHR)
1542CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_8BIT_KHR, cl_device_integer_dot_product_acceleration_properties_khr)
1543CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_4x8BIT_PACKED_KHR, cl_device_integer_dot_product_acceleration_properties_khr)
1544#endif // defined(CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_8BIT_KHR)
1545#endif // defined(cl_khr_integer_dot_product)
1546
1547#ifdef CL_PLATFORM_ICD_SUFFIX_KHR
1548CL_HPP_DECLARE_PARAM_TRAITS_(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, string)
1549#endif
1550
1551#ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
1552CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong)
1553#endif
1554#ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
1555CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, vector<size_type>)
1556#endif
1557#ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
1558CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint)
1559#endif
1560#ifdef CL_DEVICE_SIMD_WIDTH_AMD
1561CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint)
1562#endif
1563#ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD
1564CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint)
1565#endif
1566#ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD
1567CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint)
1568#endif
1569#ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
1570CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint)
1571#endif
1572#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
1573CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint)
1574#endif
1575#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
1576CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint)
1577#endif
1578#ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
1579CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint)
1580#endif
1581#ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
1582CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint)
1583#endif
1584#ifdef CL_DEVICE_BOARD_NAME_AMD
1585CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_BOARD_NAME_AMD, string)
1586#endif
1587
1588#ifdef CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM
1589CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM, cl_ulong)
1590#endif
1591#ifdef CL_DEVICE_JOB_SLOTS_ARM
1592CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_JOB_SLOTS_ARM, cl_uint)
1593#endif
1594#ifdef CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM
1595CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM, cl_bitfield)
1596#endif
1597#ifdef CL_DEVICE_SUPPORTED_REGISTER_ALLOCATIONS_ARM
1598CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SUPPORTED_REGISTER_ALLOCATIONS_ARM, vector<cl_uint>)
1599#endif
1600#ifdef CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_ARM
1601CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_ARM, cl_uint)
1602#endif
1603#ifdef CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM
1604CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM, cl_int)
1605#endif
1606
1607#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
1608CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint)
1609#endif
1610#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV
1611CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint)
1612#endif
1613#ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV
1614CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint)
1615#endif
1616#ifdef CL_DEVICE_WARP_SIZE_NV
1617CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint)
1618#endif
1619#ifdef CL_DEVICE_GPU_OVERLAP_NV
1620CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool)
1621#endif
1622#ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV
1623CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool)
1624#endif
1625#ifdef CL_DEVICE_INTEGRATED_MEMORY_NV
1626CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool)
1627#endif
1628
1629// Convenience functions
1630
1631template <typename Func, typename T>
1632inline cl_int
1633getInfo(Func f, cl_uint name, T* param)
1634{
1635 return getInfoHelper(f, name, param, 0);
1636}
1637
1638template <typename Func, typename Arg0>
1640{
1641 Func f_; const Arg0& arg0_;
1642 cl_int operator ()(
1643 cl_uint param, size_type size, void* value, size_type* size_ret)
1644 { return f_(arg0_, param, size, value, size_ret); }
1645};
1646
1647template <typename Func, typename Arg0, typename Arg1>
1649{
1650 Func f_; const Arg0& arg0_; const Arg1& arg1_;
1651 cl_int operator ()(
1652 cl_uint param, size_type size, void* value, size_type* size_ret)
1653 { return f_(arg0_, arg1_, param, size, value, size_ret); }
1654};
1655
1656template <typename Func, typename Arg0, typename T>
1657inline cl_int
1658getInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
1659{
1660 GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
1661 return getInfoHelper(f0, name, param, 0);
1662}
1663
1664template <typename Func, typename Arg0, typename Arg1, typename T>
1665inline cl_int
1666getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
1667{
1668 GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
1669 return getInfoHelper(f0, name, param, 0);
1670}
1671
1672
1673template<typename T>
1675{ };
1676
1677#if CL_HPP_TARGET_OPENCL_VERSION >= 120
1681template <>
1682struct ReferenceHandler<cl_device_id>
1683{
1693 static cl_int retain(cl_device_id device)
1694 { return ::clRetainDevice(device); }
1704 static cl_int release(cl_device_id device)
1705 { return ::clReleaseDevice(device); }
1706};
1707#else // CL_HPP_TARGET_OPENCL_VERSION >= 120
1711template <>
1712struct ReferenceHandler<cl_device_id>
1713{
1714 // cl_device_id does not have retain().
1715 static cl_int retain(cl_device_id)
1716 { return CL_SUCCESS; }
1717 // cl_device_id does not have release().
1718 static cl_int release(cl_device_id)
1719 { return CL_SUCCESS; }
1720};
1721#endif // ! (CL_HPP_TARGET_OPENCL_VERSION >= 120)
1722
1723template <>
1724struct ReferenceHandler<cl_platform_id>
1725{
1726 // cl_platform_id does not have retain().
1727 static cl_int retain(cl_platform_id)
1728 { return CL_SUCCESS; }
1729 // cl_platform_id does not have release().
1730 static cl_int release(cl_platform_id)
1731 { return CL_SUCCESS; }
1732};
1733
1734template <>
1735struct ReferenceHandler<cl_context>
1736{
1737 static cl_int retain(cl_context context)
1738 { return ::clRetainContext(context); }
1739 static cl_int release(cl_context context)
1740 { return ::clReleaseContext(context); }
1741};
1742
1743template <>
1744struct ReferenceHandler<cl_command_queue>
1745{
1746 static cl_int retain(cl_command_queue queue)
1747 { return ::clRetainCommandQueue(queue); }
1748 static cl_int release(cl_command_queue queue)
1749 { return ::clReleaseCommandQueue(queue); }
1750};
1751
1752template <>
1753struct ReferenceHandler<cl_mem>
1754{
1755 static cl_int retain(cl_mem memory)
1756 { return ::clRetainMemObject(memory); }
1757 static cl_int release(cl_mem memory)
1758 { return ::clReleaseMemObject(memory); }
1759};
1760
1761template <>
1762struct ReferenceHandler<cl_sampler>
1763{
1764 static cl_int retain(cl_sampler sampler)
1765 { return ::clRetainSampler(sampler); }
1766 static cl_int release(cl_sampler sampler)
1767 { return ::clReleaseSampler(sampler); }
1768};
1769
1770template <>
1771struct ReferenceHandler<cl_program>
1772{
1773 static cl_int retain(cl_program program)
1774 { return ::clRetainProgram(program); }
1775 static cl_int release(cl_program program)
1776 { return ::clReleaseProgram(program); }
1777};
1778
1779template <>
1780struct ReferenceHandler<cl_kernel>
1781{
1782 static cl_int retain(cl_kernel kernel)
1783 { return ::clRetainKernel(kernel); }
1784 static cl_int release(cl_kernel kernel)
1785 { return ::clReleaseKernel(kernel); }
1786};
1787
1788template <>
1789struct ReferenceHandler<cl_event>
1790{
1791 static cl_int retain(cl_event event)
1792 { return ::clRetainEvent(event); }
1793 static cl_int release(cl_event event)
1794 { return ::clReleaseEvent(event); }
1795};
1796
1797
1798#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1799// Extracts version number with major in the upper 16 bits, minor in the lower 16
1800static cl_uint getVersion(const vector<char> &versionInfo)
1801{
1802 int highVersion = 0;
1803 int lowVersion = 0;
1804 int index = 7;
1805 while(versionInfo[index] != '.' ) {
1806 highVersion *= 10;
1807 highVersion += versionInfo[index]-'0';
1808 ++index;
1809 }
1810 ++index;
1811 while(versionInfo[index] != ' ' && versionInfo[index] != '\0') {
1812 lowVersion *= 10;
1813 lowVersion += versionInfo[index]-'0';
1814 ++index;
1815 }
1816 return (highVersion << 16) | lowVersion;
1817}
1818
1819static cl_uint getPlatformVersion(cl_platform_id platform)
1820{
1821 size_type size = 0;
1822 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size);
1823
1824 vector<char> versionInfo(size);
1825 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, versionInfo.data(), &size);
1826 return getVersion(versionInfo);
1827}
1828
1829static cl_uint getDevicePlatformVersion(cl_device_id device)
1830{
1831 cl_platform_id platform;
1832 clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL);
1833 return getPlatformVersion(platform);
1834}
1835
1836static cl_uint getContextPlatformVersion(cl_context context)
1837{
1838 // The platform cannot be queried directly, so we first have to grab a
1839 // device and obtain its context
1840 size_type size = 0;
1841 clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size);
1842 if (size == 0)
1843 return 0;
1844 vector<cl_device_id> devices(size/sizeof(cl_device_id));
1845 clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices.data(), NULL);
1846 return getDevicePlatformVersion(devices[0]);
1847}
1848#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1849
1850template <typename T>
1852{
1853public:
1854 typedef T cl_type;
1855
1856protected:
1857 cl_type object_;
1858
1859public:
1860 Wrapper() : object_(NULL) { }
1861
1862 Wrapper(const cl_type &obj, bool retainObject) : object_(obj)
1863 {
1864 if (retainObject) {
1865 detail::errHandler(retain(), __RETAIN_ERR);
1866 }
1867 }
1868
1869 ~Wrapper()
1870 {
1871 if (object_ != NULL) { release(); }
1872 }
1873
1874 Wrapper(const Wrapper<cl_type>& rhs)
1875 {
1876 object_ = rhs.object_;
1877 detail::errHandler(retain(), __RETAIN_ERR);
1878 }
1879
1880 Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT_
1881 {
1882 object_ = rhs.object_;
1883 rhs.object_ = NULL;
1884 }
1885
1886 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
1887 {
1888 if (this != &rhs) {
1889 detail::errHandler(release(), __RELEASE_ERR);
1890 object_ = rhs.object_;
1891 detail::errHandler(retain(), __RETAIN_ERR);
1892 }
1893 return *this;
1894 }
1895
1896 Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
1897 {
1898 if (this != &rhs) {
1899 detail::errHandler(release(), __RELEASE_ERR);
1900 object_ = rhs.object_;
1901 rhs.object_ = NULL;
1902 }
1903 return *this;
1904 }
1905
1906 Wrapper<cl_type>& operator = (const cl_type &rhs)
1907 {
1908 detail::errHandler(release(), __RELEASE_ERR);
1909 object_ = rhs;
1910 return *this;
1911 }
1912
1913 const cl_type& operator ()() const { return object_; }
1914
1915 cl_type& operator ()() { return object_; }
1916
1917 cl_type get() const { return object_; }
1918
1919protected:
1920 template<typename Func, typename U>
1921 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
1922
1923 cl_int retain() const
1924 {
1925 if (object_ != nullptr) {
1926 return ReferenceHandler<cl_type>::retain(object_);
1927 }
1928 else {
1929 return CL_SUCCESS;
1930 }
1931 }
1932
1933 cl_int release() const
1934 {
1935 if (object_ != nullptr) {
1936 return ReferenceHandler<cl_type>::release(object_);
1937 }
1938 else {
1939 return CL_SUCCESS;
1940 }
1941 }
1942};
1943
1944template <>
1945class Wrapper<cl_device_id>
1946{
1947public:
1948 typedef cl_device_id cl_type;
1949
1950protected:
1951 cl_type object_;
1952 bool referenceCountable_;
1953
1954 static bool isReferenceCountable(cl_device_id device)
1955 {
1956 bool retVal = false;
1957#if CL_HPP_TARGET_OPENCL_VERSION >= 120
1958#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
1959 if (device != NULL) {
1960 int version = getDevicePlatformVersion(device);
1961 if(version > ((1 << 16) + 1)) {
1962 retVal = true;
1963 }
1964 }
1965#else // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1966 retVal = true;
1967#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1968#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1969 (void)device;
1970 return retVal;
1971 }
1972
1973public:
1974 Wrapper() : object_(NULL), referenceCountable_(false)
1975 {
1976 }
1977
1978 Wrapper(const cl_type &obj, bool retainObject) :
1979 object_(obj),
1980 referenceCountable_(false)
1981 {
1982 referenceCountable_ = isReferenceCountable(obj);
1983
1984 if (retainObject) {
1985 detail::errHandler(retain(), __RETAIN_ERR);
1986 }
1987 }
1988
1989 ~Wrapper()
1990 {
1991 release();
1992 }
1993
1994 Wrapper(const Wrapper<cl_type>& rhs)
1995 {
1996 object_ = rhs.object_;
1997 referenceCountable_ = isReferenceCountable(object_);
1998 detail::errHandler(retain(), __RETAIN_ERR);
1999 }
2000
2001 Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT_
2002 {
2003 object_ = rhs.object_;
2004 referenceCountable_ = rhs.referenceCountable_;
2005 rhs.object_ = NULL;
2006 rhs.referenceCountable_ = false;
2007 }
2008
2009 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
2010 {
2011 if (this != &rhs) {
2012 detail::errHandler(release(), __RELEASE_ERR);
2013 object_ = rhs.object_;
2014 referenceCountable_ = rhs.referenceCountable_;
2015 detail::errHandler(retain(), __RETAIN_ERR);
2016 }
2017 return *this;
2018 }
2019
2020 Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
2021 {
2022 if (this != &rhs) {
2023 detail::errHandler(release(), __RELEASE_ERR);
2024 object_ = rhs.object_;
2025 referenceCountable_ = rhs.referenceCountable_;
2026 rhs.object_ = NULL;
2027 rhs.referenceCountable_ = false;
2028 }
2029 return *this;
2030 }
2031
2032 Wrapper<cl_type>& operator = (const cl_type &rhs)
2033 {
2034 detail::errHandler(release(), __RELEASE_ERR);
2035 object_ = rhs;
2036 referenceCountable_ = isReferenceCountable(object_);
2037 return *this;
2038 }
2039
2040 const cl_type& operator ()() const { return object_; }
2041
2042 cl_type& operator ()() { return object_; }
2043
2044 cl_type get() const { return object_; }
2045
2046protected:
2047 template<typename Func, typename U>
2048 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
2049
2050 template<typename Func, typename U>
2051 friend inline cl_int getInfoHelper(Func, cl_uint, vector<U>*, int, typename U::cl_type);
2052
2053 cl_int retain() const
2054 {
2055 if( object_ != nullptr && referenceCountable_ ) {
2056 return ReferenceHandler<cl_type>::retain(object_);
2057 }
2058 else {
2059 return CL_SUCCESS;
2060 }
2061 }
2062
2063 cl_int release() const
2064 {
2065 if (object_ != nullptr && referenceCountable_) {
2066 return ReferenceHandler<cl_type>::release(object_);
2067 }
2068 else {
2069 return CL_SUCCESS;
2070 }
2071 }
2072};
2073
2074template <typename T>
2075inline bool operator==(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
2076{
2077 return lhs() == rhs();
2078}
2079
2080template <typename T>
2081inline bool operator!=(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
2082{
2083 return !operator==(lhs, rhs);
2084}
2085
2086} // namespace detail
2088
2089
2090using BuildLogType = vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, CL_PROGRAM_BUILD_LOG>::param_type>>;
2091#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2095class BuildError : public Error
2096{
2097private:
2098 BuildLogType buildLogs;
2099public:
2100 BuildError(cl_int err, const char * errStr, const BuildLogType &vec) : Error(err, errStr), buildLogs(vec)
2101 {
2102 }
2103
2104 BuildLogType getBuildLog() const
2105 {
2106 return buildLogs;
2107 }
2108};
2109namespace detail {
2110 static inline cl_int buildErrHandler(
2111 cl_int err,
2112 const char * errStr,
2113 const BuildLogType &buildLogs)
2114 {
2115 if (err != CL_SUCCESS) {
2116 throw BuildError(err, errStr, buildLogs);
2117 }
2118 return err;
2119 }
2120} // namespace detail
2121
2122#else
2123namespace detail {
2124 static inline cl_int buildErrHandler(
2125 cl_int err,
2126 const char * errStr,
2127 const BuildLogType &buildLogs)
2128 {
2129 (void)buildLogs; // suppress unused variable warning
2130 (void)errStr;
2131 return err;
2132 }
2133} // namespace detail
2134#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2135
2136
2142struct ImageFormat : public cl_image_format
2143{
2146
2148 ImageFormat(cl_channel_order order, cl_channel_type type)
2149 {
2150 image_channel_order = order;
2151 image_channel_data_type = type;
2152 }
2153
2155 ImageFormat(const ImageFormat &other) { *this = other; }
2156
2159 {
2160 if (this != &rhs) {
2161 this->image_channel_data_type = rhs.image_channel_data_type;
2162 this->image_channel_order = rhs.image_channel_order;
2163 }
2164 return *this;
2165 }
2166};
2167
2175class Device : public detail::Wrapper<cl_device_id>
2176{
2177private:
2178 static std::once_flag default_initialized_;
2179 static Device default_;
2180 static cl_int default_error_;
2181
2187 static void makeDefault();
2188
2194 static void makeDefaultProvided(const Device &p) {
2195 default_ = p;
2196 }
2197
2198public:
2199#ifdef CL_HPP_UNIT_TEST_ENABLE
2206 static void unitTestClearDefault() {
2207 default_ = Device();
2208 }
2209#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2210
2212 Device() : detail::Wrapper<cl_type>() { }
2213
2218 explicit Device(const cl_device_id &device, bool retainObject = false) :
2219 detail::Wrapper<cl_type>(device, retainObject) { }
2220
2226 cl_int *errResult = NULL)
2227 {
2228 std::call_once(default_initialized_, makeDefault);
2229 detail::errHandler(default_error_);
2230 if (errResult != NULL) {
2231 *errResult = default_error_;
2232 }
2233 return default_;
2234 }
2235
2243 static Device setDefault(const Device &default_device)
2244 {
2245 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_device));
2246 detail::errHandler(default_error_);
2247 return default_;
2248 }
2249
2254 Device& operator = (const cl_device_id& rhs)
2255 {
2257 return *this;
2258 }
2259
2263 Device(const Device& dev) : detail::Wrapper<cl_type>(dev) {}
2264
2269 {
2271 return *this;
2272 }
2273
2277 Device(Device&& dev) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(dev)) {}
2278
2283 {
2285 return *this;
2286 }
2287
2289 template <typename T>
2290 cl_int getInfo(cl_device_info name, T* param) const
2291 {
2292 return detail::errHandler(
2293 detail::getInfo(&::clGetDeviceInfo, object_, name, param),
2294 __GET_DEVICE_INFO_ERR);
2295 }
2296
2298 template <cl_device_info name> typename
2300 getInfo(cl_int* err = NULL) const
2301 {
2302 typename detail::param_traits<
2303 detail::cl_device_info, name>::param_type param;
2304 cl_int result = getInfo(name, &param);
2305 if (err != NULL) {
2306 *err = result;
2307 }
2308 return param;
2309 }
2310
2311
2312#if CL_HPP_TARGET_OPENCL_VERSION >= 210
2319 cl_ulong getHostTimer(cl_int *error = nullptr)
2320 {
2321 cl_ulong retVal = 0;
2322 cl_int err =
2323 clGetHostTimer(this->get(), &retVal);
2324 detail::errHandler(
2325 err,
2326 __GET_HOST_TIMER_ERR);
2327 if (error) {
2328 *error = err;
2329 }
2330 return retVal;
2331 }
2332
2343 std::pair<cl_ulong, cl_ulong> getDeviceAndHostTimer(cl_int *error = nullptr)
2344 {
2345 std::pair<cl_ulong, cl_ulong> retVal;
2346 cl_int err =
2347 clGetDeviceAndHostTimer(this->get(), &(retVal.first), &(retVal.second));
2348 detail::errHandler(
2349 err,
2350 __GET_DEVICE_AND_HOST_TIMER_ERR);
2351 if (error) {
2352 *error = err;
2353 }
2354 return retVal;
2355 }
2356#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2357
2361#if CL_HPP_TARGET_OPENCL_VERSION >= 120
2364 const cl_device_partition_property * properties,
2365 vector<Device>* devices)
2366 {
2367 cl_uint n = 0;
2368 cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n);
2369 if (err != CL_SUCCESS) {
2370 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2371 }
2372
2373 vector<cl_device_id> ids(n);
2374 err = clCreateSubDevices(object_, properties, n, ids.data(), NULL);
2375 if (err != CL_SUCCESS) {
2376 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2377 }
2378
2379 // Cannot trivially assign because we need to capture intermediates
2380 // with safe construction
2381 if (devices) {
2382 devices->resize(ids.size());
2383
2384 // Assign to param, constructing with retain behaviour
2385 // to correctly capture each underlying CL object
2386 for (size_type i = 0; i < ids.size(); i++) {
2387 // We do not need to retain because this device is being created
2388 // by the runtime
2389 (*devices)[i] = Device(ids[i], false);
2390 }
2391 }
2392
2393 return CL_SUCCESS;
2394 }
2395#elif defined(CL_HPP_USE_CL_DEVICE_FISSION)
2396
2400 cl_int createSubDevices(
2401 const cl_device_partition_property_ext * properties,
2402 vector<Device>* devices)
2403 {
2404 typedef CL_API_ENTRY cl_int
2405 ( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
2406 cl_device_id /*in_device*/,
2407 const cl_device_partition_property_ext * /* properties */,
2408 cl_uint /*num_entries*/,
2409 cl_device_id * /*out_devices*/,
2410 cl_uint * /*num_devices*/ ) CL_API_SUFFIX__VERSION_1_1;
2411
2412 static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
2413 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSubDevicesEXT);
2414
2415 cl_uint n = 0;
2416 cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
2417 if (err != CL_SUCCESS) {
2418 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2419 }
2420
2421 vector<cl_device_id> ids(n);
2422 err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids.data(), NULL);
2423 if (err != CL_SUCCESS) {
2424 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2425 }
2426 // Cannot trivially assign because we need to capture intermediates
2427 // with safe construction
2428 if (devices) {
2429 devices->resize(ids.size());
2430
2431 // Assign to param, constructing with retain behaviour
2432 // to correctly capture each underlying CL object
2433 for (size_type i = 0; i < ids.size(); i++) {
2434 // We do not need to retain because this device is being created
2435 // by the runtime
2436 (*devices)[i] = Device(ids[i], false);
2437 }
2438 }
2439 return CL_SUCCESS;
2440 }
2441#endif // defined(CL_HPP_USE_CL_DEVICE_FISSION)
2442};
2443
2444CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Device::default_initialized_;
2445CL_HPP_DEFINE_STATIC_MEMBER_ Device Device::default_;
2446CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Device::default_error_ = CL_SUCCESS;
2447
2455class Platform : public detail::Wrapper<cl_platform_id>
2456{
2457private:
2458 static std::once_flag default_initialized_;
2459 static Platform default_;
2460 static cl_int default_error_;
2461
2467 static void makeDefault() {
2468 /* Throwing an exception from a call_once invocation does not do
2469 * what we wish, so we catch it and save the error.
2470 */
2471#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2472 try
2473#endif
2474 {
2475 // If default wasn't passed ,generate one
2476 // Otherwise set it
2477 cl_uint n = 0;
2478
2479 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2480 if (err != CL_SUCCESS) {
2481 default_error_ = err;
2482 return;
2483 }
2484 if (n == 0) {
2485 default_error_ = CL_INVALID_PLATFORM;
2486 return;
2487 }
2488
2489 vector<cl_platform_id> ids(n);
2490 err = ::clGetPlatformIDs(n, ids.data(), NULL);
2491 if (err != CL_SUCCESS) {
2492 default_error_ = err;
2493 return;
2494 }
2495
2496 default_ = Platform(ids[0]);
2497 }
2498#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2499 catch (cl::Error &e) {
2500 default_error_ = e.err();
2501 }
2502#endif
2503 }
2504
2510 static void makeDefaultProvided(const Platform &p) {
2511 default_ = p;
2512 }
2513
2514public:
2515#ifdef CL_HPP_UNIT_TEST_ENABLE
2522 static void unitTestClearDefault() {
2523 default_ = Platform();
2524 }
2525#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2526
2528 Platform() : detail::Wrapper<cl_type>() { }
2529
2537 explicit Platform(const cl_platform_id &platform, bool retainObject = false) :
2538 detail::Wrapper<cl_type>(platform, retainObject) { }
2539
2544 Platform& operator = (const cl_platform_id& rhs)
2545 {
2547 return *this;
2548 }
2549
2550 static Platform getDefault(
2551 cl_int *errResult = NULL)
2552 {
2553 std::call_once(default_initialized_, makeDefault);
2554 detail::errHandler(default_error_);
2555 if (errResult != NULL) {
2556 *errResult = default_error_;
2557 }
2558 return default_;
2559 }
2560
2568 static Platform setDefault(const Platform &default_platform)
2569 {
2570 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_platform));
2571 detail::errHandler(default_error_);
2572 return default_;
2573 }
2574
2576 template <typename T>
2577 cl_int getInfo(cl_platform_info name, T* param) const
2578 {
2579 return detail::errHandler(
2580 detail::getInfo(&::clGetPlatformInfo, object_, name, param),
2581 __GET_PLATFORM_INFO_ERR);
2582 }
2583
2585 template <cl_platform_info name> typename
2587 getInfo(cl_int* err = NULL) const
2588 {
2589 typename detail::param_traits<
2590 detail::cl_platform_info, name>::param_type param;
2591 cl_int result = getInfo(name, &param);
2592 if (err != NULL) {
2593 *err = result;
2594 }
2595 return param;
2596 }
2597
2603 cl_device_type type,
2604 vector<Device>* devices) const
2605 {
2606 cl_uint n = 0;
2607 if( devices == NULL ) {
2608 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2609 }
2610 cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
2611 if (err != CL_SUCCESS && err != CL_DEVICE_NOT_FOUND) {
2612 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2613 }
2614
2615 vector<cl_device_id> ids(n);
2616 if (n>0) {
2617 err = ::clGetDeviceIDs(object_, type, n, ids.data(), NULL);
2618 if (err != CL_SUCCESS) {
2619 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2620 }
2621 }
2622
2623 // Cannot trivially assign because we need to capture intermediates
2624 // with safe construction
2625 // We must retain things we obtain from the API to avoid releasing
2626 // API-owned objects.
2627 if (devices) {
2628 devices->resize(ids.size());
2629
2630 // Assign to param, constructing with retain behaviour
2631 // to correctly capture each underlying CL object
2632 for (size_type i = 0; i < ids.size(); i++) {
2633 (*devices)[i] = Device(ids[i], true);
2634 }
2635 }
2636 return CL_SUCCESS;
2637 }
2638
2639#if defined(CL_HPP_USE_DX_INTEROP)
2663 cl_int getDevices(
2664 cl_d3d10_device_source_khr d3d_device_source,
2665 void * d3d_object,
2666 cl_d3d10_device_set_khr d3d_device_set,
2667 vector<Device>* devices) const
2668 {
2669 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
2670 cl_platform_id platform,
2671 cl_d3d10_device_source_khr d3d_device_source,
2672 void * d3d_object,
2673 cl_d3d10_device_set_khr d3d_device_set,
2674 cl_uint num_entries,
2675 cl_device_id * devices,
2676 cl_uint* num_devices);
2677
2678 if( devices == NULL ) {
2679 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2680 }
2681
2682 static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
2683 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(object_, clGetDeviceIDsFromD3D10KHR);
2684
2685 cl_uint n = 0;
2686 cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
2687 object_,
2688 d3d_device_source,
2689 d3d_object,
2690 d3d_device_set,
2691 0,
2692 NULL,
2693 &n);
2694 if (err != CL_SUCCESS) {
2695 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2696 }
2697
2698 vector<cl_device_id> ids(n);
2699 err = pfn_clGetDeviceIDsFromD3D10KHR(
2700 object_,
2701 d3d_device_source,
2702 d3d_object,
2703 d3d_device_set,
2704 n,
2705 ids.data(),
2706 NULL);
2707 if (err != CL_SUCCESS) {
2708 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2709 }
2710
2711 // Cannot trivially assign because we need to capture intermediates
2712 // with safe construction
2713 // We must retain things we obtain from the API to avoid releasing
2714 // API-owned objects.
2715 if (devices) {
2716 devices->resize(ids.size());
2717
2718 // Assign to param, constructing with retain behaviour
2719 // to correctly capture each underlying CL object
2720 for (size_type i = 0; i < ids.size(); i++) {
2721 (*devices)[i] = Device(ids[i], true);
2722 }
2723 }
2724 return CL_SUCCESS;
2725 }
2726#endif
2727
2732 static cl_int get(
2733 vector<Platform>* platforms)
2734 {
2735 cl_uint n = 0;
2736
2737 if( platforms == NULL ) {
2738 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
2739 }
2740
2741 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2742 if (err != CL_SUCCESS) {
2743 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2744 }
2745
2746 vector<cl_platform_id> ids(n);
2747 err = ::clGetPlatformIDs(n, ids.data(), NULL);
2748 if (err != CL_SUCCESS) {
2749 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2750 }
2751
2752 if (platforms) {
2753 platforms->resize(ids.size());
2754
2755 // Platforms don't reference count
2756 for (size_type i = 0; i < ids.size(); i++) {
2757 (*platforms)[i] = Platform(ids[i]);
2758 }
2759 }
2760 return CL_SUCCESS;
2761 }
2762
2767 static cl_int get(
2768 Platform * platform)
2769 {
2770 cl_int err;
2771 Platform default_platform = Platform::getDefault(&err);
2772 if (platform) {
2773 *platform = default_platform;
2774 }
2775 return err;
2776 }
2777
2787 cl_int * errResult = NULL)
2788 {
2789 cl_int err;
2790 Platform default_platform = Platform::getDefault(&err);
2791 if (errResult) {
2792 *errResult = err;
2793 }
2794 return default_platform;
2795 }
2796
2797#if CL_HPP_TARGET_OPENCL_VERSION >= 120
2799 cl_int
2801 {
2802 return ::clUnloadPlatformCompiler(object_);
2803 }
2804#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
2805}; // class Platform
2806
2807CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Platform::default_initialized_;
2808CL_HPP_DEFINE_STATIC_MEMBER_ Platform Platform::default_;
2809CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Platform::default_error_ = CL_SUCCESS;
2810
2811
2815#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2820inline CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int
2821UnloadCompiler() CL_API_SUFFIX__VERSION_1_1_DEPRECATED;
2822inline cl_int
2824{
2825 return ::clUnloadCompiler();
2826}
2827#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2828
2838 : public detail::Wrapper<cl_context>
2839{
2840private:
2841 static std::once_flag default_initialized_;
2842 static Context default_;
2843 static cl_int default_error_;
2844
2850 static void makeDefault() {
2851 /* Throwing an exception from a call_once invocation does not do
2852 * what we wish, so we catch it and save the error.
2853 */
2854#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2855 try
2856#endif
2857 {
2858#if !defined(__APPLE__) && !defined(__MACOS)
2859 const Platform &p = Platform::getDefault();
2860 cl_platform_id defaultPlatform = p();
2861 cl_context_properties properties[3] = {
2862 CL_CONTEXT_PLATFORM, (cl_context_properties)defaultPlatform, 0
2863 };
2864#else // #if !defined(__APPLE__) && !defined(__MACOS)
2865 cl_context_properties *properties = nullptr;
2866#endif // #if !defined(__APPLE__) && !defined(__MACOS)
2867
2868 default_ = Context(
2869 CL_DEVICE_TYPE_DEFAULT,
2870 properties,
2871 NULL,
2872 NULL,
2873 &default_error_);
2874 }
2875#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2876 catch (cl::Error &e) {
2877 default_error_ = e.err();
2878 }
2879#endif
2880 }
2881
2882
2888 static void makeDefaultProvided(const Context &c) {
2889 default_ = c;
2890 }
2891
2892public:
2893#ifdef CL_HPP_UNIT_TEST_ENABLE
2900 static void unitTestClearDefault() {
2901 default_ = Context();
2902 }
2903#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2904
2910 const vector<Device>& devices,
2911 const cl_context_properties* properties = NULL,
2912 void (CL_CALLBACK * notifyFptr)(
2913 const char *,
2914 const void *,
2915 size_type,
2916 void *) = NULL,
2917 void* data = NULL,
2918 cl_int* err = NULL)
2919 {
2920 cl_int error;
2921
2922 size_type numDevices = devices.size();
2923 vector<cl_device_id> deviceIDs(numDevices);
2924
2925 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
2926 deviceIDs[deviceIndex] = (devices[deviceIndex])();
2927 }
2928
2929 object_ = ::clCreateContext(
2930 properties, (cl_uint) numDevices,
2931 deviceIDs.data(),
2932 notifyFptr, data, &error);
2933
2934 detail::errHandler(error, __CREATE_CONTEXT_ERR);
2935 if (err != NULL) {
2936 *err = error;
2937 }
2938 }
2939
2945 const Device& device,
2946 const cl_context_properties* properties = NULL,
2947 void (CL_CALLBACK * notifyFptr)(
2948 const char *,
2949 const void *,
2950 size_type,
2951 void *) = NULL,
2952 void* data = NULL,
2953 cl_int* err = NULL)
2954 {
2955 cl_int error;
2956
2957 cl_device_id deviceID = device();
2958
2959 object_ = ::clCreateContext(
2960 properties, 1,
2961 &deviceID,
2962 notifyFptr, data, &error);
2963
2964 detail::errHandler(error, __CREATE_CONTEXT_ERR);
2965 if (err != NULL) {
2966 *err = error;
2967 }
2968 }
2969
2975 cl_device_type type,
2976 const cl_context_properties* properties = NULL,
2977 void (CL_CALLBACK * notifyFptr)(
2978 const char *,
2979 const void *,
2980 size_type,
2981 void *) = NULL,
2982 void* data = NULL,
2983 cl_int* err = NULL)
2984 {
2985 cl_int error;
2986
2987#if !defined(__APPLE__) && !defined(__MACOS)
2988 cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 };
2989
2990 if (properties == NULL) {
2991 // Get a valid platform ID as we cannot send in a blank one
2992 vector<Platform> platforms;
2993 error = Platform::get(&platforms);
2994 if (error != CL_SUCCESS) {
2995 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2996 if (err != NULL) {
2997 *err = error;
2998 }
2999 return;
3000 }
3001
3002 // Check the platforms we found for a device of our specified type
3003 cl_context_properties platform_id = 0;
3004 for (unsigned int i = 0; i < platforms.size(); i++) {
3005
3006 vector<Device> devices;
3007
3008#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3009 try {
3010#endif
3011
3012 error = platforms[i].getDevices(type, &devices);
3013
3014#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3015 } catch (cl::Error& e) {
3016 error = e.err();
3017 }
3018 // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type
3019 // We do error checking next anyway, and can throw there if needed
3020#endif
3021
3022 // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND
3023 if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) {
3024 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
3025 if (err != NULL) {
3026 *err = error;
3027 }
3028 }
3029
3030 if (devices.size() > 0) {
3031 platform_id = (cl_context_properties)platforms[i]();
3032 break;
3033 }
3034 }
3035
3036 if (platform_id == 0) {
3037 detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR);
3038 if (err != NULL) {
3039 *err = CL_DEVICE_NOT_FOUND;
3040 }
3041 return;
3042 }
3043
3044 prop[1] = platform_id;
3045 properties = &prop[0];
3046 }
3047#endif
3048 object_ = ::clCreateContextFromType(
3049 properties, type, notifyFptr, data, &error);
3050
3051 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
3052 if (err != NULL) {
3053 *err = error;
3054 }
3055 }
3056
3060 Context(const Context& ctx) : detail::Wrapper<cl_type>(ctx) {}
3061
3066 {
3068 return *this;
3069 }
3070
3074 Context(Context&& ctx) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(ctx)) {}
3075
3080 {
3082 return *this;
3083 }
3084
3085
3090 static Context getDefault(cl_int * err = NULL)
3091 {
3092 std::call_once(default_initialized_, makeDefault);
3093 detail::errHandler(default_error_);
3094 if (err != NULL) {
3095 *err = default_error_;
3096 }
3097 return default_;
3098 }
3099
3107 static Context setDefault(const Context &default_context)
3108 {
3109 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_context));
3110 detail::errHandler(default_error_);
3111 return default_;
3112 }
3113
3115 Context() : detail::Wrapper<cl_type>() { }
3116
3122 explicit Context(const cl_context& context, bool retainObject = false) :
3123 detail::Wrapper<cl_type>(context, retainObject) { }
3124
3130 Context& operator = (const cl_context& rhs)
3131 {
3133 return *this;
3134 }
3135
3137 template <typename T>
3138 cl_int getInfo(cl_context_info name, T* param) const
3139 {
3140 return detail::errHandler(
3141 detail::getInfo(&::clGetContextInfo, object_, name, param),
3142 __GET_CONTEXT_INFO_ERR);
3143 }
3144
3146 template <cl_context_info name> typename
3148 getInfo(cl_int* err = NULL) const
3149 {
3150 typename detail::param_traits<
3151 detail::cl_context_info, name>::param_type param;
3152 cl_int result = getInfo(name, &param);
3153 if (err != NULL) {
3154 *err = result;
3155 }
3156 return param;
3157 }
3158
3164 cl_mem_flags flags,
3165 cl_mem_object_type type,
3166 vector<ImageFormat>* formats) const
3167 {
3168 cl_uint numEntries;
3169
3170 if (!formats) {
3171 return CL_SUCCESS;
3172 }
3173
3174 cl_int err = ::clGetSupportedImageFormats(
3175 object_,
3176 flags,
3177 type,
3178 0,
3179 NULL,
3180 &numEntries);
3181 if (err != CL_SUCCESS) {
3182 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3183 }
3184
3185 if (numEntries > 0) {
3186 vector<ImageFormat> value(numEntries);
3187 err = ::clGetSupportedImageFormats(
3188 object_,
3189 flags,
3190 type,
3191 numEntries,
3192 (cl_image_format*)value.data(),
3193 NULL);
3194 if (err != CL_SUCCESS) {
3195 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3196 }
3197
3198 formats->assign(begin(value), end(value));
3199 }
3200 else {
3201 // If no values are being returned, ensure an empty vector comes back
3202 formats->clear();
3203 }
3204
3205 return CL_SUCCESS;
3206 }
3207};
3208
3209inline void Device::makeDefault()
3210{
3211 /* Throwing an exception from a call_once invocation does not do
3212 * what we wish, so we catch it and save the error.
3213 */
3214#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3215 try
3216#endif
3217 {
3218 cl_int error = 0;
3219
3220 Context context = Context::getDefault(&error);
3221 detail::errHandler(error, __CREATE_CONTEXT_ERR);
3222
3223 if (error != CL_SUCCESS) {
3224 default_error_ = error;
3225 }
3226 else {
3227 default_ = context.getInfo<CL_CONTEXT_DEVICES>()[0];
3228 default_error_ = CL_SUCCESS;
3229 }
3230 }
3231#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3232 catch (cl::Error &e) {
3233 default_error_ = e.err();
3234 }
3235#endif
3236}
3237
3238CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Context::default_initialized_;
3239CL_HPP_DEFINE_STATIC_MEMBER_ Context Context::default_;
3240CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Context::default_error_ = CL_SUCCESS;
3241
3250class Event : public detail::Wrapper<cl_event>
3251{
3252public:
3254 Event() : detail::Wrapper<cl_type>() { }
3255
3264 explicit Event(const cl_event& event, bool retainObject = false) :
3265 detail::Wrapper<cl_type>(event, retainObject) { }
3266
3272 Event& operator = (const cl_event& rhs)
3273 {
3275 return *this;
3276 }
3277
3279 template <typename T>
3280 cl_int getInfo(cl_event_info name, T* param) const
3281 {
3282 return detail::errHandler(
3283 detail::getInfo(&::clGetEventInfo, object_, name, param),
3284 __GET_EVENT_INFO_ERR);
3285 }
3286
3288 template <cl_event_info name> typename
3290 getInfo(cl_int* err = NULL) const
3291 {
3292 typename detail::param_traits<
3293 detail::cl_event_info, name>::param_type param;
3294 cl_int result = getInfo(name, &param);
3295 if (err != NULL) {
3296 *err = result;
3297 }
3298 return param;
3299 }
3300
3302 template <typename T>
3303 cl_int getProfilingInfo(cl_profiling_info name, T* param) const
3304 {
3305 return detail::errHandler(detail::getInfo(
3306 &::clGetEventProfilingInfo, object_, name, param),
3307 __GET_EVENT_PROFILE_INFO_ERR);
3308 }
3309
3311 template <cl_profiling_info name> typename
3313 getProfilingInfo(cl_int* err = NULL) const
3314 {
3315 typename detail::param_traits<
3316 detail::cl_profiling_info, name>::param_type param;
3317 cl_int result = getProfilingInfo(name, &param);
3318 if (err != NULL) {
3319 *err = result;
3320 }
3321 return param;
3322 }
3323
3328 cl_int wait() const
3329 {
3330 return detail::errHandler(
3331 ::clWaitForEvents(1, &object_),
3332 __WAIT_FOR_EVENTS_ERR);
3333 }
3334
3335#if CL_HPP_TARGET_OPENCL_VERSION >= 110
3341 cl_int type,
3342 void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
3343 void * user_data = NULL)
3344 {
3345 return detail::errHandler(
3346 ::clSetEventCallback(
3347 object_,
3348 type,
3349 pfn_notify,
3350 user_data),
3351 __SET_EVENT_CALLBACK_ERR);
3352 }
3353#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3354
3359 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};
3368
3369#if CL_HPP_TARGET_OPENCL_VERSION >= 110
3374class UserEvent : public Event
3375{
3376public:
3382 const Context& context,
3383 cl_int * err = NULL)
3384 {
3385 cl_int error;
3386 object_ = ::clCreateUserEvent(
3387 context(),
3388 &error);
3389
3390 detail::errHandler(error, __CREATE_USER_EVENT_ERR);
3391 if (err != NULL) {
3392 *err = error;
3393 }
3394 }
3395
3398
3403 cl_int setStatus(cl_int status)
3404 {
3405 return detail::errHandler(
3406 ::clSetUserEventStatus(object_,status),
3407 __SET_USER_EVENT_STATUS_ERR);
3408 }
3409};
3410#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3411
3416inline static cl_int
3417WaitForEvents(const vector<Event>& events)
3418{
3419 return detail::errHandler(
3420 ::clWaitForEvents(
3421 (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3422 __WAIT_FOR_EVENTS_ERR);
3423}
3424
3433class Memory : public detail::Wrapper<cl_mem>
3434{
3435public:
3437 Memory() : detail::Wrapper<cl_type>() { }
3438
3450 explicit Memory(const cl_mem& memory, bool retainObject) :
3451 detail::Wrapper<cl_type>(memory, retainObject) { }
3452
3458 Memory& operator = (const cl_mem& rhs)
3459 {
3461 return *this;
3462 }
3463
3467 Memory(const Memory& mem) : detail::Wrapper<cl_type>(mem) {}
3468
3473 {
3475 return *this;
3476 }
3477
3481 Memory(Memory&& mem) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(mem)) {}
3482
3487 {
3489 return *this;
3490 }
3491
3492
3494 template <typename T>
3495 cl_int getInfo(cl_mem_info name, T* param) const
3496 {
3497 return detail::errHandler(
3498 detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
3499 __GET_MEM_OBJECT_INFO_ERR);
3500 }
3501
3503 template <cl_mem_info name> typename
3505 getInfo(cl_int* err = NULL) const
3506 {
3507 typename detail::param_traits<
3508 detail::cl_mem_info, name>::param_type param;
3509 cl_int result = getInfo(name, &param);
3510 if (err != NULL) {
3511 *err = result;
3512 }
3513 return param;
3514 }
3515
3516#if CL_HPP_TARGET_OPENCL_VERSION >= 110
3531 void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
3532 void * user_data = NULL)
3533 {
3534 return detail::errHandler(
3535 ::clSetMemObjectDestructorCallback(
3536 object_,
3537 pfn_notify,
3538 user_data),
3539 __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
3540 }
3541#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3542
3543};
3544
3545// Pre-declare copy functions
3546class Buffer;
3547template< typename IteratorType >
3548cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3549template< typename IteratorType >
3550cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3551template< typename IteratorType >
3552cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3553template< typename IteratorType >
3554cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3555
3556
3557#if CL_HPP_TARGET_OPENCL_VERSION >= 200
3558namespace detail
3559{
3561 {
3562 public:
3563 static cl_svm_mem_flags getSVMMemFlags()
3564 {
3565 return 0;
3566 }
3567 };
3568} // namespace detail
3569
3570template<class Trait = detail::SVMTraitNull>
3572{
3573public:
3574 static cl_svm_mem_flags getSVMMemFlags()
3575 {
3576 return CL_MEM_READ_WRITE |
3577 Trait::getSVMMemFlags();
3578 }
3579};
3580
3581template<class Trait = detail::SVMTraitNull>
3583{
3584public:
3585 static cl_svm_mem_flags getSVMMemFlags()
3586 {
3587 return CL_MEM_READ_ONLY |
3588 Trait::getSVMMemFlags();
3589 }
3590};
3591
3592template<class Trait = detail::SVMTraitNull>
3594{
3595public:
3596 static cl_svm_mem_flags getSVMMemFlags()
3597 {
3598 return CL_MEM_WRITE_ONLY |
3599 Trait::getSVMMemFlags();
3600 }
3601};
3602
3603template<class Trait = SVMTraitReadWrite<>>
3605{
3606public:
3607 static cl_svm_mem_flags getSVMMemFlags()
3608 {
3609 return Trait::getSVMMemFlags();
3610 }
3611};
3612
3613template<class Trait = SVMTraitReadWrite<>>
3615{
3616public:
3617 static cl_svm_mem_flags getSVMMemFlags()
3618 {
3619 return CL_MEM_SVM_FINE_GRAIN_BUFFER |
3620 Trait::getSVMMemFlags();
3621 }
3622};
3623
3624template<class Trait = SVMTraitReadWrite<>>
3626{
3627public:
3628 static cl_svm_mem_flags getSVMMemFlags()
3629 {
3630 return
3631 CL_MEM_SVM_FINE_GRAIN_BUFFER |
3632 CL_MEM_SVM_ATOMICS |
3633 Trait::getSVMMemFlags();
3634 }
3635};
3636
3637// Pre-declare SVM map function
3638template<typename T>
3639inline cl_int enqueueMapSVM(
3640 T* ptr,
3641 cl_bool blocking,
3642 cl_map_flags flags,
3643 size_type size,
3644 const vector<Event>* events = NULL,
3645 Event* event = NULL);
3646
3658template<typename T, class SVMTrait>
3660private:
3661 Context context_;
3662
3663public:
3664 typedef T value_type;
3665 typedef value_type* pointer;
3666 typedef const value_type* const_pointer;
3667 typedef value_type& reference;
3668 typedef const value_type& const_reference;
3669 typedef std::size_t size_type;
3670 typedef std::ptrdiff_t difference_type;
3671
3672 template<typename U>
3673 struct rebind
3674 {
3676 };
3677
3678 template<typename U, typename V>
3679 friend class SVMAllocator;
3680
3681 SVMAllocator() :
3682 context_(Context::getDefault())
3683 {
3684 }
3685
3686 explicit SVMAllocator(cl::Context context) :
3687 context_(context)
3688 {
3689 }
3690
3691
3692 SVMAllocator(const SVMAllocator &other) :
3693 context_(other.context_)
3694 {
3695 }
3696
3697 template<typename U>
3698 SVMAllocator(const SVMAllocator<U, SVMTrait> &other) :
3699 context_(other.context_)
3700 {
3701 }
3702
3703 ~SVMAllocator()
3704 {
3705 }
3706
3707 pointer address(reference r) CL_HPP_NOEXCEPT_
3708 {
3709 return std::addressof(r);
3710 }
3711
3712 const_pointer address(const_reference r) CL_HPP_NOEXCEPT_
3713 {
3714 return std::addressof(r);
3715 }
3716
3723 pointer allocate(
3724 size_type size,
3726 {
3727 // Allocate memory with default alignment matching the size of the type
3728 void* voidPointer =
3729 clSVMAlloc(
3730 context_(),
3731 SVMTrait::getSVMMemFlags(),
3732 size*sizeof(T),
3733 0);
3734 pointer retValue = reinterpret_cast<pointer>(
3735 voidPointer);
3736#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3737 if (!retValue) {
3738 std::bad_alloc excep;
3739 throw excep;
3740 }
3741#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3742
3743 // If allocation was coarse-grained then map it
3744 if (!(SVMTrait::getSVMMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) {
3745 cl_int err = enqueueMapSVM(retValue, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, size*sizeof(T));
3746 if (err != CL_SUCCESS) {
3747 std::bad_alloc excep;
3748 throw excep;
3749 }
3750 }
3751
3752 // If exceptions disabled, return null pointer from allocator
3753 return retValue;
3754 }
3755
3756 void deallocate(pointer p, size_type)
3757 {
3758 clSVMFree(context_(), p);
3759 }
3760
3765 size_type max_size() const CL_HPP_NOEXCEPT_
3766 {
3767 size_type maxSize = std::numeric_limits<size_type>::max() / sizeof(T);
3768
3769 for (const Device &d : context_.getInfo<CL_CONTEXT_DEVICES>()) {
3770 maxSize = std::min(
3771 maxSize,
3772 static_cast<size_type>(d.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>()));
3773 }
3774
3775 return maxSize;
3776 }
3777
3778 template< class U, class... Args >
3779 void construct(U* p, Args&&... args)
3780 {
3781 new(p)T(args...);
3782 }
3783
3784 template< class U >
3785 void destroy(U* p)
3786 {
3787 p->~U();
3788 }
3789
3793 inline bool operator==(SVMAllocator const& rhs)
3794 {
3795 return (context_==rhs.context_);
3796 }
3797
3798 inline bool operator!=(SVMAllocator const& a)
3799 {
3800 return !operator==(a);
3801 }
3802}; // class SVMAllocator return cl::pointer<T>(tmp, detail::Deleter<T, Alloc>{alloc, copies});
3803
3804
3805template<class SVMTrait>
3806class SVMAllocator<void, SVMTrait> {
3807public:
3808 typedef void value_type;
3809 typedef value_type* pointer;
3810 typedef const value_type* const_pointer;
3811
3812 template<typename U>
3813 struct rebind
3814 {
3816 };
3817
3818 template<typename U, typename V>
3819 friend class SVMAllocator;
3820};
3821
3822#if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3823namespace detail
3824{
3825 template<class Alloc>
3826 class Deleter {
3827 private:
3828 Alloc alloc_;
3829 size_type copies_;
3830
3831 public:
3832 typedef typename std::allocator_traits<Alloc>::pointer pointer;
3833
3834 Deleter(const Alloc &alloc, size_type copies) : alloc_{ alloc }, copies_{ copies }
3835 {
3836 }
3837
3838 void operator()(pointer ptr) const {
3839 Alloc tmpAlloc{ alloc_ };
3840 std::allocator_traits<Alloc>::destroy(tmpAlloc, std::addressof(*ptr));
3841 std::allocator_traits<Alloc>::deallocate(tmpAlloc, ptr, copies_);
3842 }
3843 };
3844} // namespace detail
3845
3852template <class T, class Alloc, class... Args>
3853cl::pointer<T, detail::Deleter<Alloc>> allocate_pointer(const Alloc &alloc_, Args&&... args)
3854{
3855 Alloc alloc(alloc_);
3856 static const size_type copies = 1;
3857
3858 // Ensure that creation of the management block and the
3859 // object are dealt with separately such that we only provide a deleter
3860
3861 T* tmp = std::allocator_traits<Alloc>::allocate(alloc, copies);
3862 if (!tmp) {
3863 std::bad_alloc excep;
3864 throw excep;
3865 }
3866 try {
3867 std::allocator_traits<Alloc>::construct(
3868 alloc,
3869 std::addressof(*tmp),
3870 std::forward<Args>(args)...);
3871
3872 return cl::pointer<T, detail::Deleter<Alloc>>(tmp, detail::Deleter<Alloc>{alloc, copies});
3873 }
3874 catch (std::bad_alloc& b)
3875 {
3876 std::allocator_traits<Alloc>::deallocate(alloc, tmp, copies);
3877 throw;
3878 }
3879}
3880
3881template< class T, class SVMTrait, class... Args >
3882cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(Args... args)
3883{
3884 SVMAllocator<T, SVMTrait> alloc;
3885 return cl::allocate_pointer<T>(alloc, args...);
3886}
3887
3888template< class T, class SVMTrait, class... Args >
3889cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(const cl::Context &c, Args... args)
3890{
3891 SVMAllocator<T, SVMTrait> alloc(c);
3892 return cl::allocate_pointer<T>(alloc, args...);
3893}
3894#endif // #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3895
3899template < class T >
3900using coarse_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>>;
3901
3905template < class T >
3906using fine_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitFine<>>>;
3907
3911template < class T >
3912using atomic_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitAtomic<>>>;
3913
3914#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
3915
3916
3923class Buffer : public Memory
3924{
3925public:
3926
3935 const Context& context,
3936 cl_mem_flags flags,
3937 size_type size,
3938 void* host_ptr = NULL,
3939 cl_int* err = NULL)
3940 {
3941 cl_int error;
3942 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3943
3944 detail::errHandler(error, __CREATE_BUFFER_ERR);
3945 if (err != NULL) {
3946 *err = error;
3947 }
3948 }
3949
3960 cl_mem_flags flags,
3961 size_type size,
3962 void* host_ptr = NULL,
3963 cl_int* err = NULL)
3964 {
3965 cl_int error;
3966
3967 Context context = Context::getDefault(err);
3968
3969 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3970
3971 detail::errHandler(error, __CREATE_BUFFER_ERR);
3972 if (err != NULL) {
3973 *err = error;
3974 }
3975 }
3976
3982 template< typename IteratorType >
3984 IteratorType startIterator,
3985 IteratorType endIterator,
3986 bool readOnly,
3987 bool useHostPtr = false,
3988 cl_int* err = NULL)
3989 {
3990 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
3991 cl_int error;
3992
3993 cl_mem_flags flags = 0;
3994 if( readOnly ) {
3995 flags |= CL_MEM_READ_ONLY;
3996 }
3997 else {
3998 flags |= CL_MEM_READ_WRITE;
3999 }
4000 if( useHostPtr ) {
4001 flags |= CL_MEM_USE_HOST_PTR;
4002 }
4003
4004 size_type size = sizeof(DataType)*(endIterator - startIterator);
4005
4006 Context context = Context::getDefault(err);
4007
4008 if( useHostPtr ) {
4009 object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
4010 } else {
4011 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
4012 }
4013
4014 detail::errHandler(error, __CREATE_BUFFER_ERR);
4015 if (err != NULL) {
4016 *err = error;
4017 }
4018
4019 if( !useHostPtr ) {
4020 error = cl::copy(startIterator, endIterator, *this);
4021 detail::errHandler(error, __CREATE_BUFFER_ERR);
4022 if (err != NULL) {
4023 *err = error;
4024 }
4025 }
4026 }
4027
4033 template< typename IteratorType >
4034 Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator,
4035 bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
4036
4041 template< typename IteratorType >
4042 Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator,
4043 bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
4044
4046 Buffer() : Memory() { }
4047
4055 explicit Buffer(const cl_mem& buffer, bool retainObject = false) :
4056 Memory(buffer, retainObject) { }
4057
4062 Buffer& operator = (const cl_mem& rhs)
4063 {
4064 Memory::operator=(rhs);
4065 return *this;
4066 }
4067
4071 Buffer(const Buffer& buf) : Memory(buf) {}
4072
4077 {
4078 Memory::operator=(buf);
4079 return *this;
4080 }
4081
4085 Buffer(Buffer&& buf) CL_HPP_NOEXCEPT_ : Memory(std::move(buf)) {}
4086
4091 {
4092 Memory::operator=(std::move(buf));
4093 return *this;
4094 }
4095
4096#if CL_HPP_TARGET_OPENCL_VERSION >= 110
4102 cl_mem_flags flags,
4103 cl_buffer_create_type buffer_create_type,
4104 const void * buffer_create_info,
4105 cl_int * err = NULL)
4106 {
4107 Buffer result;
4108 cl_int error;
4109 result.object_ = ::clCreateSubBuffer(
4110 object_,
4111 flags,
4112 buffer_create_type,
4113 buffer_create_info,
4114 &error);
4115
4116 detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
4117 if (err != NULL) {
4118 *err = error;
4119 }
4120
4121 return result;
4122 }
4123#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
4124};
4125
4126#if defined (CL_HPP_USE_DX_INTEROP)
4135class BufferD3D10 : public Buffer
4136{
4137public:
4138
4139
4145 BufferD3D10(
4146 const Context& context,
4147 cl_mem_flags flags,
4148 ID3D10Buffer* bufobj,
4149 cl_int * err = NULL) : pfn_clCreateFromD3D10BufferKHR(nullptr)
4150 {
4151 typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
4152 cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
4153 cl_int* errcode_ret);
4154 PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR;
4155#if CL_HPP_TARGET_OPENCL_VERSION >= 120
4156 vector<cl_context_properties> props = context.getInfo<CL_CONTEXT_PROPERTIES>();
4157 cl_platform platform = -1;
4158 for( int i = 0; i < props.size(); ++i ) {
4159 if( props[i] == CL_CONTEXT_PLATFORM ) {
4160 platform = props[i+1];
4161 }
4162 }
4163 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateFromD3D10BufferKHR);
4164#elif CL_HPP_TARGET_OPENCL_VERSION >= 110
4165 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateFromD3D10BufferKHR);
4166#endif
4167
4168 cl_int error;
4169 object_ = pfn_clCreateFromD3D10BufferKHR(
4170 context(),
4171 flags,
4172 bufobj,
4173 &error);
4174
4175 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4176 if (err != NULL) {
4177 *err = error;
4178 }
4179 }
4180
4182 BufferD3D10() : Buffer() { }
4183
4191 explicit BufferD3D10(const cl_mem& buffer, bool retainObject = false) :
4192 Buffer(buffer, retainObject) { }
4193
4198 BufferD3D10& operator = (const cl_mem& rhs)
4199 {
4200 Buffer::operator=(rhs);
4201 return *this;
4202 }
4203
4207 BufferD3D10(const BufferD3D10& buf) :
4208 Buffer(buf) {}
4209
4213 BufferD3D10& operator = (const BufferD3D10 &buf)
4214 {
4215 Buffer::operator=(buf);
4216 return *this;
4217 }
4218
4222 BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4223
4227 BufferD3D10& operator = (BufferD3D10 &&buf)
4228 {
4229 Buffer::operator=(std::move(buf));
4230 return *this;
4231 }
4232};
4233#endif
4234
4243class BufferGL : public Buffer
4244{
4245public:
4252 const Context& context,
4253 cl_mem_flags flags,
4254 cl_GLuint bufobj,
4255 cl_int * err = NULL)
4256 {
4257 cl_int error;
4258 object_ = ::clCreateFromGLBuffer(
4259 context(),
4260 flags,
4261 bufobj,
4262 &error);
4263
4264 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4265 if (err != NULL) {
4266 *err = error;
4267 }
4268 }
4269
4272
4280 explicit BufferGL(const cl_mem& buffer, bool retainObject = false) :
4281 Buffer(buffer, retainObject) { }
4282
4287 BufferGL& operator = (const cl_mem& rhs)
4288 {
4289 Buffer::operator=(rhs);
4290 return *this;
4291 }
4292
4296 BufferGL(const BufferGL& buf) : Buffer(buf) {}
4297
4302 {
4303 Buffer::operator=(buf);
4304 return *this;
4305 }
4306
4310 BufferGL(BufferGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4311
4316 {
4317 Buffer::operator=(std::move(buf));
4318 return *this;
4319 }
4320
4323 cl_gl_object_type *type,
4324 cl_GLuint * gl_object_name)
4325 {
4326 return detail::errHandler(
4327 ::clGetGLObjectInfo(object_,type,gl_object_name),
4328 __GET_GL_OBJECT_INFO_ERR);
4329 }
4330};
4331
4341{
4342public:
4349 const Context& context,
4350 cl_mem_flags flags,
4351 cl_GLuint bufobj,
4352 cl_int * err = NULL)
4353 {
4354 cl_int error;
4355 object_ = ::clCreateFromGLRenderbuffer(
4356 context(),
4357 flags,
4358 bufobj,
4359 &error);
4360
4361 detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR);
4362 if (err != NULL) {
4363 *err = error;
4364 }
4365 }
4366
4369
4377 explicit BufferRenderGL(const cl_mem& buffer, bool retainObject = false) :
4378 Buffer(buffer, retainObject) { }
4379
4384 BufferRenderGL& operator = (const cl_mem& rhs)
4385 {
4386 Buffer::operator=(rhs);
4387 return *this;
4388 }
4389
4394
4399 {
4400 Buffer::operator=(buf);
4401 return *this;
4402 }
4403
4407 BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4408
4413 {
4414 Buffer::operator=(std::move(buf));
4415 return *this;
4416 }
4417
4420 cl_gl_object_type *type,
4421 cl_GLuint * gl_object_name)
4422 {
4423 return detail::errHandler(
4424 ::clGetGLObjectInfo(object_,type,gl_object_name),
4425 __GET_GL_OBJECT_INFO_ERR);
4426 }
4427};
4428
4435class Image : public Memory
4436{
4437protected:
4439 Image() : Memory() { }
4440
4448 explicit Image(const cl_mem& image, bool retainObject = false) :
4449 Memory(image, retainObject) { }
4450
4455 Image& operator = (const cl_mem& rhs)
4456 {
4457 Memory::operator=(rhs);
4458 return *this;
4459 }
4460
4464 Image(const Image& img) : Memory(img) {}
4465
4470 {
4471 Memory::operator=(img);
4472 return *this;
4473 }
4474
4478 Image(Image&& img) CL_HPP_NOEXCEPT_ : Memory(std::move(img)) {}
4479
4484 {
4485 Memory::operator=(std::move(img));
4486 return *this;
4487 }
4488
4489
4490public:
4492 template <typename T>
4493 cl_int getImageInfo(cl_image_info name, T* param) const
4494 {
4495 return detail::errHandler(
4496 detail::getInfo(&::clGetImageInfo, object_, name, param),
4497 __GET_IMAGE_INFO_ERR);
4498 }
4499
4501 template <cl_image_info name> typename
4503 getImageInfo(cl_int* err = NULL) const
4504 {
4505 typename detail::param_traits<
4506 detail::cl_image_info, name>::param_type param;
4507 cl_int result = getImageInfo(name, &param);
4508 if (err != NULL) {
4509 *err = result;
4510 }
4511 return param;
4512 }
4513};
4514
4515#if CL_HPP_TARGET_OPENCL_VERSION >= 120
4522class Image1D : public Image
4523{
4524public:
4530 const Context& context,
4531 cl_mem_flags flags,
4532 ImageFormat format,
4533 size_type width,
4534 void* host_ptr = NULL,
4535 cl_int* err = NULL)
4536 {
4537 cl_int error;
4538
4539 cl_image_desc desc = {0};
4540 desc.image_type = CL_MEM_OBJECT_IMAGE1D;
4541 desc.image_width = width;
4542
4543 object_ = ::clCreateImage(
4544 context(),
4545 flags,
4546 &format,
4547 &desc,
4548 host_ptr,
4549 &error);
4550
4551 detail::errHandler(error, __CREATE_IMAGE_ERR);
4552 if (err != NULL) {
4553 *err = error;
4554 }
4555 }
4556
4559
4567 explicit Image1D(const cl_mem& image1D, bool retainObject = false) :
4568 Image(image1D, retainObject) { }
4569
4574 Image1D& operator = (const cl_mem& rhs)
4575 {
4576 Image::operator=(rhs);
4577 return *this;
4578 }
4579
4583 Image1D(const Image1D& img) : Image(img) {}
4584
4589 {
4590 Image::operator=(img);
4591 return *this;
4592 }
4593
4597 Image1D(Image1D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4598
4603 {
4604 Image::operator=(std::move(img));
4605 return *this;
4606 }
4607
4608};
4609
4613class Image1DBuffer : public Image
4614{
4615public:
4617 const Context& context,
4618 cl_mem_flags flags,
4619 ImageFormat format,
4620 size_type width,
4621 const Buffer &buffer,
4622 cl_int* err = NULL)
4623 {
4624 cl_int error;
4625
4626 cl_image_desc desc = {0};
4627 desc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER;
4628 desc.image_width = width;
4629 desc.buffer = buffer();
4630
4631 object_ = ::clCreateImage(
4632 context(),
4633 flags,
4634 &format,
4635 &desc,
4636 NULL,
4637 &error);
4638
4639 detail::errHandler(error, __CREATE_IMAGE_ERR);
4640 if (err != NULL) {
4641 *err = error;
4642 }
4643 }
4644
4645 Image1DBuffer() { }
4646
4654 explicit Image1DBuffer(const cl_mem& image1D, bool retainObject = false) :
4655 Image(image1D, retainObject) { }
4656
4657 Image1DBuffer& operator = (const cl_mem& rhs)
4658 {
4659 Image::operator=(rhs);
4660 return *this;
4661 }
4662
4666 Image1DBuffer(const Image1DBuffer& img) : Image(img) {}
4667
4671 Image1DBuffer& operator = (const Image1DBuffer &img)
4672 {
4673 Image::operator=(img);
4674 return *this;
4675 }
4676
4680 Image1DBuffer(Image1DBuffer&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4681
4685 Image1DBuffer& operator = (Image1DBuffer &&img)
4686 {
4687 Image::operator=(std::move(img));
4688 return *this;
4689 }
4690
4691};
4692
4696class Image1DArray : public Image
4697{
4698public:
4700 const Context& context,
4701 cl_mem_flags flags,
4702 ImageFormat format,
4703 size_type arraySize,
4704 size_type width,
4705 size_type rowPitch,
4706 void* host_ptr = NULL,
4707 cl_int* err = NULL)
4708 {
4709 cl_int error;
4710
4711 cl_image_desc desc = {0};
4712 desc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
4713 desc.image_width = width;
4714 desc.image_array_size = arraySize;
4715 desc.image_row_pitch = rowPitch;
4716
4717 object_ = ::clCreateImage(
4718 context(),
4719 flags,
4720 &format,
4721 &desc,
4722 host_ptr,
4723 &error);
4724
4725 detail::errHandler(error, __CREATE_IMAGE_ERR);
4726 if (err != NULL) {
4727 *err = error;
4728 }
4729 }
4730
4731 Image1DArray() { }
4732
4740 explicit Image1DArray(const cl_mem& imageArray, bool retainObject = false) :
4741 Image(imageArray, retainObject) { }
4742
4743
4744 Image1DArray& operator = (const cl_mem& rhs)
4745 {
4746 Image::operator=(rhs);
4747 return *this;
4748 }
4749
4753 Image1DArray(const Image1DArray& img) : Image(img) {}
4754
4758 Image1DArray& operator = (const Image1DArray &img)
4759 {
4760 Image::operator=(img);
4761 return *this;
4762 }
4763
4767 Image1DArray(Image1DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4768
4772 Image1DArray& operator = (Image1DArray &&img)
4773 {
4774 Image::operator=(std::move(img));
4775 return *this;
4776 }
4777
4778};
4779#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4780
4781
4788class Image2D : public Image
4789{
4790public:
4796 const Context& context,
4797 cl_mem_flags flags,
4798 ImageFormat format,
4799 size_type width,
4800 size_type height,
4801 size_type row_pitch = 0,
4802 void* host_ptr = NULL,
4803 cl_int* err = NULL)
4804 {
4805 cl_int error;
4806 bool useCreateImage;
4807
4808#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
4809 // Run-time decision based on the actual platform
4810 {
4811 cl_uint version = detail::getContextPlatformVersion(context());
4812 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
4813 }
4814#elif CL_HPP_TARGET_OPENCL_VERSION >= 120
4815 useCreateImage = true;
4816#else
4817 useCreateImage = false;
4818#endif
4819
4820#if CL_HPP_TARGET_OPENCL_VERSION >= 120
4821 if (useCreateImage)
4822 {
4823 cl_image_desc desc = {0};
4824 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
4825 desc.image_width = width;
4826 desc.image_height = height;
4827 desc.image_row_pitch = row_pitch;
4828
4829 object_ = ::clCreateImage(
4830 context(),
4831 flags,
4832 &format,
4833 &desc,
4834 host_ptr,
4835 &error);
4836
4837 detail::errHandler(error, __CREATE_IMAGE_ERR);
4838 if (err != NULL) {
4839 *err = error;
4840 }
4841 }
4842#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
4843#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
4844 if (!useCreateImage)
4845 {
4846 object_ = ::clCreateImage2D(
4847 context(), flags,&format, width, height, row_pitch, host_ptr, &error);
4848
4849 detail::errHandler(error, __CREATE_IMAGE2D_ERR);
4850 if (err != NULL) {
4851 *err = error;
4852 }
4853 }
4854#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
4855 }
4856
4857#if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4864 const Context& context,
4865 ImageFormat format,
4866 const Buffer &sourceBuffer,
4867 size_type width,
4868 size_type height,
4869 size_type row_pitch = 0,
4870 cl_int* err = nullptr)
4871 {
4872 cl_int error;
4873
4874 cl_image_desc desc = {0};
4875 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
4876 desc.image_width = width;
4877 desc.image_height = height;
4878 desc.image_row_pitch = row_pitch;
4879 desc.buffer = sourceBuffer();
4880
4881 object_ = ::clCreateImage(
4882 context(),
4883 0, // flags inherited from buffer
4884 &format,
4885 &desc,
4886 nullptr,
4887 &error);
4888
4889 detail::errHandler(error, __CREATE_IMAGE_ERR);
4890 if (err != nullptr) {
4891 *err = error;
4892 }
4893 }
4894#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4895
4896#if CL_HPP_TARGET_OPENCL_VERSION >= 200
4910 const Context& context,
4911 cl_channel_order order,
4912 const Image &sourceImage,
4913 cl_int* err = nullptr)
4914 {
4915 cl_int error;
4916
4917 // Descriptor fields have to match source image
4918 size_type sourceWidth =
4919 sourceImage.getImageInfo<CL_IMAGE_WIDTH>();
4920 size_type sourceHeight =
4921 sourceImage.getImageInfo<CL_IMAGE_HEIGHT>();
4922 size_type sourceRowPitch =
4923 sourceImage.getImageInfo<CL_IMAGE_ROW_PITCH>();
4924 cl_uint sourceNumMIPLevels =
4925 sourceImage.getImageInfo<CL_IMAGE_NUM_MIP_LEVELS>();
4926 cl_uint sourceNumSamples =
4927 sourceImage.getImageInfo<CL_IMAGE_NUM_SAMPLES>();
4928 cl_image_format sourceFormat =
4929 sourceImage.getImageInfo<CL_IMAGE_FORMAT>();
4930
4931 // Update only the channel order.
4932 // Channel format inherited from source.
4933 sourceFormat.image_channel_order = order;
4934
4935 cl_image_desc desc = {0};
4936 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
4937 desc.image_width = sourceWidth;
4938 desc.image_height = sourceHeight;
4939 desc.image_row_pitch = sourceRowPitch;
4940 desc.num_mip_levels = sourceNumMIPLevels;
4941 desc.num_samples = sourceNumSamples;
4942 desc.buffer = sourceImage();
4943
4944 object_ = ::clCreateImage(
4945 context(),
4946 0, // flags should be inherited from mem_object
4947 &sourceFormat,
4948 &desc,
4949 nullptr,
4950 &error);
4951
4952 detail::errHandler(error, __CREATE_IMAGE_ERR);
4953 if (err != nullptr) {
4954 *err = error;
4955 }
4956 }
4957#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200
4958
4961
4969 explicit Image2D(const cl_mem& image2D, bool retainObject = false) :
4970 Image(image2D, retainObject) { }
4971
4976 Image2D& operator = (const cl_mem& rhs)
4977 {
4978 Image::operator=(rhs);
4979 return *this;
4980 }
4981
4985 Image2D(const Image2D& img) : Image(img) {}
4986
4991 {
4992 Image::operator=(img);
4993 return *this;
4994 }
4995
4999 Image2D(Image2D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5000
5005 {
5006 Image::operator=(std::move(img));
5007 return *this;
5008 }
5009
5010};
5011
5012
5013#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
5023class CL_API_PREFIX__VERSION_1_1_DEPRECATED Image2DGL : public Image2D
5024{
5025public:
5032 const Context& context,
5033 cl_mem_flags flags,
5034 cl_GLenum target,
5035 cl_GLint miplevel,
5036 cl_GLuint texobj,
5037 cl_int * err = NULL)
5038 {
5039 cl_int error;
5040 object_ = ::clCreateFromGLTexture2D(
5041 context(),
5042 flags,
5043 target,
5044 miplevel,
5045 texobj,
5046 &error);
5047
5048 detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR);
5049 if (err != NULL) {
5050 *err = error;
5051 }
5052
5053 }
5054
5057
5065 explicit Image2DGL(const cl_mem& image, bool retainObject = false) :
5066 Image2D(image, retainObject) { }
5067
5072 Image2DGL& operator = (const cl_mem& rhs)
5073 {
5074 Image2D::operator=(rhs);
5075 return *this;
5076 }
5077
5081 Image2DGL(const Image2DGL& img) : Image2D(img) {}
5082
5086 Image2DGL& operator = (const Image2DGL &img)
5087 {
5088 Image2D::operator=(img);
5089 return *this;
5090 }
5091
5095 Image2DGL(Image2DGL&& img) CL_HPP_NOEXCEPT_ : Image2D(std::move(img)) {}
5096
5100 Image2DGL& operator = (Image2DGL &&img)
5101 {
5102 Image2D::operator=(std::move(img));
5103 return *this;
5104 }
5105
5106} CL_API_SUFFIX__VERSION_1_1_DEPRECATED;
5107#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5108
5109#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5113class Image2DArray : public Image
5114{
5115public:
5117 const Context& context,
5118 cl_mem_flags flags,
5119 ImageFormat format,
5120 size_type arraySize,
5121 size_type width,
5122 size_type height,
5123 size_type rowPitch,
5124 size_type slicePitch,
5125 void* host_ptr = NULL,
5126 cl_int* err = NULL)
5127 {
5128 cl_int error;
5129
5130 cl_image_desc desc = {0};
5131 desc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
5132 desc.image_width = width;
5133 desc.image_height = height;
5134 desc.image_array_size = arraySize;
5135 desc.image_row_pitch = rowPitch;
5136 desc.image_slice_pitch = slicePitch;
5137
5138 object_ = ::clCreateImage(
5139 context(),
5140 flags,
5141 &format,
5142 &desc,
5143 host_ptr,
5144 &error);
5145
5146 detail::errHandler(error, __CREATE_IMAGE_ERR);
5147 if (err != NULL) {
5148 *err = error;
5149 }
5150 }
5151
5152 Image2DArray() { }
5153
5161 explicit Image2DArray(const cl_mem& imageArray, bool retainObject = false) : Image(imageArray, retainObject) { }
5162
5163 Image2DArray& operator = (const cl_mem& rhs)
5164 {
5165 Image::operator=(rhs);
5166 return *this;
5167 }
5168
5172 Image2DArray(const Image2DArray& img) : Image(img) {}
5173
5177 Image2DArray& operator = (const Image2DArray &img)
5178 {
5179 Image::operator=(img);
5180 return *this;
5181 }
5182
5186 Image2DArray(Image2DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5187
5191 Image2DArray& operator = (Image2DArray &&img)
5192 {
5193 Image::operator=(std::move(img));
5194 return *this;
5195 }
5196};
5197#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5198
5205class Image3D : public Image
5206{
5207public:
5213 const Context& context,
5214 cl_mem_flags flags,
5215 ImageFormat format,
5216 size_type width,
5217 size_type height,
5218 size_type depth,
5219 size_type row_pitch = 0,
5220 size_type slice_pitch = 0,
5221 void* host_ptr = NULL,
5222 cl_int* err = NULL)
5223 {
5224 cl_int error;
5225 bool useCreateImage;
5226
5227#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
5228 // Run-time decision based on the actual platform
5229 {
5230 cl_uint version = detail::getContextPlatformVersion(context());
5231 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
5232 }
5233#elif CL_HPP_TARGET_OPENCL_VERSION >= 120
5234 useCreateImage = true;
5235#else
5236 useCreateImage = false;
5237#endif
5238
5239#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5240 if (useCreateImage)
5241 {
5242 cl_image_desc desc = {0};
5243 desc.image_type = CL_MEM_OBJECT_IMAGE3D;
5244 desc.image_width = width;
5245 desc.image_height = height;
5246 desc.image_depth = depth;
5247 desc.image_row_pitch = row_pitch;
5248 desc.image_slice_pitch = slice_pitch;
5249
5250 object_ = ::clCreateImage(
5251 context(),
5252 flags,
5253 &format,
5254 &desc,
5255 host_ptr,
5256 &error);
5257
5258 detail::errHandler(error, __CREATE_IMAGE_ERR);
5259 if (err != NULL) {
5260 *err = error;
5261 }
5262 }
5263#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5264#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
5265 if (!useCreateImage)
5266 {
5267 object_ = ::clCreateImage3D(
5268 context(), flags, &format, width, height, depth, row_pitch,
5269 slice_pitch, host_ptr, &error);
5270
5271 detail::errHandler(error, __CREATE_IMAGE3D_ERR);
5272 if (err != NULL) {
5273 *err = error;
5274 }
5275 }
5276#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
5277 }
5278
5280 Image3D() : Image() { }
5281
5289 explicit Image3D(const cl_mem& image3D, bool retainObject = false) :
5290 Image(image3D, retainObject) { }
5291
5296 Image3D& operator = (const cl_mem& rhs)
5297 {
5298 Image::operator=(rhs);
5299 return *this;
5300 }
5301
5305 Image3D(const Image3D& img) : Image(img) {}
5306
5311 {
5312 Image::operator=(img);
5313 return *this;
5314 }
5315
5319 Image3D(Image3D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5320
5325 {
5326 Image::operator=(std::move(img));
5327 return *this;
5328 }
5329};
5330
5331#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
5340class Image3DGL : public Image3D
5341{
5342public:
5349 const Context& context,
5350 cl_mem_flags flags,
5351 cl_GLenum target,
5352 cl_GLint miplevel,
5353 cl_GLuint texobj,
5354 cl_int * err = NULL)
5355 {
5356 cl_int error;
5357 object_ = ::clCreateFromGLTexture3D(
5358 context(),
5359 flags,
5360 target,
5361 miplevel,
5362 texobj,
5363 &error);
5364
5365 detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR);
5366 if (err != NULL) {
5367 *err = error;
5368 }
5369 }
5370
5373
5381 explicit Image3DGL(const cl_mem& image, bool retainObject = false) :
5382 Image3D(image, retainObject) { }
5383
5388 Image3DGL& operator = (const cl_mem& rhs)
5389 {
5390 Image3D::operator=(rhs);
5391 return *this;
5392 }
5393
5397 Image3DGL(const Image3DGL& img) : Image3D(img) {}
5398
5403 {
5404 Image3D::operator=(img);
5405 return *this;
5406 }
5407
5411 Image3DGL(Image3DGL&& img) CL_HPP_NOEXCEPT_ : Image3D(std::move(img)) {}
5412
5417 {
5418 Image3D::operator=(std::move(img));
5419 return *this;
5420 }
5421};
5422#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5423
5424#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5431class ImageGL : public Image
5432{
5433public:
5434 ImageGL(
5435 const Context& context,
5436 cl_mem_flags flags,
5437 cl_GLenum target,
5438 cl_GLint miplevel,
5439 cl_GLuint texobj,
5440 cl_int * err = NULL)
5441 {
5442 cl_int error;
5443 object_ = ::clCreateFromGLTexture(
5444 context(),
5445 flags,
5446 target,
5447 miplevel,
5448 texobj,
5449 &error);
5450
5451 detail::errHandler(error, __CREATE_GL_TEXTURE_ERR);
5452 if (err != NULL) {
5453 *err = error;
5454 }
5455 }
5456
5457 ImageGL() : Image() { }
5458
5466 explicit ImageGL(const cl_mem& image, bool retainObject = false) :
5467 Image(image, retainObject) { }
5468
5469 ImageGL& operator = (const cl_mem& rhs)
5470 {
5471 Image::operator=(rhs);
5472 return *this;
5473 }
5474
5478 ImageGL(const ImageGL& img) : Image(img) {}
5479
5483 ImageGL& operator = (const ImageGL &img)
5484 {
5485 Image::operator=(img);
5486 return *this;
5487 }
5488
5492 ImageGL(ImageGL&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5493
5497 ImageGL& operator = (ImageGL &&img)
5498 {
5499 Image::operator=(std::move(img));
5500 return *this;
5501 }
5502};
5503#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5504
5505
5506
5507#if CL_HPP_TARGET_OPENCL_VERSION >= 200
5514class Pipe : public Memory
5515{
5516public:
5517
5528 const Context& context,
5529 cl_uint packet_size,
5530 cl_uint max_packets,
5531 cl_int* err = NULL)
5532 {
5533 cl_int error;
5534
5535 cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5536 object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error);
5537
5538 detail::errHandler(error, __CREATE_PIPE_ERR);
5539 if (err != NULL) {
5540 *err = error;
5541 }
5542 }
5543
5553 cl_uint packet_size,
5554 cl_uint max_packets,
5555 cl_int* err = NULL)
5556 {
5557 cl_int error;
5558
5559 Context context = Context::getDefault(err);
5560
5561 cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5562 object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error);
5563
5564 detail::errHandler(error, __CREATE_PIPE_ERR);
5565 if (err != NULL) {
5566 *err = error;
5567 }
5568 }
5569
5571 Pipe() : Memory() { }
5572
5580 explicit Pipe(const cl_mem& pipe, bool retainObject = false) :
5581 Memory(pipe, retainObject) { }
5582
5587 Pipe& operator = (const cl_mem& rhs)
5588 {
5589 Memory::operator=(rhs);
5590 return *this;
5591 }
5592
5596 Pipe(const Pipe& pipe) : Memory(pipe) {}
5597
5601 Pipe& operator = (const Pipe &pipe)
5602 {
5603 Memory::operator=(pipe);
5604 return *this;
5605 }
5606
5610 Pipe(Pipe&& pipe) CL_HPP_NOEXCEPT_ : Memory(std::move(pipe)) {}
5611
5616 {
5617 Memory::operator=(std::move(pipe));
5618 return *this;
5619 }
5620
5622 template <typename T>
5623 cl_int getInfo(cl_pipe_info name, T* param) const
5624 {
5625 return detail::errHandler(
5626 detail::getInfo(&::clGetPipeInfo, object_, name, param),
5627 __GET_PIPE_INFO_ERR);
5628 }
5629
5631 template <cl_pipe_info name> typename
5633 getInfo(cl_int* err = NULL) const
5634 {
5635 typename detail::param_traits<
5636 detail::cl_pipe_info, name>::param_type param;
5637 cl_int result = getInfo(name, &param);
5638 if (err != NULL) {
5639 *err = result;
5640 }
5641 return param;
5642 }
5643}; // class Pipe
5644#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
5645
5646
5655class Sampler : public detail::Wrapper<cl_sampler>
5656{
5657public:
5660
5666 const Context& context,
5667 cl_bool normalized_coords,
5668 cl_addressing_mode addressing_mode,
5669 cl_filter_mode filter_mode,
5670 cl_int* err = NULL)
5671 {
5672 cl_int error;
5673
5674#if CL_HPP_TARGET_OPENCL_VERSION >= 200
5675 cl_sampler_properties sampler_properties[] = {
5676 CL_SAMPLER_NORMALIZED_COORDS, normalized_coords,
5677 CL_SAMPLER_ADDRESSING_MODE, addressing_mode,
5678 CL_SAMPLER_FILTER_MODE, filter_mode,
5679 0 };
5680 object_ = ::clCreateSamplerWithProperties(
5681 context(),
5682 sampler_properties,
5683 &error);
5684
5685 detail::errHandler(error, __CREATE_SAMPLER_WITH_PROPERTIES_ERR);
5686 if (err != NULL) {
5687 *err = error;
5688 }
5689#else
5690 object_ = ::clCreateSampler(
5691 context(),
5692 normalized_coords,
5693 addressing_mode,
5694 filter_mode,
5695 &error);
5696
5697 detail::errHandler(error, __CREATE_SAMPLER_ERR);
5698 if (err != NULL) {
5699 *err = error;
5700 }
5701#endif
5702 }
5703
5712 explicit Sampler(const cl_sampler& sampler, bool retainObject = false) :
5713 detail::Wrapper<cl_type>(sampler, retainObject) { }
5714
5720 Sampler& operator = (const cl_sampler& rhs)
5721 {
5723 return *this;
5724 }
5725
5729 Sampler(const Sampler& sam) : detail::Wrapper<cl_type>(sam) {}
5730
5735 {
5737 return *this;
5738 }
5739
5743 Sampler(Sampler&& sam) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(sam)) {}
5744
5749 {
5751 return *this;
5752 }
5753
5755 template <typename T>
5756 cl_int getInfo(cl_sampler_info name, T* param) const
5757 {
5758 return detail::errHandler(
5759 detail::getInfo(&::clGetSamplerInfo, object_, name, param),
5760 __GET_SAMPLER_INFO_ERR);
5761 }
5762
5764 template <cl_sampler_info name> typename
5766 getInfo(cl_int* err = NULL) const
5767 {
5768 typename detail::param_traits<
5769 detail::cl_sampler_info, name>::param_type param;
5770 cl_int result = getInfo(name, &param);
5771 if (err != NULL) {
5772 *err = result;
5773 }
5774 return param;
5775 }
5776};
5777
5778class Program;
5779class CommandQueue;
5780class DeviceCommandQueue;
5781class Kernel;
5782
5785{
5786private:
5787 size_type sizes_[3];
5788 cl_uint dimensions_;
5789
5790public:
5793 : dimensions_(0)
5794 {
5795 sizes_[0] = 0;
5796 sizes_[1] = 0;
5797 sizes_[2] = 0;
5798 }
5799
5801 NDRange(size_type size0)
5802 : dimensions_(1)
5803 {
5804 sizes_[0] = size0;
5805 sizes_[1] = 1;
5806 sizes_[2] = 1;
5807 }
5808
5810 NDRange(size_type size0, size_type size1)
5811 : dimensions_(2)
5812 {
5813 sizes_[0] = size0;
5814 sizes_[1] = size1;
5815 sizes_[2] = 1;
5816 }
5817
5819 NDRange(size_type size0, size_type size1, size_type size2)
5820 : dimensions_(3)
5821 {
5822 sizes_[0] = size0;
5823 sizes_[1] = size1;
5824 sizes_[2] = size2;
5825 }
5826
5831 operator const size_type*() const {
5832 return sizes_;
5833 }
5834
5836 size_type dimensions() const
5837 {
5838 return dimensions_;
5839 }
5840
5842 // runtime number of dimensions
5843 size_type size() const
5844 {
5845 return dimensions_*sizeof(size_type);
5846 }
5847
5848 size_type* get()
5849 {
5850 return sizes_;
5851 }
5852
5853 const size_type* get() const
5854 {
5855 return sizes_;
5856 }
5857};
5858
5860static const NDRange NullRange;
5861
5864{
5865 size_type size_;
5866};
5867
5868namespace detail {
5869
5870template <typename T, class Enable = void>
5872
5873// Enable for objects that are not subclasses of memory
5874// Pointers, constants etc
5875template <typename T>
5876struct KernelArgumentHandler<T, typename std::enable_if<!std::is_base_of<cl::Memory, T>::value>::type>
5877{
5878 static size_type size(const T&) { return sizeof(T); }
5879 static const T* ptr(const T& value) { return &value; }
5880};
5881
5882// Enable for subclasses of memory where we want to get a reference to the cl_mem out
5883// and pass that in for safety
5884template <typename T>
5885struct KernelArgumentHandler<T, typename std::enable_if<std::is_base_of<cl::Memory, T>::value>::type>
5886{
5887 static size_type size(const T&) { return sizeof(cl_mem); }
5888 static const cl_mem* ptr(const T& value) { return &(value()); }
5889};
5890
5891// Specialization for DeviceCommandQueue defined later
5892
5893template <>
5895{
5896 static size_type size(const LocalSpaceArg& value) { return value.size_; }
5897 static const void* ptr(const LocalSpaceArg&) { return NULL; }
5898};
5899
5900}
5902
5906inline LocalSpaceArg
5907Local(size_type size)
5908{
5909 LocalSpaceArg ret = { size };
5910 return ret;
5911}
5912
5921class Kernel : public detail::Wrapper<cl_kernel>
5922{
5923public:
5924 inline Kernel(const Program& program, const char* name, cl_int* err = NULL);
5925
5928
5937 explicit Kernel(const cl_kernel& kernel, bool retainObject = false) :
5938 detail::Wrapper<cl_type>(kernel, retainObject) { }
5939
5945 Kernel& operator = (const cl_kernel& rhs)
5946 {
5948 return *this;
5949 }
5950
5954 Kernel(const Kernel& kernel) : detail::Wrapper<cl_type>(kernel) {}
5955
5959 Kernel& operator = (const Kernel &kernel)
5960 {
5962 return *this;
5963 }
5964
5968 Kernel(Kernel&& kernel) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(kernel)) {}
5969
5974 {
5975 detail::Wrapper<cl_type>::operator=(std::move(kernel));
5976 return *this;
5977 }
5978
5979 template <typename T>
5980 cl_int getInfo(cl_kernel_info name, T* param) const
5981 {
5982 return detail::errHandler(
5983 detail::getInfo(&::clGetKernelInfo, object_, name, param),
5984 __GET_KERNEL_INFO_ERR);
5985 }
5986
5987 template <cl_kernel_info name> typename
5988 detail::param_traits<detail::cl_kernel_info, name>::param_type
5989 getInfo(cl_int* err = NULL) const
5990 {
5991 typename detail::param_traits<
5992 detail::cl_kernel_info, name>::param_type param;
5993 cl_int result = getInfo(name, &param);
5994 if (err != NULL) {
5995 *err = result;
5996 }
5997 return param;
5998 }
5999
6000#if CL_HPP_TARGET_OPENCL_VERSION >= 120
6001 template <typename T>
6002 cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const
6003 {
6004 return detail::errHandler(
6005 detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param),
6006 __GET_KERNEL_ARG_INFO_ERR);
6007 }
6008
6009 template <cl_kernel_arg_info name> typename
6010 detail::param_traits<detail::cl_kernel_arg_info, name>::param_type
6011 getArgInfo(cl_uint argIndex, cl_int* err = NULL) const
6012 {
6013 typename detail::param_traits<
6014 detail::cl_kernel_arg_info, name>::param_type param;
6015 cl_int result = getArgInfo(argIndex, name, &param);
6016 if (err != NULL) {
6017 *err = result;
6018 }
6019 return param;
6020 }
6021#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6022
6023 template <typename T>
6024 cl_int getWorkGroupInfo(
6025 const Device& device, cl_kernel_work_group_info name, T* param) const
6026 {
6027 return detail::errHandler(
6028 detail::getInfo(
6029 &::clGetKernelWorkGroupInfo, object_, device(), name, param),
6030 __GET_KERNEL_WORK_GROUP_INFO_ERR);
6031 }
6032
6033 template <cl_kernel_work_group_info name> typename
6034 detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
6035 getWorkGroupInfo(const Device& device, cl_int* err = NULL) const
6036 {
6037 typename detail::param_traits<
6038 detail::cl_kernel_work_group_info, name>::param_type param;
6039 cl_int result = getWorkGroupInfo(device, name, &param);
6040 if (err != NULL) {
6041 *err = result;
6042 }
6043 return param;
6044 }
6045
6046#if (CL_HPP_TARGET_OPENCL_VERSION >= 200 && defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)) || CL_HPP_TARGET_OPENCL_VERSION >= 210
6047 cl_int getSubGroupInfo(const cl::Device &dev, cl_kernel_sub_group_info name, const cl::NDRange &range, size_type* param) const
6048 {
6049#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6050
6051 return detail::errHandler(
6052 clGetKernelSubGroupInfo(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
6053 __GET_KERNEL_SUB_GROUP_INFO_ERR);
6054
6055#else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6056
6057 typedef clGetKernelSubGroupInfoKHR_fn PFN_clGetKernelSubGroupInfoKHR;
6058 static PFN_clGetKernelSubGroupInfoKHR pfn_clGetKernelSubGroupInfoKHR = NULL;
6059 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetKernelSubGroupInfoKHR);
6060
6061 return detail::errHandler(
6062 pfn_clGetKernelSubGroupInfoKHR(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
6063 __GET_KERNEL_SUB_GROUP_INFO_ERR);
6064
6065#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6066 }
6067
6068 template <cl_kernel_sub_group_info name>
6069 size_type getSubGroupInfo(const cl::Device &dev, const cl::NDRange &range, cl_int* err = NULL) const
6070 {
6071 size_type param;
6072 cl_int result = getSubGroupInfo(dev, name, range, &param);
6073 if (err != NULL) {
6074 *err = result;
6075 }
6076 return param;
6077 }
6078#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6079
6080#if CL_HPP_TARGET_OPENCL_VERSION >= 200
6083 template<typename T, class D>
6084 cl_int setArg(cl_uint index, const cl::pointer<T, D> &argPtr)
6085 {
6086 return detail::errHandler(
6087 ::clSetKernelArgSVMPointer(object_, index, argPtr.get()),
6088 __SET_KERNEL_ARGS_ERR);
6089 }
6090
6093 template<typename T, class Alloc>
6094 cl_int setArg(cl_uint index, const cl::vector<T, Alloc> &argPtr)
6095 {
6096 return detail::errHandler(
6097 ::clSetKernelArgSVMPointer(object_, index, argPtr.data()),
6098 __SET_KERNEL_ARGS_ERR);
6099 }
6100
6103 template<typename T>
6104 typename std::enable_if<std::is_pointer<T>::value, cl_int>::type
6105 setArg(cl_uint index, const T argPtr)
6106 {
6107 return detail::errHandler(
6108 ::clSetKernelArgSVMPointer(object_, index, argPtr),
6109 __SET_KERNEL_ARGS_ERR);
6110 }
6111#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6112
6115 template <typename T>
6116 typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6117 setArg(cl_uint index, const T &value)
6118 {
6119 return detail::errHandler(
6120 ::clSetKernelArg(
6121 object_,
6122 index,
6125 __SET_KERNEL_ARGS_ERR);
6126 }
6127
6128 cl_int setArg(cl_uint index, size_type size, const void* argPtr)
6129 {
6130 return detail::errHandler(
6131 ::clSetKernelArg(object_, index, size, argPtr),
6132 __SET_KERNEL_ARGS_ERR);
6133 }
6134
6135#if CL_HPP_TARGET_OPENCL_VERSION >= 200
6140 cl_int setSVMPointers(const vector<void*> &pointerList)
6141 {
6142 return detail::errHandler(
6143 ::clSetKernelExecInfo(
6144 object_,
6145 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6146 sizeof(void*)*pointerList.size(),
6147 pointerList.data()));
6148 }
6149
6154 template<int ArrayLength>
6155 cl_int setSVMPointers(const std::array<void*, ArrayLength> &pointerList)
6156 {
6157 return detail::errHandler(
6158 ::clSetKernelExecInfo(
6159 object_,
6160 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6161 sizeof(void*)*pointerList.size(),
6162 pointerList.data()));
6163 }
6164
6176 cl_int enableFineGrainedSystemSVM(bool svmEnabled)
6177 {
6178 cl_bool svmEnabled_ = svmEnabled ? CL_TRUE : CL_FALSE;
6179 return detail::errHandler(
6180 ::clSetKernelExecInfo(
6181 object_,
6182 CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM,
6183 sizeof(cl_bool),
6184 &svmEnabled_
6185 )
6186 );
6187 }
6188
6189 template<int index, int ArrayLength, class D, typename T0, typename T1, typename... Ts>
6190 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0, const pointer<T1, D> &t1, Ts & ... ts)
6191 {
6192 pointerList[index] = static_cast<void*>(t0.get());
6193 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6194 }
6195
6196 template<int index, int ArrayLength, typename T0, typename T1, typename... Ts>
6197 typename std::enable_if<std::is_pointer<T0>::value, void>::type
6198 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0, T1 t1, Ts... ts)
6199 {
6200 pointerList[index] = static_cast<void*>(t0);
6201 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6202 }
6203
6204 template<int index, int ArrayLength, typename T0, class D>
6205 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0)
6206 {
6207 pointerList[index] = static_cast<void*>(t0.get());
6208 }
6209
6210
6211 template<int index, int ArrayLength, typename T0>
6212 typename std::enable_if<std::is_pointer<T0>::value, void>::type
6213 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0)
6214 {
6215 pointerList[index] = static_cast<void*>(t0);
6216 }
6217
6218 template<typename T0, typename... Ts>
6219 cl_int setSVMPointers(const T0 &t0, Ts & ... ts)
6220 {
6221 std::array<void*, 1 + sizeof...(Ts)> pointerList;
6222
6223 setSVMPointersHelper<0, 1 + sizeof...(Ts)>(pointerList, t0, ts...);
6224 return detail::errHandler(
6225 ::clSetKernelExecInfo(
6226 object_,
6227 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6228 sizeof(void*)*(1 + sizeof...(Ts)),
6229 pointerList.data()));
6230 }
6231
6232 template<typename T>
6233 cl_int setExecInfo(cl_kernel_exec_info param_name, const T& val)
6234 {
6235 return detail::errHandler(
6236 ::clSetKernelExecInfo(
6237 object_,
6238 param_name,
6239 sizeof(T),
6240 &val));
6241 }
6242
6243 template<cl_kernel_exec_info name>
6244 cl_int setExecInfo(typename detail::param_traits<detail::cl_kernel_exec_info, name>::param_type& val)
6245 {
6246 return setExecInfo(name, val);
6247 }
6248#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6249
6250#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6257 {
6258 cl_int error;
6259 Kernel retValue(clCloneKernel(this->get(), &error));
6260
6261 detail::errHandler(error, __CLONE_KERNEL_ERR);
6262 return retValue;
6263 }
6264#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6265};
6266
6270class Program : public detail::Wrapper<cl_program>
6271{
6272public:
6273#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6274 typedef vector<vector<unsigned char>> Binaries;
6275 typedef vector<string> Sources;
6276#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6277 typedef vector<std::pair<const void*, size_type> > Binaries;
6278 typedef vector<std::pair<const char*, size_type> > Sources;
6279#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6280
6281 Program(
6282 const string& source,
6283 bool build = false,
6284 cl_int* err = NULL)
6285 {
6286 cl_int error;
6287
6288 const char * strings = source.c_str();
6289 const size_type length = source.size();
6290
6291 Context context = Context::getDefault(err);
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
6300 error = ::clBuildProgram(
6301 object_,
6302 0,
6303 NULL,
6304#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6305 "-cl-std=CL2.0",
6306#else
6307 "",
6308#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6309 NULL,
6310 NULL);
6311
6312 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6313 }
6314
6315 if (err != NULL) {
6316 *err = error;
6317 }
6318 }
6319
6320 Program(
6321 const Context& context,
6322 const string& source,
6323 bool build = false,
6324 cl_int* err = NULL)
6325 {
6326 cl_int error;
6327
6328 const char * strings = source.c_str();
6329 const size_type length = source.size();
6330
6331 object_ = ::clCreateProgramWithSource(
6332 context(), (cl_uint)1, &strings, &length, &error);
6333
6334 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6335
6336 if (error == CL_SUCCESS && build) {
6337 error = ::clBuildProgram(
6338 object_,
6339 0,
6340 NULL,
6341#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6342 "-cl-std=CL2.0",
6343#else
6344 "",
6345#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6346 NULL,
6347 NULL);
6348
6349 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6350 }
6351
6352 if (err != NULL) {
6353 *err = error;
6354 }
6355 }
6356
6362 const Sources& sources,
6363 cl_int* err = NULL)
6364 {
6365 cl_int error;
6366 Context context = Context::getDefault(err);
6367
6368 const size_type n = (size_type)sources.size();
6369
6370 vector<size_type> lengths(n);
6371 vector<const char*> strings(n);
6372
6373 for (size_type i = 0; i < n; ++i) {
6374#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6375 strings[i] = sources[(int)i].data();
6376 lengths[i] = sources[(int)i].length();
6377#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6378 strings[i] = sources[(int)i].first;
6379 lengths[i] = sources[(int)i].second;
6380#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6381 }
6382
6383 object_ = ::clCreateProgramWithSource(
6384 context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6385
6386 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6387 if (err != NULL) {
6388 *err = error;
6389 }
6390 }
6391
6397 const Context& context,
6398 const Sources& sources,
6399 cl_int* err = NULL)
6400 {
6401 cl_int error;
6402
6403 const size_type n = (size_type)sources.size();
6404
6405 vector<size_type> lengths(n);
6406 vector<const char*> strings(n);
6407
6408 for (size_type i = 0; i < n; ++i) {
6409#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6410 strings[i] = sources[(int)i].data();
6411 lengths[i] = sources[(int)i].length();
6412#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6413 strings[i] = sources[(int)i].first;
6414 lengths[i] = sources[(int)i].second;
6415#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6416 }
6417
6418 object_ = ::clCreateProgramWithSource(
6419 context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6420
6421 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6422 if (err != NULL) {
6423 *err = error;
6424 }
6425 }
6426
6427
6428#if CL_HPP_TARGET_OPENCL_VERSION >= 210 || (CL_HPP_TARGET_OPENCL_VERSION==200 && defined(CL_HPP_USE_IL_KHR))
6434 const vector<char>& IL,
6435 bool build = false,
6436 cl_int* err = NULL)
6437 {
6438 cl_int error;
6439
6440 Context context = Context::getDefault(err);
6441
6442#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6443
6444 object_ = ::clCreateProgramWithIL(
6445 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6446
6447#else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6448
6449 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6450 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6451 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6452
6453 object_ = pfn_clCreateProgramWithILKHR(
6454 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6455
6456#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6457
6458 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6459
6460 if (error == CL_SUCCESS && build) {
6461
6462 error = ::clBuildProgram(
6463 object_,
6464 0,
6465 NULL,
6466#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6467 "-cl-std=CL2.0",
6468#else
6469 "",
6470#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6471 NULL,
6472 NULL);
6473
6474 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6475 }
6476
6477 if (err != NULL) {
6478 *err = error;
6479 }
6480 }
6481
6488 const Context& context,
6489 const vector<char>& IL,
6490 bool build = false,
6491 cl_int* err = NULL)
6492 {
6493 cl_int error;
6494
6495#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6496
6497 object_ = ::clCreateProgramWithIL(
6498 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6499
6500#else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6501
6502 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6503 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6504 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6505
6506 object_ = pfn_clCreateProgramWithILKHR(
6507 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6508
6509#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6510
6511 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6512
6513 if (error == CL_SUCCESS && build) {
6514 error = ::clBuildProgram(
6515 object_,
6516 0,
6517 NULL,
6518#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6519 "-cl-std=CL2.0",
6520#else
6521 "",
6522#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6523 NULL,
6524 NULL);
6525
6526 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6527 }
6528
6529 if (err != NULL) {
6530 *err = error;
6531 }
6532 }
6533#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6534
6555 const Context& context,
6556 const vector<Device>& devices,
6557 const Binaries& binaries,
6558 vector<cl_int>* binaryStatus = NULL,
6559 cl_int* err = NULL)
6560 {
6561 cl_int error;
6562
6563 const size_type numDevices = devices.size();
6564
6565 // Catch size mismatch early and return
6566 if(binaries.size() != numDevices) {
6567 error = CL_INVALID_VALUE;
6568 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6569 if (err != NULL) {
6570 *err = error;
6571 }
6572 return;
6573 }
6574
6575
6576 vector<size_type> lengths(numDevices);
6577 vector<const unsigned char*> images(numDevices);
6578#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6579 for (size_type i = 0; i < numDevices; ++i) {
6580 images[i] = binaries[i].data();
6581 lengths[i] = binaries[(int)i].size();
6582 }
6583#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6584 for (size_type i = 0; i < numDevices; ++i) {
6585 images[i] = (const unsigned char*)binaries[i].first;
6586 lengths[i] = binaries[(int)i].second;
6587 }
6588#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6589
6590 vector<cl_device_id> deviceIDs(numDevices);
6591 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6592 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6593 }
6594
6595 if(binaryStatus) {
6596 binaryStatus->resize(numDevices);
6597 }
6598
6599 object_ = ::clCreateProgramWithBinary(
6600 context(), (cl_uint) devices.size(),
6601 deviceIDs.data(),
6602 lengths.data(), images.data(), (binaryStatus != NULL && numDevices > 0)
6603 ? &binaryStatus->front()
6604 : NULL, &error);
6605
6606 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6607 if (err != NULL) {
6608 *err = error;
6609 }
6610 }
6611
6612
6613#if CL_HPP_TARGET_OPENCL_VERSION >= 120
6619 const Context& context,
6620 const vector<Device>& devices,
6621 const string& kernelNames,
6622 cl_int* err = NULL)
6623 {
6624 cl_int error;
6625
6626
6627 size_type numDevices = devices.size();
6628 vector<cl_device_id> deviceIDs(numDevices);
6629 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6630 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6631 }
6632
6633 object_ = ::clCreateProgramWithBuiltInKernels(
6634 context(),
6635 (cl_uint) devices.size(),
6636 deviceIDs.data(),
6637 kernelNames.c_str(),
6638 &error);
6639
6640 detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR);
6641 if (err != NULL) {
6642 *err = error;
6643 }
6644 }
6645#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6646
6647 Program() { }
6648
6649
6656 explicit Program(const cl_program& program, bool retainObject = false) :
6657 detail::Wrapper<cl_type>(program, retainObject) { }
6658
6659 Program& operator = (const cl_program& rhs)
6660 {
6662 return *this;
6663 }
6664
6668 Program(const Program& program) : detail::Wrapper<cl_type>(program) {}
6669
6673 Program& operator = (const Program &program)
6674 {
6676 return *this;
6677 }
6678
6682 Program(Program&& program) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(program)) {}
6683
6687 Program& operator = (Program &&program)
6688 {
6689 detail::Wrapper<cl_type>::operator=(std::move(program));
6690 return *this;
6691 }
6692
6693 cl_int build(
6694 const vector<Device>& devices,
6695 const char* options = NULL,
6696 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6697 void* data = NULL) const
6698 {
6699 size_type numDevices = devices.size();
6700 vector<cl_device_id> deviceIDs(numDevices);
6701
6702 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6703 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6704 }
6705
6706 cl_int buildError = ::clBuildProgram(
6707 object_,
6708 (cl_uint)
6709 devices.size(),
6710 deviceIDs.data(),
6711 options,
6712 notifyFptr,
6713 data);
6714
6715 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6716 }
6717
6718 cl_int build(
6719 const Device& device,
6720 const char* options = NULL,
6721 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6722 void* data = NULL) const
6723 {
6724 cl_device_id deviceID = device();
6725
6726 cl_int buildError = ::clBuildProgram(
6727 object_,
6728 1,
6729 &deviceID,
6730 options,
6731 notifyFptr,
6732 data);
6733
6734 BuildLogType buildLog(0);
6735 buildLog.push_back(std::make_pair(device, getBuildInfo<CL_PROGRAM_BUILD_LOG>(device)));
6736 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, buildLog);
6737 }
6738
6739 cl_int build(
6740 const char* options = NULL,
6741 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6742 void* data = NULL) const
6743 {
6744 cl_int buildError = ::clBuildProgram(
6745 object_,
6746 0,
6747 NULL,
6748 options,
6749 notifyFptr,
6750 data);
6751
6752 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6753 }
6754
6755#if CL_HPP_TARGET_OPENCL_VERSION >= 120
6756 cl_int compile(
6757 const char* options = NULL,
6758 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6759 void* data = NULL) const
6760 {
6761 cl_int error = ::clCompileProgram(
6762 object_,
6763 0,
6764 NULL,
6765 options,
6766 0,
6767 NULL,
6768 NULL,
6769 notifyFptr,
6770 data);
6771 return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6772 }
6773#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6774
6775 template <typename T>
6776 cl_int getInfo(cl_program_info name, T* param) const
6777 {
6778 return detail::errHandler(
6779 detail::getInfo(&::clGetProgramInfo, object_, name, param),
6780 __GET_PROGRAM_INFO_ERR);
6781 }
6782
6783 template <cl_program_info name> typename
6784 detail::param_traits<detail::cl_program_info, name>::param_type
6785 getInfo(cl_int* err = NULL) const
6786 {
6787 typename detail::param_traits<
6788 detail::cl_program_info, name>::param_type param;
6789 cl_int result = getInfo(name, &param);
6790 if (err != NULL) {
6791 *err = result;
6792 }
6793 return param;
6794 }
6795
6796 template <typename T>
6797 cl_int getBuildInfo(
6798 const Device& device, cl_program_build_info name, T* param) const
6799 {
6800 return detail::errHandler(
6801 detail::getInfo(
6802 &::clGetProgramBuildInfo, object_, device(), name, param),
6803 __GET_PROGRAM_BUILD_INFO_ERR);
6804 }
6805
6806 template <cl_program_build_info name> typename
6807 detail::param_traits<detail::cl_program_build_info, name>::param_type
6808 getBuildInfo(const Device& device, cl_int* err = NULL) const
6809 {
6810 typename detail::param_traits<
6811 detail::cl_program_build_info, name>::param_type param;
6812 cl_int result = getBuildInfo(device, name, &param);
6813 if (err != NULL) {
6814 *err = result;
6815 }
6816 return param;
6817 }
6818
6824 template <cl_program_build_info name>
6825 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6826 getBuildInfo(cl_int *err = NULL) const
6827 {
6828 cl_int result = CL_SUCCESS;
6829
6830 auto devs = getInfo<CL_PROGRAM_DEVICES>(&result);
6831 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6832 devInfo;
6833
6834 // If there was an initial error from getInfo return the error
6835 if (result != CL_SUCCESS) {
6836 if (err != NULL) {
6837 *err = result;
6838 }
6839 return devInfo;
6840 }
6841
6842 for (const cl::Device &d : devs) {
6843 typename detail::param_traits<
6844 detail::cl_program_build_info, name>::param_type param;
6845 result = getBuildInfo(d, name, &param);
6846 devInfo.push_back(
6848 (d, param));
6849 if (result != CL_SUCCESS) {
6850 // On error, leave the loop and return the error code
6851 break;
6852 }
6853 }
6854 if (err != NULL) {
6855 *err = result;
6856 }
6857 if (result != CL_SUCCESS) {
6858 devInfo.clear();
6859 }
6860 return devInfo;
6861 }
6862
6863 cl_int createKernels(vector<Kernel>* kernels)
6864 {
6865 cl_uint numKernels;
6866 cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
6867 if (err != CL_SUCCESS) {
6868 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6869 }
6870
6871 vector<cl_kernel> value(numKernels);
6872
6873 err = ::clCreateKernelsInProgram(
6874 object_, numKernels, value.data(), NULL);
6875 if (err != CL_SUCCESS) {
6876 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6877 }
6878
6879 if (kernels) {
6880 kernels->resize(value.size());
6881
6882 // Assign to param, constructing with retain behaviour
6883 // to correctly capture each underlying CL object
6884 for (size_type i = 0; i < value.size(); i++) {
6885 // We do not need to retain because this kernel is being created
6886 // by the runtime
6887 (*kernels)[i] = Kernel(value[i], false);
6888 }
6889 }
6890 return CL_SUCCESS;
6891 }
6892
6893#if CL_HPP_TARGET_OPENCL_VERSION >= 220
6894#if defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
6905 CL_API_PREFIX__VERSION_2_2_DEPRECATED cl_int setReleaseCallback(
6906 void (CL_CALLBACK * pfn_notify)(cl_program program, void * user_data),
6907 void * user_data = NULL) CL_API_SUFFIX__VERSION_2_2_DEPRECATED
6908 {
6909 return detail::errHandler(
6910 ::clSetProgramReleaseCallback(
6911 object_,
6912 pfn_notify,
6913 user_data),
6914 __SET_PROGRAM_RELEASE_CALLBACK_ERR);
6915 }
6916#endif // #if defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
6917
6922 template <typename T>
6923 typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6924 setSpecializationConstant(cl_uint index, const T &value)
6925 {
6926 return detail::errHandler(
6927 ::clSetProgramSpecializationConstant(
6928 object_,
6929 index,
6930 sizeof(value),
6931 &value),
6932 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6933 }
6934
6939 cl_int setSpecializationConstant(cl_uint index, size_type size, const void* value)
6940 {
6941 return detail::errHandler(
6942 ::clSetProgramSpecializationConstant(
6943 object_,
6944 index,
6945 size,
6946 value),
6947 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6948 }
6949#endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
6950};
6951
6952#if CL_HPP_TARGET_OPENCL_VERSION >= 120
6953inline Program linkProgram(
6954 Program input1,
6955 Program input2,
6956 const char* options = NULL,
6957 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6958 void* data = NULL,
6959 cl_int* err = NULL)
6960{
6961 cl_int error_local = CL_SUCCESS;
6962
6963 cl_program programs[2] = { input1(), input2() };
6964
6965 Context ctx = input1.getInfo<CL_PROGRAM_CONTEXT>(&error_local);
6966 if(error_local!=CL_SUCCESS) {
6967 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
6968 }
6969
6970 cl_program prog = ::clLinkProgram(
6971 ctx(),
6972 0,
6973 NULL,
6974 options,
6975 2,
6976 programs,
6977 notifyFptr,
6978 data,
6979 &error_local);
6980
6981 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
6982 if (err != NULL) {
6983 *err = error_local;
6984 }
6985
6986 return Program(prog);
6987}
6988
6989inline Program linkProgram(
6990 vector<Program> inputPrograms,
6991 const char* options = NULL,
6992 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6993 void* data = NULL,
6994 cl_int* err = NULL)
6995{
6996 cl_int error_local = CL_SUCCESS;
6997
6998 vector<cl_program> programs(inputPrograms.size());
6999
7000 for (unsigned int i = 0; i < inputPrograms.size(); i++) {
7001 programs[i] = inputPrograms[i]();
7002 }
7003
7004 Context ctx;
7005 if(inputPrograms.size() > 0) {
7006 ctx = inputPrograms[0].getInfo<CL_PROGRAM_CONTEXT>(&error_local);
7007 if(error_local!=CL_SUCCESS) {
7008 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
7009 }
7010 }
7011 cl_program prog = ::clLinkProgram(
7012 ctx(),
7013 0,
7014 NULL,
7015 options,
7016 (cl_uint)inputPrograms.size(),
7017 programs.data(),
7018 notifyFptr,
7019 data,
7020 &error_local);
7021
7022 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
7023 if (err != NULL) {
7024 *err = error_local;
7025 }
7026
7027 return Program(prog, false);
7028}
7029#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7030
7031// Template specialization for CL_PROGRAM_BINARIES
7032template <>
7033inline cl_int cl::Program::getInfo(cl_program_info name, vector<vector<unsigned char>>* param) const
7034{
7035 if (name != CL_PROGRAM_BINARIES) {
7036 return CL_INVALID_VALUE;
7037 }
7038 if (param) {
7039 // Resize the parameter array appropriately for each allocation
7040 // and pass down to the helper
7041
7042 vector<size_type> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>();
7043 size_type numBinaries = sizes.size();
7044
7045 // Resize the parameter array and constituent arrays
7046 param->resize(numBinaries);
7047 for (size_type i = 0; i < numBinaries; ++i) {
7048 (*param)[i].resize(sizes[i]);
7049 }
7050
7051 return detail::errHandler(
7052 detail::getInfo(&::clGetProgramInfo, object_, name, param),
7053 __GET_PROGRAM_INFO_ERR);
7054 }
7055
7056 return CL_SUCCESS;
7057}
7058
7059template<>
7060inline vector<vector<unsigned char>> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err) const
7061{
7062 vector<vector<unsigned char>> binariesVectors;
7063
7064 cl_int result = getInfo(CL_PROGRAM_BINARIES, &binariesVectors);
7065 if (err != NULL) {
7066 *err = result;
7067 }
7068 return binariesVectors;
7069}
7070
7071#if CL_HPP_TARGET_OPENCL_VERSION >= 220
7072// Template specialization for clSetProgramSpecializationConstant
7073template <>
7074inline cl_int cl::Program::setSpecializationConstant(cl_uint index, const bool &value)
7075{
7076 cl_uchar ucValue = value ? CL_UCHAR_MAX : 0;
7077 return detail::errHandler(
7078 ::clSetProgramSpecializationConstant(
7079 object_,
7080 index,
7081 sizeof(ucValue),
7082 &ucValue),
7083 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
7084}
7085#endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
7086
7087inline Kernel::Kernel(const Program& program, const char* name, cl_int* err)
7088{
7089 cl_int error;
7090
7091 object_ = ::clCreateKernel(program(), name, &error);
7092 detail::errHandler(error, __CREATE_KERNEL_ERR);
7093
7094 if (err != NULL) {
7095 *err = error;
7096 }
7097
7098}
7099
7100enum class QueueProperties : cl_command_queue_properties
7101{
7102 None = 0,
7103 Profiling = CL_QUEUE_PROFILING_ENABLE,
7104 OutOfOrder = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,
7105};
7106
7107inline QueueProperties operator|(QueueProperties lhs, QueueProperties rhs)
7108{
7109 return static_cast<QueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
7110}
7111
7112inline QueueProperties operator&(QueueProperties lhs, QueueProperties rhs)
7113{
7114 return static_cast<QueueProperties>(static_cast<cl_command_queue_properties>(lhs) & static_cast<cl_command_queue_properties>(rhs));
7115}
7116
7120class CommandQueue : public detail::Wrapper<cl_command_queue>
7121{
7122private:
7123 static std::once_flag default_initialized_;
7124 static CommandQueue default_;
7125 static cl_int default_error_;
7126
7132 static void makeDefault()
7133 {
7134 /* We don't want to throw an error from this function, so we have to
7135 * catch and set the error flag.
7136 */
7137#if defined(CL_HPP_ENABLE_EXCEPTIONS)
7138 try
7139#endif
7140 {
7141 int error;
7142 Context context = Context::getDefault(&error);
7143
7144 if (error != CL_SUCCESS) {
7145 default_error_ = error;
7146 }
7147 else {
7148 Device device = Device::getDefault();
7149 default_ = CommandQueue(context, device, 0, &default_error_);
7150 }
7151 }
7152#if defined(CL_HPP_ENABLE_EXCEPTIONS)
7153 catch (cl::Error &e) {
7154 default_error_ = e.err();
7155 }
7156#endif
7157 }
7158
7164 static void makeDefaultProvided(const CommandQueue &c) {
7165 default_ = c;
7166 }
7167
7168public:
7169#ifdef CL_HPP_UNIT_TEST_ENABLE
7176 static void unitTestClearDefault() {
7177 default_ = CommandQueue();
7178 }
7179#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
7180
7181
7187 cl_command_queue_properties properties,
7188 cl_int* err = NULL)
7189 {
7190 cl_int error;
7191
7192 Context context = Context::getDefault(&error);
7193 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7194
7195 if (error != CL_SUCCESS) {
7196 if (err != NULL) {
7197 *err = error;
7198 }
7199 }
7200 else {
7201 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7202 bool useWithProperties;
7203
7204#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7205 // Run-time decision based on the actual platform
7206 {
7207 cl_uint version = detail::getContextPlatformVersion(context());
7208 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7209 }
7210#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7211 useWithProperties = true;
7212#else
7213 useWithProperties = false;
7214#endif
7215
7216#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7217 if (useWithProperties) {
7218 cl_queue_properties queue_properties[] = {
7219 CL_QUEUE_PROPERTIES, properties, 0 };
7220 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7221 object_ = ::clCreateCommandQueueWithProperties(
7222 context(), device(), queue_properties, &error);
7223 }
7224 else {
7225 error = CL_INVALID_QUEUE_PROPERTIES;
7226 }
7227
7228 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7229 if (err != NULL) {
7230 *err = error;
7231 }
7232 }
7233#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7234#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7235 if (!useWithProperties) {
7236 object_ = ::clCreateCommandQueue(
7237 context(), device(), properties, &error);
7238
7239 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7240 if (err != NULL) {
7241 *err = error;
7242 }
7243 }
7244#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7245 }
7246 }
7247
7253 QueueProperties properties,
7254 cl_int* err = NULL)
7255 {
7256 cl_int error;
7257
7258 Context context = Context::getDefault(&error);
7259 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7260
7261 if (error != CL_SUCCESS) {
7262 if (err != NULL) {
7263 *err = error;
7264 }
7265 }
7266 else {
7267 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7268 bool useWithProperties;
7269
7270#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7271 // Run-time decision based on the actual platform
7272 {
7273 cl_uint version = detail::getContextPlatformVersion(context());
7274 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7275 }
7276#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7277 useWithProperties = true;
7278#else
7279 useWithProperties = false;
7280#endif
7281
7282#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7283 if (useWithProperties) {
7284 cl_queue_properties queue_properties[] = {
7285 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7286
7287 object_ = ::clCreateCommandQueueWithProperties(
7288 context(), device(), queue_properties, &error);
7289
7290 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7291 if (err != NULL) {
7292 *err = error;
7293 }
7294 }
7295#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7296#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7297 if (!useWithProperties) {
7298 object_ = ::clCreateCommandQueue(
7299 context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
7300
7301 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7302 if (err != NULL) {
7303 *err = error;
7304 }
7305 }
7306#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7307
7308 }
7309 }
7310
7316 const Context& context,
7317 cl_command_queue_properties properties = 0,
7318 cl_int* err = NULL)
7319 {
7320 cl_int error;
7321 bool useWithProperties;
7322 vector<cl::Device> devices;
7323 error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7324
7325 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7326
7327 if (error != CL_SUCCESS)
7328 {
7329 if (err != NULL) {
7330 *err = error;
7331 }
7332 return;
7333 }
7334
7335#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7336 // Run-time decision based on the actual platform
7337 {
7338 cl_uint version = detail::getContextPlatformVersion(context());
7339 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7340 }
7341#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7342 useWithProperties = true;
7343#else
7344 useWithProperties = false;
7345#endif
7346
7347#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7348 if (useWithProperties) {
7349 cl_queue_properties queue_properties[] = {
7350 CL_QUEUE_PROPERTIES, properties, 0 };
7351 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7352 object_ = ::clCreateCommandQueueWithProperties(
7353 context(), devices[0](), queue_properties, &error);
7354 }
7355 else {
7356 error = CL_INVALID_QUEUE_PROPERTIES;
7357 }
7358
7359 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7360 if (err != NULL) {
7361 *err = error;
7362 }
7363 }
7364#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7365#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7366 if (!useWithProperties) {
7367 object_ = ::clCreateCommandQueue(
7368 context(), devices[0](), properties, &error);
7369
7370 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7371 if (err != NULL) {
7372 *err = error;
7373 }
7374 }
7375#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7376 }
7377
7383 const Context& context,
7384 QueueProperties properties,
7385 cl_int* err = NULL)
7386 {
7387 cl_int error;
7388 bool useWithProperties;
7389 vector<cl::Device> devices;
7390 error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7391
7392 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7393
7394 if (error != CL_SUCCESS)
7395 {
7396 if (err != NULL) {
7397 *err = error;
7398 }
7399 return;
7400 }
7401
7402#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7403 // Run-time decision based on the actual platform
7404 {
7405 cl_uint version = detail::getContextPlatformVersion(context());
7406 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7407 }
7408#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7409 useWithProperties = true;
7410#else
7411 useWithProperties = false;
7412#endif
7413
7414#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7415 if (useWithProperties) {
7416 cl_queue_properties queue_properties[] = {
7417 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7418 object_ = ::clCreateCommandQueueWithProperties(
7419 context(), devices[0](), queue_properties, &error);
7420
7421 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7422 if (err != NULL) {
7423 *err = error;
7424 }
7425 }
7426#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7427#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7428 if (!useWithProperties) {
7429 object_ = ::clCreateCommandQueue(
7430 context(), devices[0](), static_cast<cl_command_queue_properties>(properties), &error);
7431
7432 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7433 if (err != NULL) {
7434 *err = error;
7435 }
7436 }
7437#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7438 }
7439
7445 const Context& context,
7446 const Device& device,
7447 cl_command_queue_properties properties = 0,
7448 cl_int* err = NULL)
7449 {
7450 cl_int error;
7451 bool useWithProperties;
7452
7453#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7454 // Run-time decision based on the actual platform
7455 {
7456 cl_uint version = detail::getContextPlatformVersion(context());
7457 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7458 }
7459#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7460 useWithProperties = true;
7461#else
7462 useWithProperties = false;
7463#endif
7464
7465#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7466 if (useWithProperties) {
7467 cl_queue_properties queue_properties[] = {
7468 CL_QUEUE_PROPERTIES, properties, 0 };
7469 object_ = ::clCreateCommandQueueWithProperties(
7470 context(), device(), queue_properties, &error);
7471
7472 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7473 if (err != NULL) {
7474 *err = error;
7475 }
7476 }
7477#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7478#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7479 if (!useWithProperties) {
7480 object_ = ::clCreateCommandQueue(
7481 context(), device(), properties, &error);
7482
7483 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7484 if (err != NULL) {
7485 *err = error;
7486 }
7487 }
7488#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7489 }
7490
7496 const Context& context,
7497 const Device& device,
7498 QueueProperties properties,
7499 cl_int* err = NULL)
7500 {
7501 cl_int error;
7502 bool useWithProperties;
7503
7504#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7505 // Run-time decision based on the actual platform
7506 {
7507 cl_uint version = detail::getContextPlatformVersion(context());
7508 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7509 }
7510#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7511 useWithProperties = true;
7512#else
7513 useWithProperties = false;
7514#endif
7515
7516#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7517 if (useWithProperties) {
7518 cl_queue_properties queue_properties[] = {
7519 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7520 object_ = ::clCreateCommandQueueWithProperties(
7521 context(), device(), queue_properties, &error);
7522
7523 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7524 if (err != NULL) {
7525 *err = error;
7526 }
7527 }
7528#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7529#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7530 if (!useWithProperties) {
7531 object_ = ::clCreateCommandQueue(
7532 context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
7533
7534 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7535 if (err != NULL) {
7536 *err = error;
7537 }
7538 }
7539#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7540 }
7541
7542 static CommandQueue getDefault(cl_int * err = NULL)
7543 {
7544 std::call_once(default_initialized_, makeDefault);
7545#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7546 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7547#else // CL_HPP_TARGET_OPENCL_VERSION >= 200
7548 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_ERR);
7549#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7550 if (err != NULL) {
7551 *err = default_error_;
7552 }
7553 return default_;
7554 }
7555
7563 static CommandQueue setDefault(const CommandQueue &default_queue)
7564 {
7565 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_queue));
7566 detail::errHandler(default_error_);
7567 return default_;
7568 }
7569
7570 CommandQueue() { }
7571
7572
7579 explicit CommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
7580 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
7581
7582 CommandQueue& operator = (const cl_command_queue& rhs)
7583 {
7585 return *this;
7586 }
7587
7591 CommandQueue(const CommandQueue& queue) : detail::Wrapper<cl_type>(queue) {}
7592
7596 CommandQueue& operator = (const CommandQueue &queue)
7597 {
7599 return *this;
7600 }
7601
7605 CommandQueue(CommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(queue)) {}
7606
7610 CommandQueue& operator = (CommandQueue &&queue)
7611 {
7612 detail::Wrapper<cl_type>::operator=(std::move(queue));
7613 return *this;
7614 }
7615
7616 template <typename T>
7617 cl_int getInfo(cl_command_queue_info name, T* param) const
7618 {
7619 return detail::errHandler(
7620 detail::getInfo(
7621 &::clGetCommandQueueInfo, object_, name, param),
7622 __GET_COMMAND_QUEUE_INFO_ERR);
7623 }
7624
7625 template <cl_command_queue_info name> typename
7626 detail::param_traits<detail::cl_command_queue_info, name>::param_type
7627 getInfo(cl_int* err = NULL) const
7628 {
7629 typename detail::param_traits<
7630 detail::cl_command_queue_info, name>::param_type param;
7631 cl_int result = getInfo(name, &param);
7632 if (err != NULL) {
7633 *err = result;
7634 }
7635 return param;
7636 }
7637
7638 cl_int enqueueReadBuffer(
7639 const Buffer& buffer,
7640 cl_bool blocking,
7641 size_type offset,
7642 size_type size,
7643 void* ptr,
7644 const vector<Event>* events = NULL,
7645 Event* event = NULL) const
7646 {
7647 cl_event tmp;
7648 cl_int err = detail::errHandler(
7649 ::clEnqueueReadBuffer(
7650 object_, buffer(), blocking, offset, size,
7651 ptr,
7652 (events != NULL) ? (cl_uint) events->size() : 0,
7653 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7654 (event != NULL) ? &tmp : NULL),
7655 __ENQUEUE_READ_BUFFER_ERR);
7656
7657 if (event != NULL && err == CL_SUCCESS)
7658 *event = tmp;
7659
7660 return err;
7661 }
7662
7663 cl_int enqueueWriteBuffer(
7664 const Buffer& buffer,
7665 cl_bool blocking,
7666 size_type offset,
7667 size_type size,
7668 const void* ptr,
7669 const vector<Event>* events = NULL,
7670 Event* event = NULL) const
7671 {
7672 cl_event tmp;
7673 cl_int err = detail::errHandler(
7674 ::clEnqueueWriteBuffer(
7675 object_, buffer(), blocking, offset, size,
7676 ptr,
7677 (events != NULL) ? (cl_uint) events->size() : 0,
7678 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7679 (event != NULL) ? &tmp : NULL),
7680 __ENQUEUE_WRITE_BUFFER_ERR);
7681
7682 if (event != NULL && err == CL_SUCCESS)
7683 *event = tmp;
7684
7685 return err;
7686 }
7687
7688 cl_int enqueueCopyBuffer(
7689 const Buffer& src,
7690 const Buffer& dst,
7691 size_type src_offset,
7692 size_type dst_offset,
7693 size_type size,
7694 const vector<Event>* events = NULL,
7695 Event* event = NULL) const
7696 {
7697 cl_event tmp;
7698 cl_int err = detail::errHandler(
7699 ::clEnqueueCopyBuffer(
7700 object_, src(), dst(), src_offset, dst_offset, size,
7701 (events != NULL) ? (cl_uint) events->size() : 0,
7702 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7703 (event != NULL) ? &tmp : NULL),
7704 __ENQEUE_COPY_BUFFER_ERR);
7705
7706 if (event != NULL && err == CL_SUCCESS)
7707 *event = tmp;
7708
7709 return err;
7710 }
7711#if CL_HPP_TARGET_OPENCL_VERSION >= 110
7712 cl_int enqueueReadBufferRect(
7713 const Buffer& buffer,
7714 cl_bool blocking,
7715 const array<size_type, 3>& buffer_offset,
7716 const array<size_type, 3>& host_offset,
7717 const array<size_type, 3>& region,
7718 size_type buffer_row_pitch,
7719 size_type buffer_slice_pitch,
7720 size_type host_row_pitch,
7721 size_type host_slice_pitch,
7722 void *ptr,
7723 const vector<Event>* events = NULL,
7724 Event* event = NULL) const
7725 {
7726 cl_event tmp;
7727 cl_int err = detail::errHandler(
7728 ::clEnqueueReadBufferRect(
7729 object_,
7730 buffer(),
7731 blocking,
7732 buffer_offset.data(),
7733 host_offset.data(),
7734 region.data(),
7735 buffer_row_pitch,
7736 buffer_slice_pitch,
7737 host_row_pitch,
7738 host_slice_pitch,
7739 ptr,
7740 (events != NULL) ? (cl_uint) events->size() : 0,
7741 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7742 (event != NULL) ? &tmp : NULL),
7743 __ENQUEUE_READ_BUFFER_RECT_ERR);
7744
7745 if (event != NULL && err == CL_SUCCESS)
7746 *event = tmp;
7747
7748 return err;
7749 }
7750
7751 cl_int enqueueWriteBufferRect(
7752 const Buffer& buffer,
7753 cl_bool blocking,
7754 const array<size_type, 3>& buffer_offset,
7755 const array<size_type, 3>& host_offset,
7756 const array<size_type, 3>& region,
7757 size_type buffer_row_pitch,
7758 size_type buffer_slice_pitch,
7759 size_type host_row_pitch,
7760 size_type host_slice_pitch,
7761 const void *ptr,
7762 const vector<Event>* events = NULL,
7763 Event* event = NULL) const
7764 {
7765 cl_event tmp;
7766 cl_int err = detail::errHandler(
7767 ::clEnqueueWriteBufferRect(
7768 object_,
7769 buffer(),
7770 blocking,
7771 buffer_offset.data(),
7772 host_offset.data(),
7773 region.data(),
7774 buffer_row_pitch,
7775 buffer_slice_pitch,
7776 host_row_pitch,
7777 host_slice_pitch,
7778 ptr,
7779 (events != NULL) ? (cl_uint) events->size() : 0,
7780 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7781 (event != NULL) ? &tmp : NULL),
7782 __ENQUEUE_WRITE_BUFFER_RECT_ERR);
7783
7784 if (event != NULL && err == CL_SUCCESS)
7785 *event = tmp;
7786
7787 return err;
7788 }
7789
7790 cl_int enqueueCopyBufferRect(
7791 const Buffer& src,
7792 const Buffer& dst,
7793 const array<size_type, 3>& src_origin,
7794 const array<size_type, 3>& dst_origin,
7795 const array<size_type, 3>& region,
7796 size_type src_row_pitch,
7797 size_type src_slice_pitch,
7798 size_type dst_row_pitch,
7799 size_type dst_slice_pitch,
7800 const vector<Event>* events = NULL,
7801 Event* event = NULL) const
7802 {
7803 cl_event tmp;
7804 cl_int err = detail::errHandler(
7805 ::clEnqueueCopyBufferRect(
7806 object_,
7807 src(),
7808 dst(),
7809 src_origin.data(),
7810 dst_origin.data(),
7811 region.data(),
7812 src_row_pitch,
7813 src_slice_pitch,
7814 dst_row_pitch,
7815 dst_slice_pitch,
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 __ENQEUE_COPY_BUFFER_RECT_ERR);
7820
7821 if (event != NULL && err == CL_SUCCESS)
7822 *event = tmp;
7823
7824 return err;
7825 }
7826#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
7827#if CL_HPP_TARGET_OPENCL_VERSION >= 120
7839 template<typename PatternType>
7841 const Buffer& buffer,
7842 PatternType pattern,
7843 size_type offset,
7844 size_type size,
7845 const vector<Event>* events = NULL,
7846 Event* event = NULL) const
7847 {
7848 cl_event tmp;
7849 cl_int err = detail::errHandler(
7850 ::clEnqueueFillBuffer(
7851 object_,
7852 buffer(),
7853 static_cast<void*>(&pattern),
7854 sizeof(PatternType),
7855 offset,
7856 size,
7857 (events != NULL) ? (cl_uint) events->size() : 0,
7858 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7859 (event != NULL) ? &tmp : NULL),
7860 __ENQUEUE_FILL_BUFFER_ERR);
7861
7862 if (event != NULL && err == CL_SUCCESS)
7863 *event = tmp;
7864
7865 return err;
7866 }
7867#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7868
7869 cl_int enqueueReadImage(
7870 const Image& image,
7871 cl_bool blocking,
7872 const array<size_type, 3>& origin,
7873 const array<size_type, 3>& region,
7874 size_type row_pitch,
7875 size_type slice_pitch,
7876 void* ptr,
7877 const vector<Event>* events = NULL,
7878 Event* event = NULL) const
7879 {
7880 cl_event tmp;
7881 cl_int err = detail::errHandler(
7882 ::clEnqueueReadImage(
7883 object_,
7884 image(),
7885 blocking,
7886 origin.data(),
7887 region.data(),
7888 row_pitch,
7889 slice_pitch,
7890 ptr,
7891 (events != NULL) ? (cl_uint) events->size() : 0,
7892 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7893 (event != NULL) ? &tmp : NULL),
7894 __ENQUEUE_READ_IMAGE_ERR);
7895
7896 if (event != NULL && err == CL_SUCCESS)
7897 *event = tmp;
7898
7899 return err;
7900 }
7901
7902 cl_int enqueueWriteImage(
7903 const Image& image,
7904 cl_bool blocking,
7905 const array<size_type, 3>& origin,
7906 const array<size_type, 3>& region,
7907 size_type row_pitch,
7908 size_type slice_pitch,
7909 const void* ptr,
7910 const vector<Event>* events = NULL,
7911 Event* event = NULL) const
7912 {
7913 cl_event tmp;
7914 cl_int err = detail::errHandler(
7915 ::clEnqueueWriteImage(
7916 object_,
7917 image(),
7918 blocking,
7919 origin.data(),
7920 region.data(),
7921 row_pitch,
7922 slice_pitch,
7923 ptr,
7924 (events != NULL) ? (cl_uint) events->size() : 0,
7925 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7926 (event != NULL) ? &tmp : NULL),
7927 __ENQUEUE_WRITE_IMAGE_ERR);
7928
7929 if (event != NULL && err == CL_SUCCESS)
7930 *event = tmp;
7931
7932 return err;
7933 }
7934
7935 cl_int enqueueCopyImage(
7936 const Image& src,
7937 const Image& dst,
7938 const array<size_type, 3>& src_origin,
7939 const array<size_type, 3>& dst_origin,
7940 const array<size_type, 3>& region,
7941 const vector<Event>* events = NULL,
7942 Event* event = NULL) const
7943 {
7944 cl_event tmp;
7945 cl_int err = detail::errHandler(
7946 ::clEnqueueCopyImage(
7947 object_,
7948 src(),
7949 dst(),
7950 src_origin.data(),
7951 dst_origin.data(),
7952 region.data(),
7953 (events != NULL) ? (cl_uint) events->size() : 0,
7954 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7955 (event != NULL) ? &tmp : NULL),
7956 __ENQUEUE_COPY_IMAGE_ERR);
7957
7958 if (event != NULL && err == CL_SUCCESS)
7959 *event = tmp;
7960
7961 return err;
7962 }
7963
7964#if CL_HPP_TARGET_OPENCL_VERSION >= 120
7973 const Image& image,
7974 cl_float4 fillColor,
7975 const array<size_type, 3>& origin,
7976 const array<size_type, 3>& region,
7977 const vector<Event>* events = NULL,
7978 Event* event = NULL) const
7979 {
7980 cl_event tmp;
7981 cl_int err = detail::errHandler(
7982 ::clEnqueueFillImage(
7983 object_,
7984 image(),
7985 static_cast<void*>(&fillColor),
7986 origin.data(),
7987 region.data(),
7988 (events != NULL) ? (cl_uint) events->size() : 0,
7989 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7990 (event != NULL) ? &tmp : NULL),
7991 __ENQUEUE_FILL_IMAGE_ERR);
7992
7993 if (event != NULL && err == CL_SUCCESS)
7994 *event = tmp;
7995
7996 return err;
7997 }
7998
8007 const Image& image,
8008 cl_int4 fillColor,
8009 const array<size_type, 3>& origin,
8010 const array<size_type, 3>& region,
8011 const vector<Event>* events = NULL,
8012 Event* event = NULL) const
8013 {
8014 cl_event tmp;
8015 cl_int err = detail::errHandler(
8016 ::clEnqueueFillImage(
8017 object_,
8018 image(),
8019 static_cast<void*>(&fillColor),
8020 origin.data(),
8021 region.data(),
8022 (events != NULL) ? (cl_uint) events->size() : 0,
8023 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8024 (event != NULL) ? &tmp : NULL),
8025 __ENQUEUE_FILL_IMAGE_ERR);
8026
8027 if (event != NULL && err == CL_SUCCESS)
8028 *event = tmp;
8029
8030 return err;
8031 }
8032
8041 const Image& image,
8042 cl_uint4 fillColor,
8043 const array<size_type, 3>& origin,
8044 const array<size_type, 3>& region,
8045 const vector<Event>* events = NULL,
8046 Event* event = NULL) const
8047 {
8048 cl_event tmp;
8049 cl_int err = detail::errHandler(
8050 ::clEnqueueFillImage(
8051 object_,
8052 image(),
8053 static_cast<void*>(&fillColor),
8054 origin.data(),
8055 region.data(),
8056 (events != NULL) ? (cl_uint) events->size() : 0,
8057 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8058 (event != NULL) ? &tmp : NULL),
8059 __ENQUEUE_FILL_IMAGE_ERR);
8060
8061 if (event != NULL && err == CL_SUCCESS)
8062 *event = tmp;
8063
8064 return err;
8065 }
8066#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8067
8068 cl_int enqueueCopyImageToBuffer(
8069 const Image& src,
8070 const Buffer& dst,
8071 const array<size_type, 3>& src_origin,
8072 const array<size_type, 3>& region,
8073 size_type dst_offset,
8074 const vector<Event>* events = NULL,
8075 Event* event = NULL) const
8076 {
8077 cl_event tmp;
8078 cl_int err = detail::errHandler(
8079 ::clEnqueueCopyImageToBuffer(
8080 object_,
8081 src(),
8082 dst(),
8083 src_origin.data(),
8084 region.data(),
8085 dst_offset,
8086 (events != NULL) ? (cl_uint) events->size() : 0,
8087 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8088 (event != NULL) ? &tmp : NULL),
8089 __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
8090
8091 if (event != NULL && err == CL_SUCCESS)
8092 *event = tmp;
8093
8094 return err;
8095 }
8096
8097 cl_int enqueueCopyBufferToImage(
8098 const Buffer& src,
8099 const Image& dst,
8100 size_type src_offset,
8101 const array<size_type, 3>& dst_origin,
8102 const array<size_type, 3>& region,
8103 const vector<Event>* events = NULL,
8104 Event* event = NULL) const
8105 {
8106 cl_event tmp;
8107 cl_int err = detail::errHandler(
8108 ::clEnqueueCopyBufferToImage(
8109 object_,
8110 src(),
8111 dst(),
8112 src_offset,
8113 dst_origin.data(),
8114 region.data(),
8115 (events != NULL) ? (cl_uint) events->size() : 0,
8116 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8117 (event != NULL) ? &tmp : NULL),
8118 __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
8119
8120 if (event != NULL && err == CL_SUCCESS)
8121 *event = tmp;
8122
8123 return err;
8124 }
8125
8126 void* enqueueMapBuffer(
8127 const Buffer& buffer,
8128 cl_bool blocking,
8129 cl_map_flags flags,
8130 size_type offset,
8131 size_type size,
8132 const vector<Event>* events = NULL,
8133 Event* event = NULL,
8134 cl_int* err = NULL) const
8135 {
8136 cl_event tmp;
8137 cl_int error;
8138 void * result = ::clEnqueueMapBuffer(
8139 object_, buffer(), blocking, flags, offset, size,
8140 (events != NULL) ? (cl_uint) events->size() : 0,
8141 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8142 (event != NULL) ? &tmp : NULL,
8143 &error);
8144
8145 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
8146 if (err != NULL) {
8147 *err = error;
8148 }
8149 if (event != NULL && error == CL_SUCCESS)
8150 *event = tmp;
8151
8152 return result;
8153 }
8154
8155 void* enqueueMapImage(
8156 const Image& buffer,
8157 cl_bool blocking,
8158 cl_map_flags flags,
8159 const array<size_type, 3>& origin,
8160 const array<size_type, 3>& region,
8161 size_type * row_pitch,
8162 size_type * slice_pitch,
8163 const vector<Event>* events = NULL,
8164 Event* event = NULL,
8165 cl_int* err = NULL) const
8166 {
8167 cl_event tmp;
8168 cl_int error;
8169 void * result = ::clEnqueueMapImage(
8170 object_, buffer(), blocking, flags,
8171 origin.data(),
8172 region.data(),
8173 row_pitch, slice_pitch,
8174 (events != NULL) ? (cl_uint) events->size() : 0,
8175 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8176 (event != NULL) ? &tmp : NULL,
8177 &error);
8178
8179 detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
8180 if (err != NULL) {
8181 *err = error;
8182 }
8183 if (event != NULL && error == CL_SUCCESS)
8184 *event = tmp;
8185 return result;
8186 }
8187
8188#if CL_HPP_TARGET_OPENCL_VERSION >= 200
8193 template<typename T>
8195 T* ptr,
8196 cl_bool blocking,
8197 cl_map_flags flags,
8198 size_type size,
8199 const vector<Event>* events = NULL,
8200 Event* event = NULL) const
8201 {
8202 cl_event tmp;
8203 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8204 object_, blocking, flags, static_cast<void*>(ptr), size,
8205 (events != NULL) ? (cl_uint)events->size() : 0,
8206 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8207 (event != NULL) ? &tmp : NULL),
8208 __ENQUEUE_MAP_BUFFER_ERR);
8209
8210 if (event != NULL && err == CL_SUCCESS)
8211 *event = tmp;
8212
8213 return err;
8214 }
8215
8216
8221 template<typename T, class D>
8223 cl::pointer<T, D> &ptr,
8224 cl_bool blocking,
8225 cl_map_flags flags,
8226 size_type size,
8227 const vector<Event>* events = NULL,
8228 Event* event = NULL) const
8229 {
8230 cl_event tmp;
8231 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8232 object_, blocking, flags, static_cast<void*>(ptr.get()), size,
8233 (events != NULL) ? (cl_uint)events->size() : 0,
8234 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8235 (event != NULL) ? &tmp : NULL),
8236 __ENQUEUE_MAP_BUFFER_ERR);
8237
8238 if (event != NULL && err == CL_SUCCESS)
8239 *event = tmp;
8240
8241 return err;
8242 }
8243
8248 template<typename T, class Alloc>
8250 cl::vector<T, Alloc> &container,
8251 cl_bool blocking,
8252 cl_map_flags flags,
8253 const vector<Event>* events = NULL,
8254 Event* event = NULL) const
8255 {
8256 cl_event tmp;
8257 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8258 object_, blocking, flags, static_cast<void*>(container.data()), container.size()*sizeof(T),
8259 (events != NULL) ? (cl_uint)events->size() : 0,
8260 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8261 (event != NULL) ? &tmp : NULL),
8262 __ENQUEUE_MAP_BUFFER_ERR);
8263
8264 if (event != NULL && err == CL_SUCCESS)
8265 *event = tmp;
8266
8267 return err;
8268 }
8269#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8270
8271 cl_int enqueueUnmapMemObject(
8272 const Memory& memory,
8273 void* mapped_ptr,
8274 const vector<Event>* events = NULL,
8275 Event* event = NULL) const
8276 {
8277 cl_event tmp;
8278 cl_int err = detail::errHandler(
8279 ::clEnqueueUnmapMemObject(
8280 object_, memory(), mapped_ptr,
8281 (events != NULL) ? (cl_uint) events->size() : 0,
8282 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8283 (event != NULL) ? &tmp : NULL),
8284 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8285
8286 if (event != NULL && err == CL_SUCCESS)
8287 *event = tmp;
8288
8289 return err;
8290 }
8291
8292
8293#if CL_HPP_TARGET_OPENCL_VERSION >= 200
8298 template<typename T>
8300 T* ptr,
8301 const vector<Event>* events = NULL,
8302 Event* event = NULL) const
8303 {
8304 cl_event tmp;
8305 cl_int err = detail::errHandler(
8306 ::clEnqueueSVMUnmap(
8307 object_, static_cast<void*>(ptr),
8308 (events != NULL) ? (cl_uint)events->size() : 0,
8309 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8310 (event != NULL) ? &tmp : NULL),
8311 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8312
8313 if (event != NULL && err == CL_SUCCESS)
8314 *event = tmp;
8315
8316 return err;
8317 }
8318
8323 template<typename T, class D>
8325 cl::pointer<T, D> &ptr,
8326 const vector<Event>* events = NULL,
8327 Event* event = NULL) const
8328 {
8329 cl_event tmp;
8330 cl_int err = detail::errHandler(
8331 ::clEnqueueSVMUnmap(
8332 object_, static_cast<void*>(ptr.get()),
8333 (events != NULL) ? (cl_uint)events->size() : 0,
8334 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8335 (event != NULL) ? &tmp : NULL),
8336 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8337
8338 if (event != NULL && err == CL_SUCCESS)
8339 *event = tmp;
8340
8341 return err;
8342 }
8343
8348 template<typename T, class Alloc>
8350 cl::vector<T, Alloc> &container,
8351 const vector<Event>* events = NULL,
8352 Event* event = NULL) const
8353 {
8354 cl_event tmp;
8355 cl_int err = detail::errHandler(
8356 ::clEnqueueSVMUnmap(
8357 object_, static_cast<void*>(container.data()),
8358 (events != NULL) ? (cl_uint)events->size() : 0,
8359 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8360 (event != NULL) ? &tmp : NULL),
8361 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8362
8363 if (event != NULL && err == CL_SUCCESS)
8364 *event = tmp;
8365
8366 return err;
8367 }
8368#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8369
8370#if CL_HPP_TARGET_OPENCL_VERSION >= 120
8383 const vector<Event> *events = 0,
8384 Event *event = 0) const
8385 {
8386 cl_event tmp;
8387 cl_int err = detail::errHandler(
8388 ::clEnqueueMarkerWithWaitList(
8389 object_,
8390 (events != NULL) ? (cl_uint) events->size() : 0,
8391 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8392 (event != NULL) ? &tmp : NULL),
8393 __ENQUEUE_MARKER_WAIT_LIST_ERR);
8394
8395 if (event != NULL && err == CL_SUCCESS)
8396 *event = tmp;
8397
8398 return err;
8399 }
8400
8413 const vector<Event> *events = 0,
8414 Event *event = 0) const
8415 {
8416 cl_event tmp;
8417 cl_int err = detail::errHandler(
8418 ::clEnqueueBarrierWithWaitList(
8419 object_,
8420 (events != NULL) ? (cl_uint) events->size() : 0,
8421 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8422 (event != NULL) ? &tmp : NULL),
8423 __ENQUEUE_BARRIER_WAIT_LIST_ERR);
8424
8425 if (event != NULL && err == CL_SUCCESS)
8426 *event = tmp;
8427
8428 return err;
8429 }
8430
8436 const vector<Memory> &memObjects,
8437 cl_mem_migration_flags flags,
8438 const vector<Event>* events = NULL,
8439 Event* event = NULL
8440 ) const
8441 {
8442 cl_event tmp;
8443
8444 vector<cl_mem> localMemObjects(memObjects.size());
8445
8446 for( int i = 0; i < (int)memObjects.size(); ++i ) {
8447 localMemObjects[i] = memObjects[i]();
8448 }
8449
8450 cl_int err = detail::errHandler(
8451 ::clEnqueueMigrateMemObjects(
8452 object_,
8453 (cl_uint)memObjects.size(),
8454 localMemObjects.data(),
8455 flags,
8456 (events != NULL) ? (cl_uint) events->size() : 0,
8457 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8458 (event != NULL) ? &tmp : NULL),
8459 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8460
8461 if (event != NULL && err == CL_SUCCESS)
8462 *event = tmp;
8463
8464 return err;
8465 }
8466#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8467
8468
8469#if CL_HPP_TARGET_OPENCL_VERSION >= 210
8475 template<typename T>
8477 const cl::vector<T*> &svmRawPointers,
8478 const cl::vector<size_type> &sizes,
8479 cl_mem_migration_flags flags = 0,
8480 const vector<Event>* events = NULL,
8481 Event* event = NULL) const
8482 {
8483 cl_event tmp;
8484 cl_int err = detail::errHandler(::clEnqueueSVMMigrateMem(
8485 object_,
8486 svmRawPointers.size(), static_cast<void**>(svmRawPointers.data()),
8487 sizes.data(), // array of sizes not passed
8488 flags,
8489 (events != NULL) ? (cl_uint)events->size() : 0,
8490 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8491 (event != NULL) ? &tmp : NULL),
8492 __ENQUEUE_MIGRATE_SVM_ERR);
8493
8494 if (event != NULL && err == CL_SUCCESS)
8495 *event = tmp;
8496
8497 return err;
8498 }
8499
8504 template<typename T>
8506 const cl::vector<T*> &svmRawPointers,
8507 cl_mem_migration_flags flags = 0,
8508 const vector<Event>* events = NULL,
8509 Event* event = NULL) const
8510 {
8511 return enqueueMigrateSVM(svmRawPointers, cl::vector<size_type>(svmRawPointers.size()), flags, events, event);
8512 }
8513
8514
8520 template<typename T, class D>
8522 const cl::vector<cl::pointer<T, D>> &svmPointers,
8523 const cl::vector<size_type> &sizes,
8524 cl_mem_migration_flags flags = 0,
8525 const vector<Event>* events = NULL,
8526 Event* event = NULL) const
8527 {
8528 cl::vector<void*> svmRawPointers;
8529 svmRawPointers.reserve(svmPointers.size());
8530 for (auto p : svmPointers) {
8531 svmRawPointers.push_back(static_cast<void*>(p.get()));
8532 }
8533
8534 return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
8535 }
8536
8537
8542 template<typename T, class D>
8544 const cl::vector<cl::pointer<T, D>> &svmPointers,
8545 cl_mem_migration_flags flags = 0,
8546 const vector<Event>* events = NULL,
8547 Event* event = NULL) const
8548 {
8549 return enqueueMigrateSVM(svmPointers, cl::vector<size_type>(svmPointers.size()), flags, events, event);
8550 }
8551
8557 template<typename T, class Alloc>
8559 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8560 const cl::vector<size_type> &sizes,
8561 cl_mem_migration_flags flags = 0,
8562 const vector<Event>* events = NULL,
8563 Event* event = NULL) const
8564 {
8565 cl::vector<void*> svmRawPointers;
8566 svmRawPointers.reserve(svmContainers.size());
8567 for (auto p : svmContainers) {
8568 svmRawPointers.push_back(static_cast<void*>(p.data()));
8569 }
8570
8571 return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
8572 }
8573
8578 template<typename T, class Alloc>
8580 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8581 cl_mem_migration_flags flags = 0,
8582 const vector<Event>* events = NULL,
8583 Event* event = NULL) const
8584 {
8585 return enqueueMigrateSVM(svmContainers, cl::vector<size_type>(svmContainers.size()), flags, events, event);
8586 }
8587
8588#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8589
8590 cl_int enqueueNDRangeKernel(
8591 const Kernel& kernel,
8592 const NDRange& offset,
8593 const NDRange& global,
8594 const NDRange& local = NullRange,
8595 const vector<Event>* events = NULL,
8596 Event* event = NULL) const
8597 {
8598 cl_event tmp;
8599 cl_int err = detail::errHandler(
8600 ::clEnqueueNDRangeKernel(
8601 object_, kernel(), (cl_uint) global.dimensions(),
8602 offset.dimensions() != 0 ? (const size_type*) offset : NULL,
8603 (const size_type*) global,
8604 local.dimensions() != 0 ? (const size_type*) local : NULL,
8605 (events != NULL) ? (cl_uint) events->size() : 0,
8606 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8607 (event != NULL) ? &tmp : NULL),
8608 __ENQUEUE_NDRANGE_KERNEL_ERR);
8609
8610 if (event != NULL && err == CL_SUCCESS)
8611 *event = tmp;
8612
8613 return err;
8614 }
8615
8616#if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8617 CL_API_PREFIX__VERSION_1_2_DEPRECATED cl_int enqueueTask(
8618 const Kernel& kernel,
8619 const vector<Event>* events = NULL,
8620 Event* event = NULL) const CL_API_SUFFIX__VERSION_1_2_DEPRECATED
8621 {
8622 cl_event tmp;
8623 cl_int err = detail::errHandler(
8624 ::clEnqueueTask(
8625 object_, kernel(),
8626 (events != NULL) ? (cl_uint) events->size() : 0,
8627 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8628 (event != NULL) ? &tmp : NULL),
8629 __ENQUEUE_TASK_ERR);
8630
8631 if (event != NULL && err == CL_SUCCESS)
8632 *event = tmp;
8633
8634 return err;
8635 }
8636#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8637
8638 cl_int enqueueNativeKernel(
8639 void (CL_CALLBACK *userFptr)(void *),
8640 std::pair<void*, size_type> args,
8641 const vector<Memory>* mem_objects = NULL,
8642 const vector<const void*>* mem_locs = NULL,
8643 const vector<Event>* events = NULL,
8644 Event* event = NULL) const
8645 {
8646 size_type elements = 0;
8647 if (mem_objects != NULL) {
8648 elements = mem_objects->size();
8649 }
8650 vector<cl_mem> mems(elements);
8651 for (unsigned int i = 0; i < elements; i++) {
8652 mems[i] = ((*mem_objects)[i])();
8653 }
8654
8655 cl_event tmp;
8656 cl_int err = detail::errHandler(
8657 ::clEnqueueNativeKernel(
8658 object_, userFptr, args.first, args.second,
8659 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8660 mems.data(),
8661 (mem_locs != NULL && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : NULL,
8662 (events != NULL) ? (cl_uint) events->size() : 0,
8663 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8664 (event != NULL) ? &tmp : NULL),
8665 __ENQUEUE_NATIVE_KERNEL);
8666
8667 if (event != NULL && err == CL_SUCCESS)
8668 *event = tmp;
8669
8670 return err;
8671 }
8672
8676#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8677 CL_API_PREFIX__VERSION_1_1_DEPRECATED
8678 cl_int enqueueMarker(Event* event = NULL) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
8679 {
8680 cl_event tmp;
8681 cl_int err = detail::errHandler(
8682 ::clEnqueueMarker(
8683 object_,
8684 (event != NULL) ? &tmp : NULL),
8685 __ENQUEUE_MARKER_ERR);
8686
8687 if (event != NULL && err == CL_SUCCESS)
8688 *event = tmp;
8689
8690 return err;
8691 }
8692
8693 CL_API_PREFIX__VERSION_1_1_DEPRECATED
8694 cl_int enqueueWaitForEvents(const vector<Event>& events) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
8695 {
8696 return detail::errHandler(
8697 ::clEnqueueWaitForEvents(
8698 object_,
8699 (cl_uint) events.size(),
8700 events.size() > 0 ? (const cl_event*) &events.front() : NULL),
8701 __ENQUEUE_WAIT_FOR_EVENTS_ERR);
8702 }
8703#endif // defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8704
8705 cl_int enqueueAcquireGLObjects(
8706 const vector<Memory>* mem_objects = NULL,
8707 const vector<Event>* events = NULL,
8708 Event* event = NULL) const
8709 {
8710 cl_event tmp;
8711 cl_int err = detail::errHandler(
8712 ::clEnqueueAcquireGLObjects(
8713 object_,
8714 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8715 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8716 (events != NULL) ? (cl_uint) events->size() : 0,
8717 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8718 (event != NULL) ? &tmp : NULL),
8719 __ENQUEUE_ACQUIRE_GL_ERR);
8720
8721 if (event != NULL && err == CL_SUCCESS)
8722 *event = tmp;
8723
8724 return err;
8725 }
8726
8727 cl_int enqueueReleaseGLObjects(
8728 const vector<Memory>* mem_objects = NULL,
8729 const vector<Event>* events = NULL,
8730 Event* event = NULL) const
8731 {
8732 cl_event tmp;
8733 cl_int err = detail::errHandler(
8734 ::clEnqueueReleaseGLObjects(
8735 object_,
8736 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8737 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8738 (events != NULL) ? (cl_uint) events->size() : 0,
8739 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8740 (event != NULL) ? &tmp : NULL),
8741 __ENQUEUE_RELEASE_GL_ERR);
8742
8743 if (event != NULL && err == CL_SUCCESS)
8744 *event = tmp;
8745
8746 return err;
8747 }
8748
8749#if defined (CL_HPP_USE_DX_INTEROP)
8750typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
8751 cl_command_queue command_queue, cl_uint num_objects,
8752 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8753 const cl_event* event_wait_list, cl_event* event);
8754typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
8755 cl_command_queue command_queue, cl_uint num_objects,
8756 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8757 const cl_event* event_wait_list, cl_event* event);
8758
8759 cl_int enqueueAcquireD3D10Objects(
8760 const vector<Memory>* mem_objects = NULL,
8761 const vector<Event>* events = NULL,
8762 Event* event = NULL) const
8763 {
8764 static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
8765#if CL_HPP_TARGET_OPENCL_VERSION >= 120
8766 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8767 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8768 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8769 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireD3D10ObjectsKHR);
8770#endif
8771#if CL_HPP_TARGET_OPENCL_VERSION >= 110
8772 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueAcquireD3D10ObjectsKHR);
8773#endif
8774
8775 cl_event tmp;
8776 cl_int err = detail::errHandler(
8777 pfn_clEnqueueAcquireD3D10ObjectsKHR(
8778 object_,
8779 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8780 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8781 (events != NULL) ? (cl_uint) events->size() : 0,
8782 (events != NULL) ? (cl_event*) &events->front() : NULL,
8783 (event != NULL) ? &tmp : NULL),
8784 __ENQUEUE_ACQUIRE_GL_ERR);
8785
8786 if (event != NULL && err == CL_SUCCESS)
8787 *event = tmp;
8788
8789 return err;
8790 }
8791
8792 cl_int enqueueReleaseD3D10Objects(
8793 const vector<Memory>* mem_objects = NULL,
8794 const vector<Event>* events = NULL,
8795 Event* event = NULL) const
8796 {
8797 static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL;
8798#if CL_HPP_TARGET_OPENCL_VERSION >= 120
8799 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8800 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8801 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8802 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseD3D10ObjectsKHR);
8803#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8804#if CL_HPP_TARGET_OPENCL_VERSION >= 110
8805 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueReleaseD3D10ObjectsKHR);
8806#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
8807
8808 cl_event tmp;
8809 cl_int err = detail::errHandler(
8810 pfn_clEnqueueReleaseD3D10ObjectsKHR(
8811 object_,
8812 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8813 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8814 (events != NULL) ? (cl_uint) events->size() : 0,
8815 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8816 (event != NULL) ? &tmp : NULL),
8817 __ENQUEUE_RELEASE_GL_ERR);
8818
8819 if (event != NULL && err == CL_SUCCESS)
8820 *event = tmp;
8821
8822 return err;
8823 }
8824#endif
8825
8829#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8830 CL_API_PREFIX__VERSION_1_1_DEPRECATED
8831 cl_int enqueueBarrier() const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
8832 {
8833 return detail::errHandler(
8834 ::clEnqueueBarrier(object_),
8835 __ENQUEUE_BARRIER_ERR);
8836 }
8837#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
8838
8839 cl_int flush() const
8840 {
8841 return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
8842 }
8843
8844 cl_int finish() const
8845 {
8846 return detail::errHandler(::clFinish(object_), __FINISH_ERR);
8847 }
8848}; // CommandQueue
8849
8850CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::default_initialized_;
8851CL_HPP_DEFINE_STATIC_MEMBER_ CommandQueue CommandQueue::default_;
8852CL_HPP_DEFINE_STATIC_MEMBER_ cl_int CommandQueue::default_error_ = CL_SUCCESS;
8853
8854
8855#if CL_HPP_TARGET_OPENCL_VERSION >= 200
8856enum class DeviceQueueProperties : cl_command_queue_properties
8857{
8858 None = 0,
8859 Profiling = CL_QUEUE_PROFILING_ENABLE,
8860};
8861
8862inline DeviceQueueProperties operator|(DeviceQueueProperties lhs, DeviceQueueProperties rhs)
8863{
8864 return static_cast<DeviceQueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
8865}
8866
8870class DeviceCommandQueue : public detail::Wrapper<cl_command_queue>
8871{
8872public:
8873
8878
8882 DeviceCommandQueue(DeviceQueueProperties properties, cl_int* err = NULL)
8883 {
8884 cl_int error;
8887
8888 cl_command_queue_properties mergedProperties =
8889 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8890
8891 cl_queue_properties queue_properties[] = {
8892 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8893 object_ = ::clCreateCommandQueueWithProperties(
8894 context(), device(), queue_properties, &error);
8895
8896 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8897 if (err != NULL) {
8898 *err = error;
8899 }
8900 }
8901
8906 const Context& context,
8907 const Device& device,
8908 DeviceQueueProperties properties = DeviceQueueProperties::None,
8909 cl_int* err = NULL)
8910 {
8911 cl_int error;
8912
8913 cl_command_queue_properties mergedProperties =
8914 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8915 cl_queue_properties queue_properties[] = {
8916 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8917 object_ = ::clCreateCommandQueueWithProperties(
8918 context(), device(), queue_properties, &error);
8919
8920 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8921 if (err != NULL) {
8922 *err = error;
8923 }
8924 }
8925
8930 const Context& context,
8931 const Device& device,
8932 cl_uint queueSize,
8933 DeviceQueueProperties properties = DeviceQueueProperties::None,
8934 cl_int* err = NULL)
8935 {
8936 cl_int error;
8937
8938 cl_command_queue_properties mergedProperties =
8939 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8940 cl_queue_properties queue_properties[] = {
8941 CL_QUEUE_PROPERTIES, mergedProperties,
8942 CL_QUEUE_SIZE, queueSize,
8943 0 };
8944 object_ = ::clCreateCommandQueueWithProperties(
8945 context(), device(), queue_properties, &error);
8946
8947 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8948 if (err != NULL) {
8949 *err = error;
8950 }
8951 }
8952
8959 explicit DeviceCommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
8960 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
8961
8962 DeviceCommandQueue& operator = (const cl_command_queue& rhs)
8963 {
8965 return *this;
8966 }
8967
8971 DeviceCommandQueue(const DeviceCommandQueue& queue) : detail::Wrapper<cl_type>(queue) {}
8972
8976 DeviceCommandQueue& operator = (const DeviceCommandQueue &queue)
8977 {
8979 return *this;
8980 }
8981
8985 DeviceCommandQueue(DeviceCommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(queue)) {}
8986
8991 {
8992 detail::Wrapper<cl_type>::operator=(std::move(queue));
8993 return *this;
8994 }
8995
8996 template <typename T>
8997 cl_int getInfo(cl_command_queue_info name, T* param) const
8998 {
8999 return detail::errHandler(
9000 detail::getInfo(
9001 &::clGetCommandQueueInfo, object_, name, param),
9002 __GET_COMMAND_QUEUE_INFO_ERR);
9003 }
9004
9005 template <cl_command_queue_info name> typename
9006 detail::param_traits<detail::cl_command_queue_info, name>::param_type
9007 getInfo(cl_int* err = NULL) const
9008 {
9009 typename detail::param_traits<
9010 detail::cl_command_queue_info, name>::param_type param;
9011 cl_int result = getInfo(name, &param);
9012 if (err != NULL) {
9013 *err = result;
9014 }
9015 return param;
9016 }
9017
9025 cl_int *err = nullptr)
9026 {
9027 cl_int error;
9030
9031 cl_command_queue_properties properties =
9032 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9033 cl_queue_properties queue_properties[] = {
9034 CL_QUEUE_PROPERTIES, properties,
9035 0 };
9036 DeviceCommandQueue deviceQueue(
9037 ::clCreateCommandQueueWithProperties(
9038 context(), device(), queue_properties, &error));
9039
9040 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9041 if (err != NULL) {
9042 *err = error;
9043 }
9044
9045 return deviceQueue;
9046 }
9047
9055 const Context &context, const Device &device, cl_int *err = nullptr)
9056 {
9057 cl_int error;
9058
9059 cl_command_queue_properties properties =
9060 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9061 cl_queue_properties queue_properties[] = {
9062 CL_QUEUE_PROPERTIES, properties,
9063 0 };
9064 DeviceCommandQueue deviceQueue(
9065 ::clCreateCommandQueueWithProperties(
9066 context(), device(), queue_properties, &error));
9067
9068 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9069 if (err != NULL) {
9070 *err = error;
9071 }
9072
9073 return deviceQueue;
9074 }
9075
9083 const Context &context, const Device &device, cl_uint queueSize, cl_int *err = nullptr)
9084 {
9085 cl_int error;
9086
9087 cl_command_queue_properties properties =
9088 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9089 cl_queue_properties queue_properties[] = {
9090 CL_QUEUE_PROPERTIES, properties,
9091 CL_QUEUE_SIZE, queueSize,
9092 0 };
9093 DeviceCommandQueue deviceQueue(
9094 ::clCreateCommandQueueWithProperties(
9095 context(), device(), queue_properties, &error));
9096
9097 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9098 if (err != NULL) {
9099 *err = error;
9100 }
9101
9102 return deviceQueue;
9103 }
9104
9105
9106
9107#if CL_HPP_TARGET_OPENCL_VERSION >= 210
9114 static DeviceCommandQueue updateDefault(const Context &context, const Device &device, const DeviceCommandQueue &default_queue, cl_int *err = nullptr)
9115 {
9116 cl_int error;
9117 error = clSetDefaultDeviceCommandQueue(context.get(), device.get(), default_queue.get());
9118
9119 detail::errHandler(error, __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR);
9120 if (err != NULL) {
9121 *err = error;
9122 }
9123 return default_queue;
9124 }
9125
9129 static DeviceCommandQueue getDefault(const CommandQueue &queue, cl_int * err = NULL)
9130 {
9131 return queue.getInfo<CL_QUEUE_DEVICE_DEFAULT>(err);
9132 }
9133
9134#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
9135}; // DeviceCommandQueue
9136
9137namespace detail
9138{
9139 // Specialization for device command queue
9140 template <>
9142 {
9143 static size_type size(const cl::DeviceCommandQueue&) { return sizeof(cl_command_queue); }
9144 static const cl_command_queue* ptr(const cl::DeviceCommandQueue& value) { return &(value()); }
9145 };
9146} // namespace detail
9147
9148#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9149
9150
9151template< typename IteratorType >
9153 const Context &context,
9154 IteratorType startIterator,
9155 IteratorType endIterator,
9156 bool readOnly,
9157 bool useHostPtr,
9158 cl_int* err)
9159{
9160 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9161 cl_int error;
9162
9163 cl_mem_flags flags = 0;
9164 if( readOnly ) {
9165 flags |= CL_MEM_READ_ONLY;
9166 }
9167 else {
9168 flags |= CL_MEM_READ_WRITE;
9169 }
9170 if( useHostPtr ) {
9171 flags |= CL_MEM_USE_HOST_PTR;
9172 }
9173
9174 size_type size = sizeof(DataType)*(endIterator - startIterator);
9175
9176 if( useHostPtr ) {
9177 object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
9178 } else {
9179 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9180 }
9181
9182 detail::errHandler(error, __CREATE_BUFFER_ERR);
9183 if (err != NULL) {
9184 *err = error;
9185 }
9186
9187 if( !useHostPtr ) {
9188 CommandQueue queue(context, 0, &error);
9189 detail::errHandler(error, __CREATE_BUFFER_ERR);
9190 if (err != NULL) {
9191 *err = error;
9192 }
9193
9194 error = cl::copy(queue, startIterator, endIterator, *this);
9195 detail::errHandler(error, __CREATE_BUFFER_ERR);
9196 if (err != NULL) {
9197 *err = error;
9198 }
9199 }
9200}
9201
9202template< typename IteratorType >
9204 const CommandQueue &queue,
9205 IteratorType startIterator,
9206 IteratorType endIterator,
9207 bool readOnly,
9208 bool useHostPtr,
9209 cl_int* err)
9210{
9211 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9212 cl_int error;
9213
9214 cl_mem_flags flags = 0;
9215 if (readOnly) {
9216 flags |= CL_MEM_READ_ONLY;
9217 }
9218 else {
9219 flags |= CL_MEM_READ_WRITE;
9220 }
9221 if (useHostPtr) {
9222 flags |= CL_MEM_USE_HOST_PTR;
9223 }
9224
9225 size_type size = sizeof(DataType)*(endIterator - startIterator);
9226
9227 Context context = queue.getInfo<CL_QUEUE_CONTEXT>();
9228
9229 if (useHostPtr) {
9230 object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
9231 }
9232 else {
9233 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9234 }
9235
9236 detail::errHandler(error, __CREATE_BUFFER_ERR);
9237 if (err != NULL) {
9238 *err = error;
9239 }
9240
9241 if (!useHostPtr) {
9242 error = cl::copy(queue, startIterator, endIterator, *this);
9243 detail::errHandler(error, __CREATE_BUFFER_ERR);
9244 if (err != NULL) {
9245 *err = error;
9246 }
9247 }
9248}
9249
9250inline cl_int enqueueReadBuffer(
9251 const Buffer& buffer,
9252 cl_bool blocking,
9253 size_type offset,
9254 size_type size,
9255 void* ptr,
9256 const vector<Event>* events = NULL,
9257 Event* event = NULL)
9258{
9259 cl_int error;
9260 CommandQueue queue = CommandQueue::getDefault(&error);
9261
9262 if (error != CL_SUCCESS) {
9263 return error;
9264 }
9265
9266 return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event);
9267}
9268
9269inline cl_int enqueueWriteBuffer(
9270 const Buffer& buffer,
9271 cl_bool blocking,
9272 size_type offset,
9273 size_type size,
9274 const void* ptr,
9275 const vector<Event>* events = NULL,
9276 Event* event = NULL)
9277{
9278 cl_int error;
9279 CommandQueue queue = CommandQueue::getDefault(&error);
9280
9281 if (error != CL_SUCCESS) {
9282 return error;
9283 }
9284
9285 return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event);
9286}
9287
9288inline void* enqueueMapBuffer(
9289 const Buffer& buffer,
9290 cl_bool blocking,
9291 cl_map_flags flags,
9292 size_type offset,
9293 size_type size,
9294 const vector<Event>* events = NULL,
9295 Event* event = NULL,
9296 cl_int* err = NULL)
9297{
9298 cl_int error;
9299 CommandQueue queue = CommandQueue::getDefault(&error);
9300 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9301 if (err != NULL) {
9302 *err = error;
9303 }
9304
9305 void * result = ::clEnqueueMapBuffer(
9306 queue(), buffer(), blocking, flags, offset, size,
9307 (events != NULL) ? (cl_uint) events->size() : 0,
9308 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
9309 (cl_event*) event,
9310 &error);
9311
9312 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9313 if (err != NULL) {
9314 *err = error;
9315 }
9316 return result;
9317}
9318
9319
9320#if CL_HPP_TARGET_OPENCL_VERSION >= 200
9326template<typename T>
9327inline cl_int enqueueMapSVM(
9328 T* ptr,
9329 cl_bool blocking,
9330 cl_map_flags flags,
9331 size_type size,
9332 const vector<Event>* events,
9333 Event* event)
9334{
9335 cl_int error;
9336 CommandQueue queue = CommandQueue::getDefault(&error);
9337 if (error != CL_SUCCESS) {
9338 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9339 }
9340
9341 return queue.enqueueMapSVM(
9342 ptr, blocking, flags, size, events, event);
9343}
9344
9350template<typename T, class D>
9351inline cl_int enqueueMapSVM(
9352 cl::pointer<T, D> &ptr,
9353 cl_bool blocking,
9354 cl_map_flags flags,
9355 size_type size,
9356 const vector<Event>* events = NULL,
9357 Event* event = NULL)
9358{
9359 cl_int error;
9360 CommandQueue queue = CommandQueue::getDefault(&error);
9361 if (error != CL_SUCCESS) {
9362 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9363 }
9364
9365 return queue.enqueueMapSVM(
9366 ptr, blocking, flags, size, events, event);
9367}
9368
9374template<typename T, class Alloc>
9375inline cl_int enqueueMapSVM(
9376 cl::vector<T, Alloc> &container,
9377 cl_bool blocking,
9378 cl_map_flags flags,
9379 const vector<Event>* events = NULL,
9380 Event* event = NULL)
9381{
9382 cl_int error;
9383 CommandQueue queue = CommandQueue::getDefault(&error);
9384 if (error != CL_SUCCESS) {
9385 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9386 }
9387
9388 return queue.enqueueMapSVM(
9389 container, blocking, flags, events, event);
9390}
9391
9392#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9393
9394inline cl_int enqueueUnmapMemObject(
9395 const Memory& memory,
9396 void* mapped_ptr,
9397 const vector<Event>* events = NULL,
9398 Event* event = NULL)
9399{
9400 cl_int error;
9401 CommandQueue queue = CommandQueue::getDefault(&error);
9402 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9403 if (error != CL_SUCCESS) {
9404 return error;
9405 }
9406
9407 cl_event tmp;
9408 cl_int err = detail::errHandler(
9409 ::clEnqueueUnmapMemObject(
9410 queue(), memory(), mapped_ptr,
9411 (events != NULL) ? (cl_uint)events->size() : 0,
9412 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
9413 (event != NULL) ? &tmp : NULL),
9414 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9415
9416 if (event != NULL && err == CL_SUCCESS)
9417 *event = tmp;
9418
9419 return err;
9420}
9421
9422#if CL_HPP_TARGET_OPENCL_VERSION >= 200
9428template<typename T>
9429inline cl_int enqueueUnmapSVM(
9430 T* ptr,
9431 const vector<Event>* events = NULL,
9432 Event* event = NULL)
9433{
9434 cl_int error;
9435 CommandQueue queue = CommandQueue::getDefault(&error);
9436 if (error != CL_SUCCESS) {
9437 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9438 }
9439
9440 return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
9441 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9442
9443}
9444
9450template<typename T, class D>
9451inline cl_int enqueueUnmapSVM(
9452 cl::pointer<T, D> &ptr,
9453 const vector<Event>* events = NULL,
9454 Event* event = NULL)
9455{
9456 cl_int error;
9457 CommandQueue queue = CommandQueue::getDefault(&error);
9458 if (error != CL_SUCCESS) {
9459 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9460 }
9461
9462 return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
9463 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9464}
9465
9471template<typename T, class Alloc>
9472inline cl_int enqueueUnmapSVM(
9473 cl::vector<T, Alloc> &container,
9474 const vector<Event>* events = NULL,
9475 Event* event = NULL)
9476{
9477 cl_int error;
9478 CommandQueue queue = CommandQueue::getDefault(&error);
9479 if (error != CL_SUCCESS) {
9480 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9481 }
9482
9483 return detail::errHandler(queue.enqueueUnmapSVM(container, events, event),
9484 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9485}
9486
9487#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9488
9489inline cl_int enqueueCopyBuffer(
9490 const Buffer& src,
9491 const Buffer& dst,
9492 size_type src_offset,
9493 size_type dst_offset,
9494 size_type size,
9495 const vector<Event>* events = NULL,
9496 Event* event = NULL)
9497{
9498 cl_int error;
9499 CommandQueue queue = CommandQueue::getDefault(&error);
9500
9501 if (error != CL_SUCCESS) {
9502 return error;
9503 }
9504
9505 return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event);
9506}
9507
9513template< typename IteratorType >
9514inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
9515{
9516 cl_int error;
9517 CommandQueue queue = CommandQueue::getDefault(&error);
9518 if (error != CL_SUCCESS)
9519 return error;
9520
9521 return cl::copy(queue, startIterator, endIterator, buffer);
9522}
9523
9529template< typename IteratorType >
9530inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
9531{
9532 cl_int error;
9533 CommandQueue queue = CommandQueue::getDefault(&error);
9534 if (error != CL_SUCCESS)
9535 return error;
9536
9537 return cl::copy(queue, buffer, startIterator, endIterator);
9538}
9539
9545template< typename IteratorType >
9546inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
9547{
9548 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9549 cl_int error;
9550
9551 size_type length = endIterator-startIterator;
9552 size_type byteLength = length*sizeof(DataType);
9553
9554 DataType *pointer =
9555 static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error));
9556 // if exceptions enabled, enqueueMapBuffer will throw
9557 if( error != CL_SUCCESS ) {
9558 return error;
9559 }
9560#if defined(_MSC_VER)
9561 std::copy(
9562 startIterator,
9563 endIterator,
9564 stdext::checked_array_iterator<DataType*>(
9565 pointer, length));
9566#else
9567 std::copy(startIterator, endIterator, pointer);
9568#endif
9569 Event endEvent;
9570 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9571 // if exceptions enabled, enqueueUnmapMemObject will throw
9572 if( error != CL_SUCCESS ) {
9573 return error;
9574 }
9575 endEvent.wait();
9576 return CL_SUCCESS;
9577}
9578
9584template< typename IteratorType >
9585inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
9586{
9587 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9588 cl_int error;
9589
9590 size_type length = endIterator-startIterator;
9591 size_type byteLength = length*sizeof(DataType);
9592
9593 DataType *pointer =
9594 static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error));
9595 // if exceptions enabled, enqueueMapBuffer will throw
9596 if( error != CL_SUCCESS ) {
9597 return error;
9598 }
9599 std::copy(pointer, pointer + length, startIterator);
9600 Event endEvent;
9601 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9602 // if exceptions enabled, enqueueUnmapMemObject will throw
9603 if( error != CL_SUCCESS ) {
9604 return error;
9605 }
9606 endEvent.wait();
9607 return CL_SUCCESS;
9608}
9609
9610
9611#if CL_HPP_TARGET_OPENCL_VERSION >= 200
9615template<typename T, class Alloc>
9616inline cl_int mapSVM(cl::vector<T, Alloc> &container)
9617{
9618 return enqueueMapSVM(container, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE);
9619}
9620
9624template<typename T, class Alloc>
9625inline cl_int unmapSVM(cl::vector<T, Alloc> &container)
9626{
9627 return enqueueUnmapSVM(container);
9628}
9629
9630#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9631
9632#if CL_HPP_TARGET_OPENCL_VERSION >= 110
9633inline cl_int enqueueReadBufferRect(
9634 const Buffer& buffer,
9635 cl_bool blocking,
9636 const array<size_type, 3>& buffer_offset,
9637 const array<size_type, 3>& host_offset,
9638 const array<size_type, 3>& region,
9639 size_type buffer_row_pitch,
9640 size_type buffer_slice_pitch,
9641 size_type host_row_pitch,
9642 size_type host_slice_pitch,
9643 void *ptr,
9644 const vector<Event>* events = NULL,
9645 Event* event = NULL)
9646{
9647 cl_int error;
9648 CommandQueue queue = CommandQueue::getDefault(&error);
9649
9650 if (error != CL_SUCCESS) {
9651 return error;
9652 }
9653
9654 return queue.enqueueReadBufferRect(
9655 buffer,
9656 blocking,
9657 buffer_offset,
9658 host_offset,
9659 region,
9660 buffer_row_pitch,
9661 buffer_slice_pitch,
9662 host_row_pitch,
9663 host_slice_pitch,
9664 ptr,
9665 events,
9666 event);
9667}
9668
9669inline cl_int enqueueWriteBufferRect(
9670 const Buffer& buffer,
9671 cl_bool blocking,
9672 const array<size_type, 3>& buffer_offset,
9673 const array<size_type, 3>& host_offset,
9674 const array<size_type, 3>& region,
9675 size_type buffer_row_pitch,
9676 size_type buffer_slice_pitch,
9677 size_type host_row_pitch,
9678 size_type host_slice_pitch,
9679 const void *ptr,
9680 const vector<Event>* events = NULL,
9681 Event* event = NULL)
9682{
9683 cl_int error;
9684 CommandQueue queue = CommandQueue::getDefault(&error);
9685
9686 if (error != CL_SUCCESS) {
9687 return error;
9688 }
9689
9690 return queue.enqueueWriteBufferRect(
9691 buffer,
9692 blocking,
9693 buffer_offset,
9694 host_offset,
9695 region,
9696 buffer_row_pitch,
9697 buffer_slice_pitch,
9698 host_row_pitch,
9699 host_slice_pitch,
9700 ptr,
9701 events,
9702 event);
9703}
9704
9705inline cl_int enqueueCopyBufferRect(
9706 const Buffer& src,
9707 const Buffer& dst,
9708 const array<size_type, 3>& src_origin,
9709 const array<size_type, 3>& dst_origin,
9710 const array<size_type, 3>& region,
9711 size_type src_row_pitch,
9712 size_type src_slice_pitch,
9713 size_type dst_row_pitch,
9714 size_type dst_slice_pitch,
9715 const vector<Event>* events = NULL,
9716 Event* event = NULL)
9717{
9718 cl_int error;
9719 CommandQueue queue = CommandQueue::getDefault(&error);
9720
9721 if (error != CL_SUCCESS) {
9722 return error;
9723 }
9724
9725 return queue.enqueueCopyBufferRect(
9726 src,
9727 dst,
9728 src_origin,
9729 dst_origin,
9730 region,
9731 src_row_pitch,
9732 src_slice_pitch,
9733 dst_row_pitch,
9734 dst_slice_pitch,
9735 events,
9736 event);
9737}
9738#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
9739
9740inline cl_int enqueueReadImage(
9741 const Image& image,
9742 cl_bool blocking,
9743 const array<size_type, 3>& origin,
9744 const array<size_type, 3>& region,
9745 size_type row_pitch,
9746 size_type slice_pitch,
9747 void* ptr,
9748 const vector<Event>* events = NULL,
9749 Event* event = NULL)
9750{
9751 cl_int error;
9752 CommandQueue queue = CommandQueue::getDefault(&error);
9753
9754 if (error != CL_SUCCESS) {
9755 return error;
9756 }
9757
9758 return queue.enqueueReadImage(
9759 image,
9760 blocking,
9761 origin,
9762 region,
9763 row_pitch,
9764 slice_pitch,
9765 ptr,
9766 events,
9767 event);
9768}
9769
9770inline cl_int enqueueWriteImage(
9771 const Image& image,
9772 cl_bool blocking,
9773 const array<size_type, 3>& origin,
9774 const array<size_type, 3>& region,
9775 size_type row_pitch,
9776 size_type slice_pitch,
9777 const void* ptr,
9778 const vector<Event>* events = NULL,
9779 Event* event = NULL)
9780{
9781 cl_int error;
9782 CommandQueue queue = CommandQueue::getDefault(&error);
9783
9784 if (error != CL_SUCCESS) {
9785 return error;
9786 }
9787
9788 return queue.enqueueWriteImage(
9789 image,
9790 blocking,
9791 origin,
9792 region,
9793 row_pitch,
9794 slice_pitch,
9795 ptr,
9796 events,
9797 event);
9798}
9799
9800inline cl_int enqueueCopyImage(
9801 const Image& src,
9802 const Image& dst,
9803 const array<size_type, 3>& src_origin,
9804 const array<size_type, 3>& dst_origin,
9805 const array<size_type, 3>& region,
9806 const vector<Event>* events = NULL,
9807 Event* event = NULL)
9808{
9809 cl_int error;
9810 CommandQueue queue = CommandQueue::getDefault(&error);
9811
9812 if (error != CL_SUCCESS) {
9813 return error;
9814 }
9815
9816 return queue.enqueueCopyImage(
9817 src,
9818 dst,
9819 src_origin,
9820 dst_origin,
9821 region,
9822 events,
9823 event);
9824}
9825
9826inline cl_int enqueueCopyImageToBuffer(
9827 const Image& src,
9828 const Buffer& dst,
9829 const array<size_type, 3>& src_origin,
9830 const array<size_type, 3>& region,
9831 size_type dst_offset,
9832 const vector<Event>* events = NULL,
9833 Event* event = NULL)
9834{
9835 cl_int error;
9836 CommandQueue queue = CommandQueue::getDefault(&error);
9837
9838 if (error != CL_SUCCESS) {
9839 return error;
9840 }
9841
9842 return queue.enqueueCopyImageToBuffer(
9843 src,
9844 dst,
9845 src_origin,
9846 region,
9847 dst_offset,
9848 events,
9849 event);
9850}
9851
9852inline cl_int enqueueCopyBufferToImage(
9853 const Buffer& src,
9854 const Image& dst,
9855 size_type src_offset,
9856 const array<size_type, 3>& dst_origin,
9857 const array<size_type, 3>& region,
9858 const vector<Event>* events = NULL,
9859 Event* event = NULL)
9860{
9861 cl_int error;
9862 CommandQueue queue = CommandQueue::getDefault(&error);
9863
9864 if (error != CL_SUCCESS) {
9865 return error;
9866 }
9867
9868 return queue.enqueueCopyBufferToImage(
9869 src,
9870 dst,
9871 src_offset,
9872 dst_origin,
9873 region,
9874 events,
9875 event);
9876}
9877
9878
9879inline cl_int flush(void)
9880{
9881 cl_int error;
9882 CommandQueue queue = CommandQueue::getDefault(&error);
9883
9884 if (error != CL_SUCCESS) {
9885 return error;
9886 }
9887
9888 return queue.flush();
9889}
9890
9891inline cl_int finish(void)
9892{
9893 cl_int error;
9894 CommandQueue queue = CommandQueue::getDefault(&error);
9895
9896 if (error != CL_SUCCESS) {
9897 return error;
9898 }
9899
9900
9901 return queue.finish();
9902}
9903
9905{
9906private:
9907 CommandQueue queue_;
9908 const NDRange offset_;
9909 const NDRange global_;
9910 const NDRange local_;
9911 vector<Event> events_;
9912
9913 template<typename... Ts>
9914 friend class KernelFunctor;
9915
9916public:
9917 EnqueueArgs(NDRange global) :
9918 queue_(CommandQueue::getDefault()),
9919 offset_(NullRange),
9920 global_(global),
9921 local_(NullRange)
9922 {
9923
9924 }
9925
9926 EnqueueArgs(NDRange global, NDRange local) :
9927 queue_(CommandQueue::getDefault()),
9928 offset_(NullRange),
9929 global_(global),
9930 local_(local)
9931 {
9932
9933 }
9934
9935 EnqueueArgs(NDRange offset, NDRange global, NDRange local) :
9936 queue_(CommandQueue::getDefault()),
9937 offset_(offset),
9938 global_(global),
9939 local_(local)
9940 {
9941
9942 }
9943
9944 EnqueueArgs(Event e, NDRange global) :
9945 queue_(CommandQueue::getDefault()),
9946 offset_(NullRange),
9947 global_(global),
9948 local_(NullRange)
9949 {
9950 events_.push_back(e);
9951 }
9952
9953 EnqueueArgs(Event e, NDRange global, NDRange local) :
9954 queue_(CommandQueue::getDefault()),
9955 offset_(NullRange),
9956 global_(global),
9957 local_(local)
9958 {
9959 events_.push_back(e);
9960 }
9961
9962 EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) :
9963 queue_(CommandQueue::getDefault()),
9964 offset_(offset),
9965 global_(global),
9966 local_(local)
9967 {
9968 events_.push_back(e);
9969 }
9970
9971 EnqueueArgs(const vector<Event> &events, NDRange global) :
9972 queue_(CommandQueue::getDefault()),
9973 offset_(NullRange),
9974 global_(global),
9975 local_(NullRange),
9976 events_(events)
9977 {
9978
9979 }
9980
9981 EnqueueArgs(const vector<Event> &events, NDRange global, NDRange local) :
9982 queue_(CommandQueue::getDefault()),
9983 offset_(NullRange),
9984 global_(global),
9985 local_(local),
9986 events_(events)
9987 {
9988
9989 }
9990
9991 EnqueueArgs(const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
9992 queue_(CommandQueue::getDefault()),
9993 offset_(offset),
9994 global_(global),
9995 local_(local),
9996 events_(events)
9997 {
9998
9999 }
10000
10001 EnqueueArgs(CommandQueue &queue, NDRange global) :
10002 queue_(queue),
10003 offset_(NullRange),
10004 global_(global),
10005 local_(NullRange)
10006 {
10007
10008 }
10009
10010 EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) :
10011 queue_(queue),
10012 offset_(NullRange),
10013 global_(global),
10014 local_(local)
10015 {
10016
10017 }
10018
10019 EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) :
10020 queue_(queue),
10021 offset_(offset),
10022 global_(global),
10023 local_(local)
10024 {
10025
10026 }
10027
10028 EnqueueArgs(CommandQueue &queue, Event e, NDRange global) :
10029 queue_(queue),
10030 offset_(NullRange),
10031 global_(global),
10032 local_(NullRange)
10033 {
10034 events_.push_back(e);
10035 }
10036
10037 EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) :
10038 queue_(queue),
10039 offset_(NullRange),
10040 global_(global),
10041 local_(local)
10042 {
10043 events_.push_back(e);
10044 }
10045
10046 EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) :
10047 queue_(queue),
10048 offset_(offset),
10049 global_(global),
10050 local_(local)
10051 {
10052 events_.push_back(e);
10053 }
10054
10055 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global) :
10056 queue_(queue),
10057 offset_(NullRange),
10058 global_(global),
10059 local_(NullRange),
10060 events_(events)
10061 {
10062
10063 }
10064
10065 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global, NDRange local) :
10066 queue_(queue),
10067 offset_(NullRange),
10068 global_(global),
10069 local_(local),
10070 events_(events)
10071 {
10072
10073 }
10074
10075 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
10076 queue_(queue),
10077 offset_(offset),
10078 global_(global),
10079 local_(local),
10080 events_(events)
10081 {
10082
10083 }
10084};
10085
10086
10087//----------------------------------------------------------------------------------------------
10088
10089
10094template<typename... Ts>
10096{
10097private:
10098 Kernel kernel_;
10099
10100 template<int index, typename T0, typename... T1s>
10101 void setArgs(T0&& t0, T1s&&... t1s)
10102 {
10103 kernel_.setArg(index, t0);
10104 setArgs<index + 1, T1s...>(std::forward<T1s>(t1s)...);
10105 }
10106
10107 template<int index, typename T0>
10108 void setArgs(T0&& t0)
10109 {
10110 kernel_.setArg(index, t0);
10111 }
10112
10113 template<int index>
10114 void setArgs()
10115 {
10116 }
10117
10118
10119public:
10120 KernelFunctor(Kernel kernel) : kernel_(kernel)
10121 {}
10122
10124 const Program& program,
10125 const string name,
10126 cl_int * err = NULL) :
10127 kernel_(program, name.c_str(), err)
10128 {}
10129
10132
10139 const EnqueueArgs& args,
10140 Ts... ts)
10141 {
10142 Event event;
10143 setArgs<0>(std::forward<Ts>(ts)...);
10144
10145 args.queue_.enqueueNDRangeKernel(
10146 kernel_,
10147 args.offset_,
10148 args.global_,
10149 args.local_,
10150 &args.events_,
10151 &event);
10152
10153 return event;
10154 }
10155
10163 const EnqueueArgs& args,
10164 Ts... ts,
10165 cl_int &error)
10166 {
10167 Event event;
10168 setArgs<0>(std::forward<Ts>(ts)...);
10169
10170 error = args.queue_.enqueueNDRangeKernel(
10171 kernel_,
10172 args.offset_,
10173 args.global_,
10174 args.local_,
10175 &args.events_,
10176 &event);
10177
10178 return event;
10179 }
10180
10181#if CL_HPP_TARGET_OPENCL_VERSION >= 200
10182 cl_int setSVMPointers(const vector<void*> &pointerList)
10183 {
10184 return kernel_.setSVMPointers(pointerList);
10185 }
10186
10187 template<typename T0, typename... T1s>
10188 cl_int setSVMPointers(const T0 &t0, T1s &... ts)
10189 {
10190 return kernel_.setSVMPointers(t0, ts...);
10191 }
10192#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10193
10194 Kernel getKernel()
10195 {
10196 return kernel_;
10197 }
10198};
10199
10200namespace compatibility {
10205 template<typename... Ts>
10207 {
10208 typedef KernelFunctor<Ts...> FunctorType;
10209
10210 FunctorType functor_;
10211
10213 const Program& program,
10214 const string name,
10215 cl_int * err = NULL) :
10216 functor_(FunctorType(program, name, err))
10217 {}
10218
10220 const Kernel kernel) :
10221 functor_(FunctorType(kernel))
10222 {}
10223
10226
10228 typedef Event type_(
10229 const EnqueueArgs&,
10230 Ts...);
10231
10232 Event operator()(
10233 const EnqueueArgs& enqueueArgs,
10234 Ts... args)
10235 {
10236 return functor_(
10237 enqueueArgs, args...);
10238 }
10239 };
10240} // namespace compatibility
10241
10242
10243//----------------------------------------------------------------------------------------------------------------------
10244
10245#undef CL_HPP_ERR_STR_
10246#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
10247#undef __GET_DEVICE_INFO_ERR
10248#undef __GET_PLATFORM_INFO_ERR
10249#undef __GET_DEVICE_IDS_ERR
10250#undef __GET_PLATFORM_IDS_ERR
10251#undef __GET_CONTEXT_INFO_ERR
10252#undef __GET_EVENT_INFO_ERR
10253#undef __GET_EVENT_PROFILE_INFO_ERR
10254#undef __GET_MEM_OBJECT_INFO_ERR
10255#undef __GET_IMAGE_INFO_ERR
10256#undef __GET_SAMPLER_INFO_ERR
10257#undef __GET_KERNEL_INFO_ERR
10258#undef __GET_KERNEL_ARG_INFO_ERR
10259#undef __GET_KERNEL_SUB_GROUP_INFO_ERR
10260#undef __GET_KERNEL_WORK_GROUP_INFO_ERR
10261#undef __GET_PROGRAM_INFO_ERR
10262#undef __GET_PROGRAM_BUILD_INFO_ERR
10263#undef __GET_COMMAND_QUEUE_INFO_ERR
10264#undef __CREATE_CONTEXT_ERR
10265#undef __CREATE_CONTEXT_FROM_TYPE_ERR
10266#undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
10267#undef __CREATE_BUFFER_ERR
10268#undef __COPY_ERR
10269#undef __CREATE_SUBBUFFER_ERR
10270#undef __CREATE_GL_BUFFER_ERR
10271#undef __CREATE_GL_RENDER_BUFFER_ERR
10272#undef __GET_GL_OBJECT_INFO_ERR
10273#undef __CREATE_IMAGE_ERR
10274#undef __CREATE_GL_TEXTURE_ERR
10275#undef __IMAGE_DIMENSION_ERR
10276#undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
10277#undef __CREATE_USER_EVENT_ERR
10278#undef __SET_USER_EVENT_STATUS_ERR
10279#undef __SET_EVENT_CALLBACK_ERR
10280#undef __WAIT_FOR_EVENTS_ERR
10281#undef __CREATE_KERNEL_ERR
10282#undef __SET_KERNEL_ARGS_ERR
10283#undef __CREATE_PROGRAM_WITH_SOURCE_ERR
10284#undef __CREATE_PROGRAM_WITH_IL_ERR
10285#undef __CREATE_PROGRAM_WITH_BINARY_ERR
10286#undef __CREATE_PROGRAM_WITH_IL_ERR
10287#undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR
10288#undef __BUILD_PROGRAM_ERR
10289#undef __COMPILE_PROGRAM_ERR
10290#undef __LINK_PROGRAM_ERR
10291#undef __CREATE_KERNELS_IN_PROGRAM_ERR
10292#undef __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR
10293#undef __CREATE_SAMPLER_WITH_PROPERTIES_ERR
10294#undef __SET_COMMAND_QUEUE_PROPERTY_ERR
10295#undef __ENQUEUE_READ_BUFFER_ERR
10296#undef __ENQUEUE_READ_BUFFER_RECT_ERR
10297#undef __ENQUEUE_WRITE_BUFFER_ERR
10298#undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
10299#undef __ENQEUE_COPY_BUFFER_ERR
10300#undef __ENQEUE_COPY_BUFFER_RECT_ERR
10301#undef __ENQUEUE_FILL_BUFFER_ERR
10302#undef __ENQUEUE_READ_IMAGE_ERR
10303#undef __ENQUEUE_WRITE_IMAGE_ERR
10304#undef __ENQUEUE_COPY_IMAGE_ERR
10305#undef __ENQUEUE_FILL_IMAGE_ERR
10306#undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
10307#undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
10308#undef __ENQUEUE_MAP_BUFFER_ERR
10309#undef __ENQUEUE_MAP_IMAGE_ERR
10310#undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
10311#undef __ENQUEUE_NDRANGE_KERNEL_ERR
10312#undef __ENQUEUE_NATIVE_KERNEL
10313#undef __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR
10314#undef __ENQUEUE_MIGRATE_SVM_ERR
10315#undef __ENQUEUE_ACQUIRE_GL_ERR
10316#undef __ENQUEUE_RELEASE_GL_ERR
10317#undef __CREATE_PIPE_ERR
10318#undef __GET_PIPE_INFO_ERR
10319#undef __RETAIN_ERR
10320#undef __RELEASE_ERR
10321#undef __FLUSH_ERR
10322#undef __FINISH_ERR
10323#undef __VECTOR_CAPACITY_ERR
10324#undef __CREATE_SUB_DEVICES_ERR
10325#undef __CREATE_SUB_DEVICES_ERR
10326#undef __ENQUEUE_MARKER_ERR
10327#undef __ENQUEUE_WAIT_FOR_EVENTS_ERR
10328#undef __ENQUEUE_BARRIER_ERR
10329#undef __UNLOAD_COMPILER_ERR
10330#undef __CREATE_GL_TEXTURE_2D_ERR
10331#undef __CREATE_GL_TEXTURE_3D_ERR
10332#undef __CREATE_IMAGE2D_ERR
10333#undef __CREATE_IMAGE3D_ERR
10334#undef __CREATE_COMMAND_QUEUE_ERR
10335#undef __ENQUEUE_TASK_ERR
10336#undef __CREATE_SAMPLER_ERR
10337#undef __ENQUEUE_MARKER_WAIT_LIST_ERR
10338#undef __ENQUEUE_BARRIER_WAIT_LIST_ERR
10339#undef __CLONE_KERNEL_ERR
10340#undef __GET_HOST_TIMER_ERR
10341#undef __GET_DEVICE_AND_HOST_TIMER_ERR
10342
10343#endif //CL_HPP_USER_OVERRIDE_ERROR_STRINGS
10344
10345// Extensions
10346#undef CL_HPP_INIT_CL_EXT_FCN_PTR_
10347#undef CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_
10348
10349#if defined(CL_HPP_USE_CL_DEVICE_FISSION)
10350#undef CL_HPP_PARAM_NAME_DEVICE_FISSION_
10351#endif // CL_HPP_USE_CL_DEVICE_FISSION
10352
10353#undef CL_HPP_NOEXCEPT_
10354#undef CL_HPP_DEFINE_STATIC_MEMBER_
10355
10356} // namespace cl
10357
10358#endif // CL_HPP_
Class interface for GL Buffer Memory Objects.
Definition: opencl.hpp:4244
BufferGL(BufferGL &&buf) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4310
BufferGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4287
BufferGL()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4271
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:4251
BufferGL(const BufferGL &buf)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4296
cl_int getObjectInfo(cl_gl_object_type *type, cl_GLuint *gl_object_name)
Wrapper for clGetGLObjectInfo().
Definition: opencl.hpp:4322
BufferGL(const cl_mem &buffer, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4280
Class interface for Buffer Memory Objects.
Definition: opencl.hpp:3924
Buffer()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4046
Buffer(const Buffer &buf)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4071
Buffer(Buffer &&buf) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4085
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:3934
Buffer(const cl_mem &buffer, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4055
Buffer & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4062
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:3983
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:4101
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:3959
Class interface for GL Render Buffer Memory Objects.
Definition: opencl.hpp:4341
cl_int getObjectInfo(cl_gl_object_type *type, cl_GLuint *gl_object_name)
Wrapper for clGetGLObjectInfo().
Definition: opencl.hpp:4419
BufferRenderGL(const cl_mem &buffer, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4377
BufferRenderGL(BufferRenderGL &&buf) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4407
BufferRenderGL()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4368
BufferRenderGL(const BufferRenderGL &buf)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4393
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:4348
BufferRenderGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4384
CommandQueue interface for cl_command_queue.
Definition: opencl.hpp:7121
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:7252
CommandQueue(const cl_command_queue &commandQueue, bool retainObject=false)
Constructor from cl_command_queue - takes ownership.
Definition: opencl.hpp:7579
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:7840
CommandQueue(CommandQueue &&queue) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:7605
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:8558
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:8543
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:8040
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:8249
cl_int enqueueMigrateMemObjects(const vector< Memory > &memObjects, cl_mem_migration_flags flags, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8435
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:8521
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:8222
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:8505
static CommandQueue setDefault(const CommandQueue &default_queue)
Definition: opencl.hpp:7563
cl_int enqueueMarkerWithWaitList(const vector< Event > *events=0, Event *event=0) const
Definition: opencl.hpp:8382
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:8579
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:7186
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:8476
cl_int enqueueUnmapSVM(cl::pointer< T, D > &ptr, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8324
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:7444
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:7495
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:7382
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:7972
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int enqueueMarker(Event *event=NULL) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition: opencl.hpp:8678
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:8006
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int enqueueBarrier() const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition: opencl.hpp:8831
cl_int enqueueBarrierWithWaitList(const vector< Event > *events=0, Event *event=0) const
Definition: opencl.hpp:8412
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:7315
CommandQueue(const CommandQueue &queue)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:7591
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:8194
cl_int enqueueUnmapSVM(cl::vector< T, Alloc > &container, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8349
cl_int enqueueUnmapSVM(T *ptr, const vector< Event > *events=NULL, Event *event=NULL) const
Definition: opencl.hpp:8299
Class interface for cl_context.
Definition: opencl.hpp:2839
Context(const vector< Device > &devices, const 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:2909
static Context setDefault(const Context &default_context)
Definition: opencl.hpp:3107
Context(const cl_context &context, bool retainObject=false)
Constructor from cl_context - takes ownership.
Definition: opencl.hpp:3122
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:3148
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:3163
Context()
Default constructor - initializes to NULL.
Definition: opencl.hpp:3115
cl_int getInfo(cl_context_info name, T *param) const
Wrapper for clGetContextInfo().
Definition: opencl.hpp:3138
Context(cl_device_type type, const 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:2974
static Context getDefault(cl_int *err=NULL)
Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT.
Definition: opencl.hpp:3090
Context(const Device &device, const 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:2944
Context(const Context &ctx)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3060
Context(Context &&ctx) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3074
Context & operator=(const Context &ctx)
Copy assignment to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3065
DeviceCommandQueue interface for device cl_command_queues.
Definition: opencl.hpp:8871
DeviceCommandQueue(const Context &context, const Device &device, DeviceQueueProperties properties=DeviceQueueProperties::None, cl_int *err=NULL)
Definition: opencl.hpp:8905
DeviceCommandQueue(const Context &context, const Device &device, cl_uint queueSize, DeviceQueueProperties properties=DeviceQueueProperties::None, cl_int *err=NULL)
Definition: opencl.hpp:8929
static DeviceCommandQueue makeDefault(const Context &context, const Device &device, cl_int *err=nullptr)
Definition: opencl.hpp:9054
static DeviceCommandQueue updateDefault(const Context &context, const Device &device, const DeviceCommandQueue &default_queue, cl_int *err=nullptr)
Definition: opencl.hpp:9114
static DeviceCommandQueue getDefault(const CommandQueue &queue, cl_int *err=NULL)
Definition: opencl.hpp:9129
static DeviceCommandQueue makeDefault(const Context &context, const Device &device, cl_uint queueSize, cl_int *err=nullptr)
Definition: opencl.hpp:9082
DeviceCommandQueue(DeviceQueueProperties properties, cl_int *err=NULL)
Definition: opencl.hpp:8882
DeviceCommandQueue(const DeviceCommandQueue &queue)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:8971
DeviceCommandQueue(DeviceCommandQueue &&queue) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:8985
DeviceCommandQueue(const cl_command_queue &commandQueue, bool retainObject=false)
Constructor from cl_command_queue - takes ownership.
Definition: opencl.hpp:8959
static DeviceCommandQueue makeDefault(cl_int *err=nullptr)
Definition: opencl.hpp:9024
Class interface for cl_device_id.
Definition: opencl.hpp:2176
Device & operator=(const cl_device_id &rhs)
Assignment operator from cl_device_id.
Definition: opencl.hpp:2254
cl_int getInfo(cl_device_info name, T *param) const
Wrapper for clGetDeviceInfo().
Definition: opencl.hpp:2290
Device()
Default constructor - initializes to NULL.
Definition: opencl.hpp:2212
cl_ulong getHostTimer(cl_int *error=nullptr)
Definition: opencl.hpp:2319
static Device getDefault(cl_int *errResult=NULL)
Returns the first device on the default context.
Definition: opencl.hpp:2225
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:2300
Device(const Device &dev)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:2263
Device(Device &&dev) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:2277
std::pair< cl_ulong, cl_ulong > getDeviceAndHostTimer(cl_int *error=nullptr)
Definition: opencl.hpp:2343
cl_int createSubDevices(const cl_device_partition_property *properties, vector< Device > *devices)
Wrapper for clCreateSubDevices().
Definition: opencl.hpp:2363
static Device setDefault(const Device &default_device)
Definition: opencl.hpp:2243
Device(const cl_device_id &device, bool retainObject=false)
Constructor from cl_device_id.
Definition: opencl.hpp:2218
Class interface for cl_event.
Definition: opencl.hpp:3251
Event(const cl_event &event, bool retainObject=false)
Constructor from cl_event - takes ownership.
Definition: opencl.hpp:3264
cl_int getProfilingInfo(cl_profiling_info name, T *param) const
Wrapper for clGetEventProfilingInfo().
Definition: opencl.hpp:3303
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:3340
cl_int getInfo(cl_event_info name, T *param) const
Wrapper for clGetEventInfo().
Definition: opencl.hpp:3280
cl_int wait() const
Blocks the calling thread until this event completes.
Definition: opencl.hpp:3328
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:3290
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:3313
Event()
Default constructor - initializes to NULL.
Definition: opencl.hpp:3254
Event & operator=(const cl_event &rhs)
Assignment operator from cl_event - takes ownership.
Definition: opencl.hpp:3272
static cl_int waitForEvents(const vector< Event > &events)
Blocks the calling thread until every event specified is complete.
Definition: opencl.hpp:3360
Image interface for arrays of 1D images.
Definition: opencl.hpp:4697
Image1DArray(const Image1DArray &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4753
Image1DArray(Image1DArray &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4767
Image1DArray(const cl_mem &imageArray, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4740
Image interface for 1D buffer images.
Definition: opencl.hpp:4614
Image1DBuffer(const Image1DBuffer &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4666
Image1DBuffer(const cl_mem &image1D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4654
Image1DBuffer(Image1DBuffer &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4680
Class interface for 1D Image Memory objects.
Definition: opencl.hpp:4523
Image1D()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4558
Image1D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4574
Image1D(const cl_mem &image1D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4567
Image1D(const Image1D &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4583
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:4529
Image1D(Image1D &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4597
Image interface for arrays of 2D images.
Definition: opencl.hpp:5114
Image2DArray(const Image2DArray &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5172
Image2DArray(const cl_mem &imageArray, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5161
Image2DArray(Image2DArray &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5186
Class interface for GL 2D Image Memory objects.
Definition: opencl.hpp:5024
Image2DGL()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5056
Image2DGL(const Image2DGL &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5081
Image2DGL(Image2DGL &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5095
Image2DGL(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5065
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:5031
Class interface for 2D Image Memory objects.
Definition: opencl.hpp:4789
Image2D(const Image2D &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4985
Image2D(const cl_mem &image2D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4969
Image2D()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4960
Image2D(Image2D &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4999
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:4795
Image2D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4976
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:4863
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:4909
Class interface for GL 3D Image Memory objects.
Definition: opencl.hpp:5341
Image3DGL()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5372
Image3DGL(Image3DGL &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5411
Image3DGL(const Image3DGL &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5397
Image3DGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:5388
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:5348
Image3DGL(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5381
Class interface for 3D Image Memory objects.
Definition: opencl.hpp:5206
Image3D(const cl_mem &image3D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5289
Image3D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:5296
Image3D()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5280
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:5212
Image3D(Image3D &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5319
Image3D(const Image3D &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5305
general image interface for GL interop. We abstract the 2D and 3D GL images into a single instance he...
Definition: opencl.hpp:5432
ImageGL(const ImageGL &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5478
ImageGL(ImageGL &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5492
ImageGL(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5466
C++ base class for Image Memory objects.
Definition: opencl.hpp:4436
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:4503
Image(const Image &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4464
Image(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:4448
cl_int getImageInfo(cl_image_info name, T *param) const
Wrapper for clGetImageInfo().
Definition: opencl.hpp:4493
Image & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:4455
Image()
Default constructor - initializes to NULL.
Definition: opencl.hpp:4439
Image(Image &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:4478
Event operator()(const EnqueueArgs &args, Ts... ts)
Definition: opencl.hpp:10138
Event result_type
Return type of the functor.
Definition: opencl.hpp:10131
Class interface for cl_kernel.
Definition: opencl.hpp:5922
Kernel(Kernel &&kernel) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5968
Kernel(const cl_kernel &kernel, bool retainObject=false)
Constructor from cl_kernel - takes ownership.
Definition: opencl.hpp:5937
cl_int setSVMPointers(const vector< void * > &pointerList)
Definition: opencl.hpp:6140
cl_int setArg(cl_uint index, const cl::pointer< T, D > &argPtr)
setArg overload taking a shared_ptr type
Definition: opencl.hpp:6084
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:6105
Kernel()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5927
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:6117
Kernel(const Kernel &kernel)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5954
cl_int setArg(cl_uint index, const cl::vector< T, Alloc > &argPtr)
setArg overload taking a vector type.
Definition: opencl.hpp:6094
Kernel & operator=(const cl_kernel &rhs)
Assignment operator from cl_kernel - takes ownership.
Definition: opencl.hpp:5945
cl_int setSVMPointers(const std::array< void *, ArrayLength > &pointerList)
Definition: opencl.hpp:6155
Kernel clone()
Definition: opencl.hpp:6256
cl_int enableFineGrainedSystemSVM(bool svmEnabled)
Enable fine-grained system SVM.
Definition: opencl.hpp:6176
Class interface for cl_mem.
Definition: opencl.hpp:3434
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:3530
Memory(const Memory &mem)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3467
Memory(Memory &&mem) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:3481
Memory(const cl_mem &memory, bool retainObject)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:3450
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:3505
Memory()
Default constructor - initializes to NULL.
Definition: opencl.hpp:3437
Memory & operator=(const cl_mem &rhs)
Assignment operator from cl_mem - takes ownership.
Definition: opencl.hpp:3458
cl_int getInfo(cl_mem_info name, T *param) const
Wrapper for clGetMemObjectInfo().
Definition: opencl.hpp:3495
Class interface for specifying NDRange values.
Definition: opencl.hpp:5785
size_type dimensions() const
Queries the number of dimensions in the range.
Definition: opencl.hpp:5836
NDRange(size_type size0, size_type size1)
Constructs two-dimensional range.
Definition: opencl.hpp:5810
NDRange(size_type size0, size_type size1, size_type size2)
Constructs three-dimensional range.
Definition: opencl.hpp:5819
size_type size() const
Returns the size of the object in bytes based on the.
Definition: opencl.hpp:5843
NDRange()
Default constructor - resulting range has zero dimensions.
Definition: opencl.hpp:5792
NDRange(size_type size0)
Constructs one-dimensional range.
Definition: opencl.hpp:5801
Class interface for Pipe Memory Objects.
Definition: opencl.hpp:5515
Pipe(Pipe &&pipe) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5610
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:5527
Pipe()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5571
cl_int getInfo(cl_pipe_info name, T *param) const
Wrapper for clGetMemObjectInfo().
Definition: opencl.hpp:5623
Pipe(cl_uint packet_size, cl_uint max_packets, cl_int *err=NULL)
Constructs a Pipe in a the default context.
Definition: opencl.hpp:5552
Pipe(const Pipe &pipe)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5596
Pipe(const cl_mem &pipe, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition: opencl.hpp:5580
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:5633
Pipe & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition: opencl.hpp:5587
Class interface for cl_platform_id.
Definition: opencl.hpp:2456
static cl_int get(Platform *platform)
Gets the first available platform.
Definition: opencl.hpp:2767
Platform(const cl_platform_id &platform, bool retainObject=false)
Constructor from cl_platform_id.
Definition: opencl.hpp:2537
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:2587
Platform()
Default constructor - initializes to NULL.
Definition: opencl.hpp:2528
cl_int unloadCompiler()
Wrapper for clUnloadCompiler().
Definition: opencl.hpp:2800
cl_int getDevices(cl_device_type type, vector< Device > *devices) const
Gets a list of devices for this platform.
Definition: opencl.hpp:2602
static Platform get(cl_int *errResult=NULL)
Gets the first available platform, returning it by value.
Definition: opencl.hpp:2786
Platform & operator=(const cl_platform_id &rhs)
Assignment operator from cl_platform_id.
Definition: opencl.hpp:2544
static cl_int get(vector< Platform > *platforms)
Gets a list of available platforms.
Definition: opencl.hpp:2732
cl_int getInfo(cl_platform_info name, T *param) const
Wrapper for clGetPlatformInfo().
Definition: opencl.hpp:2577
static Platform setDefault(const Platform &default_platform)
Definition: opencl.hpp:2568
Program interface that implements cl_program.
Definition: opencl.hpp:6271
Program(const Program &program)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:6668
Program(Program &&program) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:6682
Program(const Sources &sources, cl_int *err=NULL)
Definition: opencl.hpp:6361
Program(const Context &context, const Sources &sources, cl_int *err=NULL)
Definition: opencl.hpp:6396
Program(const vector< char > &IL, bool build=false, cl_int *err=NULL)
Definition: opencl.hpp:6433
CL_API_PREFIX__VERSION_2_2_DEPRECATED cl_int setReleaseCallback(void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data), void *user_data=NULL) CL_API_SUFFIX__VERSION_2_2_DEPRECATED
Registers a callback function to be called when destructors for program scope global variables are co...
Definition: opencl.hpp:6905
Program(const Context &context, const vector< Device > &devices, const string &kernelNames, cl_int *err=NULL)
Definition: opencl.hpp:6618
cl_int setSpecializationConstant(cl_uint index, size_type size, const void *value)
Sets a SPIR-V specialization constant.
Definition: opencl.hpp:6939
Program(const cl_program &program, bool retainObject=false)
Constructor from cl_program - takes ownership.
Definition: opencl.hpp:6656
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:6826
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:6924
Program(const Context &context, const vector< Device > &devices, const Binaries &binaries, vector< cl_int > *binaryStatus=NULL, cl_int *err=NULL)
Definition: opencl.hpp:6554
Program(const Context &context, const vector< char > &IL, bool build=false, cl_int *err=NULL)
Definition: opencl.hpp:6487
pointer allocate(size_type size, typename cl::SVMAllocator< void, SVMTrait >::const_pointer=0)
Definition: opencl.hpp:3723
bool operator==(SVMAllocator const &rhs)
Definition: opencl.hpp:3793
size_type max_size() const CL_HPP_NOEXCEPT_
Definition: opencl.hpp:3765
Class interface for cl_sampler.
Definition: opencl.hpp:5656
Sampler()
Default constructor - initializes to NULL.
Definition: opencl.hpp:5659
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:5665
Sampler(Sampler &&sam) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5743
Sampler & operator=(const cl_sampler &rhs)
Assignment operator from cl_sampler - takes ownership.
Definition: opencl.hpp:5720
Sampler(const Sampler &sam)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition: opencl.hpp:5729
cl_int getInfo(cl_sampler_info name, T *param) const
Wrapper for clGetSamplerInfo().
Definition: opencl.hpp:5756
Sampler(const cl_sampler &sampler, bool retainObject=false)
Constructor from cl_sampler - takes ownership.
Definition: opencl.hpp:5712
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:5766
Class interface for user events (a subset of cl_event's).
Definition: opencl.hpp:3375
UserEvent()
Default constructor - initializes to NULL.
Definition: opencl.hpp:3397
UserEvent(const Context &context, cl_int *err=NULL)
Constructs a user event on a given context.
Definition: opencl.hpp:3381
cl_int setStatus(cl_int status)
Sets the execution status of a user event object.
Definition: opencl.hpp:3403
The OpenCL C++ bindings are defined within this namespace.
Definition: opencl.hpp:598
cl_int copy(const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator)
Definition: opencl.hpp:9585
vector< T, cl::SVMAllocator< int, cl::SVMTraitFine<> > > fine_svm_vector
Vector alias to simplify contruction of fine-grained SVM containers.
Definition: opencl.hpp:3906
cl_int copy(IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer)
Definition: opencl.hpp:9514
LocalSpaceArg Local(size_type size)
Helper function for generating LocalSpaceArg objects.
Definition: opencl.hpp:5907
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int UnloadCompiler() CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition: opencl.hpp:2823
cl_int enqueueUnmapSVM(T *ptr, const vector< Event > *events=NULL, Event *event=NULL)
Definition: opencl.hpp:9429
cl::pointer< T, detail::Deleter< Alloc > > allocate_pointer(const Alloc &alloc_, Args &&... args)
Definition: opencl.hpp:3853
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:9327
vector< T, cl::SVMAllocator< int, cl::SVMTraitCoarse<> > > coarse_svm_vector
Vector alias to simplify contruction of coarse-grained SVM containers.
Definition: opencl.hpp:3900
cl_int mapSVM(cl::vector< T, Alloc > &container)
Definition: opencl.hpp:9616
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:3912
cl_int unmapSVM(cl::vector< T, Alloc > &container)
Definition: opencl.hpp:9625
Adds constructors and member functions for cl_image_format.
Definition: opencl.hpp:2143
ImageFormat(cl_channel_order order, cl_channel_type type)
Initializing constructor.
Definition: opencl.hpp:2148
ImageFormat & operator=(const ImageFormat &rhs)
Assignment operator.
Definition: opencl.hpp:2158
ImageFormat(const ImageFormat &other)
Copy constructor.
Definition: opencl.hpp:2155
ImageFormat()
Default constructor - performs no initialization.
Definition: opencl.hpp:2145
Local address wrapper for use with Kernel::setArg.
Definition: opencl.hpp:5864
Event type_(const EnqueueArgs &, Ts...)
Function signature of kernel functor with no event dependency.
Definition: opencl.hpp:10228
Event result_type
Return type of the functor.
Definition: opencl.hpp:10225
static cl_int release(cl_device_id device)
Definition: opencl.hpp:1704
static cl_int retain(cl_device_id device)
Definition: opencl.hpp:1693