OpenCL C++ Bindings
Loading...
Searching...
No Matches
opencl.hpp
Go to the documentation of this file.
1//
2// Copyright (c) 2008-2024 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
324
336
392#ifndef CL_HPP_
393#define CL_HPP_
394
395/* Handle deprecated preprocessor definitions. In each case, we only check for
396 * the old name if the new name is not defined, so that user code can define
397 * both and hence work with either version of the bindings.
398 */
399#if !defined(CL_HPP_USE_DX_INTEROP) && defined(USE_DX_INTEROP)
400# pragma message("opencl.hpp: USE_DX_INTEROP is deprecated. Define CL_HPP_USE_DX_INTEROP instead")
401# define CL_HPP_USE_DX_INTEROP
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#if defined(__APPLE__) || defined(__MACOSX)
523#include <OpenCL/opencl.h>
524#else
525#include <CL/opencl.h>
526#endif // !__APPLE__
527
528#if __cplusplus >= 201703L
529# define CL_HPP_DEFINE_STATIC_MEMBER_ inline
530#elif defined(_MSC_VER)
531# define CL_HPP_DEFINE_STATIC_MEMBER_ __declspec(selectany)
532#elif defined(__MINGW32__)
533# define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((selectany))
534#else
535# define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((weak))
536#endif // !_MSC_VER
537
538// Define deprecated prefixes and suffixes to ensure compilation
539// in case they are not pre-defined
540#if !defined(CL_API_PREFIX__VERSION_1_1_DEPRECATED)
541#define CL_API_PREFIX__VERSION_1_1_DEPRECATED
542#endif // #if !defined(CL_API_PREFIX__VERSION_1_1_DEPRECATED)
543#if !defined(CL_API_SUFFIX__VERSION_1_1_DEPRECATED)
544#define CL_API_SUFFIX__VERSION_1_1_DEPRECATED
545#endif // #if !defined(CL_API_SUFFIX__VERSION_1_1_DEPRECATED)
546
547#if !defined(CL_API_PREFIX__VERSION_1_2_DEPRECATED)
548#define CL_API_PREFIX__VERSION_1_2_DEPRECATED
549#endif // #if !defined(CL_API_PREFIX__VERSION_1_2_DEPRECATED)
550#if !defined(CL_API_SUFFIX__VERSION_1_2_DEPRECATED)
551#define CL_API_SUFFIX__VERSION_1_2_DEPRECATED
552#endif // #if !defined(CL_API_SUFFIX__VERSION_1_2_DEPRECATED)
553
554#if !defined(CL_API_PREFIX__VERSION_2_2_DEPRECATED)
555#define CL_API_PREFIX__VERSION_2_2_DEPRECATED
556#endif // #if !defined(CL_API_PREFIX__VERSION_2_2_DEPRECATED)
557#if !defined(CL_API_SUFFIX__VERSION_2_2_DEPRECATED)
558#define CL_API_SUFFIX__VERSION_2_2_DEPRECATED
559#endif // #if !defined(CL_API_SUFFIX__VERSION_2_2_DEPRECATED)
560
561#if !defined(CL_CALLBACK)
562#define CL_CALLBACK
563#endif //CL_CALLBACK
564
565#include <utility>
566#include <limits>
567#include <iterator>
568#include <mutex>
569#include <cstring>
570#include <functional>
571
572
573// Define a size_type to represent a correctly resolved size_t
574#if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
575namespace cl {
576 using size_type = ::size_t;
577} // namespace cl
578#else // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
579namespace cl {
580 using size_type = size_t;
581} // namespace cl
582#endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
583
584
585#if defined(CL_HPP_ENABLE_EXCEPTIONS)
586#include <exception>
587#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
588
589#if !defined(CL_HPP_NO_STD_VECTOR)
590#include <vector>
591namespace cl {
592 template < class T, class Alloc = std::allocator<T> >
593 using vector = std::vector<T, Alloc>;
594} // namespace cl
595#endif // #if !defined(CL_HPP_NO_STD_VECTOR)
596
597#if !defined(CL_HPP_NO_STD_STRING)
598#include <string>
599namespace cl {
600 using string = std::string;
601} // namespace cl
602#endif // #if !defined(CL_HPP_NO_STD_STRING)
603
604#if CL_HPP_TARGET_OPENCL_VERSION >= 200
605
606#if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
607#include <memory>
608namespace cl {
609 // Replace unique_ptr and allocate_pointer for internal use
610 // to allow user to replace them
611 template<class T, class D>
612 using pointer = std::unique_ptr<T, D>;
613} // namespace cl
614#endif
615#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
616#if !defined(CL_HPP_NO_STD_ARRAY)
617#include <array>
618namespace cl {
619 template < class T, size_type N >
620 using array = std::array<T, N>;
621} // namespace cl
622#endif // #if !defined(CL_HPP_NO_STD_ARRAY)
623
624// Define size_type appropriately to allow backward-compatibility
625// use of the old size_t interface class
626#if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
627namespace cl {
628 namespace compatibility {
633 template <int N>
634 class size_t
635 {
636 private:
637 size_type data_[N];
638
639 public:
641 size_t()
642 {
643 for (int i = 0; i < N; ++i) {
644 data_[i] = 0;
645 }
646 }
647
648 size_t(const array<size_type, N> &rhs)
649 {
650 for (int i = 0; i < N; ++i) {
651 data_[i] = rhs[i];
652 }
653 }
654
655 size_type& operator[](int index)
656 {
657 return data_[index];
658 }
659
660 const size_type& operator[](int index) const
661 {
662 return data_[index];
663 }
664
666 operator size_type* () { return data_; }
667
669 operator const size_type* () const { return data_; }
670
671 operator array<size_type, N>() const
672 {
673 array<size_type, N> ret;
674
675 for (int i = 0; i < N; ++i) {
676 ret[i] = data_[i];
677 }
678 return ret;
679 }
680 };
681 } // namespace compatibility
682
683 template<int N>
684 using size_t = compatibility::size_t<N>;
685} // namespace cl
686#endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
687
688// Helper alias to avoid confusing the macros
689namespace cl {
690 namespace detail {
691 using size_t_array = array<size_type, 3>;
692 } // namespace detail
693} // namespace cl
694
695
701namespace cl {
702
703#define CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(name) \
704 using PFN_##name = name##_fn
705
706#define CL_HPP_INIT_CL_EXT_FCN_PTR_(name) \
707 if (!pfn_##name) { \
708 pfn_##name = (PFN_##name)clGetExtensionFunctionAddress(#name); \
709 }
710
711#define CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, name) \
712 if (!pfn_##name) { \
713 pfn_##name = (PFN_##name) \
714 clGetExtensionFunctionAddressForPlatform(platform, #name); \
715 }
716
717#ifdef cl_khr_external_memory
718 enum class ExternalMemoryType : cl_external_memory_handle_type_khr;
719#endif
720
721 class Memory;
722 class Platform;
723 class Program;
724 class Device;
725 class Context;
726 class CommandQueue;
727 class DeviceCommandQueue;
728 class Memory;
729 class Buffer;
730 class Pipe;
731#ifdef cl_khr_semaphore
732 class Semaphore;
733#endif
734#if defined(cl_khr_command_buffer)
735 class CommandBufferKhr;
736 class MutableCommandKhr;
737#endif // cl_khr_command_buffer
738
739#if defined(CL_HPP_ENABLE_EXCEPTIONS)
744 class Error : public std::exception
745 {
746 private:
747 cl_int err_;
748 const char * errStr_;
749 public:
759 Error(cl_int err, const char * errStr = nullptr) : err_(err), errStr_(errStr)
760 {}
761
766 const char * what() const noexcept override
767 {
768 if (errStr_ == nullptr) {
769 return "empty";
770 }
771 else {
772 return errStr_;
773 }
774 }
775
780 cl_int err(void) const { return err_; }
781 };
782#define CL_HPP_ERR_STR_(x) #x
783#else
784#define CL_HPP_ERR_STR_(x) nullptr
785#endif // CL_HPP_ENABLE_EXCEPTIONS
786
787
788namespace detail
789{
790#if defined(CL_HPP_ENABLE_EXCEPTIONS)
791static inline cl_int errHandler (
792 cl_int err,
793 const char * errStr = nullptr)
794{
795 if (err != CL_SUCCESS) {
796 throw Error(err, errStr);
797 }
798 return err;
799}
800#else
801static inline cl_int errHandler (cl_int err, const char * errStr = nullptr)
802{
803 (void) errStr; // suppress unused variable warning
804 return err;
805}
806#endif // CL_HPP_ENABLE_EXCEPTIONS
807}
808
809
810
812#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
813#define __GET_DEVICE_INFO_ERR CL_HPP_ERR_STR_(clGetDeviceInfo)
814#define __GET_PLATFORM_INFO_ERR CL_HPP_ERR_STR_(clGetPlatformInfo)
815#define __GET_DEVICE_IDS_ERR CL_HPP_ERR_STR_(clGetDeviceIDs)
816#define __GET_PLATFORM_IDS_ERR CL_HPP_ERR_STR_(clGetPlatformIDs)
817#define __GET_CONTEXT_INFO_ERR CL_HPP_ERR_STR_(clGetContextInfo)
818#define __GET_EVENT_INFO_ERR CL_HPP_ERR_STR_(clGetEventInfo)
819#define __GET_EVENT_PROFILE_INFO_ERR CL_HPP_ERR_STR_(clGetEventProfileInfo)
820#define __GET_MEM_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetMemObjectInfo)
821#define __GET_IMAGE_INFO_ERR CL_HPP_ERR_STR_(clGetImageInfo)
822#define __GET_SAMPLER_INFO_ERR CL_HPP_ERR_STR_(clGetSamplerInfo)
823#define __GET_KERNEL_INFO_ERR CL_HPP_ERR_STR_(clGetKernelInfo)
824#if CL_HPP_TARGET_OPENCL_VERSION >= 120
825#define __GET_KERNEL_ARG_INFO_ERR CL_HPP_ERR_STR_(clGetKernelArgInfo)
826#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
827#if CL_HPP_TARGET_OPENCL_VERSION >= 210
828#define __GET_KERNEL_SUB_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelSubGroupInfo)
829#else
830#define __GET_KERNEL_SUB_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelSubGroupInfoKHR)
831#endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
832#define __GET_KERNEL_WORK_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelWorkGroupInfo)
833#define __GET_PROGRAM_INFO_ERR CL_HPP_ERR_STR_(clGetProgramInfo)
834#define __GET_PROGRAM_BUILD_INFO_ERR CL_HPP_ERR_STR_(clGetProgramBuildInfo)
835#define __GET_COMMAND_QUEUE_INFO_ERR CL_HPP_ERR_STR_(clGetCommandQueueInfo)
836
837#define __CREATE_CONTEXT_ERR CL_HPP_ERR_STR_(clCreateContext)
838#define __CREATE_CONTEXT_FROM_TYPE_ERR CL_HPP_ERR_STR_(clCreateContextFromType)
839#define __GET_SUPPORTED_IMAGE_FORMATS_ERR CL_HPP_ERR_STR_(clGetSupportedImageFormats)
840#if CL_HPP_TARGET_OPENCL_VERSION >= 300
841#define __SET_CONTEXT_DESCTRUCTOR_CALLBACK_ERR CL_HPP_ERR_STR_(clSetContextDestructorCallback)
842#endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
843
844#define __CREATE_BUFFER_ERR CL_HPP_ERR_STR_(clCreateBuffer)
845#define __COPY_ERR CL_HPP_ERR_STR_(cl::copy)
846#define __CREATE_SUBBUFFER_ERR CL_HPP_ERR_STR_(clCreateSubBuffer)
847#define __CREATE_GL_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
848#define __CREATE_GL_RENDER_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
849#define __GET_GL_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetGLObjectInfo)
850#if CL_HPP_TARGET_OPENCL_VERSION >= 120
851#define __CREATE_IMAGE_ERR CL_HPP_ERR_STR_(clCreateImage)
852#define __CREATE_GL_TEXTURE_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture)
853#define __IMAGE_DIMENSION_ERR CL_HPP_ERR_STR_(Incorrect image dimensions)
854#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
855#define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR CL_HPP_ERR_STR_(clSetMemObjectDestructorCallback)
856
857#define __CREATE_USER_EVENT_ERR CL_HPP_ERR_STR_(clCreateUserEvent)
858#define __SET_USER_EVENT_STATUS_ERR CL_HPP_ERR_STR_(clSetUserEventStatus)
859#define __SET_EVENT_CALLBACK_ERR CL_HPP_ERR_STR_(clSetEventCallback)
860#define __WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clWaitForEvents)
861
862#define __CREATE_KERNEL_ERR CL_HPP_ERR_STR_(clCreateKernel)
863#define __SET_KERNEL_ARGS_ERR CL_HPP_ERR_STR_(clSetKernelArg)
864#define __CREATE_PROGRAM_WITH_SOURCE_ERR CL_HPP_ERR_STR_(clCreateProgramWithSource)
865#define __CREATE_PROGRAM_WITH_BINARY_ERR CL_HPP_ERR_STR_(clCreateProgramWithBinary)
866#if CL_HPP_TARGET_OPENCL_VERSION >= 210
867#define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
868#else
869#define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithILKHR)
870#endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
871#if CL_HPP_TARGET_OPENCL_VERSION >= 120
872#define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR CL_HPP_ERR_STR_(clCreateProgramWithBuiltInKernels)
873#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
874#define __BUILD_PROGRAM_ERR CL_HPP_ERR_STR_(clBuildProgram)
875#if CL_HPP_TARGET_OPENCL_VERSION >= 120
876#define __COMPILE_PROGRAM_ERR CL_HPP_ERR_STR_(clCompileProgram)
877#define __LINK_PROGRAM_ERR CL_HPP_ERR_STR_(clLinkProgram)
878#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
879#define __CREATE_KERNELS_IN_PROGRAM_ERR CL_HPP_ERR_STR_(clCreateKernelsInProgram)
880
881#if CL_HPP_TARGET_OPENCL_VERSION >= 200
882#define __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateCommandQueueWithProperties)
883#define __CREATE_SAMPLER_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateSamplerWithProperties)
884#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
885#define __SET_COMMAND_QUEUE_PROPERTY_ERR CL_HPP_ERR_STR_(clSetCommandQueueProperty)
886#define __ENQUEUE_READ_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueReadBuffer)
887#define __ENQUEUE_READ_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueReadBufferRect)
888#define __ENQUEUE_WRITE_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueWriteBuffer)
889#define __ENQUEUE_WRITE_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueWriteBufferRect)
890#define __ENQEUE_COPY_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyBuffer)
891#define __ENQEUE_COPY_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferRect)
892#define __ENQUEUE_FILL_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueFillBuffer)
893#define __ENQUEUE_READ_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueReadImage)
894#define __ENQUEUE_WRITE_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueWriteImage)
895#define __ENQUEUE_COPY_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyImage)
896#define __ENQUEUE_FILL_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueFillImage)
897#define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyImageToBuffer)
898#define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferToImage)
899#define __ENQUEUE_MAP_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueMapBuffer)
900#define __ENQUEUE_MAP_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMMap)
901#define __ENQUEUE_FILL_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMMemFill)
902#define __ENQUEUE_COPY_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMMemcpy)
903#define __ENQUEUE_UNMAP_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMUnmap)
904#define __ENQUEUE_MAP_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueMapImage)
905#define __ENQUEUE_UNMAP_MEM_OBJECT_ERR CL_HPP_ERR_STR_(clEnqueueUnMapMemObject)
906#define __ENQUEUE_NDRANGE_KERNEL_ERR CL_HPP_ERR_STR_(clEnqueueNDRangeKernel)
907#define __ENQUEUE_NATIVE_KERNEL CL_HPP_ERR_STR_(clEnqueueNativeKernel)
908#if CL_HPP_TARGET_OPENCL_VERSION >= 120
909#define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR CL_HPP_ERR_STR_(clEnqueueMigrateMemObjects)
910#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
911#if CL_HPP_TARGET_OPENCL_VERSION >= 210
912#define __ENQUEUE_MIGRATE_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMMigrateMem)
913#define __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clSetDefaultDeviceCommandQueue)
914#endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
915
916
917#define __ENQUEUE_ACQUIRE_GL_ERR CL_HPP_ERR_STR_(clEnqueueAcquireGLObjects)
918#define __ENQUEUE_RELEASE_GL_ERR CL_HPP_ERR_STR_(clEnqueueReleaseGLObjects)
919
920#define __CREATE_PIPE_ERR CL_HPP_ERR_STR_(clCreatePipe)
921#define __GET_PIPE_INFO_ERR CL_HPP_ERR_STR_(clGetPipeInfo)
922
923#define __RETAIN_ERR CL_HPP_ERR_STR_(Retain Object)
924#define __RELEASE_ERR CL_HPP_ERR_STR_(Release Object)
925#define __FLUSH_ERR CL_HPP_ERR_STR_(clFlush)
926#define __FINISH_ERR CL_HPP_ERR_STR_(clFinish)
927#define __VECTOR_CAPACITY_ERR CL_HPP_ERR_STR_(Vector capacity error)
928
929#if CL_HPP_TARGET_OPENCL_VERSION >= 210
930#define __GET_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetHostTimer)
931#define __GET_DEVICE_AND_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetDeviceAndHostTimer)
932#endif
933#if CL_HPP_TARGET_OPENCL_VERSION >= 220
934#define __SET_PROGRAM_RELEASE_CALLBACK_ERR CL_HPP_ERR_STR_(clSetProgramReleaseCallback)
935#define __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR CL_HPP_ERR_STR_(clSetProgramSpecializationConstant)
936#endif
937
938#ifdef cl_khr_external_memory
939#define __ENQUEUE_ACQUIRE_EXTERNAL_MEMORY_ERR CL_HPP_ERR_STR_(clEnqueueAcquireExternalMemObjectsKHR)
940#define __ENQUEUE_RELEASE_EXTERNAL_MEMORY_ERR CL_HPP_ERR_STR_(clEnqueueReleaseExternalMemObjectsKHR)
941#endif
942
943#ifdef cl_khr_semaphore
944#define __GET_SEMAPHORE_KHR_INFO_ERR CL_HPP_ERR_STR_(clGetSemaphoreInfoKHR)
945#define __CREATE_SEMAPHORE_KHR_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateSemaphoreWithPropertiesKHR)
946#define __ENQUEUE_WAIT_SEMAPHORE_KHR_ERR CL_HPP_ERR_STR_(clEnqueueWaitSemaphoresKHR)
947#define __ENQUEUE_SIGNAL_SEMAPHORE_KHR_ERR CL_HPP_ERR_STR_(clEnqueueSignalSemaphoresKHR)
948#define __RETAIN_SEMAPHORE_KHR_ERR CL_HPP_ERR_STR_(clRetainSemaphoreKHR)
949#define __RELEASE_SEMAPHORE_KHR_ERR CL_HPP_ERR_STR_(clReleaseSemaphoreKHR)
950#endif
951
952#ifdef cl_khr_external_semaphore
953#define __GET_SEMAPHORE_HANDLE_FOR_TYPE_KHR_ERR CL_HPP_ERR_STR_(clGetSemaphoreHandleForTypeKHR)
954#endif // cl_khr_external_semaphore
955
956#if defined(cl_khr_command_buffer)
957#define __CREATE_COMMAND_BUFFER_KHR_ERR CL_HPP_ERR_STR_(clCreateCommandBufferKHR)
958#define __GET_COMMAND_BUFFER_INFO_KHR_ERR CL_HPP_ERR_STR_(clGetCommandBufferInfoKHR)
959#define __FINALIZE_COMMAND_BUFFER_KHR_ERR CL_HPP_ERR_STR_(clFinalizeCommandBufferKHR)
960#define __ENQUEUE_COMMAND_BUFFER_KHR_ERR CL_HPP_ERR_STR_(clEnqueueCommandBufferKHR)
961#define __COMMAND_BARRIER_WITH_WAIT_LIST_KHR_ERR CL_HPP_ERR_STR_(clCommandBarrierWithWaitListKHR)
962#define __COMMAND_COPY_BUFFER_KHR_ERR CL_HPP_ERR_STR_(clCommandCopyBufferKHR)
963#define __COMMAND_COPY_BUFFER_RECT_KHR_ERR CL_HPP_ERR_STR_(clCommandCopyBufferRectKHR)
964#define __COMMAND_COPY_BUFFER_TO_IMAGE_KHR_ERR CL_HPP_ERR_STR_(clCommandCopyBufferToImageKHR)
965#define __COMMAND_COPY_IMAGE_KHR_ERR CL_HPP_ERR_STR_(clCommandCopyImageKHR)
966#define __COMMAND_COPY_IMAGE_TO_BUFFER_KHR_ERR CL_HPP_ERR_STR_(clCommandCopyImageToBufferKHR)
967#define __COMMAND_FILL_BUFFER_KHR_ERR CL_HPP_ERR_STR_(clCommandFillBufferKHR)
968#define __COMMAND_FILL_IMAGE_KHR_ERR CL_HPP_ERR_STR_(clCommandFillImageKHR)
969#define __COMMAND_NDRANGE_KERNEL_KHR_ERR CL_HPP_ERR_STR_(clCommandNDRangeKernelKHR)
970#define __UPDATE_MUTABLE_COMMANDS_KHR_ERR CL_HPP_ERR_STR_(clUpdateMutableCommandsKHR)
971#define __GET_MUTABLE_COMMAND_INFO_KHR_ERR CL_HPP_ERR_STR_(clGetMutableCommandInfoKHR)
972#define __RETAIN_COMMAND_BUFFER_KHR_ERR CL_HPP_ERR_STR_(clRetainCommandBufferKHR)
973#define __RELEASE_COMMAND_BUFFER_KHR_ERR CL_HPP_ERR_STR_(clReleaseCommandBufferKHR)
974#endif // cl_khr_command_buffer
975
976#if defined(cl_ext_image_requirements_info)
977#define __GET_IMAGE_REQUIREMENT_INFO_EXT_ERR CL_HPP_ERR_STR_(clGetImageRequirementsInfoEXT)
978#endif //cl_ext_image_requirements_info
979
983#if CL_HPP_TARGET_OPENCL_VERSION >= 120
984#define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevices)
985#else
986#define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevicesEXT)
987#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
988
992#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
993#define __ENQUEUE_MARKER_ERR CL_HPP_ERR_STR_(clEnqueueMarker)
994#define __ENQUEUE_WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clEnqueueWaitForEvents)
995#define __ENQUEUE_BARRIER_ERR CL_HPP_ERR_STR_(clEnqueueBarrier)
996#define __UNLOAD_COMPILER_ERR CL_HPP_ERR_STR_(clUnloadCompiler)
997#define __CREATE_GL_TEXTURE_2D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture2D)
998#define __CREATE_GL_TEXTURE_3D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture3D)
999#define __CREATE_IMAGE2D_ERR CL_HPP_ERR_STR_(clCreateImage2D)
1000#define __CREATE_IMAGE3D_ERR CL_HPP_ERR_STR_(clCreateImage3D)
1001#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
1002
1006#if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
1007#define __CREATE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clCreateCommandQueue)
1008#define __ENQUEUE_TASK_ERR CL_HPP_ERR_STR_(clEnqueueTask)
1009#define __CREATE_SAMPLER_ERR CL_HPP_ERR_STR_(clCreateSampler)
1010#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
1011
1015#if CL_HPP_TARGET_OPENCL_VERSION >= 120
1016#define __ENQUEUE_MARKER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueMarkerWithWaitList)
1017#define __ENQUEUE_BARRIER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueBarrierWithWaitList)
1018#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1019
1020#if CL_HPP_TARGET_OPENCL_VERSION >= 210
1021#define __CLONE_KERNEL_ERR CL_HPP_ERR_STR_(clCloneKernel)
1022#endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
1023
1024#endif // CL_HPP_USER_OVERRIDE_ERROR_STRINGS
1026
1027#ifdef cl_khr_external_memory
1028CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clEnqueueAcquireExternalMemObjectsKHR);
1029CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clEnqueueReleaseExternalMemObjectsKHR);
1030
1031CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clEnqueueAcquireExternalMemObjectsKHR pfn_clEnqueueAcquireExternalMemObjectsKHR = nullptr;
1032CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clEnqueueReleaseExternalMemObjectsKHR pfn_clEnqueueReleaseExternalMemObjectsKHR = nullptr;
1033#endif // cl_khr_external_memory
1034
1035#ifdef cl_khr_semaphore
1036CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCreateSemaphoreWithPropertiesKHR);
1037CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clReleaseSemaphoreKHR);
1038CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clRetainSemaphoreKHR);
1039CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clEnqueueWaitSemaphoresKHR);
1040CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clEnqueueSignalSemaphoresKHR);
1041CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clGetSemaphoreInfoKHR);
1042
1043CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCreateSemaphoreWithPropertiesKHR pfn_clCreateSemaphoreWithPropertiesKHR = nullptr;
1044CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clReleaseSemaphoreKHR pfn_clReleaseSemaphoreKHR = nullptr;
1045CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clRetainSemaphoreKHR pfn_clRetainSemaphoreKHR = nullptr;
1046CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clEnqueueWaitSemaphoresKHR pfn_clEnqueueWaitSemaphoresKHR = nullptr;
1047CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clEnqueueSignalSemaphoresKHR pfn_clEnqueueSignalSemaphoresKHR = nullptr;
1048CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clGetSemaphoreInfoKHR pfn_clGetSemaphoreInfoKHR = nullptr;
1049#endif // cl_khr_semaphore
1050
1051#ifdef cl_khr_external_semaphore
1052CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clGetSemaphoreHandleForTypeKHR);
1053CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clGetSemaphoreHandleForTypeKHR pfn_clGetSemaphoreHandleForTypeKHR = nullptr;
1054#endif // cl_khr_external_semaphore
1055
1056#if defined(cl_khr_command_buffer)
1057CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCreateCommandBufferKHR);
1058CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clFinalizeCommandBufferKHR);
1059CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clRetainCommandBufferKHR);
1060CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clReleaseCommandBufferKHR);
1061CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clGetCommandBufferInfoKHR);
1062CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clEnqueueCommandBufferKHR);
1063CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCommandBarrierWithWaitListKHR);
1064CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCommandCopyBufferKHR);
1065CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCommandCopyBufferRectKHR);
1066CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCommandCopyBufferToImageKHR);
1067CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCommandCopyImageKHR);
1068CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCommandCopyImageToBufferKHR);
1069CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCommandFillBufferKHR);
1070CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCommandFillImageKHR);
1071CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCommandNDRangeKernelKHR);
1072
1073CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCreateCommandBufferKHR pfn_clCreateCommandBufferKHR = nullptr;
1074CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clFinalizeCommandBufferKHR pfn_clFinalizeCommandBufferKHR = nullptr;
1075CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clRetainCommandBufferKHR pfn_clRetainCommandBufferKHR = nullptr;
1076CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clReleaseCommandBufferKHR pfn_clReleaseCommandBufferKHR = nullptr;
1077CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clGetCommandBufferInfoKHR pfn_clGetCommandBufferInfoKHR = nullptr;
1078CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clEnqueueCommandBufferKHR pfn_clEnqueueCommandBufferKHR = nullptr;
1079CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCommandBarrierWithWaitListKHR pfn_clCommandBarrierWithWaitListKHR = nullptr;
1080CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCommandCopyBufferKHR pfn_clCommandCopyBufferKHR = nullptr;
1081CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCommandCopyBufferRectKHR pfn_clCommandCopyBufferRectKHR = nullptr;
1082CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCommandCopyBufferToImageKHR pfn_clCommandCopyBufferToImageKHR = nullptr;
1083CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCommandCopyImageKHR pfn_clCommandCopyImageKHR = nullptr;
1084CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCommandCopyImageToBufferKHR pfn_clCommandCopyImageToBufferKHR = nullptr;
1085CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCommandFillBufferKHR pfn_clCommandFillBufferKHR = nullptr;
1086CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCommandFillImageKHR pfn_clCommandFillImageKHR = nullptr;
1087CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCommandNDRangeKernelKHR pfn_clCommandNDRangeKernelKHR = nullptr;
1088#endif /* cl_khr_command_buffer */
1089
1090#if defined(cl_khr_command_buffer_mutable_dispatch)
1091CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clUpdateMutableCommandsKHR);
1092CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clGetMutableCommandInfoKHR);
1093
1094CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clUpdateMutableCommandsKHR pfn_clUpdateMutableCommandsKHR = nullptr;
1095CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clGetMutableCommandInfoKHR pfn_clGetMutableCommandInfoKHR = nullptr;
1096#endif /* cl_khr_command_buffer_mutable_dispatch */
1097
1098#if defined(cl_ext_image_requirements_info)
1099CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clGetImageRequirementsInfoEXT);
1100CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clGetImageRequirementsInfoEXT pfn_clGetImageRequirementsInfoEXT = nullptr;
1101#endif
1102
1103#if defined(cl_ext_device_fission)
1104CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCreateSubDevicesEXT);
1105CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCreateSubDevicesEXT
1106 pfn_clCreateSubDevicesEXT = nullptr;
1107#endif
1108
1109namespace detail {
1110
1111// Generic getInfoHelper. The final parameter is used to guide overload
1112// resolution: the actual parameter passed is an int, which makes this
1113// a worse conversion sequence than a specialization that declares the
1114// parameter as an int.
1115template<typename Functor, typename T>
1116inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long)
1117{
1118 return f(name, sizeof(T), param, nullptr);
1119}
1120
1121// Specialized for getInfo<CL_PROGRAM_BINARIES>
1122// Assumes that the output vector was correctly resized on the way in
1123template <typename Func>
1124inline cl_int getInfoHelper(Func f, cl_uint name, vector<vector<unsigned char>>* param, int)
1125{
1126 if (name != CL_PROGRAM_BINARIES) {
1127 return CL_INVALID_VALUE;
1128 }
1129 if (param) {
1130 // Create array of pointers, calculate total size and pass pointer array in
1131 size_type numBinaries = param->size();
1132 vector<unsigned char*> binariesPointers(numBinaries);
1133
1134 for (size_type i = 0; i < numBinaries; ++i)
1135 {
1136 binariesPointers[i] = (*param)[i].data();
1137 }
1138
1139 cl_int err = f(name, numBinaries * sizeof(unsigned char*), binariesPointers.data(), nullptr);
1140
1141 if (err != CL_SUCCESS) {
1142 return err;
1143 }
1144 }
1145
1146 return CL_SUCCESS;
1147}
1148
1149// Specialized getInfoHelper for vector params
1150template <typename Func, typename T>
1151inline cl_int getInfoHelper(Func f, cl_uint name, vector<T>* param, long)
1152{
1153 size_type required;
1154 cl_int err = f(name, 0, nullptr, &required);
1155 if (err != CL_SUCCESS) {
1156 return err;
1157 }
1158 const size_type elements = required / sizeof(T);
1159
1160 // Temporary to avoid changing param on an error
1161 vector<T> localData(elements);
1162 err = f(name, required, localData.data(), nullptr);
1163 if (err != CL_SUCCESS) {
1164 return err;
1165 }
1166 if (param) {
1167 *param = std::move(localData);
1168 }
1169
1170 return CL_SUCCESS;
1171}
1172
1173/* Specialization for reference-counted types. This depends on the
1174 * existence of Wrapper<T>::cl_type, and none of the other types having the
1175 * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1176 * does not work, because when using a derived type (e.g. Context) the generic
1177 * template will provide a better match.
1178 */
1179template <typename Func, typename T>
1180inline cl_int getInfoHelper(
1181 Func f, cl_uint name, vector<T>* param, int, typename T::cl_type = 0)
1182{
1183 size_type required;
1184 cl_int err = f(name, 0, nullptr, &required);
1185 if (err != CL_SUCCESS) {
1186 return err;
1187 }
1188
1189 const size_type elements = required / sizeof(typename T::cl_type);
1190
1191 vector<typename T::cl_type> value(elements);
1192 err = f(name, required, value.data(), nullptr);
1193 if (err != CL_SUCCESS) {
1194 return err;
1195 }
1196
1197 if (param) {
1198 // Assign to convert CL type to T for each element
1199 param->resize(elements);
1200
1201 // Assign to param, constructing with retain behaviour
1202 // to correctly capture each underlying CL object
1203 for (size_type i = 0; i < elements; i++) {
1204 (*param)[i] = T(value[i], true);
1205 }
1206 }
1207 return CL_SUCCESS;
1208}
1209
1210// Specialized GetInfoHelper for string params
1211template <typename Func>
1212inline cl_int getInfoHelper(Func f, cl_uint name, string* param, long)
1213{
1214 size_type required;
1215 cl_int err = f(name, 0, nullptr, &required);
1216 if (err != CL_SUCCESS) {
1217 return err;
1218 }
1219
1220 // std::string has a constant data member
1221 // a char vector does not
1222 if (required > 0) {
1223 vector<char> value(required);
1224 err = f(name, required, value.data(), nullptr);
1225 if (err != CL_SUCCESS) {
1226 return err;
1227 }
1228 if (param) {
1229 param->assign(value.begin(), value.end() - 1);
1230 }
1231 }
1232 else if (param) {
1233 param->assign("");
1234 }
1235 return CL_SUCCESS;
1236}
1237
1238// Specialized GetInfoHelper for clsize_t params
1239template <typename Func, size_type N>
1240inline cl_int getInfoHelper(Func f, cl_uint name, array<size_type, N>* param, long)
1241{
1242 size_type required;
1243 cl_int err = f(name, 0, nullptr, &required);
1244 if (err != CL_SUCCESS) {
1245 return err;
1246 }
1247
1248 size_type elements = required / sizeof(size_type);
1249 vector<size_type> value(elements, 0);
1250
1251 err = f(name, required, value.data(), nullptr);
1252 if (err != CL_SUCCESS) {
1253 return err;
1254 }
1255
1256 // Bound the copy with N to prevent overruns
1257 // if passed N > than the amount copied
1258 if (elements > N) {
1259 elements = N;
1260 }
1261 for (size_type i = 0; i < elements; ++i) {
1262 (*param)[i] = value[i];
1263 }
1264
1265 return CL_SUCCESS;
1266}
1267
1268template<typename T> struct ReferenceHandler;
1269
1270/* Specialization for reference-counted types. This depends on the
1271 * existence of Wrapper<T>::cl_type, and none of the other types having the
1272 * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1273 * does not work, because when using a derived type (e.g. Context) the generic
1274 * template will provide a better match.
1275 */
1276template<typename Func, typename T>
1277inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0)
1278{
1279 typename T::cl_type value;
1280 cl_int err = f(name, sizeof(value), &value, nullptr);
1281 if (err != CL_SUCCESS) {
1282 return err;
1283 }
1284 *param = value;
1285 if (value != nullptr)
1286 {
1287 err = param->retain();
1288 if (err != CL_SUCCESS) {
1289 return err;
1290 }
1291 }
1292 return CL_SUCCESS;
1293}
1294
1295#define CL_HPP_PARAM_NAME_INFO_1_0_(F) \
1296 F(cl_platform_info, CL_PLATFORM_PROFILE, string) \
1297 F(cl_platform_info, CL_PLATFORM_VERSION, string) \
1298 F(cl_platform_info, CL_PLATFORM_NAME, string) \
1299 F(cl_platform_info, CL_PLATFORM_VENDOR, string) \
1300 F(cl_platform_info, CL_PLATFORM_EXTENSIONS, string) \
1301 \
1302 F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
1303 F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
1304 F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
1305 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
1306 F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, size_type) \
1307 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, cl::vector<size_type>) \
1308 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
1309 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
1310 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
1311 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
1312 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
1313 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
1314 F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
1315 F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \
1316 F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
1317 F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
1318 F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
1319 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, size_type) \
1320 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, size_type) \
1321 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, size_type) \
1322 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, size_type) \
1323 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, size_type) \
1324 F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \
1325 F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, size_type) \
1326 F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
1327 F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
1328 F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
1329 F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
1330 F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
1331 F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
1332 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
1333 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
1334 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
1335 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
1336 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
1337 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
1338 F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
1339 F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
1340 F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
1341 F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, size_type) \
1342 F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
1343 F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
1344 F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
1345 F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
1346 F(cl_device_info, CL_DEVICE_PLATFORM, cl::Platform) \
1347 F(cl_device_info, CL_DEVICE_NAME, string) \
1348 F(cl_device_info, CL_DEVICE_VENDOR, string) \
1349 F(cl_device_info, CL_DRIVER_VERSION, string) \
1350 F(cl_device_info, CL_DEVICE_PROFILE, string) \
1351 F(cl_device_info, CL_DEVICE_VERSION, string) \
1352 F(cl_device_info, CL_DEVICE_EXTENSIONS, string) \
1353 \
1354 F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
1355 F(cl_context_info, CL_CONTEXT_DEVICES, cl::vector<Device>) \
1356 F(cl_context_info, CL_CONTEXT_PROPERTIES, cl::vector<cl_context_properties>) \
1357 \
1358 F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
1359 F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
1360 F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
1361 F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \
1362 \
1363 F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
1364 F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
1365 F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
1366 F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
1367 \
1368 F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
1369 F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
1370 F(cl_mem_info, CL_MEM_SIZE, size_type) \
1371 F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
1372 F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
1373 F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
1374 F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
1375 \
1376 F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
1377 F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, size_type) \
1378 F(cl_image_info, CL_IMAGE_ROW_PITCH, size_type) \
1379 F(cl_image_info, CL_IMAGE_SLICE_PITCH, size_type) \
1380 F(cl_image_info, CL_IMAGE_WIDTH, size_type) \
1381 F(cl_image_info, CL_IMAGE_HEIGHT, size_type) \
1382 F(cl_image_info, CL_IMAGE_DEPTH, size_type) \
1383 \
1384 F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
1385 F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
1386 F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \
1387 F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \
1388 F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \
1389 \
1390 F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
1391 F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
1392 F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
1393 F(cl_program_info, CL_PROGRAM_DEVICES, cl::vector<Device>) \
1394 F(cl_program_info, CL_PROGRAM_SOURCE, string) \
1395 F(cl_program_info, CL_PROGRAM_BINARY_SIZES, cl::vector<size_type>) \
1396 F(cl_program_info, CL_PROGRAM_BINARIES, cl::vector<cl::vector<unsigned char>>) \
1397 \
1398 F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
1399 F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, string) \
1400 F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, string) \
1401 \
1402 F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, string) \
1403 F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
1404 F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
1405 F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
1406 F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
1407 \
1408 F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, size_type) \
1409 F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::detail::size_t_array) \
1410 F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
1411 \
1412 F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
1413 F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
1414 F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
1415 F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
1416
1417
1418#define CL_HPP_PARAM_NAME_INFO_1_1_(F) \
1419 F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
1420 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
1421 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
1422 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
1423 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
1424 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
1425 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
1426 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
1427 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
1428 F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, string) \
1429 \
1430 F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
1431 F(cl_mem_info, CL_MEM_OFFSET, size_type) \
1432 \
1433 F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1434 F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
1435 \
1436 F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
1437
1438#define CL_HPP_PARAM_NAME_INFO_1_2_(F) \
1439 F(cl_program_info, CL_PROGRAM_NUM_KERNELS, size_type) \
1440 F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, string) \
1441 \
1442 F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \
1443 \
1444 F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, string) \
1445 \
1446 F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \
1447 F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \
1448 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, string) \
1449 F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, string) \
1450 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \
1451 \
1452 F(cl_kernel_work_group_info, CL_KERNEL_GLOBAL_WORK_SIZE, cl::detail::size_t_array) \
1453 \
1454 F(cl_device_info, CL_DEVICE_LINKER_AVAILABLE, cl_bool) \
1455 F(cl_device_info, CL_DEVICE_IMAGE_MAX_BUFFER_SIZE, size_type) \
1456 F(cl_device_info, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, size_type) \
1457 F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl::Device) \
1458 F(cl_device_info, CL_DEVICE_PARTITION_MAX_SUB_DEVICES, cl_uint) \
1459 F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, cl::vector<cl_device_partition_property>) \
1460 F(cl_device_info, CL_DEVICE_PARTITION_TYPE, cl::vector<cl_device_partition_property>) \
1461 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \
1462 F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, cl_bool) \
1463 F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \
1464 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, string) \
1465 F(cl_device_info, CL_DEVICE_PRINTF_BUFFER_SIZE, size_type) \
1466 \
1467 F(cl_image_info, CL_IMAGE_ARRAY_SIZE, size_type) \
1468 F(cl_image_info, CL_IMAGE_NUM_MIP_LEVELS, cl_uint) \
1469 F(cl_image_info, CL_IMAGE_NUM_SAMPLES, cl_uint)
1470
1471#define CL_HPP_PARAM_NAME_INFO_2_0_(F) \
1472 F(cl_device_info, CL_DEVICE_QUEUE_ON_HOST_PROPERTIES, cl_command_queue_properties) \
1473 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES, cl_command_queue_properties) \
1474 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, cl_uint) \
1475 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, cl_uint) \
1476 F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_QUEUES, cl_uint) \
1477 F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_EVENTS, cl_uint) \
1478 F(cl_device_info, CL_DEVICE_MAX_PIPE_ARGS, cl_uint) \
1479 F(cl_device_info, CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS, cl_uint) \
1480 F(cl_device_info, CL_DEVICE_PIPE_MAX_PACKET_SIZE, cl_uint) \
1481 F(cl_device_info, CL_DEVICE_SVM_CAPABILITIES, cl_device_svm_capabilities) \
1482 F(cl_device_info, CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT, cl_uint) \
1483 F(cl_device_info, CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT, cl_uint) \
1484 F(cl_device_info, CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT, cl_uint) \
1485 F(cl_device_info, CL_DEVICE_IMAGE_PITCH_ALIGNMENT, cl_uint) \
1486 F(cl_device_info, CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT, cl_uint) \
1487 F(cl_device_info, CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS, cl_uint ) \
1488 F(cl_device_info, CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE, size_type ) \
1489 F(cl_device_info, CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE, size_type ) \
1490 F(cl_profiling_info, CL_PROFILING_COMMAND_COMPLETE, cl_ulong) \
1491 F(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM, cl_bool) \
1492 F(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_SVM_PTRS, void**) \
1493 F(cl_command_queue_info, CL_QUEUE_SIZE, cl_uint) \
1494 F(cl_mem_info, CL_MEM_USES_SVM_POINTER, cl_bool) \
1495 F(cl_program_build_info, CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, size_type) \
1496 F(cl_pipe_info, CL_PIPE_PACKET_SIZE, cl_uint) \
1497 F(cl_pipe_info, CL_PIPE_MAX_PACKETS, cl_uint)
1498
1499#define CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(F) \
1500 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR, size_type) \
1501 F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR, size_type)
1502
1503#define CL_HPP_PARAM_NAME_INFO_IL_KHR_(F) \
1504 F(cl_device_info, CL_DEVICE_IL_VERSION_KHR, string) \
1505 F(cl_program_info, CL_PROGRAM_IL_KHR, cl::vector<unsigned char>)
1506
1507#define CL_HPP_PARAM_NAME_INFO_2_1_(F) \
1508 F(cl_platform_info, CL_PLATFORM_HOST_TIMER_RESOLUTION, cl_ulong) \
1509 F(cl_program_info, CL_PROGRAM_IL, cl::vector<unsigned char>) \
1510 F(cl_device_info, CL_DEVICE_MAX_NUM_SUB_GROUPS, cl_uint) \
1511 F(cl_device_info, CL_DEVICE_IL_VERSION, string) \
1512 F(cl_device_info, CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS, cl_bool) \
1513 F(cl_command_queue_info, CL_QUEUE_DEVICE_DEFAULT, cl::DeviceCommandQueue) \
1514 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE, size_type) \
1515 F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE, size_type) \
1516 F(cl_kernel_sub_group_info, CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT, cl::detail::size_t_array) \
1517 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_NUM_SUB_GROUPS, size_type) \
1518 F(cl_kernel_sub_group_info, CL_KERNEL_COMPILE_NUM_SUB_GROUPS, size_type)
1519
1520#define CL_HPP_PARAM_NAME_INFO_2_2_(F) \
1521 F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_CTORS_PRESENT, cl_bool) \
1522 F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_DTORS_PRESENT, cl_bool)
1523
1524#define CL_HPP_PARAM_NAME_DEVICE_FISSION_EXT_(F) \
1525 F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl::Device) \
1526 F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, cl::vector<cl_device_partition_property_ext>) \
1527 F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, cl::vector<cl_device_partition_property_ext>) \
1528 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
1529 F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, cl::vector<cl_device_partition_property_ext>)
1530
1531#define CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_CL3_SHARED_(F) \
1532 F(cl_platform_info, CL_PLATFORM_NUMERIC_VERSION_KHR, cl_version_khr) \
1533 F(cl_platform_info, CL_PLATFORM_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1534 \
1535 F(cl_device_info, CL_DEVICE_NUMERIC_VERSION_KHR, cl_version_khr) \
1536 F(cl_device_info, CL_DEVICE_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1537 F(cl_device_info, CL_DEVICE_ILS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1538 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>)
1539
1540#define CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_KHRONLY_(F) \
1541 F(cl_device_info, CL_DEVICE_OPENCL_C_NUMERIC_VERSION_KHR, cl_version_khr)
1542
1543// Note: the query for CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR is handled specially!
1544#define CL_HPP_PARAM_NAME_CL_KHR_SEMAPHORE_(F) \
1545 F(cl_semaphore_info_khr, CL_SEMAPHORE_CONTEXT_KHR, cl::Context) \
1546 F(cl_semaphore_info_khr, CL_SEMAPHORE_REFERENCE_COUNT_KHR, cl_uint) \
1547 F(cl_semaphore_info_khr, CL_SEMAPHORE_PROPERTIES_KHR, cl::vector<cl_semaphore_properties_khr>) \
1548 F(cl_semaphore_info_khr, CL_SEMAPHORE_TYPE_KHR, cl_semaphore_type_khr) \
1549 F(cl_semaphore_info_khr, CL_SEMAPHORE_PAYLOAD_KHR, cl_semaphore_payload_khr) \
1550 F(cl_platform_info, CL_PLATFORM_SEMAPHORE_TYPES_KHR, cl::vector<cl_semaphore_type_khr>) \
1551 F(cl_device_info, CL_DEVICE_SEMAPHORE_TYPES_KHR, cl::vector<cl_semaphore_type_khr>) \
1552
1553#define CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_MEMORY_(F) \
1554 F(cl_device_info, CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR, cl::vector<cl::ExternalMemoryType>) \
1555 F(cl_platform_info, CL_PLATFORM_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR, cl::vector<cl::ExternalMemoryType>)
1556
1557#define CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_(F) \
1558 F(cl_platform_info, CL_PLATFORM_SEMAPHORE_IMPORT_HANDLE_TYPES_KHR, cl::vector<cl_external_semaphore_handle_type_khr>) \
1559 F(cl_platform_info, CL_PLATFORM_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR, cl::vector<cl_external_semaphore_handle_type_khr>) \
1560 F(cl_device_info, CL_DEVICE_SEMAPHORE_IMPORT_HANDLE_TYPES_KHR, cl::vector<cl_external_semaphore_handle_type_khr>) \
1561 F(cl_device_info, CL_DEVICE_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR, cl::vector<cl_external_semaphore_handle_type_khr>) \
1562 F(cl_semaphore_info_khr, CL_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR, cl::vector<cl_external_semaphore_handle_type_khr>) \
1563
1564#define CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_DX_FENCE_EXT(F) \
1565 F(cl_external_semaphore_handle_type_khr, CL_SEMAPHORE_HANDLE_D3D12_FENCE_KHR, void*) \
1566
1567#define CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_OPAQUE_FD_EXT(F) \
1568 F(cl_external_semaphore_handle_type_khr, CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR, int) \
1569
1570#define CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_SYNC_FD_EXT(F) \
1571 F(cl_external_semaphore_handle_type_khr, CL_SEMAPHORE_HANDLE_SYNC_FD_KHR, int) \
1572
1573#define CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_WIN32_EXT(F) \
1574 F(cl_external_semaphore_handle_type_khr, CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR, void*) \
1575 F(cl_external_semaphore_handle_type_khr, CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KMT_KHR, void*) \
1576
1577#define CL_HPP_PARAM_NAME_INFO_3_0_(F) \
1578 F(cl_platform_info, CL_PLATFORM_NUMERIC_VERSION, cl_version) \
1579 F(cl_platform_info, CL_PLATFORM_EXTENSIONS_WITH_VERSION, cl::vector<cl_name_version>) \
1580 \
1581 F(cl_device_info, CL_DEVICE_NUMERIC_VERSION, cl_version) \
1582 F(cl_device_info, CL_DEVICE_EXTENSIONS_WITH_VERSION, cl::vector<cl_name_version>) \
1583 F(cl_device_info, CL_DEVICE_ILS_WITH_VERSION, cl::vector<cl_name_version>) \
1584 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION, cl::vector<cl_name_version>) \
1585 F(cl_device_info, CL_DEVICE_ATOMIC_MEMORY_CAPABILITIES, cl_device_atomic_capabilities) \
1586 F(cl_device_info, CL_DEVICE_ATOMIC_FENCE_CAPABILITIES, cl_device_atomic_capabilities) \
1587 F(cl_device_info, CL_DEVICE_NON_UNIFORM_WORK_GROUP_SUPPORT, cl_bool) \
1588 F(cl_device_info, CL_DEVICE_OPENCL_C_ALL_VERSIONS, cl::vector<cl_name_version>) \
1589 F(cl_device_info, CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1590 F(cl_device_info, CL_DEVICE_WORK_GROUP_COLLECTIVE_FUNCTIONS_SUPPORT, cl_bool) \
1591 F(cl_device_info, CL_DEVICE_GENERIC_ADDRESS_SPACE_SUPPORT, cl_bool) \
1592 F(cl_device_info, CL_DEVICE_OPENCL_C_FEATURES, cl::vector<cl_name_version>) \
1593 F(cl_device_info, CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES, cl_device_device_enqueue_capabilities) \
1594 F(cl_device_info, CL_DEVICE_PIPE_SUPPORT, cl_bool) \
1595 F(cl_device_info, CL_DEVICE_LATEST_CONFORMANCE_VERSION_PASSED, string) \
1596 \
1597 F(cl_command_queue_info, CL_QUEUE_PROPERTIES_ARRAY, cl::vector<cl_queue_properties>) \
1598 F(cl_mem_info, CL_MEM_PROPERTIES, cl::vector<cl_mem_properties>) \
1599 F(cl_pipe_info, CL_PIPE_PROPERTIES, cl::vector<cl_pipe_properties>) \
1600 F(cl_sampler_info, CL_SAMPLER_PROPERTIES, cl::vector<cl_sampler_properties>) \
1601
1602#define CL_HPP_PARAM_NAME_CL_IMAGE_REQUIREMENTS_EXT(F) \
1603 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_ROW_PITCH_ALIGNMENT_EXT, size_type) \
1604 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_BASE_ADDRESS_ALIGNMENT_EXT, size_type) \
1605 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_SIZE_EXT, size_type) \
1606 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_MAX_WIDTH_EXT, cl_uint) \
1607 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_MAX_HEIGHT_EXT, cl_uint) \
1608 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_MAX_DEPTH_EXT, cl_uint) \
1609 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_MAX_ARRAY_SIZE_EXT, cl_uint) \
1610
1611#define CL_HPP_PARAM_NAME_CL_IMAGE_REQUIREMENTS_SLICE_PITCH_ALIGNMENT_EXT(F) \
1612 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_SLICE_PITCH_ALIGNMENT_EXT, size_type) \
1613
1614template <typename enum_type, cl_int Name>
1615struct param_traits {};
1616
1617#define CL_HPP_DECLARE_PARAM_TRAITS_(token, param_name, T) \
1618struct token; \
1619template<> \
1620struct param_traits<detail:: token,param_name> \
1621{ \
1622 enum { value = param_name }; \
1623 typedef T param_type; \
1624};
1625
1626CL_HPP_PARAM_NAME_INFO_1_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1627#if CL_HPP_TARGET_OPENCL_VERSION >= 110
1628CL_HPP_PARAM_NAME_INFO_1_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1629#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
1630#if CL_HPP_TARGET_OPENCL_VERSION >= 120
1631CL_HPP_PARAM_NAME_INFO_1_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1632#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1633#if CL_HPP_TARGET_OPENCL_VERSION >= 200
1634CL_HPP_PARAM_NAME_INFO_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1635#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
1636#if CL_HPP_TARGET_OPENCL_VERSION >= 210
1637CL_HPP_PARAM_NAME_INFO_2_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1638#endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
1639#if CL_HPP_TARGET_OPENCL_VERSION >= 220
1640CL_HPP_PARAM_NAME_INFO_2_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1641#endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
1642#if CL_HPP_TARGET_OPENCL_VERSION >= 300
1643CL_HPP_PARAM_NAME_INFO_3_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1644#endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
1645
1646#if defined(cl_khr_subgroups) && CL_HPP_TARGET_OPENCL_VERSION < 210
1647CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1648#endif // #if defined(cl_khr_subgroups) && CL_HPP_TARGET_OPENCL_VERSION < 210
1649
1650#if defined(cl_khr_il_program) && CL_HPP_TARGET_OPENCL_VERSION < 210
1651CL_HPP_PARAM_NAME_INFO_IL_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1652#endif // #if defined(cl_khr_il_program) && CL_HPP_TARGET_OPENCL_VERSION < 210
1653
1654
1655// Flags deprecated in OpenCL 2.0
1656#define CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(F) \
1657 F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties)
1658
1659#define CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(F) \
1660 F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool)
1661
1662#define CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(F) \
1663 F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer)
1664
1665// Include deprecated query flags based on versions
1666// Only include deprecated 1.0 flags if 2.0 not active as there is an enum clash
1667#if CL_HPP_TARGET_OPENCL_VERSION > 100 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 && CL_HPP_TARGET_OPENCL_VERSION < 200
1668CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1669#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 110
1670#if CL_HPP_TARGET_OPENCL_VERSION > 110 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1671CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1672#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1673#if CL_HPP_TARGET_OPENCL_VERSION > 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1674CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1675#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
1676
1677#if defined(cl_ext_device_fission)
1678CL_HPP_PARAM_NAME_DEVICE_FISSION_EXT_(CL_HPP_DECLARE_PARAM_TRAITS_)
1679#endif // cl_ext_device_fission
1680
1681#if defined(cl_khr_extended_versioning)
1682#if CL_HPP_TARGET_OPENCL_VERSION < 300
1683CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_CL3_SHARED_(CL_HPP_DECLARE_PARAM_TRAITS_)
1684#endif // CL_HPP_TARGET_OPENCL_VERSION < 300
1685CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_KHRONLY_(CL_HPP_DECLARE_PARAM_TRAITS_)
1686#endif // cl_khr_extended_versioning
1687
1688#if defined(cl_khr_semaphore)
1689CL_HPP_PARAM_NAME_CL_KHR_SEMAPHORE_(CL_HPP_DECLARE_PARAM_TRAITS_)
1690#if defined(CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR)
1691CL_HPP_DECLARE_PARAM_TRAITS_(cl_semaphore_info_khr, CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR, cl::vector<cl::Device>)
1692#endif // defined(CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR)
1693#endif // defined(cl_khr_semaphore)
1694
1695#ifdef cl_khr_external_memory
1696CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_MEMORY_(CL_HPP_DECLARE_PARAM_TRAITS_)
1697#endif // cl_khr_external_memory
1698
1699#if defined(cl_khr_external_semaphore)
1700CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_(CL_HPP_DECLARE_PARAM_TRAITS_)
1701#endif // cl_khr_external_semaphore
1702
1703#if defined(cl_khr_external_semaphore_dx_fence)
1704CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_DX_FENCE_EXT(CL_HPP_DECLARE_PARAM_TRAITS_)
1705#endif // cl_khr_external_semaphore_dx_fence
1706#if defined(cl_khr_external_semaphore_opaque_fd)
1707CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_OPAQUE_FD_EXT(CL_HPP_DECLARE_PARAM_TRAITS_)
1708#endif // cl_khr_external_semaphore_opaque_fd
1709#if defined(cl_khr_external_semaphore_sync_fd)
1710CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_SYNC_FD_EXT(CL_HPP_DECLARE_PARAM_TRAITS_)
1711#endif // cl_khr_external_semaphore_sync_fd
1712#if defined(cl_khr_external_semaphore_win32)
1713CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_WIN32_EXT(CL_HPP_DECLARE_PARAM_TRAITS_)
1714#endif // cl_khr_external_semaphore_win32
1715
1716#if defined(cl_khr_device_uuid)
1717using uuid_array = array<cl_uchar, CL_UUID_SIZE_KHR>;
1718using luid_array = array<cl_uchar, CL_LUID_SIZE_KHR>;
1719CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_UUID_KHR, uuid_array)
1720CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DRIVER_UUID_KHR, uuid_array)
1721CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LUID_VALID_KHR, cl_bool)
1722CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LUID_KHR, luid_array)
1723CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_NODE_MASK_KHR, cl_uint)
1724#endif
1725
1726#if defined(cl_khr_pci_bus_info)
1727CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PCI_BUS_INFO_KHR, cl_device_pci_bus_info_khr)
1728#endif
1729
1730// Note: some headers do not define cl_khr_image2d_from_buffer
1731#if CL_HPP_TARGET_OPENCL_VERSION < 200
1732#if defined(CL_DEVICE_IMAGE_PITCH_ALIGNMENT_KHR)
1733CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_IMAGE_PITCH_ALIGNMENT_KHR, cl_uint)
1734#endif
1735#if defined(CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT_KHR)
1736CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT_KHR, cl_uint)
1737#endif
1738#endif // CL_HPP_TARGET_OPENCL_VERSION < 200
1739
1740#if defined(cl_khr_integer_dot_product)
1741CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGER_DOT_PRODUCT_CAPABILITIES_KHR, cl_device_integer_dot_product_capabilities_khr)
1742#if defined(CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_8BIT_KHR)
1743CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_8BIT_KHR, cl_device_integer_dot_product_acceleration_properties_khr)
1744CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_4x8BIT_PACKED_KHR, cl_device_integer_dot_product_acceleration_properties_khr)
1745#endif // defined(CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_8BIT_KHR)
1746#endif // defined(cl_khr_integer_dot_product)
1747
1748#if defined(cl_ext_image_requirements_info)
1749CL_HPP_PARAM_NAME_CL_IMAGE_REQUIREMENTS_EXT(CL_HPP_DECLARE_PARAM_TRAITS_)
1750#endif // cl_ext_image_requirements_info
1751
1752#if defined(cl_ext_image_from_buffer)
1753CL_HPP_PARAM_NAME_CL_IMAGE_REQUIREMENTS_SLICE_PITCH_ALIGNMENT_EXT(CL_HPP_DECLARE_PARAM_TRAITS_)
1754#endif // cl_ext_image_from_buffer
1755
1756#ifdef CL_PLATFORM_ICD_SUFFIX_KHR
1757CL_HPP_DECLARE_PARAM_TRAITS_(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, string)
1758#endif
1759
1760#ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
1761CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong)
1762#endif
1763#ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
1764CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, vector<size_type>)
1765#endif
1766#ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
1767CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint)
1768#endif
1769#ifdef CL_DEVICE_SIMD_WIDTH_AMD
1770CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint)
1771#endif
1772#ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD
1773CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint)
1774#endif
1775#ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD
1776CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint)
1777#endif
1778#ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
1779CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint)
1780#endif
1781#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
1782CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint)
1783#endif
1784#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
1785CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint)
1786#endif
1787#ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
1788CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint)
1789#endif
1790#ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
1791CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint)
1792#endif
1793#ifdef CL_DEVICE_BOARD_NAME_AMD
1794CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_BOARD_NAME_AMD, string)
1795#endif
1796
1797#ifdef CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM
1798CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM, cl_ulong)
1799#endif
1800#ifdef CL_DEVICE_JOB_SLOTS_ARM
1801CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_JOB_SLOTS_ARM, cl_uint)
1802#endif
1803#ifdef CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM
1804CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM, cl_bitfield)
1805#endif
1806#ifdef CL_DEVICE_SUPPORTED_REGISTER_ALLOCATIONS_ARM
1807CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SUPPORTED_REGISTER_ALLOCATIONS_ARM, vector<cl_uint>)
1808#endif
1809#ifdef CL_DEVICE_MAX_WARP_COUNT_ARM
1810CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_MAX_WARP_COUNT_ARM, cl_uint)
1811#endif
1812#ifdef CL_KERNEL_MAX_WARP_COUNT_ARM
1813CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_info, CL_KERNEL_MAX_WARP_COUNT_ARM, cl_uint)
1814#endif
1815#ifdef CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_ARM
1816CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_ARM, cl_uint)
1817#endif
1818#ifdef CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM
1819CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM, cl_int)
1820#endif
1821#ifdef CL_KERNEL_EXEC_INFO_WARP_COUNT_LIMIT_ARM
1822CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WARP_COUNT_LIMIT_ARM, cl_uint)
1823#endif
1824#ifdef CL_KERNEL_EXEC_INFO_COMPUTE_UNIT_MAX_QUEUED_BATCHES_ARM
1825CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_COMPUTE_UNIT_MAX_QUEUED_BATCHES_ARM, cl_uint)
1826#endif
1827
1828#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
1829CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint)
1830#endif
1831#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV
1832CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint)
1833#endif
1834#ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV
1835CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint)
1836#endif
1837#ifdef CL_DEVICE_WARP_SIZE_NV
1838CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint)
1839#endif
1840#ifdef CL_DEVICE_GPU_OVERLAP_NV
1841CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool)
1842#endif
1843#ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV
1844CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool)
1845#endif
1846#ifdef CL_DEVICE_INTEGRATED_MEMORY_NV
1847CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool)
1848#endif
1849
1850#if defined(cl_khr_command_buffer)
1851CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMMAND_BUFFER_CAPABILITIES_KHR, cl_device_command_buffer_capabilities_khr)
1852CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMMAND_BUFFER_REQUIRED_QUEUE_PROPERTIES_KHR, cl_command_buffer_properties_khr)
1853CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_QUEUES_KHR, cl::vector<CommandQueue>)
1854CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_NUM_QUEUES_KHR, cl_uint)
1855CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_REFERENCE_COUNT_KHR, cl_uint)
1856CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_STATE_KHR, cl_command_buffer_state_khr)
1857CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_PROPERTIES_ARRAY_KHR, cl::vector<cl_command_buffer_properties_khr>)
1858#endif /* cl_khr_command_buffer */
1859
1860#if defined(cl_khr_command_buffer_mutable_dispatch)
1861CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_COMMAND_COMMAND_QUEUE_KHR, CommandQueue)
1862CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_COMMAND_COMMAND_BUFFER_KHR, CommandBufferKhr)
1863CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_COMMAND_COMMAND_TYPE_KHR, cl_command_type)
1864CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_PROPERTIES_ARRAY_KHR, cl::vector<cl_ndrange_kernel_command_properties_khr>)
1865CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_KERNEL_KHR, cl_kernel)
1866CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_DIMENSIONS_KHR, cl_uint)
1867CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_GLOBAL_WORK_OFFSET_KHR, cl::vector<size_type>)
1868CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_GLOBAL_WORK_SIZE_KHR, cl::vector<size_type>)
1869CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_LOCAL_WORK_SIZE_KHR, cl::vector<size_type>)
1870#endif /* cl_khr_command_buffer_mutable_dispatch */
1871
1872#if defined(cl_khr_kernel_clock)
1873CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_CLOCK_CAPABILITIES_KHR, cl_device_kernel_clock_capabilities_khr)
1874#endif /* cl_khr_kernel_clock */
1875
1876// Convenience functions
1877
1878template <typename Func, typename T>
1879inline cl_int
1880getInfo(Func f, cl_uint name, T* param)
1881{
1882 return getInfoHelper(f, name, param, 0);
1883}
1884
1885template <typename Func, typename Arg0>
1886struct GetInfoFunctor0
1887{
1888 Func f_; const Arg0& arg0_;
1889 cl_int operator ()(
1890 cl_uint param, size_type size, void* value, size_type* size_ret)
1891 { return f_(arg0_, param, size, value, size_ret); }
1892};
1893
1894template <typename Func, typename Arg0, typename Arg1>
1895struct GetInfoFunctor1
1896{
1897 Func f_; const Arg0& arg0_; const Arg1& arg1_;
1898 cl_int operator ()(
1899 cl_uint param, size_type size, void* value, size_type* size_ret)
1900 { return f_(arg0_, arg1_, param, size, value, size_ret); }
1901};
1902
1903template <typename Func, typename Arg0, typename T>
1904inline cl_int
1905getInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
1906{
1907 GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
1908 return getInfoHelper(f0, name, param, 0);
1909}
1910
1911template <typename Func, typename Arg0, typename Arg1, typename T>
1912inline cl_int
1913getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
1914{
1915 GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
1916 return getInfoHelper(f0, name, param, 0);
1918
1919
1920template<typename T>
1921struct ReferenceHandler
1922{ };
1923
1924#if CL_HPP_TARGET_OPENCL_VERSION >= 120
1928template <>
1929struct ReferenceHandler<cl_device_id>
1930{
1940 static cl_int retain(cl_device_id device)
1941 { return ::clRetainDevice(device); }
1951 static cl_int release(cl_device_id device)
1952 { return ::clReleaseDevice(device); }
1953};
1954#else // CL_HPP_TARGET_OPENCL_VERSION >= 120
1958template <>
1959struct ReferenceHandler<cl_device_id>
1960{
1961 // cl_device_id does not have retain().
1962 static cl_int retain(cl_device_id)
1963 { return CL_SUCCESS; }
1964 // cl_device_id does not have release().
1965 static cl_int release(cl_device_id)
1966 { return CL_SUCCESS; }
1968#endif // ! (CL_HPP_TARGET_OPENCL_VERSION >= 120)
1969
1970template <>
1971struct ReferenceHandler<cl_platform_id>
1972{
1973 // cl_platform_id does not have retain().
1974 static cl_int retain(cl_platform_id)
1975 { return CL_SUCCESS; }
1976 // cl_platform_id does not have release().
1977 static cl_int release(cl_platform_id)
1978 { return CL_SUCCESS; }
1979};
1980
1981template <>
1982struct ReferenceHandler<cl_context>
1983{
1984 static cl_int retain(cl_context context)
1985 { return ::clRetainContext(context); }
1986 static cl_int release(cl_context context)
1987 { return ::clReleaseContext(context); }
1988};
1989
1990template <>
1991struct ReferenceHandler<cl_command_queue>
1992{
1993 static cl_int retain(cl_command_queue queue)
1994 { return ::clRetainCommandQueue(queue); }
1995 static cl_int release(cl_command_queue queue)
1996 { return ::clReleaseCommandQueue(queue); }
1997};
1998
1999template <>
2000struct ReferenceHandler<cl_mem>
2001{
2002 static cl_int retain(cl_mem memory)
2003 { return ::clRetainMemObject(memory); }
2004 static cl_int release(cl_mem memory)
2005 { return ::clReleaseMemObject(memory); }
2006};
2007
2008template <>
2009struct ReferenceHandler<cl_sampler>
2010{
2011 static cl_int retain(cl_sampler sampler)
2012 { return ::clRetainSampler(sampler); }
2013 static cl_int release(cl_sampler sampler)
2014 { return ::clReleaseSampler(sampler); }
2015};
2016
2017template <>
2018struct ReferenceHandler<cl_program>
2019{
2020 static cl_int retain(cl_program program)
2021 { return ::clRetainProgram(program); }
2022 static cl_int release(cl_program program)
2023 { return ::clReleaseProgram(program); }
2024};
2025
2026template <>
2027struct ReferenceHandler<cl_kernel>
2028{
2029 static cl_int retain(cl_kernel kernel)
2030 { return ::clRetainKernel(kernel); }
2031 static cl_int release(cl_kernel kernel)
2032 { return ::clReleaseKernel(kernel); }
2033};
2034
2035template <>
2036struct ReferenceHandler<cl_event>
2037{
2038 static cl_int retain(cl_event event)
2039 { return ::clRetainEvent(event); }
2040 static cl_int release(cl_event event)
2041 { return ::clReleaseEvent(event); }
2042};
2043
2044#ifdef cl_khr_semaphore
2045template <>
2046struct ReferenceHandler<cl_semaphore_khr>
2047{
2048 static cl_int retain(cl_semaphore_khr semaphore)
2049 {
2050 if (pfn_clRetainSemaphoreKHR != nullptr) {
2051 return pfn_clRetainSemaphoreKHR(semaphore);
2052 }
2053
2054 return CL_INVALID_OPERATION;
2055 }
2056
2057 static cl_int release(cl_semaphore_khr semaphore)
2058 {
2059 if (pfn_clReleaseSemaphoreKHR != nullptr) {
2060 return pfn_clReleaseSemaphoreKHR(semaphore);
2061 }
2062
2063 return CL_INVALID_OPERATION;
2064 }
2065};
2066#endif // cl_khr_semaphore
2067#if defined(cl_khr_command_buffer)
2068template <>
2069struct ReferenceHandler<cl_command_buffer_khr>
2070{
2071 static cl_int retain(cl_command_buffer_khr cmdBufferKhr)
2072 {
2073 if (pfn_clRetainCommandBufferKHR == nullptr) {
2074 return detail::errHandler(CL_INVALID_OPERATION, __RETAIN_COMMAND_BUFFER_KHR_ERR);
2075 }
2076 return pfn_clRetainCommandBufferKHR(cmdBufferKhr);
2077 }
2078
2079 static cl_int release(cl_command_buffer_khr cmdBufferKhr)
2080 {
2081 if (pfn_clReleaseCommandBufferKHR == nullptr) {
2082 return detail::errHandler(CL_INVALID_OPERATION, __RELEASE_COMMAND_BUFFER_KHR_ERR);
2083 }
2084 return pfn_clReleaseCommandBufferKHR(cmdBufferKhr);
2085 }
2086};
2087
2088template <>
2089struct ReferenceHandler<cl_mutable_command_khr>
2090{
2091 // cl_mutable_command_khr does not have retain().
2092 static cl_int retain(cl_mutable_command_khr)
2093 { return CL_SUCCESS; }
2094 // cl_mutable_command_khr does not have release().
2095 static cl_int release(cl_mutable_command_khr)
2096 { return CL_SUCCESS; }
2097};
2098#endif // cl_khr_command_buffer
2099
2100
2101#if (CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120) || \
2102 (CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200)
2103// Extracts version number with major in the upper 16 bits, minor in the lower 16
2104static cl_uint getVersion(const vector<char> &versionInfo)
2105{
2106 int highVersion = 0;
2107 int lowVersion = 0;
2108 int index = 7;
2109 while(versionInfo[index] != '.' ) {
2110 highVersion *= 10;
2111 highVersion += versionInfo[index]-'0';
2112 ++index;
2113 }
2114 ++index;
2115 while(versionInfo[index] != ' ' && versionInfo[index] != '\0') {
2116 lowVersion *= 10;
2117 lowVersion += versionInfo[index]-'0';
2118 ++index;
2119 }
2120 return (highVersion << 16) | lowVersion;
2121}
2122
2123static cl_uint getPlatformVersion(cl_platform_id platform)
2124{
2125 size_type size = 0;
2126 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, nullptr, &size);
2127
2128 vector<char> versionInfo(size);
2129 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, versionInfo.data(), &size);
2130 return getVersion(versionInfo);
2131}
2132
2133static cl_uint getDevicePlatformVersion(cl_device_id device)
2134{
2135 cl_platform_id platform;
2136 clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, nullptr);
2137 return getPlatformVersion(platform);
2138}
2139
2140static cl_uint getContextPlatformVersion(cl_context context)
2141{
2142 // The platform cannot be queried directly, so we first have to grab a
2143 // device and obtain its context
2144 size_type size = 0;
2145 clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, nullptr, &size);
2146 if (size == 0)
2147 return 0;
2148 vector<cl_device_id> devices(size/sizeof(cl_device_id));
2149 clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices.data(), nullptr);
2150 return getDevicePlatformVersion(devices[0]);
2152#endif // CL_HPP_TARGET_OPENCL_VERSION && CL_HPP_MINIMUM_OPENCL_VERSION
2153
2154template <typename T>
2155class Wrapper
2156{
2157public:
2158 typedef T cl_type;
2159
2160protected:
2161 cl_type object_;
2162
2163public:
2164 Wrapper() : object_(nullptr) { }
2165
2166 Wrapper(const cl_type &obj, bool retainObject) : object_(obj)
2167 {
2168 if (retainObject) {
2169 detail::errHandler(retain(), __RETAIN_ERR);
2170 }
2171 }
2172
2173 ~Wrapper()
2174 {
2175 if (object_ != nullptr) { release(); }
2176 }
2177
2178 Wrapper(const Wrapper<cl_type>& rhs)
2179 {
2180 object_ = rhs.object_;
2181 detail::errHandler(retain(), __RETAIN_ERR);
2182 }
2183
2184 Wrapper(Wrapper<cl_type>&& rhs) noexcept
2185 {
2186 object_ = rhs.object_;
2187 rhs.object_ = nullptr;
2188 }
2189
2190 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
2191 {
2192 if (this != &rhs) {
2193 detail::errHandler(release(), __RELEASE_ERR);
2194 object_ = rhs.object_;
2195 detail::errHandler(retain(), __RETAIN_ERR);
2196 }
2197 return *this;
2198 }
2199
2200 Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
2201 {
2202 if (this != &rhs) {
2203 detail::errHandler(release(), __RELEASE_ERR);
2204 object_ = rhs.object_;
2205 rhs.object_ = nullptr;
2206 }
2207 return *this;
2208 }
2209
2210 Wrapper<cl_type>& operator = (const cl_type &rhs)
2211 {
2212 detail::errHandler(release(), __RELEASE_ERR);
2213 object_ = rhs;
2214 return *this;
2215 }
2216
2217 const cl_type& operator ()() const { return object_; }
2218
2219 cl_type& operator ()() { return object_; }
2220
2221 cl_type get() const { return object_; }
2222
2223protected:
2224 template<typename Func, typename U>
2225 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
2226
2227 cl_int retain() const
2228 {
2229 if (object_ != nullptr) {
2230 return ReferenceHandler<cl_type>::retain(object_);
2231 }
2232 else {
2233 return CL_SUCCESS;
2234 }
2235 }
2236
2237 cl_int release() const
2238 {
2239 if (object_ != nullptr) {
2240 return ReferenceHandler<cl_type>::release(object_);
2241 }
2242 else {
2243 return CL_SUCCESS;
2244 }
2246};
2247
2248template <>
2249class Wrapper<cl_device_id>
2250{
2251public:
2252 typedef cl_device_id cl_type;
2253
2254protected:
2255 cl_type object_;
2256 bool referenceCountable_;
2257
2258 static bool isReferenceCountable(cl_device_id device)
2259 {
2260 bool retVal = false;
2261#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
2262 if (device != nullptr) {
2263 int version = getDevicePlatformVersion(device);
2264 if(version > ((1 << 16) + 1)) {
2265 retVal = true;
2266 }
2267 }
2268#elif CL_HPP_TARGET_OPENCL_VERSION >= 120
2269 retVal = true;
2270#endif // CL_HPP_TARGET_OPENCL_VERSION
2271 (void)device;
2272 return retVal;
2273 }
2274
2275public:
2276 Wrapper() : object_(nullptr), referenceCountable_(false)
2277 {
2278 }
2279
2280 Wrapper(const cl_type &obj, bool retainObject) :
2281 object_(obj),
2282 referenceCountable_(false)
2283 {
2284 referenceCountable_ = isReferenceCountable(obj);
2285
2286 if (retainObject) {
2287 detail::errHandler(retain(), __RETAIN_ERR);
2288 }
2289 }
2290
2291 ~Wrapper()
2292 {
2293 release();
2294 }
2295
2296 Wrapper(const Wrapper<cl_type>& rhs)
2297 {
2298 object_ = rhs.object_;
2299 referenceCountable_ = isReferenceCountable(object_);
2300 detail::errHandler(retain(), __RETAIN_ERR);
2301 }
2302
2303 Wrapper(Wrapper<cl_type>&& rhs) noexcept
2304 {
2305 object_ = rhs.object_;
2306 referenceCountable_ = rhs.referenceCountable_;
2307 rhs.object_ = nullptr;
2308 rhs.referenceCountable_ = false;
2309 }
2310
2311 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
2312 {
2313 if (this != &rhs) {
2314 detail::errHandler(release(), __RELEASE_ERR);
2315 object_ = rhs.object_;
2316 referenceCountable_ = rhs.referenceCountable_;
2317 detail::errHandler(retain(), __RETAIN_ERR);
2318 }
2319 return *this;
2320 }
2321
2322 Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
2323 {
2324 if (this != &rhs) {
2325 detail::errHandler(release(), __RELEASE_ERR);
2326 object_ = rhs.object_;
2327 referenceCountable_ = rhs.referenceCountable_;
2328 rhs.object_ = nullptr;
2329 rhs.referenceCountable_ = false;
2330 }
2331 return *this;
2332 }
2333
2334 Wrapper<cl_type>& operator = (const cl_type &rhs)
2335 {
2336 detail::errHandler(release(), __RELEASE_ERR);
2337 object_ = rhs;
2338 referenceCountable_ = isReferenceCountable(object_);
2339 return *this;
2340 }
2341
2342 const cl_type& operator ()() const { return object_; }
2343
2344 cl_type& operator ()() { return object_; }
2345
2346 cl_type get() const { return object_; }
2347
2348protected:
2349 template<typename Func, typename U>
2350 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
2351
2352 template<typename Func, typename U>
2353 friend inline cl_int getInfoHelper(Func, cl_uint, vector<U>*, int, typename U::cl_type);
2354
2355 cl_int retain() const
2356 {
2357 if( object_ != nullptr && referenceCountable_ ) {
2358 return ReferenceHandler<cl_type>::retain(object_);
2359 }
2360 else {
2361 return CL_SUCCESS;
2362 }
2363 }
2364
2365 cl_int release() const
2366 {
2367 if (object_ != nullptr && referenceCountable_) {
2368 return ReferenceHandler<cl_type>::release(object_);
2369 }
2370 else {
2371 return CL_SUCCESS;
2372 }
2373 }
2374};
2375
2376template <typename T>
2377inline bool operator==(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
2378{
2379 return lhs() == rhs();
2380}
2381
2382template <typename T>
2383inline bool operator!=(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
2384{
2385 return !operator==(lhs, rhs);
2386}
2387
2388} // namespace detail
2390
2391
2392
2393
2394
2400struct ImageFormat : public cl_image_format
2401{
2403 ImageFormat(){}
2404
2406 ImageFormat(cl_channel_order order, cl_channel_type type)
2407 {
2408 image_channel_order = order;
2409 image_channel_data_type = type;
2410 }
2411
2413 ImageFormat(const ImageFormat &other) { *this = other; }
2414
2417 {
2418 if (this != &rhs) {
2419 this->image_channel_data_type = rhs.image_channel_data_type;
2420 this->image_channel_order = rhs.image_channel_order;
2421 }
2422 return *this;
2423 }
2424};
2425
2433class Device : public detail::Wrapper<cl_device_id>
2434{
2435private:
2436 static std::once_flag default_initialized_;
2437 static Device default_;
2438 static cl_int default_error_;
2439
2445 static void makeDefault();
2446
2452 static void makeDefaultProvided(const Device &p) {
2453 default_ = p;
2454 }
2455
2456public:
2457#ifdef CL_HPP_UNIT_TEST_ENABLE
2464 static void unitTestClearDefault() {
2465 default_ = Device();
2467#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2468
2470 Device() : detail::Wrapper<cl_type>() { }
2471
2476 explicit Device(const cl_device_id &device, bool retainObject = false) :
2477 detail::Wrapper<cl_type>(device, retainObject) { }
2478
2483 static Device getDefault(
2484 cl_int *errResult = nullptr)
2485 {
2486 std::call_once(default_initialized_, makeDefault);
2487 detail::errHandler(default_error_);
2488 if (errResult != nullptr) {
2489 *errResult = default_error_;
2490 }
2491 return default_;
2492 }
2493
2501 static Device setDefault(const Device &default_device)
2502 {
2503 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_device));
2504 detail::errHandler(default_error_);
2505 return default_;
2506 }
2507
2512 Device& operator = (const cl_device_id& rhs)
2513 {
2514 detail::Wrapper<cl_type>::operator=(rhs);
2515 return *this;
2516 }
2518
2520 template <typename T>
2521 cl_int getInfo(cl_device_info name, T* param) const
2522 {
2523 return detail::errHandler(
2524 detail::getInfo(&::clGetDeviceInfo, object_, name, param),
2525 __GET_DEVICE_INFO_ERR);
2526 }
2529 template <cl_device_info name> typename
2531 getInfo(cl_int* err = nullptr) const
2532 {
2533 typename detail::param_traits<
2534 detail::cl_device_info, name>::param_type param;
2535 cl_int result = getInfo(name, &param);
2536 if (err != nullptr) {
2537 *err = result;
2538 }
2539 return param;
2540 }
2541
2542#if CL_HPP_TARGET_OPENCL_VERSION >= 210
2549 cl_ulong getHostTimer(cl_int *error = nullptr)
2550 {
2551 cl_ulong retVal = 0;
2552 cl_int err =
2553 clGetHostTimer(this->get(), &retVal);
2554 detail::errHandler(
2555 err,
2556 __GET_HOST_TIMER_ERR);
2557 if (error) {
2558 *error = err;
2559 }
2560 return retVal;
2561 }
2562
2573 std::pair<cl_ulong, cl_ulong> getDeviceAndHostTimer(cl_int *error = nullptr)
2574 {
2575 std::pair<cl_ulong, cl_ulong> retVal;
2576 cl_int err =
2577 clGetDeviceAndHostTimer(this->get(), &(retVal.first), &(retVal.second));
2578 detail::errHandler(
2579 err,
2580 __GET_DEVICE_AND_HOST_TIMER_ERR);
2581 if (error) {
2582 *error = err;
2583 }
2584 return retVal;
2585 }
2586#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2587
2588#if CL_HPP_TARGET_OPENCL_VERSION >= 120
2590 cl_int createSubDevices(const cl_device_partition_property* properties,
2591 vector<Device>* devices);
2592#endif // defined (CL_HPP_TARGET_OPENCL_VERSION >= 120)
2593
2594#if defined(cl_ext_device_fission)
2596 cl_int createSubDevices(const cl_device_partition_property_ext* properties,
2597 vector<Device>* devices);
2598#endif // defined(cl_ext_device_fission)
2599};
2600
2601using BuildLogType = vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, CL_PROGRAM_BUILD_LOG>::param_type>>;
2602#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2606class BuildError : public Error
2607{
2608private:
2609 BuildLogType buildLogs;
2610public:
2611 BuildError(cl_int err, const char * errStr, const BuildLogType &vec) : Error(err, errStr), buildLogs(vec)
2612 {
2613 }
2614
2615 BuildLogType getBuildLog() const
2616 {
2617 return buildLogs;
2618 }
2619};
2620namespace detail {
2621 static inline cl_int buildErrHandler(
2622 cl_int err,
2623 const char * errStr,
2624 const BuildLogType &buildLogs)
2625 {
2626 if (err != CL_SUCCESS) {
2627 throw BuildError(err, errStr, buildLogs);
2628 }
2629 return err;
2630 }
2631} // namespace detail
2632
2633#else
2634namespace detail {
2635 static inline cl_int buildErrHandler(
2636 cl_int err,
2637 const char * errStr,
2638 const BuildLogType &buildLogs)
2639 {
2640 (void)buildLogs; // suppress unused variable warning
2641 (void)errStr;
2642 return err;
2643 }
2644} // namespace detail
2645#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2646
2647CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Device::default_initialized_;
2648CL_HPP_DEFINE_STATIC_MEMBER_ Device Device::default_;
2649CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Device::default_error_ = CL_SUCCESS;
2650
2658class Platform : public detail::Wrapper<cl_platform_id>
2659{
2660private:
2661 static std::once_flag default_initialized_;
2662 static Platform default_;
2663 static cl_int default_error_;
2664
2670 static void makeDefault() {
2671 /* Throwing an exception from a call_once invocation does not do
2672 * what we wish, so we catch it and save the error.
2673 */
2674#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2675 try
2676#endif
2677 {
2678 // If default wasn't passed ,generate one
2679 // Otherwise set it
2680 cl_uint n = 0;
2681
2682 cl_int err = ::clGetPlatformIDs(0, nullptr, &n);
2683 if (err != CL_SUCCESS) {
2684 default_error_ = err;
2685 return;
2686 }
2687 if (n == 0) {
2688 default_error_ = CL_INVALID_PLATFORM;
2689 return;
2690 }
2691
2692 vector<cl_platform_id> ids(n);
2693 err = ::clGetPlatformIDs(n, ids.data(), nullptr);
2694 if (err != CL_SUCCESS) {
2695 default_error_ = err;
2696 return;
2697 }
2698
2699 default_ = Platform(ids[0]);
2700 }
2701#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2702 catch (cl::Error &e) {
2703 default_error_ = e.err();
2704 }
2705#endif
2706 }
2707
2713 static void makeDefaultProvided(const Platform &p) {
2714 default_ = p;
2715 }
2716
2717public:
2718#ifdef CL_HPP_UNIT_TEST_ENABLE
2725 static void unitTestClearDefault() {
2726 default_ = Platform();
2728#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2729
2731 Platform() : detail::Wrapper<cl_type>() { }
2732
2740 explicit Platform(const cl_platform_id &platform, bool retainObject = false) :
2741 detail::Wrapper<cl_type>(platform, retainObject) { }
2742
2747 Platform& operator = (const cl_platform_id& rhs)
2748 {
2749 detail::Wrapper<cl_type>::operator=(rhs);
2750 return *this;
2751 }
2752
2753 static Platform getDefault(
2754 cl_int *errResult = nullptr)
2755 {
2756 std::call_once(default_initialized_, makeDefault);
2757 detail::errHandler(default_error_);
2758 if (errResult != nullptr) {
2759 *errResult = default_error_;
2760 }
2761 return default_;
2762 }
2763
2771 static Platform setDefault(const Platform &default_platform)
2772 {
2773 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_platform));
2774 detail::errHandler(default_error_);
2775 return default_;
2777
2779 template <typename T>
2780 cl_int getInfo(cl_platform_info name, T* param) const
2781 {
2782 return detail::errHandler(
2783 detail::getInfo(&::clGetPlatformInfo, object_, name, param),
2784 __GET_PLATFORM_INFO_ERR);
2785 }
2788 template <cl_platform_info name> typename
2790 getInfo(cl_int* err = nullptr) const
2791 {
2792 typename detail::param_traits<
2793 detail::cl_platform_info, name>::param_type param;
2794 cl_int result = getInfo(name, &param);
2795 if (err != nullptr) {
2796 *err = result;
2797 }
2798 return param;
2799 }
2800
2805 cl_int getDevices(
2806 cl_device_type type,
2807 vector<Device>* devices) const
2808 {
2809 cl_uint n = 0;
2810 if( devices == nullptr ) {
2811 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2812 }
2813 cl_int err = ::clGetDeviceIDs(object_, type, 0, nullptr, &n);
2814 if (err != CL_SUCCESS && err != CL_DEVICE_NOT_FOUND) {
2815 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2816 }
2817
2818 vector<cl_device_id> ids(n);
2819 if (n>0) {
2820 err = ::clGetDeviceIDs(object_, type, n, ids.data(), nullptr);
2821 if (err != CL_SUCCESS) {
2822 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2823 }
2824 }
2825
2826 // Cannot trivially assign because we need to capture intermediates
2827 // with safe construction
2828 // We must retain things we obtain from the API to avoid releasing
2829 // API-owned objects.
2830 if (devices) {
2831 devices->resize(ids.size());
2832
2833 // Assign to param, constructing with retain behaviour
2834 // to correctly capture each underlying CL object
2835 for (size_type i = 0; i < ids.size(); i++) {
2836 (*devices)[i] = Device(ids[i], true);
2837 }
2838 }
2839 return CL_SUCCESS;
2840 }
2841
2842#if defined(CL_HPP_USE_DX_INTEROP)
2866 cl_int getDevices(
2867 cl_d3d10_device_source_khr d3d_device_source,
2868 void * d3d_object,
2869 cl_d3d10_device_set_khr d3d_device_set,
2870 vector<Device>* devices) const
2871 {
2872 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
2873 cl_platform_id platform,
2874 cl_d3d10_device_source_khr d3d_device_source,
2875 void * d3d_object,
2876 cl_d3d10_device_set_khr d3d_device_set,
2877 cl_uint num_entries,
2878 cl_device_id * devices,
2879 cl_uint* num_devices);
2880
2881 if( devices == nullptr ) {
2882 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2883 }
2884
2885 static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = nullptr;
2886#if CL_HPP_TARGET_OPENCL_VERSION >= 120
2887 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(object_, clGetDeviceIDsFromD3D10KHR);
2888#endif
2889#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
2890 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetDeviceIDsFromD3D10KHR);
2891#endif
2892
2893 cl_uint n = 0;
2894 cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
2895 object_,
2896 d3d_device_source,
2897 d3d_object,
2898 d3d_device_set,
2899 0,
2900 nullptr,
2901 &n);
2902 if (err != CL_SUCCESS) {
2903 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2904 }
2905
2906 vector<cl_device_id> ids(n);
2907 err = pfn_clGetDeviceIDsFromD3D10KHR(
2908 object_,
2909 d3d_device_source,
2910 d3d_object,
2911 d3d_device_set,
2912 n,
2913 ids.data(),
2914 nullptr);
2915 if (err != CL_SUCCESS) {
2916 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2917 }
2918
2919 // Cannot trivially assign because we need to capture intermediates
2920 // with safe construction
2921 // We must retain things we obtain from the API to avoid releasing
2922 // API-owned objects.
2923 if (devices) {
2924 devices->resize(ids.size());
2925
2926 // Assign to param, constructing with retain behaviour
2927 // to correctly capture each underlying CL object
2928 for (size_type i = 0; i < ids.size(); i++) {
2929 (*devices)[i] = Device(ids[i], true);
2930 }
2931 }
2932 return CL_SUCCESS;
2933 }
2934#endif
2935
2940 static cl_int get(
2941 vector<Platform>* platforms)
2942 {
2943 cl_uint n = 0;
2944
2945 if( platforms == nullptr ) {
2946 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
2947 }
2948
2949 cl_int err = ::clGetPlatformIDs(0, nullptr, &n);
2950 if (err != CL_SUCCESS) {
2951 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2952 }
2953
2954 vector<cl_platform_id> ids(n);
2955 err = ::clGetPlatformIDs(n, ids.data(), nullptr);
2956 if (err != CL_SUCCESS) {
2957 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2958 }
2959
2960 if (platforms) {
2961 platforms->resize(ids.size());
2962
2963 // Platforms don't reference count
2964 for (size_type i = 0; i < ids.size(); i++) {
2965 (*platforms)[i] = Platform(ids[i]);
2966 }
2967 }
2968 return CL_SUCCESS;
2969 }
2970
2975 static cl_int get(
2976 Platform * platform)
2977 {
2978 cl_int err;
2979 Platform default_platform = Platform::getDefault(&err);
2980 if (platform) {
2981 *platform = default_platform;
2982 }
2983 return err;
2984 }
2985
2994 static Platform get(
2995 cl_int * errResult = nullptr)
2996 {
2997 cl_int err;
2998 Platform default_platform = Platform::getDefault(&err);
2999 if (errResult) {
3000 *errResult = err;
3001 }
3002 return default_platform;
3003 }
3005#if CL_HPP_TARGET_OPENCL_VERSION >= 120
3007 cl_int
3009 {
3010 return ::clUnloadPlatformCompiler(object_);
3011 }
3012#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
3013}; // class Platform
3014
3015#if CL_HPP_TARGET_OPENCL_VERSION >= 120
3017inline cl_int Device::createSubDevices(const cl_device_partition_property* properties,
3018 vector<Device>* devices)
3019{
3020 cl_uint n = 0;
3021 cl_int err = clCreateSubDevices(object_, properties, 0, nullptr, &n);
3022 if (err != CL_SUCCESS)
3023 {
3024 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
3025 }
3026
3027 vector<cl_device_id> ids(n);
3028 err = clCreateSubDevices(object_, properties, n, ids.data(), nullptr);
3029 if (err != CL_SUCCESS)
3030 {
3031 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
3032 }
3033
3034 // Cannot trivially assign because we need to capture intermediates
3035 // with safe construction
3036 if (devices)
3037 {
3038 devices->resize(ids.size());
3039
3040 // Assign to param, constructing with retain behaviour
3041 // to correctly capture each underlying CL object
3042 for (size_type i = 0; i < ids.size(); i++)
3043 {
3044 // We do not need to retain because this device is being created
3045 // by the runtime
3046 (*devices)[i] = Device(ids[i], false);
3047 }
3048 }
3049
3050 return CL_SUCCESS;
3051}
3052#endif // defined (CL_HPP_TARGET_OPENCL_VERSION >= 120)
3053
3054#if defined(cl_ext_device_fission)
3056inline cl_int Device::createSubDevices(const cl_device_partition_property_ext* properties,
3057 vector<Device>* devices)
3058{
3059#if CL_HPP_TARGET_OPENCL_VERSION >= 120
3060 cl::Device device(object_);
3061 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>()();
3062 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateSubDevicesEXT);
3063#endif
3064#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
3065 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSubDevicesEXT);
3066#endif
3067
3068 cl_uint n = 0;
3069 cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, nullptr, &n);
3070 if (err != CL_SUCCESS)
3071 {
3072 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
3073 }
3074
3075 vector<cl_device_id> ids(n);
3076 err =
3077 pfn_clCreateSubDevicesEXT(object_, properties, n, ids.data(), nullptr);
3078 if (err != CL_SUCCESS)
3079 {
3080 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
3081 }
3082 // Cannot trivially assign because we need to capture intermediates
3083 // with safe construction
3084 if (devices)
3085 {
3086 devices->resize(ids.size());
3087
3088 // Assign to param, constructing with retain behaviour
3089 // to correctly capture each underlying CL object
3090 for (size_type i = 0; i < ids.size(); i++)
3091 {
3092 // We do not need to retain because this device is being created
3093 // by the runtime
3094 (*devices)[i] = Device(ids[i], false);
3095 }
3096 }
3097
3098 return CL_SUCCESS;
3099}
3100#endif // defined(cl_ext_device_fission)
3101
3102CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Platform::default_initialized_;
3103CL_HPP_DEFINE_STATIC_MEMBER_ Platform Platform::default_;
3104CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Platform::default_error_ = CL_SUCCESS;
3105
3106
3110#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
3115inline CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int
3116UnloadCompiler() CL_API_SUFFIX__VERSION_1_1_DEPRECATED;
3117inline cl_int
3119{
3120 return ::clUnloadCompiler();
3121}
3122#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
3123
3124
3125#if defined(cl_ext_image_requirements_info)
3126enum ImageRequirementsInfoExt : cl_image_requirements_info_ext
3127{
3128 RowPitchAlign = CL_IMAGE_REQUIREMENTS_ROW_PITCH_ALIGNMENT_EXT,
3129 BaseAddAlign = CL_IMAGE_REQUIREMENTS_BASE_ADDRESS_ALIGNMENT_EXT,
3130 Size = CL_IMAGE_REQUIREMENTS_SIZE_EXT,
3131 MaxWidth = CL_IMAGE_REQUIREMENTS_MAX_WIDTH_EXT,
3132 MaxHeight = CL_IMAGE_REQUIREMENTS_MAX_HEIGHT_EXT,
3133 MaxDepth = CL_IMAGE_REQUIREMENTS_MAX_DEPTH_EXT,
3134 MaxArraySize = CL_IMAGE_REQUIREMENTS_MAX_ARRAY_SIZE_EXT,
3135#if defined(cl_ext_image_from_buffer)
3136 SlicePitchAlign = CL_IMAGE_REQUIREMENTS_SLICE_PITCH_ALIGNMENT_EXT,
3137#endif
3138};
3139
3140#endif // cl_ext_image_requirements_info
3141
3142
3151class Context
3152 : public detail::Wrapper<cl_context>
3153{
3154private:
3155 static std::once_flag default_initialized_;
3156 static Context default_;
3157 static cl_int default_error_;
3158
3164 static void makeDefault() {
3165 /* Throwing an exception from a call_once invocation does not do
3166 * what we wish, so we catch it and save the error.
3167 */
3168#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3169 try
3170#endif
3171 {
3172#if !defined(__APPLE__) && !defined(__MACOS)
3173 const Platform &p = Platform::getDefault();
3174 cl_platform_id defaultPlatform = p();
3175 cl_context_properties properties[3] = {
3176 CL_CONTEXT_PLATFORM, (cl_context_properties)defaultPlatform, 0
3177 };
3178#else // #if !defined(__APPLE__) && !defined(__MACOS)
3179 cl_context_properties *properties = nullptr;
3180#endif // #if !defined(__APPLE__) && !defined(__MACOS)
3181
3182 default_ = Context(
3183 CL_DEVICE_TYPE_DEFAULT,
3184 properties,
3185 nullptr,
3186 nullptr,
3187 &default_error_);
3188 }
3189#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3190 catch (cl::Error &e) {
3191 default_error_ = e.err();
3192 }
3193#endif
3194 }
3195
3196
3202 static void makeDefaultProvided(const Context &c) {
3203 default_ = c;
3204 }
3205
3206#if defined(cl_ext_image_requirements_info)
3207 struct ImageRequirementsInfo {
3208
3209 ImageRequirementsInfo(cl_mem_flags f, const cl_mem_properties* mem_properties, const ImageFormat* format, const cl_image_desc* desc)
3210 {
3211 flags = f;
3212 properties = mem_properties;
3213 image_format = format;
3214 image_desc = desc;
3215 }
3216
3217 cl_mem_flags flags = 0;
3218 const cl_mem_properties* properties;
3219 const ImageFormat* image_format;
3220 const cl_image_desc* image_desc;
3221 };
3222
3223 static cl_int getImageRequirementsInfoExtHelper(const Context &context,
3224 const ImageRequirementsInfo &info,
3225 cl_image_requirements_info_ext param_name,
3226 size_type param_value_size,
3227 void* param_value,
3228 size_type* param_value_size_ret)
3229 {
3230
3231#if CL_HPP_TARGET_OPENCL_VERSION >= 120
3232 Device device = context.getInfo<CL_CONTEXT_DEVICES>().at(0);
3233 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>()();
3234 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clGetImageRequirementsInfoEXT);
3235#else
3236 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetImageRequirementsInfoEXT);
3237#endif
3238
3239 if (pfn_clGetImageRequirementsInfoEXT == nullptr) {
3240 return detail::errHandler(CL_INVALID_OPERATION, __GET_IMAGE_REQUIREMENT_INFO_EXT_ERR);
3241 }
3242
3243 return detail::errHandler(
3244 pfn_clGetImageRequirementsInfoEXT(context(), info.properties,
3245 info.flags, info.image_format, info.image_desc, param_name,
3246 param_value_size, param_value, param_value_size_ret),
3247 __GET_IMAGE_REQUIREMENT_INFO_EXT_ERR);
3248 }
3249#endif // cl_ext_image_requirements_info
3250
3251public:
3252#ifdef CL_HPP_UNIT_TEST_ENABLE
3259 static void unitTestClearDefault() {
3260 default_ = Context();
3261 }
3262#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
3263
3268 Context(
3269 const vector<Device>& devices,
3270 const cl_context_properties* properties = nullptr,
3271 void (CL_CALLBACK * notifyFptr)(
3272 const char *,
3273 const void *,
3274 size_type,
3275 void *) = nullptr,
3276 void* data = nullptr,
3277 cl_int* err = nullptr)
3278 {
3279 cl_int error;
3280
3281 size_type numDevices = devices.size();
3282 vector<cl_device_id> deviceIDs(numDevices);
3283
3284 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
3285 deviceIDs[deviceIndex] = (devices[deviceIndex])();
3286 }
3287
3288 object_ = ::clCreateContext(
3289 properties, (cl_uint) numDevices,
3290 deviceIDs.data(),
3291 notifyFptr, data, &error);
3292
3293 detail::errHandler(error, __CREATE_CONTEXT_ERR);
3294 if (err != nullptr) {
3295 *err = error;
3296 }
3297 }
3298
3303 Context(
3304 const Device& device,
3305 const cl_context_properties* properties = nullptr,
3306 void (CL_CALLBACK * notifyFptr)(
3307 const char *,
3308 const void *,
3309 size_type,
3310 void *) = nullptr,
3311 void* data = nullptr,
3312 cl_int* err = nullptr)
3313 {
3314 cl_int error;
3315
3316 cl_device_id deviceID = device();
3317
3318 object_ = ::clCreateContext(
3319 properties, 1,
3320 &deviceID,
3321 notifyFptr, data, &error);
3322
3323 detail::errHandler(error, __CREATE_CONTEXT_ERR);
3324 if (err != nullptr) {
3325 *err = error;
3326 }
3327 }
3328
3333 Context(
3334 cl_device_type type,
3335 const cl_context_properties* properties = nullptr,
3336 void (CL_CALLBACK * notifyFptr)(
3337 const char *,
3338 const void *,
3339 size_type,
3340 void *) = nullptr,
3341 void* data = nullptr,
3342 cl_int* err = nullptr)
3343 {
3344 cl_int error;
3345
3346#if !defined(__APPLE__) && !defined(__MACOS)
3347 cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 };
3348
3349 if (properties == nullptr) {
3350 // Get a valid platform ID as we cannot send in a blank one
3351 vector<Platform> platforms;
3352 error = Platform::get(&platforms);
3353 if (error != CL_SUCCESS) {
3354 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
3355 if (err != nullptr) {
3356 *err = error;
3357 }
3358 return;
3359 }
3360
3361 // Check the platforms we found for a device of our specified type
3362 cl_context_properties platform_id = 0;
3363 for (unsigned int i = 0; i < platforms.size(); i++) {
3364
3365 vector<Device> devices;
3366
3367#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3368 try {
3369#endif
3370
3371 error = platforms[i].getDevices(type, &devices);
3372
3373#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3374 } catch (cl::Error& e) {
3375 error = e.err();
3376 }
3377 // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type
3378 // We do error checking next anyway, and can throw there if needed
3379#endif
3380
3381 // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND
3382 if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) {
3383 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
3384 if (err != nullptr) {
3385 *err = error;
3386 }
3387 }
3388
3389 if (devices.size() > 0) {
3390 platform_id = (cl_context_properties)platforms[i]();
3391 break;
3392 }
3393 }
3394
3395 if (platform_id == 0) {
3396 detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR);
3397 if (err != nullptr) {
3398 *err = CL_DEVICE_NOT_FOUND;
3399 }
3400 return;
3401 }
3402
3403 prop[1] = platform_id;
3404 properties = &prop[0];
3405 }
3406#endif
3407 object_ = ::clCreateContextFromType(
3408 properties, type, notifyFptr, data, &error);
3409
3410 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
3411 if (err != nullptr) {
3412 *err = error;
3413 }
3414 }
3415
3416
3421 static Context getDefault(cl_int * err = nullptr)
3422 {
3423 std::call_once(default_initialized_, makeDefault);
3424 detail::errHandler(default_error_);
3425 if (err != nullptr) {
3426 *err = default_error_;
3427 }
3428 return default_;
3429 }
3430
3438 static Context setDefault(const Context &default_context)
3439 {
3440 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_context));
3441 detail::errHandler(default_error_);
3442 return default_;
3443 }
3444
3446 Context() : detail::Wrapper<cl_type>() { }
3447
3453 explicit Context(const cl_context& context, bool retainObject = false) :
3454 detail::Wrapper<cl_type>(context, retainObject) { }
3455
3461 Context& operator = (const cl_context& rhs)
3462 {
3463 detail::Wrapper<cl_type>::operator=(rhs);
3464 return *this;
3466
3468 template <typename T>
3469 cl_int getInfo(cl_context_info name, T* param) const
3470 {
3471 return detail::errHandler(
3472 detail::getInfo(&::clGetContextInfo, object_, name, param),
3473 __GET_CONTEXT_INFO_ERR);
3474 }
3477 template <cl_context_info name> typename
3479 getInfo(cl_int* err = nullptr) const
3480 {
3481 typename detail::param_traits<
3482 detail::cl_context_info, name>::param_type param;
3483 cl_int result = getInfo(name, &param);
3484 if (err != nullptr) {
3485 *err = result;
3486 }
3487 return param;
3488 }
3489
3495 cl_mem_flags flags,
3496 cl_mem_object_type type,
3497 vector<ImageFormat>* formats) const
3498 {
3499 cl_uint numEntries;
3500
3501 if (!formats) {
3502 return CL_SUCCESS;
3503 }
3504
3505 cl_int err = ::clGetSupportedImageFormats(
3506 object_,
3507 flags,
3508 type,
3509 0,
3510 nullptr,
3511 &numEntries);
3512 if (err != CL_SUCCESS) {
3513 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3514 }
3515
3516 if (numEntries > 0) {
3517 vector<ImageFormat> value(numEntries);
3518 err = ::clGetSupportedImageFormats(
3519 object_,
3520 flags,
3521 type,
3522 numEntries,
3523 (cl_image_format*)value.data(),
3524 nullptr);
3525 if (err != CL_SUCCESS) {
3526 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3527 }
3528
3529 formats->assign(value.begin(), value.end());
3530 }
3531 else {
3532 // If no values are being returned, ensure an empty vector comes back
3533 formats->clear();
3534 }
3535
3536 return CL_SUCCESS;
3537 }
3538
3539#if defined(cl_ext_image_requirements_info)
3540 template <typename T>
3541 cl_int getImageRequirementsInfoExt(cl_image_requirements_info_ext name,
3542 T* param,
3543 cl_mem_flags flags = 0,
3544 const cl_mem_properties* properties = nullptr,
3545 const ImageFormat* image_format = nullptr,
3546 const cl_image_desc* image_desc = nullptr) const
3547 {
3548 ImageRequirementsInfo imageInfo = {flags, properties, image_format, image_desc};
3549
3550 return detail::errHandler(
3551 detail::getInfo(
3552 Context::getImageRequirementsInfoExtHelper, *this, imageInfo, name, param),
3553 __GET_IMAGE_REQUIREMENT_INFO_EXT_ERR);
3554 }
3555
3556 template <cl_image_requirements_info_ext type> typename
3557 detail::param_traits<detail::cl_image_requirements_info_ext, type>::param_type
3558 getImageRequirementsInfoExt(cl_mem_flags flags = 0,
3559 const cl_mem_properties* properties = nullptr,
3560 const ImageFormat* image_format = nullptr,
3561 const cl_image_desc* image_desc = nullptr,
3562 cl_int* err = nullptr) const
3563 {
3564 typename detail::param_traits<
3565 detail::cl_image_requirements_info_ext, type>::param_type param;
3566 cl_int result = getImageRequirementsInfoExt(type, &param, flags, properties, image_format, image_desc);
3567 if (err != nullptr) {
3568 *err = result;
3569 }
3570 return param;
3571 }
3572#endif // cl_ext_image_requirements_info
3573
3574#if CL_HPP_TARGET_OPENCL_VERSION >= 300
3585 cl_int setDestructorCallback(
3586 void (CL_CALLBACK * pfn_notify)(cl_context, void *),
3587 void * user_data = nullptr)
3588 {
3589 return detail::errHandler(
3590 ::clSetContextDestructorCallback(
3591 object_,
3592 pfn_notify,
3593 user_data),
3594 __SET_CONTEXT_DESCTRUCTOR_CALLBACK_ERR);
3595 }
3596#endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
3597};
3598
3599inline void Device::makeDefault()
3600{
3601 /* Throwing an exception from a call_once invocation does not do
3602 * what we wish, so we catch it and save the error.
3603 */
3604#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3605 try
3606#endif
3607 {
3608 cl_int error = 0;
3609
3610 Context context = Context::getDefault(&error);
3611 detail::errHandler(error, __CREATE_CONTEXT_ERR);
3612
3613 if (error != CL_SUCCESS) {
3614 default_error_ = error;
3615 }
3616 else {
3617 default_ = context.getInfo<CL_CONTEXT_DEVICES>()[0];
3618 default_error_ = CL_SUCCESS;
3619 }
3620 }
3621#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3622 catch (cl::Error &e) {
3623 default_error_ = e.err();
3624 }
3625#endif
3626}
3627
3628CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Context::default_initialized_;
3629CL_HPP_DEFINE_STATIC_MEMBER_ Context Context::default_;
3630CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Context::default_error_ = CL_SUCCESS;
3631
3640class Event : public detail::Wrapper<cl_event>
3641{
3642public:
3645
3654 explicit Event(const cl_event& event, bool retainObject = false) :
3655 detail::Wrapper<cl_type>(event, retainObject) { }
3656
3662 Event& operator = (const cl_event& rhs)
3663 {
3665 return *this;
3667
3669 template <typename T>
3670 cl_int getInfo(cl_event_info name, T* param) const
3671 {
3672 return detail::errHandler(
3673 detail::getInfo(&::clGetEventInfo, object_, name, param),
3674 __GET_EVENT_INFO_ERR);
3675 }
3678 template <cl_event_info name> typename
3680 getInfo(cl_int* err = nullptr) const
3681 {
3682 typename detail::param_traits<
3683 detail::cl_event_info, name>::param_type param;
3684 cl_int result = getInfo(name, &param);
3685 if (err != nullptr) {
3686 *err = result;
3687 }
3688 return param;
3690
3692 template <typename T>
3693 cl_int getProfilingInfo(cl_profiling_info name, T* param) const
3694 {
3695 return detail::errHandler(detail::getInfo(
3696 &::clGetEventProfilingInfo, object_, name, param),
3697 __GET_EVENT_PROFILE_INFO_ERR);
3698 }
3701 template <cl_profiling_info name> typename
3703 getProfilingInfo(cl_int* err = nullptr) const
3704 {
3705 typename detail::param_traits<
3706 detail::cl_profiling_info, name>::param_type param;
3707 cl_int result = getProfilingInfo(name, &param);
3708 if (err != nullptr) {
3709 *err = result;
3710 }
3711 return param;
3712 }
3713
3718 cl_int wait() const
3719 {
3720 return detail::errHandler(
3721 ::clWaitForEvents(1, &object_),
3722 __WAIT_FOR_EVENTS_ERR);
3723 }
3724
3725#if CL_HPP_TARGET_OPENCL_VERSION >= 110
3730 cl_int setCallback(
3731 cl_int type,
3732 void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
3733 void * user_data = nullptr)
3734 {
3735 return detail::errHandler(
3736 ::clSetEventCallback(
3737 object_,
3738 type,
3739 pfn_notify,
3740 user_data),
3741 __SET_EVENT_CALLBACK_ERR);
3742 }
3743#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3744
3749 static cl_int
3750 waitForEvents(const vector<Event>& events)
3751 {
3752 static_assert(sizeof(cl::Event) == sizeof(cl_event),
3753 "Size of cl::Event must be equal to size of cl_event");
3754
3755 return detail::errHandler(
3756 ::clWaitForEvents(
3757 (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : nullptr),
3758 __WAIT_FOR_EVENTS_ERR);
3759 }
3760};
3761
3762#if CL_HPP_TARGET_OPENCL_VERSION >= 110
3767class UserEvent : public Event
3768{
3769public:
3774 UserEvent(
3775 const Context& context,
3776 cl_int * err = nullptr)
3777 {
3778 cl_int error;
3779 object_ = ::clCreateUserEvent(
3780 context(),
3781 &error);
3782
3783 detail::errHandler(error, __CREATE_USER_EVENT_ERR);
3784 if (err != nullptr) {
3785 *err = error;
3787 }
3788
3790 UserEvent() : Event() { }
3791
3796 cl_int setStatus(cl_int status)
3797 {
3798 return detail::errHandler(
3799 ::clSetUserEventStatus(object_,status),
3800 __SET_USER_EVENT_STATUS_ERR);
3801 }
3802};
3803#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3804
3809inline static cl_int
3810WaitForEvents(const vector<Event>& events)
3811{
3812 return detail::errHandler(
3813 ::clWaitForEvents(
3814 (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : nullptr),
3815 __WAIT_FOR_EVENTS_ERR);
3816}
3817
3826class Memory : public detail::Wrapper<cl_mem>
3827{
3828public:
3831
3843 explicit Memory(const cl_mem& memory, bool retainObject) :
3844 detail::Wrapper<cl_type>(memory, retainObject) { }
3845
3851 Memory& operator = (const cl_mem& rhs)
3852 {
3854 return *this;
3856
3858 template <typename T>
3859 cl_int getInfo(cl_mem_info name, T* param) const
3860 {
3861 return detail::errHandler(
3862 detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
3863 __GET_MEM_OBJECT_INFO_ERR);
3864 }
3867 template <cl_mem_info name> typename
3869 getInfo(cl_int* err = nullptr) const
3870 {
3871 typename detail::param_traits<
3872 detail::cl_mem_info, name>::param_type param;
3873 cl_int result = getInfo(name, &param);
3874 if (err != nullptr) {
3875 *err = result;
3876 }
3877 return param;
3878 }
3879
3880#if CL_HPP_TARGET_OPENCL_VERSION >= 110
3894 cl_int setDestructorCallback(
3895 void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
3896 void * user_data = nullptr)
3897 {
3898 return detail::errHandler(
3899 ::clSetMemObjectDestructorCallback(
3900 object_,
3901 pfn_notify,
3902 user_data),
3903 __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
3904 }
3905#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3906
3907};
3908
3909// Pre-declare copy functions
3910class Buffer;
3911template< typename IteratorType >
3912cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3913template< typename IteratorType >
3914cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3915template< typename IteratorType >
3916cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3917template< typename IteratorType >
3918cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3919
3921#if CL_HPP_TARGET_OPENCL_VERSION >= 200
3922namespace detail
3923{
3924 class SVMTraitNull
3925 {
3926 public:
3927 static cl_svm_mem_flags getSVMMemFlags()
3928 {
3929 return 0;
3930 }
3932} // namespace detail
3933
3934template<class Trait = detail::SVMTraitNull>
3935class SVMTraitReadWrite
3936{
3937public:
3938 static cl_svm_mem_flags getSVMMemFlags()
3939 {
3940 return CL_MEM_READ_WRITE |
3941 Trait::getSVMMemFlags();
3943};
3944
3945template<class Trait = detail::SVMTraitNull>
3946class SVMTraitReadOnly
3947{
3948public:
3949 static cl_svm_mem_flags getSVMMemFlags()
3950 {
3951 return CL_MEM_READ_ONLY |
3952 Trait::getSVMMemFlags();
3954};
3955
3956template<class Trait = detail::SVMTraitNull>
3957class SVMTraitWriteOnly
3958{
3959public:
3960 static cl_svm_mem_flags getSVMMemFlags()
3961 {
3962 return CL_MEM_WRITE_ONLY |
3963 Trait::getSVMMemFlags();
3965};
3966
3967template<class Trait = SVMTraitReadWrite<>>
3968class SVMTraitCoarse
3969{
3970public:
3971 static cl_svm_mem_flags getSVMMemFlags()
3972 {
3973 return Trait::getSVMMemFlags();
3975};
3976
3977template<class Trait = SVMTraitReadWrite<>>
3978class SVMTraitFine
3979{
3980public:
3981 static cl_svm_mem_flags getSVMMemFlags()
3982 {
3983 return CL_MEM_SVM_FINE_GRAIN_BUFFER |
3984 Trait::getSVMMemFlags();
3986};
3987
3988template<class Trait = SVMTraitReadWrite<>>
3989class SVMTraitAtomic
3990{
3991public:
3992 static cl_svm_mem_flags getSVMMemFlags()
3993 {
3994 return
3995 CL_MEM_SVM_FINE_GRAIN_BUFFER |
3996 CL_MEM_SVM_ATOMICS |
3997 Trait::getSVMMemFlags();
3998 }
3999};
4000
4001// Pre-declare SVM map function
4002template<typename T>
4003inline cl_int enqueueMapSVM(
4004 T* ptr,
4005 cl_bool blocking,
4006 cl_map_flags flags,
4007 size_type size,
4008 const vector<Event>* events = nullptr,
4009 Event* event = nullptr);
4010
4022template<typename T, class SVMTrait>
4023class SVMAllocator {
4024private:
4025 Context context_;
4026
4027public:
4028 typedef T value_type;
4029 typedef value_type* pointer;
4030 typedef const value_type* const_pointer;
4031 typedef value_type& reference;
4032 typedef const value_type& const_reference;
4033 typedef std::size_t size_type;
4034 typedef std::ptrdiff_t difference_type;
4035
4036 template<typename U>
4037 struct rebind
4038 {
4040 };
4041
4042 template<typename U, typename V>
4043 friend class SVMAllocator;
4044
4045 SVMAllocator() :
4046 context_(Context::getDefault())
4047 {
4048 }
4049
4050 explicit SVMAllocator(cl::Context context) :
4051 context_(context)
4052 {
4053 }
4054
4055
4056 SVMAllocator(const SVMAllocator &other) :
4057 context_(other.context_)
4058 {
4059 }
4060
4061 template<typename U>
4062 SVMAllocator(const SVMAllocator<U, SVMTrait> &other) :
4063 context_(other.context_)
4064 {
4065 }
4066
4067 ~SVMAllocator()
4068 {
4069 }
4070
4071 pointer address(reference r) noexcept
4072 {
4073 return std::addressof(r);
4074 }
4075
4076 const_pointer address(const_reference r) noexcept
4077 {
4078 return std::addressof(r);
4079 }
4080
4087 pointer allocate(
4088 size_type size,
4089 typename cl::SVMAllocator<void, SVMTrait>::const_pointer = 0,
4090 bool map = true)
4091 {
4092 // Allocate memory with default alignment matching the size of the type
4093 void* voidPointer =
4094 clSVMAlloc(
4095 context_(),
4096 SVMTrait::getSVMMemFlags(),
4097 size*sizeof(T),
4098 0);
4099 pointer retValue = reinterpret_cast<pointer>(
4100 voidPointer);
4101#if defined(CL_HPP_ENABLE_EXCEPTIONS)
4102 if (!retValue) {
4103 std::bad_alloc excep;
4104 throw excep;
4105 }
4106#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
4107
4108 // If allocation was coarse-grained then map it
4109 if (map && !(SVMTrait::getSVMMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) {
4110 cl_int err = enqueueMapSVM(retValue, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, size*sizeof(T));
4111 if (err != CL_SUCCESS) {
4112 clSVMFree(context_(), retValue);
4113 retValue = nullptr;
4114#if defined(CL_HPP_ENABLE_EXCEPTIONS)
4115 std::bad_alloc excep;
4116 throw excep;
4117#endif
4118 }
4119 }
4120
4121 // If exceptions disabled, return null pointer from allocator
4122 return retValue;
4123 }
4124
4125 void deallocate(pointer p, size_type)
4126 {
4127 clSVMFree(context_(), p);
4128 }
4129
4134 size_type max_size() const noexcept
4135 {
4136 size_type maxSize = std::numeric_limits<size_type>::max() / sizeof(T);
4137
4138 for (const Device &d : context_.getInfo<CL_CONTEXT_DEVICES>()) {
4139 maxSize = std::min(
4140 maxSize,
4141 static_cast<size_type>(d.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>()));
4142 }
4143
4144 return maxSize;
4145 }
4146
4147 template< class U, class... Args >
4148 void construct(U* p, Args&&... args)
4149 {
4150 new(p)T(args...);
4151 }
4152
4153 template< class U >
4154 void destroy(U* p)
4155 {
4156 p->~U();
4157 }
4162 inline bool operator==(SVMAllocator const& rhs)
4163 {
4164 return (context_==rhs.context_);
4165 }
4166
4167 inline bool operator!=(SVMAllocator const& a)
4168 {
4169 return !operator==(a);
4170 }
4171}; // class SVMAllocator return cl::pointer<T>(tmp, detail::Deleter<T, Alloc>{alloc, copies});
4172
4173
4174template<class SVMTrait>
4175class SVMAllocator<void, SVMTrait> {
4176public:
4177 typedef void value_type;
4178 typedef value_type* pointer;
4179 typedef const value_type* const_pointer;
4180
4181 template<typename U>
4182 struct rebind
4183 {
4185 };
4186
4187 template<typename U, typename V>
4188 friend class SVMAllocator;
4189};
4190
4191#if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
4192namespace detail
4193{
4194 template<class Alloc>
4195 class Deleter {
4196 private:
4197 Alloc alloc_;
4198 size_type copies_;
4199
4200 public:
4201 typedef typename std::allocator_traits<Alloc>::pointer pointer;
4202
4203 Deleter(const Alloc &alloc, size_type copies) : alloc_{ alloc }, copies_{ copies }
4204 {
4205 }
4206
4207 void operator()(pointer ptr) const {
4208 Alloc tmpAlloc{ alloc_ };
4209 std::allocator_traits<Alloc>::destroy(tmpAlloc, std::addressof(*ptr));
4210 std::allocator_traits<Alloc>::deallocate(tmpAlloc, ptr, copies_);
4211 }
4212 };
4213} // namespace detail
4214
4221template <class T, class Alloc, class... Args>
4222cl::pointer<T, detail::Deleter<Alloc>> allocate_pointer(const Alloc &alloc_, Args&&... args)
4223{
4224 Alloc alloc(alloc_);
4225 static const size_type copies = 1;
4226
4227 // Ensure that creation of the management block and the
4228 // object are dealt with separately such that we only provide a deleter
4229
4230 T* tmp = std::allocator_traits<Alloc>::allocate(alloc, copies);
4231 if (!tmp) {
4232 std::bad_alloc excep;
4233 throw excep;
4234 }
4235 try {
4236 std::allocator_traits<Alloc>::construct(
4237 alloc,
4238 std::addressof(*tmp),
4239 std::forward<Args>(args)...);
4240
4241 return cl::pointer<T, detail::Deleter<Alloc>>(tmp, detail::Deleter<Alloc>{alloc, copies});
4242 }
4243 catch (std::bad_alloc&)
4244 {
4245 std::allocator_traits<Alloc>::deallocate(alloc, tmp, copies);
4246 throw;
4247 }
4248}
4249
4250template< class T, class SVMTrait, class... Args >
4251cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(Args... args)
4252{
4253 SVMAllocator<T, SVMTrait> alloc;
4254 return cl::allocate_pointer<T>(alloc, args...);
4255}
4256
4257template< class T, class SVMTrait, class... Args >
4258cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(const cl::Context &c, Args... args)
4259{
4260 SVMAllocator<T, SVMTrait> alloc(c);
4261 return cl::allocate_pointer<T>(alloc, args...);
4262}
4263#endif // #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
4264
4268template < class T >
4269using coarse_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>>;
4270
4274template < class T >
4275using fine_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitFine<>>>;
4276
4280template < class T >
4281using atomic_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitAtomic<>>>;
4282
4283#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
4284
4285
4292class Buffer : public Memory
4293{
4294public:
4295
4303 Buffer(
4304 const Context& context,
4305 cl_mem_flags flags,
4306 size_type size,
4307 void* host_ptr = nullptr,
4308 cl_int* err = nullptr)
4309 {
4310 cl_int error;
4311 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
4312
4313 detail::errHandler(error, __CREATE_BUFFER_ERR);
4314 if (err != nullptr) {
4315 *err = error;
4316 }
4317 }
4318
4319#if CL_HPP_TARGET_OPENCL_VERSION >= 300
4330 Buffer(
4331 const Context& context,
4332 const vector<cl_mem_properties>& properties,
4333 cl_mem_flags flags,
4334 size_type size,
4335 void* host_ptr = nullptr,
4336 cl_int* err = nullptr)
4337 {
4338 cl_int error;
4339
4340 if (properties.empty()) {
4341 object_ = ::clCreateBufferWithProperties(context(), nullptr, flags,
4342 size, host_ptr, &error);
4343 }
4344 else {
4345 object_ = ::clCreateBufferWithProperties(
4346 context(), properties.data(), flags, size, host_ptr, &error);
4347 }
4348
4349 detail::errHandler(error, __CREATE_BUFFER_ERR);
4350 if (err != nullptr) {
4351 *err = error;
4352 }
4353 }
4354#endif
4355
4365 Buffer(
4366 cl_mem_flags flags,
4367 size_type size,
4368 void* host_ptr = nullptr,
4369 cl_int* err = nullptr) : Buffer(Context::getDefault(err), flags, size, host_ptr, err) { }
4370
4371#if CL_HPP_TARGET_OPENCL_VERSION >= 300
4384 Buffer(
4385 const vector<cl_mem_properties>& properties,
4386 cl_mem_flags flags,
4387 size_type size,
4388 void* host_ptr = nullptr,
4389 cl_int* err = nullptr) : Buffer(Context::getDefault(err), properties, flags, size, host_ptr, err) { }
4390#endif
4391
4397 template< typename IteratorType >
4398 Buffer(
4399 IteratorType startIterator,
4400 IteratorType endIterator,
4401 bool readOnly,
4402 bool useHostPtr = false,
4403 cl_int* err = nullptr)
4404 {
4405 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
4406 cl_int error;
4407
4408 cl_mem_flags flags = 0;
4409 if( readOnly ) {
4410 flags |= CL_MEM_READ_ONLY;
4411 }
4412 else {
4413 flags |= CL_MEM_READ_WRITE;
4414 }
4415 if( useHostPtr ) {
4416 flags |= CL_MEM_USE_HOST_PTR;
4417 }
4418
4419 size_type size = sizeof(DataType)*(endIterator - startIterator);
4420
4421 Context context = Context::getDefault(err);
4422
4423 if( useHostPtr ) {
4424 object_ = ::clCreateBuffer(context(), flags, size, const_cast<DataType*>(&*startIterator), &error);
4425 } else {
4426 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
4427 }
4428
4429 detail::errHandler(error, __CREATE_BUFFER_ERR);
4430 if (err != nullptr) {
4431 *err = error;
4432 }
4433
4434 if( !useHostPtr ) {
4435 error = cl::copy(startIterator, endIterator, *this);
4436 detail::errHandler(error, __CREATE_BUFFER_ERR);
4437 if (err != nullptr) {
4438 *err = error;
4439 }
4440 }
4441 }
4442
4448 template< typename IteratorType >
4449 Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator,
4450 bool readOnly, bool useHostPtr = false, cl_int* err = nullptr);
4451
4456 template< typename IteratorType >
4457 Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator,
4458 bool readOnly, bool useHostPtr = false, cl_int* err = nullptr);
4459
4461 Buffer() : Memory() { }
4462
4470 explicit Buffer(const cl_mem& buffer, bool retainObject = false) :
4471 Memory(buffer, retainObject) { }
4472
4477 Buffer& operator = (const cl_mem& rhs)
4478 {
4479 Memory::operator=(rhs);
4480 return *this;
4481 }
4482
4483
4484#if CL_HPP_TARGET_OPENCL_VERSION >= 110
4490 cl_mem_flags flags,
4491 cl_buffer_create_type buffer_create_type,
4492 const void * buffer_create_info,
4493 cl_int * err = nullptr)
4494 {
4495 Buffer result;
4496 cl_int error;
4497 result.object_ = ::clCreateSubBuffer(
4498 object_,
4499 flags,
4500 buffer_create_type,
4501 buffer_create_info,
4502 &error);
4503
4504 detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
4505 if (err != nullptr) {
4506 *err = error;
4507 }
4508
4509 return result;
4510 }
4511#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
4512};
4513
4514#if defined (CL_HPP_USE_DX_INTEROP)
4523class BufferD3D10 : public Buffer
4524{
4525public:
4526
4527
4533 BufferD3D10(
4534 const Context& context,
4535 cl_mem_flags flags,
4536 ID3D10Buffer* bufobj,
4537 cl_int * err = nullptr) : pfn_clCreateFromD3D10BufferKHR(nullptr)
4538 {
4539 typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
4540 cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
4541 cl_int* errcode_ret);
4542 PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR;
4543#if CL_HPP_TARGET_OPENCL_VERSION >= 120
4544 vector<cl_context_properties> props = context.getInfo<CL_CONTEXT_PROPERTIES>();
4545 cl_platform platform = nullptr;
4546 for( int i = 0; i < props.size(); ++i ) {
4547 if( props[i] == CL_CONTEXT_PLATFORM ) {
4548 platform = props[i+1];
4549 }
4550 }
4551 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateFromD3D10BufferKHR);
4552#endif
4553#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
4554 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateFromD3D10BufferKHR);
4555#endif
4556
4557 cl_int error;
4558 object_ = pfn_clCreateFromD3D10BufferKHR(
4559 context(),
4560 flags,
4561 bufobj,
4562 &error);
4563
4564 // TODO: This should really have a D3D10 rerror code!
4565 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4566 if (err != nullptr) {
4567 *err = error;
4568 }
4569 }
4570
4572 BufferD3D10() : Buffer() { }
4573
4581 explicit BufferD3D10(const cl_mem& buffer, bool retainObject = false) :
4582 Buffer(buffer, retainObject) { }
4583
4588 BufferD3D10& operator = (const cl_mem& rhs)
4589 {
4590 Buffer::operator=(rhs);
4591 return *this;
4592 }
4593};
4594#endif
4595
4604class BufferGL : public Buffer
4605{
4606public:
4612 BufferGL(
4613 const Context& context,
4614 cl_mem_flags flags,
4615 cl_GLuint bufobj,
4616 cl_int * err = nullptr)
4617 {
4618 cl_int error;
4619 object_ = ::clCreateFromGLBuffer(
4620 context(),
4621 flags,
4622 bufobj,
4623 &error);
4624
4625 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4626 if (err != nullptr) {
4627 *err = error;
4629 }
4630
4632 BufferGL() : Buffer() { }
4633
4641 explicit BufferGL(const cl_mem& buffer, bool retainObject = false) :
4642 Buffer(buffer, retainObject) { }
4643
4648 BufferGL& operator = (const cl_mem& rhs)
4649 {
4650 Buffer::operator=(rhs);
4651 return *this;
4653
4654
4656 cl_int getObjectInfo(
4657 cl_gl_object_type *type,
4658 cl_GLuint * gl_object_name)
4659 {
4660 return detail::errHandler(
4661 ::clGetGLObjectInfo(object_,type,gl_object_name),
4662 __GET_GL_OBJECT_INFO_ERR);
4663 }
4664};
4665
4674class BufferRenderGL : public Buffer
4675{
4676public:
4683 const Context& context,
4684 cl_mem_flags flags,
4685 cl_GLuint bufobj,
4686 cl_int * err = nullptr)
4687 {
4688 cl_int error;
4689 object_ = ::clCreateFromGLRenderbuffer(
4690 context(),
4691 flags,
4692 bufobj,
4693 &error);
4694
4695 detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR);
4696 if (err != nullptr) {
4697 *err = error;
4699 }
4700
4702 BufferRenderGL() : Buffer() { }
4703
4711 explicit BufferRenderGL(const cl_mem& buffer, bool retainObject = false) :
4712 Buffer(buffer, retainObject) { }
4713
4718 BufferRenderGL& operator = (const cl_mem& rhs)
4719 {
4720 Buffer::operator=(rhs);
4721 return *this;
4723
4724
4726 cl_int getObjectInfo(
4727 cl_gl_object_type *type,
4728 cl_GLuint * gl_object_name)
4729 {
4730 return detail::errHandler(
4731 ::clGetGLObjectInfo(object_,type,gl_object_name),
4732 __GET_GL_OBJECT_INFO_ERR);
4733 }
4734};
4735
4742class Image : public Memory
4743{
4744protected:
4746 Image() : Memory() { }
4747
4755 explicit Image(const cl_mem& image, bool retainObject = false) :
4756 Memory(image, retainObject) { }
4757
4762 Image& operator = (const cl_mem& rhs)
4763 {
4764 Memory::operator=(rhs);
4765 return *this;
4766 }
4767
4769public:
4771 template <typename T>
4772 cl_int getImageInfo(cl_image_info name, T* param) const
4773 {
4774 return detail::errHandler(
4775 detail::getInfo(&::clGetImageInfo, object_, name, param),
4776 __GET_IMAGE_INFO_ERR);
4777 }
4780 template <cl_image_info name> typename
4782 getImageInfo(cl_int* err = nullptr) const
4783 {
4784 typename detail::param_traits<
4785 detail::cl_image_info, name>::param_type param;
4786 cl_int result = getImageInfo(name, &param);
4787 if (err != nullptr) {
4788 *err = result;
4789 }
4790 return param;
4791 }
4792};
4793
4794#if CL_HPP_TARGET_OPENCL_VERSION >= 120
4801class Image1D : public Image
4802{
4803public:
4808 Image1D(
4809 const Context& context,
4810 cl_mem_flags flags,
4811 ImageFormat format,
4812 size_type width,
4813 void* host_ptr = nullptr,
4814 cl_int* err = nullptr)
4815 {
4816 cl_int error;
4817
4818 cl_image_desc desc = {};
4819 desc.image_type = CL_MEM_OBJECT_IMAGE1D;
4820 desc.image_width = width;
4821
4822 object_ = ::clCreateImage(
4823 context(),
4824 flags,
4825 &format,
4826 &desc,
4827 host_ptr,
4828 &error);
4829
4830 detail::errHandler(error, __CREATE_IMAGE_ERR);
4831 if (err != nullptr) {
4832 *err = error;
4834 }
4835
4837 Image1D() { }
4838
4846 explicit Image1D(const cl_mem& image1D, bool retainObject = false) :
4847 Image(image1D, retainObject) { }
4848
4853 Image1D& operator = (const cl_mem& rhs)
4854 {
4855 Image::operator=(rhs);
4856 return *this;
4857 }
4858
4859
4860};
4865class Image1DBuffer : public Image
4866{
4867public:
4869 const Context& context,
4870 cl_mem_flags flags,
4871 ImageFormat format,
4872 size_type width,
4873 const Buffer &buffer,
4874 cl_int* err = nullptr)
4875 {
4876 cl_int error;
4877
4878 cl_image_desc desc = {};
4879 desc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER;
4880 desc.image_width = width;
4881 desc.buffer = buffer();
4882
4883 object_ = ::clCreateImage(
4884 context(),
4885 flags,
4886 &format,
4887 &desc,
4888 nullptr,
4889 &error);
4890
4891 detail::errHandler(error, __CREATE_IMAGE_ERR);
4892 if (err != nullptr) {
4893 *err = error;
4894 }
4895 }
4896
4897 Image1DBuffer() { }
4898
4906 explicit Image1DBuffer(const cl_mem& image1D, bool retainObject = false) :
4907 Image(image1D, retainObject) { }
4908
4909 Image1DBuffer& operator = (const cl_mem& rhs)
4910 {
4911 Image::operator=(rhs);
4912 return *this;
4913 }
4914
4915
4916
4917};
4922class Image1DArray : public Image
4923{
4924public:
4926 const Context& context,
4927 cl_mem_flags flags,
4928 ImageFormat format,
4929 size_type arraySize,
4930 size_type width,
4931 size_type rowPitch,
4932 void* host_ptr = nullptr,
4933 cl_int* err = nullptr)
4934 {
4935 cl_int error;
4936
4937 cl_image_desc desc = {};
4938 desc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
4939 desc.image_width = width;
4940 desc.image_array_size = arraySize;
4941 desc.image_row_pitch = rowPitch;
4942
4943 object_ = ::clCreateImage(
4944 context(),
4945 flags,
4946 &format,
4947 &desc,
4948 host_ptr,
4949 &error);
4950
4951 detail::errHandler(error, __CREATE_IMAGE_ERR);
4952 if (err != nullptr) {
4953 *err = error;
4954 }
4955 }
4956
4957 Image1DArray() { }
4958
4966 explicit Image1DArray(const cl_mem& imageArray, bool retainObject = false) :
4967 Image(imageArray, retainObject) { }
4968
4969
4970 Image1DArray& operator = (const cl_mem& rhs)
4971 {
4972 Image::operator=(rhs);
4973 return *this;
4974 }
4975
4976
4977};
4978#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4979
4980
4987class Image2D : public Image
4988{
4989public:
4994 Image2D(
4995 const Context& context,
4996 cl_mem_flags flags,
4997 ImageFormat format,
4998 size_type width,
4999 size_type height,
5000 size_type row_pitch = 0,
5001 void* host_ptr = nullptr,
5002 cl_int* err = nullptr)
5003 {
5004 cl_int error;
5005 bool useCreateImage;
5006
5007#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
5008 // Run-time decision based on the actual platform
5009 {
5010 cl_uint version = detail::getContextPlatformVersion(context());
5011 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
5012 }
5013#elif CL_HPP_TARGET_OPENCL_VERSION >= 120
5014 useCreateImage = true;
5015#else
5016 useCreateImage = false;
5017#endif
5018
5019#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5020 if (useCreateImage)
5021 {
5022 cl_image_desc desc = {};
5023 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
5024 desc.image_width = width;
5025 desc.image_height = height;
5026 desc.image_row_pitch = row_pitch;
5027
5028 object_ = ::clCreateImage(
5029 context(),
5030 flags,
5031 &format,
5032 &desc,
5033 host_ptr,
5034 &error);
5035
5036 detail::errHandler(error, __CREATE_IMAGE_ERR);
5037 if (err != nullptr) {
5038 *err = error;
5039 }
5040 }
5041#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5042#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
5043 if (!useCreateImage)
5044 {
5045 object_ = ::clCreateImage2D(
5046 context(), flags,&format, width, height, row_pitch, host_ptr, &error);
5047
5048 detail::errHandler(error, __CREATE_IMAGE2D_ERR);
5049 if (err != nullptr) {
5050 *err = error;
5051 }
5052 }
5053#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
5054 }
5055
5056#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5065 Image2D(
5066 const Context& context,
5067 ImageFormat format,
5068 const Buffer &sourceBuffer,
5069 size_type width,
5070 size_type height,
5071 size_type row_pitch = 0,
5072 cl_int* err = nullptr)
5073 {
5074 cl_int error;
5075
5076 cl_image_desc desc = {};
5077 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
5078 desc.image_width = width;
5079 desc.image_height = height;
5080 desc.image_row_pitch = row_pitch;
5081 desc.buffer = sourceBuffer();
5082
5083 object_ = ::clCreateImage(
5084 context(),
5085 0, // flags inherited from buffer
5086 &format,
5087 &desc,
5088 nullptr,
5089 &error);
5090
5091 detail::errHandler(error, __CREATE_IMAGE_ERR);
5092 if (err != nullptr) {
5093 *err = error;
5094 }
5095 }
5096#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5097
5098#if CL_HPP_TARGET_OPENCL_VERSION >= 200
5111 Image2D(
5112 const Context& context,
5113 cl_channel_order order,
5114 const Image &sourceImage,
5115 cl_int* err = nullptr)
5116 {
5117 cl_int error;
5118
5119 // Descriptor fields have to match source image
5120 size_type sourceWidth =
5121 sourceImage.getImageInfo<CL_IMAGE_WIDTH>();
5122 size_type sourceHeight =
5123 sourceImage.getImageInfo<CL_IMAGE_HEIGHT>();
5124 size_type sourceRowPitch =
5125 sourceImage.getImageInfo<CL_IMAGE_ROW_PITCH>();
5126 cl_uint sourceNumMIPLevels =
5127 sourceImage.getImageInfo<CL_IMAGE_NUM_MIP_LEVELS>();
5128 cl_uint sourceNumSamples =
5129 sourceImage.getImageInfo<CL_IMAGE_NUM_SAMPLES>();
5130 cl_image_format sourceFormat =
5131 sourceImage.getImageInfo<CL_IMAGE_FORMAT>();
5132
5133 // Update only the channel order.
5134 // Channel format inherited from source.
5135 sourceFormat.image_channel_order = order;
5136
5137 cl_image_desc desc = {};
5138 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
5139 desc.image_width = sourceWidth;
5140 desc.image_height = sourceHeight;
5141 desc.image_row_pitch = sourceRowPitch;
5142 desc.num_mip_levels = sourceNumMIPLevels;
5143 desc.num_samples = sourceNumSamples;
5144 desc.buffer = sourceImage();
5145
5146 object_ = ::clCreateImage(
5147 context(),
5148 0, // flags should be inherited from mem_object
5149 &sourceFormat,
5150 &desc,
5151 nullptr,
5152 &error);
5153
5154 detail::errHandler(error, __CREATE_IMAGE_ERR);
5155 if (err != nullptr) {
5156 *err = error;
5157 }
5159#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200
5160
5162 Image2D() { }
5163
5171 explicit Image2D(const cl_mem& image2D, bool retainObject = false) :
5172 Image(image2D, retainObject) { }
5173
5178 Image2D& operator = (const cl_mem& rhs)
5179 {
5180 Image::operator=(rhs);
5181 return *this;
5182 }
5183
5184
5185
5186
5187};
5188
5189
5190#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
5200class CL_API_PREFIX__VERSION_1_1_DEPRECATED Image2DGL : public Image2D
5201{
5202public:
5208 Image2DGL(
5209 const Context& context,
5210 cl_mem_flags flags,
5211 cl_GLenum target,
5212 cl_GLint miplevel,
5213 cl_GLuint texobj,
5214 cl_int * err = nullptr)
5215 {
5216 cl_int error;
5217 object_ = ::clCreateFromGLTexture2D(
5218 context(),
5219 flags,
5220 target,
5221 miplevel,
5222 texobj,
5223 &error);
5224
5225 detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR);
5226 if (err != nullptr) {
5227 *err = error;
5228 }
5230 }
5231
5233 Image2DGL() : Image2D() { }
5234
5242 explicit Image2DGL(const cl_mem& image, bool retainObject = false) :
5243 Image2D(image, retainObject) { }
5244
5249 Image2DGL& operator = (const cl_mem& rhs)
5250 {
5251 Image2D::operator=(rhs);
5252 return *this;
5253 }
5254
5255
5256
5257} CL_API_SUFFIX__VERSION_1_1_DEPRECATED;
5258#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5259
5260#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5264class Image2DArray : public Image
5265{
5266public:
5268 const Context& context,
5269 cl_mem_flags flags,
5270 ImageFormat format,
5271 size_type arraySize,
5272 size_type width,
5273 size_type height,
5274 size_type rowPitch,
5275 size_type slicePitch,
5276 void* host_ptr = nullptr,
5277 cl_int* err = nullptr)
5278 {
5279 cl_int error;
5280
5281 cl_image_desc desc = {};
5282 desc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
5283 desc.image_width = width;
5284 desc.image_height = height;
5285 desc.image_array_size = arraySize;
5286 desc.image_row_pitch = rowPitch;
5287 desc.image_slice_pitch = slicePitch;
5288
5289 object_ = ::clCreateImage(
5290 context(),
5291 flags,
5292 &format,
5293 &desc,
5294 host_ptr,
5295 &error);
5296
5297 detail::errHandler(error, __CREATE_IMAGE_ERR);
5298 if (err != nullptr) {
5299 *err = error;
5300 }
5301 }
5302
5303 Image2DArray() { }
5304
5312 explicit Image2DArray(const cl_mem& imageArray, bool retainObject = false) : Image(imageArray, retainObject) { }
5313
5314 Image2DArray& operator = (const cl_mem& rhs)
5315 {
5316 Image::operator=(rhs);
5317 return *this;
5318 }
5319
5320};
5321#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5322
5329class Image3D : public Image
5330{
5331public:
5336 Image3D(
5337 const Context& context,
5338 cl_mem_flags flags,
5339 ImageFormat format,
5340 size_type width,
5341 size_type height,
5342 size_type depth,
5343 size_type row_pitch = 0,
5344 size_type slice_pitch = 0,
5345 void* host_ptr = nullptr,
5346 cl_int* err = nullptr)
5347 {
5348 cl_int error;
5349 bool useCreateImage;
5350
5351#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
5352 // Run-time decision based on the actual platform
5353 {
5354 cl_uint version = detail::getContextPlatformVersion(context());
5355 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
5356 }
5357#elif CL_HPP_TARGET_OPENCL_VERSION >= 120
5358 useCreateImage = true;
5359#else
5360 useCreateImage = false;
5361#endif
5362
5363#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5364 if (useCreateImage)
5365 {
5366 cl_image_desc desc = {};
5367 desc.image_type = CL_MEM_OBJECT_IMAGE3D;
5368 desc.image_width = width;
5369 desc.image_height = height;
5370 desc.image_depth = depth;
5371 desc.image_row_pitch = row_pitch;
5372 desc.image_slice_pitch = slice_pitch;
5373
5374 object_ = ::clCreateImage(
5375 context(),
5376 flags,
5377 &format,
5378 &desc,
5379 host_ptr,
5380 &error);
5381
5382 detail::errHandler(error, __CREATE_IMAGE_ERR);
5383 if (err != nullptr) {
5384 *err = error;
5385 }
5386 }
5387#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5388#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
5389 if (!useCreateImage)
5390 {
5391 object_ = ::clCreateImage3D(
5392 context(), flags, &format, width, height, depth, row_pitch,
5393 slice_pitch, host_ptr, &error);
5394
5395 detail::errHandler(error, __CREATE_IMAGE3D_ERR);
5396 if (err != nullptr) {
5397 *err = error;
5398 }
5399 }
5400#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
5401 }
5402
5404 Image3D() : Image() { }
5405
5413 explicit Image3D(const cl_mem& image3D, bool retainObject = false) :
5414 Image(image3D, retainObject) { }
5415
5420 Image3D& operator = (const cl_mem& rhs)
5421 {
5422 Image::operator=(rhs);
5423 return *this;
5424 }
5425
5426};
5427
5428#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
5437class Image3DGL : public Image3D
5438{
5439public:
5445 Image3DGL(
5446 const Context& context,
5447 cl_mem_flags flags,
5448 cl_GLenum target,
5449 cl_GLint miplevel,
5450 cl_GLuint texobj,
5451 cl_int * err = nullptr)
5452 {
5453 cl_int error;
5454 object_ = ::clCreateFromGLTexture3D(
5455 context(),
5456 flags,
5457 target,
5458 miplevel,
5459 texobj,
5460 &error);
5461
5462 detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR);
5463 if (err != nullptr) {
5464 *err = error;
5466 }
5467
5469 Image3DGL() : Image3D() { }
5470
5478 explicit Image3DGL(const cl_mem& image, bool retainObject = false) :
5479 Image3D(image, retainObject) { }
5480
5485 Image3DGL& operator = (const cl_mem& rhs)
5486 {
5487 Image3D::operator=(rhs);
5488 return *this;
5489 }
5490
5491};
5492#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5493
5494#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5501class ImageGL : public Image
5502{
5503public:
5504 ImageGL(
5505 const Context& context,
5506 cl_mem_flags flags,
5507 cl_GLenum target,
5508 cl_GLint miplevel,
5509 cl_GLuint texobj,
5510 cl_int * err = nullptr)
5511 {
5512 cl_int error;
5513 object_ = ::clCreateFromGLTexture(
5514 context(),
5515 flags,
5516 target,
5517 miplevel,
5518 texobj,
5519 &error);
5520
5521 detail::errHandler(error, __CREATE_GL_TEXTURE_ERR);
5522 if (err != nullptr) {
5523 *err = error;
5524 }
5525 }
5526
5527 ImageGL() : Image() { }
5528
5536 explicit ImageGL(const cl_mem& image, bool retainObject = false) :
5537 Image(image, retainObject) { }
5538
5539 ImageGL& operator = (const cl_mem& rhs)
5540 {
5541 Image::operator=(rhs);
5542 return *this;
5543 }
5544
5545};
5546#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5547
5548
5549
5550#if CL_HPP_TARGET_OPENCL_VERSION >= 200
5557class Pipe : public Memory
5558{
5559public:
5560
5570 Pipe(
5571 const Context& context,
5572 cl_uint packet_size,
5573 cl_uint max_packets,
5574 cl_int* err = nullptr)
5575 {
5576 cl_int error;
5577
5578 cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5579 object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error);
5580
5581 detail::errHandler(error, __CREATE_PIPE_ERR);
5582 if (err != nullptr) {
5583 *err = error;
5584 }
5585 }
5586
5595 Pipe(
5596 cl_uint packet_size,
5597 cl_uint max_packets,
5598 cl_int* err = nullptr)
5599 {
5600 cl_int error;
5601
5602 Context context = Context::getDefault(err);
5603
5604 cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5605 object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error);
5606
5607 detail::errHandler(error, __CREATE_PIPE_ERR);
5608 if (err != nullptr) {
5609 *err = error;
5611 }
5612
5614 Pipe() : Memory() { }
5615
5623 explicit Pipe(const cl_mem& pipe, bool retainObject = false) :
5624 Memory(pipe, retainObject) { }
5625
5630 Pipe& operator = (const cl_mem& rhs)
5631 {
5632 Memory::operator=(rhs);
5633 return *this;
5634 }
5635
5637
5639 template <typename T>
5640 cl_int getInfo(cl_pipe_info name, T* param) const
5641 {
5642 return detail::errHandler(
5643 detail::getInfo(&::clGetPipeInfo, object_, name, param),
5644 __GET_PIPE_INFO_ERR);
5645 }
5648 template <cl_pipe_info name> typename
5650 getInfo(cl_int* err = nullptr) const
5651 {
5652 typename detail::param_traits<
5653 detail::cl_pipe_info, name>::param_type param;
5654 cl_int result = getInfo(name, &param);
5655 if (err != nullptr) {
5656 *err = result;
5657 }
5658 return param;
5659 }
5660}; // class Pipe
5661#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
5662
5663
5672class Sampler : public detail::Wrapper<cl_sampler>
5673{
5674public:
5676 Sampler() { }
5677
5682 Sampler(
5683 const Context& context,
5684 cl_bool normalized_coords,
5685 cl_addressing_mode addressing_mode,
5686 cl_filter_mode filter_mode,
5687 cl_int* err = nullptr)
5688 {
5689 cl_int error;
5690
5691#if CL_HPP_TARGET_OPENCL_VERSION >= 200
5692 cl_sampler_properties sampler_properties[] = {
5693 CL_SAMPLER_NORMALIZED_COORDS, normalized_coords,
5694 CL_SAMPLER_ADDRESSING_MODE, addressing_mode,
5695 CL_SAMPLER_FILTER_MODE, filter_mode,
5696 0 };
5697 object_ = ::clCreateSamplerWithProperties(
5698 context(),
5699 sampler_properties,
5700 &error);
5701
5702 detail::errHandler(error, __CREATE_SAMPLER_WITH_PROPERTIES_ERR);
5703 if (err != nullptr) {
5704 *err = error;
5705 }
5706#else
5707 object_ = ::clCreateSampler(
5708 context(),
5709 normalized_coords,
5710 addressing_mode,
5711 filter_mode,
5712 &error);
5713
5714 detail::errHandler(error, __CREATE_SAMPLER_ERR);
5715 if (err != nullptr) {
5716 *err = error;
5717 }
5718#endif
5719 }
5720
5729 explicit Sampler(const cl_sampler& sampler, bool retainObject = false) :
5730 detail::Wrapper<cl_type>(sampler, retainObject) { }
5731
5737 Sampler& operator = (const cl_sampler& rhs)
5738 {
5740 return *this;
5741 }
5742
5744
5746 template <typename T>
5747 cl_int getInfo(cl_sampler_info name, T* param) const
5748 {
5749 return detail::errHandler(
5750 detail::getInfo(&::clGetSamplerInfo, object_, name, param),
5751 __GET_SAMPLER_INFO_ERR);
5752 }
5755 template <cl_sampler_info name> typename
5757 getInfo(cl_int* err = nullptr) const
5758 {
5759 typename detail::param_traits<
5760 detail::cl_sampler_info, name>::param_type param;
5761 cl_int result = getInfo(name, &param);
5762 if (err != nullptr) {
5763 *err = result;
5764 }
5765 return param;
5766 }
5767};
5768
5769class Program;
5770class CommandQueue;
5772class Kernel;
5773
5775class NDRange
5776{
5777private:
5778 size_type sizes_[3];
5779 cl_uint dimensions_;
5780
5781public:
5783 NDRange()
5784 : dimensions_(0)
5785 {
5786 sizes_[0] = 0;
5787 sizes_[1] = 0;
5788 sizes_[2] = 0;
5789 }
5790
5792 NDRange(size_type size0)
5793 : dimensions_(1)
5794 {
5795 sizes_[0] = size0;
5796 sizes_[1] = 1;
5797 sizes_[2] = 1;
5798 }
5799
5801 NDRange(size_type size0, size_type size1)
5802 : dimensions_(2)
5803 {
5804 sizes_[0] = size0;
5805 sizes_[1] = size1;
5806 sizes_[2] = 1;
5807 }
5808
5810 NDRange(size_type size0, size_type size1, size_type size2)
5811 : dimensions_(3)
5812 {
5813 sizes_[0] = size0;
5814 sizes_[1] = size1;
5815 sizes_[2] = size2;
5816 }
5817
5819 NDRange(array<size_type, 1> a) : NDRange(a[0]){}
5820
5822 NDRange(array<size_type, 2> a) : NDRange(a[0], a[1]){}
5823
5825 NDRange(array<size_type, 3> a) : NDRange(a[0], a[1], a[2]){}
5826
5831 operator const size_type*() const {
5832 return sizes_;
5833 }
5834
5836 size_type dimensions() const
5837 {
5838 return dimensions_;
5840
5842 // runtime number of dimensions
5843 size_type size() const
5844 {
5845 return dimensions_*sizeof(size_type);
5846 }
5847
5848 size_type* get()
5849 {
5850 return sizes_;
5851 }
5852
5853 const size_type* get() const
5854 {
5855 return sizes_;
5856 }
5857};
5858
5860static const NDRange NullRange;
5861
5863struct LocalSpaceArg
5864{
5865 size_type size_;
5866};
5868namespace detail {
5869
5870template <typename T, class Enable = void>
5873// Enable for objects that are not subclasses of memory
5874// Pointers, constants etc
5875template <typename T>
5876struct KernelArgumentHandler<T, typename std::enable_if<!std::is_base_of<cl::Memory, T>::value>::type>
5877{
5878 static size_type size(const T&) { return sizeof(T); }
5879 static const T* ptr(const T& value) { return &value; }
5880};
5882// Enable for subclasses of memory where we want to get a reference to the cl_mem out
5883// and pass that in for safety
5884template <typename T>
5885struct KernelArgumentHandler<T, typename std::enable_if<std::is_base_of<cl::Memory, T>::value>::type>
5886{
5887 static size_type size(const T&) { return sizeof(cl_mem); }
5888 static const cl_mem* ptr(const T& value) { return &(value()); }
5889};
5891// Specialization for DeviceCommandQueue defined later
5892
5893template <>
5895{
5896 static size_type size(const LocalSpaceArg& value) { return value.size_; }
5897 static const void* ptr(const LocalSpaceArg&) { return nullptr; }
5898};
5899
5900}
5902
5906inline LocalSpaceArg
5907Local(size_type size)
5908{
5909 LocalSpaceArg ret = { size };
5910 return ret;
5911}
5912
5921class Kernel : public detail::Wrapper<cl_kernel>
5922{
5923public:
5924 inline Kernel(const Program& program, const string& name, cl_int* err = nullptr);
5925 inline Kernel(const Program& program, const char* name, cl_int* err = nullptr);
5926
5928 Kernel() { }
5929
5938 explicit Kernel(const cl_kernel& kernel, bool retainObject = false) :
5939 detail::Wrapper<cl_type>(kernel, retainObject) { }
5940
5946 Kernel& operator = (const cl_kernel& rhs)
5947 {
5948 detail::Wrapper<cl_type>::operator=(rhs);
5949 return *this;
5950 }
5951
5952
5953
5954
5955 template <typename T>
5956 cl_int getInfo(cl_kernel_info name, T* param) const
5957 {
5958 return detail::errHandler(
5959 detail::getInfo(&::clGetKernelInfo, object_, name, param),
5960 __GET_KERNEL_INFO_ERR);
5961 }
5962
5963 template <cl_kernel_info name> typename
5964 detail::param_traits<detail::cl_kernel_info, name>::param_type
5965 getInfo(cl_int* err = nullptr) const
5966 {
5967 typename detail::param_traits<
5968 detail::cl_kernel_info, name>::param_type param;
5969 cl_int result = getInfo(name, &param);
5970 if (err != nullptr) {
5971 *err = result;
5972 }
5973 return param;
5974 }
5975
5976#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5977 template <typename T>
5978 cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const
5979 {
5980 return detail::errHandler(
5981 detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param),
5982 __GET_KERNEL_ARG_INFO_ERR);
5983 }
5984
5985 template <cl_kernel_arg_info name> typename
5986 detail::param_traits<detail::cl_kernel_arg_info, name>::param_type
5987 getArgInfo(cl_uint argIndex, cl_int* err = nullptr) const
5988 {
5989 typename detail::param_traits<
5990 detail::cl_kernel_arg_info, name>::param_type param;
5991 cl_int result = getArgInfo(argIndex, name, &param);
5992 if (err != nullptr) {
5993 *err = result;
5994 }
5995 return param;
5996 }
5997#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5998
5999 template <typename T>
6000 cl_int getWorkGroupInfo(
6001 const Device& device, cl_kernel_work_group_info name, T* param) const
6002 {
6003 return detail::errHandler(
6004 detail::getInfo(
6005 &::clGetKernelWorkGroupInfo, object_, device(), name, param),
6006 __GET_KERNEL_WORK_GROUP_INFO_ERR);
6007 }
6008
6009 template <cl_kernel_work_group_info name> typename
6010 detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
6011 getWorkGroupInfo(const Device& device, cl_int* err = nullptr) const
6012 {
6013 typename detail::param_traits<
6014 detail::cl_kernel_work_group_info, name>::param_type param;
6015 cl_int result = getWorkGroupInfo(device, name, &param);
6016 if (err != nullptr) {
6017 *err = result;
6018 }
6019 return param;
6020 }
6021
6022#if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) || CL_HPP_TARGET_OPENCL_VERSION >= 210
6023 cl_int getSubGroupInfo(const cl::Device &dev, cl_kernel_sub_group_info name, const cl::NDRange &range, size_type* param) const
6024 {
6025#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6026
6027 return detail::errHandler(
6028 clGetKernelSubGroupInfo(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
6029 __GET_KERNEL_SUB_GROUP_INFO_ERR);
6030
6031#else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6032
6033 typedef clGetKernelSubGroupInfoKHR_fn PFN_clGetKernelSubGroupInfoKHR;
6034 static PFN_clGetKernelSubGroupInfoKHR pfn_clGetKernelSubGroupInfoKHR = nullptr;
6035 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetKernelSubGroupInfoKHR);
6036
6037 return detail::errHandler(
6038 pfn_clGetKernelSubGroupInfoKHR(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
6039 __GET_KERNEL_SUB_GROUP_INFO_ERR);
6040
6041#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6042 }
6043
6044 template <cl_kernel_sub_group_info name>
6045 size_type getSubGroupInfo(const cl::Device &dev, const cl::NDRange &range, cl_int* err = nullptr) const
6046 {
6047 size_type param;
6048 cl_int result = getSubGroupInfo(dev, name, range, &param);
6049 if (err != nullptr) {
6050 *err = result;
6051 }
6052 return param;
6053 }
6054#endif // defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) || CL_HPP_TARGET_OPENCL_VERSION >= 210
6055
6056#if CL_HPP_TARGET_OPENCL_VERSION >= 200
6059 template<typename T, class D>
6060 cl_int setArg(cl_uint index, const cl::pointer<T, D> &argPtr)
6061 {
6062 return detail::errHandler(
6063 ::clSetKernelArgSVMPointer(object_, index, argPtr.get()),
6064 __SET_KERNEL_ARGS_ERR);
6065 }
6069 template<typename T, class Alloc>
6070 cl_int setArg(cl_uint index, const cl::vector<T, Alloc> &argPtr)
6071 {
6072 return detail::errHandler(
6073 ::clSetKernelArgSVMPointer(object_, index, argPtr.data()),
6074 __SET_KERNEL_ARGS_ERR);
6075 }
6076
6079 template<typename T>
6080 typename std::enable_if<std::is_pointer<T>::value, cl_int>::type
6081 setArg(cl_uint index, const T argPtr)
6082 {
6083 return detail::errHandler(
6084 ::clSetKernelArgSVMPointer(object_, index, argPtr),
6085 __SET_KERNEL_ARGS_ERR);
6086 }
6087#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6088
6091 template <typename T>
6092 typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6093 setArg(cl_uint index, const T &value)
6094 {
6095 return detail::errHandler(
6096 ::clSetKernelArg(
6097 object_,
6098 index,
6099 detail::KernelArgumentHandler<T>::size(value),
6100 detail::KernelArgumentHandler<T>::ptr(value)),
6101 __SET_KERNEL_ARGS_ERR);
6102 }
6103
6104 cl_int setArg(cl_uint index, size_type size, const void* argPtr)
6105 {
6106 return detail::errHandler(
6107 ::clSetKernelArg(object_, index, size, argPtr),
6108 __SET_KERNEL_ARGS_ERR);
6109 }
6110
6111#if CL_HPP_TARGET_OPENCL_VERSION >= 200
6116 cl_int setSVMPointers(const vector<void*> &pointerList)
6117 {
6118 return detail::errHandler(
6119 ::clSetKernelExecInfo(
6120 object_,
6121 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6122 sizeof(void*)*pointerList.size(),
6123 pointerList.data()));
6124 }
6125
6130 template<int ArrayLength>
6131 cl_int setSVMPointers(const std::array<void*, ArrayLength> &pointerList)
6132 {
6133 return detail::errHandler(
6134 ::clSetKernelExecInfo(
6135 object_,
6136 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6137 sizeof(void*)*pointerList.size(),
6138 pointerList.data()));
6139 }
6140
6152 cl_int enableFineGrainedSystemSVM(bool svmEnabled)
6153 {
6154 cl_bool svmEnabled_ = svmEnabled ? CL_TRUE : CL_FALSE;
6155 return detail::errHandler(
6156 ::clSetKernelExecInfo(
6157 object_,
6158 CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM,
6159 sizeof(cl_bool),
6160 &svmEnabled_
6161 )
6162 );
6163 }
6164
6165 template<int index, int ArrayLength, class D, typename T0, typename T1, typename... Ts>
6166 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0, const pointer<T1, D> &t1, Ts & ... ts)
6167 {
6168 pointerList[index] = static_cast<void*>(t0.get());
6169 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6170 }
6171
6172 template<int index, int ArrayLength, typename T0, typename T1, typename... Ts>
6173 typename std::enable_if<std::is_pointer<T0>::value, void>::type
6174 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0, T1 t1, Ts... ts)
6175 {
6176 pointerList[index] = static_cast<void*>(t0);
6177 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6178 }
6179
6180 template<int index, int ArrayLength, typename T0, class D>
6181 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0)
6182 {
6183 pointerList[index] = static_cast<void*>(t0.get());
6184 }
6185
6186
6187 template<int index, int ArrayLength, typename T0>
6188 typename std::enable_if<std::is_pointer<T0>::value, void>::type
6189 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0)
6190 {
6191 pointerList[index] = static_cast<void*>(t0);
6192 }
6193
6194 template<typename T0, typename... Ts>
6195 cl_int setSVMPointers(const T0 &t0, Ts & ... ts)
6196 {
6197 std::array<void*, 1 + sizeof...(Ts)> pointerList;
6198
6199 setSVMPointersHelper<0, 1 + sizeof...(Ts)>(pointerList, t0, ts...);
6200 return detail::errHandler(
6201 ::clSetKernelExecInfo(
6202 object_,
6203 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6204 sizeof(void*)*(1 + sizeof...(Ts)),
6205 pointerList.data()));
6206 }
6207
6208 template<typename T>
6209 cl_int setExecInfo(cl_kernel_exec_info param_name, const T& val)
6210 {
6211 return detail::errHandler(
6212 ::clSetKernelExecInfo(
6213 object_,
6214 param_name,
6215 sizeof(T),
6216 &val));
6217 }
6218
6219 template<cl_kernel_exec_info name>
6220 cl_int setExecInfo(typename detail::param_traits<detail::cl_kernel_exec_info, name>::param_type& val)
6221 {
6222 return setExecInfo(name, val);
6223 }
6224#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6225
6226#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6232 Kernel clone()
6233 {
6234 cl_int error;
6235 Kernel retValue(clCloneKernel(this->get(), &error));
6236
6237 detail::errHandler(error, __CLONE_KERNEL_ERR);
6238 return retValue;
6239 }
6240#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6241};
6246class Program : public detail::Wrapper<cl_program>
6247{
6248public:
6249#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6250 typedef vector<vector<unsigned char>> Binaries;
6251 typedef vector<string> Sources;
6252#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6253 typedef vector<std::pair<const void*, size_type> > Binaries;
6254 typedef vector<std::pair<const char*, size_type> > Sources;
6255#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6256
6257 Program(
6258 const string& source,
6259 bool build = false,
6260 cl_int* err = nullptr)
6261 {
6262 cl_int error;
6263
6264 const char * strings = source.c_str();
6265 const size_type length = source.size();
6266
6267 Context context = Context::getDefault(err);
6268
6269 object_ = ::clCreateProgramWithSource(
6270 context(), (cl_uint)1, &strings, &length, &error);
6271
6272 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6273
6274 if (error == CL_SUCCESS && build) {
6275
6276 error = ::clBuildProgram(
6277 object_,
6278 0,
6279 nullptr,
6280#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6281 "-cl-std=CL2.0",
6282#else
6283 "",
6284#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6285 nullptr,
6286 nullptr);
6287
6288 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6289 }
6290
6291 if (err != nullptr) {
6292 *err = error;
6293 }
6294 }
6295
6296 Program(
6297 const Context& context,
6298 const string& source,
6299 bool build = false,
6300 cl_int* err = nullptr)
6301 {
6302 cl_int error;
6303
6304 const char * strings = source.c_str();
6305 const size_type length = source.size();
6306
6307 object_ = ::clCreateProgramWithSource(
6308 context(), (cl_uint)1, &strings, &length, &error);
6309
6310 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6311
6312 if (error == CL_SUCCESS && build) {
6313 error = ::clBuildProgram(
6314 object_,
6315 0,
6316 nullptr,
6317#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6318 "-cl-std=CL2.0",
6319#else
6320 "",
6321#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6322 nullptr,
6323 nullptr);
6324
6325 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6326 }
6327
6328 if (err != nullptr) {
6329 *err = error;
6330 }
6331 }
6332
6337 Program(
6338 const Sources& sources,
6339 cl_int* err = nullptr)
6340 {
6341 cl_int error;
6342 Context context = Context::getDefault(err);
6343
6344 const size_type n = (size_type)sources.size();
6345
6346 vector<size_type> lengths(n);
6347 vector<const char*> strings(n);
6348
6349 for (size_type i = 0; i < n; ++i) {
6350#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6351 strings[i] = sources[(int)i].data();
6352 lengths[i] = sources[(int)i].length();
6353#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6354 strings[i] = sources[(int)i].first;
6355 lengths[i] = sources[(int)i].second;
6356#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6357 }
6358
6359 object_ = ::clCreateProgramWithSource(
6360 context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6361
6362 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6363 if (err != nullptr) {
6364 *err = error;
6365 }
6366 }
6367
6372 Program(
6373 const Context& context,
6374 const Sources& sources,
6375 cl_int* err = nullptr)
6376 {
6377 cl_int error;
6378
6379 const size_type n = (size_type)sources.size();
6380
6381 vector<size_type> lengths(n);
6382 vector<const char*> strings(n);
6383
6384 for (size_type i = 0; i < n; ++i) {
6385#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6386 strings[i] = sources[(int)i].data();
6387 lengths[i] = sources[(int)i].length();
6388#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6389 strings[i] = sources[(int)i].first;
6390 lengths[i] = sources[(int)i].second;
6391#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6392 }
6393
6394 object_ = ::clCreateProgramWithSource(
6395 context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6396
6397 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6398 if (err != nullptr) {
6399 *err = error;
6400 }
6401 }
6402
6403#if defined(CL_HPP_USE_IL_KHR) || CL_HPP_TARGET_OPENCL_VERSION >= 210
6409 Program(
6410 const vector<char>& IL,
6411 bool build = false,
6412 cl_int* err = nullptr)
6413 {
6414 cl_int error;
6415
6416 Context context = Context::getDefault(err);
6417
6418#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6419
6420 object_ = ::clCreateProgramWithIL(
6421 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6422
6423#else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6424
6425 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6426 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = nullptr;
6427 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6428
6429 object_ = pfn_clCreateProgramWithILKHR(
6430 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6431
6432#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6433
6434 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6435
6436 if (error == CL_SUCCESS && build) {
6437
6438 error = ::clBuildProgram(
6439 object_,
6440 0,
6441 nullptr,
6442#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6443 "-cl-std=CL2.0",
6444#else
6445 "",
6446#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6447 nullptr,
6448 nullptr);
6449
6450 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6451 }
6452
6453 if (err != nullptr) {
6454 *err = error;
6455 }
6456 }
6457
6464 Program(
6465 const Context& context,
6466 const vector<char>& IL,
6467 bool build = false,
6468 cl_int* err = nullptr)
6469 {
6470 cl_int error;
6471
6472#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6473
6474 object_ = ::clCreateProgramWithIL(
6475 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6476
6477#else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6478
6479 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6480 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = nullptr;
6481 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6482
6483 object_ = pfn_clCreateProgramWithILKHR(
6484 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6485
6486#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6487
6488 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6489
6490 if (error == CL_SUCCESS && build) {
6491 error = ::clBuildProgram(
6492 object_,
6493 0,
6494 nullptr,
6495#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6496 "-cl-std=CL2.0",
6497#else
6498 "",
6499#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6500 nullptr,
6501 nullptr);
6502
6503 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6504 }
6505
6506 if (err != nullptr) {
6507 *err = error;
6508 }
6509 }
6510#endif // defined(CL_HPP_USE_IL_KHR) || CL_HPP_TARGET_OPENCL_VERSION >= 210
6511
6531 Program(
6532 const Context& context,
6533 const vector<Device>& devices,
6534 const Binaries& binaries,
6535 vector<cl_int>* binaryStatus = nullptr,
6536 cl_int* err = nullptr)
6537 {
6538 cl_int error;
6539
6540 const size_type numDevices = devices.size();
6541
6542 // Catch size mismatch early and return
6543 if(binaries.size() != numDevices) {
6544 error = CL_INVALID_VALUE;
6545 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6546 if (err != nullptr) {
6547 *err = error;
6548 }
6549 return;
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 != nullptr && numDevices > 0)
6579 ? &binaryStatus->front()
6580 : nullptr, &error);
6581
6582 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6583 if (err != nullptr) {
6584 *err = error;
6585 }
6586 }
6587
6588
6589#if CL_HPP_TARGET_OPENCL_VERSION >= 120
6594 Program(
6595 const Context& context,
6596 const vector<Device>& devices,
6597 const string& kernelNames,
6598 cl_int* err = nullptr)
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 != nullptr) {
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
6641 cl_int build(
6642 const vector<Device>& devices,
6643 const string& options,
6644 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
6645 void* data = nullptr) const
6646 {
6647 return build(devices, options.c_str(), notifyFptr, data);
6648 }
6649
6650 cl_int build(
6651 const vector<Device>& devices,
6652 const char* options = nullptr,
6653 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
6654 void* data = nullptr) const
6655 {
6656 size_type numDevices = devices.size();
6657 vector<cl_device_id> deviceIDs(numDevices);
6658
6659 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6660 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6661 }
6662
6663 cl_int buildError = ::clBuildProgram(
6664 object_,
6665 (cl_uint)
6666 devices.size(),
6667 deviceIDs.data(),
6668 options,
6669 notifyFptr,
6670 data);
6671
6672 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6673 }
6674
6675 cl_int build(
6676 const Device& device,
6677 const string& options,
6678 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
6679 void* data = nullptr) const
6680 {
6681 return build(device, options.c_str(), notifyFptr, data);
6682 }
6683
6684 cl_int build(
6685 const Device& device,
6686 const char* options = nullptr,
6687 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
6688 void* data = nullptr) const
6689 {
6690 cl_device_id deviceID = device();
6691
6692 cl_int buildError = ::clBuildProgram(
6693 object_,
6694 1,
6695 &deviceID,
6696 options,
6697 notifyFptr,
6698 data);
6699
6700 BuildLogType buildLog(0);
6701 buildLog.push_back(std::make_pair(device, getBuildInfo<CL_PROGRAM_BUILD_LOG>(device)));
6702 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, buildLog);
6703 }
6704
6705 cl_int build(
6706 const string& options,
6707 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
6708 void* data = nullptr) const
6709 {
6710 return build(options.c_str(), notifyFptr, data);
6711 }
6712
6713 cl_int build(
6714 const char* options = nullptr,
6715 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
6716 void* data = nullptr) const
6717 {
6718 cl_int buildError = ::clBuildProgram(
6719 object_,
6720 0,
6721 nullptr,
6722 options,
6723 notifyFptr,
6724 data);
6725
6726 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6727 }
6728
6729#if CL_HPP_TARGET_OPENCL_VERSION >= 120
6730 cl_int compile(
6731 const string& options,
6732 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
6733 void* data = nullptr) const
6734 {
6735 return compile(options.c_str(), notifyFptr, data);
6736 }
6737
6738 cl_int compile(
6739 const char* options = nullptr,
6740 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
6741 void* data = nullptr) const
6742 {
6743 cl_int error = ::clCompileProgram(
6744 object_,
6745 0,
6746 nullptr,
6747 options,
6748 0,
6749 nullptr,
6750 nullptr,
6751 notifyFptr,
6752 data);
6753 return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6754 }
6755
6756 cl_int compile(
6757 const string& options,
6758 const vector<Program>& inputHeaders,
6759 const vector<string>& headerIncludeNames,
6760 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
6761 void* data = nullptr) const
6762 {
6763 return compile(options.c_str(), inputHeaders, headerIncludeNames, notifyFptr, data);
6764 }
6765
6766 cl_int compile(
6767 const char* options,
6768 const vector<Program>& inputHeaders,
6769 const vector<string>& headerIncludeNames,
6770 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
6771 void* data = nullptr) const
6772 {
6773 static_assert(sizeof(cl::Program) == sizeof(cl_program),
6774 "Size of cl::Program must be equal to size of cl_program");
6775 vector<const char*> headerIncludeNamesCStr;
6776 for(const string& name: headerIncludeNames) {
6777 headerIncludeNamesCStr.push_back(name.c_str());
6778 }
6779 cl_int error = ::clCompileProgram(
6780 object_,
6781 0,
6782 nullptr,
6783 options,
6784 static_cast<cl_uint>(inputHeaders.size()),
6785 reinterpret_cast<const cl_program*>(inputHeaders.data()),
6786 reinterpret_cast<const char**>(headerIncludeNamesCStr.data()),
6787 notifyFptr,
6788 data);
6789 return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6790 }
6791
6792 cl_int compile(
6793 const string& options,
6794 const vector<Device>& deviceList,
6795 const vector<Program>& inputHeaders = vector<Program>(),
6796 const vector<string>& headerIncludeNames = vector<string>(),
6797 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
6798 void* data = nullptr) const
6799 {
6800 return compile(options.c_str(), deviceList, inputHeaders, headerIncludeNames, notifyFptr, data);
6801 }
6802
6803 cl_int compile(
6804 const char* options,
6805 const vector<Device>& deviceList,
6806 const vector<Program>& inputHeaders = vector<Program>(),
6807 const vector<string>& headerIncludeNames = vector<string>(),
6808 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
6809 void* data = nullptr) const
6810 {
6811 static_assert(sizeof(cl::Program) == sizeof(cl_program),
6812 "Size of cl::Program must be equal to size of cl_program");
6813 vector<const char*> headerIncludeNamesCStr;
6814 for(const string& name: headerIncludeNames) {
6815 headerIncludeNamesCStr.push_back(name.c_str());
6816 }
6817 vector<cl_device_id> deviceIDList;
6818 for(const Device& device: deviceList) {
6819 deviceIDList.push_back(device());
6820 }
6821 cl_int error = ::clCompileProgram(
6822 object_,
6823 static_cast<cl_uint>(deviceList.size()),
6824 reinterpret_cast<const cl_device_id*>(deviceIDList.data()),
6825 options,
6826 static_cast<cl_uint>(inputHeaders.size()),
6827 reinterpret_cast<const cl_program*>(inputHeaders.data()),
6828 reinterpret_cast<const char**>(headerIncludeNamesCStr.data()),
6829 notifyFptr,
6830 data);
6831 return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6832 }
6833#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6834
6835 template <typename T>
6836 cl_int getInfo(cl_program_info name, T* param) const
6837 {
6838 return detail::errHandler(
6839 detail::getInfo(&::clGetProgramInfo, object_, name, param),
6840 __GET_PROGRAM_INFO_ERR);
6841 }
6842
6843 template <cl_program_info name> typename
6845 getInfo(cl_int* err = nullptr) const
6846 {
6847 typename detail::param_traits<
6848 detail::cl_program_info, name>::param_type param;
6849 cl_int result = getInfo(name, &param);
6850 if (err != nullptr) {
6851 *err = result;
6852 }
6853 return param;
6854 }
6855
6856 template <typename T>
6857 cl_int getBuildInfo(
6858 const Device& device, cl_program_build_info name, T* param) const
6859 {
6860 return detail::errHandler(
6861 detail::getInfo(
6862 &::clGetProgramBuildInfo, object_, device(), name, param),
6863 __GET_PROGRAM_BUILD_INFO_ERR);
6864 }
6865
6866 template <cl_program_build_info name> typename
6868 getBuildInfo(const Device& device, cl_int* err = nullptr) const
6869 {
6870 typename detail::param_traits<
6871 detail::cl_program_build_info, name>::param_type param;
6872 cl_int result = getBuildInfo(device, name, &param);
6873 if (err != nullptr) {
6874 *err = result;
6875 }
6876 return param;
6877 }
6878
6884 template <cl_program_build_info name>
6885 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6886 getBuildInfo(cl_int *err = nullptr) const
6887 {
6888 cl_int result = CL_SUCCESS;
6889
6890 auto devs = getInfo<CL_PROGRAM_DEVICES>(&result);
6891 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6892 devInfo;
6893
6894 // If there was an initial error from getInfo return the error
6895 if (result != CL_SUCCESS) {
6896 if (err != nullptr) {
6897 *err = result;
6898 }
6899 return devInfo;
6900 }
6901
6902 for (const cl::Device &d : devs) {
6903 typename detail::param_traits<
6904 detail::cl_program_build_info, name>::param_type param;
6905 result = getBuildInfo(d, name, &param);
6906 devInfo.push_back(
6908 (d, param));
6909 if (result != CL_SUCCESS) {
6910 // On error, leave the loop and return the error code
6911 break;
6912 }
6913 }
6914 if (err != nullptr) {
6915 *err = result;
6916 }
6917 if (result != CL_SUCCESS) {
6918 devInfo.clear();
6919 }
6920 return devInfo;
6921 }
6922
6923 cl_int createKernels(vector<Kernel>* kernels)
6924 {
6925 cl_uint numKernels;
6926 cl_int err = ::clCreateKernelsInProgram(object_, 0, nullptr, &numKernels);
6927 if (err != CL_SUCCESS) {
6928 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6929 }
6930
6931 vector<cl_kernel> value(numKernels);
6932
6933 err = ::clCreateKernelsInProgram(
6934 object_, numKernels, value.data(), nullptr);
6935 if (err != CL_SUCCESS) {
6936 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6937 }
6938
6939 if (kernels) {
6940 kernels->resize(value.size());
6941
6942 // Assign to param, constructing with retain behaviour
6943 // to correctly capture each underlying CL object
6944 for (size_type i = 0; i < value.size(); i++) {
6945 // We do not need to retain because this kernel is being created
6946 // by the runtime
6947 (*kernels)[i] = Kernel(value[i], false);
6948 }
6949 }
6950 return CL_SUCCESS;
6951 }
6952
6953#if CL_HPP_TARGET_OPENCL_VERSION >= 220
6954#if defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
6965 CL_API_PREFIX__VERSION_2_2_DEPRECATED cl_int setReleaseCallback(
6966 void (CL_CALLBACK * pfn_notify)(cl_program program, void * user_data),
6967 void * user_data = nullptr) CL_API_SUFFIX__VERSION_2_2_DEPRECATED
6968 {
6969 return detail::errHandler(
6970 ::clSetProgramReleaseCallback(
6971 object_,
6972 pfn_notify,
6973 user_data),
6974 __SET_PROGRAM_RELEASE_CALLBACK_ERR);
6975 }
6976#endif // #if defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
6977
6982 template <typename T>
6983 typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6984 setSpecializationConstant(cl_uint index, const T &value)
6985 {
6986 return detail::errHandler(
6987 ::clSetProgramSpecializationConstant(
6988 object_,
6989 index,
6990 sizeof(value),
6991 &value),
6992 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6993 }
6994
6999 cl_int setSpecializationConstant(cl_uint index, size_type size, const void* value)
7000 {
7001 return detail::errHandler(
7002 ::clSetProgramSpecializationConstant(
7003 object_,
7004 index,
7005 size,
7006 value),
7007 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
7008 }
7009#endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
7010};
7011
7012#if CL_HPP_TARGET_OPENCL_VERSION >= 120
7013inline Program linkProgram(
7014 const Program& input1,
7015 const Program& input2,
7016 const char* options = nullptr,
7017 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7018 void* data = nullptr,
7019 cl_int* err = nullptr)
7020{
7021 cl_int error_local = CL_SUCCESS;
7022 cl_program programs[2] = { input1(), input2() };
7023
7024 Context ctx = input1.getInfo<CL_PROGRAM_CONTEXT>(&error_local);
7025 if(error_local!=CL_SUCCESS) {
7026 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
7027 }
7028
7029 cl_program prog = ::clLinkProgram(
7030 ctx(),
7031 0,
7032 nullptr,
7033 options,
7034 2,
7035 programs,
7036 notifyFptr,
7037 data,
7038 &error_local);
7039
7040 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
7041 if (err != nullptr) {
7042 *err = error_local;
7043 }
7044
7045 return Program(prog);
7046}
7047
7048inline Program linkProgram(
7049 const Program& input1,
7050 const Program& input2,
7051 const string& options,
7052 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7053 void* data = nullptr,
7054 cl_int* err = nullptr)
7055{
7056 return linkProgram(input1, input2, options.c_str(), notifyFptr, data, err);
7057}
7058
7059inline Program linkProgram(
7060 const vector<Program>& inputPrograms,
7061 const char* options = nullptr,
7062 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7063 void* data = nullptr,
7064 cl_int* err = nullptr)
7065{
7066 cl_int error_local = CL_SUCCESS;
7067 Context ctx;
7068
7069 static_assert(sizeof(cl::Program) == sizeof(cl_program),
7070 "Size of cl::Program must be equal to size of cl_program");
7071
7072 if(inputPrograms.size() > 0) {
7073 ctx = inputPrograms[0].getInfo<CL_PROGRAM_CONTEXT>(&error_local);
7074 if(error_local!=CL_SUCCESS) {
7075 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
7076 }
7077 }
7078
7079 cl_program prog = ::clLinkProgram(
7080 ctx(),
7081 0,
7082 nullptr,
7083 options,
7084 static_cast<cl_uint>(inputPrograms.size()),
7085 reinterpret_cast<const cl_program *>(inputPrograms.data()),
7086 notifyFptr,
7087 data,
7088 &error_local);
7089
7090 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
7091 if (err != nullptr) {
7092 *err = error_local;
7093 }
7094
7095 return Program(prog);
7096}
7097
7098inline Program linkProgram(
7099 const vector<Program>& inputPrograms,
7100 const string& options,
7101 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7102 void* data = nullptr,
7103 cl_int* err = nullptr)
7104{
7105 return linkProgram(inputPrograms, options.c_str(), notifyFptr, data, err);
7106}
7107#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7108
7109// Template specialization for CL_PROGRAM_BINARIES
7110template <>
7111inline cl_int cl::Program::getInfo(cl_program_info name, vector<vector<unsigned char>>* param) const
7112{
7113 if (name != CL_PROGRAM_BINARIES) {
7114 return CL_INVALID_VALUE;
7115 }
7116 if (param) {
7117 // Resize the parameter array appropriately for each allocation
7118 // and pass down to the helper
7119
7120 vector<size_type> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>();
7121 size_type numBinaries = sizes.size();
7122
7123 // Resize the parameter array and constituent arrays
7124 param->resize(numBinaries);
7125 for (size_type i = 0; i < numBinaries; ++i) {
7126 (*param)[i].resize(sizes[i]);
7127 }
7128
7129 return detail::errHandler(
7130 detail::getInfo(&::clGetProgramInfo, object_, name, param),
7131 __GET_PROGRAM_INFO_ERR);
7132 }
7133
7134 return CL_SUCCESS;
7135}
7136
7137template<>
7138inline vector<vector<unsigned char>> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err) const
7139{
7140 vector<vector<unsigned char>> binariesVectors;
7141
7142 cl_int result = getInfo(CL_PROGRAM_BINARIES, &binariesVectors);
7143 if (err != nullptr) {
7144 *err = result;
7145 }
7146 return binariesVectors;
7147}
7148
7149#if CL_HPP_TARGET_OPENCL_VERSION >= 220
7150// Template specialization for clSetProgramSpecializationConstant
7151template <>
7152inline cl_int cl::Program::setSpecializationConstant(cl_uint index, const bool &value)
7153{
7154 cl_uchar ucValue = value ? CL_UCHAR_MAX : 0;
7155 return detail::errHandler(
7156 ::clSetProgramSpecializationConstant(
7157 object_,
7158 index,
7159 sizeof(ucValue),
7160 &ucValue),
7161 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
7162}
7163#endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
7164
7165inline Kernel::Kernel(const Program& program, const string& name, cl_int* err)
7166{
7167 cl_int error;
7168
7169 object_ = ::clCreateKernel(program(), name.c_str(), &error);
7170 detail::errHandler(error, __CREATE_KERNEL_ERR);
7171
7172 if (err != nullptr) {
7173 *err = error;
7174 }
7175}
7176
7177inline Kernel::Kernel(const Program& program, const char* name, cl_int* err)
7178{
7179 cl_int error;
7180
7181 object_ = ::clCreateKernel(program(), name, &error);
7182 detail::errHandler(error, __CREATE_KERNEL_ERR);
7183
7184 if (err != nullptr) {
7185 *err = error;
7186 }
7187}
7188
7189#ifdef cl_khr_external_memory
7190enum class ExternalMemoryType : cl_external_memory_handle_type_khr
7191{
7192 None = 0,
7193
7194 OpaqueFd = CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR,
7195 OpaqueWin32 = CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR,
7196 OpaqueWin32Kmt = CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR,
7197
7198 D3D11Texture = CL_EXTERNAL_MEMORY_HANDLE_D3D11_TEXTURE_KHR,
7199 D3D11TextureKmt = CL_EXTERNAL_MEMORY_HANDLE_D3D11_TEXTURE_KMT_KHR,
7200
7201 D3D12Heap = CL_EXTERNAL_MEMORY_HANDLE_D3D12_HEAP_KHR,
7202 D3D12Resource = CL_EXTERNAL_MEMORY_HANDLE_D3D12_RESOURCE_KHR,
7203
7204 DmaBuf = CL_EXTERNAL_MEMORY_HANDLE_DMA_BUF_KHR,
7205};
7206#endif
7207
7208enum class QueueProperties : cl_command_queue_properties
7209{
7210 None = 0,
7211 Profiling = CL_QUEUE_PROFILING_ENABLE,
7212 OutOfOrder = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,
7213};
7214
7215inline QueueProperties operator|(QueueProperties lhs, QueueProperties rhs)
7216{
7217 return static_cast<QueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
7218}
7219
7220inline QueueProperties operator&(QueueProperties lhs, QueueProperties rhs)
7221{
7222 return static_cast<QueueProperties>(static_cast<cl_command_queue_properties>(lhs) & static_cast<cl_command_queue_properties>(rhs));
7223}
7228class CommandQueue : public detail::Wrapper<cl_command_queue>
7229{
7230private:
7231 static std::once_flag default_initialized_;
7232 static CommandQueue default_;
7233 static cl_int default_error_;
7234
7240 static void makeDefault()
7241 {
7242 /* We don't want to throw an error from this function, so we have to
7243 * catch and set the error flag.
7244 */
7245#if defined(CL_HPP_ENABLE_EXCEPTIONS)
7246 try
7247#endif
7248 {
7249 int error;
7250 Context context = Context::getDefault(&error);
7251
7252 if (error != CL_SUCCESS) {
7253 default_error_ = error;
7254 }
7255 else {
7256 Device device = Device::getDefault();
7257 default_ = CommandQueue(context, device, 0, &default_error_);
7258 }
7259 }
7260#if defined(CL_HPP_ENABLE_EXCEPTIONS)
7261 catch (cl::Error &e) {
7262 default_error_ = e.err();
7263 }
7264#endif
7265 }
7266
7272 static void makeDefaultProvided(const CommandQueue &c) {
7273 default_ = c;
7274 }
7275
7276#ifdef cl_khr_external_memory
7277 static std::once_flag ext_memory_initialized_;
7278
7279 static void initMemoryExtension(const cl::Device& device)
7280 {
7281 auto platform = device.getInfo<CL_DEVICE_PLATFORM>()();
7282
7283 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireExternalMemObjectsKHR);
7284 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseExternalMemObjectsKHR);
7285
7286 if ((pfn_clEnqueueAcquireExternalMemObjectsKHR == nullptr)
7287 && (pfn_clEnqueueReleaseExternalMemObjectsKHR == nullptr))
7288 {
7289 detail::errHandler(CL_INVALID_VALUE, __ENQUEUE_ACQUIRE_EXTERNAL_MEMORY_ERR);
7290 }
7291 }
7292#endif // cl_khr_external_memory
7293
7294public:
7295#ifdef CL_HPP_UNIT_TEST_ENABLE
7302 static void unitTestClearDefault() {
7303 default_ = CommandQueue();
7304 }
7305#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
7306
7307
7313 cl_command_queue_properties properties,
7314 cl_int* err = nullptr)
7315 {
7316 cl_int error;
7317
7318 Context context = Context::getDefault(&error);
7319 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7320
7321 if (error != CL_SUCCESS) {
7322 if (err != nullptr) {
7323 *err = error;
7324 }
7325 }
7326 else {
7327 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7328 bool useWithProperties;
7329
7330#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7331 // Run-time decision based on the actual platform
7332 {
7333 cl_uint version = detail::getContextPlatformVersion(context());
7334 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7335 }
7336#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7337 useWithProperties = true;
7338#else
7339 useWithProperties = false;
7340#endif
7341
7342#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7343 if (useWithProperties) {
7344 cl_queue_properties queue_properties[] = {
7345 CL_QUEUE_PROPERTIES, properties, 0 };
7346 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7347 object_ = ::clCreateCommandQueueWithProperties(
7348 context(), device(), queue_properties, &error);
7349 }
7350 else {
7351 error = CL_INVALID_QUEUE_PROPERTIES;
7352 }
7353
7354 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7355 if (err != nullptr) {
7356 *err = error;
7357 }
7358 }
7359#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7360#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7361 if (!useWithProperties) {
7362 object_ = ::clCreateCommandQueue(
7363 context(), device(), properties, &error);
7364
7365 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7366 if (err != nullptr) {
7367 *err = error;
7368 }
7369 }
7370#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7371 }
7372 }
7373
7379 QueueProperties properties,
7380 cl_int* err = nullptr)
7381 {
7382 cl_int error;
7383
7384 Context context = Context::getDefault(&error);
7385 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7386
7387 if (error != CL_SUCCESS) {
7388 if (err != nullptr) {
7389 *err = error;
7390 }
7391 }
7392 else {
7393 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7394 bool useWithProperties;
7395
7396#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7397 // Run-time decision based on the actual platform
7398 {
7399 cl_uint version = detail::getContextPlatformVersion(context());
7400 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7401 }
7402#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7403 useWithProperties = true;
7404#else
7405 useWithProperties = false;
7406#endif
7407
7408#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7409 if (useWithProperties) {
7410 cl_queue_properties queue_properties[] = {
7411 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7412
7413 object_ = ::clCreateCommandQueueWithProperties(
7414 context(), device(), queue_properties, &error);
7415
7416 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7417 if (err != nullptr) {
7418 *err = error;
7419 }
7420 }
7421#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7422#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7423 if (!useWithProperties) {
7424 object_ = ::clCreateCommandQueue(
7425 context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
7426
7427 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7428 if (err != nullptr) {
7429 *err = error;
7430 }
7431 }
7432#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7433
7434 }
7435 }
7436
7441 explicit CommandQueue(
7442 const Context& context,
7443 cl_command_queue_properties properties = 0,
7444 cl_int* err = nullptr)
7445 {
7446 cl_int error;
7447 bool useWithProperties;
7448 vector<cl::Device> devices;
7449 error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7450
7451 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7452
7453 if (error != CL_SUCCESS)
7454 {
7455 if (err != nullptr) {
7456 *err = error;
7457 }
7458 return;
7459 }
7460
7461#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7462 // Run-time decision based on the actual platform
7463 {
7464 cl_uint version = detail::getContextPlatformVersion(context());
7465 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7466 }
7467#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7468 useWithProperties = true;
7469#else
7470 useWithProperties = false;
7471#endif
7472
7473#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7474 if (useWithProperties) {
7475 cl_queue_properties queue_properties[] = {
7476 CL_QUEUE_PROPERTIES, properties, 0 };
7477 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7478 object_ = ::clCreateCommandQueueWithProperties(
7479 context(), devices[0](), queue_properties, &error);
7480 }
7481 else {
7482 error = CL_INVALID_QUEUE_PROPERTIES;
7483 }
7484
7485 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7486 if (err != nullptr) {
7487 *err = error;
7488 }
7489 }
7490#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7491#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7492 if (!useWithProperties) {
7493 object_ = ::clCreateCommandQueue(
7494 context(), devices[0](), properties, &error);
7495
7496 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7497 if (err != nullptr) {
7498 *err = error;
7499 }
7500 }
7501#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7502 }
7503
7508 explicit CommandQueue(
7509 const Context& context,
7510 QueueProperties properties,
7511 cl_int* err = nullptr)
7512 {
7513 cl_int error;
7514 bool useWithProperties;
7515 vector<cl::Device> devices;
7516 error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7517
7518 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7519
7520 if (error != CL_SUCCESS)
7521 {
7522 if (err != nullptr) {
7523 *err = error;
7524 }
7525 return;
7526 }
7527
7528#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7529 // Run-time decision based on the actual platform
7530 {
7531 cl_uint version = detail::getContextPlatformVersion(context());
7532 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7533 }
7534#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7535 useWithProperties = true;
7536#else
7537 useWithProperties = false;
7538#endif
7539
7540#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7541 if (useWithProperties) {
7542 cl_queue_properties queue_properties[] = {
7543 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7544 object_ = ::clCreateCommandQueueWithProperties(
7545 context(), devices[0](), queue_properties, &error);
7546
7547 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7548 if (err != nullptr) {
7549 *err = error;
7550 }
7551 }
7552#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7553#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7554 if (!useWithProperties) {
7555 object_ = ::clCreateCommandQueue(
7556 context(), devices[0](), static_cast<cl_command_queue_properties>(properties), &error);
7557
7558 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7559 if (err != nullptr) {
7560 *err = error;
7561 }
7562 }
7563#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7564 }
7565
7571 const Context& context,
7572 const Device& device,
7573 cl_command_queue_properties properties = 0,
7574 cl_int* err = nullptr)
7575 {
7576 cl_int error;
7577 bool useWithProperties;
7578
7579#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7580 // Run-time decision based on the actual platform
7581 {
7582 cl_uint version = detail::getContextPlatformVersion(context());
7583 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7584 }
7585#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7586 useWithProperties = true;
7587#else
7588 useWithProperties = false;
7589#endif
7590
7591#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7592 if (useWithProperties) {
7593 cl_queue_properties queue_properties[] = {
7594 CL_QUEUE_PROPERTIES, properties, 0 };
7595 object_ = ::clCreateCommandQueueWithProperties(
7596 context(), device(), queue_properties, &error);
7597
7598 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7599 if (err != nullptr) {
7600 *err = error;
7601 }
7602 }
7603#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7604#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7605 if (!useWithProperties) {
7606 object_ = ::clCreateCommandQueue(
7607 context(), device(), properties, &error);
7608
7609 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7610 if (err != nullptr) {
7611 *err = error;
7612 }
7613 }
7614#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7615 }
7616
7622 const Context& context,
7623 const Device& device,
7624 QueueProperties properties,
7625 cl_int* err = nullptr)
7626 {
7627 cl_int error;
7628 bool useWithProperties;
7629
7630#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7631 // Run-time decision based on the actual platform
7632 {
7633 cl_uint version = detail::getContextPlatformVersion(context());
7634 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7635 }
7636#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7637 useWithProperties = true;
7638#else
7639 useWithProperties = false;
7640#endif
7641
7642#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7643 if (useWithProperties) {
7644 cl_queue_properties queue_properties[] = {
7645 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7646 object_ = ::clCreateCommandQueueWithProperties(
7647 context(), device(), queue_properties, &error);
7648
7649 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7650 if (err != nullptr) {
7651 *err = error;
7652 }
7653 }
7654#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7655#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7656 if (!useWithProperties) {
7657 object_ = ::clCreateCommandQueue(
7658 context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
7659
7660 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7661 if (err != nullptr) {
7662 *err = error;
7663 }
7664 }
7665#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7666 }
7667
7668 static CommandQueue getDefault(cl_int * err = nullptr)
7669 {
7670 std::call_once(default_initialized_, makeDefault);
7671#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7672 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7673#else // CL_HPP_TARGET_OPENCL_VERSION >= 200
7674 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_ERR);
7675#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7676 if (err != nullptr) {
7677 *err = default_error_;
7678 }
7679 return default_;
7680 }
7681
7689 static CommandQueue setDefault(const CommandQueue &default_queue)
7690 {
7691 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_queue));
7692 detail::errHandler(default_error_);
7693 return default_;
7694 }
7695
7696 CommandQueue() { }
7697
7698
7705 explicit CommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
7706 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
7707
7708 CommandQueue& operator = (const cl_command_queue& rhs)
7709 {
7711 return *this;
7712 }
7713
7714 template <typename T>
7715 cl_int getInfo(cl_command_queue_info name, T* param) const
7716 {
7717 return detail::errHandler(
7718 detail::getInfo(
7719 &::clGetCommandQueueInfo, object_, name, param),
7720 __GET_COMMAND_QUEUE_INFO_ERR);
7721 }
7722
7723 template <cl_command_queue_info name> typename
7725 getInfo(cl_int* err = nullptr) const
7726 {
7727 typename detail::param_traits<
7728 detail::cl_command_queue_info, name>::param_type param;
7729 cl_int result = getInfo(name, &param);
7730 if (err != nullptr) {
7731 *err = result;
7732 }
7733 return param;
7734 }
7735
7736 cl_int enqueueReadBuffer(
7737 const Buffer& buffer,
7738 cl_bool blocking,
7739 size_type offset,
7740 size_type size,
7741 void* ptr,
7742 const vector<Event>* events = nullptr,
7743 Event* event = nullptr) const
7744 {
7745 cl_event tmp;
7746 cl_int err = detail::errHandler(
7747 ::clEnqueueReadBuffer(
7748 object_, buffer(), blocking, offset, size,
7749 ptr,
7750 (events != nullptr) ? (cl_uint) events->size() : 0,
7751 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
7752 (event != nullptr) ? &tmp : nullptr),
7753 __ENQUEUE_READ_BUFFER_ERR);
7754
7755 if (event != nullptr && err == CL_SUCCESS)
7756 *event = tmp;
7757
7758 return err;
7759 }
7760
7761 cl_int enqueueWriteBuffer(
7762 const Buffer& buffer,
7763 cl_bool blocking,
7764 size_type offset,
7765 size_type size,
7766 const void* ptr,
7767 const vector<Event>* events = nullptr,
7768 Event* event = nullptr) const
7769 {
7770 cl_event tmp;
7771 cl_int err = detail::errHandler(
7772 ::clEnqueueWriteBuffer(
7773 object_, buffer(), blocking, offset, size,
7774 ptr,
7775 (events != nullptr) ? (cl_uint) events->size() : 0,
7776 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
7777 (event != nullptr) ? &tmp : nullptr),
7778 __ENQUEUE_WRITE_BUFFER_ERR);
7779
7780 if (event != nullptr && err == CL_SUCCESS)
7781 *event = tmp;
7782
7783 return err;
7784 }
7785
7786 cl_int enqueueCopyBuffer(
7787 const Buffer& src,
7788 const Buffer& dst,
7789 size_type src_offset,
7790 size_type dst_offset,
7791 size_type size,
7792 const vector<Event>* events = nullptr,
7793 Event* event = nullptr) const
7794 {
7795 cl_event tmp;
7796 cl_int err = detail::errHandler(
7797 ::clEnqueueCopyBuffer(
7798 object_, src(), dst(), src_offset, dst_offset, size,
7799 (events != nullptr) ? (cl_uint) events->size() : 0,
7800 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
7801 (event != nullptr) ? &tmp : nullptr),
7802 __ENQEUE_COPY_BUFFER_ERR);
7803
7804 if (event != nullptr && err == CL_SUCCESS)
7805 *event = tmp;
7806
7807 return err;
7808 }
7809#if CL_HPP_TARGET_OPENCL_VERSION >= 110
7810 cl_int enqueueReadBufferRect(
7811 const Buffer& buffer,
7812 cl_bool blocking,
7813 const array<size_type, 3>& buffer_offset,
7814 const array<size_type, 3>& host_offset,
7815 const array<size_type, 3>& region,
7816 size_type buffer_row_pitch,
7817 size_type buffer_slice_pitch,
7818 size_type host_row_pitch,
7819 size_type host_slice_pitch,
7820 void *ptr,
7821 const vector<Event>* events = nullptr,
7822 Event* event = nullptr) const
7823 {
7824 cl_event tmp;
7825 cl_int err = detail::errHandler(
7826 ::clEnqueueReadBufferRect(
7827 object_,
7828 buffer(),
7829 blocking,
7830 buffer_offset.data(),
7831 host_offset.data(),
7832 region.data(),
7833 buffer_row_pitch,
7834 buffer_slice_pitch,
7835 host_row_pitch,
7836 host_slice_pitch,
7837 ptr,
7838 (events != nullptr) ? (cl_uint) events->size() : 0,
7839 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
7840 (event != nullptr) ? &tmp : nullptr),
7841 __ENQUEUE_READ_BUFFER_RECT_ERR);
7842
7843 if (event != nullptr && err == CL_SUCCESS)
7844 *event = tmp;
7845
7846 return err;
7847 }
7848
7849 cl_int enqueueReadBufferRect(
7850 const Buffer& buffer,
7851 cl_bool blocking,
7852 const array<size_type, 2>& buffer_offset,
7853 const array<size_type, 2>& host_offset,
7854 const array<size_type, 2>& region,
7855 size_type buffer_row_pitch,
7856 size_type buffer_slice_pitch,
7857 size_type host_row_pitch,
7858 size_type host_slice_pitch,
7859 void* ptr,
7860 const vector<Event>* events = nullptr,
7861 Event* event = nullptr) const
7862 {
7863 return enqueueReadBufferRect(
7864 buffer,
7865 blocking,
7866 { buffer_offset[0], buffer_offset[1], 0 },
7867 { host_offset[0], host_offset[1], 0 },
7868 { region[0], region[1], 1 },
7869 buffer_row_pitch,
7870 buffer_slice_pitch,
7871 host_row_pitch,
7872 host_slice_pitch,
7873 ptr,
7874 events,
7875 event);
7876 }
7877
7878 cl_int enqueueWriteBufferRect(
7879 const Buffer& buffer,
7880 cl_bool blocking,
7881 const array<size_type, 3>& buffer_offset,
7882 const array<size_type, 3>& host_offset,
7883 const array<size_type, 3>& region,
7884 size_type buffer_row_pitch,
7885 size_type buffer_slice_pitch,
7886 size_type host_row_pitch,
7887 size_type host_slice_pitch,
7888 const void *ptr,
7889 const vector<Event>* events = nullptr,
7890 Event* event = nullptr) const
7891 {
7892 cl_event tmp;
7893 cl_int err = detail::errHandler(
7894 ::clEnqueueWriteBufferRect(
7895 object_,
7896 buffer(),
7897 blocking,
7898 buffer_offset.data(),
7899 host_offset.data(),
7900 region.data(),
7901 buffer_row_pitch,
7902 buffer_slice_pitch,
7903 host_row_pitch,
7904 host_slice_pitch,
7905 ptr,
7906 (events != nullptr) ? (cl_uint) events->size() : 0,
7907 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
7908 (event != nullptr) ? &tmp : nullptr),
7909 __ENQUEUE_WRITE_BUFFER_RECT_ERR);
7910
7911 if (event != nullptr && err == CL_SUCCESS)
7912 *event = tmp;
7913
7914 return err;
7915 }
7916
7917 cl_int enqueueWriteBufferRect(
7918 const Buffer& buffer,
7919 cl_bool blocking,
7920 const array<size_type, 2>& buffer_offset,
7921 const array<size_type, 2>& host_offset,
7922 const array<size_type, 2>& region,
7923 size_type buffer_row_pitch,
7924 size_type buffer_slice_pitch,
7925 size_type host_row_pitch,
7926 size_type host_slice_pitch,
7927 const void* ptr,
7928 const vector<Event>* events = nullptr,
7929 Event* event = nullptr) const
7930 {
7931 return enqueueWriteBufferRect(
7932 buffer,
7933 blocking,
7934 { buffer_offset[0], buffer_offset[1], 0 },
7935 { host_offset[0], host_offset[1], 0 },
7936 { region[0], region[1], 1 },
7937 buffer_row_pitch,
7938 buffer_slice_pitch,
7939 host_row_pitch,
7940 host_slice_pitch,
7941 ptr,
7942 events,
7943 event);
7944 }
7945
7946 cl_int enqueueCopyBufferRect(
7947 const Buffer& src,
7948 const Buffer& dst,
7949 const array<size_type, 3>& src_origin,
7950 const array<size_type, 3>& dst_origin,
7951 const array<size_type, 3>& region,
7952 size_type src_row_pitch,
7953 size_type src_slice_pitch,
7954 size_type dst_row_pitch,
7955 size_type dst_slice_pitch,
7956 const vector<Event>* events = nullptr,
7957 Event* event = nullptr) const
7958 {
7959 cl_event tmp;
7960 cl_int err = detail::errHandler(
7961 ::clEnqueueCopyBufferRect(
7962 object_,
7963 src(),
7964 dst(),
7965 src_origin.data(),
7966 dst_origin.data(),
7967 region.data(),
7968 src_row_pitch,
7969 src_slice_pitch,
7970 dst_row_pitch,
7971 dst_slice_pitch,
7972 (events != nullptr) ? (cl_uint) events->size() : 0,
7973 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
7974 (event != nullptr) ? &tmp : nullptr),
7975 __ENQEUE_COPY_BUFFER_RECT_ERR);
7976
7977 if (event != nullptr && err == CL_SUCCESS)
7978 *event = tmp;
7979
7980 return err;
7981 }
7982
7983 cl_int enqueueCopyBufferRect(
7984 const Buffer& src,
7985 const Buffer& dst,
7986 const array<size_type, 2>& src_origin,
7987 const array<size_type, 2>& dst_origin,
7988 const array<size_type, 2>& region,
7989 size_type src_row_pitch,
7990 size_type src_slice_pitch,
7991 size_type dst_row_pitch,
7992 size_type dst_slice_pitch,
7993 const vector<Event>* events = nullptr,
7994 Event* event = nullptr) const
7995 {
7996 return enqueueCopyBufferRect(
7997 src,
7998 dst,
7999 { src_origin[0], src_origin[1], 0 },
8000 { dst_origin[0], dst_origin[1], 0 },
8001 { region[0], region[1], 1 },
8002 src_row_pitch,
8003 src_slice_pitch,
8004 dst_row_pitch,
8005 dst_slice_pitch,
8006 events,
8007 event);
8008 }
8009
8010#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
8011#if CL_HPP_TARGET_OPENCL_VERSION >= 120
8023 template<typename PatternType>
8024 cl_int enqueueFillBuffer(
8025 const Buffer& buffer,
8026 PatternType pattern,
8027 size_type offset,
8028 size_type size,
8029 const vector<Event>* events = nullptr,
8030 Event* event = nullptr) const
8031 {
8032 cl_event tmp;
8033 cl_int err = detail::errHandler(
8034 ::clEnqueueFillBuffer(
8035 object_,
8036 buffer(),
8037 static_cast<void*>(&pattern),
8038 sizeof(PatternType),
8039 offset,
8040 size,
8041 (events != nullptr) ? (cl_uint) events->size() : 0,
8042 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8043 (event != nullptr) ? &tmp : nullptr),
8044 __ENQUEUE_FILL_BUFFER_ERR);
8045
8046 if (event != nullptr && err == CL_SUCCESS)
8047 *event = tmp;
8048
8049 return err;
8050 }
8051#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8052
8053 cl_int enqueueReadImage(
8054 const Image& image,
8055 cl_bool blocking,
8056 const array<size_type, 3>& origin,
8057 const array<size_type, 3>& region,
8058 size_type row_pitch,
8059 size_type slice_pitch,
8060 void* ptr,
8061 const vector<Event>* events = nullptr,
8062 Event* event = nullptr) const
8063 {
8064 cl_event tmp;
8065 cl_int err = detail::errHandler(
8066 ::clEnqueueReadImage(
8067 object_,
8068 image(),
8069 blocking,
8070 origin.data(),
8071 region.data(),
8072 row_pitch,
8073 slice_pitch,
8074 ptr,
8075 (events != nullptr) ? (cl_uint) events->size() : 0,
8076 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8077 (event != nullptr) ? &tmp : nullptr),
8078 __ENQUEUE_READ_IMAGE_ERR);
8079
8080 if (event != nullptr && err == CL_SUCCESS)
8081 *event = tmp;
8082
8083 return err;
8084 }
8085
8086 cl_int enqueueReadImage(
8087 const Image& image,
8088 cl_bool blocking,
8089 const array<size_type, 2>& origin,
8090 const array<size_type, 2>& region,
8091 size_type row_pitch,
8092 size_type slice_pitch,
8093 void* ptr,
8094 const vector<Event>* events = nullptr,
8095 Event* event = nullptr) const
8096 {
8097 return enqueueReadImage(
8098 image,
8099 blocking,
8100 { origin[0], origin[1], 0 },
8101 { region[0], region[1], 1 },
8102 row_pitch,
8103 slice_pitch,
8104 ptr,
8105 events,
8106 event);
8107 }
8108
8109 cl_int enqueueWriteImage(
8110 const Image& image,
8111 cl_bool blocking,
8112 const array<size_type, 3>& origin,
8113 const array<size_type, 3>& region,
8114 size_type row_pitch,
8115 size_type slice_pitch,
8116 const void* ptr,
8117 const vector<Event>* events = nullptr,
8118 Event* event = nullptr) const
8119 {
8120 cl_event tmp;
8121 cl_int err = detail::errHandler(
8122 ::clEnqueueWriteImage(
8123 object_,
8124 image(),
8125 blocking,
8126 origin.data(),
8127 region.data(),
8128 row_pitch,
8129 slice_pitch,
8130 ptr,
8131 (events != nullptr) ? (cl_uint) events->size() : 0,
8132 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8133 (event != nullptr) ? &tmp : nullptr),
8134 __ENQUEUE_WRITE_IMAGE_ERR);
8135
8136 if (event != nullptr && err == CL_SUCCESS)
8137 *event = tmp;
8138
8139 return err;
8140 }
8141
8142 cl_int enqueueWriteImage(
8143 const Image& image,
8144 cl_bool blocking,
8145 const array<size_type, 2>& origin,
8146 const array<size_type, 2>& region,
8147 size_type row_pitch,
8148 size_type slice_pitch,
8149 const void* ptr,
8150 const vector<Event>* events = nullptr,
8151 Event* event = nullptr) const
8152 {
8153 return enqueueWriteImage(
8154 image,
8155 blocking,
8156 { origin[0], origin[1], 0 },
8157 { region[0], region[1], 1 },
8158 row_pitch,
8159 slice_pitch,
8160 ptr,
8161 events,
8162 event);
8163 }
8164
8165 cl_int enqueueCopyImage(
8166 const Image& src,
8167 const Image& dst,
8168 const array<size_type, 3>& src_origin,
8169 const array<size_type, 3>& dst_origin,
8170 const array<size_type, 3>& region,
8171 const vector<Event>* events = nullptr,
8172 Event* event = nullptr) const
8173 {
8174 cl_event tmp;
8175 cl_int err = detail::errHandler(
8176 ::clEnqueueCopyImage(
8177 object_,
8178 src(),
8179 dst(),
8180 src_origin.data(),
8181 dst_origin.data(),
8182 region.data(),
8183 (events != nullptr) ? (cl_uint) events->size() : 0,
8184 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8185 (event != nullptr) ? &tmp : nullptr),
8186 __ENQUEUE_COPY_IMAGE_ERR);
8187
8188 if (event != nullptr && err == CL_SUCCESS)
8189 *event = tmp;
8190
8191 return err;
8192 }
8193
8194 cl_int enqueueCopyImage(
8195 const Image& src,
8196 const Image& dst,
8197 const array<size_type, 2>& src_origin,
8198 const array<size_type, 2>& dst_origin,
8199 const array<size_type, 2>& region,
8200 const vector<Event>* events = nullptr,
8201 Event* event = nullptr) const
8202 {
8203 return enqueueCopyImage(
8204 src,
8205 dst,
8206 { src_origin[0], src_origin[1], 0 },
8207 { dst_origin[0], dst_origin[1], 0 },
8208 { region[0], region[1], 1 },
8209 events,
8210 event);
8211 }
8212
8213#if CL_HPP_TARGET_OPENCL_VERSION >= 120
8221 template <typename T>
8222 typename std::enable_if<std::is_same<T, cl_float4>::value ||
8223 std::is_same<T, cl_int4 >::value ||
8224 std::is_same<T, cl_uint4 >::value,
8225 cl_int>::type
8227 const Image& image,
8228 T fillColor,
8229 const array<size_type, 3>& origin,
8230 const array<size_type, 3>& region,
8231 const vector<Event>* events = nullptr,
8232 Event* event = nullptr) const
8233 {
8234 cl_event tmp;
8235 cl_int err = detail::errHandler(
8236 ::clEnqueueFillImage(
8237 object_,
8238 image(),
8239 static_cast<void*>(&fillColor),
8240 origin.data(),
8241 region.data(),
8242 (events != nullptr) ? (cl_uint)events->size() : 0,
8243 (events != nullptr && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8244 (event != NULL) ? &tmp : nullptr),
8245 __ENQUEUE_FILL_IMAGE_ERR);
8246
8247 if (event != nullptr && err == CL_SUCCESS) *event = tmp;
8248
8249 return err;
8250 }
8251
8259 template <typename T>
8260 typename std::enable_if<std::is_same<T, cl_float4>::value ||
8261 std::is_same<T, cl_int4 >::value ||
8262 std::is_same<T, cl_uint4 >::value, cl_int>::type
8264 const Image& image,
8265 T fillColor,
8266 const array<size_type, 2>& origin,
8267 const array<size_type, 2>& region,
8268 const vector<Event>* events = nullptr,
8269 Event* event = nullptr) const
8270 {
8271 return enqueueFillImage(
8272 image,
8273 fillColor,
8274 { origin[0], origin[1], 0 },
8275 { region[0], region[1], 1 },
8276 events,
8277 event
8278 );
8279 }
8280#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8281
8282 cl_int enqueueCopyImageToBuffer(
8283 const Image& src,
8284 const Buffer& dst,
8285 const array<size_type, 3>& src_origin,
8286 const array<size_type, 3>& region,
8287 size_type dst_offset,
8288 const vector<Event>* events = nullptr,
8289 Event* event = nullptr) const
8290 {
8291 cl_event tmp;
8292 cl_int err = detail::errHandler(
8293 ::clEnqueueCopyImageToBuffer(
8294 object_,
8295 src(),
8296 dst(),
8297 src_origin.data(),
8298 region.data(),
8299 dst_offset,
8300 (events != nullptr) ? (cl_uint) events->size() : 0,
8301 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8302 (event != nullptr) ? &tmp : nullptr),
8303 __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
8304
8305 if (event != nullptr && err == CL_SUCCESS)
8306 *event = tmp;
8307
8308 return err;
8309 }
8310
8311 cl_int enqueueCopyImageToBuffer(
8312 const Image& src,
8313 const Buffer& dst,
8314 const array<size_type, 2>& src_origin,
8315 const array<size_type, 2>& region,
8316 size_type dst_offset,
8317 const vector<Event>* events = nullptr,
8318 Event* event = nullptr) const
8319 {
8320 return enqueueCopyImageToBuffer(
8321 src,
8322 dst,
8323 { src_origin[0], src_origin[1], 0 },
8324 { region[0], region[1], 1 },
8325 dst_offset,
8326 events,
8327 event);
8328 }
8329
8330 cl_int enqueueCopyBufferToImage(
8331 const Buffer& src,
8332 const Image& dst,
8333 size_type src_offset,
8334 const array<size_type, 3>& dst_origin,
8335 const array<size_type, 3>& region,
8336 const vector<Event>* events = nullptr,
8337 Event* event = nullptr) const
8338 {
8339 cl_event tmp;
8340 cl_int err = detail::errHandler(
8341 ::clEnqueueCopyBufferToImage(
8342 object_,
8343 src(),
8344 dst(),
8345 src_offset,
8346 dst_origin.data(),
8347 region.data(),
8348 (events != nullptr) ? (cl_uint) events->size() : 0,
8349 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8350 (event != nullptr) ? &tmp : nullptr),
8351 __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
8352
8353 if (event != nullptr && err == CL_SUCCESS)
8354 *event = tmp;
8355
8356 return err;
8357 }
8358
8359 cl_int enqueueCopyBufferToImage(
8360 const Buffer& src,
8361 const Image& dst,
8362 size_type src_offset,
8363 const array<size_type, 2>& dst_origin,
8364 const array<size_type, 2>& region,
8365 const vector<Event>* events = nullptr,
8366 Event* event = nullptr) const
8367 {
8368 return enqueueCopyBufferToImage(
8369 src,
8370 dst,
8371 src_offset,
8372 { dst_origin[0], dst_origin[1], 0 },
8373 { region[0], region[1], 1 },
8374 events,
8375 event);
8376 }
8377
8378 void* enqueueMapBuffer(
8379 const Buffer& buffer,
8380 cl_bool blocking,
8381 cl_map_flags flags,
8382 size_type offset,
8383 size_type size,
8384 const vector<Event>* events = nullptr,
8385 Event* event = nullptr,
8386 cl_int* err = nullptr) const
8387 {
8388 cl_event tmp;
8389 cl_int error;
8390 void * result = ::clEnqueueMapBuffer(
8391 object_, buffer(), blocking, flags, offset, size,
8392 (events != nullptr) ? (cl_uint) events->size() : 0,
8393 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8394 (event != nullptr) ? &tmp : nullptr,
8395 &error);
8396
8397 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
8398 if (err != nullptr) {
8399 *err = error;
8400 }
8401 if (event != nullptr && error == CL_SUCCESS)
8402 *event = tmp;
8403
8404 return result;
8405 }
8406
8407 void* enqueueMapImage(
8408 const Image& image,
8409 cl_bool blocking,
8410 cl_map_flags flags,
8411 const array<size_type, 3>& origin,
8412 const array<size_type, 3>& region,
8413 size_type * row_pitch,
8414 size_type * slice_pitch,
8415 const vector<Event>* events = nullptr,
8416 Event* event = nullptr,
8417 cl_int* err = nullptr) const
8418 {
8419 cl_event tmp;
8420 cl_int error;
8421 void * result = ::clEnqueueMapImage(
8422 object_, image(), blocking, flags,
8423 origin.data(),
8424 region.data(),
8425 row_pitch, slice_pitch,
8426 (events != nullptr) ? (cl_uint) events->size() : 0,
8427 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8428 (event != nullptr) ? &tmp : nullptr,
8429 &error);
8430
8431 detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
8432 if (err != nullptr) {
8433 *err = error;
8434 }
8435 if (event != nullptr && error == CL_SUCCESS)
8436 *event = tmp;
8437 return result;
8438 }
8439
8440 void* enqueueMapImage(
8441 const Image& image,
8442 cl_bool blocking,
8443 cl_map_flags flags,
8444 const array<size_type, 2>& origin,
8445 const array<size_type, 2>& region,
8446 size_type* row_pitch,
8447 size_type* slice_pitch,
8448 const vector<Event>* events = nullptr,
8449 Event* event = nullptr,
8450 cl_int* err = nullptr) const
8451 {
8452 return enqueueMapImage(image, blocking, flags,
8453 { origin[0], origin[1], 0 },
8454 { region[0], region[1], 1 }, row_pitch,
8455 slice_pitch, events, event, err);
8456 }
8457
8458#if CL_HPP_TARGET_OPENCL_VERSION >= 200
8459
8464 template<typename T>
8465 cl_int enqueueMemcpySVM(
8466 T *dst_ptr,
8467 const T *src_ptr,
8468 cl_bool blocking,
8469 size_type size,
8470 const vector<Event> *events = nullptr,
8471 Event *event = nullptr) const {
8472 cl_event tmp;
8473 cl_int err = detail::errHandler(::clEnqueueSVMMemcpy(
8474 object_, blocking, static_cast<void *>(dst_ptr), static_cast<const void *>(src_ptr), size,
8475 (events != nullptr) ? (cl_uint) events->size() : 0,
8476 (events != nullptr && events->size() > 0) ? (cl_event *) &events->front() : nullptr,
8477 (event != nullptr) ? &tmp : nullptr), __ENQUEUE_COPY_SVM_ERR);
8478
8479 if (event != nullptr && err == CL_SUCCESS)
8480 *event = tmp;
8481
8482 return err;
8483 }
8484
8489 template<typename T, class D>
8490 cl_int enqueueMemcpySVM(
8491 cl::pointer<T, D> &dst_ptr,
8492 const cl::pointer<T, D> &src_ptr,
8493 cl_bool blocking,
8494 size_type size,
8495 const vector<Event> *events = nullptr,
8496 Event *event = nullptr) const {
8497 cl_event tmp;
8498 cl_int err = detail::errHandler(::clEnqueueSVMMemcpy(
8499 object_, blocking, static_cast<void *>(dst_ptr.get()), static_cast<const void *>(src_ptr.get()),
8500 size,
8501 (events != nullptr) ? (cl_uint) events->size() : 0,
8502 (events != nullptr && events->size() > 0) ? (cl_event *) &events->front() : nullptr,
8503 (event != nullptr) ? &tmp : nullptr), __ENQUEUE_COPY_SVM_ERR);
8504
8505 if (event != nullptr && err == CL_SUCCESS)
8506 *event = tmp;
8507
8508 return err;
8509 }
8510
8515 template<typename T, class Alloc>
8516 cl_int enqueueMemcpySVM(
8517 cl::vector<T, Alloc> &dst_container,
8518 const cl::vector<T, Alloc> &src_container,
8519 cl_bool blocking,
8520 const vector<Event> *events = nullptr,
8521 Event *event = nullptr) const {
8522 cl_event tmp;
8523 if(src_container.size() != dst_container.size()){
8524 return detail::errHandler(CL_INVALID_VALUE,__ENQUEUE_COPY_SVM_ERR);
8525 }
8526 cl_int err = detail::errHandler(::clEnqueueSVMMemcpy(
8527 object_, blocking, static_cast<void *>(dst_container.data()),
8528 static_cast<const void *>(src_container.data()),
8529 dst_container.size() * sizeof(T),
8530 (events != nullptr) ? (cl_uint) events->size() : 0,
8531 (events != nullptr && events->size() > 0) ? (cl_event *) &events->front() : nullptr,
8532 (event != NULL) ? &tmp : nullptr), __ENQUEUE_COPY_SVM_ERR);
8533
8534 if (event != nullptr && err == CL_SUCCESS)
8535 *event = tmp;
8536
8537 return err;
8538 }
8539
8544 template<typename T, typename PatternType>
8545 cl_int enqueueMemFillSVM(
8546 T *ptr,
8547 PatternType pattern,
8548 size_type size,
8549 const vector<Event> *events = nullptr,
8550 Event *event = nullptr) const {
8551 cl_event tmp;
8552 cl_int err = detail::errHandler(::clEnqueueSVMMemFill(
8553 object_, static_cast<void *>(ptr), static_cast<void *>(&pattern),
8554 sizeof(PatternType), size,
8555 (events != nullptr) ? (cl_uint) events->size() : 0,
8556 (events != nullptr && events->size() > 0) ? (cl_event *) &events->front() : nullptr,
8557 (event != nullptr) ? &tmp : nullptr), __ENQUEUE_FILL_SVM_ERR);
8558
8559 if (event != nullptr && err == CL_SUCCESS)
8560 *event = tmp;
8561
8562 return err;
8563 }
8564
8569 template<typename T, class D, typename PatternType>
8570 cl_int enqueueMemFillSVM(
8571 cl::pointer<T, D> &ptr,
8572 PatternType pattern,
8573 size_type size,
8574 const vector<Event> *events = nullptr,
8575 Event *event = nullptr) const {
8576 cl_event tmp;
8577 cl_int err = detail::errHandler(::clEnqueueSVMMemFill(
8578 object_, static_cast<void *>(ptr.get()), static_cast<void *>(&pattern),
8579 sizeof(PatternType), size,
8580 (events != nullptr) ? (cl_uint) events->size() : 0,
8581 (events != nullptr && events->size() > 0) ? (cl_event *) &events->front() : nullptr,
8582 (event != nullptr) ? &tmp : nullptr), __ENQUEUE_FILL_SVM_ERR);
8583
8584 if (event != nullptr && err == CL_SUCCESS)
8585 *event = tmp;
8586
8587 return err;
8588 }
8589
8594 template<typename T, class Alloc, typename PatternType>
8595 cl_int enqueueMemFillSVM(
8596 cl::vector<T, Alloc> &container,
8597 PatternType pattern,
8598 const vector<Event> *events = nullptr,
8599 Event* event = nullptr) const
8600 {
8601 cl_event tmp;
8602 cl_int err = detail::errHandler(::clEnqueueSVMMemFill(
8603 object_, static_cast<void *>(container.data()), static_cast<void *>(&pattern),
8604 sizeof(PatternType), container.size() * sizeof(T),
8605 (events != nullptr) ? (cl_uint) events->size() : 0,
8606 (events != nullptr && events->size() > 0) ? (cl_event *) &events->front() : nullptr,
8607 (event != nullptr) ? &tmp : NULL), __ENQUEUE_FILL_SVM_ERR);
8608
8609 if (event != nullptr && err == CL_SUCCESS)
8610 *event = tmp;
8611
8612 return err;
8613 }
8614
8619 template<typename T>
8620 cl_int enqueueMapSVM(
8621 T* ptr,
8622 cl_bool blocking,
8623 cl_map_flags flags,
8624 size_type size,
8625 const vector<Event>* events = nullptr,
8626 Event* event = nullptr) const
8627 {
8628 cl_event tmp;
8629 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8630 object_, blocking, flags, static_cast<void*>(ptr), size,
8631 (events != nullptr) ? (cl_uint)events->size() : 0,
8632 (events != nullptr && events->size() > 0) ? (cl_event*)&events->front() : nullptr,
8633 (event != nullptr) ? &tmp : nullptr),
8634 __ENQUEUE_MAP_SVM_ERR);
8635
8636 if (event != nullptr && err == CL_SUCCESS)
8637 *event = tmp;
8638
8639 return err;
8640 }
8641
8642
8647 template<typename T, class D>
8648 cl_int enqueueMapSVM(
8649 cl::pointer<T, D> &ptr,
8650 cl_bool blocking,
8651 cl_map_flags flags,
8652 size_type size,
8653 const vector<Event>* events = nullptr,
8654 Event* event = nullptr) const
8655 {
8656 cl_event tmp;
8657 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8658 object_, blocking, flags, static_cast<void*>(ptr.get()), size,
8659 (events != nullptr) ? (cl_uint)events->size() : 0,
8660 (events != nullptr && events->size() > 0) ? (cl_event*)&events->front() : nullptr,
8661 (event != nullptr) ? &tmp : nullptr),
8662 __ENQUEUE_MAP_SVM_ERR);
8663
8664 if (event != nullptr && err == CL_SUCCESS)
8665 *event = tmp;
8666
8667 return err;
8668 }
8669
8674 template<typename T, class Alloc>
8675 cl_int enqueueMapSVM(
8676 cl::vector<T, Alloc> &container,
8677 cl_bool blocking,
8678 cl_map_flags flags,
8679 const vector<Event>* events = nullptr,
8680 Event* event = nullptr) const
8681 {
8682 cl_event tmp;
8683 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8684 object_, blocking, flags, static_cast<void*>(container.data()), container.size()*sizeof(T),
8685 (events != nullptr) ? (cl_uint)events->size() : 0,
8686 (events != nullptr && events->size() > 0) ? (cl_event*)&events->front() : nullptr,
8687 (event != nullptr) ? &tmp : nullptr),
8688 __ENQUEUE_MAP_SVM_ERR);
8689
8690 if (event != nullptr && err == CL_SUCCESS)
8691 *event = tmp;
8692
8693 return err;
8694 }
8695#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8696
8697 cl_int enqueueUnmapMemObject(
8698 const Memory& memory,
8699 void* mapped_ptr,
8700 const vector<Event>* events = nullptr,
8701 Event* event = nullptr) const
8702 {
8703 cl_event tmp;
8704 cl_int err = detail::errHandler(
8705 ::clEnqueueUnmapMemObject(
8706 object_, memory(), mapped_ptr,
8707 (events != nullptr) ? (cl_uint) events->size() : 0,
8708 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8709 (event != nullptr) ? &tmp : nullptr),
8710 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8711
8712 if (event != nullptr && err == CL_SUCCESS)
8713 *event = tmp;
8714
8715 return err;
8716 }
8717
8718
8719#if CL_HPP_TARGET_OPENCL_VERSION >= 200
8724 template<typename T>
8725 cl_int enqueueUnmapSVM(
8726 T* ptr,
8727 const vector<Event>* events = nullptr,
8728 Event* event = nullptr) const
8729 {
8730 cl_event tmp;
8731 cl_int err = detail::errHandler(
8732 ::clEnqueueSVMUnmap(
8733 object_, static_cast<void*>(ptr),
8734 (events != nullptr) ? (cl_uint)events->size() : 0,
8735 (events != nullptr && events->size() > 0) ? (cl_event*)&events->front() : nullptr,
8736 (event != nullptr) ? &tmp : nullptr),
8737 __ENQUEUE_UNMAP_SVM_ERR);
8738
8739 if (event != nullptr && err == CL_SUCCESS)
8740 *event = tmp;
8741
8742 return err;
8743 }
8744
8749 template<typename T, class D>
8750 cl_int enqueueUnmapSVM(
8751 cl::pointer<T, D> &ptr,
8752 const vector<Event>* events = nullptr,
8753 Event* event = nullptr) const
8754 {
8755 cl_event tmp;
8756 cl_int err = detail::errHandler(
8757 ::clEnqueueSVMUnmap(
8758 object_, static_cast<void*>(ptr.get()),
8759 (events != nullptr) ? (cl_uint)events->size() : 0,
8760 (events != nullptr && events->size() > 0) ? (cl_event*)&events->front() : nullptr,
8761 (event != nullptr) ? &tmp : nullptr),
8762 __ENQUEUE_UNMAP_SVM_ERR);
8763
8764 if (event != nullptr && err == CL_SUCCESS)
8765 *event = tmp;
8766
8767 return err;
8768 }
8769
8774 template<typename T, class Alloc>
8775 cl_int enqueueUnmapSVM(
8776 cl::vector<T, Alloc> &container,
8777 const vector<Event>* events = nullptr,
8778 Event* event = nullptr) const
8779 {
8780 cl_event tmp;
8781 cl_int err = detail::errHandler(
8782 ::clEnqueueSVMUnmap(
8783 object_, static_cast<void*>(container.data()),
8784 (events != nullptr) ? (cl_uint)events->size() : 0,
8785 (events != nullptr && events->size() > 0) ? (cl_event*)&events->front() : nullptr,
8786 (event != nullptr) ? &tmp : nullptr),
8787 __ENQUEUE_UNMAP_SVM_ERR);
8788
8789 if (event != nullptr && err == CL_SUCCESS)
8790 *event = tmp;
8791
8792 return err;
8793 }
8794#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8795
8796#if CL_HPP_TARGET_OPENCL_VERSION >= 120
8809 const vector<Event> *events = nullptr,
8810 Event *event = nullptr) const
8811 {
8812 cl_event tmp;
8813 cl_int err = detail::errHandler(
8814 ::clEnqueueMarkerWithWaitList(
8815 object_,
8816 (events != nullptr) ? (cl_uint) events->size() : 0,
8817 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8818 (event != nullptr) ? &tmp : nullptr),
8819 __ENQUEUE_MARKER_WAIT_LIST_ERR);
8820
8821 if (event != nullptr && err == CL_SUCCESS)
8822 *event = tmp;
8823
8824 return err;
8825 }
8826
8839 const vector<Event> *events = nullptr,
8840 Event *event = nullptr) const
8841 {
8842 cl_event tmp;
8843 cl_int err = detail::errHandler(
8844 ::clEnqueueBarrierWithWaitList(
8845 object_,
8846 (events != nullptr) ? (cl_uint) events->size() : 0,
8847 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8848 (event != nullptr) ? &tmp : nullptr),
8849 __ENQUEUE_BARRIER_WAIT_LIST_ERR);
8850
8851 if (event != nullptr && err == CL_SUCCESS)
8852 *event = tmp;
8853
8854 return err;
8855 }
8856
8862 const vector<Memory> &memObjects,
8863 cl_mem_migration_flags flags,
8864 const vector<Event>* events = nullptr,
8865 Event* event = nullptr
8866 ) const
8867 {
8868 cl_event tmp;
8869
8870 vector<cl_mem> localMemObjects(memObjects.size());
8871
8872 for( int i = 0; i < (int)memObjects.size(); ++i ) {
8873 localMemObjects[i] = memObjects[i]();
8874 }
8875
8876 cl_int err = detail::errHandler(
8877 ::clEnqueueMigrateMemObjects(
8878 object_,
8879 (cl_uint)memObjects.size(),
8880 localMemObjects.data(),
8881 flags,
8882 (events != nullptr) ? (cl_uint) events->size() : 0,
8883 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8884 (event != nullptr) ? &tmp : nullptr),
8885 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8886
8887 if (event != nullptr && err == CL_SUCCESS)
8888 *event = tmp;
8889
8890 return err;
8891 }
8892#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8893
8894
8895#if CL_HPP_TARGET_OPENCL_VERSION >= 210
8901 template<typename T>
8902 cl_int enqueueMigrateSVM(
8903 const cl::vector<T*> &svmRawPointers,
8904 const cl::vector<size_type> &sizes,
8905 cl_mem_migration_flags flags = 0,
8906 const vector<Event>* events = nullptr,
8907 Event* event = nullptr) const
8908 {
8909 cl_event tmp;
8910 cl_int err = detail::errHandler(::clEnqueueSVMMigrateMem(
8911 object_,
8912 svmRawPointers.size(), static_cast<void**>(svmRawPointers.data()),
8913 sizes.data(), // array of sizes not passed
8914 flags,
8915 (events != nullptr) ? (cl_uint)events->size() : 0,
8916 (events != nullptr && events->size() > 0) ? (cl_event*)&events->front() : nullptr,
8917 (event != nullptr) ? &tmp : nullptr),
8918 __ENQUEUE_MIGRATE_SVM_ERR);
8919
8920 if (event != nullptr && err == CL_SUCCESS)
8921 *event = tmp;
8922
8923 return err;
8924 }
8925
8930 template<typename T>
8931 cl_int enqueueMigrateSVM(
8932 const cl::vector<T*> &svmRawPointers,
8933 cl_mem_migration_flags flags = 0,
8934 const vector<Event>* events = nullptr,
8935 Event* event = nullptr) const
8936 {
8937 return enqueueMigrateSVM(svmRawPointers, cl::vector<size_type>(svmRawPointers.size()), flags, events, event);
8938 }
8939
8940
8946 template<typename T, class D>
8947 cl_int enqueueMigrateSVM(
8948 const cl::vector<cl::pointer<T, D>> &svmPointers,
8949 const cl::vector<size_type> &sizes,
8950 cl_mem_migration_flags flags = 0,
8951 const vector<Event>* events = nullptr,
8952 Event* event = nullptr) const
8953 {
8954 cl::vector<void*> svmRawPointers;
8955 svmRawPointers.reserve(svmPointers.size());
8956 for (auto p : svmPointers) {
8957 svmRawPointers.push_back(static_cast<void*>(p.get()));
8958 }
8959
8960 return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
8961 }
8962
8963
8968 template<typename T, class D>
8969 cl_int enqueueMigrateSVM(
8970 const cl::vector<cl::pointer<T, D>> &svmPointers,
8971 cl_mem_migration_flags flags = 0,
8972 const vector<Event>* events = nullptr,
8973 Event* event = nullptr) const
8974 {
8975 return enqueueMigrateSVM(svmPointers, cl::vector<size_type>(svmPointers.size()), flags, events, event);
8976 }
8977
8983 template<typename T, class Alloc>
8984 cl_int enqueueMigrateSVM(
8985 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8986 const cl::vector<size_type> &sizes,
8987 cl_mem_migration_flags flags = 0,
8988 const vector<Event>* events = nullptr,
8989 Event* event = nullptr) const
8990 {
8991 cl::vector<void*> svmRawPointers;
8992 svmRawPointers.reserve(svmContainers.size());
8993 for (auto p : svmContainers) {
8994 svmRawPointers.push_back(static_cast<void*>(p.data()));
8995 }
8996
8997 return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
8998 }
8999
9004 template<typename T, class Alloc>
9005 cl_int enqueueMigrateSVM(
9006 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
9007 cl_mem_migration_flags flags = 0,
9008 const vector<Event>* events = nullptr,
9009 Event* event = nullptr) const
9010 {
9011 return enqueueMigrateSVM(svmContainers, cl::vector<size_type>(svmContainers.size()), flags, events, event);
9012 }
9013
9014#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
9015
9016 cl_int enqueueNDRangeKernel(
9017 const Kernel& kernel,
9018 const NDRange& offset,
9019 const NDRange& global,
9020 const NDRange& local = NullRange,
9021 const vector<Event>* events = nullptr,
9022 Event* event = nullptr) const
9023 {
9024 cl_event tmp;
9025 cl_int err = detail::errHandler(
9026 ::clEnqueueNDRangeKernel(
9027 object_, kernel(), (cl_uint) global.dimensions(),
9028 offset.dimensions() != 0 ? (const size_type*) offset : nullptr,
9029 (const size_type*) global,
9030 local.dimensions() != 0 ? (const size_type*) local : nullptr,
9031 (events != nullptr) ? (cl_uint) events->size() : 0,
9032 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
9033 (event != nullptr) ? &tmp : nullptr),
9034 __ENQUEUE_NDRANGE_KERNEL_ERR);
9035
9036 if (event != nullptr && err == CL_SUCCESS)
9037 *event = tmp;
9038
9039 return err;
9040 }
9041
9042#if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
9043 CL_API_PREFIX__VERSION_1_2_DEPRECATED cl_int enqueueTask(
9044 const Kernel& kernel,
9045 const vector<Event>* events = nullptr,
9046 Event* event = nullptr) const CL_API_SUFFIX__VERSION_1_2_DEPRECATED
9047 {
9048 cl_event tmp;
9049 cl_int err = detail::errHandler(
9050 ::clEnqueueTask(
9051 object_, kernel(),
9052 (events != nullptr) ? (cl_uint) events->size() : 0,
9053 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
9054 (event != nullptr) ? &tmp : nullptr),
9055 __ENQUEUE_TASK_ERR);
9056
9057 if (event != nullptr && err == CL_SUCCESS)
9058 *event = tmp;
9059
9060 return err;
9061 }
9062#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
9063
9064 cl_int enqueueNativeKernel(
9065 void (CL_CALLBACK *userFptr)(void *),
9066 std::pair<void*, size_type> args,
9067 const vector<Memory>* mem_objects = nullptr,
9068 const vector<const void*>* mem_locs = nullptr,
9069 const vector<Event>* events = nullptr,
9070 Event* event = nullptr) const
9071 {
9072 cl_event tmp;
9073 cl_int err = detail::errHandler(
9074 ::clEnqueueNativeKernel(
9075 object_, userFptr, args.first, args.second,
9076 (mem_objects != nullptr) ? (cl_uint) mem_objects->size() : 0,
9077 (mem_objects->size() > 0 ) ? reinterpret_cast<const cl_mem *>(mem_objects->data()) : nullptr,
9078 (mem_locs != nullptr && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : nullptr,
9079 (events != nullptr) ? (cl_uint) events->size() : 0,
9080 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
9081 (event != nullptr) ? &tmp : nullptr),
9082 __ENQUEUE_NATIVE_KERNEL);
9083
9084 if (event != nullptr && err == CL_SUCCESS)
9085 *event = tmp;
9086
9087 return err;
9088 }
9089
9093#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
9094 CL_API_PREFIX__VERSION_1_1_DEPRECATED
9095 cl_int enqueueMarker(Event* event = nullptr) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
9096 {
9097 cl_event tmp;
9098 cl_int err = detail::errHandler(
9099 ::clEnqueueMarker(
9100 object_,
9101 (event != nullptr) ? &tmp : nullptr),
9102 __ENQUEUE_MARKER_ERR);
9103
9104 if (event != nullptr && err == CL_SUCCESS)
9105 *event = tmp;
9106
9107 return err;
9108 }
9109
9110 CL_API_PREFIX__VERSION_1_1_DEPRECATED
9111 cl_int enqueueWaitForEvents(const vector<Event>& events) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
9112 {
9113 return detail::errHandler(
9114 ::clEnqueueWaitForEvents(
9115 object_,
9116 (cl_uint) events.size(),
9117 events.size() > 0 ? (const cl_event*) &events.front() : nullptr),
9118 __ENQUEUE_WAIT_FOR_EVENTS_ERR);
9119 }
9120#endif // defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
9121
9122 cl_int enqueueAcquireGLObjects(
9123 const vector<Memory>* mem_objects = nullptr,
9124 const vector<Event>* events = nullptr,
9125 Event* event = nullptr) const
9126 {
9127 cl_event tmp;
9128 cl_int err = detail::errHandler(
9129 ::clEnqueueAcquireGLObjects(
9130 object_,
9131 (mem_objects != nullptr) ? (cl_uint) mem_objects->size() : 0,
9132 (mem_objects != nullptr && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): nullptr,
9133 (events != nullptr) ? (cl_uint) events->size() : 0,
9134 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
9135 (event != nullptr) ? &tmp : nullptr),
9136 __ENQUEUE_ACQUIRE_GL_ERR);
9137
9138 if (event != nullptr && err == CL_SUCCESS)
9139 *event = tmp;
9140
9141 return err;
9142 }
9143
9144 cl_int enqueueReleaseGLObjects(
9145 const vector<Memory>* mem_objects = nullptr,
9146 const vector<Event>* events = nullptr,
9147 Event* event = nullptr) const
9148 {
9149 cl_event tmp;
9150 cl_int err = detail::errHandler(
9151 ::clEnqueueReleaseGLObjects(
9152 object_,
9153 (mem_objects != nullptr) ? (cl_uint) mem_objects->size() : 0,
9154 (mem_objects != nullptr && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): nullptr,
9155 (events != nullptr) ? (cl_uint) events->size() : 0,
9156 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
9157 (event != nullptr) ? &tmp : nullptr),
9158 __ENQUEUE_RELEASE_GL_ERR);
9159
9160 if (event != nullptr && err == CL_SUCCESS)
9161 *event = tmp;
9162
9163 return err;
9164 }
9165
9166#if defined (CL_HPP_USE_DX_INTEROP)
9167typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
9168 cl_command_queue command_queue, cl_uint num_objects,
9169 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
9170 const cl_event* event_wait_list, cl_event* event);
9171typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
9172 cl_command_queue command_queue, cl_uint num_objects,
9173 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
9174 const cl_event* event_wait_list, cl_event* event);
9175
9176 cl_int enqueueAcquireD3D10Objects(
9177 const vector<Memory>* mem_objects = nullptr,
9178 const vector<Event>* events = nullptr,
9179 Event* event = nullptr) const
9180 {
9181 static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = nullptr;
9182#if CL_HPP_TARGET_OPENCL_VERSION >= 120
9183 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
9184 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
9185 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
9186 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireD3D10ObjectsKHR);
9187#endif
9188#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
9189 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueAcquireD3D10ObjectsKHR);
9190#endif
9191
9192 cl_event tmp;
9193 cl_int err = detail::errHandler(
9194 pfn_clEnqueueAcquireD3D10ObjectsKHR(
9195 object_,
9196 (mem_objects != nullptr) ? (cl_uint) mem_objects->size() : 0,
9197 (mem_objects != nullptr && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): nullptr,
9198 (events != nullptr) ? (cl_uint) events->size() : 0,
9199 (events != nullptr) ? (cl_event*) &events->front() : nullptr,
9200 (event != nullptr) ? &tmp : nullptr),
9201 __ENQUEUE_ACQUIRE_GL_ERR);
9202
9203 if (event != nullptr && err == CL_SUCCESS)
9204 *event = tmp;
9205
9206 return err;
9207 }
9208
9209 cl_int enqueueReleaseD3D10Objects(
9210 const vector<Memory>* mem_objects = nullptr,
9211 const vector<Event>* events = nullptr,
9212 Event* event = nullptr) const
9213 {
9214 static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = nullptr;
9215#if CL_HPP_TARGET_OPENCL_VERSION >= 120
9216 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
9217 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
9218 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
9219 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseD3D10ObjectsKHR);
9220#endif
9221#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
9222 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueReleaseD3D10ObjectsKHR);
9223#endif
9224
9225 cl_event tmp;
9226 cl_int err = detail::errHandler(
9227 pfn_clEnqueueReleaseD3D10ObjectsKHR(
9228 object_,
9229 (mem_objects != nullptr) ? (cl_uint) mem_objects->size() : 0,
9230 (mem_objects != nullptr && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): nullptr,
9231 (events != nullptr) ? (cl_uint) events->size() : 0,
9232 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
9233 (event != nullptr) ? &tmp : nullptr),
9234 __ENQUEUE_RELEASE_GL_ERR);
9235
9236 if (event != nullptr && err == CL_SUCCESS)
9237 *event = tmp;
9238
9239 return err;
9240 }
9241#endif
9242
9246#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
9247 CL_API_PREFIX__VERSION_1_1_DEPRECATED
9248 cl_int enqueueBarrier() const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
9249 {
9250 return detail::errHandler(
9251 ::clEnqueueBarrier(object_),
9252 __ENQUEUE_BARRIER_ERR);
9253 }
9254#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
9255
9256 cl_int flush() const
9257 {
9258 return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
9259 }
9260
9261 cl_int finish() const
9262 {
9263 return detail::errHandler(::clFinish(object_), __FINISH_ERR);
9264 }
9265
9266#ifdef cl_khr_external_memory
9267 cl_int enqueueAcquireExternalMemObjects(
9268 const vector<Memory>& mem_objects,
9269 const vector<Event>* events_wait = nullptr,
9270 Event *event = nullptr)
9271 {
9272 cl_int err = CL_INVALID_OPERATION;
9273 cl_event tmp;
9274
9275 std::call_once(ext_memory_initialized_, initMemoryExtension, this->getInfo<CL_QUEUE_DEVICE>());
9276
9277 if (pfn_clEnqueueAcquireExternalMemObjectsKHR)
9278 {
9279 err = pfn_clEnqueueAcquireExternalMemObjectsKHR(
9280 object_,
9281 static_cast<cl_uint>(mem_objects.size()),
9282 (mem_objects.size() > 0) ? reinterpret_cast<const cl_mem *>(mem_objects.data()) : nullptr,
9283 (events_wait != nullptr) ? static_cast<cl_uint>(events_wait->size()) : 0,
9284 (events_wait != nullptr && events_wait->size() > 0) ? reinterpret_cast<const cl_event*>(events_wait->data()) : nullptr,
9285 &tmp);
9286 }
9287
9288 detail::errHandler(err, __ENQUEUE_ACQUIRE_EXTERNAL_MEMORY_ERR);
9289
9290 if (event != nullptr && err == CL_SUCCESS)
9291 *event = tmp;
9292
9293 return err;
9294 }
9295
9296 cl_int enqueueReleaseExternalMemObjects(
9297 const vector<Memory>& mem_objects,
9298 const vector<Event>* events_wait = nullptr,
9299 Event *event = nullptr)
9300 {
9301 cl_int err = CL_INVALID_OPERATION;
9302 cl_event tmp;
9303
9304 std::call_once(ext_memory_initialized_, initMemoryExtension, this->getInfo<CL_QUEUE_DEVICE>());
9305
9306 if (pfn_clEnqueueReleaseExternalMemObjectsKHR)
9307 {
9308 err = pfn_clEnqueueReleaseExternalMemObjectsKHR(
9309 object_,
9310 static_cast<cl_uint>(mem_objects.size()),
9311 (mem_objects.size() > 0) ? reinterpret_cast<const cl_mem *>(mem_objects.data()) : nullptr,
9312 (events_wait != nullptr) ? static_cast<cl_uint>(events_wait->size()) : 0,
9313 (events_wait != nullptr && events_wait->size() > 0) ? reinterpret_cast<const cl_event*>(events_wait->data()) : nullptr,
9314 &tmp);
9315 }
9316
9317 detail::errHandler(err, __ENQUEUE_RELEASE_EXTERNAL_MEMORY_ERR);
9318
9319 if (event != nullptr && err == CL_SUCCESS)
9320 *event = tmp;
9321
9322 return err;
9323 }
9324#endif // cl_khr_external_memory && CL_HPP_TARGET_OPENCL_VERSION >= 300
9325
9326#ifdef cl_khr_semaphore
9327 cl_int enqueueWaitSemaphores(
9328 const vector<Semaphore> &sema_objects,
9329 const vector<cl_semaphore_payload_khr> &sema_payloads = {},
9330 const vector<Event>* events_wait_list = nullptr,
9331 Event *event = nullptr) const;
9332
9333 cl_int enqueueSignalSemaphores(
9334 const vector<Semaphore> &sema_objects,
9335 const vector<cl_semaphore_payload_khr>& sema_payloads = {},
9336 const vector<Event>* events_wait_list = nullptr,
9337 Event* event = nullptr);
9338#endif // cl_khr_semaphore
9339}; // CommandQueue
9340
9341#ifdef cl_khr_external_memory
9342CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::ext_memory_initialized_;
9343#endif
9344
9345CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::default_initialized_;
9346CL_HPP_DEFINE_STATIC_MEMBER_ CommandQueue CommandQueue::default_;
9347CL_HPP_DEFINE_STATIC_MEMBER_ cl_int CommandQueue::default_error_ = CL_SUCCESS;
9348
9349
9350#if CL_HPP_TARGET_OPENCL_VERSION >= 200
9351enum class DeviceQueueProperties : cl_command_queue_properties
9352{
9353 None = 0,
9354 Profiling = CL_QUEUE_PROFILING_ENABLE,
9355};
9356
9357inline DeviceQueueProperties operator|(DeviceQueueProperties lhs, DeviceQueueProperties rhs)
9358{
9359 return static_cast<DeviceQueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
9360}
9365class DeviceCommandQueue : public detail::Wrapper<cl_command_queue>
9366{
9367public:
9372 DeviceCommandQueue() { }
9377 DeviceCommandQueue(DeviceQueueProperties properties, cl_int* err = nullptr)
9378 {
9379 cl_int error;
9382
9383 cl_command_queue_properties mergedProperties =
9384 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
9385
9386 cl_queue_properties queue_properties[] = {
9387 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
9388 object_ = ::clCreateCommandQueueWithProperties(
9389 context(), device(), queue_properties, &error);
9390
9391 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9392 if (err != nullptr) {
9393 *err = error;
9394 }
9395 }
9401 const Context& context,
9402 const Device& device,
9403 DeviceQueueProperties properties = DeviceQueueProperties::None,
9404 cl_int* err = nullptr)
9405 {
9406 cl_int error;
9407
9408 cl_command_queue_properties mergedProperties =
9409 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
9410 cl_queue_properties queue_properties[] = {
9411 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
9412 object_ = ::clCreateCommandQueueWithProperties(
9413 context(), device(), queue_properties, &error);
9414
9415 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9416 if (err != nullptr) {
9417 *err = error;
9418 }
9419 }
9425 const Context& context,
9426 const Device& device,
9427 cl_uint queueSize,
9428 DeviceQueueProperties properties = DeviceQueueProperties::None,
9429 cl_int* err = nullptr)
9430 {
9431 cl_int error;
9432
9433 cl_command_queue_properties mergedProperties =
9434 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
9435 cl_queue_properties queue_properties[] = {
9436 CL_QUEUE_PROPERTIES, mergedProperties,
9437 CL_QUEUE_SIZE, queueSize,
9438 0 };
9439 object_ = ::clCreateCommandQueueWithProperties(
9440 context(), device(), queue_properties, &error);
9441
9442 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9443 if (err != nullptr) {
9444 *err = error;
9445 }
9446 }
9447
9454 explicit DeviceCommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
9455 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
9456
9457 DeviceCommandQueue& operator = (const cl_command_queue& rhs)
9458 {
9459 detail::Wrapper<cl_type>::operator=(rhs);
9460 return *this;
9461 }
9462
9463 template <typename T>
9464 cl_int getInfo(cl_command_queue_info name, T* param) const
9465 {
9466 return detail::errHandler(
9467 detail::getInfo(
9468 &::clGetCommandQueueInfo, object_, name, param),
9469 __GET_COMMAND_QUEUE_INFO_ERR);
9470 }
9471
9472 template <cl_command_queue_info name> typename
9473 detail::param_traits<detail::cl_command_queue_info, name>::param_type
9474 getInfo(cl_int* err = nullptr) const
9475 {
9476 typename detail::param_traits<
9477 detail::cl_command_queue_info, name>::param_type param;
9478 cl_int result = getInfo(name, &param);
9479 if (err != nullptr) {
9480 *err = result;
9481 }
9482 return param;
9483 }
9484
9492 cl_int *err = nullptr)
9493 {
9494 cl_int error;
9497
9498 cl_command_queue_properties properties =
9499 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9500 cl_queue_properties queue_properties[] = {
9501 CL_QUEUE_PROPERTIES, properties,
9502 0 };
9503 DeviceCommandQueue deviceQueue(
9504 ::clCreateCommandQueueWithProperties(
9505 context(), device(), queue_properties, &error));
9506
9507 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9508 if (err != nullptr) {
9509 *err = error;
9510 }
9511
9512 return deviceQueue;
9513 }
9514
9522 const Context &context, const Device &device, cl_int *err = nullptr)
9523 {
9524 cl_int error;
9525
9526 cl_command_queue_properties properties =
9527 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9528 cl_queue_properties queue_properties[] = {
9529 CL_QUEUE_PROPERTIES, properties,
9530 0 };
9531 DeviceCommandQueue deviceQueue(
9532 ::clCreateCommandQueueWithProperties(
9533 context(), device(), queue_properties, &error));
9534
9535 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9536 if (err != nullptr) {
9537 *err = error;
9538 }
9539
9540 return deviceQueue;
9541 }
9542
9550 const Context &context, const Device &device, cl_uint queueSize, cl_int *err = nullptr)
9551 {
9552 cl_int error;
9553
9554 cl_command_queue_properties properties =
9555 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9556 cl_queue_properties queue_properties[] = {
9557 CL_QUEUE_PROPERTIES, properties,
9558 CL_QUEUE_SIZE, queueSize,
9559 0 };
9560 DeviceCommandQueue deviceQueue(
9561 ::clCreateCommandQueueWithProperties(
9562 context(), device(), queue_properties, &error));
9563
9564 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9565 if (err != nullptr) {
9566 *err = error;
9567 }
9568
9569 return deviceQueue;
9570 }
9571
9572
9573
9574#if CL_HPP_TARGET_OPENCL_VERSION >= 210
9581 static DeviceCommandQueue updateDefault(const Context &context, const Device &device, const DeviceCommandQueue &default_queue, cl_int *err = nullptr)
9582 {
9583 cl_int error;
9584 error = clSetDefaultDeviceCommandQueue(context.get(), device.get(), default_queue.get());
9585
9586 detail::errHandler(error, __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR);
9587 if (err != nullptr) {
9588 *err = error;
9589 }
9590 return default_queue;
9591 }
9596 static DeviceCommandQueue getDefault(const CommandQueue &queue, cl_int * err = nullptr)
9597 {
9598 return queue.getInfo<CL_QUEUE_DEVICE_DEFAULT>(err);
9599 }
9600
9601#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
9602}; // DeviceCommandQueue
9603
9604namespace detail
9605{
9606 // Specialization for device command queue
9607 template <>
9609 {
9610 static size_type size(const cl::DeviceCommandQueue&) { return sizeof(cl_command_queue); }
9611 static const cl_command_queue* ptr(const cl::DeviceCommandQueue& value) { return &(value()); }
9612 };
9613} // namespace detail
9614
9615#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9616
9617
9618template< typename IteratorType >
9620 const Context &context,
9621 IteratorType startIterator,
9622 IteratorType endIterator,
9623 bool readOnly,
9624 bool useHostPtr,
9625 cl_int* err)
9626{
9627 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9628 cl_int error;
9629
9630 cl_mem_flags flags = 0;
9631 if( readOnly ) {
9632 flags |= CL_MEM_READ_ONLY;
9633 }
9634 else {
9635 flags |= CL_MEM_READ_WRITE;
9636 }
9637 if( useHostPtr ) {
9638 flags |= CL_MEM_USE_HOST_PTR;
9639 }
9640
9641 size_type size = sizeof(DataType)*(endIterator - startIterator);
9642
9643 if( useHostPtr ) {
9644 object_ = ::clCreateBuffer(context(), flags, size, const_cast<DataType*>(&*startIterator), &error);
9645 } else {
9646 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9647 }
9648
9649 detail::errHandler(error, __CREATE_BUFFER_ERR);
9650 if (err != nullptr) {
9651 *err = error;
9652 }
9653
9654 if( !useHostPtr ) {
9655 CommandQueue queue(context, 0, &error);
9656 detail::errHandler(error, __CREATE_BUFFER_ERR);
9657 if (err != nullptr) {
9658 *err = error;
9659 }
9660
9661 error = cl::copy(queue, startIterator, endIterator, *this);
9662 detail::errHandler(error, __CREATE_BUFFER_ERR);
9663 if (err != nullptr) {
9664 *err = error;
9665 }
9667}
9668
9669template< typename IteratorType >
9671 const CommandQueue &queue,
9672 IteratorType startIterator,
9673 IteratorType endIterator,
9674 bool readOnly,
9675 bool useHostPtr,
9676 cl_int* err)
9677{
9678 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9679 cl_int error;
9680
9681 cl_mem_flags flags = 0;
9682 if (readOnly) {
9683 flags |= CL_MEM_READ_ONLY;
9684 }
9685 else {
9686 flags |= CL_MEM_READ_WRITE;
9687 }
9688 if (useHostPtr) {
9689 flags |= CL_MEM_USE_HOST_PTR;
9690 }
9691
9692 size_type size = sizeof(DataType)*(endIterator - startIterator);
9693
9694 Context context = queue.getInfo<CL_QUEUE_CONTEXT>();
9695
9696 if (useHostPtr) {
9697 object_ = ::clCreateBuffer(context(), flags, size, const_cast<DataType*>(&*startIterator), &error);
9698 }
9699 else {
9700 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9701 }
9702
9703 detail::errHandler(error, __CREATE_BUFFER_ERR);
9704 if (err != nullptr) {
9705 *err = error;
9706 }
9707
9708 if (!useHostPtr) {
9709 error = cl::copy(queue, startIterator, endIterator, *this);
9710 detail::errHandler(error, __CREATE_BUFFER_ERR);
9711 if (err != nullptr) {
9712 *err = error;
9713 }
9714 }
9715}
9716
9717inline cl_int enqueueReadBuffer(
9718 const Buffer& buffer,
9719 cl_bool blocking,
9720 size_type offset,
9721 size_type size,
9722 void* ptr,
9723 const vector<Event>* events = nullptr,
9724 Event* event = nullptr)
9725{
9726 cl_int error;
9727 CommandQueue queue = CommandQueue::getDefault(&error);
9728
9729 if (error != CL_SUCCESS) {
9730 return error;
9731 }
9732
9733 return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event);
9734}
9735
9736inline cl_int enqueueWriteBuffer(
9737 const Buffer& buffer,
9738 cl_bool blocking,
9739 size_type offset,
9740 size_type size,
9741 const void* ptr,
9742 const vector<Event>* events = nullptr,
9743 Event* event = nullptr)
9744{
9745 cl_int error;
9746 CommandQueue queue = CommandQueue::getDefault(&error);
9747
9748 if (error != CL_SUCCESS) {
9749 return error;
9750 }
9751
9752 return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event);
9753}
9754
9755inline void* enqueueMapBuffer(
9756 const Buffer& buffer,
9757 cl_bool blocking,
9758 cl_map_flags flags,
9759 size_type offset,
9760 size_type size,
9761 const vector<Event>* events = nullptr,
9762 Event* event = nullptr,
9763 cl_int* err = nullptr)
9764{
9765 cl_int error;
9766 CommandQueue queue = CommandQueue::getDefault(&error);
9767 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9768 if (err != nullptr) {
9769 *err = error;
9770 }
9771
9772 void * result = ::clEnqueueMapBuffer(
9773 queue(), buffer(), blocking, flags, offset, size,
9774 (events != nullptr) ? (cl_uint) events->size() : 0,
9775 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
9776 (cl_event*) event,
9777 &error);
9778
9779 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9780 if (err != nullptr) {
9781 *err = error;
9782 }
9783 return result;
9784}
9785
9786
9787#if CL_HPP_TARGET_OPENCL_VERSION >= 200
9793template<typename T>
9794inline cl_int enqueueMapSVM(
9795 T* ptr,
9796 cl_bool blocking,
9797 cl_map_flags flags,
9798 size_type size,
9799 const vector<Event>* events,
9800 Event* event)
9801{
9802 cl_int error;
9803 CommandQueue queue = CommandQueue::getDefault(&error);
9804 if (error != CL_SUCCESS) {
9805 return detail::errHandler(error, __ENQUEUE_MAP_SVM_ERR);
9806 }
9807
9808 return queue.enqueueMapSVM(
9809 ptr, blocking, flags, size, events, event);
9810}
9811
9817template<typename T, class D>
9818inline cl_int enqueueMapSVM(
9819 cl::pointer<T, D> &ptr,
9820 cl_bool blocking,
9821 cl_map_flags flags,
9822 size_type size,
9823 const vector<Event>* events = nullptr,
9824 Event* event = nullptr)
9825{
9826 cl_int error;
9827 CommandQueue queue = CommandQueue::getDefault(&error);
9828 if (error != CL_SUCCESS) {
9829 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9830 }
9831
9832 return queue.enqueueMapSVM(
9833 ptr, blocking, flags, size, events, event);
9834}
9835
9841template<typename T, class Alloc>
9842inline cl_int enqueueMapSVM(
9843 cl::vector<T, Alloc> &container,
9844 cl_bool blocking,
9845 cl_map_flags flags,
9846 const vector<Event>* events = nullptr,
9847 Event* event = nullptr)
9848{
9849 cl_int error;
9850 CommandQueue queue = CommandQueue::getDefault(&error);
9851 if (error != CL_SUCCESS) {
9852 return detail::errHandler(error, __ENQUEUE_MAP_SVM_ERR);
9853 }
9854
9855 return queue.enqueueMapSVM(
9856 container, blocking, flags, events, event);
9857}
9858
9859#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9860
9861inline cl_int enqueueUnmapMemObject(
9862 const Memory& memory,
9863 void* mapped_ptr,
9864 const vector<Event>* events = nullptr,
9865 Event* event = nullptr)
9866{
9867 cl_int error;
9868 CommandQueue queue = CommandQueue::getDefault(&error);
9869 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9870 if (error != CL_SUCCESS) {
9871 return error;
9872 }
9873
9874 cl_event tmp;
9875 cl_int err = detail::errHandler(
9876 ::clEnqueueUnmapMemObject(
9877 queue(), memory(), mapped_ptr,
9878 (events != nullptr) ? (cl_uint)events->size() : 0,
9879 (events != nullptr && events->size() > 0) ? (cl_event*)&events->front() : nullptr,
9880 (event != nullptr) ? &tmp : nullptr),
9881 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9882
9883 if (event != nullptr && err == CL_SUCCESS)
9884 *event = tmp;
9885
9886 return err;
9887}
9888
9889#if CL_HPP_TARGET_OPENCL_VERSION >= 200
9895template<typename T>
9896inline cl_int enqueueUnmapSVM(
9897 T* ptr,
9898 const vector<Event>* events = nullptr,
9899 Event* event = nullptr)
9900{
9901 cl_int error;
9902 CommandQueue queue = CommandQueue::getDefault(&error);
9903 if (error != CL_SUCCESS) {
9904 return detail::errHandler(error, __ENQUEUE_UNMAP_SVM_ERR);
9905 }
9906
9907 return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
9908 __ENQUEUE_UNMAP_SVM_ERR);
9909
9910}
9911
9917template<typename T, class D>
9918inline cl_int enqueueUnmapSVM(
9919 cl::pointer<T, D> &ptr,
9920 const vector<Event>* events = nullptr,
9921 Event* event = nullptr)
9922{
9923 cl_int error;
9924 CommandQueue queue = CommandQueue::getDefault(&error);
9925 if (error != CL_SUCCESS) {
9926 return detail::errHandler(error, __ENQUEUE_UNMAP_SVM_ERR);
9927 }
9928
9929 return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
9930 __ENQUEUE_UNMAP_SVM_ERR);
9931}
9932
9938template<typename T, class Alloc>
9939inline cl_int enqueueUnmapSVM(
9940 cl::vector<T, Alloc> &container,
9941 const vector<Event>* events = nullptr,
9942 Event* event = nullptr)
9943{
9944 cl_int error;
9945 CommandQueue queue = CommandQueue::getDefault(&error);
9946 if (error != CL_SUCCESS) {
9947 return detail::errHandler(error, __ENQUEUE_UNMAP_SVM_ERR);
9948 }
9949
9950 return detail::errHandler(queue.enqueueUnmapSVM(container, events, event),
9951 __ENQUEUE_UNMAP_SVM_ERR);
9952}
9953
9954#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9955
9956inline cl_int enqueueCopyBuffer(
9957 const Buffer& src,
9958 const Buffer& dst,
9959 size_type src_offset,
9960 size_type dst_offset,
9961 size_type size,
9962 const vector<Event>* events = nullptr,
9963 Event* event = nullptr)
9964{
9965 cl_int error;
9966 CommandQueue queue = CommandQueue::getDefault(&error);
9967
9968 if (error != CL_SUCCESS) {
9969 return error;
9970 }
9971
9972 return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event);
9973}
9974
9980template< typename IteratorType >
9981inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
9982{
9983 cl_int error;
9984 CommandQueue queue = CommandQueue::getDefault(&error);
9985 if (error != CL_SUCCESS)
9986 return error;
9987
9988 return cl::copy(queue, startIterator, endIterator, buffer);
9989}
9990
9996template< typename IteratorType >
9997inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
9998{
9999 cl_int error;
10000 CommandQueue queue = CommandQueue::getDefault(&error);
10001 if (error != CL_SUCCESS)
10002 return error;
10003
10004 return cl::copy(queue, buffer, startIterator, endIterator);
10005}
10006
10012template< typename IteratorType >
10013inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
10014{
10015 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
10016 cl_int error;
10017
10018 size_type length = endIterator-startIterator;
10019 size_type byteLength = length*sizeof(DataType);
10020
10021 DataType *pointer =
10022 static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error));
10023 // if exceptions enabled, enqueueMapBuffer will throw
10024 if( error != CL_SUCCESS ) {
10025 return error;
10026 }
10027#if defined(_MSC_VER)
10028 std::copy(
10029 startIterator,
10030 endIterator,
10031 stdext::checked_array_iterator<DataType*>(
10032 pointer, length));
10033#else
10034 std::copy(startIterator, endIterator, pointer);
10035#endif
10036 Event endEvent;
10037 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
10038 // if exceptions enabled, enqueueUnmapMemObject will throw
10039 if( error != CL_SUCCESS ) {
10040 return error;
10041 }
10042 endEvent.wait();
10043 return CL_SUCCESS;
10044}
10045
10051template< typename IteratorType >
10052inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
10053{
10054 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
10055 cl_int error;
10056
10057 size_type length = endIterator-startIterator;
10058 size_type byteLength = length*sizeof(DataType);
10059
10060 DataType *pointer =
10061 static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error));
10062 // if exceptions enabled, enqueueMapBuffer will throw
10063 if( error != CL_SUCCESS ) {
10064 return error;
10065 }
10066 std::copy(pointer, pointer + length, startIterator);
10067 Event endEvent;
10068 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
10069 // if exceptions enabled, enqueueUnmapMemObject will throw
10070 if( error != CL_SUCCESS ) {
10071 return error;
10072 }
10073 endEvent.wait();
10074 return CL_SUCCESS;
10075}
10076
10077
10078#if CL_HPP_TARGET_OPENCL_VERSION >= 200
10082template<typename T, class Alloc>
10083inline cl_int mapSVM(cl::vector<T, Alloc> &container)
10084{
10085 return enqueueMapSVM(container, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE);
10086}
10087
10091template<typename T, class Alloc>
10092inline cl_int unmapSVM(cl::vector<T, Alloc> &container)
10093{
10094 return enqueueUnmapSVM(container);
10095}
10096
10097#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10098
10099#if CL_HPP_TARGET_OPENCL_VERSION >= 110
10100inline cl_int enqueueReadBufferRect(
10101 const Buffer& buffer,
10102 cl_bool blocking,
10103 const array<size_type, 3>& buffer_offset,
10104 const array<size_type, 3>& host_offset,
10105 const array<size_type, 3>& region,
10106 size_type buffer_row_pitch,
10107 size_type buffer_slice_pitch,
10108 size_type host_row_pitch,
10109 size_type host_slice_pitch,
10110 void *ptr,
10111 const vector<Event>* events = nullptr,
10112 Event* event = nullptr)
10113{
10114 cl_int error;
10115 CommandQueue queue = CommandQueue::getDefault(&error);
10116
10117 if (error != CL_SUCCESS) {
10118 return error;
10119 }
10120
10121 return queue.enqueueReadBufferRect(
10122 buffer,
10123 blocking,
10124 buffer_offset,
10125 host_offset,
10126 region,
10127 buffer_row_pitch,
10128 buffer_slice_pitch,
10129 host_row_pitch,
10130 host_slice_pitch,
10131 ptr,
10132 events,
10133 event);
10134}
10135
10136inline cl_int enqueueReadBufferRect(
10137 const Buffer& buffer,
10138 cl_bool blocking,
10139 const array<size_type, 2>& buffer_offset,
10140 const array<size_type, 2>& host_offset,
10141 const array<size_type, 2>& region,
10142 size_type buffer_row_pitch,
10143 size_type buffer_slice_pitch,
10144 size_type host_row_pitch,
10145 size_type host_slice_pitch,
10146 void* ptr,
10147 const vector<Event>* events = nullptr,
10148 Event* event = nullptr)
10149{
10150 return enqueueReadBufferRect(
10151 buffer,
10152 blocking,
10153 { buffer_offset[0], buffer_offset[1], 0 },
10154 { host_offset[0], host_offset[1], 0 },
10155 { region[0], region[1], 1 },
10156 buffer_row_pitch,
10157 buffer_slice_pitch,
10158 host_row_pitch,
10159 host_slice_pitch,
10160 ptr,
10161 events,
10162 event);
10163}
10164
10165inline cl_int enqueueWriteBufferRect(
10166 const Buffer& buffer,
10167 cl_bool blocking,
10168 const array<size_type, 3>& buffer_offset,
10169 const array<size_type, 3>& host_offset,
10170 const array<size_type, 3>& region,
10171 size_type buffer_row_pitch,
10172 size_type buffer_slice_pitch,
10173 size_type host_row_pitch,
10174 size_type host_slice_pitch,
10175 const void *ptr,
10176 const vector<Event>* events = nullptr,
10177 Event* event = nullptr)
10178{
10179 cl_int error;
10180 CommandQueue queue = CommandQueue::getDefault(&error);
10181
10182 if (error != CL_SUCCESS) {
10183 return error;
10184 }
10185
10186 return queue.enqueueWriteBufferRect(
10187 buffer,
10188 blocking,
10189 buffer_offset,
10190 host_offset,
10191 region,
10192 buffer_row_pitch,
10193 buffer_slice_pitch,
10194 host_row_pitch,
10195 host_slice_pitch,
10196 ptr,
10197 events,
10198 event);
10199}
10200
10201inline cl_int enqueueWriteBufferRect(
10202 const Buffer& buffer,
10203 cl_bool blocking,
10204 const array<size_type, 2>& buffer_offset,
10205 const array<size_type, 2>& host_offset,
10206 const array<size_type, 2>& region,
10207 size_type buffer_row_pitch,
10208 size_type buffer_slice_pitch,
10209 size_type host_row_pitch,
10210 size_type host_slice_pitch,
10211 const void* ptr,
10212 const vector<Event>* events = nullptr,
10213 Event* event = nullptr)
10214{
10215 return enqueueWriteBufferRect(
10216 buffer,
10217 blocking,
10218 { buffer_offset[0], buffer_offset[1], 0 },
10219 { host_offset[0], host_offset[1], 0 },
10220 { region[0], region[1], 1 },
10221 buffer_row_pitch,
10222 buffer_slice_pitch,
10223 host_row_pitch,
10224 host_slice_pitch,
10225 ptr,
10226 events,
10227 event);
10228}
10229
10230inline cl_int enqueueCopyBufferRect(
10231 const Buffer& src,
10232 const Buffer& dst,
10233 const array<size_type, 3>& src_origin,
10234 const array<size_type, 3>& dst_origin,
10235 const array<size_type, 3>& region,
10236 size_type src_row_pitch,
10237 size_type src_slice_pitch,
10238 size_type dst_row_pitch,
10239 size_type dst_slice_pitch,
10240 const vector<Event>* events = nullptr,
10241 Event* event = nullptr)
10242{
10243 cl_int error;
10244 CommandQueue queue = CommandQueue::getDefault(&error);
10245
10246 if (error != CL_SUCCESS) {
10247 return error;
10248 }
10249
10250 return queue.enqueueCopyBufferRect(
10251 src,
10252 dst,
10253 src_origin,
10254 dst_origin,
10255 region,
10256 src_row_pitch,
10257 src_slice_pitch,
10258 dst_row_pitch,
10259 dst_slice_pitch,
10260 events,
10261 event);
10262}
10263
10264inline cl_int enqueueCopyBufferRect(
10265 const Buffer& src,
10266 const Buffer& dst,
10267 const array<size_type, 2>& src_origin,
10268 const array<size_type, 2>& dst_origin,
10269 const array<size_type, 2>& region,
10270 size_type src_row_pitch,
10271 size_type src_slice_pitch,
10272 size_type dst_row_pitch,
10273 size_type dst_slice_pitch,
10274 const vector<Event>* events = nullptr,
10275 Event* event = nullptr)
10276{
10277 return enqueueCopyBufferRect(
10278 src,
10279 dst,
10280 { src_origin[0], src_origin[1], 0 },
10281 { dst_origin[0], dst_origin[1], 0 },
10282 { region[0], region[1], 1 },
10283 src_row_pitch,
10284 src_slice_pitch,
10285 dst_row_pitch,
10286 dst_slice_pitch,
10287 events,
10288 event);
10289}
10290#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
10291
10292inline cl_int enqueueReadImage(
10293 const Image& image,
10294 cl_bool blocking,
10295 const array<size_type, 3>& origin,
10296 const array<size_type, 3>& region,
10297 size_type row_pitch,
10298 size_type slice_pitch,
10299 void* ptr,
10300 const vector<Event>* events = nullptr,
10301 Event* event = nullptr)
10302{
10303 cl_int error;
10304 CommandQueue queue = CommandQueue::getDefault(&error);
10305
10306 if (error != CL_SUCCESS) {
10307 return error;
10308 }
10309
10310 return queue.enqueueReadImage(
10311 image,
10312 blocking,
10313 origin,
10314 region,
10315 row_pitch,
10316 slice_pitch,
10317 ptr,
10318 events,
10319 event);
10320}
10321
10322inline cl_int enqueueReadImage(
10323 const Image& image,
10324 cl_bool blocking,
10325 const array<size_type, 2>& origin,
10326 const array<size_type, 2>& region,
10327 size_type row_pitch,
10328 size_type slice_pitch,
10329 void* ptr,
10330 const vector<Event>* events = nullptr,
10331 Event* event = nullptr)
10332{
10333 return enqueueReadImage(
10334 image,
10335 blocking,
10336 { origin[0], origin[1], 0 },
10337 { region[0], region[1], 1 },
10338 row_pitch,
10339 slice_pitch,
10340 ptr,
10341 events,
10342 event);
10343}
10344
10345inline cl_int enqueueWriteImage(
10346 const Image& image,
10347 cl_bool blocking,
10348 const array<size_type, 3>& origin,
10349 const array<size_type, 3>& region,
10350 size_type row_pitch,
10351 size_type slice_pitch,
10352 const void* ptr,
10353 const vector<Event>* events = nullptr,
10354 Event* event = nullptr)
10355{
10356 cl_int error;
10357 CommandQueue queue = CommandQueue::getDefault(&error);
10358
10359 if (error != CL_SUCCESS) {
10360 return error;
10361 }
10362
10363 return queue.enqueueWriteImage(
10364 image,
10365 blocking,
10366 origin,
10367 region,
10368 row_pitch,
10369 slice_pitch,
10370 ptr,
10371 events,
10372 event);
10373}
10374
10375inline cl_int enqueueWriteImage(
10376 const Image& image,
10377 cl_bool blocking,
10378 const array<size_type, 2>& origin,
10379 const array<size_type, 2>& region,
10380 size_type row_pitch,
10381 size_type slice_pitch,
10382 const void* ptr,
10383 const vector<Event>* events = nullptr,
10384 Event* event = nullptr)
10385{
10386 return enqueueWriteImage(
10387 image,
10388 blocking,
10389 { origin[0], origin[1], 0 },
10390 { region[0], region[1], 1 },
10391 row_pitch,
10392 slice_pitch,
10393 ptr,
10394 events,
10395 event);
10396}
10397
10398inline cl_int enqueueCopyImage(
10399 const Image& src,
10400 const Image& dst,
10401 const array<size_type, 3>& src_origin,
10402 const array<size_type, 3>& dst_origin,
10403 const array<size_type, 3>& region,
10404 const vector<Event>* events = nullptr,
10405 Event* event = nullptr)
10406{
10407 cl_int error;
10408 CommandQueue queue = CommandQueue::getDefault(&error);
10409
10410 if (error != CL_SUCCESS) {
10411 return error;
10412 }
10413
10414 return queue.enqueueCopyImage(
10415 src,
10416 dst,
10417 src_origin,
10418 dst_origin,
10419 region,
10420 events,
10421 event);
10422}
10423
10424inline cl_int enqueueCopyImage(
10425 const Image& src,
10426 const Image& dst,
10427 const array<size_type, 2>& src_origin,
10428 const array<size_type, 2>& dst_origin,
10429 const array<size_type, 2>& region,
10430 const vector<Event>* events = nullptr,
10431 Event* event = nullptr)
10432{
10433 return enqueueCopyImage(
10434 src,
10435 dst,
10436 { src_origin[0], src_origin[1], 0 },
10437 { dst_origin[0], dst_origin[1], 0 },
10438 { region[0], region[1], 1 },
10439 events,
10440 event);
10441}
10442
10443inline cl_int enqueueCopyImageToBuffer(
10444 const Image& src,
10445 const Buffer& dst,
10446 const array<size_type, 3>& src_origin,
10447 const array<size_type, 3>& region,
10448 size_type dst_offset,
10449 const vector<Event>* events = nullptr,
10450 Event* event = nullptr)
10451{
10452 cl_int error;
10453 CommandQueue queue = CommandQueue::getDefault(&error);
10454
10455 if (error != CL_SUCCESS) {
10456 return error;
10457 }
10458
10459 return queue.enqueueCopyImageToBuffer(
10460 src,
10461 dst,
10462 src_origin,
10463 region,
10464 dst_offset,
10465 events,
10466 event);
10467}
10468
10469inline cl_int enqueueCopyImageToBuffer(
10470 const Image& src,
10471 const Buffer& dst,
10472 const array<size_type, 2>& src_origin,
10473 const array<size_type, 2>& region,
10474 size_type dst_offset,
10475 const vector<Event>* events = nullptr,
10476 Event* event = nullptr)
10477{
10478 return enqueueCopyImageToBuffer(
10479 src,
10480 dst,
10481 { src_origin[0], src_origin[1], 0 },
10482 { region[0], region[1], 1 },
10483 dst_offset,
10484 events,
10485 event);
10486}
10487
10488inline cl_int enqueueCopyBufferToImage(
10489 const Buffer& src,
10490 const Image& dst,
10491 size_type src_offset,
10492 const array<size_type, 3>& dst_origin,
10493 const array<size_type, 3>& region,
10494 const vector<Event>* events = nullptr,
10495 Event* event = nullptr)
10496{
10497 cl_int error;
10498 CommandQueue queue = CommandQueue::getDefault(&error);
10499
10500 if (error != CL_SUCCESS) {
10501 return error;
10502 }
10503
10504 return queue.enqueueCopyBufferToImage(
10505 src,
10506 dst,
10507 src_offset,
10508 dst_origin,
10509 region,
10510 events,
10511 event);
10512}
10513
10514inline cl_int enqueueCopyBufferToImage(
10515 const Buffer& src,
10516 const Image& dst,
10517 size_type src_offset,
10518 const array<size_type, 2>& dst_origin,
10519 const array<size_type, 2>& region,
10520 const vector<Event>* events = nullptr,
10521 Event* event = nullptr)
10522{
10523 cl_int error;
10524 CommandQueue queue = CommandQueue::getDefault(&error);
10525
10526 if (error != CL_SUCCESS) {
10527 return error;
10528 }
10529
10530 return enqueueCopyBufferToImage(
10531 src,
10532 dst,
10533 src_offset,
10534 { dst_origin[0], dst_origin[1], 0 },
10535 { region[0], region[1], 1 },
10536 events,
10537 event);
10538}
10539
10540inline cl_int flush(void)
10541{
10542 cl_int error;
10543 CommandQueue queue = CommandQueue::getDefault(&error);
10544
10545 if (error != CL_SUCCESS) {
10546 return error;
10547 }
10548
10549 return queue.flush();
10550}
10551
10552inline cl_int finish(void)
10553{
10554 cl_int error;
10555 CommandQueue queue = CommandQueue::getDefault(&error);
10556
10557 if (error != CL_SUCCESS) {
10558 return error;
10559 }
10560
10562 return queue.finish();
10563}
10564
10565class EnqueueArgs
10566{
10567private:
10568 CommandQueue queue_;
10569 const NDRange offset_;
10570 const NDRange global_;
10571 const NDRange local_;
10572 vector<Event> events_;
10573
10574 template<typename... Ts>
10575 friend class KernelFunctor;
10576
10577public:
10578 EnqueueArgs(NDRange global) :
10579 queue_(CommandQueue::getDefault()),
10580 offset_(NullRange),
10581 global_(global),
10582 local_(NullRange)
10583 {
10584
10585 }
10586
10587 EnqueueArgs(NDRange global, NDRange local) :
10588 queue_(CommandQueue::getDefault()),
10589 offset_(NullRange),
10590 global_(global),
10591 local_(local)
10592 {
10593
10594 }
10595
10596 EnqueueArgs(NDRange offset, NDRange global, NDRange local) :
10597 queue_(CommandQueue::getDefault()),
10598 offset_(offset),
10599 global_(global),
10600 local_(local)
10601 {
10602
10603 }
10604
10605 EnqueueArgs(Event e, NDRange global) :
10606 queue_(CommandQueue::getDefault()),
10607 offset_(NullRange),
10608 global_(global),
10609 local_(NullRange)
10610 {
10611 events_.push_back(e);
10612 }
10613
10614 EnqueueArgs(Event e, NDRange global, NDRange local) :
10615 queue_(CommandQueue::getDefault()),
10616 offset_(NullRange),
10617 global_(global),
10618 local_(local)
10619 {
10620 events_.push_back(e);
10621 }
10622
10623 EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) :
10624 queue_(CommandQueue::getDefault()),
10625 offset_(offset),
10626 global_(global),
10627 local_(local)
10628 {
10629 events_.push_back(e);
10630 }
10631
10632 EnqueueArgs(const vector<Event> &events, NDRange global) :
10633 queue_(CommandQueue::getDefault()),
10634 offset_(NullRange),
10635 global_(global),
10636 local_(NullRange),
10637 events_(events)
10638 {
10639
10640 }
10641
10642 EnqueueArgs(const vector<Event> &events, NDRange global, NDRange local) :
10643 queue_(CommandQueue::getDefault()),
10644 offset_(NullRange),
10645 global_(global),
10646 local_(local),
10647 events_(events)
10648 {
10649
10650 }
10651
10652 EnqueueArgs(const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
10653 queue_(CommandQueue::getDefault()),
10654 offset_(offset),
10655 global_(global),
10656 local_(local),
10657 events_(events)
10658 {
10659
10660 }
10661
10662 EnqueueArgs(CommandQueue &queue, NDRange global) :
10663 queue_(queue),
10664 offset_(NullRange),
10665 global_(global),
10666 local_(NullRange)
10667 {
10668
10669 }
10670
10671 EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) :
10672 queue_(queue),
10673 offset_(NullRange),
10674 global_(global),
10675 local_(local)
10676 {
10677
10678 }
10679
10680 EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) :
10681 queue_(queue),
10682 offset_(offset),
10683 global_(global),
10684 local_(local)
10685 {
10686
10687 }
10688
10689 EnqueueArgs(CommandQueue &queue, Event e, NDRange global) :
10690 queue_(queue),
10691 offset_(NullRange),
10692 global_(global),
10693 local_(NullRange)
10694 {
10695 events_.push_back(e);
10696 }
10697
10698 EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) :
10699 queue_(queue),
10700 offset_(NullRange),
10701 global_(global),
10702 local_(local)
10703 {
10704 events_.push_back(e);
10705 }
10706
10707 EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) :
10708 queue_(queue),
10709 offset_(offset),
10710 global_(global),
10711 local_(local)
10712 {
10713 events_.push_back(e);
10714 }
10715
10716 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global) :
10717 queue_(queue),
10718 offset_(NullRange),
10719 global_(global),
10720 local_(NullRange),
10721 events_(events)
10722 {
10723
10724 }
10725
10726 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global, NDRange local) :
10727 queue_(queue),
10728 offset_(NullRange),
10729 global_(global),
10730 local_(local),
10731 events_(events)
10732 {
10733
10734 }
10735
10736 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
10737 queue_(queue),
10738 offset_(offset),
10739 global_(global),
10740 local_(local),
10741 events_(events)
10742 {
10743
10744 }
10745};
10746
10747
10748//----------------------------------------------------------------------------------------------
10749
10750
10755template<typename... Ts>
10756class KernelFunctor
10757{
10758private:
10759 Kernel kernel_;
10760
10761 template<int index, typename T0, typename... T1s>
10762 void setArgs(T0&& t0, T1s&&... t1s)
10763 {
10764 kernel_.setArg(index, t0);
10765 setArgs<index + 1, T1s...>(std::forward<T1s>(t1s)...);
10766 }
10767
10768 template<int index, typename T0>
10769 void setArgs(T0&& t0)
10770 {
10771 kernel_.setArg(index, t0);
10772 }
10773
10774 template<int index>
10775 void setArgs()
10776 {
10777 }
10778
10779
10780public:
10781 KernelFunctor(Kernel kernel) : kernel_(kernel)
10782 {}
10783
10784 KernelFunctor(
10785 const Program& program,
10786 const string name,
10787 cl_int * err = nullptr) :
10788 kernel_(program, name.c_str(), err)
10789 {}
10790
10792 typedef Event result_type;
10793
10800 const EnqueueArgs& args,
10801 Ts... ts)
10802 {
10803 Event event;
10804 setArgs<0>(std::forward<Ts>(ts)...);
10805
10806 args.queue_.enqueueNDRangeKernel(
10807 kernel_,
10808 args.offset_,
10809 args.global_,
10810 args.local_,
10811 &args.events_,
10812 &event);
10813
10814 return event;
10815 }
10816
10823 Event operator() (
10824 const EnqueueArgs& args,
10825 Ts... ts,
10826 cl_int &error)
10827 {
10828 Event event;
10829 setArgs<0>(std::forward<Ts>(ts)...);
10830
10831 error = args.queue_.enqueueNDRangeKernel(
10832 kernel_,
10833 args.offset_,
10834 args.global_,
10835 args.local_,
10836 &args.events_,
10837 &event);
10838
10839 return event;
10840 }
10841
10842#if CL_HPP_TARGET_OPENCL_VERSION >= 200
10843 cl_int setSVMPointers(const vector<void*> &pointerList)
10844 {
10845 return kernel_.setSVMPointers(pointerList);
10846 }
10847
10848 template<typename T0, typename... T1s>
10849 cl_int setSVMPointers(const T0 &t0, T1s &... ts)
10850 {
10851 return kernel_.setSVMPointers(t0, ts...);
10852 }
10853#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10854
10855 Kernel getKernel()
10856 {
10857 return kernel_;
10858 }
10859};
10860
10861namespace compatibility {
10866 template<typename... Ts>
10867 struct make_kernel
10868 {
10869 typedef KernelFunctor<Ts...> FunctorType;
10870
10871 FunctorType functor_;
10872
10873 make_kernel(
10874 const Program& program,
10875 const string name,
10876 cl_int * err = nullptr) :
10877 functor_(FunctorType(program, name, err))
10878 {}
10879
10880 make_kernel(
10881 const Kernel kernel) :
10882 functor_(FunctorType(kernel))
10883 {}
10884
10886 typedef Event result_type;
10887
10889 typedef Event type_(
10890 const EnqueueArgs&,
10891 Ts...);
10892
10893 Event operator()(
10894 const EnqueueArgs& enqueueArgs,
10895 Ts... args)
10896 {
10897 return functor_(
10898 enqueueArgs, args...);
10899 }
10900 };
10901} // namespace compatibility
10902
10903#ifdef cl_khr_semaphore
10904
10905#ifdef cl_khr_external_semaphore
10906enum ExternalSemaphoreType : cl_external_semaphore_handle_type_khr
10907{
10908 None = 0,
10909#ifdef cl_khr_external_semaphore_dx_fence
10910 D3D12Fence = CL_SEMAPHORE_HANDLE_D3D12_FENCE_KHR,
10911#endif
10912#ifdef cl_khr_external_semaphore_opaque_fd
10913 OpaqueFd = CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR,
10914#endif
10915#ifdef cl_khr_external_semaphore_sync_fd
10916 SyncFd = CL_SEMAPHORE_HANDLE_SYNC_FD_KHR,
10917#endif
10918#ifdef cl_khr_external_semaphore_win32
10919 OpaqueWin32 = CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR,
10920 OpaqueWin32Kmt = CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KMT_KHR,
10921#endif // cl_khr_external_semaphore_win32
10922};
10923#endif // cl_khr_external_semaphore
10924
10925class Semaphore : public detail::Wrapper<cl_semaphore_khr>
10926{
10927public:
10928 Semaphore() : detail::Wrapper<cl_type>() {}
10929 Semaphore(
10930 const Context &context,
10931 const vector<cl_semaphore_properties_khr>& sema_props,
10932 cl_int *err = nullptr)
10933 {
10934 /* initialization of addresses to extension functions (it is done only once) */
10935 std::call_once(ext_init_, initExtensions, context);
10936
10937 cl_int error = CL_INVALID_OPERATION;
10938
10939 if (pfn_clCreateSemaphoreWithPropertiesKHR)
10940 {
10941 object_ = pfn_clCreateSemaphoreWithPropertiesKHR(
10942 context(),
10943 sema_props.data(),
10944 &error);
10945 }
10946
10947 detail::errHandler(error, __CREATE_SEMAPHORE_KHR_WITH_PROPERTIES_ERR);
10948
10949 if (err != nullptr) {
10950 *err = error;
10951 }
10952 }
10953 Semaphore(
10954 const vector<cl_semaphore_properties_khr>& sema_props,
10955 cl_int* err = nullptr):Semaphore(Context::getDefault(err), sema_props, err) {}
10956
10957 explicit Semaphore(const cl_semaphore_khr& semaphore, bool retainObject = false) :
10958 detail::Wrapper<cl_type>(semaphore, retainObject) {}
10959 Semaphore& operator = (const cl_semaphore_khr& rhs) {
10960 detail::Wrapper<cl_type>::operator=(rhs);
10961 return *this;
10962 }
10963 template <typename T>
10964 cl_int getInfo(cl_semaphore_info_khr name, T* param) const
10965 {
10966 if (pfn_clGetSemaphoreInfoKHR == nullptr) {
10967 return detail::errHandler(CL_INVALID_OPERATION,
10968 __GET_SEMAPHORE_KHR_INFO_ERR);
10969 }
10970
10971 return detail::errHandler(
10972 detail::getInfo(pfn_clGetSemaphoreInfoKHR, object_, name, param),
10973 __GET_SEMAPHORE_KHR_INFO_ERR);
10974 }
10975 template <cl_semaphore_info_khr name> typename
10976 detail::param_traits<detail::cl_semaphore_info_khr, name>::param_type
10977 getInfo(cl_int* err = nullptr) const
10978 {
10979 typename detail::param_traits<
10980 detail::cl_semaphore_info_khr, name>::param_type param;
10981 cl_int result = getInfo(name, &param);
10982 if (err != nullptr) {
10983 *err = result;
10984 }
10985 return param;
10986 }
10987
10988#ifdef cl_khr_external_semaphore
10989 template <typename T>
10990 cl_int getHandleForTypeKHR(
10991 const Device& device, cl_external_semaphore_handle_type_khr name, T* param) const
10992 {
10993 if (pfn_clGetSemaphoreHandleForTypeKHR == nullptr) {
10994 return detail::errHandler(CL_INVALID_OPERATION,
10995 __GET_SEMAPHORE_HANDLE_FOR_TYPE_KHR_ERR);
10996 }
10997
10998 return detail::errHandler(
10999 detail::getInfo(
11000 pfn_clGetSemaphoreHandleForTypeKHR, object_, device(), name, param),
11001 __GET_SEMAPHORE_HANDLE_FOR_TYPE_KHR_ERR);
11002 }
11003
11004 template <cl_external_semaphore_handle_type_khr type> typename
11005 detail::param_traits<detail::cl_external_semaphore_handle_type_khr, type>::param_type
11006 getHandleForTypeKHR(const Device& device, cl_int* err = nullptr) const
11007 {
11008 typename detail::param_traits<
11009 detail::cl_external_semaphore_handle_type_khr, type>::param_type param;
11010 cl_int result = getHandleForTypeKHR(device, type, &param);
11011 if (err != nullptr) {
11012 *err = result;
11013 }
11014 return param;
11015 }
11016#endif // cl_khr_external_semaphore
11017
11018 cl_int retain()
11019 {
11020 if (pfn_clRetainSemaphoreKHR == nullptr) {
11021 return detail::errHandler(CL_INVALID_OPERATION,
11022 __RETAIN_SEMAPHORE_KHR_ERR);
11023 }
11024 return pfn_clRetainSemaphoreKHR(object_);
11025 }
11026
11027 cl_int release()
11028 {
11029 if (pfn_clReleaseSemaphoreKHR == nullptr) {
11030 return detail::errHandler(CL_INVALID_OPERATION,
11031 __RELEASE_SEMAPHORE_KHR_ERR);
11032 }
11033 return pfn_clReleaseSemaphoreKHR(object_);
11034 }
11035
11036private:
11037 static std::once_flag ext_init_;
11038
11039 static void initExtensions(const Context& context)
11040 {
11041#if CL_HPP_TARGET_OPENCL_VERSION >= 120
11042 Device device = context.getInfo<CL_CONTEXT_DEVICES>().at(0);
11043 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>()();
11044 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateSemaphoreWithPropertiesKHR);
11045 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clReleaseSemaphoreKHR);
11046 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clRetainSemaphoreKHR);
11047 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueWaitSemaphoresKHR);
11048 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueSignalSemaphoresKHR);
11049 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clGetSemaphoreInfoKHR);
11050#ifdef cl_khr_external_semaphore
11051 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clGetSemaphoreHandleForTypeKHR);
11052#endif // cl_khr_external_semaphore
11053
11054#else
11055 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSemaphoreWithPropertiesKHR);
11056 CL_HPP_INIT_CL_EXT_FCN_PTR_(clReleaseSemaphoreKHR);
11057 CL_HPP_INIT_CL_EXT_FCN_PTR_(clRetainSemaphoreKHR);
11058 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueWaitSemaphoresKHR);
11059 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueSignalSemaphoresKHR);
11060 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetSemaphoreInfoKHR);
11061#ifdef cl_khr_external_semaphore
11062 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetSemaphoreHandleForTypeKHR);
11063#endif // cl_khr_external_semaphore
11064
11065#endif
11066 if ((pfn_clCreateSemaphoreWithPropertiesKHR == nullptr) &&
11067 (pfn_clReleaseSemaphoreKHR == nullptr) &&
11068 (pfn_clRetainSemaphoreKHR == nullptr) &&
11069 (pfn_clEnqueueWaitSemaphoresKHR == nullptr) &&
11070 (pfn_clEnqueueSignalSemaphoresKHR == nullptr) &&
11071#ifdef cl_khr_external_semaphore
11072 (pfn_clGetSemaphoreHandleForTypeKHR == nullptr) &&
11073#endif // cl_khr_external_semaphore
11074 (pfn_clGetSemaphoreInfoKHR == nullptr))
11075 {
11076 detail::errHandler(CL_INVALID_VALUE, __CREATE_SEMAPHORE_KHR_WITH_PROPERTIES_ERR);
11077 }
11078 }
11079
11080};
11081
11082CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Semaphore::ext_init_;
11083
11084inline cl_int CommandQueue::enqueueWaitSemaphores(
11085 const vector<Semaphore> &sema_objects,
11086 const vector<cl_semaphore_payload_khr> &sema_payloads,
11087 const vector<Event>* events_wait_list,
11088 Event *event) const
11089{
11090 cl_event tmp;
11091 cl_int err = CL_INVALID_OPERATION;
11092
11093 if (pfn_clEnqueueWaitSemaphoresKHR != nullptr) {
11094 err = pfn_clEnqueueWaitSemaphoresKHR(
11095 object_,
11096 (cl_uint)sema_objects.size(),
11097 (const cl_semaphore_khr *) &sema_objects.front(),
11098 (sema_payloads.size() > 0) ? &sema_payloads.front() : nullptr,
11099 (events_wait_list != nullptr) ? (cl_uint) events_wait_list->size() : 0,
11100 (events_wait_list != nullptr && events_wait_list->size() > 0) ? (cl_event*) &events_wait_list->front() : nullptr,
11101 (event != nullptr) ? &tmp : nullptr);
11102 }
11103
11104 detail::errHandler(err, __ENQUEUE_WAIT_SEMAPHORE_KHR_ERR);
11105
11106 if (event != nullptr && err == CL_SUCCESS)
11107 *event = tmp;
11108
11109 return err;
11110}
11111
11112inline cl_int CommandQueue::enqueueSignalSemaphores(
11113 const vector<Semaphore> &sema_objects,
11114 const vector<cl_semaphore_payload_khr>& sema_payloads,
11115 const vector<Event>* events_wait_list,
11116 Event* event)
11117{
11118 cl_event tmp;
11119 cl_int err = CL_INVALID_OPERATION;
11120
11121 if (pfn_clEnqueueSignalSemaphoresKHR != nullptr) {
11122 err = pfn_clEnqueueSignalSemaphoresKHR(
11123 object_,
11124 (cl_uint)sema_objects.size(),
11125 (const cl_semaphore_khr*) &sema_objects.front(),
11126 (sema_payloads.size() > 0) ? &sema_payloads.front() : nullptr,
11127 (events_wait_list != nullptr) ? (cl_uint) events_wait_list->size() : 0,
11128 (events_wait_list != nullptr && events_wait_list->size() > 0) ? (cl_event*) &events_wait_list->front() : nullptr,
11129 (event != nullptr) ? &tmp : nullptr);
11130 }
11131
11132 detail::errHandler(err, __ENQUEUE_SIGNAL_SEMAPHORE_KHR_ERR);
11133
11134 if (event != nullptr && err == CL_SUCCESS)
11135 *event = tmp;
11136
11137 return err;
11138}
11139
11140#endif // cl_khr_semaphore
11141
11142#if defined(cl_khr_command_buffer)
11146class CommandBufferKhr : public detail::Wrapper<cl_command_buffer_khr>
11147{
11148public:
11150 CommandBufferKhr() : detail::Wrapper<cl_type>() { }
11151
11152 explicit CommandBufferKhr(const vector<CommandQueue> &queues,
11153 cl_command_buffer_properties_khr properties = 0,
11154 cl_int* errcode_ret = nullptr)
11155 {
11156 cl_command_buffer_properties_khr command_buffer_properties[] = {
11157 CL_COMMAND_BUFFER_FLAGS_KHR, properties, 0
11158 };
11159
11160 /* initialization of addresses to extension functions (it is done only once) */
11161 std::call_once(ext_init_, [&] { initExtensions(queues[0].getInfo<CL_QUEUE_DEVICE>()); });
11162 cl_int error = CL_INVALID_OPERATION;
11163
11164 static_assert(sizeof(cl::CommandQueue) == sizeof(cl_command_queue),
11165 "Size of cl::CommandQueue must be equal to size of cl_command_queue");
11166
11167 if (pfn_clCreateCommandBufferKHR)
11168 {
11169 object_ = pfn_clCreateCommandBufferKHR((cl_uint) queues.size(),
11170 (cl_command_queue *) &queues.front(),
11171 command_buffer_properties,
11172 &error);
11173 }
11174
11175 detail::errHandler(error, __CREATE_COMMAND_BUFFER_KHR_ERR);
11176 if (errcode_ret != nullptr) {
11177 *errcode_ret = error;
11178 }
11179 }
11180
11181 explicit CommandBufferKhr(const cl_command_buffer_khr& commandBufferKhr, bool retainObject = false) :
11182 detail::Wrapper<cl_type>(commandBufferKhr, retainObject) { }
11183
11184 CommandBufferKhr& operator=(const cl_command_buffer_khr& rhs)
11185 {
11186 detail::Wrapper<cl_type>::operator=(rhs);
11187 return *this;
11188 }
11189
11190 template <typename T>
11191 cl_int getInfo(cl_command_buffer_info_khr name, T* param) const
11192 {
11193 if (pfn_clGetCommandBufferInfoKHR == nullptr) {
11194 return detail::errHandler(CL_INVALID_OPERATION,
11195 __GET_COMMAND_BUFFER_INFO_KHR_ERR);
11196 }
11197 return detail::errHandler(
11198 detail::getInfo(pfn_clGetCommandBufferInfoKHR, object_, name, param),
11199 __GET_COMMAND_BUFFER_INFO_KHR_ERR);
11200 }
11201
11202 template <cl_command_buffer_info_khr name> typename
11203 detail::param_traits<detail::cl_command_buffer_info_khr, name>::param_type
11204 getInfo(cl_int* err = nullptr) const
11205 {
11206 typename detail::param_traits<
11207 detail::cl_command_buffer_info_khr, name>::param_type param;
11208 cl_int result = getInfo(name, &param);
11209 if (err != nullptr) {
11210 *err = result;
11211 }
11212 return param;
11213 }
11214
11215 cl_int finalizeCommandBuffer() const
11216 {
11217 return detail::errHandler(::clFinalizeCommandBufferKHR(object_), __FINALIZE_COMMAND_BUFFER_KHR_ERR);
11218 }
11219
11220 cl_int enqueueCommandBuffer(vector<CommandQueue> &queues,
11221 const vector<Event>* events = nullptr,
11222 Event* event = nullptr)
11223 {
11224 if (pfn_clEnqueueCommandBufferKHR == nullptr) {
11225 return detail::errHandler(CL_INVALID_OPERATION,
11226 __ENQUEUE_COMMAND_BUFFER_KHR_ERR);
11227 }
11228
11229 static_assert(sizeof(cl::CommandQueue) == sizeof(cl_command_queue),
11230 "Size of cl::CommandQueue must be equal to size of cl_command_queue");
11231
11232 return detail::errHandler(pfn_clEnqueueCommandBufferKHR((cl_uint) queues.size(),
11233 (cl_command_queue *) &queues.front(),
11234 object_,
11235 (events != nullptr) ? (cl_uint) events->size() : 0,
11236 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
11237 (cl_event*) event),
11238 __ENQUEUE_COMMAND_BUFFER_KHR_ERR);
11239 }
11240
11241 cl_int commandBarrierWithWaitList(const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11242 cl_sync_point_khr* sync_point = nullptr,
11243 MutableCommandKhr* mutable_handle = nullptr,
11244 const CommandQueue* command_queue = nullptr)
11245 {
11246 if (pfn_clCommandBarrierWithWaitListKHR == nullptr) {
11247 return detail::errHandler(CL_INVALID_OPERATION,
11248 __COMMAND_BARRIER_WITH_WAIT_LIST_KHR_ERR);
11249 }
11250
11251 cl_sync_point_khr tmp_sync_point;
11252 cl_int error = detail::errHandler(
11253 pfn_clCommandBarrierWithWaitListKHR(object_,
11254 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11255 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11256 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11257 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11258 (cl_mutable_command_khr*) mutable_handle),
11259 __COMMAND_BARRIER_WITH_WAIT_LIST_KHR_ERR);
11260
11261 if (sync_point != nullptr && error == CL_SUCCESS)
11262 *sync_point = tmp_sync_point;
11263
11264 return error;
11265 }
11266
11267 cl_int commandCopyBuffer(const Buffer& src,
11268 const Buffer& dst,
11269 size_type src_offset,
11270 size_type dst_offset,
11271 size_type size,
11272 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11273 cl_sync_point_khr* sync_point = nullptr,
11274 MutableCommandKhr* mutable_handle = nullptr,
11275 const CommandQueue* command_queue = nullptr)
11276 {
11277 if (pfn_clCommandCopyBufferKHR == nullptr) {
11278 return detail::errHandler(CL_INVALID_OPERATION,
11279 __COMMAND_COPY_BUFFER_KHR_ERR);
11280 }
11281
11282 cl_sync_point_khr tmp_sync_point;
11283 cl_int error = detail::errHandler(
11284 pfn_clCommandCopyBufferKHR(object_,
11285 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11286 src(),
11287 dst(),
11288 src_offset,
11289 dst_offset,
11290 size,
11291 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11292 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11293 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11294 (cl_mutable_command_khr*) mutable_handle),
11295 __COMMAND_COPY_BUFFER_KHR_ERR);
11296
11297 if (sync_point != nullptr && error == CL_SUCCESS)
11298 *sync_point = tmp_sync_point;
11299
11300 return error;
11301 }
11302
11303 cl_int commandCopyBufferRect(const Buffer& src,
11304 const Buffer& dst,
11305 const array<size_type, 3>& src_origin,
11306 const array<size_type, 3>& dst_origin,
11307 const array<size_type, 3>& region,
11308 size_type src_row_pitch,
11309 size_type src_slice_pitch,
11310 size_type dst_row_pitch,
11311 size_type dst_slice_pitch,
11312 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11313 cl_sync_point_khr* sync_point = nullptr,
11314 MutableCommandKhr* mutable_handle = nullptr,
11315 const CommandQueue* command_queue = nullptr)
11316 {
11317 if (pfn_clCommandCopyBufferRectKHR == nullptr) {
11318 return detail::errHandler(CL_INVALID_OPERATION,
11319 __COMMAND_COPY_BUFFER_RECT_KHR_ERR);
11320 }
11321
11322 cl_sync_point_khr tmp_sync_point;
11323 cl_int error = detail::errHandler(
11324 pfn_clCommandCopyBufferRectKHR(object_,
11325 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11326 src(),
11327 dst(),
11328 src_origin.data(),
11329 dst_origin.data(),
11330 region.data(),
11331 src_row_pitch,
11332 src_slice_pitch,
11333 dst_row_pitch,
11334 dst_slice_pitch,
11335 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11336 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11337 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11338 (cl_mutable_command_khr*) mutable_handle),
11339 __COMMAND_COPY_BUFFER_RECT_KHR_ERR);
11340
11341 if (sync_point != nullptr && error == CL_SUCCESS)
11342 *sync_point = tmp_sync_point;
11343
11344 return error;
11345 }
11346
11347 cl_int commandCopyBufferToImage(const Buffer& src,
11348 const Image& dst,
11349 size_type src_offset,
11350 const array<size_type, 3>& dst_origin,
11351 const array<size_type, 3>& region,
11352 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11353 cl_sync_point_khr* sync_point = nullptr,
11354 MutableCommandKhr* mutable_handle = nullptr,
11355 const CommandQueue* command_queue = nullptr)
11356 {
11357 if (pfn_clCommandCopyBufferToImageKHR == nullptr) {
11358 return detail::errHandler(CL_INVALID_OPERATION,
11359 __COMMAND_COPY_BUFFER_TO_IMAGE_KHR_ERR);
11360 }
11361
11362 cl_sync_point_khr tmp_sync_point;
11363 cl_int error = detail::errHandler(
11364 pfn_clCommandCopyBufferToImageKHR(object_,
11365 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11366 src(),
11367 dst(),
11368 src_offset,
11369 dst_origin.data(),
11370 region.data(),
11371 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11372 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11373 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11374 (cl_mutable_command_khr*) mutable_handle),
11375 __COMMAND_COPY_BUFFER_TO_IMAGE_KHR_ERR);
11376
11377 if (sync_point != nullptr && error == CL_SUCCESS)
11378 *sync_point = tmp_sync_point;
11379
11380 return error;
11381 }
11382
11383 cl_int commandCopyImage(const Image& src,
11384 const Image& dst,
11385 const array<size_type, 3>& src_origin,
11386 const array<size_type, 3>& dst_origin,
11387 const array<size_type, 3>& region,
11388 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11389 cl_sync_point_khr* sync_point = nullptr,
11390 MutableCommandKhr* mutable_handle = nullptr,
11391 const CommandQueue* command_queue = nullptr)
11392 {
11393 if (pfn_clCommandCopyImageKHR == nullptr) {
11394 return detail::errHandler(CL_INVALID_OPERATION,
11395 __COMMAND_COPY_IMAGE_KHR_ERR);
11396 }
11397
11398 cl_sync_point_khr tmp_sync_point;
11399 cl_int error = detail::errHandler(
11400 pfn_clCommandCopyImageKHR(object_,
11401 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11402 src(),
11403 dst(),
11404 src_origin.data(),
11405 dst_origin.data(),
11406 region.data(),
11407 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11408 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11409 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11410 (cl_mutable_command_khr*) mutable_handle),
11411 __COMMAND_COPY_IMAGE_KHR_ERR);
11412
11413 if (sync_point != nullptr && error == CL_SUCCESS)
11414 *sync_point = tmp_sync_point;
11415
11416 return error;
11417 }
11418
11419 cl_int commandCopyImageToBuffer(const Image& src,
11420 const Buffer& dst,
11421 const array<size_type, 3>& src_origin,
11422 const array<size_type, 3>& region,
11423 size_type dst_offset,
11424 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11425 cl_sync_point_khr* sync_point = nullptr,
11426 MutableCommandKhr* mutable_handle = nullptr,
11427 const CommandQueue* command_queue = nullptr)
11428 {
11429 if (pfn_clCommandCopyImageToBufferKHR == nullptr) {
11430 return detail::errHandler(CL_INVALID_OPERATION,
11431 __COMMAND_COPY_IMAGE_TO_BUFFER_KHR_ERR);
11432 }
11433
11434 cl_sync_point_khr tmp_sync_point;
11435 cl_int error = detail::errHandler(
11436 pfn_clCommandCopyImageToBufferKHR(object_,
11437 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11438 src(),
11439 dst(),
11440 src_origin.data(),
11441 region.data(),
11442 dst_offset,
11443 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11444 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11445 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11446 (cl_mutable_command_khr*) mutable_handle),
11447 __COMMAND_COPY_IMAGE_TO_BUFFER_KHR_ERR);
11448
11449 if (sync_point != nullptr && error == CL_SUCCESS)
11450 *sync_point = tmp_sync_point;
11451
11452 return error;
11453 }
11454
11455 template<typename PatternType>
11456 cl_int commandFillBuffer(const Buffer& buffer,
11457 PatternType pattern,
11458 size_type offset,
11459 size_type size,
11460 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11461 cl_sync_point_khr* sync_point = nullptr,
11462 MutableCommandKhr* mutable_handle = nullptr,
11463 const CommandQueue* command_queue = nullptr)
11464 {
11465 if (pfn_clCommandFillBufferKHR == nullptr) {
11466 return detail::errHandler(CL_INVALID_OPERATION,
11467 __COMMAND_FILL_BUFFER_KHR_ERR);
11468 }
11469
11470 cl_sync_point_khr tmp_sync_point;
11471 cl_int error = detail::errHandler(
11472 pfn_clCommandFillBufferKHR(object_,
11473 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11474 buffer(),
11475 static_cast<void*>(&pattern),
11476 sizeof(PatternType),
11477 offset,
11478 size,
11479 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11480 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11481 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11482 (cl_mutable_command_khr*) mutable_handle),
11483 __COMMAND_FILL_BUFFER_KHR_ERR);
11484
11485 if (sync_point != nullptr && error == CL_SUCCESS)
11486 *sync_point = tmp_sync_point;
11487
11488 return error;
11489 }
11490
11491 cl_int commandFillImage(const Image& image,
11492 cl_float4 fillColor,
11493 const array<size_type, 3>& origin,
11494 const array<size_type, 3>& region,
11495 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11496 cl_sync_point_khr* sync_point = nullptr,
11497 MutableCommandKhr* mutable_handle = nullptr,
11498 const CommandQueue* command_queue = nullptr)
11499 {
11500 if (pfn_clCommandFillImageKHR == nullptr) {
11501 return detail::errHandler(CL_INVALID_OPERATION,
11502 __COMMAND_FILL_IMAGE_KHR_ERR);
11503 }
11504
11505 cl_sync_point_khr tmp_sync_point;
11506 cl_int error = detail::errHandler(
11507 pfn_clCommandFillImageKHR(object_,
11508 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11509 image(),
11510 static_cast<void*>(&fillColor),
11511 origin.data(),
11512 region.data(),
11513 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11514 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11515 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11516 (cl_mutable_command_khr*) mutable_handle),
11517 __COMMAND_FILL_IMAGE_KHR_ERR);
11518
11519 if (sync_point != nullptr && error == CL_SUCCESS)
11520 *sync_point = tmp_sync_point;
11521
11522 return error;
11523 }
11524
11525 cl_int commandNDRangeKernel(const cl::vector<cl_ndrange_kernel_command_properties_khr> &properties,
11526 const Kernel& kernel,
11527 const NDRange& offset,
11528 const NDRange& global,
11529 const NDRange& local = NullRange,
11530 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11531 cl_sync_point_khr* sync_point = nullptr,
11532 MutableCommandKhr* mutable_handle = nullptr,
11533 const CommandQueue* command_queue = nullptr)
11534 {
11535 if (pfn_clCommandNDRangeKernelKHR == nullptr) {
11536 return detail::errHandler(CL_INVALID_OPERATION,
11537 __COMMAND_NDRANGE_KERNEL_KHR_ERR);
11538 }
11539
11540 cl_sync_point_khr tmp_sync_point;
11541 cl_int error = detail::errHandler(
11542 pfn_clCommandNDRangeKernelKHR(object_,
11543 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11544 &properties[0],
11545 kernel(),
11546 (cl_uint) global.dimensions(),
11547 offset.dimensions() != 0 ? (const size_type*) offset : nullptr,
11548 (const size_type*) global,
11549 local.dimensions() != 0 ? (const size_type*) local : nullptr,
11550 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11551 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11552 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11553 (cl_mutable_command_khr*) mutable_handle),
11554 __COMMAND_NDRANGE_KERNEL_KHR_ERR);
11555
11556 if (sync_point != nullptr && error == CL_SUCCESS)
11557 *sync_point = tmp_sync_point;
11558
11559 return error;
11560 }
11561
11562#if defined(cl_khr_command_buffer_mutable_dispatch)
11563 cl_int updateMutableCommands(const cl_mutable_base_config_khr* mutable_config)
11564 {
11565 if (pfn_clUpdateMutableCommandsKHR == nullptr) {
11566 return detail::errHandler(CL_INVALID_OPERATION,
11567 __UPDATE_MUTABLE_COMMANDS_KHR_ERR);
11568 }
11569 return detail::errHandler(pfn_clUpdateMutableCommandsKHR(object_, mutable_config),
11570 __UPDATE_MUTABLE_COMMANDS_KHR_ERR);
11571 }
11572#endif /* cl_khr_command_buffer_mutable_dispatch */
11573
11574private:
11575 static std::once_flag ext_init_;
11576
11577 static void initExtensions(const cl::Device& device)
11578 {
11579#if CL_HPP_TARGET_OPENCL_VERSION >= 120
11580 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>()();
11581 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateCommandBufferKHR);
11582 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clFinalizeCommandBufferKHR);
11583 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clRetainCommandBufferKHR);
11584 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clReleaseCommandBufferKHR);
11585 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clGetCommandBufferInfoKHR);
11586 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueCommandBufferKHR);
11587 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandBarrierWithWaitListKHR);
11588 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandCopyBufferKHR);
11589 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandCopyBufferRectKHR);
11590 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandCopyBufferToImageKHR);
11591 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandCopyImageKHR);
11592 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandCopyImageToBufferKHR);
11593 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandFillBufferKHR);
11594 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandFillImageKHR);
11595 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandNDRangeKernelKHR);
11596#if defined(cl_khr_command_buffer_mutable_dispatch)
11597 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clUpdateMutableCommandsKHR);
11598 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clGetMutableCommandInfoKHR);
11599#endif /* cl_khr_command_buffer_mutable_dispatch */
11600#elif CL_HPP_TARGET_OPENCL_VERSION >= 110
11601 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateCommandBufferKHR);
11602 CL_HPP_INIT_CL_EXT_FCN_PTR_(clFinalizeCommandBufferKHR);
11603 CL_HPP_INIT_CL_EXT_FCN_PTR_(clRetainCommandBufferKHR);
11604 CL_HPP_INIT_CL_EXT_FCN_PTR_(clReleaseCommandBufferKHR);
11605 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetCommandBufferInfoKHR);
11606 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueCommandBufferKHR);
11607 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandBarrierWithWaitListKHR);
11608 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandCopyBufferKHR);
11609 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandCopyBufferRectKHR);
11610 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandCopyBufferToImageKHR);
11611 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandCopyImageKHR);
11612 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandCopyImageToBufferKHR);
11613 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandFillBufferKHR);
11614 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandFillImageKHR);
11615 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandNDRangeKernelKHR);
11616#if defined(cl_khr_command_buffer_mutable_dispatch)
11617 CL_HPP_INIT_CL_EXT_FCN_PTR_(clUpdateMutableCommandsKHR);
11618 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetMutableCommandInfoKHR);
11619#endif /* cl_khr_command_buffer_mutable_dispatch */
11620#endif
11621 if ((pfn_clCreateCommandBufferKHR == nullptr) &&
11622 (pfn_clFinalizeCommandBufferKHR == nullptr) &&
11623 (pfn_clRetainCommandBufferKHR == nullptr) &&
11624 (pfn_clReleaseCommandBufferKHR == nullptr) &&
11625 (pfn_clGetCommandBufferInfoKHR == nullptr) &&
11626 (pfn_clEnqueueCommandBufferKHR == nullptr) &&
11627 (pfn_clCommandBarrierWithWaitListKHR == nullptr) &&
11628 (pfn_clCommandCopyBufferKHR == nullptr) &&
11629 (pfn_clCommandCopyBufferRectKHR == nullptr) &&
11630 (pfn_clCommandCopyBufferToImageKHR == nullptr) &&
11631 (pfn_clCommandCopyImageKHR == nullptr) &&
11632 (pfn_clCommandCopyImageToBufferKHR == nullptr) &&
11633 (pfn_clCommandFillBufferKHR == nullptr) &&
11634 (pfn_clCommandFillImageKHR == nullptr) &&
11635 (pfn_clCommandNDRangeKernelKHR == nullptr)
11636#if defined(cl_khr_command_buffer_mutable_dispatch)
11637 && (pfn_clUpdateMutableCommandsKHR == nullptr)
11638 && (pfn_clGetMutableCommandInfoKHR == nullptr)
11639#endif /* cl_khr_command_buffer_mutable_dispatch */
11640 )
11641 {
11642 detail::errHandler(CL_INVALID_VALUE, __CREATE_COMMAND_BUFFER_KHR_ERR);
11643 }
11644 }
11645}; // CommandBufferKhr
11646
11647CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandBufferKhr::ext_init_;
11648
11649#if defined(cl_khr_command_buffer_mutable_dispatch)
11653class MutableCommandKhr : public detail::Wrapper<cl_mutable_command_khr>
11654{
11655public:
11657 MutableCommandKhr() : detail::Wrapper<cl_type>() { }
11658
11659 explicit MutableCommandKhr(const cl_mutable_command_khr& mutableCommandKhr, bool retainObject = false) :
11660 detail::Wrapper<cl_type>(mutableCommandKhr, retainObject) { }
11661
11662 MutableCommandKhr& operator=(const cl_mutable_command_khr& rhs)
11663 {
11664 detail::Wrapper<cl_type>::operator=(rhs);
11665 return *this;
11666 }
11667
11668 template <typename T>
11669 cl_int getInfo(cl_mutable_command_info_khr name, T* param) const
11670 {
11671 if (pfn_clGetMutableCommandInfoKHR == nullptr) {
11672 return detail::errHandler(CL_INVALID_OPERATION,
11673 __GET_MUTABLE_COMMAND_INFO_KHR_ERR);
11674 }
11675 return detail::errHandler(
11676 detail::getInfo(pfn_clGetMutableCommandInfoKHR, object_, name, param),
11677 __GET_MUTABLE_COMMAND_INFO_KHR_ERR);
11678 }
11679
11680 template <cl_mutable_command_info_khr name> typename
11681 detail::param_traits<detail::cl_mutable_command_info_khr, name>::param_type
11682 getInfo(cl_int* err = nullptr) const
11683 {
11684 typename detail::param_traits<
11685 detail::cl_mutable_command_info_khr, name>::param_type param;
11686 cl_int result = getInfo(name, &param);
11687 if (err != nullptr) {
11688 *err = result;
11689 }
11690 return param;
11691 }
11692}; // MutableCommandKhr
11693#endif /* cl_khr_command_buffer_mutable_dispatch */
11694
11695#endif // cl_khr_command_buffer
11696//----------------------------------------------------------------------------------------------------------------------
11697
11698#undef CL_HPP_ERR_STR_
11699#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
11700#undef __GET_DEVICE_INFO_ERR
11701#undef __GET_PLATFORM_INFO_ERR
11702#undef __GET_DEVICE_IDS_ERR
11703#undef __GET_PLATFORM_IDS_ERR
11704#undef __GET_CONTEXT_INFO_ERR
11705#undef __GET_EVENT_INFO_ERR
11706#undef __GET_EVENT_PROFILE_INFO_ERR
11707#undef __GET_MEM_OBJECT_INFO_ERR
11708#undef __GET_IMAGE_INFO_ERR
11709#undef __GET_SAMPLER_INFO_ERR
11710#undef __GET_KERNEL_INFO_ERR
11711#undef __GET_KERNEL_ARG_INFO_ERR
11712#undef __GET_KERNEL_SUB_GROUP_INFO_ERR
11713#undef __GET_KERNEL_WORK_GROUP_INFO_ERR
11714#undef __GET_PROGRAM_INFO_ERR
11715#undef __GET_PROGRAM_BUILD_INFO_ERR
11716#undef __GET_COMMAND_QUEUE_INFO_ERR
11717#undef __CREATE_CONTEXT_ERR
11718#undef __CREATE_CONTEXT_FROM_TYPE_ERR
11719#undef __CREATE_COMMAND_BUFFER_KHR_ERR
11720#undef __GET_COMMAND_BUFFER_INFO_KHR_ERR
11721#undef __FINALIZE_COMMAND_BUFFER_KHR_ERR
11722#undef __ENQUEUE_COMMAND_BUFFER_KHR_ERR
11723#undef __COMMAND_BARRIER_WITH_WAIT_LIST_KHR_ERR
11724#undef __COMMAND_COPY_BUFFER_KHR_ERR
11725#undef __COMMAND_COPY_BUFFER_RECT_KHR_ERR
11726#undef __COMMAND_COPY_BUFFER_TO_IMAGE_KHR_ERR
11727#undef __COMMAND_COPY_IMAGE_KHR_ERR
11728#undef __COMMAND_COPY_IMAGE_TO_BUFFER_KHR_ERR
11729#undef __COMMAND_FILL_BUFFER_KHR_ERR
11730#undef __COMMAND_FILL_IMAGE_KHR_ERR
11731#undef __COMMAND_NDRANGE_KERNEL_KHR_ERR
11732#undef __UPDATE_MUTABLE_COMMANDS_KHR_ERR
11733#undef __GET_MUTABLE_COMMAND_INFO_KHR_ERR
11734#undef __RETAIN_COMMAND_BUFFER_KHR_ERR
11735#undef __RELEASE_COMMAND_BUFFER_KHR_ERR
11736#undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
11737#undef __SET_CONTEXT_DESCTRUCTOR_CALLBACK_ERR
11738#undef __CREATE_BUFFER_ERR
11739#undef __COPY_ERR
11740#undef __CREATE_SUBBUFFER_ERR
11741#undef __CREATE_GL_BUFFER_ERR
11742#undef __CREATE_GL_RENDER_BUFFER_ERR
11743#undef __GET_GL_OBJECT_INFO_ERR
11744#undef __CREATE_IMAGE_ERR
11745#undef __CREATE_GL_TEXTURE_ERR
11746#undef __IMAGE_DIMENSION_ERR
11747#undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
11748#undef __CREATE_USER_EVENT_ERR
11749#undef __SET_USER_EVENT_STATUS_ERR
11750#undef __SET_EVENT_CALLBACK_ERR
11751#undef __WAIT_FOR_EVENTS_ERR
11752#undef __CREATE_KERNEL_ERR
11753#undef __SET_KERNEL_ARGS_ERR
11754#undef __CREATE_PROGRAM_WITH_SOURCE_ERR
11755#undef __CREATE_PROGRAM_WITH_BINARY_ERR
11756#undef __CREATE_PROGRAM_WITH_IL_ERR
11757#undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR
11758#undef __BUILD_PROGRAM_ERR
11759#undef __COMPILE_PROGRAM_ERR
11760#undef __LINK_PROGRAM_ERR
11761#undef __CREATE_KERNELS_IN_PROGRAM_ERR
11762#undef __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR
11763#undef __CREATE_SAMPLER_WITH_PROPERTIES_ERR
11764#undef __SET_COMMAND_QUEUE_PROPERTY_ERR
11765#undef __ENQUEUE_READ_BUFFER_ERR
11766#undef __ENQUEUE_READ_BUFFER_RECT_ERR
11767#undef __ENQUEUE_WRITE_BUFFER_ERR
11768#undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
11769#undef __ENQEUE_COPY_BUFFER_ERR
11770#undef __ENQEUE_COPY_BUFFER_RECT_ERR
11771#undef __ENQUEUE_FILL_BUFFER_ERR
11772#undef __ENQUEUE_READ_IMAGE_ERR
11773#undef __ENQUEUE_WRITE_IMAGE_ERR
11774#undef __ENQUEUE_COPY_IMAGE_ERR
11775#undef __ENQUEUE_FILL_IMAGE_ERR
11776#undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
11777#undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
11778#undef __ENQUEUE_MAP_BUFFER_ERR
11779#undef __ENQUEUE_MAP_IMAGE_ERR
11780#undef __ENQUEUE_MAP_SVM_ERR
11781#undef __ENQUEUE_FILL_SVM_ERR
11782#undef __ENQUEUE_COPY_SVM_ERR
11783#undef __ENQUEUE_UNMAP_SVM_ERR
11784#undef __ENQUEUE_MAP_IMAGE_ERR
11785#undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
11786#undef __ENQUEUE_NDRANGE_KERNEL_ERR
11787#undef __ENQUEUE_NATIVE_KERNEL
11788#undef __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR
11789#undef __ENQUEUE_MIGRATE_SVM_ERR
11790#undef __ENQUEUE_ACQUIRE_GL_ERR
11791#undef __ENQUEUE_RELEASE_GL_ERR
11792#undef __CREATE_PIPE_ERR
11793#undef __GET_PIPE_INFO_ERR
11794#undef __RETAIN_ERR
11795#undef __RELEASE_ERR
11796#undef __FLUSH_ERR
11797#undef __FINISH_ERR
11798#undef __VECTOR_CAPACITY_ERR
11799#undef __CREATE_SUB_DEVICES_ERR
11800#undef __ENQUEUE_ACQUIRE_EXTERNAL_MEMORY_ERR
11801#undef __ENQUEUE_RELEASE_EXTERNAL_MEMORY_ERR
11802#undef __ENQUEUE_MARKER_ERR
11803#undef __ENQUEUE_WAIT_FOR_EVENTS_ERR
11804#undef __ENQUEUE_BARRIER_ERR
11805#undef __UNLOAD_COMPILER_ERR
11806#undef __CREATE_GL_TEXTURE_2D_ERR
11807#undef __CREATE_GL_TEXTURE_3D_ERR
11808#undef __CREATE_IMAGE2D_ERR
11809#undef __CREATE_IMAGE3D_ERR
11810#undef __CREATE_COMMAND_QUEUE_ERR
11811#undef __ENQUEUE_TASK_ERR
11812#undef __CREATE_SAMPLER_ERR
11813#undef __ENQUEUE_MARKER_WAIT_LIST_ERR
11814#undef __ENQUEUE_BARRIER_WAIT_LIST_ERR
11815#undef __CLONE_KERNEL_ERR
11816#undef __GET_HOST_TIMER_ERR
11817#undef __GET_DEVICE_AND_HOST_TIMER_ERR
11818#undef __GET_SEMAPHORE_KHR_INFO_ERR
11819#undef __CREATE_SEMAPHORE_KHR_WITH_PROPERTIES_ERR
11820#undef __GET_IMAGE_REQUIREMENT_INFO_EXT_ERR
11821#undef __ENQUEUE_WAIT_SEMAPHORE_KHR_ERR
11822#undef __ENQUEUE_SIGNAL_SEMAPHORE_KHR_ERR
11823#undef __RETAIN_SEMAPHORE_KHR_ERR
11824#undef __RELEASE_SEMAPHORE_KHR_ERR
11825#undef __GET_SEMAPHORE_HANDLE_FOR_TYPE_KHR_ERR
11826
11827#endif //CL_HPP_USER_OVERRIDE_ERROR_STRINGS
11828
11829// Extensions
11830#undef CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_
11831#undef CL_HPP_INIT_CL_EXT_FCN_PTR_
11832#undef CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_
11833
11834#undef CL_HPP_DEFINE_STATIC_MEMBER_
11835
11836} // namespace cl
11837
11838#endif // CL_HPP_
BufferGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4644
BufferGL()
Default constructor - initializes to nullptr.
Definition opencl.hpp:4628
cl_int getObjectInfo(cl_gl_object_type *type, cl_GLuint *gl_object_name)
Wrapper for clGetGLObjectInfo().
Definition opencl.hpp:4652
Class interface for Buffer Memory Objects.
Definition opencl.hpp:4289
Buffer()
Default constructor - initializes to nullptr.
Definition opencl.hpp:4457
Buffer createSubBuffer(cl_mem_flags flags, cl_buffer_create_type buffer_create_type, const void *buffer_create_info, cl_int *err=nullptr)
Creates a new buffer object from this.
Definition opencl.hpp:4485
Buffer & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4473
cl_int getObjectInfo(cl_gl_object_type *type, cl_GLuint *gl_object_name)
Wrapper for clGetGLObjectInfo().
Definition opencl.hpp:4722
BufferRenderGL()
Default constructor - initializes to nullptr.
Definition opencl.hpp:4698
BufferRenderGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4714
CommandQueue interface for cl_command_queue.
Definition opencl.hpp:7225
cl_int enqueueUnmapSVM(T *ptr, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:8721
cl_int enqueueMemcpySVM(T *dst_ptr, const T *src_ptr, cl_bool blocking, size_type size, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:8461
cl_int enqueueMigrateMemObjects(const vector< Memory > &memObjects, cl_mem_migration_flags flags, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:8857
cl_int enqueueMarkerWithWaitList(const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:8804
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int enqueueMarker(Event *event=nullptr) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition opencl.hpp:9091
static CommandQueue setDefault(const CommandQueue &default_queue)
Definition opencl.hpp:7685
std::enable_if< std::is_same< T, cl_float4 >::value||std::is_same< T, cl_int4 >::value||std::is_same< T, cl_uint4 >::value, cl_int >::type enqueueFillImage(const Image &image, T fillColor, const array< size_type, 3 > &origin, const array< size_type, 3 > &region, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:8222
cl_int enqueueMapSVM(T *ptr, cl_bool blocking, cl_map_flags flags, size_type size, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:8616
cl_int enqueueMigrateSVM(const cl::vector< T * > &svmRawPointers, const cl::vector< size_type > &sizes, cl_mem_migration_flags flags=0, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:8898
cl_int enqueueMemFillSVM(T *ptr, PatternType pattern, size_type size, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:8541
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int enqueueBarrier() const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition opencl.hpp:9244
cl_int enqueueBarrierWithWaitList(const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:8834
cl_int enqueueFillBuffer(const Buffer &buffer, PatternType pattern, size_type offset, size_type size, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:8020
Class interface for cl_context.
Definition opencl.hpp:3149
Context & operator=(const cl_context &rhs)
Assignment operator from cl_context - takes ownership.
Definition opencl.hpp:3457
cl_int setDestructorCallback(void(CL_CALLBACK *pfn_notify)(cl_context, void *), void *user_data=nullptr)
Registers a destructor callback function with a context.
Definition opencl.hpp:3581
static Context setDefault(const Context &default_context)
Definition opencl.hpp:3434
static Context getDefault(cl_int *err=nullptr)
Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT.
Definition opencl.hpp:3417
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:3490
Context()
Default constructor - initializes to nullptr.
Definition opencl.hpp:3442
cl_int getInfo(cl_context_info name, T *param) const
Wrapper for clGetContextInfo().
Definition opencl.hpp:3465
DeviceCommandQueue interface for device cl_command_queues.
Definition opencl.hpp:9362
static DeviceCommandQueue updateDefault(const Context &context, const Device &device, const DeviceCommandQueue &default_queue, cl_int *err=nullptr)
Definition opencl.hpp:9577
static DeviceCommandQueue getDefault(const CommandQueue &queue, cl_int *err=nullptr)
Definition opencl.hpp:9592
static DeviceCommandQueue makeDefault(cl_int *err=nullptr)
Definition opencl.hpp:9487
Class interface for cl_device_id.
Definition opencl.hpp:2430
static Device getDefault(cl_int *errResult=nullptr)
Returns the first device on the default context.
Definition opencl.hpp:2479
Device & operator=(const cl_device_id &rhs)
Assignment operator from cl_device_id.
Definition opencl.hpp:2508
cl_int getInfo(cl_device_info name, T *param) const
Wrapper for clGetDeviceInfo().
Definition opencl.hpp:2517
Device()
Default constructor - initializes to nullptr.
Definition opencl.hpp:2466
cl_ulong getHostTimer(cl_int *error=nullptr)
Definition opencl.hpp:2545
std::pair< cl_ulong, cl_ulong > getDeviceAndHostTimer(cl_int *error=nullptr)
Definition opencl.hpp:2569
cl_int createSubDevices(const cl_device_partition_property *properties, vector< Device > *devices)
Wrapper for clCreateSubDevices().
Definition opencl.hpp:3013
static Device setDefault(const Device &default_device)
Definition opencl.hpp:2497
Class interface for cl_event.
Definition opencl.hpp:3637
cl_int setCallback(cl_int type, void(CL_CALLBACK *pfn_notify)(cl_event, cl_int, void *), void *user_data=nullptr)
Registers a user callback function for a specific command execution status.
Definition opencl.hpp:3726
cl_int getProfilingInfo(cl_profiling_info name, T *param) const
Wrapper for clGetEventProfilingInfo().
Definition opencl.hpp:3689
cl_int getInfo(cl_event_info name, T *param) const
Wrapper for clGetEventInfo().
Definition opencl.hpp:3666
cl_int wait() const
Blocks the calling thread until this event completes.
Definition opencl.hpp:3714
Event()
Default constructor - initializes to nullptr.
Definition opencl.hpp:3640
Event & operator=(const cl_event &rhs)
Assignment operator from cl_event - takes ownership.
Definition opencl.hpp:3658
static cl_int waitForEvents(const vector< Event > &events)
Blocks the calling thread until every event specified is complete.
Definition opencl.hpp:3746
Image interface for arrays of 1D images.
Definition opencl.hpp:4919
Image interface for 1D buffer images.
Definition opencl.hpp:4862
Image1D()
Default constructor - initializes to nullptr.
Definition opencl.hpp:4833
Image1D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4849
Image interface for arrays of 2D images.
Definition opencl.hpp:5261
Class interface for GL 2D Image Memory objects.
Definition opencl.hpp:5197
Class interface for 2D Image Memory objects.
Definition opencl.hpp:4984
Image2D()
Default constructor - initializes to nullptr.
Definition opencl.hpp:5158
Image2D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:5174
Image3DGL()
Default constructor - initializes to nullptr.
Definition opencl.hpp:5465
Image3DGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:5481
Class interface for 3D Image Memory objects.
Definition opencl.hpp:5326
Image3D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:5416
Image3D()
Default constructor - initializes to nullptr.
Definition opencl.hpp:5400
C++ base class for Image Memory objects.
Definition opencl.hpp:4739
cl_int getImageInfo(cl_image_info name, T *param) const
Wrapper for clGetImageInfo().
Definition opencl.hpp:4768
Image & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4758
Image()
Default constructor - initializes to nullptr.
Definition opencl.hpp:4742
Event operator()(const EnqueueArgs &args, Ts... ts)
Definition opencl.hpp:10795
Event result_type
Return type of the functor.
Definition opencl.hpp:10788
Class interface for cl_kernel.
Definition opencl.hpp:5918
cl_int setSVMPointers(const vector< void * > &pointerList)
Definition opencl.hpp:6112
cl_int setArg(cl_uint index, const cl::pointer< T, D > &argPtr)
setArg overload taking a shared_ptr type
Definition opencl.hpp:6056
Kernel()
Default constructor - initializes to nullptr.
Definition opencl.hpp:5924
Kernel & operator=(const cl_kernel &rhs)
Assignment operator from cl_kernel - takes ownership.
Definition opencl.hpp:5942
Kernel clone()
Definition opencl.hpp:6228
cl_int enableFineGrainedSystemSVM(bool svmEnabled)
Enable fine-grained system SVM.
Definition opencl.hpp:6148
Class interface for cl_mem.
Definition opencl.hpp:3823
Memory()
Default constructor - initializes to nullptr.
Definition opencl.hpp:3826
Memory & operator=(const cl_mem &rhs)
Assignment operator from cl_mem - takes ownership.
Definition opencl.hpp:3847
cl_int getInfo(cl_mem_info name, T *param) const
Wrapper for clGetMemObjectInfo().
Definition opencl.hpp:3855
cl_int setDestructorCallback(void(CL_CALLBACK *pfn_notify)(cl_mem, void *), void *user_data=nullptr)
Registers a callback function to be called when the memory object is no longer needed.
Definition opencl.hpp:3890
Class interface for specifying NDRange values.
Definition opencl.hpp:5772
size_type dimensions() const
Queries the number of dimensions in the range.
Definition opencl.hpp:5832
size_type size() const
Returns the size of the object in bytes based on the.
Definition opencl.hpp:5839
NDRange()
Default constructor - resulting range has zero dimensions.
Definition opencl.hpp:5779
Pipe()
Default constructor - initializes to nullptr.
Definition opencl.hpp:5610
cl_int getInfo(cl_pipe_info name, T *param) const
Wrapper for clGetMemObjectInfo().
Definition opencl.hpp:5636
Pipe & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:5626
Platform()
Default constructor - initializes to nullptr.
Definition opencl.hpp:2727
cl_int unloadCompiler()
Wrapper for clUnloadCompiler().
Definition opencl.hpp:3004
cl_int getDevices(cl_device_type type, vector< Device > *devices) const
Gets a list of devices for this platform.
Definition opencl.hpp:2801
Platform & operator=(const cl_platform_id &rhs)
Assignment operator from cl_platform_id.
Definition opencl.hpp:2743
static cl_int get(vector< Platform > *platforms)
Gets a list of available platforms.
Definition opencl.hpp:2936
cl_int getInfo(cl_platform_info name, T *param) const
Wrapper for clGetPlatformInfo().
Definition opencl.hpp:2776
static Platform setDefault(const Platform &default_platform)
Definition opencl.hpp:2767
Program interface that implements cl_program.
Definition opencl.hpp:6243
CL_API_PREFIX__VERSION_2_2_DEPRECATED cl_int setReleaseCallback(void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data), void *user_data=nullptr) 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:6961
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:6980
bool operator==(SVMAllocator const &rhs)
Definition opencl.hpp:4158
pointer allocate(size_type size, typename cl::SVMAllocator< void, SVMTrait >::const_pointer=0, bool map=true)
Definition opencl.hpp:4083
size_type max_size() const noexcept
Definition opencl.hpp:4130
Class interface for cl_sampler.
Definition opencl.hpp:5669
Sampler()
Default constructor - initializes to nullptr.
Definition opencl.hpp:5672
Sampler & operator=(const cl_sampler &rhs)
Assignment operator from cl_sampler - takes ownership.
Definition opencl.hpp:5733
cl_int getInfo(cl_sampler_info name, T *param) const
Wrapper for clGetSamplerInfo().
Definition opencl.hpp:5743
UserEvent()
Default constructor - initializes to nullptr.
Definition opencl.hpp:3786
cl_int setStatus(cl_int status)
Sets the execution status of a user event object.
Definition opencl.hpp:3792
The OpenCL C++ bindings are defined within this namespace.
Definition opencl.hpp:575
cl_int copy(IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer)
Definition opencl.hpp:9977
vector< T, cl::SVMAllocator< int, cl::SVMTraitCoarse<> > > coarse_svm_vector
Vector alias to simplify contruction of coarse-grained SVM containers.
Definition opencl.hpp:4265
LocalSpaceArg Local(size_type size)
Helper function for generating LocalSpaceArg objects.
Definition opencl.hpp:5903
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int UnloadCompiler() CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition opencl.hpp:3114
vector< T, cl::SVMAllocator< int, cl::SVMTraitFine<> > > fine_svm_vector
Vector alias to simplify contruction of fine-grained SVM containers.
Definition opencl.hpp:4271
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:4277
cl::pointer< T, detail::Deleter< Alloc > > allocate_pointer(const Alloc &alloc_, Args &&... args)
Definition opencl.hpp:4218
cl_int enqueueUnmapSVM(T *ptr, const vector< Event > *events=nullptr, Event *event=nullptr)
Definition opencl.hpp:9892
cl_int enqueueMapSVM(T *ptr, cl_bool blocking, cl_map_flags flags, size_type size, const vector< Event > *events=nullptr, Event *event=nullptr)
Definition opencl.hpp:9790
cl_int mapSVM(cl::vector< T, Alloc > &container)
Definition opencl.hpp:10079
cl_int unmapSVM(cl::vector< T, Alloc > &container)
Definition opencl.hpp:10088
Adds constructors and member functions for cl_image_format.
Definition opencl.hpp:2397
ImageFormat & operator=(const ImageFormat &rhs)
Assignment operator.
Definition opencl.hpp:2412
ImageFormat()
Default constructor - performs no initialization.
Definition opencl.hpp:2399
Local address wrapper for use with Kernel::setArg.
Definition opencl.hpp:5860
Event type_(const EnqueueArgs &, Ts...)
Function signature of kernel functor with no event dependency.
Definition opencl.hpp:10885
Event result_type
Return type of the functor.
Definition opencl.hpp:10882