OpenCL C++ Bindings
Loading...
Searching...
No Matches
opencl.hpp
Go to the documentation of this file.
1//
2// Copyright (c) 2008-2020 The Khronos Group Inc.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
311
324
388#ifndef CL_HPP_
389#define CL_HPP_
390
391/* Handle deprecated preprocessor definitions. In each case, we only check for
392 * the old name if the new name is not defined, so that user code can define
393 * both and hence work with either version of the bindings.
394 */
395#if !defined(CL_HPP_USE_DX_INTEROP) && defined(USE_DX_INTEROP)
396# pragma message("opencl.hpp: USE_DX_INTEROP is deprecated. Define CL_HPP_USE_DX_INTEROP instead")
397# define CL_HPP_USE_DX_INTEROP
398#endif
399#if !defined(CL_HPP_USE_CL_DEVICE_FISSION) && defined(USE_CL_DEVICE_FISSION)
400# pragma message("opencl.hpp: USE_CL_DEVICE_FISSION is deprecated. Define CL_HPP_USE_CL_DEVICE_FISSION instead")
401# define CL_HPP_USE_CL_DEVICE_FISSION
402#endif
403#if !defined(CL_HPP_ENABLE_EXCEPTIONS) && defined(__CL_ENABLE_EXCEPTIONS)
404# pragma message("opencl.hpp: __CL_ENABLE_EXCEPTIONS is deprecated. Define CL_HPP_ENABLE_EXCEPTIONS instead")
405# define CL_HPP_ENABLE_EXCEPTIONS
406#endif
407#if !defined(CL_HPP_NO_STD_VECTOR) && defined(__NO_STD_VECTOR)
408# pragma message("opencl.hpp: __NO_STD_VECTOR is deprecated. Define CL_HPP_NO_STD_VECTOR instead")
409# define CL_HPP_NO_STD_VECTOR
410#endif
411#if !defined(CL_HPP_NO_STD_STRING) && defined(__NO_STD_STRING)
412# pragma message("opencl.hpp: __NO_STD_STRING is deprecated. Define CL_HPP_NO_STD_STRING instead")
413# define CL_HPP_NO_STD_STRING
414#endif
415#if defined(VECTOR_CLASS)
416# pragma message("opencl.hpp: VECTOR_CLASS is deprecated. Alias cl::vector instead")
417#endif
418#if defined(STRING_CLASS)
419# pragma message("opencl.hpp: STRING_CLASS is deprecated. Alias cl::string instead.")
420#endif
421#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) && defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
422# pragma message("opencl.hpp: __CL_USER_OVERRIDE_ERROR_STRINGS is deprecated. Define CL_HPP_USER_OVERRIDE_ERROR_STRINGS instead")
423# define CL_HPP_USER_OVERRIDE_ERROR_STRINGS
424#endif
425
426/* Warn about features that are no longer supported
427 */
428#if defined(__USE_DEV_VECTOR)
429# pragma message("opencl.hpp: __USE_DEV_VECTOR is no longer supported. Expect compilation errors")
430#endif
431#if defined(__USE_DEV_STRING)
432# pragma message("opencl.hpp: __USE_DEV_STRING is no longer supported. Expect compilation errors")
433#endif
434
435/* Detect which version to target */
436#if !defined(CL_HPP_TARGET_OPENCL_VERSION)
437# pragma message("opencl.hpp: CL_HPP_TARGET_OPENCL_VERSION is not defined. It will default to 300 (OpenCL 3.0)")
438# define CL_HPP_TARGET_OPENCL_VERSION 300
439#endif
440#if CL_HPP_TARGET_OPENCL_VERSION != 100 && \
441 CL_HPP_TARGET_OPENCL_VERSION != 110 && \
442 CL_HPP_TARGET_OPENCL_VERSION != 120 && \
443 CL_HPP_TARGET_OPENCL_VERSION != 200 && \
444 CL_HPP_TARGET_OPENCL_VERSION != 210 && \
445 CL_HPP_TARGET_OPENCL_VERSION != 220 && \
446 CL_HPP_TARGET_OPENCL_VERSION != 300
447# pragma message("opencl.hpp: CL_HPP_TARGET_OPENCL_VERSION is not a valid value (100, 110, 120, 200, 210, 220 or 300). It will be set to 300 (OpenCL 3.0).")
448# undef CL_HPP_TARGET_OPENCL_VERSION
449# define CL_HPP_TARGET_OPENCL_VERSION 300
450#endif
451
452/* Forward target OpenCL version to C headers if necessary */
453#if defined(CL_TARGET_OPENCL_VERSION)
454/* Warn if prior definition of CL_TARGET_OPENCL_VERSION is lower than
455 * requested C++ bindings version */
456#if CL_TARGET_OPENCL_VERSION < CL_HPP_TARGET_OPENCL_VERSION
457# pragma message("CL_TARGET_OPENCL_VERSION is already defined as is lower than CL_HPP_TARGET_OPENCL_VERSION")
458#endif
459#else
460# define CL_TARGET_OPENCL_VERSION CL_HPP_TARGET_OPENCL_VERSION
461#endif
462
463#if !defined(CL_HPP_MINIMUM_OPENCL_VERSION)
464# define CL_HPP_MINIMUM_OPENCL_VERSION 200
465#endif
466#if CL_HPP_MINIMUM_OPENCL_VERSION != 100 && \
467 CL_HPP_MINIMUM_OPENCL_VERSION != 110 && \
468 CL_HPP_MINIMUM_OPENCL_VERSION != 120 && \
469 CL_HPP_MINIMUM_OPENCL_VERSION != 200 && \
470 CL_HPP_MINIMUM_OPENCL_VERSION != 210 && \
471 CL_HPP_MINIMUM_OPENCL_VERSION != 220 && \
472 CL_HPP_MINIMUM_OPENCL_VERSION != 300
473# pragma message("opencl.hpp: CL_HPP_MINIMUM_OPENCL_VERSION is not a valid value (100, 110, 120, 200, 210, 220 or 300). It will be set to 100")
474# undef CL_HPP_MINIMUM_OPENCL_VERSION
475# define CL_HPP_MINIMUM_OPENCL_VERSION 100
476#endif
477#if CL_HPP_MINIMUM_OPENCL_VERSION > CL_HPP_TARGET_OPENCL_VERSION
478# error "CL_HPP_MINIMUM_OPENCL_VERSION must not be greater than CL_HPP_TARGET_OPENCL_VERSION"
479#endif
480
481#if CL_HPP_MINIMUM_OPENCL_VERSION <= 100 && !defined(CL_USE_DEPRECATED_OPENCL_1_0_APIS)
482# define CL_USE_DEPRECATED_OPENCL_1_0_APIS
483#endif
484#if CL_HPP_MINIMUM_OPENCL_VERSION <= 110 && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
485# define CL_USE_DEPRECATED_OPENCL_1_1_APIS
486#endif
487#if CL_HPP_MINIMUM_OPENCL_VERSION <= 120 && !defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
488# define CL_USE_DEPRECATED_OPENCL_1_2_APIS
489#endif
490#if CL_HPP_MINIMUM_OPENCL_VERSION <= 200 && !defined(CL_USE_DEPRECATED_OPENCL_2_0_APIS)
491# define CL_USE_DEPRECATED_OPENCL_2_0_APIS
492#endif
493#if CL_HPP_MINIMUM_OPENCL_VERSION <= 210 && !defined(CL_USE_DEPRECATED_OPENCL_2_1_APIS)
494# define CL_USE_DEPRECATED_OPENCL_2_1_APIS
495#endif
496#if CL_HPP_MINIMUM_OPENCL_VERSION <= 220 && !defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
497# define CL_USE_DEPRECATED_OPENCL_2_2_APIS
498#endif
499
500#ifdef _WIN32
501
502#include <malloc.h>
503
504#if defined(CL_HPP_USE_DX_INTEROP)
505#include <CL/cl_d3d10.h>
506#include <CL/cl_dx9_media_sharing.h>
507#endif
508#endif // _WIN32
509
510#if defined(_MSC_VER)
511#include <intrin.h>
512#endif // _MSC_VER
513
514 // Check for a valid C++ version
515
516// Need to do both tests here because for some reason __cplusplus is not
517// updated in visual studio
518#if (!defined(_MSC_VER) && __cplusplus < 201103L) || (defined(_MSC_VER) && _MSC_VER < 1700)
519#error Visual studio 2013 or another C++11-supporting compiler required
520#endif
521
522//
523#if defined(CL_HPP_USE_CL_DEVICE_FISSION) || defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)
524#include <CL/cl_ext.h>
525#endif
526
527#if defined(__APPLE__) || defined(__MACOSX)
528#include <OpenCL/opencl.h>
529#else
530#include <CL/opencl.h>
531#endif // !__APPLE__
532
533#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L )
534#define CL_HPP_NOEXCEPT_ noexcept
535#else
536#define CL_HPP_NOEXCEPT_
537#endif
538
539#if __cplusplus >= 201703L
540# define CL_HPP_DEFINE_STATIC_MEMBER_ inline
541#elif defined(_MSC_VER)
542# define CL_HPP_DEFINE_STATIC_MEMBER_ __declspec(selectany)
543#elif defined(__MINGW32__)
544# define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((selectany))
545#else
546# define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((weak))
547#endif // !_MSC_VER
548
549// Define deprecated prefixes and suffixes to ensure compilation
550// in case they are not pre-defined
551#if !defined(CL_API_PREFIX__VERSION_1_1_DEPRECATED)
552#define CL_API_PREFIX__VERSION_1_1_DEPRECATED
553#endif // #if !defined(CL_API_PREFIX__VERSION_1_1_DEPRECATED)
554#if !defined(CL_API_SUFFIX__VERSION_1_1_DEPRECATED)
555#define CL_API_SUFFIX__VERSION_1_1_DEPRECATED
556#endif // #if !defined(CL_API_PREFIX__VERSION_1_1_DEPRECATED)
557
558#if !defined(CL_API_PREFIX__VERSION_1_2_DEPRECATED)
559#define CL_API_PREFIX__VERSION_1_2_DEPRECATED
560#endif // #if !defined(CL_API_PREFIX__VERSION_1_2_DEPRECATED)
561#if !defined(CL_API_SUFFIX__VERSION_1_2_DEPRECATED)
562#define CL_API_SUFFIX__VERSION_1_2_DEPRECATED
563#endif // #if !defined(CL_API_PREFIX__VERSION_1_2_DEPRECATED)
564
565#if !defined(CL_CALLBACK)
566#define CL_CALLBACK
567#endif //CL_CALLBACK
568
569#include <utility>
570#include <limits>
571#include <iterator>
572#include <mutex>
573#include <cstring>
574#include <functional>
575
576
577// Define a size_type to represent a correctly resolved size_t
578#if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
579namespace cl {
580 using size_type = ::size_t;
581} // namespace cl
582#else // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
583namespace cl {
584 using size_type = size_t;
585} // namespace cl
586#endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
587
588
589#if defined(CL_HPP_ENABLE_EXCEPTIONS)
590#include <exception>
591#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
592
593#if !defined(CL_HPP_NO_STD_VECTOR)
594#include <vector>
595namespace cl {
596 template < class T, class Alloc = std::allocator<T> >
597 using vector = std::vector<T, Alloc>;
598} // namespace cl
599#endif // #if !defined(CL_HPP_NO_STD_VECTOR)
600
601#if !defined(CL_HPP_NO_STD_STRING)
602#include <string>
603namespace cl {
604 using string = std::string;
605} // namespace cl
606#endif // #if !defined(CL_HPP_NO_STD_STRING)
607
608#if CL_HPP_TARGET_OPENCL_VERSION >= 200
609
610#if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
611#include <memory>
612namespace cl {
613 // Replace unique_ptr and allocate_pointer for internal use
614 // to allow user to replace them
615 template<class T, class D>
616 using pointer = std::unique_ptr<T, D>;
617} // namespace cl
618#endif
619#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
620#if !defined(CL_HPP_NO_STD_ARRAY)
621#include <array>
622namespace cl {
623 template < class T, size_type N >
624 using array = std::array<T, N>;
625} // namespace cl
626#endif // #if !defined(CL_HPP_NO_STD_ARRAY)
627
628// Define size_type appropriately to allow backward-compatibility
629// use of the old size_t interface class
630#if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
631namespace cl {
632 namespace compatibility {
637 template <int N>
638 class size_t
639 {
640 private:
641 size_type data_[N];
642
643 public:
645 size_t()
646 {
647 for (int i = 0; i < N; ++i) {
648 data_[i] = 0;
649 }
650 }
651
652 size_t(const array<size_type, N> &rhs)
653 {
654 for (int i = 0; i < N; ++i) {
655 data_[i] = rhs[i];
656 }
657 }
658
659 size_type& operator[](int index)
660 {
661 return data_[index];
662 }
663
664 const size_type& operator[](int index) const
665 {
666 return data_[index];
667 }
668
670 operator size_type* () { return data_; }
671
673 operator const size_type* () const { return data_; }
674
675 operator array<size_type, N>() const
676 {
677 array<size_type, N> ret;
678
679 for (int i = 0; i < N; ++i) {
680 ret[i] = data_[i];
681 }
682 return ret;
683 }
684 };
685 } // namespace compatibility
686
687 template<int N>
688 using size_t = compatibility::size_t<N>;
689} // namespace cl
690#endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
691
692// Helper alias to avoid confusing the macros
693namespace cl {
694 namespace detail {
695 using size_t_array = array<size_type, 3>;
696 } // namespace detail
697} // namespace cl
698
699
705namespace cl {
706 class Memory;
707
708#define CL_HPP_INIT_CL_EXT_FCN_PTR_(name) \
709 if (!pfn_##name) { \
710 pfn_##name = (PFN_##name) \
711 clGetExtensionFunctionAddress(#name); \
712 if (!pfn_##name) { \
713 } \
714 }
715
716#define CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, name) \
717 if (!pfn_##name) { \
718 pfn_##name = (PFN_##name) \
719 clGetExtensionFunctionAddressForPlatform(platform, #name); \
720 if (!pfn_##name) { \
721 } \
722 }
723
724 class Program;
725 class Device;
726 class Context;
727 class CommandQueue;
728 class DeviceCommandQueue;
729 class Memory;
730 class Buffer;
731 class Pipe;
732
733#if defined(CL_HPP_ENABLE_EXCEPTIONS)
738 class Error : public std::exception
739 {
740 private:
741 cl_int err_;
742 const char * errStr_;
743 public:
753 Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr)
754 {}
755
756 ~Error() throw() {}
757
762 virtual const char * what() const throw ()
763 {
764 if (errStr_ == NULL) {
765 return "empty";
766 }
767 else {
768 return errStr_;
769 }
770 }
771
776 cl_int err(void) const { return err_; }
777 };
778#define CL_HPP_ERR_STR_(x) #x
779#else
780#define CL_HPP_ERR_STR_(x) NULL
781#endif // CL_HPP_ENABLE_EXCEPTIONS
782
783
784namespace detail
785{
786#if defined(CL_HPP_ENABLE_EXCEPTIONS)
787static inline cl_int errHandler (
788 cl_int err,
789 const char * errStr = NULL)
790{
791 if (err != CL_SUCCESS) {
792 throw Error(err, errStr);
793 }
794 return err;
795}
796#else
797static inline cl_int errHandler (cl_int err, const char * errStr = NULL)
798{
799 (void) errStr; // suppress unused variable warning
800 return err;
801}
802#endif // CL_HPP_ENABLE_EXCEPTIONS
803}
804
805
806
808#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
809#define __GET_DEVICE_INFO_ERR CL_HPP_ERR_STR_(clGetDeviceInfo)
810#define __GET_PLATFORM_INFO_ERR CL_HPP_ERR_STR_(clGetPlatformInfo)
811#define __GET_DEVICE_IDS_ERR CL_HPP_ERR_STR_(clGetDeviceIDs)
812#define __GET_PLATFORM_IDS_ERR CL_HPP_ERR_STR_(clGetPlatformIDs)
813#define __GET_CONTEXT_INFO_ERR CL_HPP_ERR_STR_(clGetContextInfo)
814#define __GET_EVENT_INFO_ERR CL_HPP_ERR_STR_(clGetEventInfo)
815#define __GET_EVENT_PROFILE_INFO_ERR CL_HPP_ERR_STR_(clGetEventProfileInfo)
816#define __GET_MEM_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetMemObjectInfo)
817#define __GET_IMAGE_INFO_ERR CL_HPP_ERR_STR_(clGetImageInfo)
818#define __GET_SAMPLER_INFO_ERR CL_HPP_ERR_STR_(clGetSamplerInfo)
819#define __GET_KERNEL_INFO_ERR CL_HPP_ERR_STR_(clGetKernelInfo)
820#if CL_HPP_TARGET_OPENCL_VERSION >= 120
821#define __GET_KERNEL_ARG_INFO_ERR CL_HPP_ERR_STR_(clGetKernelArgInfo)
822#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
823#if CL_HPP_TARGET_OPENCL_VERSION >= 200
824#define __GET_KERNEL_SUB_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelSubGroupInfo)
825#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
826#define __GET_KERNEL_WORK_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelWorkGroupInfo)
827#define __GET_PROGRAM_INFO_ERR CL_HPP_ERR_STR_(clGetProgramInfo)
828#define __GET_PROGRAM_BUILD_INFO_ERR CL_HPP_ERR_STR_(clGetProgramBuildInfo)
829#define __GET_COMMAND_QUEUE_INFO_ERR CL_HPP_ERR_STR_(clGetCommandQueueInfo)
830
831#define __CREATE_CONTEXT_ERR CL_HPP_ERR_STR_(clCreateContext)
832#define __CREATE_CONTEXT_FROM_TYPE_ERR CL_HPP_ERR_STR_(clCreateContextFromType)
833#define __GET_SUPPORTED_IMAGE_FORMATS_ERR CL_HPP_ERR_STR_(clGetSupportedImageFormats)
834
835#define __CREATE_BUFFER_ERR CL_HPP_ERR_STR_(clCreateBuffer)
836#define __COPY_ERR CL_HPP_ERR_STR_(cl::copy)
837#define __CREATE_SUBBUFFER_ERR CL_HPP_ERR_STR_(clCreateSubBuffer)
838#define __CREATE_GL_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
839#define __CREATE_GL_RENDER_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
840#define __GET_GL_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetGLObjectInfo)
841#if CL_HPP_TARGET_OPENCL_VERSION >= 120
842#define __CREATE_IMAGE_ERR CL_HPP_ERR_STR_(clCreateImage)
843#define __CREATE_GL_TEXTURE_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture)
844#define __IMAGE_DIMENSION_ERR CL_HPP_ERR_STR_(Incorrect image dimensions)
845#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
846#define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR CL_HPP_ERR_STR_(clSetMemObjectDestructorCallback)
847
848#define __CREATE_USER_EVENT_ERR CL_HPP_ERR_STR_(clCreateUserEvent)
849#define __SET_USER_EVENT_STATUS_ERR CL_HPP_ERR_STR_(clSetUserEventStatus)
850#define __SET_EVENT_CALLBACK_ERR CL_HPP_ERR_STR_(clSetEventCallback)
851#define __WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clWaitForEvents)
852
853#define __CREATE_KERNEL_ERR CL_HPP_ERR_STR_(clCreateKernel)
854#define __SET_KERNEL_ARGS_ERR CL_HPP_ERR_STR_(clSetKernelArg)
855#define __CREATE_PROGRAM_WITH_SOURCE_ERR CL_HPP_ERR_STR_(clCreateProgramWithSource)
856#if CL_HPP_TARGET_OPENCL_VERSION >= 200
857#define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
858#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
859#define __CREATE_PROGRAM_WITH_BINARY_ERR CL_HPP_ERR_STR_(clCreateProgramWithBinary)
860#if CL_HPP_TARGET_OPENCL_VERSION >= 210
861#define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
862#endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
863#if CL_HPP_TARGET_OPENCL_VERSION >= 120
864#define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR CL_HPP_ERR_STR_(clCreateProgramWithBuiltInKernels)
865#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
866#define __BUILD_PROGRAM_ERR CL_HPP_ERR_STR_(clBuildProgram)
867#if CL_HPP_TARGET_OPENCL_VERSION >= 120
868#define __COMPILE_PROGRAM_ERR CL_HPP_ERR_STR_(clCompileProgram)
869#define __LINK_PROGRAM_ERR CL_HPP_ERR_STR_(clLinkProgram)
870#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
871#define __CREATE_KERNELS_IN_PROGRAM_ERR CL_HPP_ERR_STR_(clCreateKernelsInProgram)
872
873#if CL_HPP_TARGET_OPENCL_VERSION >= 200
874#define __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateCommandQueueWithProperties)
875#define __CREATE_SAMPLER_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateSamplerWithProperties)
876#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
877#define __SET_COMMAND_QUEUE_PROPERTY_ERR CL_HPP_ERR_STR_(clSetCommandQueueProperty)
878#define __ENQUEUE_READ_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueReadBuffer)
879#define __ENQUEUE_READ_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueReadBufferRect)
880#define __ENQUEUE_WRITE_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueWriteBuffer)
881#define __ENQUEUE_WRITE_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueWriteBufferRect)
882#define __ENQEUE_COPY_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyBuffer)
883#define __ENQEUE_COPY_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferRect)
884#define __ENQUEUE_FILL_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueFillBuffer)
885#define __ENQUEUE_READ_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueReadImage)
886#define __ENQUEUE_WRITE_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueWriteImage)
887#define __ENQUEUE_COPY_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyImage)
888#define __ENQUEUE_FILL_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueFillImage)
889#define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyImageToBuffer)
890#define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferToImage)
891#define __ENQUEUE_MAP_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueMapBuffer)
892#define __ENQUEUE_MAP_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueMapImage)
893#define __ENQUEUE_UNMAP_MEM_OBJECT_ERR CL_HPP_ERR_STR_(clEnqueueUnMapMemObject)
894#define __ENQUEUE_NDRANGE_KERNEL_ERR CL_HPP_ERR_STR_(clEnqueueNDRangeKernel)
895#define __ENQUEUE_NATIVE_KERNEL CL_HPP_ERR_STR_(clEnqueueNativeKernel)
896#if CL_HPP_TARGET_OPENCL_VERSION >= 120
897#define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR CL_HPP_ERR_STR_(clEnqueueMigrateMemObjects)
898#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
899#if CL_HPP_TARGET_OPENCL_VERSION >= 210
900#define __ENQUEUE_MIGRATE_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMMigrateMem)
901#define __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clSetDefaultDeviceCommandQueue)
902#endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
903
904
905#define __ENQUEUE_ACQUIRE_GL_ERR CL_HPP_ERR_STR_(clEnqueueAcquireGLObjects)
906#define __ENQUEUE_RELEASE_GL_ERR CL_HPP_ERR_STR_(clEnqueueReleaseGLObjects)
907
908#define __CREATE_PIPE_ERR CL_HPP_ERR_STR_(clCreatePipe)
909#define __GET_PIPE_INFO_ERR CL_HPP_ERR_STR_(clGetPipeInfo)
910
911
912#define __RETAIN_ERR CL_HPP_ERR_STR_(Retain Object)
913#define __RELEASE_ERR CL_HPP_ERR_STR_(Release Object)
914#define __FLUSH_ERR CL_HPP_ERR_STR_(clFlush)
915#define __FINISH_ERR CL_HPP_ERR_STR_(clFinish)
916#define __VECTOR_CAPACITY_ERR CL_HPP_ERR_STR_(Vector capacity error)
917
918#if CL_HPP_TARGET_OPENCL_VERSION >= 210
919#define __GET_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetHostTimer)
920#define __GET_DEVICE_AND_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetDeviceAndHostTimer)
921#endif
922#if CL_HPP_TARGET_OPENCL_VERSION >= 220
923#define __SET_PROGRAM_RELEASE_CALLBACK_ERR CL_HPP_ERR_STR_(clSetProgramReleaseCallback)
924#define __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR CL_HPP_ERR_STR_(clSetProgramSpecializationConstant)
925#endif
926
927
931#if CL_HPP_TARGET_OPENCL_VERSION >= 120
932#define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevices)
933#else
934#define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevicesEXT)
935#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
936
940#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
941#define __ENQUEUE_MARKER_ERR CL_HPP_ERR_STR_(clEnqueueMarker)
942#define __ENQUEUE_WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clEnqueueWaitForEvents)
943#define __ENQUEUE_BARRIER_ERR CL_HPP_ERR_STR_(clEnqueueBarrier)
944#define __UNLOAD_COMPILER_ERR CL_HPP_ERR_STR_(clUnloadCompiler)
945#define __CREATE_GL_TEXTURE_2D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture2D)
946#define __CREATE_GL_TEXTURE_3D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture3D)
947#define __CREATE_IMAGE2D_ERR CL_HPP_ERR_STR_(clCreateImage2D)
948#define __CREATE_IMAGE3D_ERR CL_HPP_ERR_STR_(clCreateImage3D)
949#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
950
954#if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
955#define __CREATE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clCreateCommandQueue)
956#define __ENQUEUE_TASK_ERR CL_HPP_ERR_STR_(clEnqueueTask)
957#define __CREATE_SAMPLER_ERR CL_HPP_ERR_STR_(clCreateSampler)
958#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
959
963#if CL_HPP_TARGET_OPENCL_VERSION >= 120
964#define __ENQUEUE_MARKER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueMarkerWithWaitList)
965#define __ENQUEUE_BARRIER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueBarrierWithWaitList)
966#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
967
968#if CL_HPP_TARGET_OPENCL_VERSION >= 210
969#define __CLONE_KERNEL_ERR CL_HPP_ERR_STR_(clCloneKernel)
970#endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
971
972#endif // CL_HPP_USER_OVERRIDE_ERROR_STRINGS
974
975
976namespace detail {
977
978// Generic getInfoHelper. The final parameter is used to guide overload
979// resolution: the actual parameter passed is an int, which makes this
980// a worse conversion sequence than a specialization that declares the
981// parameter as an int.
982template<typename Functor, typename T>
983inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long)
984{
985 return f(name, sizeof(T), param, NULL);
986}
987
988// Specialized for getInfo<CL_PROGRAM_BINARIES>
989// Assumes that the output vector was correctly resized on the way in
990template <typename Func>
991inline cl_int getInfoHelper(Func f, cl_uint name, vector<vector<unsigned char>>* param, int)
992{
993 if (name != CL_PROGRAM_BINARIES) {
994 return CL_INVALID_VALUE;
995 }
996 if (param) {
997 // Create array of pointers, calculate total size and pass pointer array in
998 size_type numBinaries = param->size();
999 vector<unsigned char*> binariesPointers(numBinaries);
1000
1001 for (size_type i = 0; i < numBinaries; ++i)
1002 {
1003 binariesPointers[i] = (*param)[i].data();
1004 }
1005
1006 cl_int err = f(name, numBinaries * sizeof(unsigned char*), binariesPointers.data(), NULL);
1007
1008 if (err != CL_SUCCESS) {
1009 return err;
1010 }
1011 }
1012
1013
1014 return CL_SUCCESS;
1015}
1016
1017// Specialized getInfoHelper for vector params
1018template <typename Func, typename T>
1019inline cl_int getInfoHelper(Func f, cl_uint name, vector<T>* param, long)
1020{
1021 size_type required;
1022 cl_int err = f(name, 0, NULL, &required);
1023 if (err != CL_SUCCESS) {
1024 return err;
1025 }
1026 const size_type elements = required / sizeof(T);
1027
1028 // Temporary to avoid changing param on an error
1029 vector<T> localData(elements);
1030 err = f(name, required, localData.data(), NULL);
1031 if (err != CL_SUCCESS) {
1032 return err;
1033 }
1034 if (param) {
1035 *param = std::move(localData);
1036 }
1037
1038 return CL_SUCCESS;
1039}
1040
1041/* Specialization for reference-counted types. This depends on the
1042 * existence of Wrapper<T>::cl_type, and none of the other types having the
1043 * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1044 * does not work, because when using a derived type (e.g. Context) the generic
1045 * template will provide a better match.
1046 */
1047template <typename Func, typename T>
1048inline cl_int getInfoHelper(
1049 Func f, cl_uint name, vector<T>* param, int, typename T::cl_type = 0)
1050{
1051 size_type required;
1052 cl_int err = f(name, 0, NULL, &required);
1053 if (err != CL_SUCCESS) {
1054 return err;
1055 }
1056
1057 const size_type elements = required / sizeof(typename T::cl_type);
1058
1059 vector<typename T::cl_type> value(elements);
1060 err = f(name, required, value.data(), NULL);
1061 if (err != CL_SUCCESS) {
1062 return err;
1063 }
1064
1065 if (param) {
1066 // Assign to convert CL type to T for each element
1067 param->resize(elements);
1068
1069 // Assign to param, constructing with retain behaviour
1070 // to correctly capture each underlying CL object
1071 for (size_type i = 0; i < elements; i++) {
1072 (*param)[i] = T(value[i], true);
1073 }
1074 }
1075 return CL_SUCCESS;
1076}
1077
1078// Specialized GetInfoHelper for string params
1079template <typename Func>
1080inline cl_int getInfoHelper(Func f, cl_uint name, string* param, long)
1081{
1082 size_type required;
1083 cl_int err = f(name, 0, NULL, &required);
1084 if (err != CL_SUCCESS) {
1085 return err;
1086 }
1087
1088 // std::string has a constant data member
1089 // a char vector does not
1090 if (required > 0) {
1091 vector<char> value(required);
1092 err = f(name, required, value.data(), NULL);
1093 if (err != CL_SUCCESS) {
1094 return err;
1095 }
1096 if (param) {
1097 param->assign(begin(value), prev(end(value)));
1098 }
1099 }
1100 else if (param) {
1101 param->assign("");
1102 }
1103 return CL_SUCCESS;
1104}
1105
1106// Specialized GetInfoHelper for clsize_t params
1107template <typename Func, size_type N>
1108inline cl_int getInfoHelper(Func f, cl_uint name, array<size_type, N>* param, long)
1109{
1110 size_type required;
1111 cl_int err = f(name, 0, NULL, &required);
1112 if (err != CL_SUCCESS) {
1113 return err;
1114 }
1115
1116 size_type elements = required / sizeof(size_type);
1117 vector<size_type> value(elements, 0);
1118
1119 err = f(name, required, value.data(), NULL);
1120 if (err != CL_SUCCESS) {
1121 return err;
1122 }
1123
1124 // Bound the copy with N to prevent overruns
1125 // if passed N > than the amount copied
1126 if (elements > N) {
1127 elements = N;
1128 }
1129 for (size_type i = 0; i < elements; ++i) {
1130 (*param)[i] = value[i];
1131 }
1132
1133 return CL_SUCCESS;
1134}
1135
1136template<typename T> struct ReferenceHandler;
1137
1138/* Specialization for reference-counted types. This depends on the
1139 * existence of Wrapper<T>::cl_type, and none of the other types having the
1140 * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1141 * does not work, because when using a derived type (e.g. Context) the generic
1142 * template will provide a better match.
1143 */
1144template<typename Func, typename T>
1145inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0)
1146{
1147 typename T::cl_type value;
1148 cl_int err = f(name, sizeof(value), &value, NULL);
1149 if (err != CL_SUCCESS) {
1150 return err;
1151 }
1152 *param = value;
1153 if (value != NULL)
1154 {
1155 err = param->retain();
1156 if (err != CL_SUCCESS) {
1157 return err;
1158 }
1159 }
1160 return CL_SUCCESS;
1161}
1162
1163#define CL_HPP_PARAM_NAME_INFO_1_0_(F) \
1164 F(cl_platform_info, CL_PLATFORM_PROFILE, string) \
1165 F(cl_platform_info, CL_PLATFORM_VERSION, string) \
1166 F(cl_platform_info, CL_PLATFORM_NAME, string) \
1167 F(cl_platform_info, CL_PLATFORM_VENDOR, string) \
1168 F(cl_platform_info, CL_PLATFORM_EXTENSIONS, string) \
1169 \
1170 F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
1171 F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
1172 F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
1173 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
1174 F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, size_type) \
1175 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, cl::vector<size_type>) \
1176 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
1177 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
1178 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
1179 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
1180 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
1181 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
1182 F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
1183 F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \
1184 F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
1185 F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
1186 F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
1187 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, size_type) \
1188 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, size_type) \
1189 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, size_type) \
1190 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, size_type) \
1191 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, size_type) \
1192 F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \
1193 F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, size_type) \
1194 F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
1195 F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
1196 F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
1197 F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
1198 F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
1199 F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
1200 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
1201 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
1202 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
1203 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
1204 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
1205 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
1206 F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
1207 F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
1208 F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
1209 F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, size_type) \
1210 F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
1211 F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
1212 F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
1213 F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
1214 F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
1215 F(cl_device_info, CL_DEVICE_NAME, string) \
1216 F(cl_device_info, CL_DEVICE_VENDOR, string) \
1217 F(cl_device_info, CL_DRIVER_VERSION, string) \
1218 F(cl_device_info, CL_DEVICE_PROFILE, string) \
1219 F(cl_device_info, CL_DEVICE_VERSION, string) \
1220 F(cl_device_info, CL_DEVICE_EXTENSIONS, string) \
1221 \
1222 F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
1223 F(cl_context_info, CL_CONTEXT_DEVICES, cl::vector<Device>) \
1224 F(cl_context_info, CL_CONTEXT_PROPERTIES, cl::vector<cl_context_properties>) \
1225 \
1226 F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
1227 F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
1228 F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
1229 F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \
1230 \
1231 F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
1232 F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
1233 F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
1234 F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
1235 \
1236 F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
1237 F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
1238 F(cl_mem_info, CL_MEM_SIZE, size_type) \
1239 F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
1240 F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
1241 F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
1242 F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
1243 \
1244 F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
1245 F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, size_type) \
1246 F(cl_image_info, CL_IMAGE_ROW_PITCH, size_type) \
1247 F(cl_image_info, CL_IMAGE_SLICE_PITCH, size_type) \
1248 F(cl_image_info, CL_IMAGE_WIDTH, size_type) \
1249 F(cl_image_info, CL_IMAGE_HEIGHT, size_type) \
1250 F(cl_image_info, CL_IMAGE_DEPTH, size_type) \
1251 \
1252 F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
1253 F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
1254 F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \
1255 F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \
1256 F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \
1257 \
1258 F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
1259 F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
1260 F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
1261 F(cl_program_info, CL_PROGRAM_DEVICES, cl::vector<Device>) \
1262 F(cl_program_info, CL_PROGRAM_SOURCE, string) \
1263 F(cl_program_info, CL_PROGRAM_BINARY_SIZES, cl::vector<size_type>) \
1264 F(cl_program_info, CL_PROGRAM_BINARIES, cl::vector<cl::vector<unsigned char>>) \
1265 \
1266 F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
1267 F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, string) \
1268 F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, string) \
1269 \
1270 F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, string) \
1271 F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
1272 F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
1273 F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
1274 F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
1275 \
1276 F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, size_type) \
1277 F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::detail::size_t_array) \
1278 F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
1279 \
1280 F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
1281 F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
1282 F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
1283 F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
1284
1285
1286#define CL_HPP_PARAM_NAME_INFO_1_1_(F) \
1287 F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
1288 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
1289 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
1290 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
1291 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
1292 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
1293 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
1294 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
1295 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
1296 F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, string) \
1297 \
1298 F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
1299 F(cl_mem_info, CL_MEM_OFFSET, size_type) \
1300 \
1301 F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1302 F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
1303 \
1304 F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
1305
1306#define CL_HPP_PARAM_NAME_INFO_1_2_(F) \
1307 F(cl_program_info, CL_PROGRAM_NUM_KERNELS, size_type) \
1308 F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, string) \
1309 \
1310 F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \
1311 \
1312 F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, string) \
1313 \
1314 F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \
1315 F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \
1316 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, string) \
1317 F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, string) \
1318 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \
1319 \
1320 F(cl_kernel_work_group_info, CL_KERNEL_GLOBAL_WORK_SIZE, cl::detail::size_t_array) \
1321 \
1322 F(cl_device_info, CL_DEVICE_LINKER_AVAILABLE, cl_bool) \
1323 F(cl_device_info, CL_DEVICE_IMAGE_MAX_BUFFER_SIZE, size_type) \
1324 F(cl_device_info, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, size_type) \
1325 F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl::Device) \
1326 F(cl_device_info, CL_DEVICE_PARTITION_MAX_SUB_DEVICES, cl_uint) \
1327 F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, cl::vector<cl_device_partition_property>) \
1328 F(cl_device_info, CL_DEVICE_PARTITION_TYPE, cl::vector<cl_device_partition_property>) \
1329 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \
1330 F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, cl_bool) \
1331 F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \
1332 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, string) \
1333 F(cl_device_info, CL_DEVICE_PRINTF_BUFFER_SIZE, size_type) \
1334 \
1335 F(cl_image_info, CL_IMAGE_ARRAY_SIZE, size_type) \
1336 F(cl_image_info, CL_IMAGE_NUM_MIP_LEVELS, cl_uint) \
1337 F(cl_image_info, CL_IMAGE_NUM_SAMPLES, cl_uint)
1338
1339#define CL_HPP_PARAM_NAME_INFO_2_0_(F) \
1340 F(cl_device_info, CL_DEVICE_QUEUE_ON_HOST_PROPERTIES, cl_command_queue_properties) \
1341 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES, cl_command_queue_properties) \
1342 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, cl_uint) \
1343 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, cl_uint) \
1344 F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_QUEUES, cl_uint) \
1345 F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_EVENTS, cl_uint) \
1346 F(cl_device_info, CL_DEVICE_MAX_PIPE_ARGS, cl_uint) \
1347 F(cl_device_info, CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS, cl_uint) \
1348 F(cl_device_info, CL_DEVICE_PIPE_MAX_PACKET_SIZE, cl_uint) \
1349 F(cl_device_info, CL_DEVICE_SVM_CAPABILITIES, cl_device_svm_capabilities) \
1350 F(cl_device_info, CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT, cl_uint) \
1351 F(cl_device_info, CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT, cl_uint) \
1352 F(cl_device_info, CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT, cl_uint) \
1353 F(cl_device_info, CL_DEVICE_IMAGE_PITCH_ALIGNMENT, cl_uint) \
1354 F(cl_device_info, CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT, cl_uint) \
1355 F(cl_device_info, CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS, cl_uint ) \
1356 F(cl_device_info, CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE, size_type ) \
1357 F(cl_device_info, CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE, size_type ) \
1358 F(cl_profiling_info, CL_PROFILING_COMMAND_COMPLETE, cl_ulong) \
1359 F(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM, cl_bool) \
1360 F(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_SVM_PTRS, void**) \
1361 F(cl_command_queue_info, CL_QUEUE_SIZE, cl_uint) \
1362 F(cl_mem_info, CL_MEM_USES_SVM_POINTER, cl_bool) \
1363 F(cl_program_build_info, CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, size_type) \
1364 F(cl_pipe_info, CL_PIPE_PACKET_SIZE, cl_uint) \
1365 F(cl_pipe_info, CL_PIPE_MAX_PACKETS, cl_uint)
1366
1367#define CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(F) \
1368 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR, size_type) \
1369 F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR, size_type)
1370
1371#define CL_HPP_PARAM_NAME_INFO_IL_KHR_(F) \
1372 F(cl_device_info, CL_DEVICE_IL_VERSION_KHR, string) \
1373 F(cl_program_info, CL_PROGRAM_IL_KHR, cl::vector<unsigned char>)
1374
1375#define CL_HPP_PARAM_NAME_INFO_2_1_(F) \
1376 F(cl_platform_info, CL_PLATFORM_HOST_TIMER_RESOLUTION, cl_ulong) \
1377 F(cl_program_info, CL_PROGRAM_IL, cl::vector<unsigned char>) \
1378 F(cl_device_info, CL_DEVICE_MAX_NUM_SUB_GROUPS, cl_uint) \
1379 F(cl_device_info, CL_DEVICE_IL_VERSION, string) \
1380 F(cl_device_info, CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS, cl_bool) \
1381 F(cl_command_queue_info, CL_QUEUE_DEVICE_DEFAULT, cl::DeviceCommandQueue) \
1382 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE, size_type) \
1383 F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE, size_type) \
1384 F(cl_kernel_sub_group_info, CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT, cl::detail::size_t_array) \
1385 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_NUM_SUB_GROUPS, size_type) \
1386 F(cl_kernel_sub_group_info, CL_KERNEL_COMPILE_NUM_SUB_GROUPS, size_type)
1387
1388#define CL_HPP_PARAM_NAME_INFO_2_2_(F) \
1389 F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_CTORS_PRESENT, cl_bool) \
1390 F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_DTORS_PRESENT, cl_bool)
1391
1392#define CL_HPP_PARAM_NAME_DEVICE_FISSION_(F) \
1393 F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
1394 F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, cl::vector<cl_device_partition_property_ext>) \
1395 F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, cl::vector<cl_device_partition_property_ext>) \
1396 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
1397 F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, cl::vector<cl_device_partition_property_ext>)
1398
1399#define CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_CL3_SHARED_(F) \
1400 F(cl_platform_info, CL_PLATFORM_NUMERIC_VERSION_KHR, cl_version_khr) \
1401 F(cl_platform_info, CL_PLATFORM_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1402 \
1403 F(cl_device_info, CL_DEVICE_NUMERIC_VERSION_KHR, cl_version_khr) \
1404 F(cl_device_info, CL_DEVICE_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1405 F(cl_device_info, CL_DEVICE_ILS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1406 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>)
1407
1408#define CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_KHRONLY_(F) \
1409 F(cl_device_info, CL_DEVICE_OPENCL_C_NUMERIC_VERSION_KHR, cl_version_khr)
1410
1411#define CL_HPP_PARAM_NAME_INFO_3_0_(F) \
1412 F(cl_platform_info, CL_PLATFORM_NUMERIC_VERSION, cl_version) \
1413 F(cl_platform_info, CL_PLATFORM_EXTENSIONS_WITH_VERSION, cl::vector<cl_name_version>) \
1414 \
1415 F(cl_device_info, CL_DEVICE_NUMERIC_VERSION, cl_version) \
1416 F(cl_device_info, CL_DEVICE_EXTENSIONS_WITH_VERSION, cl::vector<cl_name_version>) \
1417 F(cl_device_info, CL_DEVICE_ILS_WITH_VERSION, cl::vector<cl_name_version>) \
1418 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION, cl::vector<cl_name_version>) \
1419 F(cl_device_info, CL_DEVICE_ATOMIC_MEMORY_CAPABILITIES, cl_device_atomic_capabilities) \
1420 F(cl_device_info, CL_DEVICE_ATOMIC_FENCE_CAPABILITIES, cl_device_atomic_capabilities) \
1421 F(cl_device_info, CL_DEVICE_NON_UNIFORM_WORK_GROUP_SUPPORT, cl_bool) \
1422 F(cl_device_info, CL_DEVICE_OPENCL_C_ALL_VERSIONS, cl::vector<cl_name_version>) \
1423 F(cl_device_info, CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1424 F(cl_device_info, CL_DEVICE_WORK_GROUP_COLLECTIVE_FUNCTIONS_SUPPORT, cl_bool) \
1425 F(cl_device_info, CL_DEVICE_GENERIC_ADDRESS_SPACE_SUPPORT, cl_bool) \
1426 F(cl_device_info, CL_DEVICE_OPENCL_C_FEATURES, cl::vector<cl_name_version>) \
1427 F(cl_device_info, CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES, cl_device_device_enqueue_capabilities) \
1428 F(cl_device_info, CL_DEVICE_PIPE_SUPPORT, cl_bool) \
1429 F(cl_device_info, CL_DEVICE_LATEST_CONFORMANCE_VERSION_PASSED, string) \
1430 \
1431 F(cl_command_queue_info, CL_QUEUE_PROPERTIES_ARRAY, cl::vector<cl_queue_properties>) \
1432 F(cl_mem_info, CL_MEM_PROPERTIES, cl::vector<cl_mem_properties>) \
1433 F(cl_pipe_info, CL_PIPE_PROPERTIES, cl::vector<cl_pipe_properties>) \
1434 F(cl_sampler_info, CL_SAMPLER_PROPERTIES, cl::vector<cl_sampler_properties>)
1435
1436template <typename enum_type, cl_int Name>
1438
1439#define CL_HPP_DECLARE_PARAM_TRAITS_(token, param_name, T) \
1440struct token; \
1441template<> \
1442struct param_traits<detail:: token,param_name> \
1443{ \
1444 enum { value = param_name }; \
1445 typedef T param_type; \
1446};
1447
1448CL_HPP_PARAM_NAME_INFO_1_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1449#if CL_HPP_TARGET_OPENCL_VERSION >= 110
1450CL_HPP_PARAM_NAME_INFO_1_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1451#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
1452#if CL_HPP_TARGET_OPENCL_VERSION >= 120
1453CL_HPP_PARAM_NAME_INFO_1_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1454#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1455#if CL_HPP_TARGET_OPENCL_VERSION >= 200
1456CL_HPP_PARAM_NAME_INFO_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1457#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
1458#if CL_HPP_TARGET_OPENCL_VERSION >= 210
1459CL_HPP_PARAM_NAME_INFO_2_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1460#endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
1461#if CL_HPP_TARGET_OPENCL_VERSION >= 220
1462CL_HPP_PARAM_NAME_INFO_2_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1463#endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
1464#if CL_HPP_TARGET_OPENCL_VERSION >= 300
1465CL_HPP_PARAM_NAME_INFO_3_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1466#endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
1467
1468#if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1469CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1470#endif // #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1471
1472#if defined(CL_HPP_USE_IL_KHR)
1473CL_HPP_PARAM_NAME_INFO_IL_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1474#endif // #if defined(CL_HPP_USE_IL_KHR)
1475
1476
1477// Flags deprecated in OpenCL 2.0
1478#define CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(F) \
1479 F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties)
1480
1481#define CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(F) \
1482 F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool)
1483
1484#define CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(F) \
1485 F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer)
1486
1487// Include deprecated query flags based on versions
1488// Only include deprecated 1.0 flags if 2.0 not active as there is an enum clash
1489#if CL_HPP_TARGET_OPENCL_VERSION > 100 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 && CL_HPP_TARGET_OPENCL_VERSION < 200
1490CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1491#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 110
1492#if CL_HPP_TARGET_OPENCL_VERSION > 110 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1493CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1494#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1495#if CL_HPP_TARGET_OPENCL_VERSION > 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1496CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1497#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
1498
1499#if defined(CL_HPP_USE_CL_DEVICE_FISSION)
1500CL_HPP_PARAM_NAME_DEVICE_FISSION_(CL_HPP_DECLARE_PARAM_TRAITS_);
1501#endif // CL_HPP_USE_CL_DEVICE_FISSION
1502
1503#if defined(cl_khr_extended_versioning)
1504#if CL_HPP_TARGET_OPENCL_VERSION < 300
1505CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_CL3_SHARED_(CL_HPP_DECLARE_PARAM_TRAITS_)
1506#endif // CL_HPP_TARGET_OPENCL_VERSION < 300
1507CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_KHRONLY_(CL_HPP_DECLARE_PARAM_TRAITS_)
1508#endif // cl_khr_extended_versioning
1509
1510#if defined(cl_khr_device_uuid)
1511using uuid_array = array<cl_uchar, CL_UUID_SIZE_KHR>;
1512using luid_array = array<cl_uchar, CL_LUID_SIZE_KHR>;
1513CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_UUID_KHR, uuid_array)
1514CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DRIVER_UUID_KHR, uuid_array)
1515CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LUID_VALID_KHR, cl_bool)
1516CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LUID_KHR, luid_array)
1517CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_NODE_MASK_KHR, cl_uint)
1518#endif
1519
1520#if defined(cl_khr_pci_bus_info)
1521CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PCI_BUS_INFO_KHR, cl_device_pci_bus_info_khr)
1522#endif
1523
1524#if defined(cl_khr_integer_dot_product)
1525CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGER_DOT_PRODUCT_CAPABILITIES_KHR, cl_device_integer_dot_product_capabilities_khr)
1526#endif
1527
1528#ifdef CL_PLATFORM_ICD_SUFFIX_KHR
1529CL_HPP_DECLARE_PARAM_TRAITS_(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, string)
1530#endif
1531
1532#ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
1533CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong)
1534#endif
1535#ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
1536CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, vector<size_type>)
1537#endif
1538#ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
1539CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint)
1540#endif
1541#ifdef CL_DEVICE_SIMD_WIDTH_AMD
1542CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint)
1543#endif
1544#ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD
1545CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint)
1546#endif
1547#ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD
1548CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint)
1549#endif
1550#ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
1551CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint)
1552#endif
1553#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
1554CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint)
1555#endif
1556#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
1557CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint)
1558#endif
1559#ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
1560CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint)
1561#endif
1562#ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
1563CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint)
1564#endif
1565
1566#ifdef CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM
1567CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM, cl_ulong)
1568#endif
1569#ifdef CL_DEVICE_JOB_SLOTS_ARM
1570CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_JOB_SLOTS_ARM, cl_uint)
1571#endif
1572#ifdef CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM
1573CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM, cl_bitfield)
1574#endif
1575#ifdef CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_ARM
1576CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_ARM, cl_uint)
1577#endif
1578#ifdef CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM
1579CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM, cl_int)
1580#endif
1581
1582#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
1583CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint)
1584#endif
1585#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV
1586CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint)
1587#endif
1588#ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV
1589CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint)
1590#endif
1591#ifdef CL_DEVICE_WARP_SIZE_NV
1592CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint)
1593#endif
1594#ifdef CL_DEVICE_GPU_OVERLAP_NV
1595CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool)
1596#endif
1597#ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV
1598CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool)
1599#endif
1600#ifdef CL_DEVICE_INTEGRATED_MEMORY_NV
1601CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool)
1602#endif
1603
1604// Convenience functions
1605
1606template <typename Func, typename T>
1607inline cl_int
1608getInfo(Func f, cl_uint name, T* param)
1609{
1610 return getInfoHelper(f, name, param, 0);
1611}
1612
1613template <typename Func, typename Arg0>
1615{
1616 Func f_; const Arg0& arg0_;
1617 cl_int operator ()(
1618 cl_uint param, size_type size, void* value, size_type* size_ret)
1619 { return f_(arg0_, param, size, value, size_ret); }
1620};
1621
1622template <typename Func, typename Arg0, typename Arg1>
1624{
1625 Func f_; const Arg0& arg0_; const Arg1& arg1_;
1626 cl_int operator ()(
1627 cl_uint param, size_type size, void* value, size_type* size_ret)
1628 { return f_(arg0_, arg1_, param, size, value, size_ret); }
1629};
1630
1631template <typename Func, typename Arg0, typename T>
1632inline cl_int
1633getInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
1634{
1635 GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
1636 return getInfoHelper(f0, name, param, 0);
1637}
1638
1639template <typename Func, typename Arg0, typename Arg1, typename T>
1640inline cl_int
1641getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
1642{
1643 GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
1644 return getInfoHelper(f0, name, param, 0);
1645}
1646
1647
1648template<typename T>
1650{ };
1651
1652#if CL_HPP_TARGET_OPENCL_VERSION >= 120
1656template <>
1657struct ReferenceHandler<cl_device_id>
1658{
1668 static cl_int retain(cl_device_id device)
1669 { return ::clRetainDevice(device); }
1679 static cl_int release(cl_device_id device)
1680 { return ::clReleaseDevice(device); }
1681};
1682#else // CL_HPP_TARGET_OPENCL_VERSION >= 120
1686template <>
1687struct ReferenceHandler<cl_device_id>
1688{
1689 // cl_device_id does not have retain().
1690 static cl_int retain(cl_device_id)
1691 { return CL_SUCCESS; }
1692 // cl_device_id does not have release().
1693 static cl_int release(cl_device_id)
1694 { return CL_SUCCESS; }
1695};
1696#endif // ! (CL_HPP_TARGET_OPENCL_VERSION >= 120)
1697
1698template <>
1699struct ReferenceHandler<cl_platform_id>
1700{
1701 // cl_platform_id does not have retain().
1702 static cl_int retain(cl_platform_id)
1703 { return CL_SUCCESS; }
1704 // cl_platform_id does not have release().
1705 static cl_int release(cl_platform_id)
1706 { return CL_SUCCESS; }
1707};
1708
1709template <>
1710struct ReferenceHandler<cl_context>
1711{
1712 static cl_int retain(cl_context context)
1713 { return ::clRetainContext(context); }
1714 static cl_int release(cl_context context)
1715 { return ::clReleaseContext(context); }
1716};
1717
1718template <>
1719struct ReferenceHandler<cl_command_queue>
1720{
1721 static cl_int retain(cl_command_queue queue)
1722 { return ::clRetainCommandQueue(queue); }
1723 static cl_int release(cl_command_queue queue)
1724 { return ::clReleaseCommandQueue(queue); }
1725};
1726
1727template <>
1728struct ReferenceHandler<cl_mem>
1729{
1730 static cl_int retain(cl_mem memory)
1731 { return ::clRetainMemObject(memory); }
1732 static cl_int release(cl_mem memory)
1733 { return ::clReleaseMemObject(memory); }
1734};
1735
1736template <>
1737struct ReferenceHandler<cl_sampler>
1738{
1739 static cl_int retain(cl_sampler sampler)
1740 { return ::clRetainSampler(sampler); }
1741 static cl_int release(cl_sampler sampler)
1742 { return ::clReleaseSampler(sampler); }
1743};
1744
1745template <>
1746struct ReferenceHandler<cl_program>
1747{
1748 static cl_int retain(cl_program program)
1749 { return ::clRetainProgram(program); }
1750 static cl_int release(cl_program program)
1751 { return ::clReleaseProgram(program); }
1752};
1753
1754template <>
1755struct ReferenceHandler<cl_kernel>
1756{
1757 static cl_int retain(cl_kernel kernel)
1758 { return ::clRetainKernel(kernel); }
1759 static cl_int release(cl_kernel kernel)
1760 { return ::clReleaseKernel(kernel); }
1761};
1762
1763template <>
1764struct ReferenceHandler<cl_event>
1765{
1766 static cl_int retain(cl_event event)
1767 { return ::clRetainEvent(event); }
1768 static cl_int release(cl_event event)
1769 { return ::clReleaseEvent(event); }
1770};
1771
1772
1773#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1774// Extracts version number with major in the upper 16 bits, minor in the lower 16
1775static cl_uint getVersion(const vector<char> &versionInfo)
1776{
1777 int highVersion = 0;
1778 int lowVersion = 0;
1779 int index = 7;
1780 while(versionInfo[index] != '.' ) {
1781 highVersion *= 10;
1782 highVersion += versionInfo[index]-'0';
1783 ++index;
1784 }
1785 ++index;
1786 while(versionInfo[index] != ' ' && versionInfo[index] != '\0') {
1787 lowVersion *= 10;
1788 lowVersion += versionInfo[index]-'0';
1789 ++index;
1790 }
1791 return (highVersion << 16) | lowVersion;
1792}
1793
1794static cl_uint getPlatformVersion(cl_platform_id platform)
1795{
1796 size_type size = 0;
1797 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size);
1798
1799 vector<char> versionInfo(size);
1800 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, versionInfo.data(), &size);
1801 return getVersion(versionInfo);
1802}
1803
1804static cl_uint getDevicePlatformVersion(cl_device_id device)
1805{
1806 cl_platform_id platform;
1807 clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL);
1808 return getPlatformVersion(platform);
1809}
1810
1811static cl_uint getContextPlatformVersion(cl_context context)
1812{
1813 // The platform cannot be queried directly, so we first have to grab a
1814 // device and obtain its context
1815 size_type size = 0;
1816 clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size);
1817 if (size == 0)
1818 return 0;
1819 vector<cl_device_id> devices(size/sizeof(cl_device_id));
1820 clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices.data(), NULL);
1821 return getDevicePlatformVersion(devices[0]);
1822}
1823#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1824
1825template <typename T>
1827{
1828public:
1829 typedef T cl_type;
1830
1831protected:
1832 cl_type object_;
1833
1834public:
1835 Wrapper() : object_(NULL) { }
1836
1837 Wrapper(const cl_type &obj, bool retainObject) : object_(obj)
1838 {
1839 if (retainObject) {
1840 detail::errHandler(retain(), __RETAIN_ERR);
1841 }
1842 }
1843
1844 ~Wrapper()
1845 {
1846 if (object_ != NULL) { release(); }
1847 }
1848
1849 Wrapper(const Wrapper<cl_type>& rhs)
1850 {
1851 object_ = rhs.object_;
1852 detail::errHandler(retain(), __RETAIN_ERR);
1853 }
1854
1855 Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT_
1856 {
1857 object_ = rhs.object_;
1858 rhs.object_ = NULL;
1859 }
1860
1861 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
1862 {
1863 if (this != &rhs) {
1864 detail::errHandler(release(), __RELEASE_ERR);
1865 object_ = rhs.object_;
1866 detail::errHandler(retain(), __RETAIN_ERR);
1867 }
1868 return *this;
1869 }
1870
1871 Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
1872 {
1873 if (this != &rhs) {
1874 detail::errHandler(release(), __RELEASE_ERR);
1875 object_ = rhs.object_;
1876 rhs.object_ = NULL;
1877 }
1878 return *this;
1879 }
1880
1881 Wrapper<cl_type>& operator = (const cl_type &rhs)
1882 {
1883 detail::errHandler(release(), __RELEASE_ERR);
1884 object_ = rhs;
1885 return *this;
1886 }
1887
1888 const cl_type& operator ()() const { return object_; }
1889
1890 cl_type& operator ()() { return object_; }
1891
1892 cl_type get() const { return object_; }
1893
1894protected:
1895 template<typename Func, typename U>
1896 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
1897
1898 cl_int retain() const
1899 {
1900 if (object_ != nullptr) {
1901 return ReferenceHandler<cl_type>::retain(object_);
1902 }
1903 else {
1904 return CL_SUCCESS;
1905 }
1906 }
1907
1908 cl_int release() const
1909 {
1910 if (object_ != nullptr) {
1911 return ReferenceHandler<cl_type>::release(object_);
1912 }
1913 else {
1914 return CL_SUCCESS;
1915 }
1916 }
1917};
1918
1919template <>
1920class Wrapper<cl_device_id>
1921{
1922public:
1923 typedef cl_device_id cl_type;
1924
1925protected:
1926 cl_type object_;
1927 bool referenceCountable_;
1928
1929 static bool isReferenceCountable(cl_device_id device)
1930 {
1931 bool retVal = false;
1932#if CL_HPP_TARGET_OPENCL_VERSION >= 120
1933#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
1934 if (device != NULL) {
1935 int version = getDevicePlatformVersion(device);
1936 if(version > ((1 << 16) + 1)) {
1937 retVal = true;
1938 }
1939 }
1940#else // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1941 retVal = true;
1942#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1943#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1944 return retVal;
1945 }
1946
1947public:
1948 Wrapper() : object_(NULL), referenceCountable_(false)
1949 {
1950 }
1951
1952 Wrapper(const cl_type &obj, bool retainObject) :
1953 object_(obj),
1954 referenceCountable_(false)
1955 {
1956 referenceCountable_ = isReferenceCountable(obj);
1957
1958 if (retainObject) {
1959 detail::errHandler(retain(), __RETAIN_ERR);
1960 }
1961 }
1962
1963 ~Wrapper()
1964 {
1965 release();
1966 }
1967
1968 Wrapper(const Wrapper<cl_type>& rhs)
1969 {
1970 object_ = rhs.object_;
1971 referenceCountable_ = isReferenceCountable(object_);
1972 detail::errHandler(retain(), __RETAIN_ERR);
1973 }
1974
1975 Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT_
1976 {
1977 object_ = rhs.object_;
1978 referenceCountable_ = rhs.referenceCountable_;
1979 rhs.object_ = NULL;
1980 rhs.referenceCountable_ = false;
1981 }
1982
1983 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
1984 {
1985 if (this != &rhs) {
1986 detail::errHandler(release(), __RELEASE_ERR);
1987 object_ = rhs.object_;
1988 referenceCountable_ = rhs.referenceCountable_;
1989 detail::errHandler(retain(), __RETAIN_ERR);
1990 }
1991 return *this;
1992 }
1993
1994 Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
1995 {
1996 if (this != &rhs) {
1997 detail::errHandler(release(), __RELEASE_ERR);
1998 object_ = rhs.object_;
1999 referenceCountable_ = rhs.referenceCountable_;
2000 rhs.object_ = NULL;
2001 rhs.referenceCountable_ = false;
2002 }
2003 return *this;
2004 }
2005
2006 Wrapper<cl_type>& operator = (const cl_type &rhs)
2007 {
2008 detail::errHandler(release(), __RELEASE_ERR);
2009 object_ = rhs;
2010 referenceCountable_ = isReferenceCountable(object_);
2011 return *this;
2012 }
2013
2014 const cl_type& operator ()() const { return object_; }
2015
2016 cl_type& operator ()() { return object_; }
2017
2018 cl_type get() const { return object_; }
2019
2020protected:
2021 template<typename Func, typename U>
2022 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
2023
2024 template<typename Func, typename U>
2025 friend inline cl_int getInfoHelper(Func, cl_uint, vector<U>*, int, typename U::cl_type);
2026
2027 cl_int retain() const
2028 {
2029 if( object_ != nullptr && referenceCountable_ ) {
2030 return ReferenceHandler<cl_type>::retain(object_);
2031 }
2032 else {
2033 return CL_SUCCESS;
2034 }
2035 }
2036
2037 cl_int release() const
2038 {
2039 if (object_ != nullptr && referenceCountable_) {
2040 return ReferenceHandler<cl_type>::release(object_);
2041 }
2042 else {
2043 return CL_SUCCESS;
2044 }
2045 }
2046};
2047
2048template <typename T>
2049inline bool operator==(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
2050{
2051 return lhs() == rhs();
2052}
2053
2054template <typename T>
2055inline bool operator!=(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
2056{
2057 return !operator==(lhs, rhs);
2058}
2059
2060} // namespace detail
2062
2063
2064using BuildLogType = vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, CL_PROGRAM_BUILD_LOG>::param_type>>;
2065#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2069class BuildError : public Error
2070{
2071private:
2072 BuildLogType buildLogs;
2073public:
2074 BuildError(cl_int err, const char * errStr, const BuildLogType &vec) : Error(err, errStr), buildLogs(vec)
2075 {
2076 }
2077
2078 BuildLogType getBuildLog() const
2079 {
2080 return buildLogs;
2081 }
2082};
2083namespace detail {
2084 static inline cl_int buildErrHandler(
2085 cl_int err,
2086 const char * errStr,
2087 const BuildLogType &buildLogs)
2088 {
2089 if (err != CL_SUCCESS) {
2090 throw BuildError(err, errStr, buildLogs);
2091 }
2092 return err;
2093 }
2094} // namespace detail
2095
2096#else
2097namespace detail {
2098 static inline cl_int buildErrHandler(
2099 cl_int err,
2100 const char * errStr,
2101 const BuildLogType &buildLogs)
2102 {
2103 (void)buildLogs; // suppress unused variable warning
2104 (void)errStr;
2105 return err;
2106 }
2107} // namespace detail
2108#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2109
2110
2116struct ImageFormat : public cl_image_format
2117{
2120
2122 ImageFormat(cl_channel_order order, cl_channel_type type)
2123 {
2124 image_channel_order = order;
2125 image_channel_data_type = type;
2126 }
2127
2129 ImageFormat(const ImageFormat &other) { *this = other; }
2130
2133 {
2134 if (this != &rhs) {
2135 this->image_channel_data_type = rhs.image_channel_data_type;
2136 this->image_channel_order = rhs.image_channel_order;
2137 }
2138 return *this;
2139 }
2140};
2141
2149class Device : public detail::Wrapper<cl_device_id>
2150{
2151private:
2152 static std::once_flag default_initialized_;
2153 static Device default_;
2154 static cl_int default_error_;
2155
2161 static void makeDefault();
2162
2168 static void makeDefaultProvided(const Device &p) {
2169 default_ = p;
2170 }
2171
2172public:
2173#ifdef CL_HPP_UNIT_TEST_ENABLE
2180 static void unitTestClearDefault() {
2181 default_ = Device();
2182 }
2183#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2184
2186 Device() : detail::Wrapper<cl_type>() { }
2187
2192 explicit Device(const cl_device_id &device, bool retainObject = false) :
2193 detail::Wrapper<cl_type>(device, retainObject) { }
2194
2200 cl_int *errResult = NULL)
2201 {
2202 std::call_once(default_initialized_, makeDefault);
2203 detail::errHandler(default_error_);
2204 if (errResult != NULL) {
2205 *errResult = default_error_;
2206 }
2207 return default_;
2208 }
2209
2217 static Device setDefault(const Device &default_device)
2218 {
2219 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_device));
2220 detail::errHandler(default_error_);
2221 return default_;
2222 }
2223
2228 Device& operator = (const cl_device_id& rhs)
2229 {
2231 return *this;
2232 }
2233
2237 Device(const Device& dev) : detail::Wrapper<cl_type>(dev) {}
2238
2243 {
2245 return *this;
2246 }
2247
2251 Device(Device&& dev) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(dev)) {}
2252
2257 {
2259 return *this;
2260 }
2261
2263 template <typename T>
2264 cl_int getInfo(cl_device_info name, T* param) const
2265 {
2266 return detail::errHandler(
2267 detail::getInfo(&::clGetDeviceInfo, object_, name, param),
2268 __GET_DEVICE_INFO_ERR);
2269 }
2270
2272 template <cl_device_info name> typename
2274 getInfo(cl_int* err = NULL) const
2275 {
2276 typename detail::param_traits<
2277 detail::cl_device_info, name>::param_type param;
2278 cl_int result = getInfo(name, &param);
2279 if (err != NULL) {
2280 *err = result;
2281 }
2282 return param;
2283 }
2284
2285
2286#if CL_HPP_TARGET_OPENCL_VERSION >= 210
2293 cl_ulong getHostTimer(cl_int *error = nullptr)
2294 {
2295 cl_ulong retVal = 0;
2296 cl_int err =
2297 clGetHostTimer(this->get(), &retVal);
2298 detail::errHandler(
2299 err,
2300 __GET_HOST_TIMER_ERR);
2301 if (error) {
2302 *error = err;
2303 }
2304 return retVal;
2305 }
2306
2317 std::pair<cl_ulong, cl_ulong> getDeviceAndHostTimer(cl_int *error = nullptr)
2318 {
2319 std::pair<cl_ulong, cl_ulong> retVal;
2320 cl_int err =
2321 clGetDeviceAndHostTimer(this->get(), &(retVal.first), &(retVal.second));
2322 detail::errHandler(
2323 err,
2324 __GET_DEVICE_AND_HOST_TIMER_ERR);
2325 if (error) {
2326 *error = err;
2327 }
2328 return retVal;
2329 }
2330#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2331
2335#if CL_HPP_TARGET_OPENCL_VERSION >= 120
2338 const cl_device_partition_property * properties,
2339 vector<Device>* devices)
2340 {
2341 cl_uint n = 0;
2342 cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n);
2343 if (err != CL_SUCCESS) {
2344 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2345 }
2346
2347 vector<cl_device_id> ids(n);
2348 err = clCreateSubDevices(object_, properties, n, ids.data(), NULL);
2349 if (err != CL_SUCCESS) {
2350 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2351 }
2352
2353 // Cannot trivially assign because we need to capture intermediates
2354 // with safe construction
2355 if (devices) {
2356 devices->resize(ids.size());
2357
2358 // Assign to param, constructing with retain behaviour
2359 // to correctly capture each underlying CL object
2360 for (size_type i = 0; i < ids.size(); i++) {
2361 // We do not need to retain because this device is being created
2362 // by the runtime
2363 (*devices)[i] = Device(ids[i], false);
2364 }
2365 }
2366
2367 return CL_SUCCESS;
2368 }
2369#elif defined(CL_HPP_USE_CL_DEVICE_FISSION)
2370
2374 cl_int createSubDevices(
2375 const cl_device_partition_property_ext * properties,
2376 vector<Device>* devices)
2377 {
2378 typedef CL_API_ENTRY cl_int
2379 ( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
2380 cl_device_id /*in_device*/,
2381 const cl_device_partition_property_ext * /* properties */,
2382 cl_uint /*num_entries*/,
2383 cl_device_id * /*out_devices*/,
2384 cl_uint * /*num_devices*/ ) CL_API_SUFFIX__VERSION_1_1;
2385
2386 static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
2387 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSubDevicesEXT);
2388
2389 cl_uint n = 0;
2390 cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
2391 if (err != CL_SUCCESS) {
2392 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2393 }
2394
2395 vector<cl_device_id> ids(n);
2396 err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids.data(), NULL);
2397 if (err != CL_SUCCESS) {
2398 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2399 }
2400 // Cannot trivially assign because we need to capture intermediates
2401 // with safe construction
2402 if (devices) {
2403 devices->resize(ids.size());
2404
2405 // Assign to param, constructing with retain behaviour
2406 // to correctly capture each underlying CL object
2407 for (size_type i = 0; i < ids.size(); i++) {
2408 // We do not need to retain because this device is being created
2409 // by the runtime
2410 (*devices)[i] = Device(ids[i], false);
2411 }
2412 }
2413 return CL_SUCCESS;
2414 }
2415#endif // defined(CL_HPP_USE_CL_DEVICE_FISSION)
2416};
2417
2418CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Device::default_initialized_;
2419CL_HPP_DEFINE_STATIC_MEMBER_ Device Device::default_;
2420CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Device::default_error_ = CL_SUCCESS;
2421
2429class Platform : public detail::Wrapper<cl_platform_id>
2430{
2431private:
2432 static std::once_flag default_initialized_;
2433 static Platform default_;
2434 static cl_int default_error_;
2435
2441 static void makeDefault() {
2442 /* Throwing an exception from a call_once invocation does not do
2443 * what we wish, so we catch it and save the error.
2444 */
2445#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2446 try
2447#endif
2448 {
2449 // If default wasn't passed ,generate one
2450 // Otherwise set it
2451 cl_uint n = 0;
2452
2453 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2454 if (err != CL_SUCCESS) {
2455 default_error_ = err;
2456 return;
2457 }
2458 if (n == 0) {
2459 default_error_ = CL_INVALID_PLATFORM;
2460 return;
2461 }
2462
2463 vector<cl_platform_id> ids(n);
2464 err = ::clGetPlatformIDs(n, ids.data(), NULL);
2465 if (err != CL_SUCCESS) {
2466 default_error_ = err;
2467 return;
2468 }
2469
2470 default_ = Platform(ids[0]);
2471 }
2472#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2473 catch (cl::Error &e) {
2474 default_error_ = e.err();
2475 }
2476#endif
2477 }
2478
2484 static void makeDefaultProvided(const Platform &p) {
2485 default_ = p;
2486 }
2487
2488public:
2489#ifdef CL_HPP_UNIT_TEST_ENABLE
2496 static void unitTestClearDefault() {
2497 default_ = Platform();
2498 }
2499#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2500
2502 Platform() : detail::Wrapper<cl_type>() { }
2503
2511 explicit Platform(const cl_platform_id &platform, bool retainObject = false) :
2512 detail::Wrapper<cl_type>(platform, retainObject) { }
2513
2518 Platform& operator = (const cl_platform_id& rhs)
2519 {
2521 return *this;
2522 }
2523
2524 static Platform getDefault(
2525 cl_int *errResult = NULL)
2526 {
2527 std::call_once(default_initialized_, makeDefault);
2528 detail::errHandler(default_error_);
2529 if (errResult != NULL) {
2530 *errResult = default_error_;
2531 }
2532 return default_;
2533 }
2534
2542 static Platform setDefault(const Platform &default_platform)
2543 {
2544 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_platform));
2545 detail::errHandler(default_error_);
2546 return default_;
2547 }
2548
2550 template <typename T>
2551 cl_int getInfo(cl_platform_info name, T* param) const
2552 {
2553 return detail::errHandler(
2554 detail::getInfo(&::clGetPlatformInfo, object_, name, param),
2555 __GET_PLATFORM_INFO_ERR);
2556 }
2557
2559 template <cl_platform_info name> typename
2561 getInfo(cl_int* err = NULL) const
2562 {
2563 typename detail::param_traits<
2564 detail::cl_platform_info, name>::param_type param;
2565 cl_int result = getInfo(name, &param);
2566 if (err != NULL) {
2567 *err = result;
2568 }
2569 return param;
2570 }
2571
2577 cl_device_type type,
2578 vector<Device>* devices) const
2579 {
2580 cl_uint n = 0;
2581 if( devices == NULL ) {
2582 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2583 }
2584 cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
2585 if (err != CL_SUCCESS && err != CL_DEVICE_NOT_FOUND) {
2586 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2587 }
2588
2589 vector<cl_device_id> ids(n);
2590 if (n>0) {
2591 err = ::clGetDeviceIDs(object_, type, n, ids.data(), NULL);
2592 if (err != CL_SUCCESS) {
2593 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2594 }
2595 }
2596
2597 // Cannot trivially assign because we need to capture intermediates
2598 // with safe construction
2599 // We must retain things we obtain from the API to avoid releasing
2600 // API-owned objects.
2601 if (devices) {
2602 devices->resize(ids.size());
2603
2604 // Assign to param, constructing with retain behaviour
2605 // to correctly capture each underlying CL object
2606 for (size_type i = 0; i < ids.size(); i++) {
2607 (*devices)[i] = Device(ids[i], true);
2608 }
2609 }
2610 return CL_SUCCESS;
2611 }
2612
2613#if defined(CL_HPP_USE_DX_INTEROP)
2637 cl_int getDevices(
2638 cl_d3d10_device_source_khr d3d_device_source,
2639 void * d3d_object,
2640 cl_d3d10_device_set_khr d3d_device_set,
2641 vector<Device>* devices) const
2642 {
2643 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
2644 cl_platform_id platform,
2645 cl_d3d10_device_source_khr d3d_device_source,
2646 void * d3d_object,
2647 cl_d3d10_device_set_khr d3d_device_set,
2648 cl_uint num_entries,
2649 cl_device_id * devices,
2650 cl_uint* num_devices);
2651
2652 if( devices == NULL ) {
2653 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2654 }
2655
2656 static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
2657 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(object_, clGetDeviceIDsFromD3D10KHR);
2658
2659 cl_uint n = 0;
2660 cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
2661 object_,
2662 d3d_device_source,
2663 d3d_object,
2664 d3d_device_set,
2665 0,
2666 NULL,
2667 &n);
2668 if (err != CL_SUCCESS) {
2669 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2670 }
2671
2672 vector<cl_device_id> ids(n);
2673 err = pfn_clGetDeviceIDsFromD3D10KHR(
2674 object_,
2675 d3d_device_source,
2676 d3d_object,
2677 d3d_device_set,
2678 n,
2679 ids.data(),
2680 NULL);
2681 if (err != CL_SUCCESS) {
2682 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2683 }
2684
2685 // Cannot trivially assign because we need to capture intermediates
2686 // with safe construction
2687 // We must retain things we obtain from the API to avoid releasing
2688 // API-owned objects.
2689 if (devices) {
2690 devices->resize(ids.size());
2691
2692 // Assign to param, constructing with retain behaviour
2693 // to correctly capture each underlying CL object
2694 for (size_type i = 0; i < ids.size(); i++) {
2695 (*devices)[i] = Device(ids[i], true);
2696 }
2697 }
2698 return CL_SUCCESS;
2699 }
2700#endif
2701
2706 static cl_int get(
2707 vector<Platform>* platforms)
2708 {
2709 cl_uint n = 0;
2710
2711 if( platforms == NULL ) {
2712 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
2713 }
2714
2715 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2716 if (err != CL_SUCCESS) {
2717 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2718 }
2719
2720 vector<cl_platform_id> ids(n);
2721 err = ::clGetPlatformIDs(n, ids.data(), NULL);
2722 if (err != CL_SUCCESS) {
2723 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2724 }
2725
2726 if (platforms) {
2727 platforms->resize(ids.size());
2728
2729 // Platforms don't reference count
2730 for (size_type i = 0; i < ids.size(); i++) {
2731 (*platforms)[i] = Platform(ids[i]);
2732 }
2733 }
2734 return CL_SUCCESS;
2735 }
2736
2741 static cl_int get(
2742 Platform * platform)
2743 {
2744 cl_int err;
2745 Platform default_platform = Platform::getDefault(&err);
2746 if (platform) {
2747 *platform = default_platform;
2748 }
2749 return err;
2750 }
2751
2761 cl_int * errResult = NULL)
2762 {
2763 cl_int err;
2764 Platform default_platform = Platform::getDefault(&err);
2765 if (errResult) {
2766 *errResult = err;
2767 }
2768 return default_platform;
2769 }
2770
2771#if CL_HPP_TARGET_OPENCL_VERSION >= 120
2773 cl_int
2775 {
2776 return ::clUnloadPlatformCompiler(object_);
2777 }
2778#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
2779}; // class Platform
2780
2781CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Platform::default_initialized_;
2782CL_HPP_DEFINE_STATIC_MEMBER_ Platform Platform::default_;
2783CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Platform::default_error_ = CL_SUCCESS;
2784
2785
2789#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2794inline CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int
2795UnloadCompiler() CL_API_SUFFIX__VERSION_1_1_DEPRECATED;
2796inline cl_int
2798{
2799 return ::clUnloadCompiler();
2800}
2801#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2802
2812 : public detail::Wrapper<cl_context>
2813{
2814private:
2815 static std::once_flag default_initialized_;
2816 static Context default_;
2817 static cl_int default_error_;
2818
2824 static void makeDefault() {
2825 /* Throwing an exception from a call_once invocation does not do
2826 * what we wish, so we catch it and save the error.
2827 */
2828#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2829 try
2830#endif
2831 {
2832#if !defined(__APPLE__) && !defined(__MACOS)
2833 const Platform &p = Platform::getDefault();
2834 cl_platform_id defaultPlatform = p();
2835 cl_context_properties properties[3] = {
2836 CL_CONTEXT_PLATFORM, (cl_context_properties)defaultPlatform, 0
2837 };
2838#else // #if !defined(__APPLE__) && !defined(__MACOS)
2839 cl_context_properties *properties = nullptr;
2840#endif // #if !defined(__APPLE__) && !defined(__MACOS)
2841
2842 default_ = Context(
2843 CL_DEVICE_TYPE_DEFAULT,
2844 properties,
2845 NULL,
2846 NULL,
2847 &default_error_);
2848 }
2849#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2850 catch (cl::Error &e) {
2851 default_error_ = e.err();
2852 }
2853#endif
2854 }
2855
2856
2862 static void makeDefaultProvided(const Context &c) {
2863 default_ = c;
2864 }
2865
2866public:
2867#ifdef CL_HPP_UNIT_TEST_ENABLE
2874 static void unitTestClearDefault() {
2875 default_ = Context();
2876 }
2877#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2878
2884 const vector<Device>& devices,
2885 const cl_context_properties* properties = NULL,
2886 void (CL_CALLBACK * notifyFptr)(
2887 const char *,
2888 const void *,
2889 size_type,
2890 void *) = NULL,
2891 void* data = NULL,
2892 cl_int* err = NULL)
2893 {
2894 cl_int error;
2895
2896 size_type numDevices = devices.size();
2897 vector<cl_device_id> deviceIDs(numDevices);
2898
2899 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
2900 deviceIDs[deviceIndex] = (devices[deviceIndex])();
2901 }
2902
2903 object_ = ::clCreateContext(
2904 properties, (cl_uint) numDevices,
2905 deviceIDs.data(),
2906 notifyFptr, data, &error);
2907
2908 detail::errHandler(error, __CREATE_CONTEXT_ERR);
2909 if (err != NULL) {
2910 *err = error;
2911 }
2912 }
2913
2919 const Device& device,
2920 const cl_context_properties* properties = NULL,
2921 void (CL_CALLBACK * notifyFptr)(
2922 const char *,
2923 const void *,
2924 size_type,
2925 void *) = NULL,
2926 void* data = NULL,
2927 cl_int* err = NULL)
2928 {
2929 cl_int error;
2930
2931 cl_device_id deviceID = device();
2932
2933 object_ = ::clCreateContext(
2934 properties, 1,
2935 &deviceID,
2936 notifyFptr, data, &error);
2937
2938 detail::errHandler(error, __CREATE_CONTEXT_ERR);
2939 if (err != NULL) {
2940 *err = error;
2941 }
2942 }
2943
2949 cl_device_type type,
2950 const cl_context_properties* properties = NULL,
2951 void (CL_CALLBACK * notifyFptr)(
2952 const char *,
2953 const void *,
2954 size_type,
2955 void *) = NULL,
2956 void* data = NULL,
2957 cl_int* err = NULL)
2958 {
2959 cl_int error;
2960
2961#if !defined(__APPLE__) && !defined(__MACOS)
2962 cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 };
2963
2964 if (properties == NULL) {
2965 // Get a valid platform ID as we cannot send in a blank one
2966 vector<Platform> platforms;
2967 error = Platform::get(&platforms);
2968 if (error != CL_SUCCESS) {
2969 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2970 if (err != NULL) {
2971 *err = error;
2972 }
2973 return;
2974 }
2975
2976 // Check the platforms we found for a device of our specified type
2977 cl_context_properties platform_id = 0;
2978 for (unsigned int i = 0; i < platforms.size(); i++) {
2979
2980 vector<Device> devices;
2981
2982#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2983 try {
2984#endif
2985
2986 error = platforms[i].getDevices(type, &devices);
2987
2988#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2989 } catch (cl::Error& e) {
2990 error = e.err();
2991 }
2992 // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type
2993 // We do error checking next anyway, and can throw there if needed
2994#endif
2995
2996 // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND
2997 if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) {
2998 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2999 if (err != NULL) {
3000 *err = error;
3001 }
3002 }
3003
3004 if (devices.size() > 0) {
3005 platform_id = (cl_context_properties)platforms[i]();
3006 break;
3007 }
3008 }
3009
3010 if (platform_id == 0) {
3011 detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR);
3012 if (err != NULL) {
3013 *err = CL_DEVICE_NOT_FOUND;
3014 }
3015 return;
3016 }
3017
3018 prop[1] = platform_id;
3019 properties = &prop[0];
3020 }
3021#endif
3022 object_ = ::clCreateContextFromType(
3023 properties, type, notifyFptr, data, &error);
3024
3025 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
3026 if (err != NULL) {
3027 *err = error;
3028 }
3029 }
3030
3034 Context(const Context& ctx) : detail::Wrapper<cl_type>(ctx) {}
3035
3040 {
3042 return *this;
3043 }
3044
3048 Context(Context&& ctx) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(ctx)) {}
3049
3054 {
3056 return *this;
3057 }
3058
3059
3064 static Context getDefault(cl_int * err = NULL)
3065 {
3066 std::call_once(default_initialized_, makeDefault);
3067 detail::errHandler(default_error_);
3068 if (err != NULL) {
3069 *err = default_error_;
3070 }
3071 return default_;
3072 }
3073
3081 static Context setDefault(const Context &default_context)
3082 {
3083 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_context));
3084 detail::errHandler(default_error_);
3085 return default_;
3086 }
3087
3089 Context() : detail::Wrapper<cl_type>() { }
3090
3096 explicit Context(const cl_context& context, bool retainObject = false) :
3097 detail::Wrapper<cl_type>(context, retainObject) { }
3098
3104 Context& operator = (const cl_context& rhs)
3105 {
3107 return *this;
3108 }
3109
3111 template <typename T>
3112 cl_int getInfo(cl_context_info name, T* param) const
3113 {
3114 return detail::errHandler(
3115 detail::getInfo(&::clGetContextInfo, object_, name, param),
3116 __GET_CONTEXT_INFO_ERR);
3117 }
3118
3120 template <cl_context_info name> typename
3122 getInfo(cl_int* err = NULL) const
3123 {
3124 typename detail::param_traits<
3125 detail::cl_context_info, name>::param_type param;
3126 cl_int result = getInfo(name, &param);
3127 if (err != NULL) {
3128 *err = result;
3129 }
3130 return param;
3131 }
3132
3138 cl_mem_flags flags,
3139 cl_mem_object_type type,
3140 vector<ImageFormat>* formats) const
3141 {
3142 cl_uint numEntries;
3143
3144 if (!formats) {
3145 return CL_SUCCESS;
3146 }
3147
3148 cl_int err = ::clGetSupportedImageFormats(
3149 object_,
3150 flags,
3151 type,
3152 0,
3153 NULL,
3154 &numEntries);
3155 if (err != CL_SUCCESS) {
3156 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3157 }
3158
3159 if (numEntries > 0) {
3160 vector<ImageFormat> value(numEntries);
3161 err = ::clGetSupportedImageFormats(
3162 object_,
3163 flags,
3164 type,
3165 numEntries,
3166 (cl_image_format*)value.data(),
3167 NULL);
3168 if (err != CL_SUCCESS) {
3169 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3170 }
3171
3172 formats->assign(begin(value), end(value));
3173 }
3174 else {
3175 // If no values are being returned, ensure an empty vector comes back
3176 formats->clear();
3177 }
3178
3179 return CL_SUCCESS;
3180 }
3181};
3182
3183inline void Device::makeDefault()
3184{
3185 /* Throwing an exception from a call_once invocation does not do
3186 * what we wish, so we catch it and save the error.
3187 */
3188#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3189 try
3190#endif
3191 {
3192 cl_int error = 0;
3193
3194 Context context = Context::getDefault(&error);
3195 detail::errHandler(error, __CREATE_CONTEXT_ERR);
3196
3197 if (error != CL_SUCCESS) {
3198 default_error_ = error;
3199 }
3200 else {
3201 default_ = context.getInfo<CL_CONTEXT_DEVICES>()[0];
3202 default_error_ = CL_SUCCESS;
3203 }
3204 }
3205#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3206 catch (cl::Error &e) {
3207 default_error_ = e.err();
3208 }
3209#endif
3210}
3211
3212CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Context::default_initialized_;
3213CL_HPP_DEFINE_STATIC_MEMBER_ Context Context::default_;
3214CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Context::default_error_ = CL_SUCCESS;
3215
3224class Event : public detail::Wrapper<cl_event>
3225{
3226public:
3228 Event() : detail::Wrapper<cl_type>() { }
3229
3238 explicit Event(const cl_event& event, bool retainObject = false) :
3239 detail::Wrapper<cl_type>(event, retainObject) { }
3240
3246 Event& operator = (const cl_event& rhs)
3247 {
3249 return *this;
3250 }
3251
3253 template <typename T>
3254 cl_int getInfo(cl_event_info name, T* param) const
3255 {
3256 return detail::errHandler(
3257 detail::getInfo(&::clGetEventInfo, object_, name, param),
3258 __GET_EVENT_INFO_ERR);
3259 }
3260
3262 template <cl_event_info name> typename
3264 getInfo(cl_int* err = NULL) const
3265 {
3266 typename detail::param_traits<
3267 detail::cl_event_info, name>::param_type param;
3268 cl_int result = getInfo(name, &param);
3269 if (err != NULL) {
3270 *err = result;
3271 }
3272 return param;
3273 }
3274
3276 template <typename T>
3277 cl_int getProfilingInfo(cl_profiling_info name, T* param) const
3278 {
3279 return detail::errHandler(detail::getInfo(
3280 &::clGetEventProfilingInfo, object_, name, param),
3281 __GET_EVENT_PROFILE_INFO_ERR);
3282 }
3283
3285 template <cl_profiling_info name> typename
3287 getProfilingInfo(cl_int* err = NULL) const
3288 {
3289 typename detail::param_traits<
3290 detail::cl_profiling_info, name>::param_type param;
3291 cl_int result = getProfilingInfo(name, &param);
3292 if (err != NULL) {
3293 *err = result;
3294 }
3295 return param;
3296 }
3297
3302 cl_int wait() const
3303 {
3304 return detail::errHandler(
3305 ::clWaitForEvents(1, &object_),
3306 __WAIT_FOR_EVENTS_ERR);
3307 }
3308
3309#if CL_HPP_TARGET_OPENCL_VERSION >= 110
3315 cl_int type,
3316 void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
3317 void * user_data = NULL)
3318 {
3319 return detail::errHandler(
3320 ::clSetEventCallback(
3321 object_,
3322 type,
3323 pfn_notify,
3324 user_data),
3325 __SET_EVENT_CALLBACK_ERR);
3326 }
3327#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3328
3333 static cl_int
3334 waitForEvents(const vector<Event>& events)
3335 {
3336 return detail::errHandler(
3337 ::clWaitForEvents(
3338 (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3339 __WAIT_FOR_EVENTS_ERR);
3340 }
3341};
3342
3343#if CL_HPP_TARGET_OPENCL_VERSION >= 110
3348class UserEvent : public Event
3349{
3350public:
3356 const Context& context,
3357 cl_int * err = NULL)
3358 {
3359 cl_int error;
3360 object_ = ::clCreateUserEvent(
3361 context(),
3362 &error);
3363
3364 detail::errHandler(error, __CREATE_USER_EVENT_ERR);
3365 if (err != NULL) {
3366 *err = error;
3367 }
3368 }
3369
3372
3377 cl_int setStatus(cl_int status)
3378 {
3379 return detail::errHandler(
3380 ::clSetUserEventStatus(object_,status),
3381 __SET_USER_EVENT_STATUS_ERR);
3382 }
3383};
3384#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3385
3390inline static cl_int
3391WaitForEvents(const vector<Event>& events)
3392{
3393 return detail::errHandler(
3394 ::clWaitForEvents(
3395 (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3396 __WAIT_FOR_EVENTS_ERR);
3397}
3398
3407class Memory : public detail::Wrapper<cl_mem>
3408{
3409public:
3411 Memory() : detail::Wrapper<cl_type>() { }
3412
3424 explicit Memory(const cl_mem& memory, bool retainObject) :
3425 detail::Wrapper<cl_type>(memory, retainObject) { }
3426
3432 Memory& operator = (const cl_mem& rhs)
3433 {
3435 return *this;
3436 }
3437
3441 Memory(const Memory& mem) : detail::Wrapper<cl_type>(mem) {}
3442
3447 {
3449 return *this;
3450 }
3451
3455 Memory(Memory&& mem) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(mem)) {}
3456
3461 {
3463 return *this;
3464 }
3465
3466
3468 template <typename T>
3469 cl_int getInfo(cl_mem_info name, T* param) const
3470 {
3471 return detail::errHandler(
3472 detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
3473 __GET_MEM_OBJECT_INFO_ERR);
3474 }
3475
3477 template <cl_mem_info name> typename
3479 getInfo(cl_int* err = NULL) const
3480 {
3481 typename detail::param_traits<
3482 detail::cl_mem_info, name>::param_type param;
3483 cl_int result = getInfo(name, &param);
3484 if (err != NULL) {
3485 *err = result;
3486 }
3487 return param;
3488 }
3489
3490#if CL_HPP_TARGET_OPENCL_VERSION >= 110
3505 void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
3506 void * user_data = NULL)
3507 {
3508 return detail::errHandler(
3509 ::clSetMemObjectDestructorCallback(
3510 object_,
3511 pfn_notify,
3512 user_data),
3513 __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
3514 }
3515#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3516
3517};
3518
3519// Pre-declare copy functions
3520class Buffer;
3521template< typename IteratorType >
3522cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3523template< typename IteratorType >
3524cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3525template< typename IteratorType >
3526cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3527template< typename IteratorType >
3528cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3529
3530
3531#if CL_HPP_TARGET_OPENCL_VERSION >= 200
3532namespace detail
3533{
3535 {
3536 public:
3537 static cl_svm_mem_flags getSVMMemFlags()
3538 {
3539 return 0;
3540 }
3541 };
3542} // namespace detail
3543
3544template<class Trait = detail::SVMTraitNull>
3546{
3547public:
3548 static cl_svm_mem_flags getSVMMemFlags()
3549 {
3550 return CL_MEM_READ_WRITE |
3551 Trait::getSVMMemFlags();
3552 }
3553};
3554
3555template<class Trait = detail::SVMTraitNull>
3557{
3558public:
3559 static cl_svm_mem_flags getSVMMemFlags()
3560 {
3561 return CL_MEM_READ_ONLY |
3562 Trait::getSVMMemFlags();
3563 }
3564};
3565
3566template<class Trait = detail::SVMTraitNull>
3568{
3569public:
3570 static cl_svm_mem_flags getSVMMemFlags()
3571 {
3572 return CL_MEM_WRITE_ONLY |
3573 Trait::getSVMMemFlags();
3574 }
3575};
3576
3577template<class Trait = SVMTraitReadWrite<>>
3579{
3580public:
3581 static cl_svm_mem_flags getSVMMemFlags()
3582 {
3583 return Trait::getSVMMemFlags();
3584 }
3585};
3586
3587template<class Trait = SVMTraitReadWrite<>>
3589{
3590public:
3591 static cl_svm_mem_flags getSVMMemFlags()
3592 {
3593 return CL_MEM_SVM_FINE_GRAIN_BUFFER |
3594 Trait::getSVMMemFlags();
3595 }
3596};
3597
3598template<class Trait = SVMTraitReadWrite<>>
3600{
3601public:
3602 static cl_svm_mem_flags getSVMMemFlags()
3603 {
3604 return
3605 CL_MEM_SVM_FINE_GRAIN_BUFFER |
3606 CL_MEM_SVM_ATOMICS |
3607 Trait::getSVMMemFlags();
3608 }
3609};
3610
3611// Pre-declare SVM map function
3612template<typename T>
3613inline cl_int enqueueMapSVM(
3614 T* ptr,
3615 cl_bool blocking,
3616 cl_map_flags flags,
3617 size_type size,
3618 const vector<Event>* events = NULL,
3619 Event* event = NULL);
3620
3632template<typename T, class SVMTrait>
3634private:
3635 Context context_;
3636
3637public:
3638 typedef T value_type;
3639 typedef value_type* pointer;
3640 typedef const value_type* const_pointer;
3641 typedef value_type& reference;
3642 typedef const value_type& const_reference;
3643 typedef std::size_t size_type;
3644 typedef std::ptrdiff_t difference_type;
3645
3646 template<typename U>
3647 struct rebind
3648 {
3650 };
3651
3652 template<typename U, typename V>
3653 friend class SVMAllocator;
3654
3655 SVMAllocator() :
3656 context_(Context::getDefault())
3657 {
3658 }
3659
3660 explicit SVMAllocator(cl::Context context) :
3661 context_(context)
3662 {
3663 }
3664
3665
3666 SVMAllocator(const SVMAllocator &other) :
3667 context_(other.context_)
3668 {
3669 }
3670
3671 template<typename U>
3672 SVMAllocator(const SVMAllocator<U, SVMTrait> &other) :
3673 context_(other.context_)
3674 {
3675 }
3676
3677 ~SVMAllocator()
3678 {
3679 }
3680
3681 pointer address(reference r) CL_HPP_NOEXCEPT_
3682 {
3683 return std::addressof(r);
3684 }
3685
3686 const_pointer address(const_reference r) CL_HPP_NOEXCEPT_
3687 {
3688 return std::addressof(r);
3689 }
3690
3697 pointer allocate(
3698 size_type size,
3699 typename cl::SVMAllocator<void, SVMTrait>::const_pointer = 0)
3700 {
3701 // Allocate memory with default alignment matching the size of the type
3702 void* voidPointer =
3703 clSVMAlloc(
3704 context_(),
3705 SVMTrait::getSVMMemFlags(),
3706 size*sizeof(T),
3707 0);
3708 pointer retValue = reinterpret_cast<pointer>(
3709 voidPointer);
3710#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3711 if (!retValue) {
3712 std::bad_alloc excep;
3713 throw excep;
3714 }
3715#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3716
3717 // If allocation was coarse-grained then map it
3718 if (!(SVMTrait::getSVMMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) {
3719 cl_int err = enqueueMapSVM(retValue, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, size*sizeof(T));
3720 if (err != CL_SUCCESS) {
3721 std::bad_alloc excep;
3722 throw excep;
3723 }
3724 }
3725
3726 // If exceptions disabled, return null pointer from allocator
3727 return retValue;
3728 }
3729
3730 void deallocate(pointer p, size_type)
3731 {
3732 clSVMFree(context_(), p);
3733 }
3734
3739 size_type max_size() const CL_HPP_NOEXCEPT_
3740 {
3741 size_type maxSize = std::numeric_limits<size_type>::max() / sizeof(T);
3742
3743 for (const Device &d : context_.getInfo<CL_CONTEXT_DEVICES>()) {
3744 maxSize = std::min(
3745 maxSize,
3746 static_cast<size_type>(d.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>()));
3747 }
3748
3749 return maxSize;
3750 }
3751
3752 template< class U, class... Args >
3753 void construct(U* p, Args&&... args)
3754 {
3755 new(p)T(args...);
3756 }
3757
3758 template< class U >
3759 void destroy(U* p)
3760 {
3761 p->~U();
3762 }
3763
3767 inline bool operator==(SVMAllocator const& rhs)
3768 {
3769 return (context_==rhs.context_);
3770 }
3771
3772 inline bool operator!=(SVMAllocator const& a)
3773 {
3774 return !operator==(a);
3775 }
3776}; // class SVMAllocator return cl::pointer<T>(tmp, detail::Deleter<T, Alloc>{alloc, copies});
3777
3778
3779template<class SVMTrait>
3780class SVMAllocator<void, SVMTrait> {
3781public:
3782 typedef void value_type;
3783 typedef value_type* pointer;
3784 typedef const value_type* const_pointer;
3785
3786 template<typename U>
3787 struct rebind
3788 {
3790 };
3791
3792 template<typename U, typename V>
3793 friend class SVMAllocator;
3794};
3795
3796#if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3797namespace detail
3798{
3799 template<class Alloc>
3800 class Deleter {
3801 private:
3802 Alloc alloc_;
3803 size_type copies_;
3804
3805 public:
3806 typedef typename std::allocator_traits<Alloc>::pointer pointer;
3807
3808 Deleter(const Alloc &alloc, size_type copies) : alloc_{ alloc }, copies_{ copies }
3809 {
3810 }
3811
3812 void operator()(pointer ptr) const {
3813 Alloc tmpAlloc{ alloc_ };
3814 std::allocator_traits<Alloc>::destroy(tmpAlloc, std::addressof(*ptr));
3815 std::allocator_traits<Alloc>::deallocate(tmpAlloc, ptr, copies_);
3816 }
3817 };
3818} // namespace detail
3819
3826template <class T, class Alloc, class... Args>
3827cl::pointer<T, detail::Deleter<Alloc>> allocate_pointer(const Alloc &alloc_, Args&&... args)
3828{
3829 Alloc alloc(alloc_);
3830 static const size_type copies = 1;
3831
3832 // Ensure that creation of the management block and the
3833 // object are dealt with separately such that we only provide a deleter
3834
3835 T* tmp = std::allocator_traits<Alloc>::allocate(alloc, copies);
3836 if (!tmp) {
3837 std::bad_alloc excep;
3838 throw excep;
3839 }
3840 try {
3841 std::allocator_traits<Alloc>::construct(
3842 alloc,
3843 std::addressof(*tmp),
3844 std::forward<Args>(args)...);
3845
3846 return cl::pointer<T, detail::Deleter<Alloc>>(tmp, detail::Deleter<Alloc>{alloc, copies});
3847 }
3848 catch (std::bad_alloc& b)
3849 {
3850 std::allocator_traits<Alloc>::deallocate(alloc, tmp, copies);
3851 throw;
3852 }
3853}
3854
3855template< class T, class SVMTrait, class... Args >
3856cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(Args... args)
3857{
3858 SVMAllocator<T, SVMTrait> alloc;
3859 return cl::allocate_pointer<T>(alloc, args...);
3860}
3861
3862template< class T, class SVMTrait, class... Args >
3863cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(const cl::Context &c, Args... args)
3864{
3865 SVMAllocator<T, SVMTrait> alloc(c);
3866 return cl::allocate_pointer<T>(alloc, args...);
3867}
3868#endif // #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3869
3873template < class T >
3874using coarse_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>>;
3875
3879template < class T >
3880using fine_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitFine<>>>;
3881
3885template < class T >
3886using atomic_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitAtomic<>>>;
3887
3888#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
3889
3890
3897class Buffer : public Memory
3898{
3899public:
3900
3909 const Context& context,
3910 cl_mem_flags flags,
3911 size_type size,
3912 void* host_ptr = NULL,
3913 cl_int* err = NULL)
3914 {
3915 cl_int error;
3916 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3917
3918 detail::errHandler(error, __CREATE_BUFFER_ERR);
3919 if (err != NULL) {
3920 *err = error;
3921 }
3922 }
3923
3934 cl_mem_flags flags,
3935 size_type size,
3936 void* host_ptr = NULL,
3937 cl_int* err = NULL)
3938 {
3939 cl_int error;
3940
3941 Context context = Context::getDefault(err);
3942
3943 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3944
3945 detail::errHandler(error, __CREATE_BUFFER_ERR);
3946 if (err != NULL) {
3947 *err = error;
3948 }
3949 }
3950
3956 template< typename IteratorType >
3958 IteratorType startIterator,
3959 IteratorType endIterator,
3960 bool readOnly,
3961 bool useHostPtr = false,
3962 cl_int* err = NULL)
3963 {
3964 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
3965 cl_int error;
3966
3967 cl_mem_flags flags = 0;
3968 if( readOnly ) {
3969 flags |= CL_MEM_READ_ONLY;
3970 }
3971 else {
3972 flags |= CL_MEM_READ_WRITE;
3973 }
3974 if( useHostPtr ) {
3975 flags |= CL_MEM_USE_HOST_PTR;
3976 }
3977
3978 size_type size = sizeof(DataType)*(endIterator - startIterator);
3979
3980 Context context = Context::getDefault(err);
3981
3982 if( useHostPtr ) {
3983 object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
3984 } else {
3985 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
3986 }
3987
3988 detail::errHandler(error, __CREATE_BUFFER_ERR);
3989 if (err != NULL) {
3990 *err = error;
3991 }
3992
3993 if( !useHostPtr ) {
3994 error = cl::copy(startIterator, endIterator, *this);
3995 detail::errHandler(error, __CREATE_BUFFER_ERR);
3996 if (err != NULL) {
3997 *err = error;
3998 }
3999 }
4000 }
4001
4007 template< typename IteratorType >
4008 Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator,
4009 bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
4010
4015 template< typename IteratorType >
4016 Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator,
4017 bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
4018
4020 Buffer() : Memory() { }
4021
4029 explicit Buffer(const cl_mem& buffer, bool retainObject = false) :
4030 Memory(buffer, retainObject) { }
4031
4036 Buffer& operator = (const cl_mem& rhs)
4037 {
4038 Memory::operator=(rhs);
4039 return *this;
4040 }
4041
4045 Buffer(const Buffer& buf) : Memory(buf) {}
4046
4051 {
4052 Memory::operator=(buf);
4053 return *this;
4054 }
4055
4059 Buffer(Buffer&& buf) CL_HPP_NOEXCEPT_ : Memory(std::move(buf)) {}
4060
4065 {
4066 Memory::operator=(std::move(buf));
4067 return *this;
4068 }
4069
4070#if CL_HPP_TARGET_OPENCL_VERSION >= 110
4076 cl_mem_flags flags,
4077 cl_buffer_create_type buffer_create_type,
4078 const void * buffer_create_info,
4079 cl_int * err = NULL)
4080 {
4081 Buffer result;
4082 cl_int error;
4083 result.object_ = ::clCreateSubBuffer(
4084 object_,
4085 flags,
4086 buffer_create_type,
4087 buffer_create_info,
4088 &error);
4089
4090 detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
4091 if (err != NULL) {
4092 *err = error;
4093 }
4094
4095 return result;
4096 }
4097#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
4098};
4099
4100#if defined (CL_HPP_USE_DX_INTEROP)
4109class BufferD3D10 : public Buffer
4110{
4111public:
4112
4113
4119 BufferD3D10(
4120 const Context& context,
4121 cl_mem_flags flags,
4122 ID3D10Buffer* bufobj,
4123 cl_int * err = NULL) : pfn_clCreateFromD3D10BufferKHR(nullptr)
4124 {
4125 typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
4126 cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
4127 cl_int* errcode_ret);
4128 PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR;
4129#if CL_HPP_TARGET_OPENCL_VERSION >= 120
4130 vector<cl_context_properties> props = context.getInfo<CL_CONTEXT_PROPERTIES>();
4131 cl_platform platform = -1;
4132 for( int i = 0; i < props.size(); ++i ) {
4133 if( props[i] == CL_CONTEXT_PLATFORM ) {
4134 platform = props[i+1];
4135 }
4136 }
4137 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateFromD3D10BufferKHR);
4138#elif CL_HPP_TARGET_OPENCL_VERSION >= 110
4139 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateFromD3D10BufferKHR);
4140#endif
4141
4142 cl_int error;
4143 object_ = pfn_clCreateFromD3D10BufferKHR(
4144 context(),
4145 flags,
4146 bufobj,
4147 &error);
4148
4149 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4150 if (err != NULL) {
4151 *err = error;
4152 }
4153 }
4154
4156 BufferD3D10() : Buffer() { }
4157
4165 explicit BufferD3D10(const cl_mem& buffer, bool retainObject = false) :
4166 Buffer(buffer, retainObject) { }
4167
4172 BufferD3D10& operator = (const cl_mem& rhs)
4173 {
4174 Buffer::operator=(rhs);
4175 return *this;
4176 }
4177
4181 BufferD3D10(const BufferD3D10& buf) :
4182 Buffer(buf) {}
4183
4187 BufferD3D10& operator = (const BufferD3D10 &buf)
4188 {
4189 Buffer::operator=(buf);
4190 return *this;
4191 }
4192
4196 BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4197
4201 BufferD3D10& operator = (BufferD3D10 &&buf)
4202 {
4203 Buffer::operator=(std::move(buf));
4204 return *this;
4205 }
4206};
4207#endif
4208
4217class BufferGL : public Buffer
4218{
4219public:
4226 const Context& context,
4227 cl_mem_flags flags,
4228 cl_GLuint bufobj,
4229 cl_int * err = NULL)
4230 {
4231 cl_int error;
4232 object_ = ::clCreateFromGLBuffer(
4233 context(),
4234 flags,
4235 bufobj,
4236 &error);
4237
4238 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4239 if (err != NULL) {
4240 *err = error;
4241 }
4242 }
4243
4246
4254 explicit BufferGL(const cl_mem& buffer, bool retainObject = false) :
4255 Buffer(buffer, retainObject) { }
4256
4261 BufferGL& operator = (const cl_mem& rhs)
4262 {
4263 Buffer::operator=(rhs);
4264 return *this;
4265 }
4266
4270 BufferGL(const BufferGL& buf) : Buffer(buf) {}
4271
4276 {
4277 Buffer::operator=(buf);
4278 return *this;
4279 }
4280
4284 BufferGL(BufferGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4285
4290 {
4291 Buffer::operator=(std::move(buf));
4292 return *this;
4293 }
4294
4297 cl_gl_object_type *type,
4298 cl_GLuint * gl_object_name)
4299 {
4300 return detail::errHandler(
4301 ::clGetGLObjectInfo(object_,type,gl_object_name),
4302 __GET_GL_OBJECT_INFO_ERR);
4303 }
4304};
4305
4315{
4316public:
4323 const Context& context,
4324 cl_mem_flags flags,
4325 cl_GLuint bufobj,
4326 cl_int * err = NULL)
4327 {
4328 cl_int error;
4329 object_ = ::clCreateFromGLRenderbuffer(
4330 context(),
4331 flags,
4332 bufobj,
4333 &error);
4334
4335 detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR);
4336 if (err != NULL) {
4337 *err = error;
4338 }
4339 }
4340
4343
4351 explicit BufferRenderGL(const cl_mem& buffer, bool retainObject = false) :
4352 Buffer(buffer, retainObject) { }
4353
4358 BufferRenderGL& operator = (const cl_mem& rhs)
4359 {
4360 Buffer::operator=(rhs);
4361 return *this;
4362 }
4363
4368
4373 {
4374 Buffer::operator=(buf);
4375 return *this;
4376 }
4377
4381 BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4382
4387 {
4388 Buffer::operator=(std::move(buf));
4389 return *this;
4390 }
4391
4394 cl_gl_object_type *type,
4395 cl_GLuint * gl_object_name)
4396 {
4397 return detail::errHandler(
4398 ::clGetGLObjectInfo(object_,type,gl_object_name),
4399 __GET_GL_OBJECT_INFO_ERR);
4400 }
4401};
4402
4409class Image : public Memory
4410{
4411protected:
4413 Image() : Memory() { }
4414
4422 explicit Image(const cl_mem& image, bool retainObject = false) :
4423 Memory(image, retainObject) { }
4424
4429 Image& operator = (const cl_mem& rhs)
4430 {
4431 Memory::operator=(rhs);
4432 return *this;
4433 }
4434
4438 Image(const Image& img) : Memory(img) {}
4439
4444 {
4445 Memory::operator=(img);
4446 return *this;
4447 }
4448
4452 Image(Image&& img) CL_HPP_NOEXCEPT_ : Memory(std::move(img)) {}
4453
4458 {
4459 Memory::operator=(std::move(img));
4460 return *this;
4461 }
4462
4463
4464public:
4466 template <typename T>
4467 cl_int getImageInfo(cl_image_info name, T* param) const
4468 {
4469 return detail::errHandler(
4470 detail::getInfo(&::clGetImageInfo, object_, name, param),
4471 __GET_IMAGE_INFO_ERR);
4472 }
4473
4475 template <cl_image_info name> typename
4477 getImageInfo(cl_int* err = NULL) const
4478 {
4479 typename detail::param_traits<
4480 detail::cl_image_info, name>::param_type param;
4481 cl_int result = getImageInfo(name, &param);
4482 if (err != NULL) {
4483 *err = result;
4484 }
4485 return param;
4486 }
4487};
4488
4489#if CL_HPP_TARGET_OPENCL_VERSION >= 120
4496class Image1D : public Image
4497{
4498public:
4504 const Context& context,
4505 cl_mem_flags flags,
4506 ImageFormat format,
4507 size_type width,
4508 void* host_ptr = NULL,
4509 cl_int* err = NULL)
4510 {
4511 cl_int error;
4512
4513 cl_image_desc desc = {0};
4514 desc.image_type = CL_MEM_OBJECT_IMAGE1D;
4515 desc.image_width = width;
4516
4517 object_ = ::clCreateImage(
4518 context(),
4519 flags,
4520 &format,
4521 &desc,
4522 host_ptr,
4523 &error);
4524
4525 detail::errHandler(error, __CREATE_IMAGE_ERR);
4526 if (err != NULL) {
4527 *err = error;
4528 }
4529 }
4530
4533
4541 explicit Image1D(const cl_mem& image1D, bool retainObject = false) :
4542 Image(image1D, retainObject) { }
4543
4548 Image1D& operator = (const cl_mem& rhs)
4549 {
4550 Image::operator=(rhs);
4551 return *this;
4552 }
4553
4557 Image1D(const Image1D& img) : Image(img) {}
4558
4563 {
4564 Image::operator=(img);
4565 return *this;
4566 }
4567
4571 Image1D(Image1D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4572
4577 {
4578 Image::operator=(std::move(img));
4579 return *this;
4580 }
4581
4582};
4583
4587class Image1DBuffer : public Image
4588{
4589public:
4591 const Context& context,
4592 cl_mem_flags flags,
4593 ImageFormat format,
4594 size_type width,
4595 const Buffer &buffer,
4596 cl_int* err = NULL)
4597 {
4598 cl_int error;
4599
4600 cl_image_desc desc = {0};
4601 desc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER;
4602 desc.image_width = width;
4603 desc.buffer = buffer();
4604
4605 object_ = ::clCreateImage(
4606 context(),
4607 flags,
4608 &format,
4609 &desc,
4610 NULL,
4611 &error);
4612
4613 detail::errHandler(error, __CREATE_IMAGE_ERR);
4614 if (err != NULL) {
4615 *err = error;
4616 }
4617 }
4618
4619 Image1DBuffer() { }
4620
4628 explicit Image1DBuffer(const cl_mem& image1D, bool retainObject = false) :
4629 Image(image1D, retainObject) { }
4630
4631 Image1DBuffer& operator = (const cl_mem& rhs)
4632 {
4633 Image::operator=(rhs);
4634 return *this;
4635 }
4636
4640 Image1DBuffer(const Image1DBuffer& img) : Image(img) {}
4641
4645 Image1DBuffer& operator = (const Image1DBuffer &img)
4646 {
4647 Image::operator=(img);
4648 return *this;
4649 }
4650
4654 Image1DBuffer(Image1DBuffer&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4655
4659 Image1DBuffer& operator = (Image1DBuffer &&img)
4660 {
4661 Image::operator=(std::move(img));
4662 return *this;
4663 }
4664
4665};
4666
4670class Image1DArray : public Image
4671{
4672public:
4674 const Context& context,
4675 cl_mem_flags flags,
4676 ImageFormat format,
4677 size_type arraySize,
4678 size_type width,
4679 size_type rowPitch,
4680 void* host_ptr = NULL,
4681 cl_int* err = NULL)
4682 {
4683 cl_int error;
4684
4685 cl_image_desc desc = {0};
4686 desc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
4687 desc.image_width = width;
4688 desc.image_array_size = arraySize;
4689 desc.image_row_pitch = rowPitch;
4690
4691 object_ = ::clCreateImage(
4692 context(),
4693 flags,
4694 &format,
4695 &desc,
4696 host_ptr,
4697 &error);
4698
4699 detail::errHandler(error, __CREATE_IMAGE_ERR);
4700 if (err != NULL) {
4701 *err = error;
4702 }
4703 }
4704
4705 Image1DArray() { }
4706
4714 explicit Image1DArray(const cl_mem& imageArray, bool retainObject = false) :
4715 Image(imageArray, retainObject) { }
4716
4717
4718 Image1DArray& operator = (const cl_mem& rhs)
4719 {
4720 Image::operator=(rhs);
4721 return *this;
4722 }
4723
4727 Image1DArray(const Image1DArray& img) : Image(img) {}
4728
4732 Image1DArray& operator = (const Image1DArray &img)
4733 {
4734 Image::operator=(img);
4735 return *this;
4736 }
4737
4741 Image1DArray(Image1DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4742
4746 Image1DArray& operator = (Image1DArray &&img)
4747 {
4748 Image::operator=(std::move(img));
4749 return *this;
4750 }
4751
4752};
4753#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4754
4755
4762class Image2D : public Image
4763{
4764public:
4770 const Context& context,
4771 cl_mem_flags flags,
4772 ImageFormat format,
4773 size_type width,
4774 size_type height,
4775 size_type row_pitch = 0,
4776 void* host_ptr = NULL,
4777 cl_int* err = NULL)
4778 {
4779 cl_int error;
4780 bool useCreateImage;
4781
4782#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
4783 // Run-time decision based on the actual platform
4784 {
4785 cl_uint version = detail::getContextPlatformVersion(context());
4786 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
4787 }
4788#elif CL_HPP_TARGET_OPENCL_VERSION >= 120
4789 useCreateImage = true;
4790#else
4791 useCreateImage = false;
4792#endif
4793
4794#if CL_HPP_TARGET_OPENCL_VERSION >= 120
4795 if (useCreateImage)
4796 {
4797 cl_image_desc desc = {0};
4798 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
4799 desc.image_width = width;
4800 desc.image_height = height;
4801 desc.image_row_pitch = row_pitch;
4802
4803 object_ = ::clCreateImage(
4804 context(),
4805 flags,
4806 &format,
4807 &desc,
4808 host_ptr,
4809 &error);
4810
4811 detail::errHandler(error, __CREATE_IMAGE_ERR);
4812 if (err != NULL) {
4813 *err = error;
4814 }
4815 }
4816#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
4817#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
4818 if (!useCreateImage)
4819 {
4820 object_ = ::clCreateImage2D(
4821 context(), flags,&format, width, height, row_pitch, host_ptr, &error);
4822
4823 detail::errHandler(error, __CREATE_IMAGE2D_ERR);
4824 if (err != NULL) {
4825 *err = error;
4826 }
4827 }
4828#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
4829 }
4830
4831#if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4838 const Context& context,
4839 ImageFormat format,
4840 const Buffer &sourceBuffer,
4841 size_type width,
4842 size_type height,
4843 size_type row_pitch = 0,
4844 cl_int* err = nullptr)
4845 {
4846 cl_int error;
4847
4848 cl_image_desc desc = {0};
4849 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
4850 desc.image_width = width;
4851 desc.image_height = height;
4852 desc.image_row_pitch = row_pitch;
4853 desc.buffer = sourceBuffer();
4854
4855 object_ = ::clCreateImage(
4856 context(),
4857 0, // flags inherited from buffer
4858 &format,
4859 &desc,
4860 nullptr,
4861 &error);
4862
4863 detail::errHandler(error, __CREATE_IMAGE_ERR);
4864 if (err != nullptr) {
4865 *err = error;
4866 }
4867 }
4868#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4869
4870#if CL_HPP_TARGET_OPENCL_VERSION >= 200
4884 const Context& context,
4885 cl_channel_order order,
4886 const Image &sourceImage,
4887 cl_int* err = nullptr)
4888 {
4889 cl_int error;
4890
4891 // Descriptor fields have to match source image
4892 size_type sourceWidth =
4893 sourceImage.getImageInfo<CL_IMAGE_WIDTH>();
4894 size_type sourceHeight =
4895 sourceImage.getImageInfo<CL_IMAGE_HEIGHT>();
4896 size_type sourceRowPitch =
4897 sourceImage.getImageInfo<CL_IMAGE_ROW_PITCH>();
4898 cl_uint sourceNumMIPLevels =
4899 sourceImage.getImageInfo<CL_IMAGE_NUM_MIP_LEVELS>();
4900 cl_uint sourceNumSamples =
4901 sourceImage.getImageInfo<CL_IMAGE_NUM_SAMPLES>();
4902 cl_image_format sourceFormat =
4903 sourceImage.getImageInfo<CL_IMAGE_FORMAT>();
4904
4905 // Update only the channel order.
4906 // Channel format inherited from source.
4907 sourceFormat.image_channel_order = order;
4908
4909 cl_image_desc desc = {0};
4910 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
4911 desc.image_width = sourceWidth;
4912 desc.image_height = sourceHeight;
4913 desc.image_row_pitch = sourceRowPitch;
4914 desc.num_mip_levels = sourceNumMIPLevels;
4915 desc.num_samples = sourceNumSamples;
4916 desc.buffer = sourceImage();
4917
4918 object_ = ::clCreateImage(
4919 context(),
4920 0, // flags should be inherited from mem_object
4921 &sourceFormat,
4922 &desc,
4923 nullptr,
4924 &error);
4925
4926 detail::errHandler(error, __CREATE_IMAGE_ERR);
4927 if (err != nullptr) {
4928 *err = error;
4929 }
4930 }
4931#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200
4932
4935
4943 explicit Image2D(const cl_mem& image2D, bool retainObject = false) :
4944 Image(image2D, retainObject) { }
4945
4950 Image2D& operator = (const cl_mem& rhs)
4951 {
4952 Image::operator=(rhs);
4953 return *this;
4954 }
4955
4959 Image2D(const Image2D& img) : Image(img) {}
4960
4965 {
4966 Image::operator=(img);
4967 return *this;
4968 }
4969
4973 Image2D(Image2D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4974
4979 {
4980 Image::operator=(std::move(img));
4981 return *this;
4982 }
4983
4984};
4985
4986
4987#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
4997class CL_API_PREFIX__VERSION_1_1_DEPRECATED Image2DGL : public Image2D
4998{
4999public:
5006 const Context& context,
5007 cl_mem_flags flags,
5008 cl_GLenum target,
5009 cl_GLint miplevel,
5010 cl_GLuint texobj,
5011 cl_int * err = NULL)
5012 {
5013 cl_int error;
5014 object_ = ::clCreateFromGLTexture2D(
5015 context(),
5016 flags,
5017 target,
5018 miplevel,
5019 texobj,
5020 &error);
5021
5022 detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR);
5023 if (err != NULL) {
5024 *err = error;
5025 }
5026
5027 }
5028
5031
5039 explicit Image2DGL(const cl_mem& image, bool retainObject = false) :
5040 Image2D(image, retainObject) { }
5041
5046 Image2DGL& operator = (const cl_mem& rhs)
5047 {
5048 Image2D::operator=(rhs);
5049 return *this;
5050 }
5051
5055 Image2DGL(const Image2DGL& img) : Image2D(img) {}
5056
5060 Image2DGL& operator = (const Image2DGL &img)
5061 {
5062 Image2D::operator=(img);
5063 return *this;
5064 }
5065
5069 Image2DGL(Image2DGL&& img) CL_HPP_NOEXCEPT_ : Image2D(std::move(img)) {}
5070
5074 Image2DGL& operator = (Image2DGL &&img)
5075 {
5076 Image2D::operator=(std::move(img));
5077 return *this;
5078 }
5079
5080} CL_API_SUFFIX__VERSION_1_1_DEPRECATED;
5081#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5082
5083#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5087class Image2DArray : public Image
5088{
5089public:
5091 const Context& context,
5092 cl_mem_flags flags,
5093 ImageFormat format,
5094 size_type arraySize,
5095 size_type width,
5096 size_type height,
5097 size_type rowPitch,
5098 size_type slicePitch,
5099 void* host_ptr = NULL,
5100 cl_int* err = NULL)
5101 {
5102 cl_int error;
5103
5104 cl_image_desc desc = {0};
5105 desc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
5106 desc.image_width = width;
5107 desc.image_height = height;
5108 desc.image_array_size = arraySize;
5109 desc.image_row_pitch = rowPitch;
5110 desc.image_slice_pitch = slicePitch;
5111
5112 object_ = ::clCreateImage(
5113 context(),
5114 flags,
5115 &format,
5116 &desc,
5117 host_ptr,
5118 &error);
5119
5120 detail::errHandler(error, __CREATE_IMAGE_ERR);
5121 if (err != NULL) {
5122 *err = error;
5123 }
5124 }
5125
5126 Image2DArray() { }
5127
5135 explicit Image2DArray(const cl_mem& imageArray, bool retainObject = false) : Image(imageArray, retainObject) { }
5136
5137 Image2DArray& operator = (const cl_mem& rhs)
5138 {
5139 Image::operator=(rhs);
5140 return *this;
5141 }
5142
5146 Image2DArray(const Image2DArray& img) : Image(img) {}
5147
5151 Image2DArray& operator = (const Image2DArray &img)
5152 {
5153 Image::operator=(img);
5154 return *this;
5155 }
5156
5160 Image2DArray(Image2DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5161
5165 Image2DArray& operator = (Image2DArray &&img)
5166 {
5167 Image::operator=(std::move(img));
5168 return *this;
5169 }
5170};
5171#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5172
5179class Image3D : public Image
5180{
5181public:
5187 const Context& context,
5188 cl_mem_flags flags,
5189 ImageFormat format,
5190 size_type width,
5191 size_type height,
5192 size_type depth,
5193 size_type row_pitch = 0,
5194 size_type slice_pitch = 0,
5195 void* host_ptr = NULL,
5196 cl_int* err = NULL)
5197 {
5198 cl_int error;
5199 bool useCreateImage;
5200
5201#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
5202 // Run-time decision based on the actual platform
5203 {
5204 cl_uint version = detail::getContextPlatformVersion(context());
5205 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
5206 }
5207#elif CL_HPP_TARGET_OPENCL_VERSION >= 120
5208 useCreateImage = true;
5209#else
5210 useCreateImage = false;
5211#endif
5212
5213#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5214 if (useCreateImage)
5215 {
5216 cl_image_desc desc = {0};
5217 desc.image_type = CL_MEM_OBJECT_IMAGE3D;
5218 desc.image_width = width;
5219 desc.image_height = height;
5220 desc.image_depth = depth;
5221 desc.image_row_pitch = row_pitch;
5222 desc.image_slice_pitch = slice_pitch;
5223
5224 object_ = ::clCreateImage(
5225 context(),
5226 flags,
5227 &format,
5228 &desc,
5229 host_ptr,
5230 &error);
5231
5232 detail::errHandler(error, __CREATE_IMAGE_ERR);
5233 if (err != NULL) {
5234 *err = error;
5235 }
5236 }
5237#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5238#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
5239 if (!useCreateImage)
5240 {
5241 object_ = ::clCreateImage3D(
5242 context(), flags, &format, width, height, depth, row_pitch,
5243 slice_pitch, host_ptr, &error);
5244
5245 detail::errHandler(error, __CREATE_IMAGE3D_ERR);
5246 if (err != NULL) {
5247 *err = error;
5248 }
5249 }
5250#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
5251 }
5252
5254 Image3D() : Image() { }
5255
5263 explicit Image3D(const cl_mem& image3D, bool retainObject = false) :
5264 Image(image3D, retainObject) { }
5265
5270 Image3D& operator = (const cl_mem& rhs)
5271 {
5272 Image::operator=(rhs);
5273 return *this;
5274 }
5275
5279 Image3D(const Image3D& img) : Image(img) {}
5280
5285 {
5286 Image::operator=(img);
5287 return *this;
5288 }
5289
5293 Image3D(Image3D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5294
5299 {
5300 Image::operator=(std::move(img));
5301 return *this;
5302 }
5303};
5304
5305#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
5314class Image3DGL : public Image3D
5315{
5316public:
5323 const Context& context,
5324 cl_mem_flags flags,
5325 cl_GLenum target,
5326 cl_GLint miplevel,
5327 cl_GLuint texobj,
5328 cl_int * err = NULL)
5329 {
5330 cl_int error;
5331 object_ = ::clCreateFromGLTexture3D(
5332 context(),
5333 flags,
5334 target,
5335 miplevel,
5336 texobj,
5337 &error);
5338
5339 detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR);
5340 if (err != NULL) {
5341 *err = error;
5342 }
5343 }
5344
5347
5355 explicit Image3DGL(const cl_mem& image, bool retainObject = false) :
5356 Image3D(image, retainObject) { }
5357
5362 Image3DGL& operator = (const cl_mem& rhs)
5363 {
5364 Image3D::operator=(rhs);
5365 return *this;
5366 }
5367
5371 Image3DGL(const Image3DGL& img) : Image3D(img) {}
5372
5377 {
5378 Image3D::operator=(img);
5379 return *this;
5380 }
5381
5385 Image3DGL(Image3DGL&& img) CL_HPP_NOEXCEPT_ : Image3D(std::move(img)) {}
5386
5391 {
5392 Image3D::operator=(std::move(img));
5393 return *this;
5394 }
5395};
5396#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5397
5398#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5405class ImageGL : public Image
5406{
5407public:
5408 ImageGL(
5409 const Context& context,
5410 cl_mem_flags flags,
5411 cl_GLenum target,
5412 cl_GLint miplevel,
5413 cl_GLuint texobj,
5414 cl_int * err = NULL)
5415 {
5416 cl_int error;
5417 object_ = ::clCreateFromGLTexture(
5418 context(),
5419 flags,
5420 target,
5421 miplevel,
5422 texobj,
5423 &error);
5424
5425 detail::errHandler(error, __CREATE_GL_TEXTURE_ERR);
5426 if (err != NULL) {
5427 *err = error;
5428 }
5429 }
5430
5431 ImageGL() : Image() { }
5432
5440 explicit ImageGL(const cl_mem& image, bool retainObject = false) :
5441 Image(image, retainObject) { }
5442
5443 ImageGL& operator = (const cl_mem& rhs)
5444 {
5445 Image::operator=(rhs);
5446 return *this;
5447 }
5448
5452 ImageGL(const ImageGL& img) : Image(img) {}
5453
5457 ImageGL& operator = (const ImageGL &img)
5458 {
5459 Image::operator=(img);
5460 return *this;
5461 }
5462
5466 ImageGL(ImageGL&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5467
5471 ImageGL& operator = (ImageGL &&img)
5472 {
5473 Image::operator=(std::move(img));
5474 return *this;
5475 }
5476};
5477#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5478
5479
5480
5481#if CL_HPP_TARGET_OPENCL_VERSION >= 200
5488class Pipe : public Memory
5489{
5490public:
5491
5502 const Context& context,
5503 cl_uint packet_size,
5504 cl_uint max_packets,
5505 cl_int* err = NULL)
5506 {
5507 cl_int error;
5508
5509 cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5510 object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error);
5511
5512 detail::errHandler(error, __CREATE_PIPE_ERR);
5513 if (err != NULL) {
5514 *err = error;
5515 }
5516 }
5517
5527 cl_uint packet_size,
5528 cl_uint max_packets,
5529 cl_int* err = NULL)
5530 {
5531 cl_int error;
5532
5533 Context context = Context::getDefault(err);
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
5545 Pipe() : Memory() { }
5546
5554 explicit Pipe(const cl_mem& pipe, bool retainObject = false) :
5555 Memory(pipe, retainObject) { }
5556
5561 Pipe& operator = (const cl_mem& rhs)
5562 {
5563 Memory::operator=(rhs);
5564 return *this;
5565 }
5566
5570 Pipe(const Pipe& pipe) : Memory(pipe) {}
5571
5575 Pipe& operator = (const Pipe &pipe)
5576 {
5577 Memory::operator=(pipe);
5578 return *this;
5579 }
5580
5584 Pipe(Pipe&& pipe) CL_HPP_NOEXCEPT_ : Memory(std::move(pipe)) {}
5585
5590 {
5591 Memory::operator=(std::move(pipe));
5592 return *this;
5593 }
5594
5596 template <typename T>
5597 cl_int getInfo(cl_pipe_info name, T* param) const
5598 {
5599 return detail::errHandler(
5600 detail::getInfo(&::clGetPipeInfo, object_, name, param),
5601 __GET_PIPE_INFO_ERR);
5602 }
5603
5605 template <cl_pipe_info name> typename
5607 getInfo(cl_int* err = NULL) const
5608 {
5609 typename detail::param_traits<
5610 detail::cl_pipe_info, name>::param_type param;
5611 cl_int result = getInfo(name, &param);
5612 if (err != NULL) {
5613 *err = result;
5614 }
5615 return param;
5616 }
5617}; // class Pipe
5618#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
5619
5620
5629class Sampler : public detail::Wrapper<cl_sampler>
5630{
5631public:
5634
5640 const Context& context,
5641 cl_bool normalized_coords,
5642 cl_addressing_mode addressing_mode,
5643 cl_filter_mode filter_mode,
5644 cl_int* err = NULL)
5645 {
5646 cl_int error;
5647
5648#if CL_HPP_TARGET_OPENCL_VERSION >= 200
5649 cl_sampler_properties sampler_properties[] = {
5650 CL_SAMPLER_NORMALIZED_COORDS, normalized_coords,
5651 CL_SAMPLER_ADDRESSING_MODE, addressing_mode,
5652 CL_SAMPLER_FILTER_MODE, filter_mode,
5653 0 };
5654 object_ = ::clCreateSamplerWithProperties(
5655 context(),
5656 sampler_properties,
5657 &error);
5658
5659 detail::errHandler(error, __CREATE_SAMPLER_WITH_PROPERTIES_ERR);
5660 if (err != NULL) {
5661 *err = error;
5662 }
5663#else
5664 object_ = ::clCreateSampler(
5665 context(),
5666 normalized_coords,
5667 addressing_mode,
5668 filter_mode,
5669 &error);
5670
5671 detail::errHandler(error, __CREATE_SAMPLER_ERR);
5672 if (err != NULL) {
5673 *err = error;
5674 }
5675#endif
5676 }
5677
5686 explicit Sampler(const cl_sampler& sampler, bool retainObject = false) :
5687 detail::Wrapper<cl_type>(sampler, retainObject) { }
5688
5694 Sampler& operator = (const cl_sampler& rhs)
5695 {
5697 return *this;
5698 }
5699
5703 Sampler(const Sampler& sam) : detail::Wrapper<cl_type>(sam) {}
5704
5709 {
5711 return *this;
5712 }
5713
5717 Sampler(Sampler&& sam) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(sam)) {}
5718
5723 {
5725 return *this;
5726 }
5727
5729 template <typename T>
5730 cl_int getInfo(cl_sampler_info name, T* param) const
5731 {
5732 return detail::errHandler(
5733 detail::getInfo(&::clGetSamplerInfo, object_, name, param),
5734 __GET_SAMPLER_INFO_ERR);
5735 }
5736
5738 template <cl_sampler_info name> typename
5740 getInfo(cl_int* err = NULL) const
5741 {
5742 typename detail::param_traits<
5743 detail::cl_sampler_info, name>::param_type param;
5744 cl_int result = getInfo(name, &param);
5745 if (err != NULL) {
5746 *err = result;
5747 }
5748 return param;
5749 }
5750};
5751
5752class Program;
5753class CommandQueue;
5754class DeviceCommandQueue;
5755class Kernel;
5756
5759{
5760private:
5761 size_type sizes_[3];
5762 cl_uint dimensions_;
5763
5764public:
5767 : dimensions_(0)
5768 {
5769 sizes_[0] = 0;
5770 sizes_[1] = 0;
5771 sizes_[2] = 0;
5772 }
5773
5775 NDRange(size_type size0)
5776 : dimensions_(1)
5777 {
5778 sizes_[0] = size0;
5779 sizes_[1] = 1;
5780 sizes_[2] = 1;
5781 }
5782
5784 NDRange(size_type size0, size_type size1)
5785 : dimensions_(2)
5786 {
5787 sizes_[0] = size0;
5788 sizes_[1] = size1;
5789 sizes_[2] = 1;
5790 }
5791
5793 NDRange(size_type size0, size_type size1, size_type size2)
5794 : dimensions_(3)
5795 {
5796 sizes_[0] = size0;
5797 sizes_[1] = size1;
5798 sizes_[2] = size2;
5799 }
5800
5805 operator const size_type*() const {
5806 return sizes_;
5807 }
5808
5810 size_type dimensions() const
5811 {
5812 return dimensions_;
5813 }
5814
5816 // runtime number of dimensions
5817 size_type size() const
5818 {
5819 return dimensions_*sizeof(size_type);
5820 }
5821
5822 size_type* get()
5823 {
5824 return sizes_;
5825 }
5826
5827 const size_type* get() const
5828 {
5829 return sizes_;
5830 }
5831};
5832
5834static const NDRange NullRange;
5835
5838{
5839 size_type size_;
5840};
5841
5842namespace detail {
5843
5844template <typename T, class Enable = void>
5846
5847// Enable for objects that are not subclasses of memory
5848// Pointers, constants etc
5849template <typename T>
5850struct KernelArgumentHandler<T, typename std::enable_if<!std::is_base_of<cl::Memory, T>::value>::type>
5851{
5852 static size_type size(const T&) { return sizeof(T); }
5853 static const T* ptr(const T& value) { return &value; }
5854};
5855
5856// Enable for subclasses of memory where we want to get a reference to the cl_mem out
5857// and pass that in for safety
5858template <typename T>
5859struct KernelArgumentHandler<T, typename std::enable_if<std::is_base_of<cl::Memory, T>::value>::type>
5860{
5861 static size_type size(const T&) { return sizeof(cl_mem); }
5862 static const cl_mem* ptr(const T& value) { return &(value()); }
5863};
5864
5865// Specialization for DeviceCommandQueue defined later
5866
5867template <>
5869{
5870 static size_type size(const LocalSpaceArg& value) { return value.size_; }
5871 static const void* ptr(const LocalSpaceArg&) { return NULL; }
5872};
5873
5874}
5876
5880inline LocalSpaceArg
5881Local(size_type size)
5882{
5883 LocalSpaceArg ret = { size };
5884 return ret;
5885}
5886
5895class Kernel : public detail::Wrapper<cl_kernel>
5896{
5897public:
5898 inline Kernel(const Program& program, const char* name, cl_int* err = NULL);
5899
5902
5911 explicit Kernel(const cl_kernel& kernel, bool retainObject = false) :
5912 detail::Wrapper<cl_type>(kernel, retainObject) { }
5913
5919 Kernel& operator = (const cl_kernel& rhs)
5920 {
5922 return *this;
5923 }
5924
5928 Kernel(const Kernel& kernel) : detail::Wrapper<cl_type>(kernel) {}
5929
5933 Kernel& operator = (const Kernel &kernel)
5934 {
5936 return *this;
5937 }
5938
5942 Kernel(Kernel&& kernel) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(kernel)) {}
5943
5948 {
5949 detail::Wrapper<cl_type>::operator=(std::move(kernel));
5950 return *this;
5951 }
5952
5953 template <typename T>
5954 cl_int getInfo(cl_kernel_info name, T* param) const
5955 {
5956 return detail::errHandler(
5957 detail::getInfo(&::clGetKernelInfo, object_, name, param),
5958 __GET_KERNEL_INFO_ERR);
5959 }
5960
5961 template <cl_kernel_info name> typename
5962 detail::param_traits<detail::cl_kernel_info, name>::param_type
5963 getInfo(cl_int* err = NULL) const
5964 {
5965 typename detail::param_traits<
5966 detail::cl_kernel_info, name>::param_type param;
5967 cl_int result = getInfo(name, &param);
5968 if (err != NULL) {
5969 *err = result;
5970 }
5971 return param;
5972 }
5973
5974#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5975 template <typename T>
5976 cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const
5977 {
5978 return detail::errHandler(
5979 detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param),
5980 __GET_KERNEL_ARG_INFO_ERR);
5981 }
5982
5983 template <cl_kernel_arg_info name> typename
5984 detail::param_traits<detail::cl_kernel_arg_info, name>::param_type
5985 getArgInfo(cl_uint argIndex, cl_int* err = NULL) const
5986 {
5987 typename detail::param_traits<
5988 detail::cl_kernel_arg_info, name>::param_type param;
5989 cl_int result = getArgInfo(argIndex, name, &param);
5990 if (err != NULL) {
5991 *err = result;
5992 }
5993 return param;
5994 }
5995#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5996
5997 template <typename T>
5998 cl_int getWorkGroupInfo(
5999 const Device& device, cl_kernel_work_group_info name, T* param) const
6000 {
6001 return detail::errHandler(
6002 detail::getInfo(
6003 &::clGetKernelWorkGroupInfo, object_, device(), name, param),
6004 __GET_KERNEL_WORK_GROUP_INFO_ERR);
6005 }
6006
6007 template <cl_kernel_work_group_info name> typename
6008 detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
6009 getWorkGroupInfo(const Device& device, cl_int* err = NULL) const
6010 {
6011 typename detail::param_traits<
6012 detail::cl_kernel_work_group_info, name>::param_type param;
6013 cl_int result = getWorkGroupInfo(device, name, &param);
6014 if (err != NULL) {
6015 *err = result;
6016 }
6017 return param;
6018 }
6019
6020#if (CL_HPP_TARGET_OPENCL_VERSION >= 200 && defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)) || CL_HPP_TARGET_OPENCL_VERSION >= 210
6021 cl_int getSubGroupInfo(const cl::Device &dev, cl_kernel_sub_group_info name, const cl::NDRange &range, size_type* param) const
6022 {
6023#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6024
6025 return detail::errHandler(
6026 clGetKernelSubGroupInfo(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
6027 __GET_KERNEL_SUB_GROUP_INFO_ERR);
6028
6029#else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6030
6031 typedef clGetKernelSubGroupInfoKHR_fn PFN_clGetKernelSubGroupInfoKHR;
6032 static PFN_clGetKernelSubGroupInfoKHR pfn_clGetKernelSubGroupInfoKHR = NULL;
6033 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetKernelSubGroupInfoKHR);
6034
6035 return detail::errHandler(
6036 pfn_clGetKernelSubGroupInfoKHR(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
6037 __GET_KERNEL_SUB_GROUP_INFO_ERR);
6038
6039#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6040 }
6041
6042 template <cl_kernel_sub_group_info name>
6043 size_type getSubGroupInfo(const cl::Device &dev, const cl::NDRange &range, cl_int* err = NULL) const
6044 {
6045 size_type param;
6046 cl_int result = getSubGroupInfo(dev, name, range, &param);
6047 if (err != NULL) {
6048 *err = result;
6049 }
6050 return param;
6051 }
6052#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6053
6054#if CL_HPP_TARGET_OPENCL_VERSION >= 200
6057 template<typename T, class D>
6058 cl_int setArg(cl_uint index, const cl::pointer<T, D> &argPtr)
6059 {
6060 return detail::errHandler(
6061 ::clSetKernelArgSVMPointer(object_, index, argPtr.get()),
6062 __SET_KERNEL_ARGS_ERR);
6063 }
6064
6067 template<typename T, class Alloc>
6068 cl_int setArg(cl_uint index, const cl::vector<T, Alloc> &argPtr)
6069 {
6070 return detail::errHandler(
6071 ::clSetKernelArgSVMPointer(object_, index, argPtr.data()),
6072 __SET_KERNEL_ARGS_ERR);
6073 }
6074
6077 template<typename T>
6078 typename std::enable_if<std::is_pointer<T>::value, cl_int>::type
6079 setArg(cl_uint index, const T argPtr)
6080 {
6081 return detail::errHandler(
6082 ::clSetKernelArgSVMPointer(object_, index, argPtr),
6083 __SET_KERNEL_ARGS_ERR);
6084 }
6085#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6086
6089 template <typename T>
6090 typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6091 setArg(cl_uint index, const T &value)
6092 {
6093 return detail::errHandler(
6094 ::clSetKernelArg(
6095 object_,
6096 index,
6099 __SET_KERNEL_ARGS_ERR);
6100 }
6101
6102 cl_int setArg(cl_uint index, size_type size, const void* argPtr)
6103 {
6104 return detail::errHandler(
6105 ::clSetKernelArg(object_, index, size, argPtr),
6106 __SET_KERNEL_ARGS_ERR);
6107 }
6108
6109#if CL_HPP_TARGET_OPENCL_VERSION >= 200
6114 cl_int setSVMPointers(const vector<void*> &pointerList)
6115 {
6116 return detail::errHandler(
6117 ::clSetKernelExecInfo(
6118 object_,
6119 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6120 sizeof(void*)*pointerList.size(),
6121 pointerList.data()));
6122 }
6123
6128 template<int ArrayLength>
6129 cl_int setSVMPointers(const std::array<void*, ArrayLength> &pointerList)
6130 {
6131 return detail::errHandler(
6132 ::clSetKernelExecInfo(
6133 object_,
6134 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6135 sizeof(void*)*pointerList.size(),
6136 pointerList.data()));
6137 }
6138
6150 cl_int enableFineGrainedSystemSVM(bool svmEnabled)
6151 {
6152 cl_bool svmEnabled_ = svmEnabled ? CL_TRUE : CL_FALSE;
6153 return detail::errHandler(
6154 ::clSetKernelExecInfo(
6155 object_,
6156 CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM,
6157 sizeof(cl_bool),
6158 &svmEnabled_
6159 )
6160 );
6161 }
6162
6163 template<int index, int ArrayLength, class D, typename T0, typename T1, typename... Ts>
6164 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0, const pointer<T1, D> &t1, Ts & ... ts)
6165 {
6166 pointerList[index] = static_cast<void*>(t0.get());
6167 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6168 }
6169
6170 template<int index, int ArrayLength, typename T0, typename T1, typename... Ts>
6171 typename std::enable_if<std::is_pointer<T0>::value, void>::type
6172 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0, T1 t1, Ts... ts)
6173 {
6174 pointerList[index] = static_cast<void*>(t0);
6175 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6176 }
6177
6178 template<int index, int ArrayLength, typename T0, class D>
6179 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0)
6180 {
6181 pointerList[index] = static_cast<void*>(t0.get());
6182 }
6183
6184
6185 template<int index, int ArrayLength, typename T0>
6186 typename std::enable_if<std::is_pointer<T0>::value, void>::type
6187 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0)
6188 {
6189 pointerList[index] = static_cast<void*>(t0);
6190 }
6191
6192 template<typename T0, typename... Ts>
6193 cl_int setSVMPointers(const T0 &t0, Ts & ... ts)
6194 {
6195 std::array<void*, 1 + sizeof...(Ts)> pointerList;
6196
6197 setSVMPointersHelper<0, 1 + sizeof...(Ts)>(pointerList, t0, ts...);
6198 return detail::errHandler(
6199 ::clSetKernelExecInfo(
6200 object_,
6201 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6202 sizeof(void*)*(1 + sizeof...(Ts)),
6203 pointerList.data()));
6204 }
6205
6206 template<typename T>
6207 cl_int setExecInfo(cl_kernel_exec_info param_name, const T& val)
6208 {
6209 return detail::errHandler(
6210 ::clSetKernelExecInfo(
6211 object_,
6212 param_name,
6213 sizeof(T),
6214 &val));
6215 }
6216
6217 template<cl_kernel_exec_info name>
6218 cl_int setExecInfo(typename detail::param_traits<detail::cl_kernel_exec_info, name>::param_type& val)
6219 {
6220 return setExecInfo(name, val);
6221 }
6222#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6223
6224#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6231 {
6232 cl_int error;
6233 Kernel retValue(clCloneKernel(this->get(), &error));
6234
6235 detail::errHandler(error, __CLONE_KERNEL_ERR);
6236 return retValue;
6237 }
6238#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6239};
6240
6244class Program : public detail::Wrapper<cl_program>
6245{
6246public:
6247#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6248 typedef vector<vector<unsigned char>> Binaries;
6249 typedef vector<string> Sources;
6250#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6251 typedef vector<std::pair<const void*, size_type> > Binaries;
6252 typedef vector<std::pair<const char*, size_type> > Sources;
6253#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6254
6255 Program(
6256 const string& source,
6257 bool build = false,
6258 cl_int* err = NULL)
6259 {
6260 cl_int error;
6261
6262 const char * strings = source.c_str();
6263 const size_type length = source.size();
6264
6265 Context context = Context::getDefault(err);
6266
6267 object_ = ::clCreateProgramWithSource(
6268 context(), (cl_uint)1, &strings, &length, &error);
6269
6270 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6271
6272 if (error == CL_SUCCESS && build) {
6273
6274 error = ::clBuildProgram(
6275 object_,
6276 0,
6277 NULL,
6278#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6279 "-cl-std=CL2.0",
6280#else
6281 "",
6282#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6283 NULL,
6284 NULL);
6285
6286 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6287 }
6288
6289 if (err != NULL) {
6290 *err = error;
6291 }
6292 }
6293
6294 Program(
6295 const Context& context,
6296 const string& source,
6297 bool build = false,
6298 cl_int* err = NULL)
6299 {
6300 cl_int error;
6301
6302 const char * strings = source.c_str();
6303 const size_type length = source.size();
6304
6305 object_ = ::clCreateProgramWithSource(
6306 context(), (cl_uint)1, &strings, &length, &error);
6307
6308 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6309
6310 if (error == CL_SUCCESS && build) {
6311 error = ::clBuildProgram(
6312 object_,
6313 0,
6314 NULL,
6315#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6316 "-cl-std=CL2.0",
6317#else
6318 "",
6319#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6320 NULL,
6321 NULL);
6322
6323 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6324 }
6325
6326 if (err != NULL) {
6327 *err = error;
6328 }
6329 }
6330
6336 const Sources& sources,
6337 cl_int* err = NULL)
6338 {
6339 cl_int error;
6340 Context context = Context::getDefault(err);
6341
6342 const size_type n = (size_type)sources.size();
6343
6344 vector<size_type> lengths(n);
6345 vector<const char*> strings(n);
6346
6347 for (size_type i = 0; i < n; ++i) {
6348#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6349 strings[i] = sources[(int)i].data();
6350 lengths[i] = sources[(int)i].length();
6351#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6352 strings[i] = sources[(int)i].first;
6353 lengths[i] = sources[(int)i].second;
6354#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6355 }
6356
6357 object_ = ::clCreateProgramWithSource(
6358 context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6359
6360 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6361 if (err != NULL) {
6362 *err = error;
6363 }
6364 }
6365
6371 const Context& context,
6372 const Sources& sources,
6373 cl_int* err = NULL)
6374 {
6375 cl_int error;
6376
6377 const size_type n = (size_type)sources.size();
6378
6379 vector<size_type> lengths(n);
6380 vector<const char*> strings(n);
6381
6382 for (size_type i = 0; i < n; ++i) {
6383#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6384 strings[i] = sources[(int)i].data();
6385 lengths[i] = sources[(int)i].length();
6386#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6387 strings[i] = sources[(int)i].first;
6388 lengths[i] = sources[(int)i].second;
6389#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6390 }
6391
6392 object_ = ::clCreateProgramWithSource(
6393 context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6394
6395 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6396 if (err != NULL) {
6397 *err = error;
6398 }
6399 }
6400
6401
6402#if CL_HPP_TARGET_OPENCL_VERSION >= 210 || (CL_HPP_TARGET_OPENCL_VERSION==200 && defined(CL_HPP_USE_IL_KHR))
6408 const vector<char>& IL,
6409 bool build = false,
6410 cl_int* err = NULL)
6411 {
6412 cl_int error;
6413
6414 Context context = Context::getDefault(err);
6415
6416#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6417
6418 object_ = ::clCreateProgramWithIL(
6419 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6420
6421#else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6422
6423 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6424 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6425 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6426
6427 return detail::errHandler(
6428 pfn_clCreateProgramWithILKHR(
6429 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6430
6431#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6432
6433 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6434
6435 if (error == CL_SUCCESS && build) {
6436
6437 error = ::clBuildProgram(
6438 object_,
6439 0,
6440 NULL,
6441#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6442 "-cl-std=CL2.0",
6443#else
6444 "",
6445#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6446 NULL,
6447 NULL);
6448
6449 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6450 }
6451
6452 if (err != NULL) {
6453 *err = error;
6454 }
6455 }
6456
6463 const Context& context,
6464 const vector<char>& IL,
6465 bool build = false,
6466 cl_int* err = NULL)
6467 {
6468 cl_int error;
6469
6470#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6471
6472 object_ = ::clCreateProgramWithIL(
6473 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6474
6475#else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6476
6477 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6478 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6479 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6480
6481 return detail::errHandler(
6482 pfn_clCreateProgramWithILKHR(
6483 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6484
6485#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6486
6487 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6488
6489 if (error == CL_SUCCESS && build) {
6490 error = ::clBuildProgram(
6491 object_,
6492 0,
6493 NULL,
6494#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6495 "-cl-std=CL2.0",
6496#else
6497 "",
6498#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6499 NULL,
6500 NULL);
6501
6502 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6503 }
6504
6505 if (err != NULL) {
6506 *err = error;
6507 }
6508 }
6509#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6510
6531 const Context& context,
6532 const vector<Device>& devices,
6533 const Binaries& binaries,
6534 vector<cl_int>* binaryStatus = NULL,
6535 cl_int* err = NULL)
6536 {
6537 cl_int error;
6538
6539 const size_type numDevices = devices.size();
6540
6541 // Catch size mismatch early and return
6542 if(binaries.size() != numDevices) {
6543 error = CL_INVALID_VALUE;
6544 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6545 if (err != NULL) {
6546 *err = error;
6547 }
6548 return;
6549 }
6550
6551
6552 vector<size_type> lengths(numDevices);
6553 vector<const unsigned char*> images(numDevices);
6554#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6555 for (size_type i = 0; i < numDevices; ++i) {
6556 images[i] = binaries[i].data();
6557 lengths[i] = binaries[(int)i].size();
6558 }
6559#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6560 for (size_type i = 0; i < numDevices; ++i) {
6561 images[i] = (const unsigned char*)binaries[i].first;
6562 lengths[i] = binaries[(int)i].second;
6563 }
6564#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6565
6566 vector<cl_device_id> deviceIDs(numDevices);
6567 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6568 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6569 }
6570
6571 if(binaryStatus) {
6572 binaryStatus->resize(numDevices);
6573 }
6574
6575 object_ = ::clCreateProgramWithBinary(
6576 context(), (cl_uint) devices.size(),
6577 deviceIDs.data(),
6578 lengths.data(), images.data(), (binaryStatus != NULL && numDevices > 0)
6579 ? &binaryStatus->front()
6580 : NULL, &error);
6581
6582 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6583 if (err != NULL) {
6584 *err = error;
6585 }
6586 }
6587
6588
6589#if CL_HPP_TARGET_OPENCL_VERSION >= 120
6595 const Context& context,
6596 const vector<Device>& devices,
6597 const string& kernelNames,
6598 cl_int* err = NULL)
6599 {
6600 cl_int error;
6601
6602
6603 size_type numDevices = devices.size();
6604 vector<cl_device_id> deviceIDs(numDevices);
6605 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6606 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6607 }
6608
6609 object_ = ::clCreateProgramWithBuiltInKernels(
6610 context(),
6611 (cl_uint) devices.size(),
6612 deviceIDs.data(),
6613 kernelNames.c_str(),
6614 &error);
6615
6616 detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR);
6617 if (err != NULL) {
6618 *err = error;
6619 }
6620 }
6621#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6622
6623 Program() { }
6624
6625
6632 explicit Program(const cl_program& program, bool retainObject = false) :
6633 detail::Wrapper<cl_type>(program, retainObject) { }
6634
6635 Program& operator = (const cl_program& rhs)
6636 {
6638 return *this;
6639 }
6640
6644 Program(const Program& program) : detail::Wrapper<cl_type>(program) {}
6645
6649 Program& operator = (const Program &program)
6650 {
6652 return *this;
6653 }
6654
6658 Program(Program&& program) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(program)) {}
6659
6663 Program& operator = (Program &&program)
6664 {
6665 detail::Wrapper<cl_type>::operator=(std::move(program));
6666 return *this;
6667 }
6668
6669 cl_int build(
6670 const vector<Device>& devices,
6671 const char* options = NULL,
6672 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6673 void* data = NULL) const
6674 {
6675 size_type numDevices = devices.size();
6676 vector<cl_device_id> deviceIDs(numDevices);
6677
6678 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6679 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6680 }
6681
6682 cl_int buildError = ::clBuildProgram(
6683 object_,
6684 (cl_uint)
6685 devices.size(),
6686 deviceIDs.data(),
6687 options,
6688 notifyFptr,
6689 data);
6690
6691 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6692 }
6693
6694 cl_int build(
6695 const Device& device,
6696 const char* options = NULL,
6697 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6698 void* data = NULL) const
6699 {
6700 cl_device_id deviceID = device();
6701
6702 cl_int buildError = ::clBuildProgram(
6703 object_,
6704 1,
6705 &deviceID,
6706 options,
6707 notifyFptr,
6708 data);
6709
6710 BuildLogType buildLog(1);
6711 buildLog.push_back(std::make_pair(device, getBuildInfo<CL_PROGRAM_BUILD_LOG>(device)));
6712 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, buildLog);
6713 }
6714
6715 cl_int build(
6716 const char* options = NULL,
6717 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6718 void* data = NULL) const
6719 {
6720 cl_int buildError = ::clBuildProgram(
6721 object_,
6722 0,
6723 NULL,
6724 options,
6725 notifyFptr,
6726 data);
6727
6728 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6729 }
6730
6731#if CL_HPP_TARGET_OPENCL_VERSION >= 120
6732 cl_int compile(
6733 const char* options = NULL,
6734 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6735 void* data = NULL) const
6736 {
6737 cl_int error = ::clCompileProgram(
6738 object_,
6739 0,
6740 NULL,
6741 options,
6742 0,
6743 NULL,
6744 NULL,
6745 notifyFptr,
6746 data);
6747 return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6748 }
6749#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6750
6751 template <typename T>
6752 cl_int getInfo(cl_program_info name, T* param) const
6753 {
6754 return detail::errHandler(
6755 detail::getInfo(&::clGetProgramInfo, object_, name, param),
6756 __GET_PROGRAM_INFO_ERR);
6757 }
6758
6759 template <cl_program_info name> typename
6760 detail::param_traits<detail::cl_program_info, name>::param_type
6761 getInfo(cl_int* err = NULL) const
6762 {
6763 typename detail::param_traits<
6764 detail::cl_program_info, name>::param_type param;
6765 cl_int result = getInfo(name, &param);
6766 if (err != NULL) {
6767 *err = result;
6768 }
6769 return param;
6770 }
6771
6772 template <typename T>
6773 cl_int getBuildInfo(
6774 const Device& device, cl_program_build_info name, T* param) const
6775 {
6776 return detail::errHandler(
6777 detail::getInfo(
6778 &::clGetProgramBuildInfo, object_, device(), name, param),
6779 __GET_PROGRAM_BUILD_INFO_ERR);
6780 }
6781
6782 template <cl_program_build_info name> typename
6783 detail::param_traits<detail::cl_program_build_info, name>::param_type
6784 getBuildInfo(const Device& device, cl_int* err = NULL) const
6785 {
6786 typename detail::param_traits<
6787 detail::cl_program_build_info, name>::param_type param;
6788 cl_int result = getBuildInfo(device, name, &param);
6789 if (err != NULL) {
6790 *err = result;
6791 }
6792 return param;
6793 }
6794
6800 template <cl_program_build_info name>
6801 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6802 getBuildInfo(cl_int *err = NULL) const
6803 {
6804 cl_int result = CL_SUCCESS;
6805
6806 auto devs = getInfo<CL_PROGRAM_DEVICES>(&result);
6807 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6808 devInfo;
6809
6810 // If there was an initial error from getInfo return the error
6811 if (result != CL_SUCCESS) {
6812 if (err != NULL) {
6813 *err = result;
6814 }
6815 return devInfo;
6816 }
6817
6818 for (const cl::Device &d : devs) {
6819 typename detail::param_traits<
6820 detail::cl_program_build_info, name>::param_type param;
6821 result = getBuildInfo(d, name, &param);
6822 devInfo.push_back(
6824 (d, param));
6825 if (result != CL_SUCCESS) {
6826 // On error, leave the loop and return the error code
6827 break;
6828 }
6829 }
6830 if (err != NULL) {
6831 *err = result;
6832 }
6833 if (result != CL_SUCCESS) {
6834 devInfo.clear();
6835 }
6836 return devInfo;
6837 }
6838
6839 cl_int createKernels(vector<Kernel>* kernels)
6840 {
6841 cl_uint numKernels;
6842 cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
6843 if (err != CL_SUCCESS) {
6844 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6845 }
6846
6847 vector<cl_kernel> value(numKernels);
6848
6849 err = ::clCreateKernelsInProgram(
6850 object_, numKernels, value.data(), NULL);
6851 if (err != CL_SUCCESS) {
6852 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6853 }
6854
6855 if (kernels) {
6856 kernels->resize(value.size());
6857
6858 // Assign to param, constructing with retain behaviour
6859 // to correctly capture each underlying CL object
6860 for (size_type i = 0; i < value.size(); i++) {
6861 // We do not need to retain because this kernel is being created
6862 // by the runtime
6863 (*kernels)[i] = Kernel(value[i], false);
6864 }
6865 }
6866 return CL_SUCCESS;
6867 }
6868
6869#if CL_HPP_TARGET_OPENCL_VERSION >= 220
6870#if defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
6881 CL_API_PREFIX__VERSION_2_2_DEPRECATED cl_int setReleaseCallback(
6882 void (CL_CALLBACK * pfn_notify)(cl_program program, void * user_data),
6883 void * user_data = NULL) CL_API_SUFFIX__VERSION_2_2_DEPRECATED
6884 {
6885 return detail::errHandler(
6886 ::clSetProgramReleaseCallback(
6887 object_,
6888 pfn_notify,
6889 user_data),
6890 __SET_PROGRAM_RELEASE_CALLBACK_ERR);
6891 }
6892#endif // #if defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
6893
6898 template <typename T>
6899 typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6900 setSpecializationConstant(cl_uint index, const T &value)
6901 {
6902 return detail::errHandler(
6903 ::clSetProgramSpecializationConstant(
6904 object_,
6905 index,
6906 sizeof(value),
6907 &value),
6908 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6909 }
6910
6915 cl_int setSpecializationConstant(cl_uint index, size_type size, const void* value)
6916 {
6917 return detail::errHandler(
6918 ::clSetProgramSpecializationConstant(
6919 object_,
6920 index,
6921 size,
6922 value),
6923 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6924 }
6925#endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
6926};
6927
6928#if CL_HPP_TARGET_OPENCL_VERSION >= 120
6929inline Program linkProgram(
6930 Program input1,
6931 Program input2,
6932 const char* options = NULL,
6933 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6934 void* data = NULL,
6935 cl_int* err = NULL)
6936{
6937 cl_int error_local = CL_SUCCESS;
6938
6939 cl_program programs[2] = { input1(), input2() };
6940
6941 Context ctx = input1.getInfo<CL_PROGRAM_CONTEXT>(&error_local);
6942 if(error_local!=CL_SUCCESS) {
6943 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
6944 }
6945
6946 cl_program prog = ::clLinkProgram(
6947 ctx(),
6948 0,
6949 NULL,
6950 options,
6951 2,
6952 programs,
6953 notifyFptr,
6954 data,
6955 &error_local);
6956
6957 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
6958 if (err != NULL) {
6959 *err = error_local;
6960 }
6961
6962 return Program(prog);
6963}
6964
6965inline Program linkProgram(
6966 vector<Program> inputPrograms,
6967 const char* options = NULL,
6968 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6969 void* data = NULL,
6970 cl_int* err = NULL)
6971{
6972 cl_int error_local = CL_SUCCESS;
6973
6974 vector<cl_program> programs(inputPrograms.size());
6975
6976 for (unsigned int i = 0; i < inputPrograms.size(); i++) {
6977 programs[i] = inputPrograms[i]();
6978 }
6979
6980 Context ctx;
6981 if(inputPrograms.size() > 0) {
6982 ctx = inputPrograms[0].getInfo<CL_PROGRAM_CONTEXT>(&error_local);
6983 if(error_local!=CL_SUCCESS) {
6984 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
6985 }
6986 }
6987 cl_program prog = ::clLinkProgram(
6988 ctx(),
6989 0,
6990 NULL,
6991 options,
6992 (cl_uint)inputPrograms.size(),
6993 programs.data(),
6994 notifyFptr,
6995 data,
6996 &error_local);
6997
6998 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
6999 if (err != NULL) {
7000 *err = error_local;
7001 }
7002
7003 return Program(prog, false);
7004}
7005#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7006
7007// Template specialization for CL_PROGRAM_BINARIES
7008template <>
7009inline cl_int cl::Program::getInfo(cl_program_info name, vector<vector<unsigned char>>* param) const
7010{
7011 if (name != CL_PROGRAM_BINARIES) {
7012 return CL_INVALID_VALUE;
7013 }
7014 if (param) {
7015 // Resize the parameter array appropriately for each allocation
7016 // and pass down to the helper
7017
7018 vector<size_type> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>();
7019 size_type numBinaries = sizes.size();
7020
7021 // Resize the parameter array and constituent arrays
7022 param->resize(numBinaries);
7023 for (size_type i = 0; i < numBinaries; ++i) {
7024 (*param)[i].resize(sizes[i]);
7025 }
7026
7027 return detail::errHandler(
7028 detail::getInfo(&::clGetProgramInfo, object_, name, param),
7029 __GET_PROGRAM_INFO_ERR);
7030 }
7031
7032 return CL_SUCCESS;
7033}
7034
7035template<>
7036inline vector<vector<unsigned char>> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err) const
7037{
7038 vector<vector<unsigned char>> binariesVectors;
7039
7040 cl_int result = getInfo(CL_PROGRAM_BINARIES, &binariesVectors);
7041 if (err != NULL) {
7042 *err = result;
7043 }
7044 return binariesVectors;
7045}
7046
7047#if CL_HPP_TARGET_OPENCL_VERSION >= 220
7048// Template specialization for clSetProgramSpecializationConstant
7049template <>
7050inline cl_int cl::Program::setSpecializationConstant(cl_uint index, const bool &value)
7051{
7052 cl_uchar ucValue = value ? CL_UCHAR_MAX : 0;
7053 return detail::errHandler(
7054 ::clSetProgramSpecializationConstant(
7055 object_,
7056 index,
7057 sizeof(ucValue),
7058 &ucValue),
7059 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
7060}
7061#endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
7062
7063inline Kernel::Kernel(const Program& program, const char* name, cl_int* err)
7064{
7065 cl_int error;
7066
7067 object_ = ::clCreateKernel(program(), name, &error);
7068 detail::errHandler(error, __CREATE_KERNEL_ERR);
7069
7070 if (err != NULL) {
7071 *err = error;
7072 }
7073
7074}
7075
7076enum class QueueProperties : cl_command_queue_properties
7077{
7078 None = 0,
7079 Profiling = CL_QUEUE_PROFILING_ENABLE,
7080 OutOfOrder = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,
7081};
7082
7083inline QueueProperties operator|(QueueProperties lhs, QueueProperties rhs)
7084{
7085 return static_cast<QueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
7086}
7087
7091class CommandQueue : public detail::Wrapper<cl_command_queue>
7092{
7093private:
7094 static std::once_flag default_initialized_;
7095 static CommandQueue default_;
7096 static cl_int default_error_;
7097
7103 static void makeDefault()
7104 {
7105 /* We don't want to throw an error from this function, so we have to
7106 * catch and set the error flag.
7107 */
7108#if defined(CL_HPP_ENABLE_EXCEPTIONS)
7109 try
7110#endif
7111 {
7112 int error;
7113 Context context = Context::getDefault(&error);
7114
7115 if (error != CL_SUCCESS) {
7116 default_error_ = error;
7117 }
7118 else {
7119 Device device = Device::getDefault();
7120 default_ = CommandQueue(context, device, 0, &default_error_);
7121 }
7122 }
7123#if defined(CL_HPP_ENABLE_EXCEPTIONS)
7124 catch (cl::Error &e) {
7125 default_error_ = e.err();
7126 }
7127#endif
7128 }
7129
7135 static void makeDefaultProvided(const CommandQueue &c) {
7136 default_ = c;
7137 }
7138
7139public:
7140#ifdef CL_HPP_UNIT_TEST_ENABLE
7147 static void unitTestClearDefault() {
7148 default_ = CommandQueue();
7149 }
7150#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
7151
7152
7158 cl_command_queue_properties properties,
7159 cl_int* err = NULL)
7160 {
7161 cl_int error;
7162
7163 Context context = Context::getDefault(&error);
7164 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7165
7166 if (error != CL_SUCCESS) {
7167 if (err != NULL) {
7168 *err = error;
7169 }
7170 }
7171 else {
7172 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7173 bool useWithProperties;
7174
7175#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7176 // Run-time decision based on the actual platform
7177 {
7178 cl_uint version = detail::getContextPlatformVersion(context());
7179 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7180 }
7181#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7182 useWithProperties = true;
7183#else
7184 useWithProperties = false;
7185#endif
7186
7187#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7188 if (useWithProperties) {
7189 cl_queue_properties queue_properties[] = {
7190 CL_QUEUE_PROPERTIES, properties, 0 };
7191 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7192 object_ = ::clCreateCommandQueueWithProperties(
7193 context(), device(), queue_properties, &error);
7194 }
7195 else {
7196 error = CL_INVALID_QUEUE_PROPERTIES;
7197 }
7198
7199 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7200 if (err != NULL) {
7201 *err = error;
7202 }
7203 }
7204#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7205#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7206 if (!useWithProperties) {
7207 object_ = ::clCreateCommandQueue(
7208 context(), device(), properties, &error);
7209
7210 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7211 if (err != NULL) {
7212 *err = error;
7213 }
7214 }
7215#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7216 }
7217 }
7218
7224 QueueProperties properties,
7225 cl_int* err = NULL)
7226 {
7227 cl_int error;
7228
7229 Context context = Context::getDefault(&error);
7230 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7231
7232 if (error != CL_SUCCESS) {
7233 if (err != NULL) {
7234 *err = error;
7235 }
7236 }
7237 else {
7238 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7239 bool useWithProperties;
7240
7241#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7242 // Run-time decision based on the actual platform
7243 {
7244 cl_uint version = detail::getContextPlatformVersion(context());
7245 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7246 }
7247#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7248 useWithProperties = true;
7249#else
7250 useWithProperties = false;
7251#endif
7252
7253#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7254 if (useWithProperties) {
7255 cl_queue_properties queue_properties[] = {
7256 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7257
7258 object_ = ::clCreateCommandQueueWithProperties(
7259 context(), device(), queue_properties, &error);
7260
7261 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7262 if (err != NULL) {
7263 *err = error;
7264 }
7265 }
7266#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7267#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7268 if (!useWithProperties) {
7269 object_ = ::clCreateCommandQueue(
7270 context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
7271
7272 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7273 if (err != NULL) {
7274 *err = error;
7275 }
7276 }
7277#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7278
7279 }
7280 }
7281
7287 const Context& context,
7288 cl_command_queue_properties properties = 0,
7289 cl_int* err = NULL)
7290 {
7291 cl_int error;
7292 bool useWithProperties;
7293 vector<cl::Device> devices;
7294 error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7295
7296 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7297
7298 if (error != CL_SUCCESS)
7299 {
7300 if (err != NULL) {
7301 *err = error;
7302 }
7303 return;
7304 }
7305
7306#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7307 // Run-time decision based on the actual platform
7308 {
7309 cl_uint version = detail::getContextPlatformVersion(context());
7310 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7311 }
7312#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7313 useWithProperties = true;
7314#else
7315 useWithProperties = false;
7316#endif
7317
7318#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7319 if (useWithProperties) {
7320 cl_queue_properties queue_properties[] = {
7321 CL_QUEUE_PROPERTIES, properties, 0 };
7322 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7323 object_ = ::clCreateCommandQueueWithProperties(
7324 context(), devices[0](), queue_properties, &error);
7325 }
7326 else {
7327 error = CL_INVALID_QUEUE_PROPERTIES;
7328 }
7329
7330 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7331 if (err != NULL) {
7332 *err = error;
7333 }
7334 }
7335#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7336#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7337 if (!useWithProperties) {
7338 object_ = ::clCreateCommandQueue(
7339 context(), devices[0](), properties, &error);
7340
7341 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7342 if (err != NULL) {
7343 *err = error;
7344 }
7345 }
7346#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7347 }
7348
7354 const Context& context,
7355 QueueProperties properties,
7356 cl_int* err = NULL)
7357 {
7358 cl_int error;
7359 bool useWithProperties;
7360 vector<cl::Device> devices;
7361 error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7362
7363 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7364
7365 if (error != CL_SUCCESS)
7366 {
7367 if (err != NULL) {
7368 *err = error;
7369 }
7370 return;
7371 }
7372
7373#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7374 // Run-time decision based on the actual platform
7375 {
7376 cl_uint version = detail::getContextPlatformVersion(context());
7377 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7378 }
7379#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7380 useWithProperties = true;
7381#else
7382 useWithProperties = false;
7383#endif
7384
7385#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7386 if (useWithProperties) {
7387 cl_queue_properties queue_properties[] = {
7388 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7389 object_ = ::clCreateCommandQueueWithProperties(
7390 context(), devices[0](), queue_properties, &error);
7391
7392 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7393 if (err != NULL) {
7394 *err = error;
7395 }
7396 }
7397#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7398#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7399 if (!useWithProperties) {
7400 object_ = ::clCreateCommandQueue(
7401 context(), devices[0](), static_cast<cl_command_queue_properties>(properties), &error);
7402
7403 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7404 if (err != NULL) {
7405 *err = error;
7406 }
7407 }
7408#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7409 }
7410
7416 const Context& context,
7417 const Device& device,
7418 cl_command_queue_properties properties = 0,
7419 cl_int* err = NULL)
7420 {
7421 cl_int error;
7422 bool useWithProperties;
7423
7424#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7425 // Run-time decision based on the actual platform
7426 {
7427 cl_uint version = detail::getContextPlatformVersion(context());
7428 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7429 }
7430#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7431 useWithProperties = true;
7432#else
7433 useWithProperties = false;
7434#endif
7435
7436#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7437 if (useWithProperties) {
7438 cl_queue_properties queue_properties[] = {
7439 CL_QUEUE_PROPERTIES, properties, 0 };
7440 object_ = ::clCreateCommandQueueWithProperties(
7441 context(), device(), queue_properties, &error);
7442
7443 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7444 if (err != NULL) {
7445 *err = error;
7446 }
7447 }
7448#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7449#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7450 if (!useWithProperties) {
7451 object_ = ::clCreateCommandQueue(
7452 context(), device(), properties, &error);
7453
7454 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7455 if (err != NULL) {
7456 *err = error;
7457 }
7458 }
7459#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7460 }
7461
7467 const Context& context,
7468 const Device& device,
7469 QueueProperties properties,
7470 cl_int* err = NULL)
7471 {
7472 cl_int error;
7473 bool useWithProperties;
7474
7475#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7476 // Run-time decision based on the actual platform
7477 {
7478 cl_uint version = detail::getContextPlatformVersion(context());
7479 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7480 }
7481#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7482 useWithProperties = true;
7483#else
7484 useWithProperties = false;
7485#endif
7486
7487#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7488 if (useWithProperties) {
7489 cl_queue_properties queue_properties[] = {
7490 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7491 object_ = ::clCreateCommandQueueWithProperties(
7492 context(), device(), queue_properties, &error);
7493
7494 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7495 if (err != NULL) {
7496 *err = error;
7497 }
7498 }
7499#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7500#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7501 if (!useWithProperties) {
7502 object_ = ::clCreateCommandQueue(
7503 context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
7504
7505 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7506 if (err != NULL) {
7507 *err = error;
7508 }
7509 }
7510#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7511 }
7512
7513 static CommandQueue getDefault(cl_int * err = NULL)
7514 {
7515 std::call_once(default_initialized_, makeDefault);
7516#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7517 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7518#else // CL_HPP_TARGET_OPENCL_VERSION >= 200
7519 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_ERR);
7520#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7521 if (err != NULL) {
7522 *err = default_error_;
7523 }
7524 return default_;
7525 }
7526
7534 static CommandQueue setDefault(const CommandQueue &default_queue)
7535 {
7536 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_queue));
7537 detail::errHandler(default_error_);
7538 return default_;
7539 }
7540
7541 CommandQueue() { }
7542
7543
7550 explicit CommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
7551 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
7552
7553 CommandQueue& operator = (const cl_command_queue& rhs)
7554 {
7556 return *this;
7557 }
7558
7562 CommandQueue(const CommandQueue& queue) : detail::Wrapper<cl_type>(queue) {}
7563
7567 CommandQueue& operator = (const CommandQueue &queue)
7568 {
7570 return *this;
7571 }
7572
7576 CommandQueue(CommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(queue)) {}
7577
7581 CommandQueue& operator = (CommandQueue &&queue)
7582 {
7583 detail::Wrapper<cl_type>::operator=(std::move(queue));
7584 return *this;
7585 }
7586
7587 template <typename T>
7588 cl_int getInfo(cl_command_queue_info name, T* param) const
7589 {
7590 return detail::errHandler(
7591 detail::getInfo(
7592 &::clGetCommandQueueInfo, object_, name, param),
7593 __GET_COMMAND_QUEUE_INFO_ERR);
7594 }
7595
7596 template <cl_command_queue_info name> typename
7597 detail::param_traits<detail::cl_command_queue_info, name>::param_type
7598 getInfo(cl_int* err = NULL) const
7599 {
7600 typename detail::param_traits<
7601 detail::cl_command_queue_info, name>::param_type param;
7602 cl_int result = getInfo(name, &param);
7603 if (err != NULL) {
7604 *err = result;
7605 }
7606 return param;
7607 }
7608
7609 cl_int enqueueReadBuffer(
7610 const Buffer& buffer,
7611 cl_bool blocking,
7612 size_type offset,
7613 size_type size,
7614 void* ptr,
7615 const vector<Event>* events = NULL,
7616 Event* event = NULL) const
7617 {
7618 cl_event tmp;
7619 cl_int err = detail::errHandler(
7620 ::clEnqueueReadBuffer(
7621 object_, buffer(), blocking, offset, size,
7622 ptr,
7623 (events != NULL) ? (cl_uint) events->size() : 0,
7624 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7625 (event != NULL) ? &tmp : NULL),
7626 __ENQUEUE_READ_BUFFER_ERR);
7627
7628 if (event != NULL && err == CL_SUCCESS)
7629 *event = tmp;
7630
7631 return err;
7632 }
7633
7634 cl_int enqueueWriteBuffer(
7635 const Buffer& buffer,
7636 cl_bool blocking,
7637 size_type offset,
7638 size_type size,
7639 const void* ptr,
7640 const vector<Event>* events = NULL,
7641 Event* event = NULL) const
7642 {
7643 cl_event tmp;
7644 cl_int err = detail::errHandler(
7645 ::clEnqueueWriteBuffer(
7646 object_, buffer(), blocking, offset, size,
7647 ptr,
7648 (events != NULL) ? (cl_uint) events->size() : 0,
7649 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7650 (event != NULL) ? &tmp : NULL),
7651 __ENQUEUE_WRITE_BUFFER_ERR);
7652
7653 if (event != NULL && err == CL_SUCCESS)
7654 *event = tmp;
7655
7656 return err;
7657 }
7658
7659 cl_int enqueueCopyBuffer(
7660 const Buffer& src,
7661 const Buffer& dst,
7662 size_type src_offset,
7663 size_type dst_offset,
7664 size_type size,
7665 const vector<Event>* events = NULL,
7666 Event* event = NULL) const
7667 {
7668 cl_event tmp;
7669 cl_int err = detail::errHandler(
7670 ::clEnqueueCopyBuffer(
7671 object_, src(), dst(), src_offset, dst_offset, size,
7672 (events != NULL) ? (cl_uint) events->size() : 0,
7673 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7674 (event != NULL) ? &tmp : NULL),
7675 __ENQEUE_COPY_BUFFER_ERR);
7676
7677 if (event != NULL && err == CL_SUCCESS)
7678 *event = tmp;
7679
7680 return err;
7681 }
7682#if CL_HPP_TARGET_OPENCL_VERSION >= 110
7683 cl_int enqueueReadBufferRect(
7684 const Buffer& buffer,
7685 cl_bool blocking,
7686 const array<size_type, 3>& buffer_offset,
7687 const array<size_type, 3>& host_offset,
7688 const array<size_type, 3>& region,
7689 size_type buffer_row_pitch,
7690 size_type buffer_slice_pitch,
7691 size_type host_row_pitch,
7692 size_type host_slice_pitch,
7693 void *ptr,
7694 const vector<Event>* events = NULL,
7695 Event* event = NULL) const
7696 {
7697 cl_event tmp;
7698 cl_int err = detail::errHandler(
7699 ::clEnqueueReadBufferRect(
7700 object_,
7701 buffer(),
7702 blocking,
7703 buffer_offset.data(),
7704 host_offset.data(),
7705 region.data(),
7706 buffer_row_pitch,
7707 buffer_slice_pitch,
7708 host_row_pitch,
7709 host_slice_pitch,
7710 ptr,
7711 (events != NULL) ? (cl_uint) events->size() : 0,
7712 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7713 (event != NULL) ? &tmp : NULL),
7714 __ENQUEUE_READ_BUFFER_RECT_ERR);
7715
7716 if (event != NULL && err == CL_SUCCESS)
7717 *event = tmp;
7718
7719 return err;
7720 }
7721
7722 cl_int enqueueWriteBufferRect(
7723 const Buffer& buffer,
7724 cl_bool blocking,
7725 const array<size_type, 3>& buffer_offset,
7726 const array<size_type, 3>& host_offset,
7727 const array<size_type, 3>& region,
7728 size_type buffer_row_pitch,
7729 size_type buffer_slice_pitch,
7730 size_type host_row_pitch,
7731 size_type host_slice_pitch,
7732 const void *ptr,
7733 const vector<Event>* events = NULL,
7734 Event* event = NULL) const
7735 {
7736 cl_event tmp;
7737 cl_int err = detail::errHandler(
7738 ::clEnqueueWriteBufferRect(
7739 object_,
7740 buffer(),
7741 blocking,
7742 buffer_offset.data(),
7743 host_offset.data(),
7744 region.data(),
7745 buffer_row_pitch,
7746 buffer_slice_pitch,
7747 host_row_pitch,
7748 host_slice_pitch,
7749 ptr,
7750 (events != NULL) ? (cl_uint) events->size() : 0,
7751 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7752 (event != NULL) ? &tmp : NULL),
7753 __ENQUEUE_WRITE_BUFFER_RECT_ERR);
7754
7755 if (event != NULL && err == CL_SUCCESS)
7756 *event = tmp;
7757
7758 return err;
7759 }
7760
7761 cl_int enqueueCopyBufferRect(
7762 const Buffer& src,
7763 const Buffer& dst,
7764 const array<size_type, 3>& src_origin,
7765 const array<size_type, 3>& dst_origin,
7766 const array<size_type, 3>& region,
7767 size_type src_row_pitch,
7768 size_type src_slice_pitch,
7769 size_type dst_row_pitch,
7770 size_type dst_slice_pitch,
7771 const vector<Event>* events = NULL,
7772 Event* event = NULL) const
7773 {
7774 cl_event tmp;
7775 cl_int err = detail::errHandler(
7776 ::clEnqueueCopyBufferRect(
7777 object_,
7778 src(),
7779 dst(),
7780 src_origin.data(),
7781 dst_origin.data(),
7782 region.data(),
7783 src_row_pitch,
7784 src_slice_pitch,
7785 dst_row_pitch,
7786 dst_slice_pitch,
7787 (events != NULL) ? (cl_uint) events->size() : 0,
7788 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7789 (event != NULL) ? &tmp : NULL),
7790 __ENQEUE_COPY_BUFFER_RECT_ERR);
7791
7792 if (event != NULL && err == CL_SUCCESS)
7793 *event = tmp;
7794
7795 return err;
7796 }
7797#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
7798#if CL_HPP_TARGET_OPENCL_VERSION >= 120
7810 template<typename PatternType>
7812 const Buffer& buffer,
7813 PatternType pattern,
7814 size_type offset,
7815 size_type size,
7816 const vector<Event>* events = NULL,
7817 Event* event = NULL) const
7818 {
7819 cl_event tmp;
7820 cl_int err = detail::errHandler(
7821 ::clEnqueueFillBuffer(
7822 object_,
7823 buffer(),
7824 static_cast<void*>(&pattern),
7825 sizeof(PatternType),
7826 offset,
7827 size,
7828 (events != NULL) ? (cl_uint) events->size() : 0,
7829 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7830 (event != NULL) ? &tmp : NULL),
7831 __ENQUEUE_FILL_BUFFER_ERR);
7832
7833 if (event != NULL && err == CL_SUCCESS)
7834 *event = tmp;
7835
7836 return err;
7837 }
7838#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7839
7840 cl_int enqueueReadImage(
7841 const Image& image,
7842 cl_bool blocking,
7843 const array<size_type, 3>& origin,
7844 const array<size_type, 3>& region,
7845 size_type row_pitch,
7846 size_type slice_pitch,
7847 void* ptr,
7848 const vector<Event>* events = NULL,
7849 Event* event = NULL) const
7850 {
7851 cl_event tmp;
7852 cl_int err = detail::errHandler(
7853 ::clEnqueueReadImage(
7854 object_,
7855 image(),
7856 blocking,
7857 origin.data(),
7858 region.data(),
7859 row_pitch,
7860 slice_pitch,
7861 ptr,
7862 (events != NULL) ? (cl_uint) events->size() : 0,
7863 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7864 (event != NULL) ? &tmp : NULL),
7865 __ENQUEUE_READ_IMAGE_ERR);
7866
7867 if (event != NULL && err == CL_SUCCESS)
7868 *event = tmp;
7869
7870 return err;
7871 }
7872
7873 cl_int enqueueWriteImage(
7874 const Image& image,
7875 cl_bool blocking,
7876 const array<size_type, 3>& origin,
7877 const array<size_type, 3>& region,
7878 size_type row_pitch,
7879 size_type slice_pitch,
7880 const void* ptr,
7881 const vector<Event>* events = NULL,
7882 Event* event = NULL) const
7883 {
7884 cl_event tmp;
7885 cl_int err = detail::errHandler(
7886 ::clEnqueueWriteImage(
7887 object_,
7888 image(),
7889 blocking,
7890 origin.data(),
7891 region.data(),
7892 row_pitch,
7893 slice_pitch,
7894 ptr,
7895 (events != NULL) ? (cl_uint) events->size() : 0,
7896 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7897 (event != NULL) ? &tmp : NULL),
7898 __ENQUEUE_WRITE_IMAGE_ERR);
7899
7900 if (event != NULL && err == CL_SUCCESS)
7901 *event = tmp;
7902
7903 return err;
7904 }
7905
7906 cl_int enqueueCopyImage(
7907 const Image& src,
7908 const Image& dst,
7909 const array<size_type, 3>& src_origin,
7910 const array<size_type, 3>& dst_origin,
7911 const array<size_type, 3>& region,
7912 const vector<Event>* events = NULL,
7913 Event* event = NULL) const
7914 {
7915 cl_event tmp;
7916 cl_int err = detail::errHandler(
7917 ::clEnqueueCopyImage(
7918 object_,
7919 src(),
7920 dst(),
7921 src_origin.data(),
7922 dst_origin.data(),
7923 region.data(),
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_COPY_IMAGE_ERR);
7928
7929 if (event != NULL && err == CL_SUCCESS)
7930 *event = tmp;
7931
7932 return err;
7933 }
7934
7935#if CL_HPP_TARGET_OPENCL_VERSION >= 120
7944 const Image& image,
7945 cl_float4 fillColor,
7946 const array<size_type, 3>& origin,
7947 const array<size_type, 3>& region,
7948 const vector<Event>* events = NULL,
7949 Event* event = NULL) const
7950 {
7951 cl_event tmp;
7952 cl_int err = detail::errHandler(
7953 ::clEnqueueFillImage(
7954 object_,
7955 image(),
7956 static_cast<void*>(&fillColor),
7957 origin.data(),
7958 region.data(),
7959 (events != NULL) ? (cl_uint) events->size() : 0,
7960 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7961 (event != NULL) ? &tmp : NULL),
7962 __ENQUEUE_FILL_IMAGE_ERR);
7963
7964 if (event != NULL && err == CL_SUCCESS)
7965 *event = tmp;
7966
7967 return err;
7968 }
7969
7978 const Image& image,
7979 cl_int4 fillColor,
7980 const array<size_type, 3>& origin,
7981 const array<size_type, 3>& region,
7982 const vector<Event>* events = NULL,
7983 Event* event = NULL) const
7984 {
7985 cl_event tmp;
7986 cl_int err = detail::errHandler(
7987 ::clEnqueueFillImage(
7988 object_,
7989 image(),
7990 static_cast<void*>(&fillColor),
7991 origin.data(),
7992 region.data(),
7993 (events != NULL) ? (cl_uint) events->size() : 0,
7994 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7995 (event != NULL) ? &tmp : NULL),
7996 __ENQUEUE_FILL_IMAGE_ERR);
7997
7998 if (event != NULL && err == CL_SUCCESS)
7999 *event = tmp;
8000
8001 return err;
8002 }
8003
8012 const Image& image,
8013 cl_uint4 fillColor,
8014 const array<size_type, 3>& origin,
8015 const array<size_type, 3>& region,
8016 const vector<Event>* events = NULL,
8017 Event* event = NULL) const
8018 {
8019 cl_event tmp;
8020 cl_int err = detail::errHandler(
8021 ::clEnqueueFillImage(
8022 object_,
8023 image(),
8024 static_cast<void*>(&fillColor),
8025 origin.data(),
8026 region.data(),
8027 (events != NULL) ? (cl_uint) events->size() : 0,
8028 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8029 (event != NULL) ? &tmp : NULL),
8030 __ENQUEUE_FILL_IMAGE_ERR);
8031
8032 if (event != NULL && err == CL_SUCCESS)
8033 *event = tmp;
8034
8035 return err;
8036 }
8037#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8038
8039 cl_int enqueueCopyImageToBuffer(
8040 const Image& src,
8041 const Buffer& dst,
8042 const array<size_type, 3>& src_origin,
8043 const array<size_type, 3>& region,
8044 size_type dst_offset,
8045 const vector<Event>* events = NULL,
8046 Event* event = NULL) const
8047 {
8048 cl_event tmp;
8049 cl_int err = detail::errHandler(
8050 ::clEnqueueCopyImageToBuffer(
8051 object_,
8052 src(),
8053 dst(),
8054 src_origin.data(),
8055 region.data(),
8056 dst_offset,
8057 (events != NULL) ? (cl_uint) events->size() : 0,
8058 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8059 (event != NULL) ? &tmp : NULL),
8060 __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
8061
8062 if (event != NULL && err == CL_SUCCESS)
8063 *event = tmp;
8064
8065 return err;
8066 }
8067
8068 cl_int enqueueCopyBufferToImage(
8069 const Buffer& src,
8070 const Image& dst,
8071 size_type src_offset,
8072 const array<size_type, 3>& dst_origin,
8073 const array<size_type, 3>& region,
8074 const vector<Event>* events = NULL,
8075 Event* event = NULL) const
8076 {
8077 cl_event tmp;
8078 cl_int err = detail::errHandler(
8079 ::clEnqueueCopyBufferToImage(
8080 object_,
8081 src(),
8082 dst(),
8083 src_offset,
8084 dst_origin.data(),
8085 region.data(),
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_BUFFER_TO_IMAGE_ERR);
8090
8091 if (event != NULL && err == CL_SUCCESS)
8092 *event = tmp;
8093
8094 return err;
8095 }
8096
8097 void* enqueueMapBuffer(
8098 const Buffer& buffer,
8099 cl_bool blocking,
8100 cl_map_flags flags,
8101 size_type offset,
8102 size_type size,
8103 const vector<Event>* events = NULL,
8104 Event* event = NULL,
8105 cl_int* err = NULL) const
8106 {
8107 cl_event tmp;
8108 cl_int error;
8109 void * result = ::clEnqueueMapBuffer(
8110 object_, buffer(), blocking, flags, offset, size,
8111 (events != NULL) ? (cl_uint) events->size() : 0,
8112 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8113 (event != NULL) ? &tmp : NULL,
8114 &error);
8115
8116 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
8117 if (err != NULL) {
8118 *err = error;
8119 }
8120 if (event != NULL && error == CL_SUCCESS)
8121 *event = tmp;
8122
8123 return result;
8124 }
8125
8126 void* enqueueMapImage(
8127 const Image& buffer,
8128 cl_bool blocking,
8129 cl_map_flags flags,
8130 const array<size_type, 3>& origin,
8131 const array<size_type, 3>& region,
8132 size_type * row_pitch,
8133 size_type * slice_pitch,
8134 const vector<Event>* events = NULL,
8135 Event* event = NULL,
8136 cl_int* err = NULL) const
8137 {
8138 cl_event tmp;
8139 cl_int error;
8140 void * result = ::clEnqueueMapImage(
8141 object_, buffer(), blocking, flags,
8142 origin.data(),
8143 region.data(),
8144 row_pitch, slice_pitch,
8145 (events != NULL) ? (cl_uint) events->size() : 0,
8146 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8147 (event != NULL) ? &tmp : NULL,
8148 &error);
8149
8150 detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
8151 if (err != NULL) {
8152 *err = error;
8153 }
8154 if (event != NULL && error == CL_SUCCESS)
8155 *event = tmp;
8156 return result;
8157 }
8158
8159#if CL_HPP_TARGET_OPENCL_VERSION >= 200
8164 template<typename T>
8166 T* ptr,
8167 cl_bool blocking,
8168 cl_map_flags flags,
8169 size_type size,
8170 const vector<Event>* events = NULL,
8171 Event* event = NULL) const
8172 {
8173 cl_event tmp;
8174 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8175 object_, blocking, flags, static_cast<void*>(ptr), size,
8176 (events != NULL) ? (cl_uint)events->size() : 0,
8177 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8178 (event != NULL) ? &tmp : NULL),
8179 __ENQUEUE_MAP_BUFFER_ERR);
8180
8181 if (event != NULL && err == CL_SUCCESS)
8182 *event = tmp;
8183
8184 return err;
8185 }
8186
8187
8192 template<typename T, class D>
8194 cl::pointer<T, D> &ptr,
8195 cl_bool blocking,
8196 cl_map_flags flags,
8197 size_type size,
8198 const vector<Event>* events = NULL,
8199 Event* event = NULL) const
8200 {
8201 cl_event tmp;
8202 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8203 object_, blocking, flags, static_cast<void*>(ptr.get()), size,
8204 (events != NULL) ? (cl_uint)events->size() : 0,
8205 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8206 (event != NULL) ? &tmp : NULL),
8207 __ENQUEUE_MAP_BUFFER_ERR);
8208
8209 if (event != NULL && err == CL_SUCCESS)
8210 *event = tmp;
8211
8212 return err;
8213 }
8214
8219 template<typename T, class Alloc>
8221 cl::vector<T, Alloc> &container,
8222 cl_bool blocking,
8223 cl_map_flags flags,
8224 const vector<Event>* events = NULL,
8225 Event* event = NULL) const
8226 {
8227 cl_event tmp;
8228 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8229 object_, blocking, flags, static_cast<void*>(container.data()), container.size()*sizeof(T),
8230 (events != NULL) ? (cl_uint)events->size() : 0,
8231 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8232 (event != NULL) ? &tmp : NULL),
8233 __ENQUEUE_MAP_BUFFER_ERR);
8234
8235 if (event != NULL && err == CL_SUCCESS)
8236 *event = tmp;
8237
8238 return err;
8239 }
8240#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8241
8242 cl_int enqueueUnmapMemObject(
8243 const Memory& memory,
8244 void* mapped_ptr,
8245 const vector<Event>* events = NULL,
8246 Event* event = NULL) const
8247 {
8248 cl_event tmp;
8249 cl_int err = detail::errHandler(
8250 ::clEnqueueUnmapMemObject(
8251 object_, memory(), mapped_ptr,
8252 (events != NULL) ? (cl_uint) events->size() : 0,
8253 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8254 (event != NULL) ? &tmp : NULL),
8255 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8256
8257 if (event != NULL && err == CL_SUCCESS)
8258 *event = tmp;
8259
8260 return err;
8261 }
8262
8263
8264#if CL_HPP_TARGET_OPENCL_VERSION >= 200
8269 template<typename T>
8271 T* ptr,
8272 const vector<Event>* events = NULL,
8273 Event* event = NULL) const
8274 {
8275 cl_event tmp;
8276 cl_int err = detail::errHandler(
8277 ::clEnqueueSVMUnmap(
8278 object_, static_cast<void*>(ptr),
8279 (events != NULL) ? (cl_uint)events->size() : 0,
8280 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8281 (event != NULL) ? &tmp : NULL),
8282 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8283
8284 if (event != NULL && err == CL_SUCCESS)
8285 *event = tmp;
8286
8287 return err;
8288 }
8289
8294 template<typename T, class D>
8296 cl::pointer<T, D> &ptr,
8297 const vector<Event>* events = NULL,
8298 Event* event = NULL) const
8299 {
8300 cl_event tmp;
8301 cl_int err = detail::errHandler(
8302 ::clEnqueueSVMUnmap(
8303 object_, static_cast<void*>(ptr.get()),
8304 (events != NULL) ? (cl_uint)events->size() : 0,
8305 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8306 (event != NULL) ? &tmp : NULL),
8307 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8308
8309 if (event != NULL && err == CL_SUCCESS)
8310 *event = tmp;
8311
8312 return err;
8313 }
8314
8319 template<typename T, class Alloc>
8321 cl::vector<T, Alloc> &container,
8322 const vector<Event>* events = NULL,
8323 Event* event = NULL) const
8324 {
8325 cl_event tmp;
8326 cl_int err = detail::errHandler(
8327 ::clEnqueueSVMUnmap(
8328 object_, static_cast<void*>(container.data()),
8329 (events != NULL) ? (cl_uint)events->size() : 0,
8330 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8331 (event != NULL) ? &tmp : NULL),
8332 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8333
8334 if (event != NULL && err == CL_SUCCESS)
8335 *event = tmp;
8336
8337 return err;
8338 }
8339#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8340
8341#if CL_HPP_TARGET_OPENCL_VERSION >= 120
8354 const vector<Event> *events = 0,
8355 Event *event = 0) const
8356 {
8357 cl_event tmp;
8358 cl_int err = detail::errHandler(
8359 ::clEnqueueMarkerWithWaitList(
8360 object_,
8361 (events != NULL) ? (cl_uint) events->size() : 0,
8362 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8363 (event != NULL) ? &tmp : NULL),
8364 __ENQUEUE_MARKER_WAIT_LIST_ERR);
8365
8366 if (event != NULL && err == CL_SUCCESS)
8367 *event = tmp;
8368
8369 return err;
8370 }
8371
8384 const vector<Event> *events = 0,
8385 Event *event = 0) const
8386 {
8387 cl_event tmp;
8388 cl_int err = detail::errHandler(
8389 ::clEnqueueBarrierWithWaitList(
8390 object_,
8391 (events != NULL) ? (cl_uint) events->size() : 0,
8392 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8393 (event != NULL) ? &tmp : NULL),
8394 __ENQUEUE_BARRIER_WAIT_LIST_ERR);
8395
8396 if (event != NULL && err == CL_SUCCESS)
8397 *event = tmp;
8398
8399 return err;
8400 }
8401
8407 const vector<Memory> &memObjects,
8408 cl_mem_migration_flags flags,
8409 const vector<Event>* events = NULL,
8410 Event* event = NULL
8411 ) const
8412 {
8413 cl_event tmp;
8414
8415 vector<cl_mem> localMemObjects(memObjects.size());
8416
8417 for( int i = 0; i < (int)memObjects.size(); ++i ) {
8418 localMemObjects[i] = memObjects[i]();
8419 }
8420
8421 cl_int err = detail::errHandler(
8422 ::clEnqueueMigrateMemObjects(
8423 object_,
8424 (cl_uint)memObjects.size(),
8425 localMemObjects.data(),
8426 flags,
8427 (events != NULL) ? (cl_uint) events->size() : 0,
8428 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8429 (event != NULL) ? &tmp : NULL),
8430 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8431
8432 if (event != NULL && err == CL_SUCCESS)
8433 *event = tmp;
8434
8435 return err;
8436 }
8437#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8438
8439
8440#if CL_HPP_TARGET_OPENCL_VERSION >= 210
8446 template<typename T>
8448 const cl::vector<T*> &svmRawPointers,
8449 const cl::vector<size_type> &sizes,
8450 cl_mem_migration_flags flags = 0,
8451 const vector<Event>* events = NULL,
8452 Event* event = NULL) const
8453 {
8454 cl_event tmp;
8455 cl_int err = detail::errHandler(::clEnqueueSVMMigrateMem(
8456 object_,
8457 svmRawPointers.size(), static_cast<void**>(svmRawPointers.data()),
8458 sizes.data(), // array of sizes not passed
8459 flags,
8460 (events != NULL) ? (cl_uint)events->size() : 0,
8461 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8462 (event != NULL) ? &tmp : NULL),
8463 __ENQUEUE_MIGRATE_SVM_ERR);
8464
8465 if (event != NULL && err == CL_SUCCESS)
8466 *event = tmp;
8467
8468 return err;
8469 }
8470
8475 template<typename T>
8477 const cl::vector<T*> &svmRawPointers,
8478 cl_mem_migration_flags flags = 0,
8479 const vector<Event>* events = NULL,
8480 Event* event = NULL) const
8481 {
8482 return enqueueMigrateSVM(svmRawPointers, cl::vector<size_type>(svmRawPointers.size()), flags, events, event);
8483 }
8484
8485
8491 template<typename T, class D>
8493 const cl::vector<cl::pointer<T, D>> &svmPointers,
8494 const cl::vector<size_type> &sizes,
8495 cl_mem_migration_flags flags = 0,
8496 const vector<Event>* events = NULL,
8497 Event* event = NULL) const
8498 {
8499 cl::vector<void*> svmRawPointers;
8500 svmRawPointers.reserve(svmPointers.size());
8501 for (auto p : svmPointers) {
8502 svmRawPointers.push_back(static_cast<void*>(p.get()));
8503 }
8504
8505 return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
8506 }
8507
8508
8513 template<typename T, class D>
8515 const cl::vector<cl::pointer<T, D>> &svmPointers,
8516 cl_mem_migration_flags flags = 0,
8517 const vector<Event>* events = NULL,
8518 Event* event = NULL) const
8519 {
8520 return enqueueMigrateSVM(svmPointers, cl::vector<size_type>(svmPointers.size()), flags, events, event);
8521 }
8522
8528 template<typename T, class Alloc>
8530 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8531 const cl::vector<size_type> &sizes,
8532 cl_mem_migration_flags flags = 0,
8533 const vector<Event>* events = NULL,
8534 Event* event = NULL) const
8535 {
8536 cl::vector<void*> svmRawPointers;
8537 svmRawPointers.reserve(svmContainers.size());
8538 for (auto p : svmContainers) {
8539 svmRawPointers.push_back(static_cast<void*>(p.data()));
8540 }
8541
8542 return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
8543 }
8544
8549 template<typename T, class Alloc>
8551 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8552 cl_mem_migration_flags flags = 0,
8553 const vector<Event>* events = NULL,
8554 Event* event = NULL) const
8555 {
8556 return enqueueMigrateSVM(svmContainers, cl::vector<size_type>(svmContainers.size()), flags, events, event);
8557 }
8558
8559#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8560
8561 cl_int enqueueNDRangeKernel(
8562 const Kernel& kernel,
8563 const NDRange& offset,
8564 const NDRange& global,
8565 const NDRange& local = NullRange,
8566 const vector<Event>* events = NULL,
8567 Event* event = NULL) const
8568 {
8569 cl_event tmp;
8570 cl_int err = detail::errHandler(
8571 ::clEnqueueNDRangeKernel(
8572 object_, kernel(), (cl_uint) global.dimensions(),
8573 offset.dimensions() != 0 ? (const size_type*) offset : NULL,
8574 (const size_type*) global,
8575 local.dimensions() != 0 ? (const size_type*) local : NULL,
8576 (events != NULL) ? (cl_uint) events->size() : 0,
8577 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8578 (event != NULL) ? &tmp : NULL),
8579 __ENQUEUE_NDRANGE_KERNEL_ERR);
8580
8581 if (event != NULL && err == CL_SUCCESS)
8582 *event = tmp;
8583
8584 return err;
8585 }
8586
8587#if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8588 CL_API_PREFIX__VERSION_1_2_DEPRECATED cl_int enqueueTask(
8589 const Kernel& kernel,
8590 const vector<Event>* events = NULL,
8591 Event* event = NULL) const CL_API_SUFFIX__VERSION_1_2_DEPRECATED
8592 {
8593 cl_event tmp;
8594 cl_int err = detail::errHandler(
8595 ::clEnqueueTask(
8596 object_, kernel(),
8597 (events != NULL) ? (cl_uint) events->size() : 0,
8598 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8599 (event != NULL) ? &tmp : NULL),
8600 __ENQUEUE_TASK_ERR);
8601
8602 if (event != NULL && err == CL_SUCCESS)
8603 *event = tmp;
8604
8605 return err;
8606 }
8607#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8608
8609 cl_int enqueueNativeKernel(
8610 void (CL_CALLBACK *userFptr)(void *),
8611 std::pair<void*, size_type> args,
8612 const vector<Memory>* mem_objects = NULL,
8613 const vector<const void*>* mem_locs = NULL,
8614 const vector<Event>* events = NULL,
8615 Event* event = NULL) const
8616 {
8617 size_type elements = 0;
8618 if (mem_objects != NULL) {
8619 elements = mem_objects->size();
8620 }
8621 vector<cl_mem> mems(elements);
8622 for (unsigned int i = 0; i < elements; i++) {
8623 mems[i] = ((*mem_objects)[i])();
8624 }
8625
8626 cl_event tmp;
8627 cl_int err = detail::errHandler(
8628 ::clEnqueueNativeKernel(
8629 object_, userFptr, args.first, args.second,
8630 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8631 mems.data(),
8632 (mem_locs != NULL && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : NULL,
8633 (events != NULL) ? (cl_uint) events->size() : 0,
8634 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8635 (event != NULL) ? &tmp : NULL),
8636 __ENQUEUE_NATIVE_KERNEL);
8637
8638 if (event != NULL && err == CL_SUCCESS)
8639 *event = tmp;
8640
8641 return err;
8642 }
8643
8647#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8648 CL_API_PREFIX__VERSION_1_1_DEPRECATED
8649 cl_int enqueueMarker(Event* event = NULL) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
8650 {
8651 cl_event tmp;
8652 cl_int err = detail::errHandler(
8653 ::clEnqueueMarker(
8654 object_,
8655 (event != NULL) ? &tmp : NULL),
8656 __ENQUEUE_MARKER_ERR);
8657
8658 if (event != NULL && err == CL_SUCCESS)
8659 *event = tmp;
8660
8661 return err;
8662 }
8663
8664 CL_API_PREFIX__VERSION_1_1_DEPRECATED
8665 cl_int enqueueWaitForEvents(const vector<Event>& events) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
8666 {
8667 return detail::errHandler(
8668 ::clEnqueueWaitForEvents(
8669 object_,
8670 (cl_uint) events.size(),
8671 events.size() > 0 ? (const cl_event*) &events.front() : NULL),
8672 __ENQUEUE_WAIT_FOR_EVENTS_ERR);
8673 }
8674#endif // defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8675
8676 cl_int enqueueAcquireGLObjects(
8677 const vector<Memory>* mem_objects = NULL,
8678 const vector<Event>* events = NULL,
8679 Event* event = NULL) const
8680 {
8681 cl_event tmp;
8682 cl_int err = detail::errHandler(
8683 ::clEnqueueAcquireGLObjects(
8684 object_,
8685 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8686 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8687 (events != NULL) ? (cl_uint) events->size() : 0,
8688 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8689 (event != NULL) ? &tmp : NULL),
8690 __ENQUEUE_ACQUIRE_GL_ERR);
8691
8692 if (event != NULL && err == CL_SUCCESS)
8693 *event = tmp;
8694
8695 return err;
8696 }
8697
8698 cl_int enqueueReleaseGLObjects(
8699 const vector<Memory>* mem_objects = NULL,
8700 const vector<Event>* events = NULL,
8701 Event* event = NULL) const
8702 {
8703 cl_event tmp;
8704 cl_int err = detail::errHandler(
8705 ::clEnqueueReleaseGLObjects(
8706 object_,
8707 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8708 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8709 (events != NULL) ? (cl_uint) events->size() : 0,
8710 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8711 (event != NULL) ? &tmp : NULL),
8712 __ENQUEUE_RELEASE_GL_ERR);
8713
8714 if (event != NULL && err == CL_SUCCESS)
8715 *event = tmp;
8716
8717 return err;
8718 }
8719
8720#if defined (CL_HPP_USE_DX_INTEROP)
8721typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
8722 cl_command_queue command_queue, cl_uint num_objects,
8723 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8724 const cl_event* event_wait_list, cl_event* event);
8725typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
8726 cl_command_queue command_queue, cl_uint num_objects,
8727 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8728 const cl_event* event_wait_list, cl_event* event);
8729
8730 cl_int enqueueAcquireD3D10Objects(
8731 const vector<Memory>* mem_objects = NULL,
8732 const vector<Event>* events = NULL,
8733 Event* event = NULL) const
8734 {
8735 static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
8736#if CL_HPP_TARGET_OPENCL_VERSION >= 120
8737 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8738 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8739 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8740 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireD3D10ObjectsKHR);
8741#endif
8742#if CL_HPP_TARGET_OPENCL_VERSION >= 110
8743 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueAcquireD3D10ObjectsKHR);
8744#endif
8745
8746 cl_event tmp;
8747 cl_int err = detail::errHandler(
8748 pfn_clEnqueueAcquireD3D10ObjectsKHR(
8749 object_,
8750 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8751 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8752 (events != NULL) ? (cl_uint) events->size() : 0,
8753 (events != NULL) ? (cl_event*) &events->front() : NULL,
8754 (event != NULL) ? &tmp : NULL),
8755 __ENQUEUE_ACQUIRE_GL_ERR);
8756
8757 if (event != NULL && err == CL_SUCCESS)
8758 *event = tmp;
8759
8760 return err;
8761 }
8762
8763 cl_int enqueueReleaseD3D10Objects(
8764 const vector<Memory>* mem_objects = NULL,
8765 const vector<Event>* events = NULL,
8766 Event* event = NULL) const
8767 {
8768 static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL;
8769#if CL_HPP_TARGET_OPENCL_VERSION >= 120
8770 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8771 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8772 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8773 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseD3D10ObjectsKHR);
8774#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8775#if CL_HPP_TARGET_OPENCL_VERSION >= 110
8776 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueReleaseD3D10ObjectsKHR);
8777#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
8778
8779 cl_event tmp;
8780 cl_int err = detail::errHandler(
8781 pfn_clEnqueueReleaseD3D10ObjectsKHR(
8782 object_,
8783 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8784 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8785 (events != NULL) ? (cl_uint) events->size() : 0,
8786 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8787 (event != NULL) ? &tmp : NULL),
8788 __ENQUEUE_RELEASE_GL_ERR);
8789
8790 if (event != NULL && err == CL_SUCCESS)
8791 *event = tmp;
8792
8793 return err;
8794 }
8795#endif
8796
8800#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8801 CL_API_PREFIX__VERSION_1_1_DEPRECATED
8802 cl_int enqueueBarrier() const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
8803 {
8804 return detail::errHandler(
8805 ::clEnqueueBarrier(object_),
8806 __ENQUEUE_BARRIER_ERR);
8807 }
8808#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
8809
8810 cl_int flush() const
8811 {
8812 return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
8813 }
8814
8815 cl_int finish() const
8816 {
8817 return detail::errHandler(::clFinish(object_), __FINISH_ERR);
8818 }
8819}; // CommandQueue
8820
8821CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::default_initialized_;
8822CL_HPP_DEFINE_STATIC_MEMBER_ CommandQueue CommandQueue::default_;
8823CL_HPP_DEFINE_STATIC_MEMBER_ cl_int CommandQueue::default_error_ = CL_SUCCESS;
8824
8825
8826#if CL_HPP_TARGET_OPENCL_VERSION >= 200
8827enum class DeviceQueueProperties : cl_command_queue_properties
8828{
8829 None = 0,
8830 Profiling = CL_QUEUE_PROFILING_ENABLE,
8831};
8832
8833inline DeviceQueueProperties operator|(DeviceQueueProperties lhs, DeviceQueueProperties rhs)
8834{
8835 return static_cast<DeviceQueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
8836}
8837
8841class DeviceCommandQueue : public detail::Wrapper<cl_command_queue>
8842{
8843public:
8844
8849
8853 DeviceCommandQueue(DeviceQueueProperties properties, cl_int* err = NULL)
8854 {
8855 cl_int error;
8858
8859 cl_command_queue_properties mergedProperties =
8860 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8861
8862 cl_queue_properties queue_properties[] = {
8863 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8864 object_ = ::clCreateCommandQueueWithProperties(
8865 context(), device(), queue_properties, &error);
8866
8867 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8868 if (err != NULL) {
8869 *err = error;
8870 }
8871 }
8872
8877 const Context& context,
8878 const Device& device,
8879 DeviceQueueProperties properties = DeviceQueueProperties::None,
8880 cl_int* err = NULL)
8881 {
8882 cl_int error;
8883
8884 cl_command_queue_properties mergedProperties =
8885 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8886 cl_queue_properties queue_properties[] = {
8887 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8888 object_ = ::clCreateCommandQueueWithProperties(
8889 context(), device(), queue_properties, &error);
8890
8891 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8892 if (err != NULL) {
8893 *err = error;
8894 }
8895 }
8896
8901 const Context& context,
8902 const Device& device,
8903 cl_uint queueSize,
8904 DeviceQueueProperties properties = DeviceQueueProperties::None,
8905 cl_int* err = NULL)
8906 {
8907 cl_int error;
8908
8909 cl_command_queue_properties mergedProperties =
8910 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8911 cl_queue_properties queue_properties[] = {
8912 CL_QUEUE_PROPERTIES, mergedProperties,
8913 CL_QUEUE_SIZE, queueSize,
8914 0 };
8915 object_ = ::clCreateCommandQueueWithProperties(
8916 context(), device(), queue_properties, &error);
8917
8918 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8919 if (err != NULL) {
8920 *err = error;
8921 }
8922 }
8923
8930 explicit DeviceCommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
8931 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
8932
8933 DeviceCommandQueue& operator = (const cl_command_queue& rhs)
8934 {
8936 return *this;
8937 }
8938
8942 DeviceCommandQueue(const DeviceCommandQueue& queue) : detail::Wrapper<cl_type>(queue) {}
8943
8947 DeviceCommandQueue& operator = (const DeviceCommandQueue &queue)
8948 {
8950 return *this;
8951 }
8952
8956 DeviceCommandQueue(DeviceCommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(queue)) {}
8957
8962 {
8963 detail::Wrapper<cl_type>::operator=(std::move(queue));
8964 return *this;
8965 }
8966
8967 template <typename T>
8968 cl_int getInfo(cl_command_queue_info name, T* param) const
8969 {
8970 return detail::errHandler(
8971 detail::getInfo(
8972 &::clGetCommandQueueInfo, object_, name, param),
8973 __GET_COMMAND_QUEUE_INFO_ERR);
8974 }
8975
8976 template <cl_command_queue_info name> typename
8977 detail::param_traits<detail::cl_command_queue_info, name>::param_type
8978 getInfo(cl_int* err = NULL) const
8979 {
8980 typename detail::param_traits<
8981 detail::cl_command_queue_info, name>::param_type param;
8982 cl_int result = getInfo(name, &param);
8983 if (err != NULL) {
8984 *err = result;
8985 }
8986 return param;
8987 }
8988
8996 cl_int *err = nullptr)
8997 {
8998 cl_int error;
9001
9002 cl_command_queue_properties properties =
9003 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9004 cl_queue_properties queue_properties[] = {
9005 CL_QUEUE_PROPERTIES, properties,
9006 0 };
9007 DeviceCommandQueue deviceQueue(
9008 ::clCreateCommandQueueWithProperties(
9009 context(), device(), queue_properties, &error));
9010
9011 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9012 if (err != NULL) {
9013 *err = error;
9014 }
9015
9016 return deviceQueue;
9017 }
9018
9026 const Context &context, const Device &device, cl_int *err = nullptr)
9027 {
9028 cl_int error;
9029
9030 cl_command_queue_properties properties =
9031 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9032 cl_queue_properties queue_properties[] = {
9033 CL_QUEUE_PROPERTIES, properties,
9034 0 };
9035 DeviceCommandQueue deviceQueue(
9036 ::clCreateCommandQueueWithProperties(
9037 context(), device(), queue_properties, &error));
9038
9039 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9040 if (err != NULL) {
9041 *err = error;
9042 }
9043
9044 return deviceQueue;
9045 }
9046
9054 const Context &context, const Device &device, cl_uint queueSize, cl_int *err = nullptr)
9055 {
9056 cl_int error;
9057
9058 cl_command_queue_properties properties =
9059 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9060 cl_queue_properties queue_properties[] = {
9061 CL_QUEUE_PROPERTIES, properties,
9062 CL_QUEUE_SIZE, queueSize,
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
9076
9077
9078#if CL_HPP_TARGET_OPENCL_VERSION >= 210
9085 static DeviceCommandQueue updateDefault(const Context &context, const Device &device, const DeviceCommandQueue &default_queue, cl_int *err = nullptr)
9086 {
9087 cl_int error;
9088 error = clSetDefaultDeviceCommandQueue(context.get(), device.get(), default_queue.get());
9089
9090 detail::errHandler(error, __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR);
9091 if (err != NULL) {
9092 *err = error;
9093 }
9094 return default_queue;
9095 }
9096
9100 static DeviceCommandQueue getDefault(const CommandQueue &queue, cl_int * err = NULL)
9101 {
9102 return queue.getInfo<CL_QUEUE_DEVICE_DEFAULT>(err);
9103 }
9104
9105#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
9106}; // DeviceCommandQueue
9107
9108namespace detail
9109{
9110 // Specialization for device command queue
9111 template <>
9113 {
9114 static size_type size(const cl::DeviceCommandQueue&) { return sizeof(cl_command_queue); }
9115 static const cl_command_queue* ptr(const cl::DeviceCommandQueue& value) { return &(value()); }
9116 };
9117} // namespace detail
9118
9119#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9120
9121
9122template< typename IteratorType >
9124 const Context &context,
9125 IteratorType startIterator,
9126 IteratorType endIterator,
9127 bool readOnly,
9128 bool useHostPtr,
9129 cl_int* err)
9130{
9131 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9132 cl_int error;
9133
9134 cl_mem_flags flags = 0;
9135 if( readOnly ) {
9136 flags |= CL_MEM_READ_ONLY;
9137 }
9138 else {
9139 flags |= CL_MEM_READ_WRITE;
9140 }
9141 if( useHostPtr ) {
9142 flags |= CL_MEM_USE_HOST_PTR;
9143 }
9144
9145 size_type size = sizeof(DataType)*(endIterator - startIterator);
9146
9147 if( useHostPtr ) {
9148 object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
9149 } else {
9150 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9151 }
9152
9153 detail::errHandler(error, __CREATE_BUFFER_ERR);
9154 if (err != NULL) {
9155 *err = error;
9156 }
9157
9158 if( !useHostPtr ) {
9159 CommandQueue queue(context, 0, &error);
9160 detail::errHandler(error, __CREATE_BUFFER_ERR);
9161 if (err != NULL) {
9162 *err = error;
9163 }
9164
9165 error = cl::copy(queue, startIterator, endIterator, *this);
9166 detail::errHandler(error, __CREATE_BUFFER_ERR);
9167 if (err != NULL) {
9168 *err = error;
9169 }
9170 }
9171}
9172
9173template< typename IteratorType >
9175 const CommandQueue &queue,
9176 IteratorType startIterator,
9177 IteratorType endIterator,
9178 bool readOnly,
9179 bool useHostPtr,
9180 cl_int* err)
9181{
9182 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9183 cl_int error;
9184
9185 cl_mem_flags flags = 0;
9186 if (readOnly) {
9187 flags |= CL_MEM_READ_ONLY;
9188 }
9189 else {
9190 flags |= CL_MEM_READ_WRITE;
9191 }
9192 if (useHostPtr) {
9193 flags |= CL_MEM_USE_HOST_PTR;
9194 }
9195
9196 size_type size = sizeof(DataType)*(endIterator - startIterator);
9197
9198 Context context = queue.getInfo<CL_QUEUE_CONTEXT>();
9199
9200 if (useHostPtr) {
9201 object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
9202 }
9203 else {
9204 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9205 }
9206
9207 detail::errHandler(error, __CREATE_BUFFER_ERR);
9208 if (err != NULL) {
9209 *err = error;
9210 }
9211
9212 if (!useHostPtr) {
9213 error = cl::copy(queue, startIterator, endIterator, *this);
9214 detail::errHandler(error, __CREATE_BUFFER_ERR);
9215 if (err != NULL) {
9216 *err = error;
9217 }
9218 }
9219}
9220
9221inline cl_int enqueueReadBuffer(
9222 const Buffer& buffer,
9223 cl_bool blocking,
9224 size_type offset,
9225 size_type size,
9226 void* ptr,
9227 const vector<Event>* events = NULL,
9228 Event* event = NULL)
9229{
9230 cl_int error;
9231 CommandQueue queue = CommandQueue::getDefault(&error);
9232
9233 if (error != CL_SUCCESS) {
9234 return error;
9235 }
9236
9237 return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event);
9238}
9239
9240inline cl_int enqueueWriteBuffer(
9241 const Buffer& buffer,
9242 cl_bool blocking,
9243 size_type offset,
9244 size_type size,
9245 const void* ptr,
9246 const vector<Event>* events = NULL,
9247 Event* event = NULL)
9248{
9249 cl_int error;
9250 CommandQueue queue = CommandQueue::getDefault(&error);
9251
9252 if (error != CL_SUCCESS) {
9253 return error;
9254 }
9255
9256 return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event);
9257}
9258
9259inline void* enqueueMapBuffer(
9260 const Buffer& buffer,
9261 cl_bool blocking,
9262 cl_map_flags flags,
9263 size_type offset,
9264 size_type size,
9265 const vector<Event>* events = NULL,
9266 Event* event = NULL,
9267 cl_int* err = NULL)
9268{
9269 cl_int error;
9270 CommandQueue queue = CommandQueue::getDefault(&error);
9271 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9272 if (err != NULL) {
9273 *err = error;
9274 }
9275
9276 void * result = ::clEnqueueMapBuffer(
9277 queue(), buffer(), blocking, flags, offset, size,
9278 (events != NULL) ? (cl_uint) events->size() : 0,
9279 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
9280 (cl_event*) event,
9281 &error);
9282
9283 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9284 if (err != NULL) {
9285 *err = error;
9286 }
9287 return result;
9288}
9289
9290
9291#if CL_HPP_TARGET_OPENCL_VERSION >= 200
9297template<typename T>
9298inline cl_int enqueueMapSVM(
9299 T* ptr,
9300 cl_bool blocking,
9301 cl_map_flags flags,
9302 size_type size,
9303 const vector<Event>* events,
9304 Event* event)
9305{
9306 cl_int error;
9307 CommandQueue queue = CommandQueue::getDefault(&error);
9308 if (error != CL_SUCCESS) {
9309 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9310 }
9311
9312 return queue.enqueueMapSVM(
9313 ptr, blocking, flags, size, events, event);
9314}
9315
9321template<typename T, class D>
9322inline cl_int enqueueMapSVM(
9323 cl::pointer<T, D> ptr,
9324 cl_bool blocking,
9325 cl_map_flags flags,
9326 size_type size,
9327 const vector<Event>* events = NULL,
9328 Event* event = NULL)
9329{
9330 cl_int error;
9331 CommandQueue queue = CommandQueue::getDefault(&error);
9332 if (error != CL_SUCCESS) {
9333 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9334 }
9335
9336 return queue.enqueueMapSVM(
9337 ptr, blocking, flags, size, events, event);
9338}
9339
9345template<typename T, class Alloc>
9346inline cl_int enqueueMapSVM(
9347 cl::vector<T, Alloc> container,
9348 cl_bool blocking,
9349 cl_map_flags flags,
9350 const vector<Event>* events = NULL,
9351 Event* event = NULL)
9352{
9353 cl_int error;
9354 CommandQueue queue = CommandQueue::getDefault(&error);
9355 if (error != CL_SUCCESS) {
9356 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9357 }
9358
9359 return queue.enqueueMapSVM(
9360 container, blocking, flags, events, event);
9361}
9362
9363#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9364
9365inline cl_int enqueueUnmapMemObject(
9366 const Memory& memory,
9367 void* mapped_ptr,
9368 const vector<Event>* events = NULL,
9369 Event* event = NULL)
9370{
9371 cl_int error;
9372 CommandQueue queue = CommandQueue::getDefault(&error);
9373 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9374 if (error != CL_SUCCESS) {
9375 return error;
9376 }
9377
9378 cl_event tmp;
9379 cl_int err = detail::errHandler(
9380 ::clEnqueueUnmapMemObject(
9381 queue(), memory(), mapped_ptr,
9382 (events != NULL) ? (cl_uint)events->size() : 0,
9383 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
9384 (event != NULL) ? &tmp : NULL),
9385 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9386
9387 if (event != NULL && err == CL_SUCCESS)
9388 *event = tmp;
9389
9390 return err;
9391}
9392
9393#if CL_HPP_TARGET_OPENCL_VERSION >= 200
9399template<typename T>
9400inline cl_int enqueueUnmapSVM(
9401 T* ptr,
9402 const vector<Event>* events = NULL,
9403 Event* event = NULL)
9404{
9405 cl_int error;
9406 CommandQueue queue = CommandQueue::getDefault(&error);
9407 if (error != CL_SUCCESS) {
9408 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9409 }
9410
9411 return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
9412 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9413
9414}
9415
9421template<typename T, class D>
9422inline cl_int enqueueUnmapSVM(
9423 cl::pointer<T, D> &ptr,
9424 const vector<Event>* events = NULL,
9425 Event* event = NULL)
9426{
9427 cl_int error;
9428 CommandQueue queue = CommandQueue::getDefault(&error);
9429 if (error != CL_SUCCESS) {
9430 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9431 }
9432
9433 return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
9434 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9435}
9436
9442template<typename T, class Alloc>
9443inline cl_int enqueueUnmapSVM(
9444 cl::vector<T, Alloc> &container,
9445 const vector<Event>* events = NULL,
9446 Event* event = NULL)
9447{
9448 cl_int error;
9449 CommandQueue queue = CommandQueue::getDefault(&error);
9450 if (error != CL_SUCCESS) {
9451 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9452 }
9453
9454 return detail::errHandler(queue.enqueueUnmapSVM(container, events, event),
9455 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9456}
9457
9458#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9459
9460inline cl_int enqueueCopyBuffer(
9461 const Buffer& src,
9462 const Buffer& dst,
9463 size_type src_offset,
9464 size_type dst_offset,
9465 size_type size,
9466 const vector<Event>* events = NULL,
9467 Event* event = NULL)
9468{
9469 cl_int error;
9470 CommandQueue queue = CommandQueue::getDefault(&error);
9471
9472 if (error != CL_SUCCESS) {
9473 return error;
9474 }
9475
9476 return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event);
9477}
9478
9484template< typename IteratorType >
9485inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
9486{
9487 cl_int error;
9488 CommandQueue queue = CommandQueue::getDefault(&error);
9489 if (error != CL_SUCCESS)
9490 return error;
9491
9492 return cl::copy(queue, startIterator, endIterator, buffer);
9493}
9494
9500template< typename IteratorType >
9501inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
9502{
9503 cl_int error;
9504 CommandQueue queue = CommandQueue::getDefault(&error);
9505 if (error != CL_SUCCESS)
9506 return error;
9507
9508 return cl::copy(queue, buffer, startIterator, endIterator);
9509}
9510
9516template< typename IteratorType >
9517inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
9518{
9519 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9520 cl_int error;
9521
9522 size_type length = endIterator-startIterator;
9523 size_type byteLength = length*sizeof(DataType);
9524
9525 DataType *pointer =
9526 static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error));
9527 // if exceptions enabled, enqueueMapBuffer will throw
9528 if( error != CL_SUCCESS ) {
9529 return error;
9530 }
9531#if defined(_MSC_VER)
9532 std::copy(
9533 startIterator,
9534 endIterator,
9535 stdext::checked_array_iterator<DataType*>(
9536 pointer, length));
9537#else
9538 std::copy(startIterator, endIterator, pointer);
9539#endif
9540 Event endEvent;
9541 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9542 // if exceptions enabled, enqueueUnmapMemObject will throw
9543 if( error != CL_SUCCESS ) {
9544 return error;
9545 }
9546 endEvent.wait();
9547 return CL_SUCCESS;
9548}
9549
9555template< typename IteratorType >
9556inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
9557{
9558 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9559 cl_int error;
9560
9561 size_type length = endIterator-startIterator;
9562 size_type byteLength = length*sizeof(DataType);
9563
9564 DataType *pointer =
9565 static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error));
9566 // if exceptions enabled, enqueueMapBuffer will throw
9567 if( error != CL_SUCCESS ) {
9568 return error;
9569 }
9570 std::copy(pointer, pointer + length, startIterator);
9571 Event endEvent;
9572 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9573 // if exceptions enabled, enqueueUnmapMemObject will throw
9574 if( error != CL_SUCCESS ) {
9575 return error;
9576 }
9577 endEvent.wait();
9578 return CL_SUCCESS;
9579}
9580
9581
9582#if CL_HPP_TARGET_OPENCL_VERSION >= 200
9586template<typename T, class Alloc>
9587inline cl_int mapSVM(cl::vector<T, Alloc> &container)
9588{
9589 return enqueueMapSVM(container, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE);
9590}
9591
9595template<typename T, class Alloc>
9596inline cl_int unmapSVM(cl::vector<T, Alloc> &container)
9597{
9598 return enqueueUnmapSVM(container);
9599}
9600
9601#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9602
9603#if CL_HPP_TARGET_OPENCL_VERSION >= 110
9604inline cl_int enqueueReadBufferRect(
9605 const Buffer& buffer,
9606 cl_bool blocking,
9607 const array<size_type, 3>& buffer_offset,
9608 const array<size_type, 3>& host_offset,
9609 const array<size_type, 3>& region,
9610 size_type buffer_row_pitch,
9611 size_type buffer_slice_pitch,
9612 size_type host_row_pitch,
9613 size_type host_slice_pitch,
9614 void *ptr,
9615 const vector<Event>* events = NULL,
9616 Event* event = NULL)
9617{
9618 cl_int error;
9619 CommandQueue queue = CommandQueue::getDefault(&error);
9620
9621 if (error != CL_SUCCESS) {
9622 return error;
9623 }
9624
9625 return queue.enqueueReadBufferRect(
9626 buffer,
9627 blocking,
9628 buffer_offset,
9629 host_offset,
9630 region,
9631 buffer_row_pitch,
9632 buffer_slice_pitch,
9633 host_row_pitch,
9634 host_slice_pitch,
9635 ptr,
9636 events,
9637 event);
9638}
9639
9640inline cl_int enqueueWriteBufferRect(
9641 const Buffer& buffer,
9642 cl_bool blocking,
9643 const array<size_type, 3>& buffer_offset,
9644 const array<size_type, 3>& host_offset,
9645 const array<size_type, 3>& region,
9646 size_type buffer_row_pitch,
9647 size_type buffer_slice_pitch,
9648 size_type host_row_pitch,
9649 size_type host_slice_pitch,
9650 const void *ptr,
9651 const vector<Event>* events = NULL,
9652 Event* event = NULL)
9653{
9654 cl_int error;
9655 CommandQueue queue = CommandQueue::getDefault(&error);
9656
9657 if (error != CL_SUCCESS) {
9658 return error;
9659 }
9660
9661 return queue.enqueueWriteBufferRect(
9662 buffer,
9663 blocking,
9664 buffer_offset,
9665 host_offset,
9666 region,
9667 buffer_row_pitch,
9668 buffer_slice_pitch,
9669 host_row_pitch,
9670 host_slice_pitch,
9671 ptr,
9672 events,
9673 event);
9674}
9675
9676inline cl_int enqueueCopyBufferRect(
9677 const Buffer& src,
9678 const Buffer& dst,
9679 const array<size_type, 3>& src_origin,
9680 const array<size_type, 3>& dst_origin,
9681 const array<size_type, 3>& region,
9682 size_type src_row_pitch,
9683 size_type src_slice_pitch,
9684 size_type dst_row_pitch,
9685 size_type dst_slice_pitch,
9686 const vector<Event>* events = NULL,
9687 Event* event = NULL)
9688{
9689 cl_int error;
9690 CommandQueue queue = CommandQueue::getDefault(&error);
9691
9692 if (error != CL_SUCCESS) {
9693 return error;
9694 }
9695
9696 return queue.enqueueCopyBufferRect(
9697 src,
9698 dst,
9699 src_origin,
9700 dst_origin,
9701 region,
9702 src_row_pitch,
9703 src_slice_pitch,
9704 dst_row_pitch,
9705 dst_slice_pitch,
9706 events,
9707 event);
9708}
9709#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
9710
9711inline cl_int enqueueReadImage(
9712 const Image& image,
9713 cl_bool blocking,
9714 const array<size_type, 3>& origin,
9715 const array<size_type, 3>& region,
9716 size_type row_pitch,
9717 size_type slice_pitch,
9718 void* ptr,
9719 const vector<Event>* events = NULL,
9720 Event* event = NULL)
9721{
9722 cl_int error;
9723 CommandQueue queue = CommandQueue::getDefault(&error);
9724
9725 if (error != CL_SUCCESS) {
9726 return error;
9727 }
9728
9729 return queue.enqueueReadImage(
9730 image,
9731 blocking,
9732 origin,
9733 region,
9734 row_pitch,
9735 slice_pitch,
9736 ptr,
9737 events,
9738 event);
9739}
9740
9741inline cl_int enqueueWriteImage(
9742 const Image& image,
9743 cl_bool blocking,
9744 const array<size_type, 3>& origin,
9745 const array<size_type, 3>& region,
9746 size_type row_pitch,
9747 size_type slice_pitch,
9748 const void* ptr,
9749 const vector<Event>* events = NULL,
9750 Event* event = NULL)
9751{
9752 cl_int error;
9753 CommandQueue queue = CommandQueue::getDefault(&error);
9754
9755 if (error != CL_SUCCESS) {
9756 return error;
9757 }
9758
9759 return queue.enqueueWriteImage(
9760 image,
9761 blocking,
9762 origin,
9763 region,
9764 row_pitch,
9765 slice_pitch,
9766 ptr,
9767 events,
9768 event);
9769}
9770
9771inline cl_int enqueueCopyImage(
9772 const Image& src,
9773 const Image& dst,
9774 const array<size_type, 3>& src_origin,
9775 const array<size_type, 3>& dst_origin,
9776 const array<size_type, 3>& region,
9777 const vector<Event>* events = NULL,
9778 Event* event = NULL)
9779{
9780 cl_int error;
9781 CommandQueue queue = CommandQueue::getDefault(&error);
9782
9783 if (error != CL_SUCCESS) {
9784 return error;
9785 }
9786
9787 return queue.enqueueCopyImage(
9788 src,
9789 dst,
9790 src_origin,
9791 dst_origin,
9792 region,
9793 events,
9794 event);
9795}
9796
9797inline cl_int enqueueCopyImageToBuffer(
9798 const Image& src,
9799 const Buffer& dst,
9800 const array<size_type, 3>& src_origin,
9801 const array<size_type, 3>& region,
9802 size_type dst_offset,
9803 const vector<Event>* events = NULL,
9804 Event* event = NULL)
9805{
9806 cl_int error;
9807 CommandQueue queue = CommandQueue::getDefault(&error);
9808
9809 if (error != CL_SUCCESS) {
9810 return error;
9811 }
9812
9813 return queue.enqueueCopyImageToBuffer(
9814 src,
9815 dst,
9816 src_origin,
9817 region,
9818 dst_offset,
9819 events,
9820 event);
9821}
9822
9823inline cl_int enqueueCopyBufferToImage(
9824 const Buffer& src,
9825 const Image& dst,
9826 size_type src_offset,
9827 const array<size_type, 3>& dst_origin,
9828 const array<size_type, 3>& region,
9829 const vector<Event>* events = NULL,
9830 Event* event = NULL)
9831{
9832 cl_int error;
9833 CommandQueue queue = CommandQueue::getDefault(&error);
9834
9835 if (error != CL_SUCCESS) {
9836 return error;
9837 }
9838
9839 return queue.enqueueCopyBufferToImage(
9840 src,
9841 dst,
9842 src_offset,
9843 dst_origin,
9844 region,
9845 events,
9846 event);
9847}
9848
9849
9850inline cl_int flush(void)
9851{
9852 cl_int error;
9853 CommandQueue queue = CommandQueue::getDefault(&error);
9854
9855 if (error != CL_SUCCESS) {
9856 return error;
9857 }
9858
9859 return queue.flush();
9860}
9861
9862inline cl_int finish(void)
9863{
9864 cl_int error;
9865 CommandQueue queue = CommandQueue::getDefault(&error);
9866
9867 if (error != CL_SUCCESS) {
9868 return error;
9869 }
9870
9871
9872 return queue.finish();
9873}
9874
9876{
9877private:
9878 CommandQueue queue_;
9879 const NDRange offset_;
9880 const NDRange global_;
9881 const NDRange local_;
9882 vector<Event> events_;
9883
9884 template<typename... Ts>
9885 friend class KernelFunctor;
9886
9887public:
9888 EnqueueArgs(NDRange global) :
9889 queue_(CommandQueue::getDefault()),
9890 offset_(NullRange),
9891 global_(global),
9892 local_(NullRange)
9893 {
9894
9895 }
9896
9897 EnqueueArgs(NDRange global, NDRange local) :
9898 queue_(CommandQueue::getDefault()),
9899 offset_(NullRange),
9900 global_(global),
9901 local_(local)
9902 {
9903
9904 }
9905
9906 EnqueueArgs(NDRange offset, NDRange global, NDRange local) :
9907 queue_(CommandQueue::getDefault()),
9908 offset_(offset),
9909 global_(global),
9910 local_(local)
9911 {
9912
9913 }
9914
9915 EnqueueArgs(Event e, NDRange global) :
9916 queue_(CommandQueue::getDefault()),
9917 offset_(NullRange),
9918 global_(global),
9919 local_(NullRange)
9920 {
9921 events_.push_back(e);
9922 }
9923
9924 EnqueueArgs(Event e, NDRange global, NDRange local) :
9925 queue_(CommandQueue::getDefault()),
9926 offset_(NullRange),
9927 global_(global),
9928 local_(local)
9929 {
9930 events_.push_back(e);
9931 }
9932
9933 EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) :
9934 queue_(CommandQueue::getDefault()),
9935 offset_(offset),
9936 global_(global),
9937 local_(local)
9938 {
9939 events_.push_back(e);
9940 }
9941
9942 EnqueueArgs(const vector<Event> &events, NDRange global) :
9943 queue_(CommandQueue::getDefault()),
9944 offset_(NullRange),
9945 global_(global),
9946 local_(NullRange),
9947 events_(events)
9948 {
9949
9950 }
9951
9952 EnqueueArgs(const vector<Event> &events, NDRange global, NDRange local) :
9953 queue_(CommandQueue::getDefault()),
9954 offset_(NullRange),
9955 global_(global),
9956 local_(local),
9957 events_(events)
9958 {
9959
9960 }
9961
9962 EnqueueArgs(const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
9963 queue_(CommandQueue::getDefault()),
9964 offset_(offset),
9965 global_(global),
9966 local_(local),
9967 events_(events)
9968 {
9969
9970 }
9971
9972 EnqueueArgs(CommandQueue &queue, NDRange global) :
9973 queue_(queue),
9974 offset_(NullRange),
9975 global_(global),
9976 local_(NullRange)
9977 {
9978
9979 }
9980
9981 EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) :
9982 queue_(queue),
9983 offset_(NullRange),
9984 global_(global),
9985 local_(local)
9986 {
9987
9988 }
9989
9990 EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) :
9991 queue_(queue),
9992 offset_(offset),
9993 global_(global),
9994 local_(local)
9995 {
9996
9997 }
9998
9999 EnqueueArgs(CommandQueue &queue, Event e, NDRange global) :
10000 queue_(queue),
10001 offset_(NullRange),
10002 global_(global),
10003 local_(NullRange)
10004 {
10005 events_.push_back(e);
10006 }
10007
10008 EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) :
10009 queue_(queue),
10010 offset_(NullRange),
10011 global_(global),
10012 local_(local)
10013 {
10014 events_.push_back(e);
10015 }
10016
10017 EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) :
10018 queue_(queue),
10019 offset_(offset),
10020 global_(global),
10021 local_(local)
10022 {
10023 events_.push_back(e);
10024 }
10025
10026 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global) :
10027 queue_(queue),
10028 offset_(NullRange),
10029 global_(global),
10030 local_(NullRange),
10031 events_(events)
10032 {
10033
10034 }
10035
10036 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global, NDRange local) :
10037 queue_(queue),
10038 offset_(NullRange),
10039 global_(global),
10040 local_(local),
10041 events_(events)
10042 {
10043
10044 }
10045
10046 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
10047 queue_(queue),
10048 offset_(offset),
10049 global_(global),
10050 local_(local),
10051 events_(events)
10052 {
10053
10054 }
10055};
10056
10057
10058//----------------------------------------------------------------------------------------------
10059
10060
10065template<typename... Ts>
10067{
10068private:
10069 Kernel kernel_;
10070
10071 template<int index, typename T0, typename... T1s>
10072 void setArgs(T0&& t0, T1s&&... t1s)
10073 {
10074 kernel_.setArg(index, t0);
10075 setArgs<index + 1, T1s...>(std::forward<T1s>(t1s)...);
10076 }
10077
10078 template<int index, typename T0>
10079 void setArgs(T0&& t0)
10080 {
10081 kernel_.setArg(index, t0);
10082 }
10083
10084 template<int index>
10085 void setArgs()
10086 {
10087 }
10088
10089
10090public:
10091 KernelFunctor(Kernel kernel) : kernel_(kernel)
10092 {}
10093
10095 const Program& program,
10096 const string name,
10097 cl_int * err = NULL) :
10098 kernel_(program, name.c_str(), err)
10099 {}
10100
10103
10110 const EnqueueArgs& args,
10111 Ts... ts)
10112 {
10113 Event event;
10114 setArgs<0>(std::forward<Ts>(ts)...);
10115
10116 args.queue_.enqueueNDRangeKernel(
10117 kernel_,
10118 args.offset_,
10119 args.global_,
10120 args.local_,
10121 &args.events_,
10122 &event);
10123
10124 return event;
10125 }
10126
10134 const EnqueueArgs& args,
10135 Ts... ts,
10136 cl_int &error)
10137 {
10138 Event event;
10139 setArgs<0>(std::forward<Ts>(ts)...);
10140
10141 error = args.queue_.enqueueNDRangeKernel(
10142 kernel_,
10143 args.offset_,
10144 args.global_,
10145 args.local_,
10146 &args.events_,
10147 &event);
10148
10149 return event;
10150 }
10151
10152#if CL_HPP_TARGET_OPENCL_VERSION >= 200
10153 cl_int setSVMPointers(const vector<void*> &pointerList)
10154 {
10155 return kernel_.setSVMPointers(pointerList);
10156 }
10157
10158 template<typename T0, typename... T1s>
10159 cl_int setSVMPointers(const T0 &t0, T1s &... ts)
10160 {
10161 return kernel_.setSVMPointers(t0, ts...);
10162 }
10163#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10164
10165 Kernel getKernel()
10166 {
10167 return kernel_;
10168 }
10169};
10170
10171namespace compatibility {
10176 template<typename... Ts>
10178 {
10179 typedef KernelFunctor<Ts...> FunctorType;
10180
10181 FunctorType functor_;
10182
10184 const Program& program,
10185 const string name,
10186 cl_int * err = NULL) :
10187 functor_(FunctorType(program, name, err))
10188 {}
10189
10191 const Kernel kernel) :
10192 functor_(FunctorType(kernel))
10193 {}
10194
10197
10199 typedef Event type_(
10200 const EnqueueArgs&,
10201 Ts...);
10202
10203 Event operator()(
10204 const EnqueueArgs& enqueueArgs,
10205 Ts... args)
10206 {
10207 return functor_(
10208 enqueueArgs, args...);
10209 }
10210 };
10211} // namespace compatibility
10212
10213
10214//----------------------------------------------------------------------------------------------------------------------
10215
10216#undef CL_HPP_ERR_STR_
10217#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
10218#undef __GET_DEVICE_INFO_ERR
10219#undef __GET_PLATFORM_INFO_ERR
10220#undef __GET_DEVICE_IDS_ERR
10221#undef __GET_PLATFORM_IDS_ERR
10222#undef __GET_CONTEXT_INFO_ERR
10223#undef __GET_EVENT_INFO_ERR
10224#undef __GET_EVENT_PROFILE_INFO_ERR
10225#undef __GET_MEM_OBJECT_INFO_ERR
10226#undef __GET_IMAGE_INFO_ERR
10227#undef __GET_SAMPLER_INFO_ERR
10228#undef __GET_KERNEL_INFO_ERR
10229#undef __GET_KERNEL_ARG_INFO_ERR
10230#undef __GET_KERNEL_SUB_GROUP_INFO_ERR
10231#undef __GET_KERNEL_WORK_GROUP_INFO_ERR
10232#undef __GET_PROGRAM_INFO_ERR
10233#undef __GET_PROGRAM_BUILD_INFO_ERR
10234#undef __GET_COMMAND_QUEUE_INFO_ERR
10235#undef __CREATE_CONTEXT_ERR
10236#undef __CREATE_CONTEXT_FROM_TYPE_ERR
10237#undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
10238#undef __CREATE_BUFFER_ERR
10239#undef __COPY_ERR
10240#undef __CREATE_SUBBUFFER_ERR
10241#undef __CREATE_GL_BUFFER_ERR
10242#undef __CREATE_GL_RENDER_BUFFER_ERR
10243#undef __GET_GL_OBJECT_INFO_ERR
10244#undef __CREATE_IMAGE_ERR
10245#undef __CREATE_GL_TEXTURE_ERR
10246#undef __IMAGE_DIMENSION_ERR
10247#undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
10248#undef __CREATE_USER_EVENT_ERR
10249#undef __SET_USER_EVENT_STATUS_ERR
10250#undef __SET_EVENT_CALLBACK_ERR
10251#undef __WAIT_FOR_EVENTS_ERR
10252#undef __CREATE_KERNEL_ERR
10253#undef __SET_KERNEL_ARGS_ERR
10254#undef __CREATE_PROGRAM_WITH_SOURCE_ERR
10255#undef __CREATE_PROGRAM_WITH_IL_ERR
10256#undef __CREATE_PROGRAM_WITH_BINARY_ERR
10257#undef __CREATE_PROGRAM_WITH_IL_ERR
10258#undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR
10259#undef __BUILD_PROGRAM_ERR
10260#undef __COMPILE_PROGRAM_ERR
10261#undef __LINK_PROGRAM_ERR
10262#undef __CREATE_KERNELS_IN_PROGRAM_ERR
10263#undef __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR
10264#undef __CREATE_SAMPLER_WITH_PROPERTIES_ERR
10265#undef __SET_COMMAND_QUEUE_PROPERTY_ERR
10266#undef __ENQUEUE_READ_BUFFER_ERR
10267#undef __ENQUEUE_READ_BUFFER_RECT_ERR
10268#undef __ENQUEUE_WRITE_BUFFER_ERR
10269#undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
10270#undef __ENQEUE_COPY_BUFFER_ERR
10271#undef __ENQEUE_COPY_BUFFER_RECT_ERR
10272#undef __ENQUEUE_FILL_BUFFER_ERR
10273#undef __ENQUEUE_READ_IMAGE_ERR
10274#undef __ENQUEUE_WRITE_IMAGE_ERR
10275#undef __ENQUEUE_COPY_IMAGE_ERR
10276#undef __ENQUEUE_FILL_IMAGE_ERR
10277#undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
10278#undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
10279#undef __ENQUEUE_MAP_BUFFER_ERR
10280#undef __ENQUEUE_MAP_IMAGE_ERR
10281#undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
10282#undef __ENQUEUE_NDRANGE_KERNEL_ERR
10283#undef __ENQUEUE_NATIVE_KERNEL
10284#undef __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR
10285#undef __ENQUEUE_MIGRATE_SVM_ERR
10286#undef __ENQUEUE_ACQUIRE_GL_ERR
10287#undef __ENQUEUE_RELEASE_GL_ERR
10288#undef __CREATE_PIPE_ERR
10289#undef __GET_PIPE_INFO_ERR
10290#undef __RETAIN_ERR
10291#undef __RELEASE_ERR
10292#undef __FLUSH_ERR
10293#undef __FINISH_ERR
10294#undef __VECTOR_CAPACITY_ERR
10295#undef __CREATE_SUB_DEVICES_ERR
10296#undef __CREATE_SUB_DEVICES_ERR
10297#undef __ENQUEUE_MARKER_ERR
10298#undef __ENQUEUE_WAIT_FOR_EVENTS_ERR
10299#undef __ENQUEUE_BARRIER_ERR
10300#undef __UNLOAD_COMPILER_ERR
10301#undef __CREATE_GL_TEXTURE_2D_ERR
10302#undef __CREATE_GL_TEXTURE_3D_ERR
10303#undef __CREATE_IMAGE2D_ERR
10304#undef __CREATE_IMAGE3D_ERR
10305#undef __CREATE_COMMAND_QUEUE_ERR
10306#undef __ENQUEUE_TASK_ERR
10307#undef __CREATE_SAMPLER_ERR
10308#undef __ENQUEUE_MARKER_WAIT_LIST_ERR
10309#undef __ENQUEUE_BARRIER_WAIT_LIST_ERR
10310#undef __CLONE_KERNEL_ERR
10311#undef __GET_HOST_TIMER_ERR
10312#undef __GET_DEVICE_AND_HOST_TIMER_ERR
10313
10314#endif //CL_HPP_USER_OVERRIDE_ERROR_STRINGS
10315
10316// Extensions
10317#undef CL_HPP_INIT_CL_EXT_FCN_PTR_
10318#undef CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_
10319
10320#if defined(CL_HPP_USE_CL_DEVICE_FISSION)
10321#undef CL_HPP_PARAM_NAME_DEVICE_FISSION_
10322#endif // CL_HPP_USE_CL_DEVICE_FISSION
10323
10324#undef CL_HPP_NOEXCEPT_
10325#undef CL_HPP_DEFINE_STATIC_MEMBER_
10326
10327} // namespace cl
10328
10329#endif // CL_HPP_
Class interface for GL Buffer Memory Objects.
Definition opencl.hpp:4218
BufferGL(BufferGL &&buf) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:4284
BufferGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4261
BufferGL()
Default constructor - initializes to NULL.
Definition opencl.hpp:4245
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:4225
BufferGL(const BufferGL &buf)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:4270
cl_int getObjectInfo(cl_gl_object_type *type, cl_GLuint *gl_object_name)
Wrapper for clGetGLObjectInfo().
Definition opencl.hpp:4296
BufferGL(const cl_mem &buffer, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition opencl.hpp:4254
Class interface for Buffer Memory Objects.
Definition opencl.hpp:3898
Buffer()
Default constructor - initializes to NULL.
Definition opencl.hpp:4020
Buffer(const Buffer &buf)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:4045
Buffer(Buffer &&buf) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:4059
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:3908
Buffer(const cl_mem &buffer, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition opencl.hpp:4029
Buffer & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4036
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:3957
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:4075
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:3933
Class interface for GL Render Buffer Memory Objects.
Definition opencl.hpp:4315
cl_int getObjectInfo(cl_gl_object_type *type, cl_GLuint *gl_object_name)
Wrapper for clGetGLObjectInfo().
Definition opencl.hpp:4393
BufferRenderGL(const cl_mem &buffer, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition opencl.hpp:4351
BufferRenderGL(BufferRenderGL &&buf) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:4381
BufferRenderGL()
Default constructor - initializes to NULL.
Definition opencl.hpp:4342
BufferRenderGL(const BufferRenderGL &buf)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:4367
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:4322
BufferRenderGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4358
CommandQueue interface for cl_command_queue.
Definition opencl.hpp:7092
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:7223
CommandQueue(const cl_command_queue &commandQueue, bool retainObject=false)
Constructor from cl_command_queue - takes ownership.
Definition opencl.hpp:7550
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:7811
CommandQueue(CommandQueue &&queue) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:7576
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:8529
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:8514
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:8011
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:8220
cl_int enqueueMigrateMemObjects(const vector< Memory > &memObjects, cl_mem_migration_flags flags, const vector< Event > *events=NULL, Event *event=NULL) const
Definition opencl.hpp:8406
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:8492
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:8193
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:8476
static CommandQueue setDefault(const CommandQueue &default_queue)
Definition opencl.hpp:7534
cl_int enqueueMarkerWithWaitList(const vector< Event > *events=0, Event *event=0) const
Definition opencl.hpp:8353
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:8550
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:7157
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:8447
cl_int enqueueUnmapSVM(cl::pointer< T, D > &ptr, const vector< Event > *events=NULL, Event *event=NULL) const
Definition opencl.hpp:8295
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:7415
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:7466
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:7353
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:7943
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int enqueueMarker(Event *event=NULL) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition opencl.hpp:8649
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:7977
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int enqueueBarrier() const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition opencl.hpp:8802
cl_int enqueueBarrierWithWaitList(const vector< Event > *events=0, Event *event=0) const
Definition opencl.hpp:8383
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:7286
CommandQueue(const CommandQueue &queue)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:7562
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:8165
cl_int enqueueUnmapSVM(cl::vector< T, Alloc > &container, const vector< Event > *events=NULL, Event *event=NULL) const
Definition opencl.hpp:8320
cl_int enqueueUnmapSVM(T *ptr, const vector< Event > *events=NULL, Event *event=NULL) const
Definition opencl.hpp:8270
Class interface for cl_context.
Definition opencl.hpp:2813
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:2883
static Context setDefault(const Context &default_context)
Definition opencl.hpp:3081
Context(const cl_context &context, bool retainObject=false)
Constructor from cl_context - takes ownership.
Definition opencl.hpp:3096
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:3122
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:3137
Context()
Default constructor - initializes to NULL.
Definition opencl.hpp:3089
cl_int getInfo(cl_context_info name, T *param) const
Wrapper for clGetContextInfo().
Definition opencl.hpp:3112
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:2948
static Context getDefault(cl_int *err=NULL)
Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT.
Definition opencl.hpp:3064
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:2918
Context(const Context &ctx)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:3034
Context(Context &&ctx) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:3048
Context & operator=(const Context &ctx)
Copy assignment to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:3039
DeviceCommandQueue interface for device cl_command_queues.
Definition opencl.hpp:8842
DeviceCommandQueue(const Context &context, const Device &device, DeviceQueueProperties properties=DeviceQueueProperties::None, cl_int *err=NULL)
Definition opencl.hpp:8876
DeviceCommandQueue(const Context &context, const Device &device, cl_uint queueSize, DeviceQueueProperties properties=DeviceQueueProperties::None, cl_int *err=NULL)
Definition opencl.hpp:8900
static DeviceCommandQueue makeDefault(const Context &context, const Device &device, cl_int *err=nullptr)
Definition opencl.hpp:9025
static DeviceCommandQueue updateDefault(const Context &context, const Device &device, const DeviceCommandQueue &default_queue, cl_int *err=nullptr)
Definition opencl.hpp:9085
static DeviceCommandQueue getDefault(const CommandQueue &queue, cl_int *err=NULL)
Definition opencl.hpp:9100
static DeviceCommandQueue makeDefault(const Context &context, const Device &device, cl_uint queueSize, cl_int *err=nullptr)
Definition opencl.hpp:9053
DeviceCommandQueue(DeviceQueueProperties properties, cl_int *err=NULL)
Definition opencl.hpp:8853
DeviceCommandQueue(const DeviceCommandQueue &queue)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:8942
DeviceCommandQueue(DeviceCommandQueue &&queue) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:8956
DeviceCommandQueue(const cl_command_queue &commandQueue, bool retainObject=false)
Constructor from cl_command_queue - takes ownership.
Definition opencl.hpp:8930
static DeviceCommandQueue makeDefault(cl_int *err=nullptr)
Definition opencl.hpp:8995
Class interface for cl_device_id.
Definition opencl.hpp:2150
Device & operator=(const cl_device_id &rhs)
Assignment operator from cl_device_id.
Definition opencl.hpp:2228
cl_int getInfo(cl_device_info name, T *param) const
Wrapper for clGetDeviceInfo().
Definition opencl.hpp:2264
Device()
Default constructor - initializes to NULL.
Definition opencl.hpp:2186
cl_ulong getHostTimer(cl_int *error=nullptr)
Definition opencl.hpp:2293
static Device getDefault(cl_int *errResult=NULL)
Returns the first device on the default context.
Definition opencl.hpp:2199
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:2274
Device(const Device &dev)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:2237
Device(Device &&dev) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:2251
std::pair< cl_ulong, cl_ulong > getDeviceAndHostTimer(cl_int *error=nullptr)
Definition opencl.hpp:2317
cl_int createSubDevices(const cl_device_partition_property *properties, vector< Device > *devices)
Wrapper for clCreateSubDevices().
Definition opencl.hpp:2337
static Device setDefault(const Device &default_device)
Definition opencl.hpp:2217
Device(const cl_device_id &device, bool retainObject=false)
Constructor from cl_device_id.
Definition opencl.hpp:2192
Class interface for cl_event.
Definition opencl.hpp:3225
Event(const cl_event &event, bool retainObject=false)
Constructor from cl_event - takes ownership.
Definition opencl.hpp:3238
cl_int getProfilingInfo(cl_profiling_info name, T *param) const
Wrapper for clGetEventProfilingInfo().
Definition opencl.hpp:3277
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:3314
cl_int getInfo(cl_event_info name, T *param) const
Wrapper for clGetEventInfo().
Definition opencl.hpp:3254
cl_int wait() const
Blocks the calling thread until this event completes.
Definition opencl.hpp:3302
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:3264
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:3287
Event()
Default constructor - initializes to NULL.
Definition opencl.hpp:3228
Event & operator=(const cl_event &rhs)
Assignment operator from cl_event - takes ownership.
Definition opencl.hpp:3246
static cl_int waitForEvents(const vector< Event > &events)
Blocks the calling thread until every event specified is complete.
Definition opencl.hpp:3334
Image interface for arrays of 1D images.
Definition opencl.hpp:4671
Image1DArray(const Image1DArray &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:4727
Image1DArray(Image1DArray &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:4741
Image1DArray(const cl_mem &imageArray, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition opencl.hpp:4714
Image interface for 1D buffer images.
Definition opencl.hpp:4588
Image1DBuffer(const Image1DBuffer &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:4640
Image1DBuffer(const cl_mem &image1D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition opencl.hpp:4628
Image1DBuffer(Image1DBuffer &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:4654
Class interface for 1D Image Memory objects.
Definition opencl.hpp:4497
Image1D()
Default constructor - initializes to NULL.
Definition opencl.hpp:4532
Image1D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4548
Image1D(const cl_mem &image1D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition opencl.hpp:4541
Image1D(const Image1D &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:4557
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:4503
Image1D(Image1D &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:4571
Image interface for arrays of 2D images.
Definition opencl.hpp:5088
Image2DArray(const Image2DArray &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:5146
Image2DArray(const cl_mem &imageArray, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition opencl.hpp:5135
Image2DArray(Image2DArray &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:5160
Class interface for GL 2D Image Memory objects.
Definition opencl.hpp:4998
Image2DGL()
Default constructor - initializes to NULL.
Definition opencl.hpp:5030
Image2DGL(const Image2DGL &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:5055
Image2DGL(Image2DGL &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:5069
Image2DGL(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition opencl.hpp:5039
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:5005
Class interface for 2D Image Memory objects.
Definition opencl.hpp:4763
Image2D(const Image2D &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:4959
Image2D(const cl_mem &image2D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition opencl.hpp:4943
Image2D()
Default constructor - initializes to NULL.
Definition opencl.hpp:4934
Image2D(Image2D &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:4973
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:4769
Image2D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4950
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:4837
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:4883
Class interface for GL 3D Image Memory objects.
Definition opencl.hpp:5315
Image3DGL()
Default constructor - initializes to NULL.
Definition opencl.hpp:5346
Image3DGL(Image3DGL &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:5385
Image3DGL(const Image3DGL &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:5371
Image3DGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:5362
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:5322
Image3DGL(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition opencl.hpp:5355
Class interface for 3D Image Memory objects.
Definition opencl.hpp:5180
Image3D(const cl_mem &image3D, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition opencl.hpp:5263
Image3D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:5270
Image3D()
Default constructor - initializes to NULL.
Definition opencl.hpp:5254
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:5186
Image3D(Image3D &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:5293
Image3D(const Image3D &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:5279
general image interface for GL interop. We abstract the 2D and 3D GL images into a single instance he...
Definition opencl.hpp:5406
ImageGL(const ImageGL &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:5452
ImageGL(ImageGL &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:5466
ImageGL(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition opencl.hpp:5440
C++ base class for Image Memory objects.
Definition opencl.hpp:4410
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:4477
Image(const Image &img)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:4438
Image(const cl_mem &image, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition opencl.hpp:4422
cl_int getImageInfo(cl_image_info name, T *param) const
Wrapper for clGetImageInfo().
Definition opencl.hpp:4467
Image & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4429
Image()
Default constructor - initializes to NULL.
Definition opencl.hpp:4413
Image(Image &&img) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:4452
Event operator()(const EnqueueArgs &args, Ts... ts)
Definition opencl.hpp:10109
Event result_type
Return type of the functor.
Definition opencl.hpp:10102
Class interface for cl_kernel.
Definition opencl.hpp:5896
Kernel(Kernel &&kernel) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:5942
Kernel(const cl_kernel &kernel, bool retainObject=false)
Constructor from cl_kernel - takes ownership.
Definition opencl.hpp:5911
cl_int setSVMPointers(const vector< void * > &pointerList)
Definition opencl.hpp:6114
cl_int setArg(cl_uint index, const cl::pointer< T, D > &argPtr)
setArg overload taking a shared_ptr type
Definition opencl.hpp:6058
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:6079
Kernel()
Default constructor - initializes to NULL.
Definition opencl.hpp:5901
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:6091
Kernel(const Kernel &kernel)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:5928
cl_int setArg(cl_uint index, const cl::vector< T, Alloc > &argPtr)
setArg overload taking a vector type.
Definition opencl.hpp:6068
Kernel & operator=(const cl_kernel &rhs)
Assignment operator from cl_kernel - takes ownership.
Definition opencl.hpp:5919
cl_int setSVMPointers(const std::array< void *, ArrayLength > &pointerList)
Definition opencl.hpp:6129
Kernel clone()
Definition opencl.hpp:6230
cl_int enableFineGrainedSystemSVM(bool svmEnabled)
Enable fine-grained system SVM.
Definition opencl.hpp:6150
Class interface for cl_mem.
Definition opencl.hpp:3408
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:3504
Memory(const Memory &mem)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:3441
Memory(Memory &&mem) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:3455
Memory(const cl_mem &memory, bool retainObject)
Constructor from cl_mem - takes ownership.
Definition opencl.hpp:3424
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:3479
Memory()
Default constructor - initializes to NULL.
Definition opencl.hpp:3411
Memory & operator=(const cl_mem &rhs)
Assignment operator from cl_mem - takes ownership.
Definition opencl.hpp:3432
cl_int getInfo(cl_mem_info name, T *param) const
Wrapper for clGetMemObjectInfo().
Definition opencl.hpp:3469
Class interface for specifying NDRange values.
Definition opencl.hpp:5759
size_type dimensions() const
Queries the number of dimensions in the range.
Definition opencl.hpp:5810
NDRange(size_type size0, size_type size1)
Constructs two-dimensional range.
Definition opencl.hpp:5784
NDRange(size_type size0, size_type size1, size_type size2)
Constructs three-dimensional range.
Definition opencl.hpp:5793
size_type size() const
Returns the size of the object in bytes based on the.
Definition opencl.hpp:5817
NDRange()
Default constructor - resulting range has zero dimensions.
Definition opencl.hpp:5766
NDRange(size_type size0)
Constructs one-dimensional range.
Definition opencl.hpp:5775
Class interface for Pipe Memory Objects.
Definition opencl.hpp:5489
Pipe(Pipe &&pipe) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:5584
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:5501
Pipe()
Default constructor - initializes to NULL.
Definition opencl.hpp:5545
cl_int getInfo(cl_pipe_info name, T *param) const
Wrapper for clGetMemObjectInfo().
Definition opencl.hpp:5597
Pipe(cl_uint packet_size, cl_uint max_packets, cl_int *err=NULL)
Constructs a Pipe in a the default context.
Definition opencl.hpp:5526
Pipe(const Pipe &pipe)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:5570
Pipe(const cl_mem &pipe, bool retainObject=false)
Constructor from cl_mem - takes ownership.
Definition opencl.hpp:5554
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:5607
Pipe & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:5561
Class interface for cl_platform_id.
Definition opencl.hpp:2430
static cl_int get(Platform *platform)
Gets the first available platform.
Definition opencl.hpp:2741
Platform(const cl_platform_id &platform, bool retainObject=false)
Constructor from cl_platform_id.
Definition opencl.hpp:2511
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:2561
Platform()
Default constructor - initializes to NULL.
Definition opencl.hpp:2502
cl_int unloadCompiler()
Wrapper for clUnloadCompiler().
Definition opencl.hpp:2774
cl_int getDevices(cl_device_type type, vector< Device > *devices) const
Gets a list of devices for this platform.
Definition opencl.hpp:2576
static Platform get(cl_int *errResult=NULL)
Gets the first available platform, returning it by value.
Definition opencl.hpp:2760
Platform & operator=(const cl_platform_id &rhs)
Assignment operator from cl_platform_id.
Definition opencl.hpp:2518
static cl_int get(vector< Platform > *platforms)
Gets a list of available platforms.
Definition opencl.hpp:2706
cl_int getInfo(cl_platform_info name, T *param) const
Wrapper for clGetPlatformInfo().
Definition opencl.hpp:2551
static Platform setDefault(const Platform &default_platform)
Definition opencl.hpp:2542
Program interface that implements cl_program.
Definition opencl.hpp:6245
Program(const Program &program)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:6644
Program(Program &&program) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:6658
Program(const Sources &sources, cl_int *err=NULL)
Definition opencl.hpp:6335
Program(const Context &context, const Sources &sources, cl_int *err=NULL)
Definition opencl.hpp:6370
Program(const vector< char > &IL, bool build=false, cl_int *err=NULL)
Definition opencl.hpp:6407
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:6881
Program(const Context &context, const vector< Device > &devices, const string &kernelNames, cl_int *err=NULL)
Definition opencl.hpp:6594
cl_int setSpecializationConstant(cl_uint index, size_type size, const void *value)
Sets a SPIR-V specialization constant.
Definition opencl.hpp:6915
Program(const cl_program &program, bool retainObject=false)
Constructor from cl_program - takes ownership.
Definition opencl.hpp:6632
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:6802
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:6900
Program(const Context &context, const vector< Device > &devices, const Binaries &binaries, vector< cl_int > *binaryStatus=NULL, cl_int *err=NULL)
Definition opencl.hpp:6530
Program(const Context &context, const vector< char > &IL, bool build=false, cl_int *err=NULL)
Definition opencl.hpp:6462
pointer allocate(size_type size, typename cl::SVMAllocator< void, SVMTrait >::const_pointer=0)
Definition opencl.hpp:3697
bool operator==(SVMAllocator const &rhs)
Definition opencl.hpp:3767
size_type max_size() const CL_HPP_NOEXCEPT_
Definition opencl.hpp:3739
Class interface for cl_sampler.
Definition opencl.hpp:5630
Sampler()
Default constructor - initializes to NULL.
Definition opencl.hpp:5633
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:5639
Sampler(Sampler &&sam) CL_HPP_NOEXCEPT_
Move constructor to forward move to the superclass correctly. Required for MSVC.
Definition opencl.hpp:5717
Sampler & operator=(const cl_sampler &rhs)
Assignment operator from cl_sampler - takes ownership.
Definition opencl.hpp:5694
Sampler(const Sampler &sam)
Copy constructor to forward copy to the superclass correctly. Required for MSVC.
Definition opencl.hpp:5703
cl_int getInfo(cl_sampler_info name, T *param) const
Wrapper for clGetSamplerInfo().
Definition opencl.hpp:5730
Sampler(const cl_sampler &sampler, bool retainObject=false)
Constructor from cl_sampler - takes ownership.
Definition opencl.hpp:5686
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:5740
Class interface for user events (a subset of cl_event's).
Definition opencl.hpp:3349
UserEvent()
Default constructor - initializes to NULL.
Definition opencl.hpp:3371
UserEvent(const Context &context, cl_int *err=NULL)
Constructs a user event on a given context.
Definition opencl.hpp:3355
cl_int setStatus(cl_int status)
Sets the execution status of a user event object.
Definition opencl.hpp:3377
The OpenCL C++ bindings are defined within this namespace.
Definition opencl.hpp:583
vector< T, cl::SVMAllocator< int, cl::SVMTraitFine<> > > fine_svm_vector
Vector alias to simplify contruction of fine-grained SVM containers.
Definition opencl.hpp:3880
cl_int copy(IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer)
Definition opencl.hpp:9485
LocalSpaceArg Local(size_type size)
Helper function for generating LocalSpaceArg objects.
Definition opencl.hpp:5881
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int UnloadCompiler() CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition opencl.hpp:2797
cl_int enqueueUnmapSVM(T *ptr, const vector< Event > *events=NULL, Event *event=NULL)
Definition opencl.hpp:9400
cl::pointer< T, detail::Deleter< Alloc > > allocate_pointer(const Alloc &alloc_, Args &&... args)
Definition opencl.hpp:3827
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:9298
vector< T, cl::SVMAllocator< int, cl::SVMTraitCoarse<> > > coarse_svm_vector
Vector alias to simplify contruction of coarse-grained SVM containers.
Definition opencl.hpp:3874
cl_int mapSVM(cl::vector< T, Alloc > &container)
Definition opencl.hpp:9587
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:3886
cl_int unmapSVM(cl::vector< T, Alloc > &container)
Definition opencl.hpp:9596
Adds constructors and member functions for cl_image_format.
Definition opencl.hpp:2117
ImageFormat(cl_channel_order order, cl_channel_type type)
Initializing constructor.
Definition opencl.hpp:2122
ImageFormat & operator=(const ImageFormat &rhs)
Assignment operator.
Definition opencl.hpp:2132
ImageFormat(const ImageFormat &other)
Copy constructor.
Definition opencl.hpp:2129
ImageFormat()
Default constructor - performs no initialization.
Definition opencl.hpp:2119
Local address wrapper for use with Kernel::setArg.
Definition opencl.hpp:5838
Event type_(const EnqueueArgs &, Ts...)
Function signature of kernel functor with no event dependency.
Definition opencl.hpp:10199
Event result_type
Return type of the functor.
Definition opencl.hpp:10196
static cl_int release(cl_device_id device)
Definition opencl.hpp:1679
static cl_int retain(cl_device_id device)
Definition opencl.hpp:1668