OpenCL C++ Bindings: opencl.hpp Source File

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)
575 namespace 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_OPAQUE_FD_EXT(F) \
1565 F(cl_external_semaphore_handle_type_khr, CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR, int) \
1566
1567#define CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_SYNC_FD_EXT(F) \
1568 F(cl_external_semaphore_handle_type_khr, CL_SEMAPHORE_HANDLE_SYNC_FD_KHR, int) \
1569
1570#define CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_WIN32_EXT(F) \
1571 F(cl_external_semaphore_handle_type_khr, CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR, void*) \
1572 F(cl_external_semaphore_handle_type_khr, CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KMT_KHR, void*) \
1573
1574#define CL_HPP_PARAM_NAME_INFO_3_0_(F) \
1575 F(cl_platform_info, CL_PLATFORM_NUMERIC_VERSION, cl_version) \
1576 F(cl_platform_info, CL_PLATFORM_EXTENSIONS_WITH_VERSION, cl::vector<cl_name_version>) \
1577 \
1578 F(cl_device_info, CL_DEVICE_NUMERIC_VERSION, cl_version) \
1579 F(cl_device_info, CL_DEVICE_EXTENSIONS_WITH_VERSION, cl::vector<cl_name_version>) \
1580 F(cl_device_info, CL_DEVICE_ILS_WITH_VERSION, cl::vector<cl_name_version>) \
1581 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION, cl::vector<cl_name_version>) \
1582 F(cl_device_info, CL_DEVICE_ATOMIC_MEMORY_CAPABILITIES, cl_device_atomic_capabilities) \
1583 F(cl_device_info, CL_DEVICE_ATOMIC_FENCE_CAPABILITIES, cl_device_atomic_capabilities) \
1584 F(cl_device_info, CL_DEVICE_NON_UNIFORM_WORK_GROUP_SUPPORT, cl_bool) \
1585 F(cl_device_info, CL_DEVICE_OPENCL_C_ALL_VERSIONS, cl::vector<cl_name_version>) \
1586 F(cl_device_info, CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1587 F(cl_device_info, CL_DEVICE_WORK_GROUP_COLLECTIVE_FUNCTIONS_SUPPORT, cl_bool) \
1588 F(cl_device_info, CL_DEVICE_GENERIC_ADDRESS_SPACE_SUPPORT, cl_bool) \
1589 F(cl_device_info, CL_DEVICE_OPENCL_C_FEATURES, cl::vector<cl_name_version>) \
1590 F(cl_device_info, CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES, cl_device_device_enqueue_capabilities) \
1591 F(cl_device_info, CL_DEVICE_PIPE_SUPPORT, cl_bool) \
1592 F(cl_device_info, CL_DEVICE_LATEST_CONFORMANCE_VERSION_PASSED, string) \
1593 \
1594 F(cl_command_queue_info, CL_QUEUE_PROPERTIES_ARRAY, cl::vector<cl_queue_properties>) \
1595 F(cl_mem_info, CL_MEM_PROPERTIES, cl::vector<cl_mem_properties>) \
1596 F(cl_pipe_info, CL_PIPE_PROPERTIES, cl::vector<cl_pipe_properties>) \
1597 F(cl_sampler_info, CL_SAMPLER_PROPERTIES, cl::vector<cl_sampler_properties>) \
1598
1599#define CL_HPP_PARAM_NAME_CL_IMAGE_REQUIREMENTS_EXT(F) \
1600 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_ROW_PITCH_ALIGNMENT_EXT, size_type) \
1601 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_BASE_ADDRESS_ALIGNMENT_EXT, size_type) \
1602 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_SIZE_EXT, size_type) \
1603 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_MAX_WIDTH_EXT, cl_uint) \
1604 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_MAX_HEIGHT_EXT, cl_uint) \
1605 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_MAX_DEPTH_EXT, cl_uint) \
1606 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_MAX_ARRAY_SIZE_EXT, cl_uint) \
1607
1608#define CL_HPP_PARAM_NAME_CL_IMAGE_REQUIREMENTS_SLICE_PITCH_ALIGNMENT_EXT(F) \
1609 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_SLICE_PITCH_ALIGNMENT_EXT, size_type) \
1610
1611#define CL_HPP_PARAM_NAME_CL_INTEL_COMMAND_QUEUE_FAMILIES_(F) \
1612 F(cl_device_info, CL_DEVICE_QUEUE_FAMILY_PROPERTIES_INTEL, cl::vector<cl_queue_family_properties_intel>) \
1613 \
1614 F(cl_command_queue_info, CL_QUEUE_FAMILY_INTEL, cl_uint) \
1615 F(cl_command_queue_info, CL_QUEUE_INDEX_INTEL, cl_uint)
1616
1617#define CL_HPP_PARAM_NAME_CL_INTEL_UNIFIED_SHARED_MEMORY_(F) \
1618 F(cl_device_info, CL_DEVICE_HOST_MEM_CAPABILITIES_INTEL, cl_device_unified_shared_memory_capabilities_intel ) \
1619 F(cl_device_info, CL_DEVICE_DEVICE_MEM_CAPABILITIES_INTEL, cl_device_unified_shared_memory_capabilities_intel ) \
1620 F(cl_device_info, CL_DEVICE_SINGLE_DEVICE_SHARED_MEM_CAPABILITIES_INTEL, cl_device_unified_shared_memory_capabilities_intel ) \
1621 F(cl_device_info, CL_DEVICE_CROSS_DEVICE_SHARED_MEM_CAPABILITIES_INTEL, cl_device_unified_shared_memory_capabilities_intel ) \
1622 F(cl_device_info, CL_DEVICE_SHARED_SYSTEM_MEM_CAPABILITIES_INTEL, cl_device_unified_shared_memory_capabilities_intel )
1623
1624template <typename enum_type, cl_int Name>
1625struct param_traits {};
1626
1627#define CL_HPP_DECLARE_PARAM_TRAITS_(token, param_name, T) \
1628struct token; \
1629template<> \
1630struct param_traits<detail:: token,param_name> \
1631{ \
1632 enum { value = param_name }; \
1633 typedef T param_type; \
1634};
1635
1636CL_HPP_PARAM_NAME_INFO_1_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1637#if CL_HPP_TARGET_OPENCL_VERSION >= 110
1638CL_HPP_PARAM_NAME_INFO_1_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1639#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
1640#if CL_HPP_TARGET_OPENCL_VERSION >= 120
1641CL_HPP_PARAM_NAME_INFO_1_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1642#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1643#if CL_HPP_TARGET_OPENCL_VERSION >= 200
1644CL_HPP_PARAM_NAME_INFO_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1645#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
1646#if CL_HPP_TARGET_OPENCL_VERSION >= 210
1647CL_HPP_PARAM_NAME_INFO_2_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1648#endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
1649#if CL_HPP_TARGET_OPENCL_VERSION >= 220
1650CL_HPP_PARAM_NAME_INFO_2_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1651#endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
1652#if CL_HPP_TARGET_OPENCL_VERSION >= 300
1653CL_HPP_PARAM_NAME_INFO_3_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1654#endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
1655
1656#if defined(cl_khr_subgroups) && CL_HPP_TARGET_OPENCL_VERSION < 210
1657CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1658#endif // #if defined(cl_khr_subgroups) && CL_HPP_TARGET_OPENCL_VERSION < 210
1659
1660#if defined(cl_khr_il_program) && CL_HPP_TARGET_OPENCL_VERSION < 210
1661CL_HPP_PARAM_NAME_INFO_IL_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1662#endif // #if defined(cl_khr_il_program) && CL_HPP_TARGET_OPENCL_VERSION < 210
1663
1664
1665// Flags deprecated in OpenCL 2.0
1666#define CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(F) \
1667 F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties)
1668
1669#define CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(F) \
1670 F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool)
1671
1672#define CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(F) \
1673 F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer)
1674
1675// Include deprecated query flags based on versions
1676// Only include deprecated 1.0 flags if 2.0 not active as there is an enum clash
1677#if CL_HPP_TARGET_OPENCL_VERSION > 100 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 && CL_HPP_TARGET_OPENCL_VERSION < 200
1678CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1679#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 110
1680#if CL_HPP_TARGET_OPENCL_VERSION > 110 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1681CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1682#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1683#if CL_HPP_TARGET_OPENCL_VERSION > 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1684CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1685#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
1686
1687#if defined(cl_ext_device_fission)
1688CL_HPP_PARAM_NAME_DEVICE_FISSION_EXT_(CL_HPP_DECLARE_PARAM_TRAITS_)
1689#endif // cl_ext_device_fission
1690
1691#if defined(cl_khr_extended_versioning)
1692#if CL_HPP_TARGET_OPENCL_VERSION < 300
1693CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_CL3_SHARED_(CL_HPP_DECLARE_PARAM_TRAITS_)
1694#endif // CL_HPP_TARGET_OPENCL_VERSION < 300
1695CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_KHRONLY_(CL_HPP_DECLARE_PARAM_TRAITS_)
1696#endif // cl_khr_extended_versioning
1697
1698#if defined(cl_khr_semaphore)
1699CL_HPP_PARAM_NAME_CL_KHR_SEMAPHORE_(CL_HPP_DECLARE_PARAM_TRAITS_)
1700#if defined(CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR)
1701CL_HPP_DECLARE_PARAM_TRAITS_(cl_semaphore_info_khr, CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR, cl::vector<cl::Device>)
1702#endif // defined(CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR)
1703#endif // defined(cl_khr_semaphore)
1704
1705#ifdef cl_khr_external_memory
1706CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_MEMORY_(CL_HPP_DECLARE_PARAM_TRAITS_)
1707#endif // cl_khr_external_memory
1708
1709#if defined(cl_khr_external_semaphore)
1710CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_(CL_HPP_DECLARE_PARAM_TRAITS_)
1711#endif // cl_khr_external_semaphore
1712
1713#if defined(cl_khr_external_semaphore_opaque_fd)
1714CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_OPAQUE_FD_EXT(CL_HPP_DECLARE_PARAM_TRAITS_)
1715#endif // cl_khr_external_semaphore_opaque_fd
1716#if defined(cl_khr_external_semaphore_sync_fd)
1717CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_SYNC_FD_EXT(CL_HPP_DECLARE_PARAM_TRAITS_)
1718#endif // cl_khr_external_semaphore_sync_fd
1719#if defined(cl_khr_external_semaphore_win32)
1720CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_WIN32_EXT(CL_HPP_DECLARE_PARAM_TRAITS_)
1721#endif // cl_khr_external_semaphore_win32
1722
1723#if defined(cl_khr_device_uuid)
1724using uuid_array = array<cl_uchar, CL_UUID_SIZE_KHR>;
1725using luid_array = array<cl_uchar, CL_LUID_SIZE_KHR>;
1726CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_UUID_KHR, uuid_array)
1727CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DRIVER_UUID_KHR, uuid_array)
1728CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LUID_VALID_KHR, cl_bool)
1729CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LUID_KHR, luid_array)
1730CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_NODE_MASK_KHR, cl_uint)
1731#endif
1732
1733#if defined(cl_khr_pci_bus_info)
1734CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PCI_BUS_INFO_KHR, cl_device_pci_bus_info_khr)
1735#endif
1736
1737// Note: some headers do not define cl_khr_image2d_from_buffer
1738#if CL_HPP_TARGET_OPENCL_VERSION < 200
1739#if defined(CL_DEVICE_IMAGE_PITCH_ALIGNMENT_KHR)
1740CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_IMAGE_PITCH_ALIGNMENT_KHR, cl_uint)
1741#endif
1742#if defined(CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT_KHR)
1743CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT_KHR, cl_uint)
1744#endif
1745#endif // CL_HPP_TARGET_OPENCL_VERSION < 200
1746
1747#if defined(cl_khr_integer_dot_product)
1748CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGER_DOT_PRODUCT_CAPABILITIES_KHR, cl_device_integer_dot_product_capabilities_khr)
1749#if defined(CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_8BIT_KHR)
1750CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_8BIT_KHR, cl_device_integer_dot_product_acceleration_properties_khr)
1751CL_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)
1752#endif // defined(CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_8BIT_KHR)
1753#endif // defined(cl_khr_integer_dot_product)
1754
1755#if defined(cl_ext_image_requirements_info)
1756CL_HPP_PARAM_NAME_CL_IMAGE_REQUIREMENTS_EXT(CL_HPP_DECLARE_PARAM_TRAITS_)
1757#endif // cl_ext_image_requirements_info
1758
1759#if defined(cl_ext_image_from_buffer)
1760CL_HPP_PARAM_NAME_CL_IMAGE_REQUIREMENTS_SLICE_PITCH_ALIGNMENT_EXT(CL_HPP_DECLARE_PARAM_TRAITS_)
1761#endif // cl_ext_image_from_buffer
1762
1763#ifdef CL_PLATFORM_ICD_SUFFIX_KHR
1764CL_HPP_DECLARE_PARAM_TRAITS_(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, string)
1765#endif
1766
1767#ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
1768CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong)
1769#endif
1770#ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
1771CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, vector<size_type>)
1772#endif
1773#ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
1774CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint)
1775#endif
1776#ifdef CL_DEVICE_SIMD_WIDTH_AMD
1777CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint)
1778#endif
1779#ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD
1780CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint)
1781#endif
1782#ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD
1783CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint)
1784#endif
1785#ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
1786CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint)
1787#endif
1788#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
1789CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint)
1790#endif
1791#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
1792CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint)
1793#endif
1794#ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
1795CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint)
1796#endif
1797#ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
1798CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint)
1799#endif
1800#ifdef CL_DEVICE_BOARD_NAME_AMD
1801CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_BOARD_NAME_AMD, string)
1802#endif
1803
1804#ifdef CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM
1805CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM, cl_ulong)
1806#endif
1807#ifdef CL_DEVICE_JOB_SLOTS_ARM
1808CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_JOB_SLOTS_ARM, cl_uint)
1809#endif
1810#ifdef CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM
1811CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM, cl_bitfield)
1812#endif
1813#ifdef CL_DEVICE_SUPPORTED_REGISTER_ALLOCATIONS_ARM
1814CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SUPPORTED_REGISTER_ALLOCATIONS_ARM, vector<cl_uint>)
1815#endif
1816#ifdef CL_DEVICE_MAX_WARP_COUNT_ARM
1817CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_MAX_WARP_COUNT_ARM, cl_uint)
1818#endif
1819#ifdef CL_KERNEL_MAX_WARP_COUNT_ARM
1820CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_info, CL_KERNEL_MAX_WARP_COUNT_ARM, cl_uint)
1821#endif
1822#ifdef CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_ARM
1823CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_ARM, cl_uint)
1824#endif
1825#ifdef CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM
1826CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM, cl_int)
1827#endif
1828#ifdef CL_KERNEL_EXEC_INFO_WARP_COUNT_LIMIT_ARM
1829CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WARP_COUNT_LIMIT_ARM, cl_uint)
1830#endif
1831#ifdef CL_KERNEL_EXEC_INFO_COMPUTE_UNIT_MAX_QUEUED_BATCHES_ARM
1832CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_COMPUTE_UNIT_MAX_QUEUED_BATCHES_ARM, cl_uint)
1833#endif
1834
1835#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
1836CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint)
1837#endif
1838#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV
1839CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint)
1840#endif
1841#ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV
1842CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint)
1843#endif
1844#ifdef CL_DEVICE_WARP_SIZE_NV
1845CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint)
1846#endif
1847#ifdef CL_DEVICE_GPU_OVERLAP_NV
1848CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool)
1849#endif
1850#ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV
1851CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool)
1852#endif
1853#ifdef CL_DEVICE_INTEGRATED_MEMORY_NV
1854CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool)
1855#endif
1856
1857#if defined(cl_khr_command_buffer)
1858CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMMAND_BUFFER_CAPABILITIES_KHR, cl_device_command_buffer_capabilities_khr)
1859CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMMAND_BUFFER_REQUIRED_QUEUE_PROPERTIES_KHR, cl_command_queue_properties)
1860CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_QUEUES_KHR, cl::vector<CommandQueue>)
1861CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_NUM_QUEUES_KHR, cl_uint)
1862CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_REFERENCE_COUNT_KHR, cl_uint)
1863CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_STATE_KHR, cl_command_buffer_state_khr)
1864CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_PROPERTIES_ARRAY_KHR, cl::vector<cl_command_buffer_properties_khr>)
1865#endif /* cl_khr_command_buffer */
1866
1867#if defined(cl_khr_command_buffer_mutable_dispatch)
1868CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_COMMAND_COMMAND_QUEUE_KHR, CommandQueue)
1869CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_COMMAND_COMMAND_BUFFER_KHR, CommandBufferKhr)
1870CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_COMMAND_COMMAND_TYPE_KHR, cl_command_type)
1871
1872#if CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 2)
1873CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_COMMAND_PROPERTIES_ARRAY_KHR, cl::vector<cl_command_properties_khr>)
1874#else
1875CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_PROPERTIES_ARRAY_KHR, cl::vector<cl_ndrange_kernel_command_properties_khr>)
1876#endif
1877CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_KERNEL_KHR, cl_kernel)
1878CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_DIMENSIONS_KHR, cl_uint)
1879CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_GLOBAL_WORK_OFFSET_KHR, cl::vector<size_type>)
1880CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_GLOBAL_WORK_SIZE_KHR, cl::vector<size_type>)
1881CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_LOCAL_WORK_SIZE_KHR, cl::vector<size_type>)
1882#endif /* cl_khr_command_buffer_mutable_dispatch */
1883
1884#if defined(cl_khr_kernel_clock)
1885CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_CLOCK_CAPABILITIES_KHR, cl_device_kernel_clock_capabilities_khr)
1886#endif /* cl_khr_kernel_clock */
1887
1888#if defined(cl_ext_float_atomics)
1889CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SINGLE_FP_ATOMIC_CAPABILITIES_EXT, cl_device_fp_atomic_capabilities_ext)
1890CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_DOUBLE_FP_ATOMIC_CAPABILITIES_EXT, cl_device_fp_atomic_capabilities_ext)
1891CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_HALF_FP_ATOMIC_CAPABILITIES_EXT, cl_device_fp_atomic_capabilities_ext)
1892#endif /* cl_ext_float_atomics */
1893
1894#if defined(cl_intel_command_queue_families)
1895CL_HPP_PARAM_NAME_CL_INTEL_COMMAND_QUEUE_FAMILIES_(CL_HPP_DECLARE_PARAM_TRAITS_)
1896#endif // cl_intel_command_queue_families
1897
1898#if defined(cl_intel_device_attribute_query)
1899CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_IP_VERSION_INTEL, cl_uint)
1900CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_ID_INTEL, cl_uint)
1901CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_NUM_SLICES_INTEL, cl_uint)
1902CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_NUM_SUB_SLICES_PER_SLICE_INTEL, cl_uint)
1903CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_NUM_EUS_PER_SUB_SLICE_INTEL, cl_uint)
1904CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_NUM_THREADS_PER_EU_INTEL, cl_uint)
1905CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_FEATURE_CAPABILITIES_INTEL, cl_device_feature_capabilities_intel)
1906#endif // cl_intel_device_attribute_query
1907
1908#if defined(cl_intel_required_subgroup_size)
1909CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SUB_GROUP_SIZES_INTEL, cl::vector<size_type>)
1910CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_work_group_info, CL_KERNEL_SPILL_MEM_SIZE_INTEL, cl_ulong)
1911#endif // cl_intel_required_subgroup_size
1912
1913#if defined(cl_intel_unified_shared_memory)
1914CL_HPP_PARAM_NAME_CL_INTEL_UNIFIED_SHARED_MEMORY_(CL_HPP_DECLARE_PARAM_TRAITS_)
1915#endif // cl_intel_unified_shared_memory
1916
1917// Convenience functions
1918
1919template <typename Func, typename T>
1920inline cl_int
1921getInfo(Func f, cl_uint name, T* param)
1922{
1923 return getInfoHelper(f, name, param, 0);
1924}
1925
1926template <typename Func, typename Arg0>
1927struct GetInfoFunctor0
1928{
1929 Func f_; const Arg0& arg0_;
1930 cl_int operator ()(
1931 cl_uint param, size_type size, void* value, size_type* size_ret)
1932 { return f_(arg0_, param, size, value, size_ret); }
1933};
1934
1935template <typename Func, typename Arg0, typename Arg1>
1936struct GetInfoFunctor1
1937{
1938 Func f_; const Arg0& arg0_; const Arg1& arg1_;
1939 cl_int operator ()(
1940 cl_uint param, size_type size, void* value, size_type* size_ret)
1941 { return f_(arg0_, arg1_, param, size, value, size_ret); }
1942};
1943
1944template <typename Func, typename Arg0, typename T>
1945inline cl_int
1946getInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
1947{
1948 GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
1949 return getInfoHelper(f0, name, param, 0);
1950}
1951
1952template <typename Func, typename Arg0, typename Arg1, typename T>
1953inline cl_int
1954getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
1955{
1956 GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
1957 return getInfoHelper(f0, name, param, 0);
1958}
1959
1960
1961template<typename T>
1962struct ReferenceHandler
1963{ };
1964
1965#if CL_HPP_TARGET_OPENCL_VERSION >= 120
1969template <>
1970struct ReferenceHandler<cl_device_id>
1971{
1981 static cl_int retain(cl_device_id device)
1982 { return ::clRetainDevice(device); }
1992 static cl_int release(cl_device_id device)
1993 { return ::clReleaseDevice(device); }
1994};
1995#else // CL_HPP_TARGET_OPENCL_VERSION >= 120
1999template <>
2000struct ReferenceHandler<cl_device_id>
2001{
2002 // cl_device_id does not have retain().
2003 static cl_int retain(cl_device_id)
2004 { return CL_SUCCESS; }
2005 // cl_device_id does not have release().
2006 static cl_int release(cl_device_id)
2007 { return CL_SUCCESS; }
2008};
2009#endif // ! (CL_HPP_TARGET_OPENCL_VERSION >= 120)
2010
2011template <>
2012struct ReferenceHandler<cl_platform_id>
2013{
2014 // cl_platform_id does not have retain().
2015 static cl_int retain(cl_platform_id)
2016 { return CL_SUCCESS; }
2017 // cl_platform_id does not have release().
2018 static cl_int release(cl_platform_id)
2019 { return CL_SUCCESS; }
2020};
2021
2022template <>
2023struct ReferenceHandler<cl_context>
2024{
2025 static cl_int retain(cl_context context)
2026 { return ::clRetainContext(context); }
2027 static cl_int release(cl_context context)
2028 { return ::clReleaseContext(context); }
2029};
2030
2031template <>
2032struct ReferenceHandler<cl_command_queue>
2033{
2034 static cl_int retain(cl_command_queue queue)
2035 { return ::clRetainCommandQueue(queue); }
2036 static cl_int release(cl_command_queue queue)
2037 { return ::clReleaseCommandQueue(queue); }
2038};
2039
2040template <>
2041struct ReferenceHandler<cl_mem>
2042{
2043 static cl_int retain(cl_mem memory)
2044 { return ::clRetainMemObject(memory); }
2045 static cl_int release(cl_mem memory)
2046 { return ::clReleaseMemObject(memory); }
2047};
2048
2049template <>
2050struct ReferenceHandler<cl_sampler>
2051{
2052 static cl_int retain(cl_sampler sampler)
2053 { return ::clRetainSampler(sampler); }
2054 static cl_int release(cl_sampler sampler)
2055 { return ::clReleaseSampler(sampler); }
2056};
2057
2058template <>
2059struct ReferenceHandler<cl_program>
2060{
2061 static cl_int retain(cl_program program)
2062 { return ::clRetainProgram(program); }
2063 static cl_int release(cl_program program)
2064 { return ::clReleaseProgram(program); }
2065};
2066
2067template <>
2068struct ReferenceHandler<cl_kernel>
2069{
2070 static cl_int retain(cl_kernel kernel)
2071 { return ::clRetainKernel(kernel); }
2072 static cl_int release(cl_kernel kernel)
2073 { return ::clReleaseKernel(kernel); }
2074};
2075
2076template <>
2077struct ReferenceHandler<cl_event>
2078{
2079 static cl_int retain(cl_event event)
2080 { return ::clRetainEvent(event); }
2081 static cl_int release(cl_event event)
2082 { return ::clReleaseEvent(event); }
2083};
2084
2085#ifdef cl_khr_semaphore
2086template <>
2087struct ReferenceHandler<cl_semaphore_khr>
2088{
2089 static cl_int retain(cl_semaphore_khr semaphore)
2090 {
2091 if (pfn_clRetainSemaphoreKHR != nullptr) {
2092 return pfn_clRetainSemaphoreKHR(semaphore);
2093 }
2094
2095 return CL_INVALID_OPERATION;
2096 }
2097
2098 static cl_int release(cl_semaphore_khr semaphore)
2099 {
2100 if (pfn_clReleaseSemaphoreKHR != nullptr) {
2101 return pfn_clReleaseSemaphoreKHR(semaphore);
2102 }
2103
2104 return CL_INVALID_OPERATION;
2105 }
2106};
2107#endif // cl_khr_semaphore
2108#if defined(cl_khr_command_buffer)
2109template <>
2110struct ReferenceHandler<cl_command_buffer_khr>
2111{
2112 static cl_int retain(cl_command_buffer_khr cmdBufferKhr)
2113 {
2114 if (pfn_clRetainCommandBufferKHR == nullptr) {
2115 return detail::errHandler(CL_INVALID_OPERATION, __RETAIN_COMMAND_BUFFER_KHR_ERR);
2116 }
2117 return pfn_clRetainCommandBufferKHR(cmdBufferKhr);
2118 }
2119
2120 static cl_int release(cl_command_buffer_khr cmdBufferKhr)
2121 {
2122 if (pfn_clReleaseCommandBufferKHR == nullptr) {
2123 return detail::errHandler(CL_INVALID_OPERATION, __RELEASE_COMMAND_BUFFER_KHR_ERR);
2124 }
2125 return pfn_clReleaseCommandBufferKHR(cmdBufferKhr);
2126 }
2127};
2128
2129template <>
2130struct ReferenceHandler<cl_mutable_command_khr>
2131{
2132 // cl_mutable_command_khr does not have retain().
2133 static cl_int retain(cl_mutable_command_khr)
2134 { return CL_SUCCESS; }
2135 // cl_mutable_command_khr does not have release().
2136 static cl_int release(cl_mutable_command_khr)
2137 { return CL_SUCCESS; }
2138};
2139#endif // cl_khr_command_buffer
2140
2141
2142#if (CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120) || \
2143 (CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200)
2144// Extracts version number with major in the upper 16 bits, minor in the lower 16
2145static cl_uint getVersion(const vector<char> &versionInfo)
2146{
2147 int highVersion = 0;
2148 int lowVersion = 0;
2149 int index = 7;
2150 while(versionInfo[index] != '.' ) {
2151 highVersion *= 10;
2152 highVersion += versionInfo[index]-'0';
2153 ++index;
2154 }
2155 ++index;
2156 while(versionInfo[index] != ' ' && versionInfo[index] != '\0') {
2157 lowVersion *= 10;
2158 lowVersion += versionInfo[index]-'0';
2159 ++index;
2160 }
2161 return (highVersion << 16) | lowVersion;
2162}
2163
2164static cl_uint getPlatformVersion(cl_platform_id platform)
2165{
2166 size_type size = 0;
2167 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, nullptr, &size);
2168
2169 vector<char> versionInfo(size);
2170 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, versionInfo.data(), &size);
2171 return getVersion(versionInfo);
2172}
2173
2174static cl_uint getDevicePlatformVersion(cl_device_id device)
2175{
2176 cl_platform_id platform;
2177 clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, nullptr);
2178 return getPlatformVersion(platform);
2179}
2180
2181static cl_uint getContextPlatformVersion(cl_context context)
2182{
2183 // The platform cannot be queried directly, so we first have to grab a
2184 // device and obtain its context
2185 size_type size = 0;
2186 clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, nullptr, &size);
2187 if (size == 0)
2188 return 0;
2189 vector<cl_device_id> devices(size/sizeof(cl_device_id));
2190 clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices.data(), nullptr);
2191 return getDevicePlatformVersion(devices[0]);
2192}
2193#endif // CL_HPP_TARGET_OPENCL_VERSION && CL_HPP_MINIMUM_OPENCL_VERSION
2194
2195template <typename T>
2196class Wrapper
2197{
2198public:
2199 typedef T cl_type;
2200
2201protected:
2202 cl_type object_;
2203
2204public:
2205 Wrapper() : object_(nullptr) { }
2206
2207 Wrapper(const cl_type &obj, bool retainObject) : object_(obj)
2208 {
2209 if (retainObject) {
2210 detail::errHandler(retain(), __RETAIN_ERR);
2211 }
2212 }
2213
2214 ~Wrapper()
2215 {
2216 if (object_ != nullptr) { release(); }
2217 }
2218
2219 Wrapper(const Wrapper<cl_type>& rhs)
2220 {
2221 object_ = rhs.object_;
2222 detail::errHandler(retain(), __RETAIN_ERR);
2223 }
2224
2225 Wrapper(Wrapper<cl_type>&& rhs) noexcept
2226 {
2227 object_ = rhs.object_;
2228 rhs.object_ = nullptr;
2229 }
2230
2231 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
2232 {
2233 if (this != &rhs) {
2234 detail::errHandler(release(), __RELEASE_ERR);
2235 object_ = rhs.object_;
2236 detail::errHandler(retain(), __RETAIN_ERR);
2237 }
2238 return *this;
2239 }
2240
2241 Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
2242 {
2243 if (this != &rhs) {
2244 detail::errHandler(release(), __RELEASE_ERR);
2245 object_ = rhs.object_;
2246 rhs.object_ = nullptr;
2247 }
2248 return *this;
2249 }
2250
2251 Wrapper<cl_type>& operator = (const cl_type &rhs)
2252 {
2253 detail::errHandler(release(), __RELEASE_ERR);
2254 object_ = rhs;
2255 return *this;
2256 }
2257
2258 const cl_type& operator ()() const { return object_; }
2259
2260 cl_type& operator ()() { return object_; }
2261
2262 cl_type get() const { return object_; }
2263
2264protected:
2265 template<typename Func, typename U>
2266 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
2267
2268 cl_int retain() const
2269 {
2270 if (object_ != nullptr) {
2271 return ReferenceHandler<cl_type>::retain(object_);
2272 }
2273 else {
2274 return CL_SUCCESS;
2275 }
2276 }
2277
2278 cl_int release() const
2279 {
2280 if (object_ != nullptr) {
2281 return ReferenceHandler<cl_type>::release(object_);
2282 }
2283 else {
2284 return CL_SUCCESS;
2285 }
2286 }
2287};
2288
2289template <>
2290class Wrapper<cl_device_id>
2291{
2292public:
2293 typedef cl_device_id cl_type;
2294
2295protected:
2296 cl_type object_;
2297 bool referenceCountable_;
2298
2299 static bool isReferenceCountable(cl_device_id device)
2300 {
2301 bool retVal = false;
2302#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
2303 if (device != nullptr) {
2304 int version = getDevicePlatformVersion(device);
2305 if(version > ((1 << 16) + 1)) {
2306 retVal = true;
2307 }
2308 }
2309#elif CL_HPP_TARGET_OPENCL_VERSION >= 120
2310 retVal = true;
2311#endif // CL_HPP_TARGET_OPENCL_VERSION
2312 (void)device;
2313 return retVal;
2314 }
2315
2316public:
2317 Wrapper() : object_(nullptr), referenceCountable_(false)
2318 {
2319 }
2320
2321 Wrapper(const cl_type &obj, bool retainObject) :
2322 object_(obj),
2323 referenceCountable_(false)
2324 {
2325 referenceCountable_ = isReferenceCountable(obj);
2326
2327 if (retainObject) {
2328 detail::errHandler(retain(), __RETAIN_ERR);
2329 }
2330 }
2331
2332 ~Wrapper()
2333 {
2334 release();
2335 }
2336
2337 Wrapper(const Wrapper<cl_type>& rhs)
2338 {
2339 object_ = rhs.object_;
2340 referenceCountable_ = isReferenceCountable(object_);
2341 detail::errHandler(retain(), __RETAIN_ERR);
2342 }
2343
2344 Wrapper(Wrapper<cl_type>&& rhs) noexcept
2345 {
2346 object_ = rhs.object_;
2347 referenceCountable_ = rhs.referenceCountable_;
2348 rhs.object_ = nullptr;
2349 rhs.referenceCountable_ = false;
2350 }
2351
2352 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
2353 {
2354 if (this != &rhs) {
2355 detail::errHandler(release(), __RELEASE_ERR);
2356 object_ = rhs.object_;
2357 referenceCountable_ = rhs.referenceCountable_;
2358 detail::errHandler(retain(), __RETAIN_ERR);
2359 }
2360 return *this;
2361 }
2362
2363 Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
2364 {
2365 if (this != &rhs) {
2366 detail::errHandler(release(), __RELEASE_ERR);
2367 object_ = rhs.object_;
2368 referenceCountable_ = rhs.referenceCountable_;
2369 rhs.object_ = nullptr;
2370 rhs.referenceCountable_ = false;
2371 }
2372 return *this;
2373 }
2374
2375 Wrapper<cl_type>& operator = (const cl_type &rhs)
2376 {
2377 detail::errHandler(release(), __RELEASE_ERR);
2378 object_ = rhs;
2379 referenceCountable_ = isReferenceCountable(object_);
2380 return *this;
2381 }
2382
2383 const cl_type& operator ()() const { return object_; }
2384
2385 cl_type& operator ()() { return object_; }
2386
2387 cl_type get() const { return object_; }
2388
2389protected:
2390 template<typename Func, typename U>
2391 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
2392
2393 template<typename Func, typename U>
2394 friend inline cl_int getInfoHelper(Func, cl_uint, vector<U>*, int, typename U::cl_type);
2395
2396 cl_int retain() const
2397 {
2398 if( object_ != nullptr && referenceCountable_ ) {
2399 return ReferenceHandler<cl_type>::retain(object_);
2400 }
2401 else {
2402 return CL_SUCCESS;
2403 }
2404 }
2405
2406 cl_int release() const
2407 {
2408 if (object_ != nullptr && referenceCountable_) {
2409 return ReferenceHandler<cl_type>::release(object_);
2410 }
2411 else {
2412 return CL_SUCCESS;
2413 }
2414 }
2415};
2416
2417template <typename T>
2418inline bool operator==(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
2419{
2420 return lhs() == rhs();
2421}
2422
2423template <typename T>
2424inline bool operator!=(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
2425{
2426 return !operator==(lhs, rhs);
2427}
2428
2429} // namespace detail
2431
2432
2433
2434
2435
2441struct ImageFormat : public cl_image_format
2442{
2444 ImageFormat(){}
2445
2447 ImageFormat(cl_channel_order order, cl_channel_type type)
2448 {
2449 image_channel_order = order;
2450 image_channel_data_type = type;
2451 }
2452
2454 ImageFormat(const ImageFormat &other) { *this = other; }
2455
2457 ImageFormat& operator = (const ImageFormat& rhs)
2458 {
2459 if (this != &rhs) {
2460 this->image_channel_data_type = rhs.image_channel_data_type;
2461 this->image_channel_order = rhs.image_channel_order;
2462 }
2463 return *this;
2464 }
2465};
2466
2474class Device : public detail::Wrapper<cl_device_id>
2475{
2476private:
2477 static std::once_flag default_initialized_;
2478 static Device default_;
2479 static cl_int default_error_;
2480
2486 static void makeDefault();
2487
2493 static void makeDefaultProvided(const Device &p) {
2494 default_ = p;
2495 }
2496
2497public:
2498#ifdef CL_HPP_UNIT_TEST_ENABLE
2505 static void unitTestClearDefault() {
2506 default_ = Device();
2507 }
2508#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2509
2511 Device() : detail::Wrapper<cl_type>() { }
2512
2517 explicit Device(const cl_device_id &device, bool retainObject = false) :
2518 detail::Wrapper<cl_type>(device, retainObject) { }
2519
2524 static Device getDefault(
2525 cl_int *errResult = nullptr)
2526 {
2527 std::call_once(default_initialized_, makeDefault);
2528 detail::errHandler(default_error_);
2529 if (errResult != nullptr) {
2530 *errResult = default_error_;
2531 }
2532 return default_;
2533 }
2534
2542 static Device setDefault(const Device &default_device)
2543 {
2544 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_device));
2545 detail::errHandler(default_error_);
2546 return default_;
2547 }
2548
2553 Device& operator = (const cl_device_id& rhs)
2554 {
2555 detail::Wrapper<cl_type>::operator=(rhs);
2556 return *this;
2557 }
2558
2559
2561 template <typename T>
2562 cl_int getInfo(cl_device_info name, T* param) const
2563 {
2564 return detail::errHandler(
2565 detail::getInfo(&::clGetDeviceInfo, object_, name, param),
2566 __GET_DEVICE_INFO_ERR);
2567 }
2568
2570 template <cl_device_info name> typename
2571 detail::param_traits<detail::cl_device_info, name>::param_type
2572 getInfo(cl_int* err = nullptr) const
2573 {
2574 typename detail::param_traits<
2575 detail::cl_device_info, name>::param_type param;
2576 cl_int result = getInfo(name, &param);
2577 if (err != nullptr) {
2578 *err = result;
2579 }
2580 return param;
2581 }
2582
2583#if CL_HPP_TARGET_OPENCL_VERSION >= 210
2590 cl_ulong getHostTimer(cl_int *error = nullptr)
2591 {
2592 cl_ulong retVal = 0;
2593 cl_int err =
2594 clGetHostTimer(this->get(), &retVal);
2595 detail::errHandler(
2596 err,
2597 __GET_HOST_TIMER_ERR);
2598 if (error) {
2599 *error = err;
2600 }
2601 return retVal;
2602 }
2603
2614 std::pair<cl_ulong, cl_ulong> getDeviceAndHostTimer(cl_int *error = nullptr)
2615 {
2616 std::pair<cl_ulong, cl_ulong> retVal;
2617 cl_int err =
2618 clGetDeviceAndHostTimer(this->get(), &(retVal.first), &(retVal.second));
2619 detail::errHandler(
2620 err,
2621 __GET_DEVICE_AND_HOST_TIMER_ERR);
2622 if (error) {
2623 *error = err;
2624 }
2625 return retVal;
2626 }
2627#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2628
2629#if CL_HPP_TARGET_OPENCL_VERSION >= 120
2631 cl_int createSubDevices(const cl_device_partition_property* properties,
2632 vector<Device>* devices);
2633#endif // defined (CL_HPP_TARGET_OPENCL_VERSION >= 120)
2634
2635#if defined(cl_ext_device_fission)
2637 cl_int createSubDevices(const cl_device_partition_property_ext* properties,
2638 vector<Device>* devices);
2639#endif // defined(cl_ext_device_fission)
2640};
2641
2642using BuildLogType = vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, CL_PROGRAM_BUILD_LOG>::param_type>>;
2643#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2647class BuildError : public Error
2648{
2649private:
2650 BuildLogType buildLogs;
2651public:
2652 BuildError(cl_int err, const char * errStr, const BuildLogType &vec) : Error(err, errStr), buildLogs(vec)
2653 {
2654 }
2655
2656 BuildLogType getBuildLog() const
2657 {
2658 return buildLogs;
2659 }
2660};
2661namespace detail {
2662 static inline cl_int buildErrHandler(
2663 cl_int err,
2664 const char * errStr,
2665 const BuildLogType &buildLogs)
2666 {
2667 if (err != CL_SUCCESS) {
2668 throw BuildError(err, errStr, buildLogs);
2669 }
2670 return err;
2671 }
2672} // namespace detail
2673
2674#else
2675namespace detail {
2676 static inline cl_int buildErrHandler(
2677 cl_int err,
2678 const char * errStr,
2679 const BuildLogType &buildLogs)
2680 {
2681 (void)buildLogs; // suppress unused variable warning
2682 (void)errStr;
2683 return err;
2684 }
2685} // namespace detail
2686#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2687
2688CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Device::default_initialized_;
2689CL_HPP_DEFINE_STATIC_MEMBER_ Device Device::default_;
2690CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Device::default_error_ = CL_SUCCESS;
2691
2699class Platform : public detail::Wrapper<cl_platform_id>
2700{
2701private:
2702 static std::once_flag default_initialized_;
2703 static Platform default_;
2704 static cl_int default_error_;
2705
2711 static void makeDefault() {
2712 /* Throwing an exception from a call_once invocation does not do
2713 * what we wish, so we catch it and save the error.
2714 */
2715#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2716 try
2717#endif
2718 {
2719 // If default wasn't passed ,generate one
2720 // Otherwise set it
2721 cl_uint n = 0;
2722
2723 cl_int err = ::clGetPlatformIDs(0, nullptr, &n);
2724 if (err != CL_SUCCESS) {
2725 default_error_ = err;
2726 return;
2727 }
2728 if (n == 0) {
2729 default_error_ = CL_INVALID_PLATFORM;
2730 return;
2731 }
2732
2733 vector<cl_platform_id> ids(n);
2734 err = ::clGetPlatformIDs(n, ids.data(), nullptr);
2735 if (err != CL_SUCCESS) {
2736 default_error_ = err;
2737 return;
2738 }
2739
2740 default_ = Platform(ids[0]);
2741 }
2742#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2743 catch (cl::Error &e) {
2744 default_error_ = e.err();
2745 }
2746#endif
2747 }
2748
2754 static void makeDefaultProvided(const Platform &p) {
2755 default_ = p;
2756 }
2757
2758public:
2759#ifdef CL_HPP_UNIT_TEST_ENABLE
2766 static void unitTestClearDefault() {
2767 default_ = Platform();
2768 }
2769#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2770
2772 Platform() : detail::Wrapper<cl_type>() { }
2773
2781 explicit Platform(const cl_platform_id &platform, bool retainObject = false) :
2782 detail::Wrapper<cl_type>(platform, retainObject) { }
2783
2788 Platform& operator = (const cl_platform_id& rhs)
2789 {
2790 detail::Wrapper<cl_type>::operator=(rhs);
2791 return *this;
2792 }
2793
2794 static Platform getDefault(
2795 cl_int *errResult = nullptr)
2796 {
2797 std::call_once(default_initialized_, makeDefault);
2798 detail::errHandler(default_error_);
2799 if (errResult != nullptr) {
2800 *errResult = default_error_;
2801 }
2802 return default_;
2803 }
2804
2812 static Platform setDefault(const Platform &default_platform)
2813 {
2814 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_platform));
2815 detail::errHandler(default_error_);
2816 return default_;
2817 }
2818
2820 template <typename T>
2821 cl_int getInfo(cl_platform_info name, T* param) const
2822 {
2823 return detail::errHandler(
2824 detail::getInfo(&::clGetPlatformInfo, object_, name, param),
2825 __GET_PLATFORM_INFO_ERR);
2826 }
2827
2829 template <cl_platform_info name> typename
2830 detail::param_traits<detail::cl_platform_info, name>::param_type
2831 getInfo(cl_int* err = nullptr) const
2832 {
2833 typename detail::param_traits<
2834 detail::cl_platform_info, name>::param_type param;
2835 cl_int result = getInfo(name, &param);
2836 if (err != nullptr) {
2837 *err = result;
2838 }
2839 return param;
2840 }
2841
2846 cl_int getDevices(
2847 cl_device_type type,
2848 vector<Device>* devices) const
2849 {
2850 cl_uint n = 0;
2851 if( devices == nullptr ) {
2852 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2853 }
2854 cl_int err = ::clGetDeviceIDs(object_, type, 0, nullptr, &n);
2855 if (err != CL_SUCCESS && err != CL_DEVICE_NOT_FOUND) {
2856 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2857 }
2858
2859 vector<cl_device_id> ids(n);
2860 if (n>0) {
2861 err = ::clGetDeviceIDs(object_, type, n, ids.data(), nullptr);
2862 if (err != CL_SUCCESS) {
2863 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2864 }
2865 }
2866
2867 // Cannot trivially assign because we need to capture intermediates
2868 // with safe construction
2869 // We must retain things we obtain from the API to avoid releasing
2870 // API-owned objects.
2871 if (devices) {
2872 devices->resize(ids.size());
2873
2874 // Assign to param, constructing with retain behaviour
2875 // to correctly capture each underlying CL object
2876 for (size_type i = 0; i < ids.size(); i++) {
2877 (*devices)[i] = Device(ids[i], true);
2878 }
2879 }
2880 return CL_SUCCESS;
2881 }
2882
2883#if defined(CL_HPP_USE_DX_INTEROP)
2907 cl_int getDevices(
2908 cl_d3d10_device_source_khr d3d_device_source,
2909 void * d3d_object,
2910 cl_d3d10_device_set_khr d3d_device_set,
2911 vector<Device>* devices) const
2912 {
2913 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
2914 cl_platform_id platform,
2915 cl_d3d10_device_source_khr d3d_device_source,
2916 void * d3d_object,
2917 cl_d3d10_device_set_khr d3d_device_set,
2918 cl_uint num_entries,
2919 cl_device_id * devices,
2920 cl_uint* num_devices);
2921
2922 if( devices == nullptr ) {
2923 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2924 }
2925
2926 static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = nullptr;
2927#if CL_HPP_TARGET_OPENCL_VERSION >= 120
2928 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(object_, clGetDeviceIDsFromD3D10KHR);
2929#endif
2930#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
2931 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetDeviceIDsFromD3D10KHR);
2932#endif
2933
2934 cl_uint n = 0;
2935 cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
2936 object_,
2937 d3d_device_source,
2938 d3d_object,
2939 d3d_device_set,
2940 0,
2941 nullptr,
2942 &n);
2943 if (err != CL_SUCCESS) {
2944 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2945 }
2946
2947 vector<cl_device_id> ids(n);
2948 err = pfn_clGetDeviceIDsFromD3D10KHR(
2949 object_,
2950 d3d_device_source,
2951 d3d_object,
2952 d3d_device_set,
2953 n,
2954 ids.data(),
2955 nullptr);
2956 if (err != CL_SUCCESS) {
2957 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2958 }
2959
2960 // Cannot trivially assign because we need to capture intermediates
2961 // with safe construction
2962 // We must retain things we obtain from the API to avoid releasing
2963 // API-owned objects.
2964 if (devices) {
2965 devices->resize(ids.size());
2966
2967 // Assign to param, constructing with retain behaviour
2968 // to correctly capture each underlying CL object
2969 for (size_type i = 0; i < ids.size(); i++) {
2970 (*devices)[i] = Device(ids[i], true);
2971 }
2972 }
2973 return CL_SUCCESS;
2974 }
2975#endif
2976
2981 static cl_int get(
2982 vector<Platform>* platforms)
2983 {
2984 cl_uint n = 0;
2985
2986 if( platforms == nullptr ) {
2987 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
2988 }
2989
2990 cl_int err = ::clGetPlatformIDs(0, nullptr, &n);
2991 if (err != CL_SUCCESS) {
2992 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2993 }
2994
2995 vector<cl_platform_id> ids(n);
2996 err = ::clGetPlatformIDs(n, ids.data(), nullptr);
2997 if (err != CL_SUCCESS) {
2998 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2999 }
3000
3001 if (platforms) {
3002 platforms->resize(ids.size());
3003
3004 // Platforms don't reference count
3005 for (size_type i = 0; i < ids.size(); i++) {
3006 (*platforms)[i] = Platform(ids[i]);
3007 }
3008 }
3009 return CL_SUCCESS;
3010 }
3011
3016 static cl_int get(
3017 Platform * platform)
3018 {
3019 cl_int err;
3020 Platform default_platform = Platform::getDefault(&err);
3021 if (platform) {
3022 *platform = default_platform;
3023 }
3024 return err;
3025 }
3026
3035 static Platform get(
3036 cl_int * errResult = nullptr)
3037 {
3038 cl_int err;
3039 Platform default_platform = Platform::getDefault(&err);
3040 if (errResult) {
3041 *errResult = err;
3042 }
3043 return default_platform;
3044 }
3045
3046#if CL_HPP_TARGET_OPENCL_VERSION >= 120
3048 cl_int
3049 unloadCompiler()
3050 {
3051 return ::clUnloadPlatformCompiler(object_);
3052 }
3053#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
3054}; // class Platform
3055
3056#if CL_HPP_TARGET_OPENCL_VERSION >= 120
3058inline cl_int Device::createSubDevices(const cl_device_partition_property* properties,
3059 vector<Device>* devices)
3060{
3061 cl_uint n = 0;
3062 cl_int err = clCreateSubDevices(object_, properties, 0, nullptr, &n);
3063 if (err != CL_SUCCESS)
3064 {
3065 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
3066 }
3067
3068 vector<cl_device_id> ids(n);
3069 err = clCreateSubDevices(object_, properties, n, ids.data(), nullptr);
3070 if (err != CL_SUCCESS)
3071 {
3072 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
3073 }
3074
3075 // Cannot trivially assign because we need to capture intermediates
3076 // with safe construction
3077 if (devices)
3078 {
3079 devices->resize(ids.size());
3080
3081 // Assign to param, constructing with retain behaviour
3082 // to correctly capture each underlying CL object
3083 for (size_type i = 0; i < ids.size(); i++)
3084 {
3085 // We do not need to retain because this device is being created
3086 // by the runtime
3087 (*devices)[i] = Device(ids[i], false);
3088 }
3089 }
3090
3091 return CL_SUCCESS;
3092}
3093#endif // defined (CL_HPP_TARGET_OPENCL_VERSION >= 120)
3094
3095#if defined(cl_ext_device_fission)
3097inline cl_int Device::createSubDevices(const cl_device_partition_property_ext* properties,
3098 vector<Device>* devices)
3099{
3100#if CL_HPP_TARGET_OPENCL_VERSION >= 120
3101 cl::Device device(object_);
3102 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>()();
3103 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateSubDevicesEXT);
3104#endif
3105#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
3106 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSubDevicesEXT);
3107#endif
3108
3109 cl_uint n = 0;
3110 cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, nullptr, &n);
3111 if (err != CL_SUCCESS)
3112 {
3113 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
3114 }
3115
3116 vector<cl_device_id> ids(n);
3117 err =
3118 pfn_clCreateSubDevicesEXT(object_, properties, n, ids.data(), nullptr);
3119 if (err != CL_SUCCESS)
3120 {
3121 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
3122 }
3123 // Cannot trivially assign because we need to capture intermediates
3124 // with safe construction
3125 if (devices)
3126 {
3127 devices->resize(ids.size());
3128
3129 // Assign to param, constructing with retain behaviour
3130 // to correctly capture each underlying CL object
3131 for (size_type i = 0; i < ids.size(); i++)
3132 {
3133 // We do not need to retain because this device is being created
3134 // by the runtime
3135 (*devices)[i] = Device(ids[i], false);
3136 }
3137 }
3138
3139 return CL_SUCCESS;
3140}
3141#endif // defined(cl_ext_device_fission)
3142
3143CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Platform::default_initialized_;
3144CL_HPP_DEFINE_STATIC_MEMBER_ Platform Platform::default_;
3145CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Platform::default_error_ = CL_SUCCESS;
3146
3147
3151#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
3156inline CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int
3157 UnloadCompiler() CL_API_SUFFIX__VERSION_1_1_DEPRECATED;
3158inline cl_int
3159 UnloadCompiler()
3160{
3161 return ::clUnloadCompiler();
3162}
3163#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
3164
3165
3166#if defined(cl_ext_image_requirements_info)
3167enum ImageRequirementsInfoExt : cl_image_requirements_info_ext
3168{
3169 RowPitchAlign = CL_IMAGE_REQUIREMENTS_ROW_PITCH_ALIGNMENT_EXT,
3170 BaseAddAlign = CL_IMAGE_REQUIREMENTS_BASE_ADDRESS_ALIGNMENT_EXT,
3171 Size = CL_IMAGE_REQUIREMENTS_SIZE_EXT,
3172 MaxWidth = CL_IMAGE_REQUIREMENTS_MAX_WIDTH_EXT,
3173 MaxHeight = CL_IMAGE_REQUIREMENTS_MAX_HEIGHT_EXT,
3174 MaxDepth = CL_IMAGE_REQUIREMENTS_MAX_DEPTH_EXT,
3175 MaxArraySize = CL_IMAGE_REQUIREMENTS_MAX_ARRAY_SIZE_EXT,
3176#if defined(cl_ext_image_from_buffer)
3177 SlicePitchAlign = CL_IMAGE_REQUIREMENTS_SLICE_PITCH_ALIGNMENT_EXT,
3178#endif
3179};
3180
3181#endif // cl_ext_image_requirements_info
3182
3183
3192class Context
3193 : public detail::Wrapper<cl_context>
3194{
3195private:
3196 static std::once_flag default_initialized_;
3197 static Context default_;
3198 static cl_int default_error_;
3199
3205 static void makeDefault() {
3206 /* Throwing an exception from a call_once invocation does not do
3207 * what we wish, so we catch it and save the error.
3208 */
3209#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3210 try
3211#endif
3212 {
3213#if !defined(__APPLE__) && !defined(__MACOS)
3214 const Platform &p = Platform::getDefault();
3215 cl_platform_id defaultPlatform = p();
3216 cl_context_properties properties[3] = {
3217 CL_CONTEXT_PLATFORM, (cl_context_properties)defaultPlatform, 0
3218 };
3219#else // #if !defined(__APPLE__) && !defined(__MACOS)
3220 cl_context_properties *properties = nullptr;
3221#endif // #if !defined(__APPLE__) && !defined(__MACOS)
3222
3223 default_ = Context(
3224 CL_DEVICE_TYPE_DEFAULT,
3225 properties,
3226 nullptr,
3227 nullptr,
3228 &default_error_);
3229 }
3230#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3231 catch (cl::Error &e) {
3232 default_error_ = e.err();
3233 }
3234#endif
3235 }
3236
3237
3243 static void makeDefaultProvided(const Context &c) {
3244 default_ = c;
3245 }
3246
3247#if defined(cl_ext_image_requirements_info)
3248 struct ImageRequirementsInfo {
3249
3250 ImageRequirementsInfo(cl_mem_flags f, const cl_mem_properties* mem_properties, const ImageFormat* format, const cl_image_desc* desc)
3251 {
3252 flags = f;
3253 properties = mem_properties;
3254 image_format = format;
3255 image_desc = desc;
3256 }
3257
3258 cl_mem_flags flags = 0;
3259 const cl_mem_properties* properties;
3260 const ImageFormat* image_format;
3261 const cl_image_desc* image_desc;
3262 };
3263
3264 static cl_int getImageRequirementsInfoExtHelper(const Context &context,
3265 const ImageRequirementsInfo &info,
3266 cl_image_requirements_info_ext param_name,
3267 size_type param_value_size,
3268 void* param_value,
3269 size_type* param_value_size_ret)
3270 {
3271
3272#if CL_HPP_TARGET_OPENCL_VERSION >= 120
3273 Device device = context.getInfo<CL_CONTEXT_DEVICES>().at(0);
3274 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>()();
3275 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clGetImageRequirementsInfoEXT);
3276#else
3277 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetImageRequirementsInfoEXT);
3278#endif
3279
3280 if (pfn_clGetImageRequirementsInfoEXT == nullptr) {
3281 return detail::errHandler(CL_INVALID_OPERATION, __GET_IMAGE_REQUIREMENT_INFO_EXT_ERR);
3282 }
3283
3284 return detail::errHandler(
3285 pfn_clGetImageRequirementsInfoEXT(context(), info.properties,
3286 info.flags, info.image_format, info.image_desc, param_name,
3287 param_value_size, param_value, param_value_size_ret),
3288 __GET_IMAGE_REQUIREMENT_INFO_EXT_ERR);
3289 }
3290#endif // cl_ext_image_requirements_info
3291
3292public:
3293#ifdef CL_HPP_UNIT_TEST_ENABLE
3300 static void unitTestClearDefault() {
3301 default_ = Context();
3302 }
3303#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
3304
3309 Context(
3310 const vector<Device>& devices,
3311 const cl_context_properties* properties = nullptr,
3312 void (CL_CALLBACK * notifyFptr)(
3313 const char *,
3314 const void *,
3315 size_type,
3316 void *) = nullptr,
3317 void* data = nullptr,
3318 cl_int* err = nullptr)
3319 {
3320 cl_int error;
3321
3322 size_type numDevices = devices.size();
3323 vector<cl_device_id> deviceIDs(numDevices);
3324
3325 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
3326 deviceIDs[deviceIndex] = (devices[deviceIndex])();
3327 }
3328
3329 object_ = ::clCreateContext(
3330 properties, (cl_uint) numDevices,
3331 deviceIDs.data(),
3332 notifyFptr, data, &error);
3333
3334 detail::errHandler(error, __CREATE_CONTEXT_ERR);
3335 if (err != nullptr) {
3336 *err = error;
3337 }
3338 }
3339
3344 Context(
3345 const Device& device,
3346 const cl_context_properties* properties = nullptr,
3347 void (CL_CALLBACK * notifyFptr)(
3348 const char *,
3349 const void *,
3350 size_type,
3351 void *) = nullptr,
3352 void* data = nullptr,
3353 cl_int* err = nullptr)
3354 {
3355 cl_int error;
3356
3357 cl_device_id deviceID = device();
3358
3359 object_ = ::clCreateContext(
3360 properties, 1,
3361 &deviceID,
3362 notifyFptr, data, &error);
3363
3364 detail::errHandler(error, __CREATE_CONTEXT_ERR);
3365 if (err != nullptr) {
3366 *err = error;
3367 }
3368 }
3369
3374 Context(
3375 cl_device_type type,
3376 const cl_context_properties* properties = nullptr,
3377 void (CL_CALLBACK * notifyFptr)(
3378 const char *,
3379 const void *,
3380 size_type,
3381 void *) = nullptr,
3382 void* data = nullptr,
3383 cl_int* err = nullptr)
3384 {
3385 cl_int error;
3386
3387#if !defined(__APPLE__) && !defined(__MACOS)
3388 cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 };
3389
3390 if (properties == nullptr) {
3391 // Get a valid platform ID as we cannot send in a blank one
3392 vector<Platform> platforms;
3393 error = Platform::get(&platforms);
3394 if (error != CL_SUCCESS) {
3395 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
3396 if (err != nullptr) {
3397 *err = error;
3398 }
3399 return;
3400 }
3401
3402 // Check the platforms we found for a device of our specified type
3403 cl_context_properties platform_id = 0;
3404 for (unsigned int i = 0; i < platforms.size(); i++) {
3405
3406 vector<Device> devices;
3407
3408#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3409 try {
3410#endif
3411
3412 error = platforms[i].getDevices(type, &devices);
3413
3414#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3415 } catch (cl::Error& e) {
3416 error = e.err();
3417 }
3418 // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type
3419 // We do error checking next anyway, and can throw there if needed
3420#endif
3421
3422 // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND
3423 if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) {
3424 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
3425 if (err != nullptr) {
3426 *err = error;
3427 }
3428 }
3429
3430 if (devices.size() > 0) {
3431 platform_id = (cl_context_properties)platforms[i]();
3432 break;
3433 }
3434 }
3435
3436 if (platform_id == 0) {
3437 detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR);
3438 if (err != nullptr) {
3439 *err = CL_DEVICE_NOT_FOUND;
3440 }
3441 return;
3442 }
3443
3444 prop[1] = platform_id;
3445 properties = &prop[0];
3446 }
3447#endif
3448 object_ = ::clCreateContextFromType(
3449 properties, type, notifyFptr, data, &error);
3450
3451 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
3452 if (err != nullptr) {
3453 *err = error;
3454 }
3455 }
3456
3457
3462 static Context getDefault(cl_int * err = nullptr)
3463 {
3464 std::call_once(default_initialized_, makeDefault);
3465 detail::errHandler(default_error_);
3466 if (err != nullptr) {
3467 *err = default_error_;
3468 }
3469 return default_;
3470 }
3471
3479 static Context setDefault(const Context &default_context)
3480 {
3481 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_context));
3482 detail::errHandler(default_error_);
3483 return default_;
3484 }
3485
3487 Context() : detail::Wrapper<cl_type>() { }
3488
3494 explicit Context(const cl_context& context, bool retainObject = false) :
3495 detail::Wrapper<cl_type>(context, retainObject) { }
3496
3502 Context& operator = (const cl_context& rhs)
3503 {
3504 detail::Wrapper<cl_type>::operator=(rhs);
3505 return *this;
3506 }
3507
3509 template <typename T>
3510 cl_int getInfo(cl_context_info name, T* param) const
3511 {
3512 return detail::errHandler(
3513 detail::getInfo(&::clGetContextInfo, object_, name, param),
3514 __GET_CONTEXT_INFO_ERR);
3515 }
3516
3518 template <cl_context_info name> typename
3519 detail::param_traits<detail::cl_context_info, name>::param_type
3520 getInfo(cl_int* err = nullptr) const
3521 {
3522 typename detail::param_traits<
3523 detail::cl_context_info, name>::param_type param;
3524 cl_int result = getInfo(name, &param);
3525 if (err != nullptr) {
3526 *err = result;
3527 }
3528 return param;
3529 }
3530
3535 cl_int getSupportedImageFormats(
3536 cl_mem_flags flags,
3537 cl_mem_object_type type,
3538 vector<ImageFormat>* formats) const
3539 {
3540 cl_uint numEntries;
3541
3542 if (!formats) {
3543 return CL_SUCCESS;
3544 }
3545
3546 cl_int err = ::clGetSupportedImageFormats(
3547 object_,
3548 flags,
3549 type,
3550 0,
3551 nullptr,
3552 &numEntries);
3553 if (err != CL_SUCCESS) {
3554 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3555 }
3556
3557 if (numEntries > 0) {
3558 vector<ImageFormat> value(numEntries);
3559 err = ::clGetSupportedImageFormats(
3560 object_,
3561 flags,
3562 type,
3563 numEntries,
3564 (cl_image_format*)value.data(),
3565 nullptr);
3566 if (err != CL_SUCCESS) {
3567 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3568 }
3569
3570 formats->assign(value.begin(), value.end());
3571 }
3572 else {
3573 // If no values are being returned, ensure an empty vector comes back
3574 formats->clear();
3575 }
3576
3577 return CL_SUCCESS;
3578 }
3579
3580#if defined(cl_ext_image_requirements_info)
3581 template <typename T>
3582 cl_int getImageRequirementsInfoExt(cl_image_requirements_info_ext name,
3583 T* param,
3584 cl_mem_flags flags = 0,
3585 const cl_mem_properties* properties = nullptr,
3586 const ImageFormat* image_format = nullptr,
3587 const cl_image_desc* image_desc = nullptr) const
3588 {
3589 ImageRequirementsInfo imageInfo = {flags, properties, image_format, image_desc};
3590
3591 return detail::errHandler(
3592 detail::getInfo(
3593 Context::getImageRequirementsInfoExtHelper, *this, imageInfo, name, param),
3594 __GET_IMAGE_REQUIREMENT_INFO_EXT_ERR);
3595 }
3596
3597 template <cl_image_requirements_info_ext type> typename
3598 detail::param_traits<detail::cl_image_requirements_info_ext, type>::param_type
3599 getImageRequirementsInfoExt(cl_mem_flags flags = 0,
3600 const cl_mem_properties* properties = nullptr,
3601 const ImageFormat* image_format = nullptr,
3602 const cl_image_desc* image_desc = nullptr,
3603 cl_int* err = nullptr) const
3604 {
3605 typename detail::param_traits<
3606 detail::cl_image_requirements_info_ext, type>::param_type param;
3607 cl_int result = getImageRequirementsInfoExt(type, &param, flags, properties, image_format, image_desc);
3608 if (err != nullptr) {
3609 *err = result;
3610 }
3611 return param;
3612 }
3613#endif // cl_ext_image_requirements_info
3614
3615#if CL_HPP_TARGET_OPENCL_VERSION >= 300
3626 cl_int setDestructorCallback(
3627 void (CL_CALLBACK * pfn_notify)(cl_context, void *),
3628 void * user_data = nullptr)
3629 {
3630 return detail::errHandler(
3631 ::clSetContextDestructorCallback(
3632 object_,
3633 pfn_notify,
3634 user_data),
3635 __SET_CONTEXT_DESCTRUCTOR_CALLBACK_ERR);
3636 }
3637#endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
3638};
3639
3640inline void Device::makeDefault()
3641{
3642 /* Throwing an exception from a call_once invocation does not do
3643 * what we wish, so we catch it and save the error.
3644 */
3645#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3646 try
3647#endif
3648 {
3649 cl_int error = 0;
3650
3651 Context context = Context::getDefault(&error);
3652 detail::errHandler(error, __CREATE_CONTEXT_ERR);
3653
3654 if (error != CL_SUCCESS) {
3655 default_error_ = error;
3656 }
3657 else {
3658 default_ = context.getInfo<CL_CONTEXT_DEVICES>()[0];
3659 default_error_ = CL_SUCCESS;
3660 }
3661 }
3662#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3663 catch (cl::Error &e) {
3664 default_error_ = e.err();
3665 }
3666#endif
3667}
3668
3669CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Context::default_initialized_;
3670CL_HPP_DEFINE_STATIC_MEMBER_ Context Context::default_;
3671CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Context::default_error_ = CL_SUCCESS;
3672
3681 class Event : public detail::Wrapper<cl_event>
3682{
3683public:
3685 Event() : detail::Wrapper<cl_type>() { }
3686
3695 explicit Event(const cl_event& event, bool retainObject = false) :
3696 detail::Wrapper<cl_type>(event, retainObject) { }
3697
3703 Event& operator = (const cl_event& rhs)
3704 {
3705 detail::Wrapper<cl_type>::operator=(rhs);
3706 return *this;
3707 }
3708
3710 template <typename T>
3711 cl_int getInfo(cl_event_info name, T* param) const
3712 {
3713 return detail::errHandler(
3714 detail::getInfo(&::clGetEventInfo, object_, name, param),
3715 __GET_EVENT_INFO_ERR);
3716 }
3717
3719 template <cl_event_info name> typename
3720 detail::param_traits<detail::cl_event_info, name>::param_type
3721 getInfo(cl_int* err = nullptr) const
3722 {
3723 typename detail::param_traits<
3724 detail::cl_event_info, name>::param_type param;
3725 cl_int result = getInfo(name, &param);
3726 if (err != nullptr) {
3727 *err = result;
3728 }
3729 return param;
3730 }
3731
3733 template <typename T>
3734 cl_int getProfilingInfo(cl_profiling_info name, T* param) const
3735 {
3736 return detail::errHandler(detail::getInfo(
3737 &::clGetEventProfilingInfo, object_, name, param),
3738 __GET_EVENT_PROFILE_INFO_ERR);
3739 }
3740
3742 template <cl_profiling_info name> typename
3743 detail::param_traits<detail::cl_profiling_info, name>::param_type
3744 getProfilingInfo(cl_int* err = nullptr) const
3745 {
3746 typename detail::param_traits<
3747 detail::cl_profiling_info, name>::param_type param;
3748 cl_int result = getProfilingInfo(name, &param);
3749 if (err != nullptr) {
3750 *err = result;
3751 }
3752 return param;
3753 }
3754
3759 cl_int wait() const
3760 {
3761 return detail::errHandler(
3762 ::clWaitForEvents(1, &object_),
3763 __WAIT_FOR_EVENTS_ERR);
3764 }
3765
3766#if CL_HPP_TARGET_OPENCL_VERSION >= 110
3771 cl_int setCallback(
3772 cl_int type,
3773 void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
3774 void * user_data = nullptr)
3775 {
3776 return detail::errHandler(
3777 ::clSetEventCallback(
3778 object_,
3779 type,
3780 pfn_notify,
3781 user_data),
3782 __SET_EVENT_CALLBACK_ERR);
3783 }
3784#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3785
3790 static cl_int
3791 waitForEvents(const vector<Event>& events)
3792 {
3793 static_assert(sizeof(cl::Event) == sizeof(cl_event),
3794 "Size of cl::Event must be equal to size of cl_event");
3795
3796 return detail::errHandler(
3797 ::clWaitForEvents(
3798 (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : nullptr),
3799 __WAIT_FOR_EVENTS_ERR);
3800 }
3801};
3802
3803#if CL_HPP_TARGET_OPENCL_VERSION >= 110
3808class UserEvent : public Event
3809{
3810public:
3815 UserEvent(
3816 const Context& context,
3817 cl_int * err = nullptr)
3818 {
3819 cl_int error;
3820 object_ = ::clCreateUserEvent(
3821 context(),
3822 &error);
3823
3824 detail::errHandler(error, __CREATE_USER_EVENT_ERR);
3825 if (err != nullptr) {
3826 *err = error;
3827 }
3828 }
3829
3831 UserEvent() : Event() { }
3832
3837 cl_int setStatus(cl_int status)
3838 {
3839 return detail::errHandler(
3840 ::clSetUserEventStatus(object_,status),
3841 __SET_USER_EVENT_STATUS_ERR);
3842 }
3843};
3844#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3845
3850inline static cl_int
3851WaitForEvents(const vector<Event>& events)
3852{
3853 return detail::errHandler(
3854 ::clWaitForEvents(
3855 (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : nullptr),
3856 __WAIT_FOR_EVENTS_ERR);
3857}
3858
3867 class Memory : public detail::Wrapper<cl_mem>
3868{
3869public:
3871 Memory() : detail::Wrapper<cl_type>() { }
3872
3884 explicit Memory(const cl_mem& memory, bool retainObject) :
3885 detail::Wrapper<cl_type>(memory, retainObject) { }
3886
3892 Memory& operator = (const cl_mem& rhs)
3893 {
3894 detail::Wrapper<cl_type>::operator=(rhs);
3895 return *this;
3896 }
3897
3899 template <typename T>
3900 cl_int getInfo(cl_mem_info name, T* param) const
3901 {
3902 return detail::errHandler(
3903 detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
3904 __GET_MEM_OBJECT_INFO_ERR);
3905 }
3906
3908 template <cl_mem_info name> typename
3909 detail::param_traits<detail::cl_mem_info, name>::param_type
3910 getInfo(cl_int* err = nullptr) const
3911 {
3912 typename detail::param_traits<
3913 detail::cl_mem_info, name>::param_type param;
3914 cl_int result = getInfo(name, &param);
3915 if (err != nullptr) {
3916 *err = result;
3917 }
3918 return param;
3919 }
3920
3921#if CL_HPP_TARGET_OPENCL_VERSION >= 110
3935 cl_int setDestructorCallback(
3936 void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
3937 void * user_data = nullptr)
3938 {
3939 return detail::errHandler(
3940 ::clSetMemObjectDestructorCallback(
3941 object_,
3942 pfn_notify,
3943 user_data),
3944 __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
3945 }
3946#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3947
3948};
3949
3950// Pre-declare copy functions
3951class Buffer;
3952template< typename IteratorType >
3953cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3954template< typename IteratorType >
3955cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3956template< typename IteratorType >
3957cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3958template< typename IteratorType >
3959cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3960
3961
3962#if CL_HPP_TARGET_OPENCL_VERSION >= 200
3963namespace detail
3964{
3965 class SVMTraitNull
3966 {
3967 public:
3968 static cl_svm_mem_flags getSVMMemFlags()
3969 {
3970 return 0;
3971 }
3972 };
3973} // namespace detail
3974
3975template<class Trait = detail::SVMTraitNull>
3976class SVMTraitReadWrite
3977{
3978public:
3979 static cl_svm_mem_flags getSVMMemFlags()
3980 {
3981 return CL_MEM_READ_WRITE |
3982 Trait::getSVMMemFlags();
3983 }
3984};
3985
3986template<class Trait = detail::SVMTraitNull>
3987class SVMTraitReadOnly
3988{
3989public:
3990 static cl_svm_mem_flags getSVMMemFlags()
3991 {
3992 return CL_MEM_READ_ONLY |
3993 Trait::getSVMMemFlags();
3994 }
3995};
3996
3997template<class Trait = detail::SVMTraitNull>
3998class SVMTraitWriteOnly
3999{
4000public:
4001 static cl_svm_mem_flags getSVMMemFlags()
4002 {
4003 return CL_MEM_WRITE_ONLY |
4004 Trait::getSVMMemFlags();
4005 }
4006};
4007
4008template<class Trait = SVMTraitReadWrite<>>
4009class SVMTraitCoarse
4010{
4011public:
4012 static cl_svm_mem_flags getSVMMemFlags()
4013 {
4014 return Trait::getSVMMemFlags();
4015 }
4016};
4017
4018template<class Trait = SVMTraitReadWrite<>>
4019class SVMTraitFine
4020{
4021public:
4022 static cl_svm_mem_flags getSVMMemFlags()
4023 {
4024 return CL_MEM_SVM_FINE_GRAIN_BUFFER |
4025 Trait::getSVMMemFlags();
4026 }
4027};
4028
4029template<class Trait = SVMTraitReadWrite<>>
4030class SVMTraitAtomic
4031{
4032public:
4033 static cl_svm_mem_flags getSVMMemFlags()
4034 {
4035 return
4036 CL_MEM_SVM_FINE_GRAIN_BUFFER |
4037 CL_MEM_SVM_ATOMICS |
4038 Trait::getSVMMemFlags();
4039 }
4040};
4041
4042// Pre-declare SVM map function
4043template<typename T>
4044inline cl_int enqueueMapSVM(
4045 T* ptr,
4046 cl_bool blocking,
4047 cl_map_flags flags,
4048 size_type size,
4049 const vector<Event>* events = nullptr,
4050 Event* event = nullptr);
4051
4063template<typename T, class SVMTrait>
4064class SVMAllocator {
4065private:
4066 Context context_;
4067
4068public:
4069 typedef T value_type;
4070 typedef value_type* pointer;
4071 typedef const value_type* const_pointer;
4072 typedef value_type& reference;
4073 typedef const value_type& const_reference;
4074 typedef std::size_t size_type;
4075 typedef std::ptrdiff_t difference_type;
4076
4077 template<typename U>
4078 struct rebind
4079 {
4080 typedef SVMAllocator<U, SVMTrait> other;
4081 };
4082
4083 template<typename U, typename V>
4084 friend class SVMAllocator;
4085
4086 SVMAllocator() :
4087 context_(Context::getDefault())
4088 {
4089 }
4090
4091 explicit SVMAllocator(cl::Context context) :
4092 context_(context)
4093 {
4094 }
4095
4096
4097 SVMAllocator(const SVMAllocator &other) :
4098 context_(other.context_)
4099 {
4100 }
4101
4102 template<typename U>
4103 SVMAllocator(const SVMAllocator<U, SVMTrait> &other) :
4104 context_(other.context_)
4105 {
4106 }
4107
4108 ~SVMAllocator()
4109 {
4110 }
4111
4112 pointer address(reference r) noexcept
4113 {
4114 return std::addressof(r);
4115 }
4116
4117 const_pointer address(const_reference r) noexcept
4118 {
4119 return std::addressof(r);
4120 }
4121
4128 pointer allocate(
4129 size_type size,
4130 typename cl::SVMAllocator<void, SVMTrait>::const_pointer = 0,
4131 bool map = true)
4132 {
4133 // Allocate memory with default alignment matching the size of the type
4134 void* voidPointer =
4135 clSVMAlloc(
4136 context_(),
4137 SVMTrait::getSVMMemFlags(),
4138 size*sizeof(T),
4139 0);
4140 pointer retValue = reinterpret_cast<pointer>(
4141 voidPointer);
4142#if defined(CL_HPP_ENABLE_EXCEPTIONS)
4143 if (!retValue) {
4144 std::bad_alloc excep;
4145 throw excep;
4146 }
4147#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
4148
4149 // If allocation was coarse-grained then map it
4150 if (map && !(SVMTrait::getSVMMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) {
4151 cl_int err = enqueueMapSVM(retValue, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, size*sizeof(T));
4152 if (err != CL_SUCCESS) {
4153 clSVMFree(context_(), retValue);
4154 retValue = nullptr;
4155#if defined(CL_HPP_ENABLE_EXCEPTIONS)
4156 std::bad_alloc excep;
4157 throw excep;
4158#endif
4159 }
4160 }
4161
4162 // If exceptions disabled, return null pointer from allocator
4163 return retValue;
4164 }
4165
4166 void deallocate(pointer p, size_type)
4167 {
4168 clSVMFree(context_(), p);
4169 }
4170
4175 size_type max_size() const noexcept
4176 {
4177 size_type maxSize = std::numeric_limits<size_type>::max() / sizeof(T);
4178
4179 for (const Device &d : context_.getInfo<CL_CONTEXT_DEVICES>()) {
4180 maxSize = std::min(
4181 maxSize,
4182 static_cast<size_type>(d.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>()));
4183 }
4184
4185 return maxSize;
4186 }
4187
4188 template< class U, class... Args >
4189 void construct(U* p, Args&&... args)
4190 {
4191 new(p)T(args...);
4192 }
4193
4194 template< class U >
4195 void destroy(U* p)
4196 {
4197 p->~U();
4198 }
4199
4203 inline bool operator==(SVMAllocator const& rhs)
4204 {
4205 return (context_==rhs.context_);
4206 }
4207
4208 inline bool operator!=(SVMAllocator const& a)
4209 {
4210 return !operator==(a);
4211 }
4212}; // class SVMAllocator return cl::pointer<T>(tmp, detail::Deleter<T, Alloc>{alloc, copies});
4213
4214
4215template<class SVMTrait>
4216class SVMAllocator<void, SVMTrait> {
4217public:
4218 typedef void value_type;
4219 typedef value_type* pointer;
4220 typedef const value_type* const_pointer;
4221
4222 template<typename U>
4223 struct rebind
4224 {
4225 typedef SVMAllocator<U, SVMTrait> other;
4226 };
4227
4228 template<typename U, typename V>
4229 friend class SVMAllocator;
4230};
4231
4232#if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
4233namespace detail
4234{
4235 template<class Alloc>
4236 class Deleter {
4237 private:
4238 Alloc alloc_;
4239 size_type copies_;
4240
4241 public:
4242 typedef typename std::allocator_traits<Alloc>::pointer pointer;
4243
4244 Deleter(const Alloc &alloc, size_type copies) : alloc_{ alloc }, copies_{ copies }
4245 {
4246 }
4247
4248 void operator()(pointer ptr) const {
4249 Alloc tmpAlloc{ alloc_ };
4250 std::allocator_traits<Alloc>::destroy(tmpAlloc, std::addressof(*ptr));
4251 std::allocator_traits<Alloc>::deallocate(tmpAlloc, ptr, copies_);
4252 }
4253 };
4254} // namespace detail
4255
4262template <class T, class Alloc, class... Args>
4263cl::pointer<T, detail::Deleter<Alloc>> allocate_pointer(const Alloc &alloc_, Args&&... args)
4264{
4265 Alloc alloc(alloc_);
4266 static const size_type copies = 1;
4267
4268 // Ensure that creation of the management block and the
4269 // object are dealt with separately such that we only provide a deleter
4270
4271 T* tmp = std::allocator_traits<Alloc>::allocate(alloc, copies);
4272 if (!tmp) {
4273#if defined(CL_HPP_ENABLE_EXCEPTIONS)
4274 std::bad_alloc excep;
4275 throw excep;
4276#else
4277 return nullptr;
4278#endif
4279 }
4280
4281#if defined(CL_HPP_ENABLE_EXCEPTIONS)
4282 try
4283#endif
4284 {
4285 std::allocator_traits<Alloc>::construct(
4286 alloc,
4287 std::addressof(*tmp),
4288 std::forward<Args>(args)...);
4289
4290 return cl::pointer<T, detail::Deleter<Alloc>>(tmp, detail::Deleter<Alloc>{alloc, copies});
4291 }
4292#if defined(CL_HPP_ENABLE_EXCEPTIONS)
4293 catch (std::bad_alloc&)
4294 {
4295 std::allocator_traits<Alloc>::deallocate(alloc, tmp, copies);
4296 throw;
4297 }
4298#endif
4299}
4300
4301template< class T, class SVMTrait, class... Args >
4302cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(Args... args)
4303{
4304 SVMAllocator<T, SVMTrait> alloc;
4305 return cl::allocate_pointer<T>(alloc, args...);
4306}
4307
4308template< class T, class SVMTrait, class... Args >
4309cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(const cl::Context &c, Args... args)
4310{
4311 SVMAllocator<T, SVMTrait> alloc(c);
4312 return cl::allocate_pointer<T>(alloc, args...);
4313}
4314#endif // #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
4315
4319template < class T >
4320using coarse_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>>;
4321
4325template < class T >
4326using fine_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitFine<>>>;
4327
4331template < class T >
4332using atomic_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitAtomic<>>>;
4333
4334#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
4335
4336
4343class Buffer : public Memory
4344{
4345public:
4346
4354 Buffer(
4355 const Context& context,
4356 cl_mem_flags flags,
4357 size_type size,
4358 void* host_ptr = nullptr,
4359 cl_int* err = nullptr)
4360 {
4361 cl_int error;
4362 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
4363
4364 detail::errHandler(error, __CREATE_BUFFER_ERR);
4365 if (err != nullptr) {
4366 *err = error;
4367 }
4368 }
4369
4370#if CL_HPP_TARGET_OPENCL_VERSION >= 300
4381 Buffer(
4382 const Context& context,
4383 const vector<cl_mem_properties>& properties,
4384 cl_mem_flags flags,
4385 size_type size,
4386 void* host_ptr = nullptr,
4387 cl_int* err = nullptr)
4388 {
4389 cl_int error;
4390
4391 if (properties.empty()) {
4392 object_ = ::clCreateBufferWithProperties(context(), nullptr, flags,
4393 size, host_ptr, &error);
4394 }
4395 else {
4396 object_ = ::clCreateBufferWithProperties(
4397 context(), properties.data(), flags, size, host_ptr, &error);
4398 }
4399
4400 detail::errHandler(error, __CREATE_BUFFER_ERR);
4401 if (err != nullptr) {
4402 *err = error;
4403 }
4404 }
4405#endif
4406
4416 Buffer(
4417 cl_mem_flags flags,
4418 size_type size,
4419 void* host_ptr = nullptr,
4420 cl_int* err = nullptr) : Buffer(Context::getDefault(err), flags, size, host_ptr, err) { }
4421
4422#if CL_HPP_TARGET_OPENCL_VERSION >= 300
4435 Buffer(
4436 const vector<cl_mem_properties>& properties,
4437 cl_mem_flags flags,
4438 size_type size,
4439 void* host_ptr = nullptr,
4440 cl_int* err = nullptr) : Buffer(Context::getDefault(err), properties, flags, size, host_ptr, err) { }
4441#endif
4442
4448 template< typename IteratorType >
4449 Buffer(
4450 IteratorType startIterator,
4451 IteratorType endIterator,
4452 bool readOnly,
4453 bool useHostPtr = false,
4454 cl_int* err = nullptr)
4455 {
4456 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
4457 cl_int error;
4458
4459 cl_mem_flags flags = 0;
4460 if( readOnly ) {
4461 flags |= CL_MEM_READ_ONLY;
4462 }
4463 else {
4464 flags |= CL_MEM_READ_WRITE;
4465 }
4466 if( useHostPtr ) {
4467 flags |= CL_MEM_USE_HOST_PTR;
4468 }
4469
4470 size_type size = sizeof(DataType)*(endIterator - startIterator);
4471
4472 Context context = Context::getDefault(err);
4473
4474 if( useHostPtr ) {
4475 object_ = ::clCreateBuffer(context(), flags, size, const_cast<DataType*>(&*startIterator), &error);
4476 } else {
4477 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
4478 }
4479
4480 detail::errHandler(error, __CREATE_BUFFER_ERR);
4481 if (err != nullptr) {
4482 *err = error;
4483 }
4484
4485 if( !useHostPtr ) {
4486 error = cl::copy(startIterator, endIterator, *this);
4487 detail::errHandler(error, __CREATE_BUFFER_ERR);
4488 if (err != nullptr) {
4489 *err = error;
4490 }
4491 }
4492 }
4493
4499 template< typename IteratorType >
4500 Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator,
4501 bool readOnly, bool useHostPtr = false, cl_int* err = nullptr);
4502
4507 template< typename IteratorType >
4508 Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator,
4509 bool readOnly, bool useHostPtr = false, cl_int* err = nullptr);
4510
4512 Buffer() : Memory() { }
4513
4521 explicit Buffer(const cl_mem& buffer, bool retainObject = false) :
4522 Memory(buffer, retainObject) { }
4523
4528 Buffer& operator = (const cl_mem& rhs)
4529 {
4530 Memory::operator=(rhs);
4531 return *this;
4532 }
4533
4534
4535#if CL_HPP_TARGET_OPENCL_VERSION >= 110
4540 Buffer createSubBuffer(
4541 cl_mem_flags flags,
4542 cl_buffer_create_type buffer_create_type,
4543 const void * buffer_create_info,
4544 cl_int * err = nullptr)
4545 {
4546 Buffer result;
4547 cl_int error;
4548 result.object_ = ::clCreateSubBuffer(
4549 object_,
4550 flags,
4551 buffer_create_type,
4552 buffer_create_info,
4553 &error);
4554
4555 detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
4556 if (err != nullptr) {
4557 *err = error;
4558 }
4559
4560 return result;
4561 }
4562#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
4563};
4564
4565#if defined (CL_HPP_USE_DX_INTEROP)
4574class BufferD3D10 : public Buffer
4575{
4576public:
4577
4578
4584 BufferD3D10(
4585 const Context& context,
4586 cl_mem_flags flags,
4587 ID3D10Buffer* bufobj,
4588 cl_int * err = nullptr) : pfn_clCreateFromD3D10BufferKHR(nullptr)
4589 {
4590 typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
4591 cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
4592 cl_int* errcode_ret);
4593 PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR;
4594#if CL_HPP_TARGET_OPENCL_VERSION >= 120
4595 vector<cl_context_properties> props = context.getInfo<CL_CONTEXT_PROPERTIES>();
4596 cl_platform platform = nullptr;
4597 for( int i = 0; i < props.size(); ++i ) {
4598 if( props[i] == CL_CONTEXT_PLATFORM ) {
4599 platform = props[i+1];
4600 }
4601 }
4602 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateFromD3D10BufferKHR);
4603#endif
4604#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
4605 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateFromD3D10BufferKHR);
4606#endif
4607
4608 cl_int error;
4609 object_ = pfn_clCreateFromD3D10BufferKHR(
4610 context(),
4611 flags,
4612 bufobj,
4613 &error);
4614
4615 // TODO: This should really have a D3D10 rerror code!
4616 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4617 if (err != nullptr) {
4618 *err = error;
4619 }
4620 }
4621
4623 BufferD3D10() : Buffer() { }
4624
4632 explicit BufferD3D10(const cl_mem& buffer, bool retainObject = false) :
4633 Buffer(buffer, retainObject) { }
4634
4639 BufferD3D10& operator = (const cl_mem& rhs)
4640 {
4641 Buffer::operator=(rhs);
4642 return *this;
4643 }
4644};
4645#endif
4646
4655class BufferGL : public Buffer
4656{
4657public:
4663 BufferGL(
4664 const Context& context,
4665 cl_mem_flags flags,
4666 cl_GLuint bufobj,
4667 cl_int * err = nullptr)
4668 {
4669 cl_int error;
4670 object_ = ::clCreateFromGLBuffer(
4671 context(),
4672 flags,
4673 bufobj,
4674 &error);
4675
4676 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4677 if (err != nullptr) {
4678 *err = error;
4679 }
4680 }
4681
4683 BufferGL() : Buffer() { }
4684
4692 explicit BufferGL(const cl_mem& buffer, bool retainObject = false) :
4693 Buffer(buffer, retainObject) { }
4694
4699 BufferGL& operator = (const cl_mem& rhs)
4700 {
4701 Buffer::operator=(rhs);
4702 return *this;
4703 }
4704
4705
4707 cl_int getObjectInfo(
4708 cl_gl_object_type *type,
4709 cl_GLuint * gl_object_name)
4710 {
4711 return detail::errHandler(
4712 ::clGetGLObjectInfo(object_,type,gl_object_name),
4713 __GET_GL_OBJECT_INFO_ERR);
4714 }
4715};
4716
4725class BufferRenderGL : public Buffer
4726{
4727public:
4733 BufferRenderGL(
4734 const Context& context,
4735 cl_mem_flags flags,
4736 cl_GLuint bufobj,
4737 cl_int * err = nullptr)
4738 {
4739 cl_int error;
4740 object_ = ::clCreateFromGLRenderbuffer(
4741 context(),
4742 flags,
4743 bufobj,
4744 &error);
4745
4746 detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR);
4747 if (err != nullptr) {
4748 *err = error;
4749 }
4750 }
4751
4753 BufferRenderGL() : Buffer() { }
4754
4762 explicit BufferRenderGL(const cl_mem& buffer, bool retainObject = false) :
4763 Buffer(buffer, retainObject) { }
4764
4769 BufferRenderGL& operator = (const cl_mem& rhs)
4770 {
4771 Buffer::operator=(rhs);
4772 return *this;
4773 }
4774
4775
4777 cl_int getObjectInfo(
4778 cl_gl_object_type *type,
4779 cl_GLuint * gl_object_name)
4780 {
4781 return detail::errHandler(
4782 ::clGetGLObjectInfo(object_,type,gl_object_name),
4783 __GET_GL_OBJECT_INFO_ERR);
4784 }
4785};
4786
4793 class Image : public Memory
4794{
4795protected:
4797 Image() : Memory() { }
4798
4806 explicit Image(const cl_mem& image, bool retainObject = false) :
4807 Memory(image, retainObject) { }
4808
4813 Image& operator = (const cl_mem& rhs)
4814 {
4815 Memory::operator=(rhs);
4816 return *this;
4817 }
4818
4819
4820public:
4822 template <typename T>
4823 cl_int getImageInfo(cl_image_info name, T* param) const
4824 {
4825 return detail::errHandler(
4826 detail::getInfo(&::clGetImageInfo, object_, name, param),
4827 __GET_IMAGE_INFO_ERR);
4828 }
4829
4831 template <cl_image_info name> typename
4832 detail::param_traits<detail::cl_image_info, name>::param_type
4833 getImageInfo(cl_int* err = nullptr) const
4834 {
4835 typename detail::param_traits<
4836 detail::cl_image_info, name>::param_type param;
4837 cl_int result = getImageInfo(name, &param);
4838 if (err != nullptr) {
4839 *err = result;
4840 }
4841 return param;
4842 }
4843};
4844
4845#if CL_HPP_TARGET_OPENCL_VERSION >= 120
4852class Image1D : public Image
4853{
4854public:
4859 Image1D(
4860 const Context& context,
4861 cl_mem_flags flags,
4862 ImageFormat format,
4863 size_type width,
4864 void* host_ptr = nullptr,
4865 cl_int* err = nullptr)
4866 {
4867 cl_int error;
4868
4869 cl_image_desc desc = {};
4870 desc.image_type = CL_MEM_OBJECT_IMAGE1D;
4871 desc.image_width = width;
4872
4873 object_ = ::clCreateImage(
4874 context(),
4875 flags,
4876 &format,
4877 &desc,
4878 host_ptr,
4879 &error);
4880
4881 detail::errHandler(error, __CREATE_IMAGE_ERR);
4882 if (err != nullptr) {
4883 *err = error;
4884 }
4885 }
4886
4888 Image1D() { }
4889
4890#if CL_HPP_TARGET_OPENCL_VERSION >= 300
4901 Image1D(const Context &context, const vector<cl_mem_properties> &properties,
4902 cl_mem_flags flags, ImageFormat format, size_type width,
4903 void *host_ptr = nullptr, cl_int *err = nullptr) {
4904 cl_int error;
4905
4906 cl_image_desc desc = {};
4907 desc.image_type = CL_MEM_OBJECT_IMAGE1D;
4908 desc.image_width = width;
4909
4910 if (properties.empty()) {
4911 object_ = ::clCreateImageWithProperties(
4912 context(), nullptr, flags, &format, &desc, host_ptr, &error);
4913 } else {
4914 object_ =
4915 ::clCreateImageWithProperties(context(), properties.data(), flags,
4916 &format, &desc, host_ptr, &error);
4917 }
4918
4919 detail::errHandler(error, __CREATE_IMAGE_ERR);
4920 if (err != nullptr) {
4921 *err = error;
4922 }
4923 }
4924#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 300
4925
4933 explicit Image1D(const cl_mem& image1D, bool retainObject = false) :
4934 Image(image1D, retainObject) { }
4935
4940 Image1D& operator = (const cl_mem& rhs)
4941 {
4942 Image::operator=(rhs);
4943 return *this;
4944 }
4945
4946
4947};
4948
4952class Image1DBuffer : public Image
4953{
4954public:
4955 Image1DBuffer(
4956 const Context& context,
4957 cl_mem_flags flags,
4958 ImageFormat format,
4959 size_type width,
4960 const Buffer &buffer,
4961 cl_int* err = nullptr)
4962 {
4963 cl_int error;
4964
4965 cl_image_desc desc = {};
4966 desc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER;
4967 desc.image_width = width;
4968 desc.buffer = buffer();
4969
4970 object_ = ::clCreateImage(
4971 context(),
4972 flags,
4973 &format,
4974 &desc,
4975 nullptr,
4976 &error);
4977
4978 detail::errHandler(error, __CREATE_IMAGE_ERR);
4979 if (err != nullptr) {
4980 *err = error;
4981 }
4982 }
4983
4984 Image1DBuffer() { }
4985
4986#if CL_HPP_TARGET_OPENCL_VERSION >= 300
4996 Image1DBuffer(const Context &context,
4997 const vector<cl_mem_properties> &properties,
4998 cl_mem_flags flags, ImageFormat format, size_type width,
4999 const Buffer &buffer, cl_int *err = nullptr) {
5000 cl_int error;
5001
5002 cl_image_desc desc = {};
5003 desc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER;
5004 desc.image_width = width;
5005 desc.buffer = buffer();
5006
5007 if (properties.empty()) {
5008 object_ = ::clCreateImageWithProperties(
5009 context(), nullptr, flags, &format, &desc, nullptr, &error);
5010 } else {
5011 object_ =
5012 ::clCreateImageWithProperties(context(), properties.data(), flags,
5013 &format, &desc, nullptr, &error);
5014 }
5015
5016 detail::errHandler(error, __CREATE_IMAGE_ERR);
5017 if (err != nullptr) {
5018 *err = error;
5019 }
5020 }
5021#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 300
5022
5030 explicit Image1DBuffer(const cl_mem& image1D, bool retainObject = false) :
5031 Image(image1D, retainObject) { }
5032
5033 Image1DBuffer& operator = (const cl_mem& rhs)
5034 {
5035 Image::operator=(rhs);
5036 return *this;
5037 }
5038};
5039
5043class Image1DArray : public Image
5044{
5045public:
5046 Image1DArray(
5047 const Context& context,
5048 cl_mem_flags flags,
5049 ImageFormat format,
5050 size_type arraySize,
5051 size_type width,
5052 size_type rowPitch,
5053 void* host_ptr = nullptr,
5054 cl_int* err = nullptr)
5055 {
5056 cl_int error;
5057
5058 cl_image_desc desc = {};
5059 desc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
5060 desc.image_width = width;
5061 desc.image_array_size = arraySize;
5062 desc.image_row_pitch = rowPitch;
5063
5064 object_ = ::clCreateImage(
5065 context(),
5066 flags,
5067 &format,
5068 &desc,
5069 host_ptr,
5070 &error);
5071
5072 detail::errHandler(error, __CREATE_IMAGE_ERR);
5073 if (err != nullptr) {
5074 *err = error;
5075 }
5076 }
5077
5078 Image1DArray() { }
5079
5080#if CL_HPP_TARGET_OPENCL_VERSION >= 300
5091 Image1DArray(const Context &context,
5092 const vector<cl_mem_properties> &properties,
5093 cl_mem_flags flags, ImageFormat format, size_type arraySize,
5094 size_type width, size_type rowPitch = 0,
5095 void *host_ptr = nullptr, cl_int *err = nullptr) {
5096 cl_int error;
5097
5098 cl_image_desc desc = {};
5099 desc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
5100 desc.image_width = width;
5101 desc.image_array_size = arraySize;
5102 desc.image_row_pitch = rowPitch;
5103
5104 if (properties.empty()) {
5105 object_ = ::clCreateImageWithProperties(
5106 context(), nullptr, flags, &format, &desc, host_ptr, &error);
5107 } else {
5108 object_ =
5109 ::clCreateImageWithProperties(context(), properties.data(), flags,
5110 &format, &desc, host_ptr, &error);
5111 }
5112
5113 detail::errHandler(error, __CREATE_IMAGE_ERR);
5114 if (err != nullptr) {
5115 *err = error;
5116 }
5117 }
5118#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 300
5119
5127 explicit Image1DArray(const cl_mem& imageArray, bool retainObject = false) :
5128 Image(imageArray, retainObject) { }
5129
5130
5131 Image1DArray& operator = (const cl_mem& rhs)
5132 {
5133 Image::operator=(rhs);
5134 return *this;
5135 }
5136
5137
5138};
5139#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5140
5141
5148class Image2D : public Image
5149{
5150public:
5155 Image2D(
5156 const Context& context,
5157 cl_mem_flags flags,
5158 ImageFormat format,
5159 size_type width,
5160 size_type height,
5161 size_type row_pitch = 0,
5162 void* host_ptr = nullptr,
5163 cl_int* err = nullptr)
5164 {
5165 cl_int error;
5166 bool useCreateImage;
5167
5168#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
5169 // Run-time decision based on the actual platform
5170 {
5171 cl_uint version = detail::getContextPlatformVersion(context());
5172 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
5173 }
5174#elif CL_HPP_TARGET_OPENCL_VERSION >= 120
5175 useCreateImage = true;
5176#else
5177 useCreateImage = false;
5178#endif
5179
5180#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5181 if (useCreateImage)
5182 {
5183 cl_image_desc desc = {};
5184 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
5185 desc.image_width = width;
5186 desc.image_height = height;
5187 desc.image_row_pitch = row_pitch;
5188
5189 object_ = ::clCreateImage(
5190 context(),
5191 flags,
5192 &format,
5193 &desc,
5194 host_ptr,
5195 &error);
5196
5197 detail::errHandler(error, __CREATE_IMAGE_ERR);
5198 if (err != nullptr) {
5199 *err = error;
5200 }
5201 }
5202#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5203#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
5204 if (!useCreateImage)
5205 {
5206 object_ = ::clCreateImage2D(
5207 context(), flags,&format, width, height, row_pitch, host_ptr, &error);
5208
5209 detail::errHandler(error, __CREATE_IMAGE2D_ERR);
5210 if (err != nullptr) {
5211 *err = error;
5212 }
5213 }
5214#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
5215 }
5216
5217#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5226 Image2D(
5227 const Context& context,
5228 ImageFormat format,
5229 const Buffer &sourceBuffer,
5230 size_type width,
5231 size_type height,
5232 size_type row_pitch = 0,
5233 cl_int* err = nullptr)
5234 {
5235 cl_int error;
5236
5237 cl_image_desc desc = {};
5238 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
5239 desc.image_width = width;
5240 desc.image_height = height;
5241 desc.image_row_pitch = row_pitch;
5242 desc.buffer = sourceBuffer();
5243
5244 object_ = ::clCreateImage(
5245 context(),
5246 0, // flags inherited from buffer
5247 &format,
5248 &desc,
5249 nullptr,
5250 &error);
5251
5252 detail::errHandler(error, __CREATE_IMAGE_ERR);
5253 if (err != nullptr) {
5254 *err = error;
5255 }
5256 }
5257#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5258
5259#if CL_HPP_TARGET_OPENCL_VERSION >= 200
5272 Image2D(
5273 const Context& context,
5274 cl_channel_order order,
5275 const Image &sourceImage,
5276 cl_int* err = nullptr)
5277 {
5278 cl_int error;
5279
5280 // Descriptor fields have to match source image
5281 size_type sourceWidth =
5282 sourceImage.getImageInfo<CL_IMAGE_WIDTH>();
5283 size_type sourceHeight =
5284 sourceImage.getImageInfo<CL_IMAGE_HEIGHT>();
5285 size_type sourceRowPitch =
5286 sourceImage.getImageInfo<CL_IMAGE_ROW_PITCH>();
5287 cl_uint sourceNumMIPLevels =
5288 sourceImage.getImageInfo<CL_IMAGE_NUM_MIP_LEVELS>();
5289 cl_uint sourceNumSamples =
5290 sourceImage.getImageInfo<CL_IMAGE_NUM_SAMPLES>();
5291 cl_image_format sourceFormat =
5292 sourceImage.getImageInfo<CL_IMAGE_FORMAT>();
5293
5294 // Update only the channel order.
5295 // Channel format inherited from source.
5296 sourceFormat.image_channel_order = order;
5297
5298 cl_image_desc desc = {};
5299 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
5300 desc.image_width = sourceWidth;
5301 desc.image_height = sourceHeight;
5302 desc.image_row_pitch = sourceRowPitch;
5303 desc.num_mip_levels = sourceNumMIPLevels;
5304 desc.num_samples = sourceNumSamples;
5305 desc.buffer = sourceImage();
5306
5307 object_ = ::clCreateImage(
5308 context(),
5309 0, // flags should be inherited from mem_object
5310 &sourceFormat,
5311 &desc,
5312 nullptr,
5313 &error);
5314
5315 detail::errHandler(error, __CREATE_IMAGE_ERR);
5316 if (err != nullptr) {
5317 *err = error;
5318 }
5319 }
5320#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200
5321
5322#if CL_HPP_TARGET_OPENCL_VERSION >= 300
5333 Image2D(const Context &context, const vector<cl_mem_properties> &properties,
5334 cl_mem_flags flags, ImageFormat format, size_type width,
5335 size_type height, size_type row_pitch = 0, void *host_ptr = nullptr,
5336 cl_int *err = nullptr) {
5337 cl_int error;
5338
5339 cl_image_desc desc = {};
5340 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
5341 desc.image_width = width;
5342 desc.image_height = height;
5343 desc.image_row_pitch = row_pitch;
5344
5345 if (properties.empty()) {
5346 object_ = ::clCreateImageWithProperties(
5347 context(), nullptr, flags, &format, &desc, host_ptr, &error);
5348 } else {
5349 object_ =
5350 ::clCreateImageWithProperties(context(), properties.data(), flags,
5351 &format, &desc, host_ptr, &error);
5352 }
5353
5354 detail::errHandler(error, __CREATE_IMAGE_ERR);
5355 if (err != nullptr) {
5356 *err = error;
5357 }
5358 }
5359
5369 Image2D(const Context &context, const vector<cl_mem_properties> &properties,
5370 cl_mem_flags flags, ImageFormat format, const Buffer &buffer,
5371 size_type width, size_type height, size_type row_pitch = 0,
5372 cl_int *err = nullptr) {
5373 cl_int error;
5374
5375 cl_image_desc desc = {};
5376 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
5377 desc.image_width = width;
5378 desc.image_height = height;
5379 desc.image_row_pitch = row_pitch;
5380 desc.buffer = buffer();
5381
5382 if (properties.empty()) {
5383 object_ = ::clCreateImageWithProperties(
5384 context(), nullptr, flags, &format, &desc, nullptr, &error);
5385 } else {
5386 object_ =
5387 ::clCreateImageWithProperties(context(), properties.data(), flags,
5388 &format, &desc, nullptr, &error);
5389 }
5390
5391 detail::errHandler(error, __CREATE_IMAGE_ERR);
5392 if (err != nullptr) {
5393 *err = error;
5394 }
5395 }
5396
5397#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 300
5398
5400 Image2D() { }
5401
5409 explicit Image2D(const cl_mem& image2D, bool retainObject = false) :
5410 Image(image2D, retainObject) { }
5411
5416 Image2D& operator = (const cl_mem& rhs)
5417 {
5418 Image::operator=(rhs);
5419 return *this;
5420 }
5421};
5422
5423
5424#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
5434class CL_API_PREFIX__VERSION_1_1_DEPRECATED Image2DGL : public Image2D
5435{
5436public:
5442 Image2DGL(
5443 const Context& context,
5444 cl_mem_flags flags,
5445 cl_GLenum target,
5446 cl_GLint miplevel,
5447 cl_GLuint texobj,
5448 cl_int * err = nullptr)
5449 {
5450 cl_int error;
5451 object_ = ::clCreateFromGLTexture2D(
5452 context(),
5453 flags,
5454 target,
5455 miplevel,
5456 texobj,
5457 &error);
5458
5459 detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR);
5460 if (err != nullptr) {
5461 *err = error;
5462 }
5463
5464 }
5465
5467 Image2DGL() : Image2D() { }
5468
5476 explicit Image2DGL(const cl_mem& image, bool retainObject = false) :
5477 Image2D(image, retainObject) { }
5478
5483 Image2DGL& operator = (const cl_mem& rhs)
5484 {
5485 Image2D::operator=(rhs);
5486 return *this;
5487 }
5488
5489
5490
5491} CL_API_SUFFIX__VERSION_1_1_DEPRECATED;
5492#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5493
5494#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5498class Image2DArray : public Image
5499{
5500public:
5501 Image2DArray(
5502 const Context& context,
5503 cl_mem_flags flags,
5504 ImageFormat format,
5505 size_type arraySize,
5506 size_type width,
5507 size_type height,
5508 size_type rowPitch,
5509 size_type slicePitch,
5510 void* host_ptr = nullptr,
5511 cl_int* err = nullptr)
5512 {
5513 cl_int error;
5514
5515 cl_image_desc desc = {};
5516 desc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
5517 desc.image_width = width;
5518 desc.image_height = height;
5519 desc.image_array_size = arraySize;
5520 desc.image_row_pitch = rowPitch;
5521 desc.image_slice_pitch = slicePitch;
5522
5523 object_ = ::clCreateImage(
5524 context(),
5525 flags,
5526 &format,
5527 &desc,
5528 host_ptr,
5529 &error);
5530
5531 detail::errHandler(error, __CREATE_IMAGE_ERR);
5532 if (err != nullptr) {
5533 *err = error;
5534 }
5535 }
5536
5537#if CL_HPP_TARGET_OPENCL_VERSION >= 300
5548 Image2DArray(const Context &context,
5549 const vector<cl_mem_properties> &properties,
5550 cl_mem_flags flags, ImageFormat format, size_type arraySize,
5551 size_type width, size_type height, size_type rowPitch = 0,
5552 size_type slicePitch = 0, void *host_ptr = nullptr,
5553 cl_int *err = nullptr) {
5554 cl_int error;
5555
5556 cl_image_desc desc = {};
5557 desc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
5558 desc.image_width = width;
5559 desc.image_height = height;
5560 desc.image_array_size = arraySize;
5561 desc.image_row_pitch = rowPitch;
5562 desc.image_slice_pitch = slicePitch;
5563
5564 if (properties.empty()) {
5565 object_ = ::clCreateImageWithProperties(
5566 context(), nullptr, flags, &format, &desc, host_ptr, &error);
5567 } else {
5568 object_ =
5569 ::clCreateImageWithProperties(context(), properties.data(), flags,
5570 &format, &desc, host_ptr, &error);
5571 }
5572
5573 detail::errHandler(error, __CREATE_IMAGE_ERR);
5574 if (err != nullptr) {
5575 *err = error;
5576 }
5577 }
5578#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 300
5579
5580 Image2DArray() { }
5581
5589 explicit Image2DArray(const cl_mem& imageArray, bool retainObject = false) : Image(imageArray, retainObject) { }
5590
5591 Image2DArray& operator = (const cl_mem& rhs)
5592 {
5593 Image::operator=(rhs);
5594 return *this;
5595 }
5596
5597};
5598#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5599
5606class Image3D : public Image
5607{
5608public:
5613 Image3D(
5614 const Context& context,
5615 cl_mem_flags flags,
5616 ImageFormat format,
5617 size_type width,
5618 size_type height,
5619 size_type depth,
5620 size_type row_pitch = 0,
5621 size_type slice_pitch = 0,
5622 void* host_ptr = nullptr,
5623 cl_int* err = nullptr)
5624 {
5625 cl_int error;
5626 bool useCreateImage;
5627
5628#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
5629 // Run-time decision based on the actual platform
5630 {
5631 cl_uint version = detail::getContextPlatformVersion(context());
5632 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
5633 }
5634#elif CL_HPP_TARGET_OPENCL_VERSION >= 120
5635 useCreateImage = true;
5636#else
5637 useCreateImage = false;
5638#endif
5639
5640#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5641 if (useCreateImage)
5642 {
5643 cl_image_desc desc = {};
5644 desc.image_type = CL_MEM_OBJECT_IMAGE3D;
5645 desc.image_width = width;
5646 desc.image_height = height;
5647 desc.image_depth = depth;
5648 desc.image_row_pitch = row_pitch;
5649 desc.image_slice_pitch = slice_pitch;
5650
5651 object_ = ::clCreateImage(
5652 context(),
5653 flags,
5654 &format,
5655 &desc,
5656 host_ptr,
5657 &error);
5658
5659 detail::errHandler(error, __CREATE_IMAGE_ERR);
5660 if (err != nullptr) {
5661 *err = error;
5662 }
5663 }
5664#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5665#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
5666 if (!useCreateImage)
5667 {
5668 object_ = ::clCreateImage3D(
5669 context(), flags, &format, width, height, depth, row_pitch,
5670 slice_pitch, host_ptr, &error);
5671
5672 detail::errHandler(error, __CREATE_IMAGE3D_ERR);
5673 if (err != nullptr) {
5674 *err = error;
5675 }
5676 }
5677#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
5678 }
5679
5680#if CL_HPP_TARGET_OPENCL_VERSION >= 300
5691 Image3D(const Context &context, const vector<cl_mem_properties> &properties,
5692 cl_mem_flags flags, ImageFormat format, size_type width,
5693 size_type height, size_type depth, size_type row_pitch = 0,
5694 size_type slice_pitch = 0, void *host_ptr = nullptr,
5695 cl_int *err = nullptr) {
5696 cl_int error;
5697
5698 cl_image_desc desc = {};
5699 desc.image_type = CL_MEM_OBJECT_IMAGE3D;
5700 desc.image_width = width;
5701 desc.image_height = height;
5702 desc.image_depth = depth;
5703 desc.image_row_pitch = row_pitch;
5704 desc.image_slice_pitch = slice_pitch;
5705
5706 if (properties.empty()) {
5707 object_ = ::clCreateImageWithProperties(
5708 context(), nullptr, flags, &format, &desc, host_ptr, &error);
5709 } else {
5710 object_ =
5711 ::clCreateImageWithProperties(context(), properties.data(), flags,
5712 &format, &desc, host_ptr, &error);
5713 }
5714
5715 detail::errHandler(error, __CREATE_IMAGE_ERR);
5716 if (err != nullptr) {
5717 *err = error;
5718 }
5719 }
5720#endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 300
5721
5723 Image3D() : Image() { }
5724
5732 explicit Image3D(const cl_mem& image3D, bool retainObject = false) :
5733 Image(image3D, retainObject) { }
5734
5739 Image3D& operator = (const cl_mem& rhs)
5740 {
5741 Image::operator=(rhs);
5742 return *this;
5743 }
5744
5745};
5746
5747#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
5756class Image3DGL : public Image3D
5757{
5758public:
5764 Image3DGL(
5765 const Context& context,
5766 cl_mem_flags flags,
5767 cl_GLenum target,
5768 cl_GLint miplevel,
5769 cl_GLuint texobj,
5770 cl_int * err = nullptr)
5771 {
5772 cl_int error;
5773 object_ = ::clCreateFromGLTexture3D(
5774 context(),
5775 flags,
5776 target,
5777 miplevel,
5778 texobj,
5779 &error);
5780
5781 detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR);
5782 if (err != nullptr) {
5783 *err = error;
5784 }
5785 }
5786
5788 Image3DGL() : Image3D() { }
5789
5797 explicit Image3DGL(const cl_mem& image, bool retainObject = false) :
5798 Image3D(image, retainObject) { }
5799
5804 Image3DGL& operator = (const cl_mem& rhs)
5805 {
5806 Image3D::operator=(rhs);
5807 return *this;
5808 }
5809
5810};
5811#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5812
5813#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5820class ImageGL : public Image
5821{
5822public:
5823 ImageGL(
5824 const Context& context,
5825 cl_mem_flags flags,
5826 cl_GLenum target,
5827 cl_GLint miplevel,
5828 cl_GLuint texobj,
5829 cl_int * err = nullptr)
5830 {
5831 cl_int error;
5832 object_ = ::clCreateFromGLTexture(
5833 context(),
5834 flags,
5835 target,
5836 miplevel,
5837 texobj,
5838 &error);
5839
5840 detail::errHandler(error, __CREATE_GL_TEXTURE_ERR);
5841 if (err != nullptr) {
5842 *err = error;
5843 }
5844 }
5845
5846 ImageGL() : Image() { }
5847
5855 explicit ImageGL(const cl_mem& image, bool retainObject = false) :
5856 Image(image, retainObject) { }
5857
5858 ImageGL& operator = (const cl_mem& rhs)
5859 {
5860 Image::operator=(rhs);
5861 return *this;
5862 }
5863
5864};
5865#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5866
5867
5868
5869#if CL_HPP_TARGET_OPENCL_VERSION >= 200
5876class Pipe : public Memory
5877{
5878public:
5879
5889 Pipe(
5890 const Context& context,
5891 cl_uint packet_size,
5892 cl_uint max_packets,
5893 cl_int* err = nullptr)
5894 {
5895 cl_int error;
5896
5897 cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5898 object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error);
5899
5900 detail::errHandler(error, __CREATE_PIPE_ERR);
5901 if (err != nullptr) {
5902 *err = error;
5903 }
5904 }
5905
5914 Pipe(
5915 cl_uint packet_size,
5916 cl_uint max_packets,
5917 cl_int* err = nullptr)
5918 {
5919 cl_int error;
5920
5921 Context context = Context::getDefault(err);
5922
5923 cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5924 object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error);
5925
5926 detail::errHandler(error, __CREATE_PIPE_ERR);
5927 if (err != nullptr) {
5928 *err = error;
5929 }
5930 }
5931
5933 Pipe() : Memory() { }
5934
5942 explicit Pipe(const cl_mem& pipe, bool retainObject = false) :
5943 Memory(pipe, retainObject) { }
5944
5949 Pipe& operator = (const cl_mem& rhs)
5950 {
5951 Memory::operator=(rhs);
5952 return *this;
5953 }
5954
5955
5956
5958 template <typename T>
5959 cl_int getInfo(cl_pipe_info name, T* param) const
5960 {
5961 return detail::errHandler(
5962 detail::getInfo(&::clGetPipeInfo, object_, name, param),
5963 __GET_PIPE_INFO_ERR);
5964 }
5965
5967 template <cl_pipe_info name> typename
5968 detail::param_traits<detail::cl_pipe_info, name>::param_type
5969 getInfo(cl_int* err = nullptr) const
5970 {
5971 typename detail::param_traits<
5972 detail::cl_pipe_info, name>::param_type param;
5973 cl_int result = getInfo(name, &param);
5974 if (err != nullptr) {
5975 *err = result;
5976 }
5977 return param;
5978 }
5979}; // class Pipe
5980#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
5981
5982
5991 class Sampler : public detail::Wrapper<cl_sampler>
5992{
5993public:
5995 Sampler() { }
5996
6001 Sampler(
6002 const Context& context,
6003 cl_bool normalized_coords,
6004 cl_addressing_mode addressing_mode,
6005 cl_filter_mode filter_mode,
6006 cl_int* err = nullptr)
6007 {
6008 cl_int error;
6009
6010#if CL_HPP_TARGET_OPENCL_VERSION >= 200
6011 cl_sampler_properties sampler_properties[] = {
6012 CL_SAMPLER_NORMALIZED_COORDS, normalized_coords,
6013 CL_SAMPLER_ADDRESSING_MODE, addressing_mode,
6014 CL_SAMPLER_FILTER_MODE, filter_mode,
6015 0 };
6016 object_ = ::clCreateSamplerWithProperties(
6017 context(),
6018 sampler_properties,
6019 &error);
6020
6021 detail::errHandler(error, __CREATE_SAMPLER_WITH_PROPERTIES_ERR);
6022 if (err != nullptr) {
6023 *err = error;
6024 }
6025#else
6026 object_ = ::clCreateSampler(
6027 context(),
6028 normalized_coords,
6029 addressing_mode,
6030 filter_mode,
6031 &error);
6032
6033 detail::errHandler(error, __CREATE_SAMPLER_ERR);
6034 if (err != nullptr) {
6035 *err = error;
6036 }
6037#endif
6038 }
6039
6048 explicit Sampler(const cl_sampler& sampler, bool retainObject = false) :
6049 detail::Wrapper<cl_type>(sampler, retainObject) { }
6050
6056 Sampler& operator = (const cl_sampler& rhs)
6057 {
6058 detail::Wrapper<cl_type>::operator=(rhs);
6059 return *this;
6060 }
6061
6062
6063
6065 template <typename T>
6066 cl_int getInfo(cl_sampler_info name, T* param) const
6067 {
6068 return detail::errHandler(
6069 detail::getInfo(&::clGetSamplerInfo, object_, name, param),
6070 __GET_SAMPLER_INFO_ERR);
6071 }
6072
6074 template <cl_sampler_info name> typename
6075 detail::param_traits<detail::cl_sampler_info, name>::param_type
6076 getInfo(cl_int* err = nullptr) const
6077 {
6078 typename detail::param_traits<
6079 detail::cl_sampler_info, name>::param_type param;
6080 cl_int result = getInfo(name, &param);
6081 if (err != nullptr) {
6082 *err = result;
6083 }
6084 return param;
6085 }
6086};
6087
6088class Program;
6089class CommandQueue;
6090 class DeviceCommandQueue;
6091class Kernel;
6092
6094class NDRange
6095{
6096private:
6097 size_type sizes_[3];
6098 cl_uint dimensions_;
6099
6100public:
6102 NDRange()
6103 : dimensions_(0)
6104 {
6105 sizes_[0] = 0;
6106 sizes_[1] = 0;
6107 sizes_[2] = 0;
6108 }
6109
6111 NDRange(size_type size0)
6112 : dimensions_(1)
6113 {
6114 sizes_[0] = size0;
6115 sizes_[1] = 1;
6116 sizes_[2] = 1;
6117 }
6118
6120 NDRange(size_type size0, size_type size1)
6121 : dimensions_(2)
6122 {
6123 sizes_[0] = size0;
6124 sizes_[1] = size1;
6125 sizes_[2] = 1;
6126 }
6127
6129 NDRange(size_type size0, size_type size1, size_type size2)
6130 : dimensions_(3)
6131 {
6132 sizes_[0] = size0;
6133 sizes_[1] = size1;
6134 sizes_[2] = size2;
6135 }
6136
6138 NDRange(array<size_type, 1> a) : NDRange(a[0]){}
6139
6141 NDRange(array<size_type, 2> a) : NDRange(a[0], a[1]){}
6142
6144 NDRange(array<size_type, 3> a) : NDRange(a[0], a[1], a[2]){}
6145
6150 operator const size_type*() const {
6151 return sizes_;
6152 }
6153
6155 size_type dimensions() const
6156 {
6157 return dimensions_;
6158 }
6159
6161 // runtime number of dimensions
6162 size_type size() const
6163 {
6164 return dimensions_*sizeof(size_type);
6165 }
6166
6167 size_type* get()
6168 {
6169 return sizes_;
6170 }
6171
6172 const size_type* get() const
6173 {
6174 return sizes_;
6175 }
6176};
6177
6179static const NDRange NullRange;
6180
6182struct LocalSpaceArg
6183{
6184 size_type size_;
6185};
6186
6187namespace detail {
6188
6189template <typename T, class Enable = void>
6190struct KernelArgumentHandler;
6191
6192// Enable for objects that are not subclasses of memory
6193// Pointers, constants etc
6194template <typename T>
6195struct KernelArgumentHandler<T, typename std::enable_if<!std::is_base_of<cl::Memory, T>::value>::type>
6196{
6197 static size_type size(const T&) { return sizeof(T); }
6198 static const T* ptr(const T& value) { return &value; }
6199};
6200
6201// Enable for subclasses of memory where we want to get a reference to the cl_mem out
6202// and pass that in for safety
6203template <typename T>
6204struct KernelArgumentHandler<T, typename std::enable_if<std::is_base_of<cl::Memory, T>::value>::type>
6205{
6206 static size_type size(const T&) { return sizeof(cl_mem); }
6207 static const cl_mem* ptr(const T& value) { return &(value()); }
6208};
6209
6210// Specialization for DeviceCommandQueue defined later
6211
6212template <>
6213struct KernelArgumentHandler<LocalSpaceArg, void>
6214{
6215 static size_type size(const LocalSpaceArg& value) { return value.size_; }
6216 static const void* ptr(const LocalSpaceArg&) { return nullptr; }
6217};
6218
6219}
6221
6225inline LocalSpaceArg
6226 Local(size_type size)
6227{
6228 LocalSpaceArg ret = { size };
6229 return ret;
6230}
6231
6240class Kernel : public detail::Wrapper<cl_kernel>
6241{
6242public:
6243 inline Kernel(const Program& program, const string& name, cl_int* err = nullptr);
6244 inline Kernel(const Program& program, const char* name, cl_int* err = nullptr);
6245
6247 Kernel() { }
6248
6257 explicit Kernel(const cl_kernel& kernel, bool retainObject = false) :
6258 detail::Wrapper<cl_type>(kernel, retainObject) { }
6259
6265 Kernel& operator = (const cl_kernel& rhs)
6266 {
6267 detail::Wrapper<cl_type>::operator=(rhs);
6268 return *this;
6269 }
6270
6271
6272
6273
6274 template <typename T>
6275 cl_int getInfo(cl_kernel_info name, T* param) const
6276 {
6277 return detail::errHandler(
6278 detail::getInfo(&::clGetKernelInfo, object_, name, param),
6279 __GET_KERNEL_INFO_ERR);
6280 }
6281
6282 template <cl_kernel_info name> typename
6283 detail::param_traits<detail::cl_kernel_info, name>::param_type
6284 getInfo(cl_int* err = nullptr) const
6285 {
6286 typename detail::param_traits<
6287 detail::cl_kernel_info, name>::param_type param;
6288 cl_int result = getInfo(name, &param);
6289 if (err != nullptr) {
6290 *err = result;
6291 }
6292 return param;
6293 }
6294
6295#if CL_HPP_TARGET_OPENCL_VERSION >= 120
6296 template <typename T>
6297 cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const
6298 {
6299 return detail::errHandler(
6300 detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param),
6301 __GET_KERNEL_ARG_INFO_ERR);
6302 }
6303
6304 template <cl_kernel_arg_info name> typename
6305 detail::param_traits<detail::cl_kernel_arg_info, name>::param_type
6306 getArgInfo(cl_uint argIndex, cl_int* err = nullptr) const
6307 {
6308 typename detail::param_traits<
6309 detail::cl_kernel_arg_info, name>::param_type param;
6310 cl_int result = getArgInfo(argIndex, name, &param);
6311 if (err != nullptr) {
6312 *err = result;
6313 }
6314 return param;
6315 }
6316#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6317
6318 template <typename T>
6319 cl_int getWorkGroupInfo(
6320 const Device& device, cl_kernel_work_group_info name, T* param) const
6321 {
6322 return detail::errHandler(
6323 detail::getInfo(
6324 &::clGetKernelWorkGroupInfo, object_, device(), name, param),
6325 __GET_KERNEL_WORK_GROUP_INFO_ERR);
6326 }
6327
6328 template <cl_kernel_work_group_info name> typename
6329 detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
6330 getWorkGroupInfo(const Device& device, cl_int* err = nullptr) const
6331 {
6332 typename detail::param_traits<
6333 detail::cl_kernel_work_group_info, name>::param_type param;
6334 cl_int result = getWorkGroupInfo(device, name, &param);
6335 if (err != nullptr) {
6336 *err = result;
6337 }
6338 return param;
6339 }
6340
6341#if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) || CL_HPP_TARGET_OPENCL_VERSION >= 210
6342 cl_int getSubGroupInfo(const cl::Device &dev, cl_kernel_sub_group_info name, const cl::NDRange &range, size_type* param) const
6343 {
6344#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6345
6346 return detail::errHandler(
6347 clGetKernelSubGroupInfo(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
6348 __GET_KERNEL_SUB_GROUP_INFO_ERR);
6349
6350#else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6351
6352 typedef clGetKernelSubGroupInfoKHR_fn PFN_clGetKernelSubGroupInfoKHR;
6353 static PFN_clGetKernelSubGroupInfoKHR pfn_clGetKernelSubGroupInfoKHR = nullptr;
6354 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetKernelSubGroupInfoKHR);
6355
6356 return detail::errHandler(
6357 pfn_clGetKernelSubGroupInfoKHR(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
6358 __GET_KERNEL_SUB_GROUP_INFO_ERR);
6359
6360#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6361 }
6362
6363 template <cl_kernel_sub_group_info name>
6364 size_type getSubGroupInfo(const cl::Device &dev, const cl::NDRange &range, cl_int* err = nullptr) const
6365 {
6366 size_type param;
6367 cl_int result = getSubGroupInfo(dev, name, range, &param);
6368 if (err != nullptr) {
6369 *err = result;
6370 }
6371 return param;
6372 }
6373#endif // defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) || CL_HPP_TARGET_OPENCL_VERSION >= 210
6374
6375#if CL_HPP_TARGET_OPENCL_VERSION >= 200
6378 template<typename T, class D>
6379 cl_int setArg(cl_uint index, const cl::pointer<T, D> &argPtr)
6380 {
6381 return detail::errHandler(
6382 ::clSetKernelArgSVMPointer(object_, index, argPtr.get()),
6383 __SET_KERNEL_ARGS_ERR);
6384 }
6385
6388 template<typename T, class Alloc>
6389 cl_int setArg(cl_uint index, const cl::vector<T, Alloc> &argPtr)
6390 {
6391 return detail::errHandler(
6392 ::clSetKernelArgSVMPointer(object_, index, argPtr.data()),
6393 __SET_KERNEL_ARGS_ERR);
6394 }
6395
6398 template<typename T>
6399 typename std::enable_if<std::is_pointer<T>::value, cl_int>::type
6400 setArg(cl_uint index, const T argPtr)
6401 {
6402 return detail::errHandler(
6403 ::clSetKernelArgSVMPointer(object_, index, argPtr),
6404 __SET_KERNEL_ARGS_ERR);
6405 }
6406#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6407
6410 template <typename T>
6411 typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6412 setArg(cl_uint index, const T &value)
6413 {
6414 return detail::errHandler(
6415 ::clSetKernelArg(
6416 object_,
6417 index,
6418 detail::KernelArgumentHandler<T>::size(value),
6419 detail::KernelArgumentHandler<T>::ptr(value)),
6420 __SET_KERNEL_ARGS_ERR);
6421 }
6422
6423 cl_int setArg(cl_uint index, size_type size, const void* argPtr)
6424 {
6425 return detail::errHandler(
6426 ::clSetKernelArg(object_, index, size, argPtr),
6427 __SET_KERNEL_ARGS_ERR);
6428 }
6429
6430#if CL_HPP_TARGET_OPENCL_VERSION >= 200
6435 cl_int setSVMPointers(const vector<void*> &pointerList)
6436 {
6437 return detail::errHandler(
6438 ::clSetKernelExecInfo(
6439 object_,
6440 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6441 sizeof(void*)*pointerList.size(),
6442 pointerList.data()));
6443 }
6444
6449 template<int ArrayLength>
6450 cl_int setSVMPointers(const std::array<void*, ArrayLength> &pointerList)
6451 {
6452 return detail::errHandler(
6453 ::clSetKernelExecInfo(
6454 object_,
6455 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6456 sizeof(void*)*pointerList.size(),
6457 pointerList.data()));
6458 }
6459
6471 cl_int enableFineGrainedSystemSVM(bool svmEnabled)
6472 {
6473 cl_bool svmEnabled_ = svmEnabled ? CL_TRUE : CL_FALSE;
6474 return detail::errHandler(
6475 ::clSetKernelExecInfo(
6476 object_,
6477 CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM,
6478 sizeof(cl_bool),
6479 &svmEnabled_
6480 )
6481 );
6482 }
6483
6484 template<int index, int ArrayLength, class D, typename T0, typename T1, typename... Ts>
6485 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0, const pointer<T1, D> &t1, Ts & ... ts)
6486 {
6487 pointerList[index] = static_cast<void*>(t0.get());
6488 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6489 }
6490
6491 template<int index, int ArrayLength, typename T0, typename T1, typename... Ts>
6492 typename std::enable_if<std::is_pointer<T0>::value, void>::type
6493 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0, T1 t1, Ts... ts)
6494 {
6495 pointerList[index] = static_cast<void*>(t0);
6496 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6497 }
6498
6499 template<int index, int ArrayLength, typename T0, class D>
6500 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0)
6501 {
6502 pointerList[index] = static_cast<void*>(t0.get());
6503 }
6504
6505
6506 template<int index, int ArrayLength, typename T0>
6507 typename std::enable_if<std::is_pointer<T0>::value, void>::type
6508 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0)
6509 {
6510 pointerList[index] = static_cast<void*>(t0);
6511 }
6512
6513 template<typename T0, typename... Ts>
6514 cl_int setSVMPointers(const T0 &t0, Ts & ... ts)
6515 {
6516 std::array<void*, 1 + sizeof...(Ts)> pointerList;
6517
6518 setSVMPointersHelper<0, 1 + sizeof...(Ts)>(pointerList, t0, ts...);
6519 return detail::errHandler(
6520 ::clSetKernelExecInfo(
6521 object_,
6522 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6523 sizeof(void*)*(1 + sizeof...(Ts)),
6524 pointerList.data()));
6525 }
6526
6527 template<typename T>
6528 cl_int setExecInfo(cl_kernel_exec_info param_name, const T& val)
6529 {
6530 return detail::errHandler(
6531 ::clSetKernelExecInfo(
6532 object_,
6533 param_name,
6534 sizeof(T),
6535 &val));
6536 }
6537
6538 template<cl_kernel_exec_info name>
6539 cl_int setExecInfo(typename detail::param_traits<detail::cl_kernel_exec_info, name>::param_type& val)
6540 {
6541 return setExecInfo(name, val);
6542 }
6543#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6544
6545#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6551 Kernel clone()
6552 {
6553 cl_int error;
6554 Kernel retValue(clCloneKernel(this->get(), &error));
6555
6556 detail::errHandler(error, __CLONE_KERNEL_ERR);
6557 return retValue;
6558 }
6559#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6560};
6561
6565class Program : public detail::Wrapper<cl_program>
6566{
6567public:
6568#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6569 typedef vector<vector<unsigned char>> Binaries;
6570 typedef vector<string> Sources;
6571#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6572 typedef vector<std::pair<const void*, size_type> > Binaries;
6573 typedef vector<std::pair<const char*, size_type> > Sources;
6574#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6575
6576 Program(
6577 const string& source,
6578 bool build = false,
6579 cl_int* err = nullptr)
6580 {
6581 cl_int error;
6582
6583 const char * strings = source.c_str();
6584 const size_type length = source.size();
6585
6586 Context context = Context::getDefault(err);
6587
6588 object_ = ::clCreateProgramWithSource(
6589 context(), (cl_uint)1, &strings, &length, &error);
6590
6591 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6592
6593 if (error == CL_SUCCESS && build) {
6594
6595 error = ::clBuildProgram(
6596 object_,
6597 0,
6598 nullptr,
6599#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6600 "-cl-std=CL2.0",
6601#else
6602 "",
6603#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6604 nullptr,
6605 nullptr);
6606
6607 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6608 }
6609
6610 if (err != nullptr) {
6611 *err = error;
6612 }
6613 }
6614
6615 Program(
6616 const Context& context,
6617 const string& source,
6618 bool build = false,
6619 cl_int* err = nullptr)
6620 {
6621 cl_int error;
6622
6623 const char * strings = source.c_str();
6624 const size_type length = source.size();
6625
6626 object_ = ::clCreateProgramWithSource(
6627 context(), (cl_uint)1, &strings, &length, &error);
6628
6629 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6630
6631 if (error == CL_SUCCESS && build) {
6632 error = ::clBuildProgram(
6633 object_,
6634 0,
6635 nullptr,
6636#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6637 "-cl-std=CL2.0",
6638#else
6639 "",
6640#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6641 nullptr,
6642 nullptr);
6643
6644 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6645 }
6646
6647 if (err != nullptr) {
6648 *err = error;
6649 }
6650 }
6651
6656 Program(
6657 const Sources& sources,
6658 cl_int* err = nullptr)
6659 {
6660 cl_int error;
6661 Context context = Context::getDefault(err);
6662
6663 const size_type n = (size_type)sources.size();
6664
6665 vector<size_type> lengths(n);
6666 vector<const char*> strings(n);
6667
6668 for (size_type i = 0; i < n; ++i) {
6669#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6670 strings[i] = sources[(int)i].data();
6671 lengths[i] = sources[(int)i].length();
6672#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6673 strings[i] = sources[(int)i].first;
6674 lengths[i] = sources[(int)i].second;
6675#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6676 }
6677
6678 object_ = ::clCreateProgramWithSource(
6679 context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6680
6681 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6682 if (err != nullptr) {
6683 *err = error;
6684 }
6685 }
6686
6691 Program(
6692 const Context& context,
6693 const Sources& sources,
6694 cl_int* err = nullptr)
6695 {
6696 cl_int error;
6697
6698 const size_type n = (size_type)sources.size();
6699
6700 vector<size_type> lengths(n);
6701 vector<const char*> strings(n);
6702
6703 for (size_type i = 0; i < n; ++i) {
6704#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6705 strings[i] = sources[(int)i].data();
6706 lengths[i] = sources[(int)i].length();
6707#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6708 strings[i] = sources[(int)i].first;
6709 lengths[i] = sources[(int)i].second;
6710#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6711 }
6712
6713 object_ = ::clCreateProgramWithSource(
6714 context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6715
6716 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6717 if (err != nullptr) {
6718 *err = error;
6719 }
6720 }
6721
6722#if defined(CL_HPP_USE_IL_KHR) || CL_HPP_TARGET_OPENCL_VERSION >= 210
6728 Program(
6729 const vector<char>& IL,
6730 bool build = false,
6731 cl_int* err = nullptr)
6732 {
6733 cl_int error;
6734
6735 Context context = Context::getDefault(err);
6736
6737#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6738
6739 object_ = ::clCreateProgramWithIL(
6740 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6741
6742#else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6743
6744 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6745 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = nullptr;
6746 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6747
6748 object_ = pfn_clCreateProgramWithILKHR(
6749 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6750
6751#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6752
6753 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6754
6755 if (error == CL_SUCCESS && build) {
6756
6757 error = ::clBuildProgram(
6758 object_,
6759 0,
6760 nullptr,
6761#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6762 "-cl-std=CL2.0",
6763#else
6764 "",
6765#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6766 nullptr,
6767 nullptr);
6768
6769 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6770 }
6771
6772 if (err != nullptr) {
6773 *err = error;
6774 }
6775 }
6776
6783 Program(
6784 const Context& context,
6785 const vector<char>& IL,
6786 bool build = false,
6787 cl_int* err = nullptr)
6788 {
6789 cl_int error;
6790
6791#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6792
6793 object_ = ::clCreateProgramWithIL(
6794 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6795
6796#else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6797
6798 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6799 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = nullptr;
6800 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6801
6802 object_ = pfn_clCreateProgramWithILKHR(
6803 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6804
6805#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6806
6807 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6808
6809 if (error == CL_SUCCESS && build) {
6810 error = ::clBuildProgram(
6811 object_,
6812 0,
6813 nullptr,
6814#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6815 "-cl-std=CL2.0",
6816#else
6817 "",
6818#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6819 nullptr,
6820 nullptr);
6821
6822 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6823 }
6824
6825 if (err != nullptr) {
6826 *err = error;
6827 }
6828 }
6829#endif // defined(CL_HPP_USE_IL_KHR) || CL_HPP_TARGET_OPENCL_VERSION >= 210
6830
6850 Program(
6851 const Context& context,
6852 const vector<Device>& devices,
6853 const Binaries& binaries,
6854 vector<cl_int>* binaryStatus = nullptr,
6855 cl_int* err = nullptr)
6856 {
6857 cl_int error;
6858
6859 const size_type numDevices = devices.size();
6860
6861 // Catch size mismatch early and return
6862 if(binaries.size() != numDevices) {
6863 error = CL_INVALID_VALUE;
6864 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6865 if (err != nullptr) {
6866 *err = error;
6867 }
6868 return;
6869 }
6870
6871 vector<size_type> lengths(numDevices);
6872 vector<const unsigned char*> images(numDevices);
6873#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6874 for (size_type i = 0; i < numDevices; ++i) {
6875 images[i] = binaries[i].data();
6876 lengths[i] = binaries[(int)i].size();
6877 }
6878#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6879 for (size_type i = 0; i < numDevices; ++i) {
6880 images[i] = (const unsigned char*)binaries[i].first;
6881 lengths[i] = binaries[(int)i].second;
6882 }
6883#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6884
6885 vector<cl_device_id> deviceIDs(numDevices);
6886 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6887 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6888 }
6889
6890 if(binaryStatus) {
6891 binaryStatus->resize(numDevices);
6892 }
6893
6894 object_ = ::clCreateProgramWithBinary(
6895 context(), (cl_uint) devices.size(),
6896 deviceIDs.data(),
6897 lengths.data(), images.data(), (binaryStatus != nullptr && numDevices > 0)
6898 ? &binaryStatus->front()
6899 : nullptr, &error);
6900
6901 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6902 if (err != nullptr) {
6903 *err = error;
6904 }
6905 }
6906
6907
6908#if CL_HPP_TARGET_OPENCL_VERSION >= 120
6913 Program(
6914 const Context& context,
6915 const vector<Device>& devices,
6916 const string& kernelNames,
6917 cl_int* err = nullptr)
6918 {
6919 cl_int error;
6920
6921
6922 size_type numDevices = devices.size();
6923 vector<cl_device_id> deviceIDs(numDevices);
6924 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6925 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6926 }
6927
6928 object_ = ::clCreateProgramWithBuiltInKernels(
6929 context(),
6930 (cl_uint) devices.size(),
6931 deviceIDs.data(),
6932 kernelNames.c_str(),
6933 &error);
6934
6935 detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR);
6936 if (err != nullptr) {
6937 *err = error;
6938 }
6939 }
6940#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6941
6942 Program() { }
6943
6944
6951 explicit Program(const cl_program& program, bool retainObject = false) :
6952 detail::Wrapper<cl_type>(program, retainObject) { }
6953
6954 Program& operator = (const cl_program& rhs)
6955 {
6956 detail::Wrapper<cl_type>::operator=(rhs);
6957 return *this;
6958 }
6959
6960 cl_int build(
6961 const vector<Device>& devices,
6962 const string& options,
6963 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
6964 void* data = nullptr) const
6965 {
6966 return build(devices, options.c_str(), notifyFptr, data);
6967 }
6968
6969 cl_int build(
6970 const vector<Device>& devices,
6971 const char* options = nullptr,
6972 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
6973 void* data = nullptr) const
6974 {
6975 size_type numDevices = devices.size();
6976 vector<cl_device_id> deviceIDs(numDevices);
6977
6978 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6979 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6980 }
6981
6982 cl_int buildError = ::clBuildProgram(
6983 object_,
6984 (cl_uint)
6985 devices.size(),
6986 deviceIDs.data(),
6987 options,
6988 notifyFptr,
6989 data);
6990
6991 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6992 }
6993
6994 cl_int build(
6995 const Device& device,
6996 const string& options,
6997 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
6998 void* data = nullptr) const
6999 {
7000 return build(device, options.c_str(), notifyFptr, data);
7001 }
7002
7003 cl_int build(
7004 const Device& device,
7005 const char* options = nullptr,
7006 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7007 void* data = nullptr) const
7008 {
7009 cl_device_id deviceID = device();
7010
7011 cl_int buildError = ::clBuildProgram(
7012 object_,
7013 1,
7014 &deviceID,
7015 options,
7016 notifyFptr,
7017 data);
7018
7019 BuildLogType buildLog(0);
7020 buildLog.push_back(std::make_pair(device, getBuildInfo<CL_PROGRAM_BUILD_LOG>(device)));
7021 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, buildLog);
7022 }
7023
7024 cl_int build(
7025 const string& options,
7026 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7027 void* data = nullptr) const
7028 {
7029 return build(options.c_str(), notifyFptr, data);
7030 }
7031
7032 cl_int build(
7033 const char* options = nullptr,
7034 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7035 void* data = nullptr) const
7036 {
7037 cl_int buildError = ::clBuildProgram(
7038 object_,
7039 0,
7040 nullptr,
7041 options,
7042 notifyFptr,
7043 data);
7044
7045 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
7046 }
7047
7048#if CL_HPP_TARGET_OPENCL_VERSION >= 120
7049 cl_int compile(
7050 const string& options,
7051 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7052 void* data = nullptr) const
7053 {
7054 return compile(options.c_str(), notifyFptr, data);
7055 }
7056
7057 cl_int compile(
7058 const char* options = nullptr,
7059 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7060 void* data = nullptr) const
7061 {
7062 cl_int error = ::clCompileProgram(
7063 object_,
7064 0,
7065 nullptr,
7066 options,
7067 0,
7068 nullptr,
7069 nullptr,
7070 notifyFptr,
7071 data);
7072 return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
7073 }
7074
7075 cl_int compile(
7076 const string& options,
7077 const vector<Program>& inputHeaders,
7078 const vector<string>& headerIncludeNames,
7079 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7080 void* data = nullptr) const
7081 {
7082 return compile(options.c_str(), inputHeaders, headerIncludeNames, notifyFptr, data);
7083 }
7084
7085 cl_int compile(
7086 const char* options,
7087 const vector<Program>& inputHeaders,
7088 const vector<string>& headerIncludeNames,
7089 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7090 void* data = nullptr) const
7091 {
7092 static_assert(sizeof(cl::Program) == sizeof(cl_program),
7093 "Size of cl::Program must be equal to size of cl_program");
7094 vector<const char*> headerIncludeNamesCStr;
7095 for(const string& name: headerIncludeNames) {
7096 headerIncludeNamesCStr.push_back(name.c_str());
7097 }
7098 cl_int error = ::clCompileProgram(
7099 object_,
7100 0,
7101 nullptr,
7102 options,
7103 static_cast<cl_uint>(inputHeaders.size()),
7104 reinterpret_cast<const cl_program*>(inputHeaders.data()),
7105 reinterpret_cast<const char**>(headerIncludeNamesCStr.data()),
7106 notifyFptr,
7107 data);
7108 return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
7109 }
7110
7111 cl_int compile(
7112 const string& options,
7113 const vector<Device>& deviceList,
7114 const vector<Program>& inputHeaders = vector<Program>(),
7115 const vector<string>& headerIncludeNames = vector<string>(),
7116 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7117 void* data = nullptr) const
7118 {
7119 return compile(options.c_str(), deviceList, inputHeaders, headerIncludeNames, notifyFptr, data);
7120 }
7121
7122 cl_int compile(
7123 const char* options,
7124 const vector<Device>& deviceList,
7125 const vector<Program>& inputHeaders = vector<Program>(),
7126 const vector<string>& headerIncludeNames = vector<string>(),
7127 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7128 void* data = nullptr) const
7129 {
7130 static_assert(sizeof(cl::Program) == sizeof(cl_program),
7131 "Size of cl::Program must be equal to size of cl_program");
7132 vector<const char*> headerIncludeNamesCStr;
7133 for(const string& name: headerIncludeNames) {
7134 headerIncludeNamesCStr.push_back(name.c_str());
7135 }
7136 vector<cl_device_id> deviceIDList;
7137 for(const Device& device: deviceList) {
7138 deviceIDList.push_back(device());
7139 }
7140 cl_int error = ::clCompileProgram(
7141 object_,
7142 static_cast<cl_uint>(deviceList.size()),
7143 reinterpret_cast<const cl_device_id*>(deviceIDList.data()),
7144 options,
7145 static_cast<cl_uint>(inputHeaders.size()),
7146 reinterpret_cast<const cl_program*>(inputHeaders.data()),
7147 reinterpret_cast<const char**>(headerIncludeNamesCStr.data()),
7148 notifyFptr,
7149 data);
7150 return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
7151 }
7152#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7153
7154 template <typename T>
7155 cl_int getInfo(cl_program_info name, T* param) const
7156 {
7157 return detail::errHandler(
7158 detail::getInfo(&::clGetProgramInfo, object_, name, param),
7159 __GET_PROGRAM_INFO_ERR);
7160 }
7161
7162 template <cl_program_info name> typename
7163 detail::param_traits<detail::cl_program_info, name>::param_type
7164 getInfo(cl_int* err = nullptr) const
7165 {
7166 typename detail::param_traits<
7167 detail::cl_program_info, name>::param_type param;
7168 cl_int result = getInfo(name, &param);
7169 if (err != nullptr) {
7170 *err = result;
7171 }
7172 return param;
7173 }
7174
7175 template <typename T>
7176 cl_int getBuildInfo(
7177 const Device& device, cl_program_build_info name, T* param) const
7178 {
7179 return detail::errHandler(
7180 detail::getInfo(
7181 &::clGetProgramBuildInfo, object_, device(), name, param),
7182 __GET_PROGRAM_BUILD_INFO_ERR);
7183 }
7184
7185 template <cl_program_build_info name> typename
7186 detail::param_traits<detail::cl_program_build_info, name>::param_type
7187 getBuildInfo(const Device& device, cl_int* err = nullptr) const
7188 {
7189 typename detail::param_traits<
7190 detail::cl_program_build_info, name>::param_type param;
7191 cl_int result = getBuildInfo(device, name, &param);
7192 if (err != nullptr) {
7193 *err = result;
7194 }
7195 return param;
7196 }
7197
7203 template <cl_program_build_info name>
7204 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
7205 getBuildInfo(cl_int *err = nullptr) const
7206 {
7207 cl_int result = CL_SUCCESS;
7208
7209 auto devs = getInfo<CL_PROGRAM_DEVICES>(&result);
7210 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
7211 devInfo;
7212
7213 // If there was an initial error from getInfo return the error
7214 if (result != CL_SUCCESS) {
7215 if (err != nullptr) {
7216 *err = result;
7217 }
7218 return devInfo;
7219 }
7220
7221 for (const cl::Device &d : devs) {
7222 typename detail::param_traits<
7223 detail::cl_program_build_info, name>::param_type param;
7224 result = getBuildInfo(d, name, &param);
7225 devInfo.push_back(
7226 std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>
7227 (d, param));
7228 if (result != CL_SUCCESS) {
7229 // On error, leave the loop and return the error code
7230 break;
7231 }
7232 }
7233 if (err != nullptr) {
7234 *err = result;
7235 }
7236 if (result != CL_SUCCESS) {
7237 devInfo.clear();
7238 }
7239 return devInfo;
7240 }
7241
7242 cl_int createKernels(vector<Kernel>* kernels)
7243 {
7244 cl_uint numKernels;
7245 cl_int err = ::clCreateKernelsInProgram(object_, 0, nullptr, &numKernels);
7246 if (err != CL_SUCCESS) {
7247 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
7248 }
7249
7250 vector<cl_kernel> value(numKernels);
7251
7252 err = ::clCreateKernelsInProgram(
7253 object_, numKernels, value.data(), nullptr);
7254 if (err != CL_SUCCESS) {
7255 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
7256 }
7257
7258 if (kernels) {
7259 kernels->resize(value.size());
7260
7261 // Assign to param, constructing with retain behaviour
7262 // to correctly capture each underlying CL object
7263 for (size_type i = 0; i < value.size(); i++) {
7264 // We do not need to retain because this kernel is being created
7265 // by the runtime
7266 (*kernels)[i] = Kernel(value[i], false);
7267 }
7268 }
7269 return CL_SUCCESS;
7270 }
7271
7272#if CL_HPP_TARGET_OPENCL_VERSION >= 220
7273#if defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
7284 CL_API_PREFIX__VERSION_2_2_DEPRECATED cl_int setReleaseCallback(
7285 void (CL_CALLBACK * pfn_notify)(cl_program program, void * user_data),
7286 void * user_data = nullptr) CL_API_SUFFIX__VERSION_2_2_DEPRECATED
7287 {
7288 return detail::errHandler(
7289 ::clSetProgramReleaseCallback(
7290 object_,
7291 pfn_notify,
7292 user_data),
7293 __SET_PROGRAM_RELEASE_CALLBACK_ERR);
7294 }
7295#endif // #if defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
7296
7301 template <typename T>
7302 typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
7303 setSpecializationConstant(cl_uint index, const T &value)
7304 {
7305 return detail::errHandler(
7306 ::clSetProgramSpecializationConstant(
7307 object_,
7308 index,
7309 sizeof(value),
7310 &value),
7311 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
7312 }
7313
7318 cl_int setSpecializationConstant(cl_uint index, size_type size, const void* value)
7319 {
7320 return detail::errHandler(
7321 ::clSetProgramSpecializationConstant(
7322 object_,
7323 index,
7324 size,
7325 value),
7326 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
7327 }
7328#endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
7329};
7330
7331#if CL_HPP_TARGET_OPENCL_VERSION >= 120
7332inline Program linkProgram(
7333 const Program& input1,
7334 const Program& input2,
7335 const char* options = nullptr,
7336 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7337 void* data = nullptr,
7338 cl_int* err = nullptr)
7339{
7340 cl_int error_local = CL_SUCCESS;
7341 cl_program programs[2] = { input1(), input2() };
7342
7343 Context ctx = input1.getInfo<CL_PROGRAM_CONTEXT>(&error_local);
7344 if(error_local!=CL_SUCCESS) {
7345 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
7346 }
7347
7348 cl_program prog = ::clLinkProgram(
7349 ctx(),
7350 0,
7351 nullptr,
7352 options,
7353 2,
7354 programs,
7355 notifyFptr,
7356 data,
7357 &error_local);
7358
7359 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
7360 if (err != nullptr) {
7361 *err = error_local;
7362 }
7363
7364 return Program(prog);
7365}
7366
7367inline Program linkProgram(
7368 const Program& input1,
7369 const Program& input2,
7370 const string& options,
7371 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7372 void* data = nullptr,
7373 cl_int* err = nullptr)
7374{
7375 return linkProgram(input1, input2, options.c_str(), notifyFptr, data, err);
7376}
7377
7378inline Program linkProgram(
7379 const vector<Program>& inputPrograms,
7380 const char* options = nullptr,
7381 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7382 void* data = nullptr,
7383 cl_int* err = nullptr)
7384{
7385 cl_int error_local = CL_SUCCESS;
7386 Context ctx;
7387
7388 static_assert(sizeof(cl::Program) == sizeof(cl_program),
7389 "Size of cl::Program must be equal to size of cl_program");
7390
7391 if(inputPrograms.size() > 0) {
7392 ctx = inputPrograms[0].getInfo<CL_PROGRAM_CONTEXT>(&error_local);
7393 if(error_local!=CL_SUCCESS) {
7394 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
7395 }
7396 }
7397
7398 cl_program prog = ::clLinkProgram(
7399 ctx(),
7400 0,
7401 nullptr,
7402 options,
7403 static_cast<cl_uint>(inputPrograms.size()),
7404 reinterpret_cast<const cl_program *>(inputPrograms.data()),
7405 notifyFptr,
7406 data,
7407 &error_local);
7408
7409 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
7410 if (err != nullptr) {
7411 *err = error_local;
7412 }
7413
7414 return Program(prog);
7415}
7416
7417inline Program linkProgram(
7418 const vector<Program>& inputPrograms,
7419 const string& options,
7420 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7421 void* data = nullptr,
7422 cl_int* err = nullptr)
7423{
7424 return linkProgram(inputPrograms, options.c_str(), notifyFptr, data, err);
7425}
7426#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7427
7428// Template specialization for CL_PROGRAM_BINARIES
7429template <>
7430inline cl_int cl::Program::getInfo(cl_program_info name, vector<vector<unsigned char>>* param) const
7431{
7432 if (name != CL_PROGRAM_BINARIES) {
7433 return CL_INVALID_VALUE;
7434 }
7435 if (param) {
7436 // Resize the parameter array appropriately for each allocation
7437 // and pass down to the helper
7438
7439 vector<size_type> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>();
7440 size_type numBinaries = sizes.size();
7441
7442 // Resize the parameter array and constituent arrays
7443 param->resize(numBinaries);
7444 for (size_type i = 0; i < numBinaries; ++i) {
7445 (*param)[i].resize(sizes[i]);
7446 }
7447
7448 return detail::errHandler(
7449 detail::getInfo(&::clGetProgramInfo, object_, name, param),
7450 __GET_PROGRAM_INFO_ERR);
7451 }
7452
7453 return CL_SUCCESS;
7454}
7455
7456template<>
7457inline vector<vector<unsigned char>> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err) const
7458{
7459 vector<vector<unsigned char>> binariesVectors;
7460
7461 cl_int result = getInfo(CL_PROGRAM_BINARIES, &binariesVectors);
7462 if (err != nullptr) {
7463 *err = result;
7464 }
7465 return binariesVectors;
7466}
7467
7468#if CL_HPP_TARGET_OPENCL_VERSION >= 220
7469// Template specialization for clSetProgramSpecializationConstant
7470template <>
7471inline cl_int cl::Program::setSpecializationConstant(cl_uint index, const bool &value)
7472{
7473 cl_uchar ucValue = value ? CL_UCHAR_MAX : 0;
7474 return detail::errHandler(
7475 ::clSetProgramSpecializationConstant(
7476 object_,
7477 index,
7478 sizeof(ucValue),
7479 &ucValue),
7480 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
7481}
7482#endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
7483
7484inline Kernel::Kernel(const Program& program, const string& name, cl_int* err)
7485{
7486 cl_int error;
7487
7488 object_ = ::clCreateKernel(program(), name.c_str(), &error);
7489 detail::errHandler(error, __CREATE_KERNEL_ERR);
7490
7491 if (err != nullptr) {
7492 *err = error;
7493 }
7494}
7495
7496inline Kernel::Kernel(const Program& program, const char* name, cl_int* err)
7497{
7498 cl_int error;
7499
7500 object_ = ::clCreateKernel(program(), name, &error);
7501 detail::errHandler(error, __CREATE_KERNEL_ERR);
7502
7503 if (err != nullptr) {
7504 *err = error;
7505 }
7506}
7507
7508#ifdef cl_khr_external_memory
7509enum class ExternalMemoryType : cl_external_memory_handle_type_khr
7510{
7511 None = 0,
7512#ifdef cl_khr_external_memory_opaque_fd
7513 OpaqueFd = CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR,
7514#endif // cl_khr_external_memory_opaque_fd
7515#ifdef cl_khr_external_memory_win32
7516 OpaqueWin32 = CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR,
7517 OpaqueWin32Kmt = CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR,
7518#endif // cl_khr_external_memory_win32
7519#ifdef cl_khr_external_memory_dma_buf
7520 DmaBuf = CL_EXTERNAL_MEMORY_HANDLE_DMA_BUF_KHR,
7521#endif // cl_khr_external_memory_dma_buf
7522};
7523#endif // cl_khr_external_memory
7524
7525enum class QueueProperties : cl_command_queue_properties
7526{
7527 None = 0,
7528 Profiling = CL_QUEUE_PROFILING_ENABLE,
7529 OutOfOrder = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,
7530};
7531
7532inline QueueProperties operator|(QueueProperties lhs, QueueProperties rhs)
7533{
7534 return static_cast<QueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
7535}
7536
7537inline QueueProperties operator&(QueueProperties lhs, QueueProperties rhs)
7538{
7539 return static_cast<QueueProperties>(static_cast<cl_command_queue_properties>(lhs) & static_cast<cl_command_queue_properties>(rhs));
7540}
7541
7545class CommandQueue : public detail::Wrapper<cl_command_queue>
7546{
7547private:
7548 static std::once_flag default_initialized_;
7549 static CommandQueue default_;
7550 static cl_int default_error_;
7551
7557 static void makeDefault()
7558 {
7559 /* We don't want to throw an error from this function, so we have to
7560 * catch and set the error flag.
7561 */
7562#if defined(CL_HPP_ENABLE_EXCEPTIONS)
7563 try
7564#endif
7565 {
7566 int error;
7567 Context context = Context::getDefault(&error);
7568
7569 if (error != CL_SUCCESS) {
7570 default_error_ = error;
7571 }
7572 else {
7573 Device device = Device::getDefault();
7574 default_ = CommandQueue(context, device, 0, &default_error_);
7575 }
7576 }
7577#if defined(CL_HPP_ENABLE_EXCEPTIONS)
7578 catch (cl::Error &e) {
7579 default_error_ = e.err();
7580 }
7581#endif
7582 }
7583
7589 static void makeDefaultProvided(const CommandQueue &c) {
7590 default_ = c;
7591 }
7592
7593#ifdef cl_khr_external_memory
7594 static std::once_flag ext_memory_initialized_;
7595
7596 static void initMemoryExtension(const cl::Device& device)
7597 {
7598 auto platform = device.getInfo<CL_DEVICE_PLATFORM>()();
7599
7600 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireExternalMemObjectsKHR);
7601 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseExternalMemObjectsKHR);
7602
7603 if ((pfn_clEnqueueAcquireExternalMemObjectsKHR == nullptr)
7604 && (pfn_clEnqueueReleaseExternalMemObjectsKHR == nullptr))
7605 {
7606 detail::errHandler(CL_INVALID_VALUE, __ENQUEUE_ACQUIRE_EXTERNAL_MEMORY_ERR);
7607 }
7608 }
7609#endif // cl_khr_external_memory
7610
7611public:
7612#ifdef CL_HPP_UNIT_TEST_ENABLE
7619 static void unitTestClearDefault() {
7620 default_ = CommandQueue();
7621 }
7622#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
7623
7624
7629 CommandQueue(
7630 cl_command_queue_properties properties,
7631 cl_int* err = nullptr)
7632 {
7633 cl_int error;
7634
7635 Context context = Context::getDefault(&error);
7636 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7637
7638 if (error != CL_SUCCESS) {
7639 if (err != nullptr) {
7640 *err = error;
7641 }
7642 }
7643 else {
7644 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7645 bool useWithProperties;
7646
7647#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7648 // Run-time decision based on the actual platform
7649 {
7650 cl_uint version = detail::getContextPlatformVersion(context());
7651 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7652 }
7653#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7654 useWithProperties = true;
7655#else
7656 useWithProperties = false;
7657#endif
7658
7659#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7660 if (useWithProperties) {
7661 cl_queue_properties queue_properties[] = {
7662 CL_QUEUE_PROPERTIES, properties, 0 };
7663 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7664 object_ = ::clCreateCommandQueueWithProperties(
7665 context(), device(), queue_properties, &error);
7666 }
7667 else {
7668 error = CL_INVALID_QUEUE_PROPERTIES;
7669 }
7670
7671 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7672 if (err != nullptr) {
7673 *err = error;
7674 }
7675 }
7676#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7677#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7678 if (!useWithProperties) {
7679 object_ = ::clCreateCommandQueue(
7680 context(), device(), properties, &error);
7681
7682 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7683 if (err != nullptr) {
7684 *err = error;
7685 }
7686 }
7687#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7688 }
7689 }
7690
7695 CommandQueue(
7696 QueueProperties properties,
7697 cl_int* err = nullptr)
7698 {
7699 cl_int error;
7700
7701 Context context = Context::getDefault(&error);
7702 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7703
7704 if (error != CL_SUCCESS) {
7705 if (err != nullptr) {
7706 *err = error;
7707 }
7708 }
7709 else {
7710 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7711 bool useWithProperties;
7712
7713#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7714 // Run-time decision based on the actual platform
7715 {
7716 cl_uint version = detail::getContextPlatformVersion(context());
7717 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7718 }
7719#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7720 useWithProperties = true;
7721#else
7722 useWithProperties = false;
7723#endif
7724
7725#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7726 if (useWithProperties) {
7727 cl_queue_properties queue_properties[] = {
7728 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7729
7730 object_ = ::clCreateCommandQueueWithProperties(
7731 context(), device(), queue_properties, &error);
7732
7733 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7734 if (err != nullptr) {
7735 *err = error;
7736 }
7737 }
7738#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7739#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7740 if (!useWithProperties) {
7741 object_ = ::clCreateCommandQueue(
7742 context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
7743
7744 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7745 if (err != nullptr) {
7746 *err = error;
7747 }
7748 }
7749#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7750
7751 }
7752 }
7753
7758 explicit CommandQueue(
7759 const Context& context,
7760 cl_command_queue_properties properties = 0,
7761 cl_int* err = nullptr)
7762 {
7763 cl_int error;
7764 bool useWithProperties;
7765 vector<cl::Device> devices;
7766 error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7767
7768 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7769
7770 if (error != CL_SUCCESS)
7771 {
7772 if (err != nullptr) {
7773 *err = error;
7774 }
7775 return;
7776 }
7777
7778#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7779 // Run-time decision based on the actual platform
7780 {
7781 cl_uint version = detail::getContextPlatformVersion(context());
7782 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7783 }
7784#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7785 useWithProperties = true;
7786#else
7787 useWithProperties = false;
7788#endif
7789
7790#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7791 if (useWithProperties) {
7792 cl_queue_properties queue_properties[] = {
7793 CL_QUEUE_PROPERTIES, properties, 0 };
7794 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7795 object_ = ::clCreateCommandQueueWithProperties(
7796 context(), devices[0](), queue_properties, &error);
7797 }
7798 else {
7799 error = CL_INVALID_QUEUE_PROPERTIES;
7800 }
7801
7802 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7803 if (err != nullptr) {
7804 *err = error;
7805 }
7806 }
7807#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7808#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7809 if (!useWithProperties) {
7810 object_ = ::clCreateCommandQueue(
7811 context(), devices[0](), properties, &error);
7812
7813 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7814 if (err != nullptr) {
7815 *err = error;
7816 }
7817 }
7818#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7819 }
7820
7825 explicit CommandQueue(
7826 const Context& context,
7827 QueueProperties properties,
7828 cl_int* err = nullptr)
7829 {
7830 cl_int error;
7831 bool useWithProperties;
7832 vector<cl::Device> devices;
7833 error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7834
7835 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7836
7837 if (error != CL_SUCCESS)
7838 {
7839 if (err != nullptr) {
7840 *err = error;
7841 }
7842 return;
7843 }
7844
7845#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7846 // Run-time decision based on the actual platform
7847 {
7848 cl_uint version = detail::getContextPlatformVersion(context());
7849 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7850 }
7851#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7852 useWithProperties = true;
7853#else
7854 useWithProperties = false;
7855#endif
7856
7857#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7858 if (useWithProperties) {
7859 cl_queue_properties queue_properties[] = {
7860 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7861 object_ = ::clCreateCommandQueueWithProperties(
7862 context(), devices[0](), queue_properties, &error);
7863
7864 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7865 if (err != nullptr) {
7866 *err = error;
7867 }
7868 }
7869#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7870#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7871 if (!useWithProperties) {
7872 object_ = ::clCreateCommandQueue(
7873 context(), devices[0](), static_cast<cl_command_queue_properties>(properties), &error);
7874
7875 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7876 if (err != nullptr) {
7877 *err = error;
7878 }
7879 }
7880#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7881 }
7882
7887 CommandQueue(
7888 const Context& context,
7889 const Device& device,
7890 cl_command_queue_properties properties = 0,
7891 cl_int* err = nullptr)
7892 {
7893 cl_int error;
7894 bool useWithProperties;
7895
7896#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7897 // Run-time decision based on the actual platform
7898 {
7899 cl_uint version = detail::getContextPlatformVersion(context());
7900 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7901 }
7902#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7903 useWithProperties = true;
7904#else
7905 useWithProperties = false;
7906#endif
7907
7908#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7909 if (useWithProperties) {
7910 cl_queue_properties queue_properties[] = {
7911 CL_QUEUE_PROPERTIES, properties, 0 };
7912 object_ = ::clCreateCommandQueueWithProperties(
7913 context(), device(), queue_properties, &error);
7914
7915 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7916 if (err != nullptr) {
7917 *err = error;
7918 }
7919 }
7920#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7921#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7922 if (!useWithProperties) {
7923 object_ = ::clCreateCommandQueue(
7924 context(), device(), properties, &error);
7925
7926 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7927 if (err != nullptr) {
7928 *err = error;
7929 }
7930 }
7931#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7932 }
7933
7938 CommandQueue(
7939 const Context& context,
7940 const Device& device,
7941 QueueProperties properties,
7942 cl_int* err = nullptr)
7943 {
7944 cl_int error;
7945 bool useWithProperties;
7946
7947#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7948 // Run-time decision based on the actual platform
7949 {
7950 cl_uint version = detail::getContextPlatformVersion(context());
7951 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7952 }
7953#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7954 useWithProperties = true;
7955#else
7956 useWithProperties = false;
7957#endif
7958
7959#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7960 if (useWithProperties) {
7961 cl_queue_properties queue_properties[] = {
7962 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7963 object_ = ::clCreateCommandQueueWithProperties(
7964 context(), device(), queue_properties, &error);
7965
7966 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7967 if (err != nullptr) {
7968 *err = error;
7969 }
7970 }
7971#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7972#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7973 if (!useWithProperties) {
7974 object_ = ::clCreateCommandQueue(
7975 context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
7976
7977 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7978 if (err != nullptr) {
7979 *err = error;
7980 }
7981 }
7982#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7983 }
7984
7985 static CommandQueue getDefault(cl_int * err = nullptr)
7986 {
7987 std::call_once(default_initialized_, makeDefault);
7988#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7989 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7990#else // CL_HPP_TARGET_OPENCL_VERSION >= 200
7991 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_ERR);
7992#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7993 if (err != nullptr) {
7994 *err = default_error_;
7995 }
7996 return default_;
7997 }
7998
8006 static CommandQueue setDefault(const CommandQueue &default_queue)
8007 {
8008 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_queue));
8009 detail::errHandler(default_error_);
8010 return default_;
8011 }
8012
8013 CommandQueue() { }
8014
8015
8022 explicit CommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
8023 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
8024
8025 CommandQueue& operator = (const cl_command_queue& rhs)
8026 {
8027 detail::Wrapper<cl_type>::operator=(rhs);
8028 return *this;
8029 }
8030
8031 template <typename T>
8032 cl_int getInfo(cl_command_queue_info name, T* param) const
8033 {
8034 return detail::errHandler(
8035 detail::getInfo(
8036 &::clGetCommandQueueInfo, object_, name, param),
8037 __GET_COMMAND_QUEUE_INFO_ERR);
8038 }
8039
8040 template <cl_command_queue_info name> typename
8041 detail::param_traits<detail::cl_command_queue_info, name>::param_type
8042 getInfo(cl_int* err = nullptr) const
8043 {
8044 typename detail::param_traits<
8045 detail::cl_command_queue_info, name>::param_type param;
8046 cl_int result = getInfo(name, &param);
8047 if (err != nullptr) {
8048 *err = result;
8049 }
8050 return param;
8051 }
8052
8053 cl_int enqueueReadBuffer(
8054 const Buffer& buffer,
8055 cl_bool blocking,
8056 size_type offset,
8057 size_type size,
8058 void* ptr,
8059 const vector<Event>* events = nullptr,
8060 Event* event = nullptr) const
8061 {
8062 cl_event tmp;
8063 cl_int err = detail::errHandler(
8064 ::clEnqueueReadBuffer(
8065 object_, buffer(), blocking, offset, size,
8066 ptr,
8067 (events != nullptr) ? (cl_uint) events->size() : 0,
8068 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8069 (event != nullptr) ? &tmp : nullptr),
8070 __ENQUEUE_READ_BUFFER_ERR);
8071
8072 if (event != nullptr && err == CL_SUCCESS)
8073 *event = tmp;
8074
8075 return err;
8076 }
8077
8078 cl_int enqueueWriteBuffer(
8079 const Buffer& buffer,
8080 cl_bool blocking,
8081 size_type offset,
8082 size_type size,
8083 const void* ptr,
8084 const vector<Event>* events = nullptr,
8085 Event* event = nullptr) const
8086 {
8087 cl_event tmp;
8088 cl_int err = detail::errHandler(
8089 ::clEnqueueWriteBuffer(
8090 object_, buffer(), blocking, offset, size,
8091 ptr,
8092 (events != nullptr) ? (cl_uint) events->size() : 0,
8093 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8094 (event != nullptr) ? &tmp : nullptr),
8095 __ENQUEUE_WRITE_BUFFER_ERR);
8096
8097 if (event != nullptr && err == CL_SUCCESS)
8098 *event = tmp;
8099
8100 return err;
8101 }
8102
8103 cl_int enqueueCopyBuffer(
8104 const Buffer& src,
8105 const Buffer& dst,
8106 size_type src_offset,
8107 size_type dst_offset,
8108 size_type size,
8109 const vector<Event>* events = nullptr,
8110 Event* event = nullptr) const
8111 {
8112 cl_event tmp;
8113 cl_int err = detail::errHandler(
8114 ::clEnqueueCopyBuffer(
8115 object_, src(), dst(), src_offset, dst_offset, size,
8116 (events != nullptr) ? (cl_uint) events->size() : 0,
8117 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8118 (event != nullptr) ? &tmp : nullptr),
8119 __ENQEUE_COPY_BUFFER_ERR);
8120
8121 if (event != nullptr && err == CL_SUCCESS)
8122 *event = tmp;
8123
8124 return err;
8125 }
8126#if CL_HPP_TARGET_OPENCL_VERSION >= 110
8127 cl_int enqueueReadBufferRect(
8128 const Buffer& buffer,
8129 cl_bool blocking,
8130 const array<size_type, 3>& buffer_offset,
8131 const array<size_type, 3>& host_offset,
8132 const array<size_type, 3>& region,
8133 size_type buffer_row_pitch,
8134 size_type buffer_slice_pitch,
8135 size_type host_row_pitch,
8136 size_type host_slice_pitch,
8137 void *ptr,
8138 const vector<Event>* events = nullptr,
8139 Event* event = nullptr) const
8140 {
8141 cl_event tmp;
8142 cl_int err = detail::errHandler(
8143 ::clEnqueueReadBufferRect(
8144 object_,
8145 buffer(),
8146 blocking,
8147 buffer_offset.data(),
8148 host_offset.data(),
8149 region.data(),
8150 buffer_row_pitch,
8151 buffer_slice_pitch,
8152 host_row_pitch,
8153 host_slice_pitch,
8154 ptr,
8155 (events != nullptr) ? (cl_uint) events->size() : 0,
8156 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8157 (event != nullptr) ? &tmp : nullptr),
8158 __ENQUEUE_READ_BUFFER_RECT_ERR);
8159
8160 if (event != nullptr && err == CL_SUCCESS)
8161 *event = tmp;
8162
8163 return err;
8164 }
8165
8166 cl_int enqueueReadBufferRect(
8167 const Buffer& buffer,
8168 cl_bool blocking,
8169 const array<size_type, 2>& buffer_offset,
8170 const array<size_type, 2>& host_offset,
8171 const array<size_type, 2>& region,
8172 size_type buffer_row_pitch,
8173 size_type buffer_slice_pitch,
8174 size_type host_row_pitch,
8175 size_type host_slice_pitch,
8176 void* ptr,
8177 const vector<Event>* events = nullptr,
8178 Event* event = nullptr) const
8179 {
8180 return enqueueReadBufferRect(
8181 buffer,
8182 blocking,
8183 { buffer_offset[0], buffer_offset[1], 0 },
8184 { host_offset[0], host_offset[1], 0 },
8185 { region[0], region[1], 1 },
8186 buffer_row_pitch,
8187 buffer_slice_pitch,
8188 host_row_pitch,
8189 host_slice_pitch,
8190 ptr,
8191 events,
8192 event);
8193 }
8194
8195 cl_int enqueueWriteBufferRect(
8196 const Buffer& buffer,
8197 cl_bool blocking,
8198 const array<size_type, 3>& buffer_offset,
8199 const array<size_type, 3>& host_offset,
8200 const array<size_type, 3>& region,
8201 size_type buffer_row_pitch,
8202 size_type buffer_slice_pitch,
8203 size_type host_row_pitch,
8204 size_type host_slice_pitch,
8205 const void *ptr,
8206 const vector<Event>* events = nullptr,
8207 Event* event = nullptr) const
8208 {
8209 cl_event tmp;
8210 cl_int err = detail::errHandler(
8211 ::clEnqueueWriteBufferRect(
8212 object_,
8213 buffer(),
8214 blocking,
8215 buffer_offset.data(),
8216 host_offset.data(),
8217 region.data(),
8218 buffer_row_pitch,
8219 buffer_slice_pitch,
8220 host_row_pitch,
8221 host_slice_pitch,
8222 ptr,
8223 (events != nullptr) ? (cl_uint) events->size() : 0,
8224 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8225 (event != nullptr) ? &tmp : nullptr),
8226 __ENQUEUE_WRITE_BUFFER_RECT_ERR);
8227
8228 if (event != nullptr && err == CL_SUCCESS)
8229 *event = tmp;
8230
8231 return err;
8232 }
8233
8234 cl_int enqueueWriteBufferRect(
8235 const Buffer& buffer,
8236 cl_bool blocking,
8237 const array<size_type, 2>& buffer_offset,
8238 const array<size_type, 2>& host_offset,
8239 const array<size_type, 2>& region,
8240 size_type buffer_row_pitch,
8241 size_type buffer_slice_pitch,
8242 size_type host_row_pitch,
8243 size_type host_slice_pitch,
8244 const void* ptr,
8245 const vector<Event>* events = nullptr,
8246 Event* event = nullptr) const
8247 {
8248 return enqueueWriteBufferRect(
8249 buffer,
8250 blocking,
8251 { buffer_offset[0], buffer_offset[1], 0 },
8252 { host_offset[0], host_offset[1], 0 },
8253 { region[0], region[1], 1 },
8254 buffer_row_pitch,
8255 buffer_slice_pitch,
8256 host_row_pitch,
8257 host_slice_pitch,
8258 ptr,
8259 events,
8260 event);
8261 }
8262
8263 cl_int enqueueCopyBufferRect(
8264 const Buffer& src,
8265 const Buffer& dst,
8266 const array<size_type, 3>& src_origin,
8267 const array<size_type, 3>& dst_origin,
8268 const array<size_type, 3>& region,
8269 size_type src_row_pitch,
8270 size_type src_slice_pitch,
8271 size_type dst_row_pitch,
8272 size_type dst_slice_pitch,
8273 const vector<Event>* events = nullptr,
8274 Event* event = nullptr) const
8275 {
8276 cl_event tmp;
8277 cl_int err = detail::errHandler(
8278 ::clEnqueueCopyBufferRect(
8279 object_,
8280 src(),
8281 dst(),
8282 src_origin.data(),
8283 dst_origin.data(),
8284 region.data(),
8285 src_row_pitch,
8286 src_slice_pitch,
8287 dst_row_pitch,
8288 dst_slice_pitch,
8289 (events != nullptr) ? (cl_uint) events->size() : 0,
8290 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8291 (event != nullptr) ? &tmp : nullptr),
8292 __ENQEUE_COPY_BUFFER_RECT_ERR);
8293
8294 if (event != nullptr && err == CL_SUCCESS)
8295 *event = tmp;
8296
8297 return err;
8298 }
8299
8300 cl_int enqueueCopyBufferRect(
8301 const Buffer& src,
8302 const Buffer& dst,
8303 const array<size_type, 2>& src_origin,
8304 const array<size_type, 2>& dst_origin,
8305 const array<size_type, 2>& region,
8306 size_type src_row_pitch,
8307 size_type src_slice_pitch,
8308 size_type dst_row_pitch,
8309 size_type dst_slice_pitch,
8310 const vector<Event>* events = nullptr,
8311 Event* event = nullptr) const
8312 {
8313 return enqueueCopyBufferRect(
8314 src,
8315 dst,
8316 { src_origin[0], src_origin[1], 0 },
8317 { dst_origin[0], dst_origin[1], 0 },
8318 { region[0], region[1], 1 },
8319 src_row_pitch,
8320 src_slice_pitch,
8321 dst_row_pitch,
8322 dst_slice_pitch,
8323 events,
8324 event);
8325 }
8326
8327#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
8328#if CL_HPP_TARGET_OPENCL_VERSION >= 120
8340 template<typename PatternType>
8341 cl_int enqueueFillBuffer(
8342 const Buffer& buffer,
8343 PatternType pattern,
8344 size_type offset,
8345 size_type size,
8346 const vector<Event>* events = nullptr,
8347 Event* event = nullptr) const
8348 {
8349 cl_event tmp;
8350 cl_int err = detail::errHandler(
8351 ::clEnqueueFillBuffer(
8352 object_,
8353 buffer(),
8354 static_cast<void*>(&pattern),
8355 sizeof(PatternType),
8356 offset,
8357 size,
8358 (events != nullptr) ? (cl_uint) events->size() : 0,
8359 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8360 (event != nullptr) ? &tmp : nullptr),
8361 __ENQUEUE_FILL_BUFFER_ERR);
8362
8363 if (event != nullptr && err == CL_SUCCESS)
8364 *event = tmp;
8365
8366 return err;
8367 }
8368#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8369
8370 cl_int enqueueReadImage(
8371 const Image& image,
8372 cl_bool blocking,
8373 const array<size_type, 3>& origin,
8374 const array<size_type, 3>& region,
8375 size_type row_pitch,
8376 size_type slice_pitch,
8377 void* ptr,
8378 const vector<Event>* events = nullptr,
8379 Event* event = nullptr) const
8380 {
8381 cl_event tmp;
8382 cl_int err = detail::errHandler(
8383 ::clEnqueueReadImage(
8384 object_,
8385 image(),
8386 blocking,
8387 origin.data(),
8388 region.data(),
8389 row_pitch,
8390 slice_pitch,
8391 ptr,
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 __ENQUEUE_READ_IMAGE_ERR);
8396
8397 if (event != nullptr && err == CL_SUCCESS)
8398 *event = tmp;
8399
8400 return err;
8401 }
8402
8403 cl_int enqueueReadImage(
8404 const Image& image,
8405 cl_bool blocking,
8406 const array<size_type, 2>& origin,
8407 const array<size_type, 2>& region,
8408 size_type row_pitch,
8409 size_type slice_pitch,
8410 void* ptr,
8411 const vector<Event>* events = nullptr,
8412 Event* event = nullptr) const
8413 {
8414 return enqueueReadImage(
8415 image,
8416 blocking,
8417 { origin[0], origin[1], 0 },
8418 { region[0], region[1], 1 },
8419 row_pitch,
8420 slice_pitch,
8421 ptr,
8422 events,
8423 event);
8424 }
8425
8426 cl_int enqueueWriteImage(
8427 const Image& image,
8428 cl_bool blocking,
8429 const array<size_type, 3>& origin,
8430 const array<size_type, 3>& region,
8431 size_type row_pitch,
8432 size_type slice_pitch,
8433 const void* ptr,
8434 const vector<Event>* events = nullptr,
8435 Event* event = nullptr) const
8436 {
8437 cl_event tmp;
8438 cl_int err = detail::errHandler(
8439 ::clEnqueueWriteImage(
8440 object_,
8441 image(),
8442 blocking,
8443 origin.data(),
8444 region.data(),
8445 row_pitch,
8446 slice_pitch,
8447 ptr,
8448 (events != nullptr) ? (cl_uint) events->size() : 0,
8449 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8450 (event != nullptr) ? &tmp : nullptr),
8451 __ENQUEUE_WRITE_IMAGE_ERR);
8452
8453 if (event != nullptr && err == CL_SUCCESS)
8454 *event = tmp;
8455
8456 return err;
8457 }
8458
8459 cl_int enqueueWriteImage(
8460 const Image& image,
8461 cl_bool blocking,
8462 const array<size_type, 2>& origin,
8463 const array<size_type, 2>& region,
8464 size_type row_pitch,
8465 size_type slice_pitch,
8466 const void* ptr,
8467 const vector<Event>* events = nullptr,
8468 Event* event = nullptr) const
8469 {
8470 return enqueueWriteImage(
8471 image,
8472 blocking,
8473 { origin[0], origin[1], 0 },
8474 { region[0], region[1], 1 },
8475 row_pitch,
8476 slice_pitch,
8477 ptr,
8478 events,
8479 event);
8480 }
8481
8482 cl_int enqueueCopyImage(
8483 const Image& src,
8484 const Image& dst,
8485 const array<size_type, 3>& src_origin,
8486 const array<size_type, 3>& dst_origin,
8487 const array<size_type, 3>& region,
8488 const vector<Event>* events = nullptr,
8489 Event* event = nullptr) const
8490 {
8491 cl_event tmp;
8492 cl_int err = detail::errHandler(
8493 ::clEnqueueCopyImage(
8494 object_,
8495 src(),
8496 dst(),
8497 src_origin.data(),
8498 dst_origin.data(),
8499 region.data(),
8500 (events != nullptr) ? (cl_uint) events->size() : 0,
8501 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8502 (event != nullptr) ? &tmp : nullptr),
8503 __ENQUEUE_COPY_IMAGE_ERR);
8504
8505 if (event != nullptr && err == CL_SUCCESS)
8506 *event = tmp;
8507
8508 return err;
8509 }
8510
8511 cl_int enqueueCopyImage(
8512 const Image& src,
8513 const Image& dst,
8514 const array<size_type, 2>& src_origin,
8515 const array<size_type, 2>& dst_origin,
8516 const array<size_type, 2>& region,
8517 const vector<Event>* events = nullptr,
8518 Event* event = nullptr) const
8519 {
8520 return enqueueCopyImage(
8521 src,
8522 dst,
8523 { src_origin[0], src_origin[1], 0 },
8524 { dst_origin[0], dst_origin[1], 0 },
8525 { region[0], region[1], 1 },
8526 events,
8527 event);
8528 }
8529
8530#if CL_HPP_TARGET_OPENCL_VERSION >= 120
8538 template <typename T>
8539 typename std::enable_if<std::is_same<T, cl_float4>::value ||
8540 std::is_same<T, cl_int4 >::value ||
8541 std::is_same<T, cl_uint4 >::value,
8542 cl_int>::type
8543 enqueueFillImage(
8544 const Image& image,
8545 T fillColor,
8546 const array<size_type, 3>& origin,
8547 const array<size_type, 3>& region,
8548 const vector<Event>* events = nullptr,
8549 Event* event = nullptr) const
8550 {
8551 cl_event tmp;
8552 cl_int err = detail::errHandler(
8553 ::clEnqueueFillImage(
8554 object_,
8555 image(),
8556 static_cast<void*>(&fillColor),
8557 origin.data(),
8558 region.data(),
8559 (events != nullptr) ? (cl_uint)events->size() : 0,
8560 (events != nullptr && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8561 (event != NULL) ? &tmp : nullptr),
8562 __ENQUEUE_FILL_IMAGE_ERR);
8563
8564 if (event != nullptr && err == CL_SUCCESS) *event = tmp;
8565
8566 return err;
8567 }
8568
8576 template <typename T>
8577 typename std::enable_if<std::is_same<T, cl_float4>::value ||
8578 std::is_same<T, cl_int4 >::value ||
8579 std::is_same<T, cl_uint4 >::value, cl_int>::type
8580 enqueueFillImage(
8581 const Image& image,
8582 T fillColor,
8583 const array<size_type, 2>& origin,
8584 const array<size_type, 2>& region,
8585 const vector<Event>* events = nullptr,
8586 Event* event = nullptr) const
8587 {
8588 return enqueueFillImage(
8589 image,
8590 fillColor,
8591 { origin[0], origin[1], 0 },
8592 { region[0], region[1], 1 },
8593 events,
8594 event
8595 );
8596 }
8597#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8598
8599 cl_int enqueueCopyImageToBuffer(
8600 const Image& src,
8601 const Buffer& dst,
8602 const array<size_type, 3>& src_origin,
8603 const array<size_type, 3>& region,
8604 size_type dst_offset,
8605 const vector<Event>* events = nullptr,
8606 Event* event = nullptr) const
8607 {
8608 cl_event tmp;
8609 cl_int err = detail::errHandler(
8610 ::clEnqueueCopyImageToBuffer(
8611 object_,
8612 src(),
8613 dst(),
8614 src_origin.data(),
8615 region.data(),
8616 dst_offset,
8617 (events != nullptr) ? (cl_uint) events->size() : 0,
8618 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8619 (event != nullptr) ? &tmp : nullptr),
8620 __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
8621
8622 if (event != nullptr && err == CL_SUCCESS)
8623 *event = tmp;
8624
8625 return err;
8626 }
8627
8628 cl_int enqueueCopyImageToBuffer(
8629 const Image& src,
8630 const Buffer& dst,
8631 const array<size_type, 2>& src_origin,
8632 const array<size_type, 2>& region,
8633 size_type dst_offset,
8634 const vector<Event>* events = nullptr,
8635 Event* event = nullptr) const
8636 {
8637 return enqueueCopyImageToBuffer(
8638 src,
8639 dst,
8640 { src_origin[0], src_origin[1], 0 },
8641 { region[0], region[1], 1 },
8642 dst_offset,
8643 events,
8644 event);
8645 }
8646
8647 cl_int enqueueCopyBufferToImage(
8648 const Buffer& src,
8649 const Image& dst,
8650 size_type src_offset,
8651 const array<size_type, 3>& dst_origin,
8652 const array<size_type, 3>& region,
8653 const vector<Event>* events = nullptr,
8654 Event* event = nullptr) const
8655 {
8656 cl_event tmp;
8657 cl_int err = detail::errHandler(
8658 ::clEnqueueCopyBufferToImage(
8659 object_,
8660 src(),
8661 dst(),
8662 src_offset,
8663 dst_origin.data(),
8664 region.data(),
8665 (events != nullptr) ? (cl_uint) events->size() : 0,
8666 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8667 (event != nullptr) ? &tmp : nullptr),
8668 __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
8669
8670 if (event != nullptr && err == CL_SUCCESS)
8671 *event = tmp;
8672
8673 return err;
8674 }
8675
8676 cl_int enqueueCopyBufferToImage(
8677 const Buffer& src,
8678 const Image& dst,
8679 size_type src_offset,
8680 const array<size_type, 2>& dst_origin,
8681 const array<size_type, 2>& region,
8682 const vector<Event>* events = nullptr,
8683 Event* event = nullptr) const
8684 {
8685 return enqueueCopyBufferToImage(
8686 src,
8687 dst,
8688 src_offset,
8689 { dst_origin[0], dst_origin[1], 0 },
8690 { region[0], region[1], 1 },
8691 events,
8692 event);
8693 }
8694
8695 void* enqueueMapBuffer(
8696 const Buffer& buffer,
8697 cl_bool blocking,
8698 cl_map_flags flags,
8699 size_type offset,
8700 size_type size,
8701 const vector<Event>* events = nullptr,
8702 Event* event = nullptr,
8703 cl_int* err = nullptr) const
8704 {
8705 cl_event tmp;
8706 cl_int error;
8707 void * result = ::clEnqueueMapBuffer(
8708 object_, buffer(), blocking, flags, offset, size,
8709 (events != nullptr) ? (cl_uint) events->size() : 0,
8710 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8711 (event != nullptr) ? &tmp : nullptr,
8712 &error);
8713
8714 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
8715 if (err != nullptr) {
8716 *err = error;
8717 }
8718 if (event != nullptr && error == CL_SUCCESS)
8719 *event = tmp;
8720
8721 return result;
8722 }
8723
8724 void* enqueueMapImage(
8725 const Image& image,
8726 cl_bool blocking,
8727 cl_map_flags flags,
8728 const array<size_type, 3>& origin,
8729 const array<size_type, 3>& region,
8730 size_type * row_pitch,
8731 size_type * slice_pitch,
8732 const vector<Event>* events = nullptr,
8733 Event* event = nullptr,
8734 cl_int* err = nullptr) const
8735 {
8736 cl_event tmp;
8737 cl_int error;
8738 void * result = ::clEnqueueMapImage(
8739 object_, image(), blocking, flags,
8740 origin.data(),
8741 region.data(),
8742 row_pitch, slice_pitch,
8743 (events != nullptr) ? (cl_uint) events->size() : 0,
8744 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
8745 (event != nullptr) ? &tmp : nullptr,
8746 &error);
8747
8748 detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
8749 if (err != nullptr) {
8750 *err = error;
8751 }
8752 if (event != nullptr && error == CL_SUCCESS)
8753 *event = tmp;
8754 return result;
8755 }
8756
8757 void* enqueueMapImage(
8758 const Image& image,
8759 cl_bool blocking,
8760 cl_map_flags flags,
8761 const array<size_type, 2>& origin,
8762 const array<size_type, 2>& region,
8763 size_type* row_pitch,
8764 size_type* slice_pitch,
8765 const vector<Event>* events = nullptr,
8766 Event* event = nullptr,
8767 cl_int* err = nullptr) const
8768 {
8769 return enqueueMapImage(image, blocking, flags,
8770 { origin[0], origin[1], 0 },
8771 { region[0], region[1], 1 }, row_pitch,
8772 slice_pitch, events, event, err);
8773 }
8774
8775#if CL_HPP_TARGET_OPENCL_VERSION >= 200
8776
8781 template<typename T>
8782 cl_int enqueueMemcpySVM(
8783 T *dst_ptr,
8784 const T *src_ptr,
8785 cl_bool blocking,
8786 size_type size,
8787 const vector<Event> *events = nullptr,
8788 Event *event = nullptr) const {
8789 cl_event tmp;
8790 cl_int err = detail::errHandler(::clEnqueueSVMMemcpy(
8791 object_, blocking, static_cast<void *>(dst_ptr), static_cast<const void *>(src_ptr), size,
8792 (events != nullptr) ? (cl_uint) events->size() : 0,
8793 (events != nullptr && events->size() > 0) ? (cl_event *) &events->front() : nullptr,
8794 (event != nullptr) ? &tmp : nullptr), __ENQUEUE_COPY_SVM_ERR);
8795
8796 if (event != nullptr && err == CL_SUCCESS)
8797 *event = tmp;
8798
8799 return err;
8800 }
8801
8806 template<typename T, class D>
8807 cl_int enqueueMemcpySVM(
8808 cl::pointer<T, D> &dst_ptr,
8809 const cl::pointer<T, D> &src_ptr,
8810 cl_bool blocking,
8811 size_type size,
8812 const vector<Event> *events = nullptr,
8813 Event *event = nullptr) const {
8814 cl_event tmp;
8815 cl_int err = detail::errHandler(::clEnqueueSVMMemcpy(
8816 object_, blocking, static_cast<void *>(dst_ptr.get()), static_cast<const void *>(src_ptr.get()),
8817 size,
8818 (events != nullptr) ? (cl_uint) events->size() : 0,
8819 (events != nullptr && events->size() > 0) ? (cl_event *) &events->front() : nullptr,
8820 (event != nullptr) ? &tmp : nullptr), __ENQUEUE_COPY_SVM_ERR);
8821
8822 if (event != nullptr && err == CL_SUCCESS)
8823 *event = tmp;
8824
8825 return err;
8826 }
8827
8832 template<typename T, class Alloc>
8833 cl_int enqueueMemcpySVM(
8834 cl::vector<T, Alloc> &dst_container,
8835 const cl::vector<T, Alloc> &src_container,
8836 cl_bool blocking,
8837 const vector<Event> *events = nullptr,
8838 Event *event = nullptr) const {
8839 cl_event tmp;
8840 if(src_container.size() != dst_container.size()){
8841 return detail::errHandler(CL_INVALID_VALUE,__ENQUEUE_COPY_SVM_ERR);
8842 }
8843 cl_int err = detail::errHandler(::clEnqueueSVMMemcpy(
8844 object_, blocking, static_cast<void *>(dst_container.data()),
8845 static_cast<const void *>(src_container.data()),
8846 dst_container.size() * sizeof(T),
8847 (events != nullptr) ? (cl_uint) events->size() : 0,
8848 (events != nullptr && events->size() > 0) ? (cl_event *) &events->front() : nullptr,
8849 (event != NULL) ? &tmp : nullptr), __ENQUEUE_COPY_SVM_ERR);
8850
8851 if (event != nullptr && err == CL_SUCCESS)
8852 *event = tmp;
8853
8854 return err;
8855 }
8856
8861 template<typename T, typename PatternType>
8862 cl_int enqueueMemFillSVM(
8863 T *ptr,
8864 PatternType pattern,
8865 size_type size,
8866 const vector<Event> *events = nullptr,
8867 Event *event = nullptr) const {
8868 cl_event tmp;
8869 cl_int err = detail::errHandler(::clEnqueueSVMMemFill(
8870 object_, static_cast<void *>(ptr), static_cast<void *>(&pattern),
8871 sizeof(PatternType), size,
8872 (events != nullptr) ? (cl_uint) events->size() : 0,
8873 (events != nullptr && events->size() > 0) ? (cl_event *) &events->front() : nullptr,
8874 (event != nullptr) ? &tmp : nullptr), __ENQUEUE_FILL_SVM_ERR);
8875
8876 if (event != nullptr && err == CL_SUCCESS)
8877 *event = tmp;
8878
8879 return err;
8880 }
8881
8886 template<typename T, class D, typename PatternType>
8887 cl_int enqueueMemFillSVM(
8888 cl::pointer<T, D> &ptr,
8889 PatternType pattern,
8890 size_type size,
8891 const vector<Event> *events = nullptr,
8892 Event *event = nullptr) const {
8893 cl_event tmp;
8894 cl_int err = detail::errHandler(::clEnqueueSVMMemFill(
8895 object_, static_cast<void *>(ptr.get()), static_cast<void *>(&pattern),
8896 sizeof(PatternType), size,
8897 (events != nullptr) ? (cl_uint) events->size() : 0,
8898 (events != nullptr && events->size() > 0) ? (cl_event *) &events->front() : nullptr,
8899 (event != nullptr) ? &tmp : nullptr), __ENQUEUE_FILL_SVM_ERR);
8900
8901 if (event != nullptr && err == CL_SUCCESS)
8902 *event = tmp;
8903
8904 return err;
8905 }
8906
8911 template<typename T, class Alloc, typename PatternType>
8912 cl_int enqueueMemFillSVM(
8913 cl::vector<T, Alloc> &container,
8914 PatternType pattern,
8915 const vector<Event> *events = nullptr,
8916 Event* event = nullptr) const
8917 {
8918 cl_event tmp;
8919 cl_int err = detail::errHandler(::clEnqueueSVMMemFill(
8920 object_, static_cast<void *>(container.data()), static_cast<void *>(&pattern),
8921 sizeof(PatternType), container.size() * sizeof(T),
8922 (events != nullptr) ? (cl_uint) events->size() : 0,
8923 (events != nullptr && events->size() > 0) ? (cl_event *) &events->front() : nullptr,
8924 (event != nullptr) ? &tmp : NULL), __ENQUEUE_FILL_SVM_ERR);
8925
8926 if (event != nullptr && err == CL_SUCCESS)
8927 *event = tmp;
8928
8929 return err;
8930 }
8931
8936 template<typename T>
8937 cl_int enqueueMapSVM(
8938 T* ptr,
8939 cl_bool blocking,
8940 cl_map_flags flags,
8941 size_type size,
8942 const vector<Event>* events = nullptr,
8943 Event* event = nullptr) const
8944 {
8945 cl_event tmp;
8946 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8947 object_, blocking, flags, static_cast<void*>(ptr), size,
8948 (events != nullptr) ? (cl_uint)events->size() : 0,
8949 (events != nullptr && events->size() > 0) ? (cl_event*)&events->front() : nullptr,
8950 (event != nullptr) ? &tmp : nullptr),
8951 __ENQUEUE_MAP_SVM_ERR);
8952
8953 if (event != nullptr && err == CL_SUCCESS)
8954 *event = tmp;
8955
8956 return err;
8957 }
8958
8959
8964 template<typename T, class D>
8965 cl_int enqueueMapSVM(
8966 cl::pointer<T, D> &ptr,
8967 cl_bool blocking,
8968 cl_map_flags flags,
8969 size_type size,
8970 const vector<Event>* events = nullptr,
8971 Event* event = nullptr) const
8972 {
8973 cl_event tmp;
8974 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8975 object_, blocking, flags, static_cast<void*>(ptr.get()), size,
8976 (events != nullptr) ? (cl_uint)events->size() : 0,
8977 (events != nullptr && events->size() > 0) ? (cl_event*)&events->front() : nullptr,
8978 (event != nullptr) ? &tmp : nullptr),
8979 __ENQUEUE_MAP_SVM_ERR);
8980
8981 if (event != nullptr && err == CL_SUCCESS)
8982 *event = tmp;
8983
8984 return err;
8985 }
8986
8991 template<typename T, class Alloc>
8992 cl_int enqueueMapSVM(
8993 cl::vector<T, Alloc> &container,
8994 cl_bool blocking,
8995 cl_map_flags flags,
8996 const vector<Event>* events = nullptr,
8997 Event* event = nullptr) const
8998 {
8999 cl_event tmp;
9000 cl_int err = detail::errHandler(::clEnqueueSVMMap(
9001 object_, blocking, flags, static_cast<void*>(container.data()), container.size()*sizeof(T),
9002 (events != nullptr) ? (cl_uint)events->size() : 0,
9003 (events != nullptr && events->size() > 0) ? (cl_event*)&events->front() : nullptr,
9004 (event != nullptr) ? &tmp : nullptr),
9005 __ENQUEUE_MAP_SVM_ERR);
9006
9007 if (event != nullptr && err == CL_SUCCESS)
9008 *event = tmp;
9009
9010 return err;
9011 }
9012#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9013
9014 cl_int enqueueUnmapMemObject(
9015 const Memory& memory,
9016 void* mapped_ptr,
9017 const vector<Event>* events = nullptr,
9018 Event* event = nullptr) const
9019 {
9020 cl_event tmp;
9021 cl_int err = detail::errHandler(
9022 ::clEnqueueUnmapMemObject(
9023 object_, memory(), mapped_ptr,
9024 (events != nullptr) ? (cl_uint) events->size() : 0,
9025 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
9026 (event != nullptr) ? &tmp : nullptr),
9027 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9028
9029 if (event != nullptr && err == CL_SUCCESS)
9030 *event = tmp;
9031
9032 return err;
9033 }
9034
9035
9036#if CL_HPP_TARGET_OPENCL_VERSION >= 200
9041 template<typename T>
9042 cl_int enqueueUnmapSVM(
9043 T* ptr,
9044 const vector<Event>* events = nullptr,
9045 Event* event = nullptr) const
9046 {
9047 cl_event tmp;
9048 cl_int err = detail::errHandler(
9049 ::clEnqueueSVMUnmap(
9050 object_, static_cast<void*>(ptr),
9051 (events != nullptr) ? (cl_uint)events->size() : 0,
9052 (events != nullptr && events->size() > 0) ? (cl_event*)&events->front() : nullptr,
9053 (event != nullptr) ? &tmp : nullptr),
9054 __ENQUEUE_UNMAP_SVM_ERR);
9055
9056 if (event != nullptr && err == CL_SUCCESS)
9057 *event = tmp;
9058
9059 return err;
9060 }
9061
9066 template<typename T, class D>
9067 cl_int enqueueUnmapSVM(
9068 cl::pointer<T, D> &ptr,
9069 const vector<Event>* events = nullptr,
9070 Event* event = nullptr) const
9071 {
9072 cl_event tmp;
9073 cl_int err = detail::errHandler(
9074 ::clEnqueueSVMUnmap(
9075 object_, static_cast<void*>(ptr.get()),
9076 (events != nullptr) ? (cl_uint)events->size() : 0,
9077 (events != nullptr && events->size() > 0) ? (cl_event*)&events->front() : nullptr,
9078 (event != nullptr) ? &tmp : nullptr),
9079 __ENQUEUE_UNMAP_SVM_ERR);
9080
9081 if (event != nullptr && err == CL_SUCCESS)
9082 *event = tmp;
9083
9084 return err;
9085 }
9086
9091 template<typename T, class Alloc>
9092 cl_int enqueueUnmapSVM(
9093 cl::vector<T, Alloc> &container,
9094 const vector<Event>* events = nullptr,
9095 Event* event = nullptr) const
9096 {
9097 cl_event tmp;
9098 cl_int err = detail::errHandler(
9099 ::clEnqueueSVMUnmap(
9100 object_, static_cast<void*>(container.data()),
9101 (events != nullptr) ? (cl_uint)events->size() : 0,
9102 (events != nullptr && events->size() > 0) ? (cl_event*)&events->front() : nullptr,
9103 (event != nullptr) ? &tmp : nullptr),
9104 __ENQUEUE_UNMAP_SVM_ERR);
9105
9106 if (event != nullptr && err == CL_SUCCESS)
9107 *event = tmp;
9108
9109 return err;
9110 }
9111#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9112
9113#if CL_HPP_TARGET_OPENCL_VERSION >= 120
9125 cl_int enqueueMarkerWithWaitList(
9126 const vector<Event> *events = nullptr,
9127 Event *event = nullptr) const
9128 {
9129 cl_event tmp;
9130 cl_int err = detail::errHandler(
9131 ::clEnqueueMarkerWithWaitList(
9132 object_,
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_MARKER_WAIT_LIST_ERR);
9137
9138 if (event != nullptr && err == CL_SUCCESS)
9139 *event = tmp;
9140
9141 return err;
9142 }
9143
9155 cl_int enqueueBarrierWithWaitList(
9156 const vector<Event> *events = nullptr,
9157 Event *event = nullptr) const
9158 {
9159 cl_event tmp;
9160 cl_int err = detail::errHandler(
9161 ::clEnqueueBarrierWithWaitList(
9162 object_,
9163 (events != nullptr) ? (cl_uint) events->size() : 0,
9164 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
9165 (event != nullptr) ? &tmp : nullptr),
9166 __ENQUEUE_BARRIER_WAIT_LIST_ERR);
9167
9168 if (event != nullptr && err == CL_SUCCESS)
9169 *event = tmp;
9170
9171 return err;
9172 }
9173
9178 cl_int enqueueMigrateMemObjects(
9179 const vector<Memory> &memObjects,
9180 cl_mem_migration_flags flags,
9181 const vector<Event>* events = nullptr,
9182 Event* event = nullptr
9183 ) const
9184 {
9185 cl_event tmp;
9186
9187 vector<cl_mem> localMemObjects(memObjects.size());
9188
9189 for( int i = 0; i < (int)memObjects.size(); ++i ) {
9190 localMemObjects[i] = memObjects[i]();
9191 }
9192
9193 cl_int err = detail::errHandler(
9194 ::clEnqueueMigrateMemObjects(
9195 object_,
9196 (cl_uint)memObjects.size(),
9197 localMemObjects.data(),
9198 flags,
9199 (events != nullptr) ? (cl_uint) events->size() : 0,
9200 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
9201 (event != nullptr) ? &tmp : nullptr),
9202 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9203
9204 if (event != nullptr && err == CL_SUCCESS)
9205 *event = tmp;
9206
9207 return err;
9208 }
9209#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
9210
9211
9212#if CL_HPP_TARGET_OPENCL_VERSION >= 210
9218 template<typename T>
9219 cl_int enqueueMigrateSVM(
9220 const cl::vector<T*> &svmRawPointers,
9221 const cl::vector<size_type> &sizes,
9222 cl_mem_migration_flags flags = 0,
9223 const vector<Event>* events = nullptr,
9224 Event* event = nullptr) const
9225 {
9226 cl_event tmp;
9227 cl_int err = detail::errHandler(::clEnqueueSVMMigrateMem(
9228 object_,
9229 svmRawPointers.size(), static_cast<void**>(svmRawPointers.data()),
9230 sizes.data(), // array of sizes not passed
9231 flags,
9232 (events != nullptr) ? (cl_uint)events->size() : 0,
9233 (events != nullptr && events->size() > 0) ? (cl_event*)&events->front() : nullptr,
9234 (event != nullptr) ? &tmp : nullptr),
9235 __ENQUEUE_MIGRATE_SVM_ERR);
9236
9237 if (event != nullptr && err == CL_SUCCESS)
9238 *event = tmp;
9239
9240 return err;
9241 }
9242
9247 template<typename T>
9248 cl_int enqueueMigrateSVM(
9249 const cl::vector<T*> &svmRawPointers,
9250 cl_mem_migration_flags flags = 0,
9251 const vector<Event>* events = nullptr,
9252 Event* event = nullptr) const
9253 {
9254 return enqueueMigrateSVM(svmRawPointers, cl::vector<size_type>(svmRawPointers.size()), flags, events, event);
9255 }
9256
9257
9263 template<typename T, class D>
9264 cl_int enqueueMigrateSVM(
9265 const cl::vector<cl::pointer<T, D>> &svmPointers,
9266 const cl::vector<size_type> &sizes,
9267 cl_mem_migration_flags flags = 0,
9268 const vector<Event>* events = nullptr,
9269 Event* event = nullptr) const
9270 {
9271 cl::vector<void*> svmRawPointers;
9272 svmRawPointers.reserve(svmPointers.size());
9273 for (auto p : svmPointers) {
9274 svmRawPointers.push_back(static_cast<void*>(p.get()));
9275 }
9276
9277 return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
9278 }
9279
9280
9285 template<typename T, class D>
9286 cl_int enqueueMigrateSVM(
9287 const cl::vector<cl::pointer<T, D>> &svmPointers,
9288 cl_mem_migration_flags flags = 0,
9289 const vector<Event>* events = nullptr,
9290 Event* event = nullptr) const
9291 {
9292 return enqueueMigrateSVM(svmPointers, cl::vector<size_type>(svmPointers.size()), flags, events, event);
9293 }
9294
9300 template<typename T, class Alloc>
9301 cl_int enqueueMigrateSVM(
9302 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
9303 const cl::vector<size_type> &sizes,
9304 cl_mem_migration_flags flags = 0,
9305 const vector<Event>* events = nullptr,
9306 Event* event = nullptr) const
9307 {
9308 cl::vector<void*> svmRawPointers;
9309 svmRawPointers.reserve(svmContainers.size());
9310 for (auto p : svmContainers) {
9311 svmRawPointers.push_back(static_cast<void*>(p.data()));
9312 }
9313
9314 return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
9315 }
9316
9321 template<typename T, class Alloc>
9322 cl_int enqueueMigrateSVM(
9323 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
9324 cl_mem_migration_flags flags = 0,
9325 const vector<Event>* events = nullptr,
9326 Event* event = nullptr) const
9327 {
9328 return enqueueMigrateSVM(svmContainers, cl::vector<size_type>(svmContainers.size()), flags, events, event);
9329 }
9330
9331#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
9332
9333 cl_int enqueueNDRangeKernel(
9334 const Kernel& kernel,
9335 const NDRange& offset,
9336 const NDRange& global,
9337 const NDRange& local = NullRange,
9338 const vector<Event>* events = nullptr,
9339 Event* event = nullptr) const
9340 {
9341 cl_event tmp;
9342 cl_int err = detail::errHandler(
9343 ::clEnqueueNDRangeKernel(
9344 object_, kernel(), (cl_uint) global.dimensions(),
9345 offset.dimensions() != 0 ? (const size_type*) offset : nullptr,
9346 (const size_type*) global,
9347 local.dimensions() != 0 ? (const size_type*) local : nullptr,
9348 (events != nullptr) ? (cl_uint) events->size() : 0,
9349 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
9350 (event != nullptr) ? &tmp : nullptr),
9351 __ENQUEUE_NDRANGE_KERNEL_ERR);
9352
9353 if (event != nullptr && err == CL_SUCCESS)
9354 *event = tmp;
9355
9356 return err;
9357 }
9358
9359#if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
9360 CL_API_PREFIX__VERSION_1_2_DEPRECATED cl_int enqueueTask(
9361 const Kernel& kernel,
9362 const vector<Event>* events = nullptr,
9363 Event* event = nullptr) const CL_API_SUFFIX__VERSION_1_2_DEPRECATED
9364 {
9365 cl_event tmp;
9366 cl_int err = detail::errHandler(
9367 ::clEnqueueTask(
9368 object_, kernel(),
9369 (events != nullptr) ? (cl_uint) events->size() : 0,
9370 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
9371 (event != nullptr) ? &tmp : nullptr),
9372 __ENQUEUE_TASK_ERR);
9373
9374 if (event != nullptr && err == CL_SUCCESS)
9375 *event = tmp;
9376
9377 return err;
9378 }
9379#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
9380
9381 cl_int enqueueNativeKernel(
9382 void (CL_CALLBACK *userFptr)(void *),
9383 std::pair<void*, size_type> args,
9384 const vector<Memory>* mem_objects = nullptr,
9385 const vector<const void*>* mem_locs = nullptr,
9386 const vector<Event>* events = nullptr,
9387 Event* event = nullptr) const
9388 {
9389 cl_event tmp;
9390 cl_int err = detail::errHandler(
9391 ::clEnqueueNativeKernel(
9392 object_, userFptr, args.first, args.second,
9393 (mem_objects != nullptr) ? (cl_uint) mem_objects->size() : 0,
9394 (mem_objects->size() > 0 ) ? reinterpret_cast<const cl_mem *>(mem_objects->data()) : nullptr,
9395 (mem_locs != nullptr && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : nullptr,
9396 (events != nullptr) ? (cl_uint) events->size() : 0,
9397 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
9398 (event != nullptr) ? &tmp : nullptr),
9399 __ENQUEUE_NATIVE_KERNEL);
9400
9401 if (event != nullptr && err == CL_SUCCESS)
9402 *event = tmp;
9403
9404 return err;
9405 }
9406
9410#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
9411 CL_API_PREFIX__VERSION_1_1_DEPRECATED
9412 cl_int enqueueMarker(Event* event = nullptr) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
9413 {
9414 cl_event tmp;
9415 cl_int err = detail::errHandler(
9416 ::clEnqueueMarker(
9417 object_,
9418 (event != nullptr) ? &tmp : nullptr),
9419 __ENQUEUE_MARKER_ERR);
9420
9421 if (event != nullptr && err == CL_SUCCESS)
9422 *event = tmp;
9423
9424 return err;
9425 }
9426
9427 CL_API_PREFIX__VERSION_1_1_DEPRECATED
9428 cl_int enqueueWaitForEvents(const vector<Event>& events) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
9429 {
9430 return detail::errHandler(
9431 ::clEnqueueWaitForEvents(
9432 object_,
9433 (cl_uint) events.size(),
9434 events.size() > 0 ? (const cl_event*) &events.front() : nullptr),
9435 __ENQUEUE_WAIT_FOR_EVENTS_ERR);
9436 }
9437#endif // defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
9438
9439 cl_int enqueueAcquireGLObjects(
9440 const vector<Memory>* mem_objects = nullptr,
9441 const vector<Event>* events = nullptr,
9442 Event* event = nullptr) const
9443 {
9444 cl_event tmp;
9445 cl_int err = detail::errHandler(
9446 ::clEnqueueAcquireGLObjects(
9447 object_,
9448 (mem_objects != nullptr) ? (cl_uint) mem_objects->size() : 0,
9449 (mem_objects != nullptr && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): nullptr,
9450 (events != nullptr) ? (cl_uint) events->size() : 0,
9451 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
9452 (event != nullptr) ? &tmp : nullptr),
9453 __ENQUEUE_ACQUIRE_GL_ERR);
9454
9455 if (event != nullptr && err == CL_SUCCESS)
9456 *event = tmp;
9457
9458 return err;
9459 }
9460
9461 cl_int enqueueReleaseGLObjects(
9462 const vector<Memory>* mem_objects = nullptr,
9463 const vector<Event>* events = nullptr,
9464 Event* event = nullptr) const
9465 {
9466 cl_event tmp;
9467 cl_int err = detail::errHandler(
9468 ::clEnqueueReleaseGLObjects(
9469 object_,
9470 (mem_objects != nullptr) ? (cl_uint) mem_objects->size() : 0,
9471 (mem_objects != nullptr && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): nullptr,
9472 (events != nullptr) ? (cl_uint) events->size() : 0,
9473 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
9474 (event != nullptr) ? &tmp : nullptr),
9475 __ENQUEUE_RELEASE_GL_ERR);
9476
9477 if (event != nullptr && err == CL_SUCCESS)
9478 *event = tmp;
9479
9480 return err;
9481 }
9482
9483#if defined (CL_HPP_USE_DX_INTEROP)
9484typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
9485 cl_command_queue command_queue, cl_uint num_objects,
9486 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
9487 const cl_event* event_wait_list, cl_event* event);
9488typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
9489 cl_command_queue command_queue, cl_uint num_objects,
9490 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
9491 const cl_event* event_wait_list, cl_event* event);
9492
9493 cl_int enqueueAcquireD3D10Objects(
9494 const vector<Memory>* mem_objects = nullptr,
9495 const vector<Event>* events = nullptr,
9496 Event* event = nullptr) const
9497 {
9498 static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = nullptr;
9499#if CL_HPP_TARGET_OPENCL_VERSION >= 120
9500 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
9501 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
9502 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
9503 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireD3D10ObjectsKHR);
9504#endif
9505#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
9506 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueAcquireD3D10ObjectsKHR);
9507#endif
9508
9509 cl_event tmp;
9510 cl_int err = detail::errHandler(
9511 pfn_clEnqueueAcquireD3D10ObjectsKHR(
9512 object_,
9513 (mem_objects != nullptr) ? (cl_uint) mem_objects->size() : 0,
9514 (mem_objects != nullptr && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): nullptr,
9515 (events != nullptr) ? (cl_uint) events->size() : 0,
9516 (events != nullptr) ? (cl_event*) &events->front() : nullptr,
9517 (event != nullptr) ? &tmp : nullptr),
9518 __ENQUEUE_ACQUIRE_GL_ERR);
9519
9520 if (event != nullptr && err == CL_SUCCESS)
9521 *event = tmp;
9522
9523 return err;
9524 }
9525
9526 cl_int enqueueReleaseD3D10Objects(
9527 const vector<Memory>* mem_objects = nullptr,
9528 const vector<Event>* events = nullptr,
9529 Event* event = nullptr) const
9530 {
9531 static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = nullptr;
9532#if CL_HPP_TARGET_OPENCL_VERSION >= 120
9533 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
9534 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
9535 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
9536 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseD3D10ObjectsKHR);
9537#endif
9538#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
9539 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueReleaseD3D10ObjectsKHR);
9540#endif
9541
9542 cl_event tmp;
9543 cl_int err = detail::errHandler(
9544 pfn_clEnqueueReleaseD3D10ObjectsKHR(
9545 object_,
9546 (mem_objects != nullptr) ? (cl_uint) mem_objects->size() : 0,
9547 (mem_objects != nullptr && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): nullptr,
9548 (events != nullptr) ? (cl_uint) events->size() : 0,
9549 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
9550 (event != nullptr) ? &tmp : nullptr),
9551 __ENQUEUE_RELEASE_GL_ERR);
9552
9553 if (event != nullptr && err == CL_SUCCESS)
9554 *event = tmp;
9555
9556 return err;
9557 }
9558#endif
9559
9563#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
9564 CL_API_PREFIX__VERSION_1_1_DEPRECATED
9565 cl_int enqueueBarrier() const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
9566 {
9567 return detail::errHandler(
9568 ::clEnqueueBarrier(object_),
9569 __ENQUEUE_BARRIER_ERR);
9570 }
9571#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
9572
9573 cl_int flush() const
9574 {
9575 return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
9576 }
9577
9578 cl_int finish() const
9579 {
9580 return detail::errHandler(::clFinish(object_), __FINISH_ERR);
9581 }
9582
9583#ifdef cl_khr_external_memory
9584 cl_int enqueueAcquireExternalMemObjects(
9585 const vector<Memory>& mem_objects,
9586 const vector<Event>* events_wait = nullptr,
9587 Event *event = nullptr)
9588 {
9589 cl_int err = CL_INVALID_OPERATION;
9590 cl_event tmp;
9591
9592 std::call_once(ext_memory_initialized_, initMemoryExtension, this->getInfo<CL_QUEUE_DEVICE>());
9593
9594 if (pfn_clEnqueueAcquireExternalMemObjectsKHR)
9595 {
9596 err = pfn_clEnqueueAcquireExternalMemObjectsKHR(
9597 object_,
9598 static_cast<cl_uint>(mem_objects.size()),
9599 (mem_objects.size() > 0) ? reinterpret_cast<const cl_mem *>(mem_objects.data()) : nullptr,
9600 (events_wait != nullptr) ? static_cast<cl_uint>(events_wait->size()) : 0,
9601 (events_wait != nullptr && events_wait->size() > 0) ? reinterpret_cast<const cl_event*>(events_wait->data()) : nullptr,
9602 &tmp);
9603 }
9604
9605 detail::errHandler(err, __ENQUEUE_ACQUIRE_EXTERNAL_MEMORY_ERR);
9606
9607 if (event != nullptr && err == CL_SUCCESS)
9608 *event = tmp;
9609
9610 return err;
9611 }
9612
9613 cl_int enqueueReleaseExternalMemObjects(
9614 const vector<Memory>& mem_objects,
9615 const vector<Event>* events_wait = nullptr,
9616 Event *event = nullptr)
9617 {
9618 cl_int err = CL_INVALID_OPERATION;
9619 cl_event tmp;
9620
9621 std::call_once(ext_memory_initialized_, initMemoryExtension, this->getInfo<CL_QUEUE_DEVICE>());
9622
9623 if (pfn_clEnqueueReleaseExternalMemObjectsKHR)
9624 {
9625 err = pfn_clEnqueueReleaseExternalMemObjectsKHR(
9626 object_,
9627 static_cast<cl_uint>(mem_objects.size()),
9628 (mem_objects.size() > 0) ? reinterpret_cast<const cl_mem *>(mem_objects.data()) : nullptr,
9629 (events_wait != nullptr) ? static_cast<cl_uint>(events_wait->size()) : 0,
9630 (events_wait != nullptr && events_wait->size() > 0) ? reinterpret_cast<const cl_event*>(events_wait->data()) : nullptr,
9631 &tmp);
9632 }
9633
9634 detail::errHandler(err, __ENQUEUE_RELEASE_EXTERNAL_MEMORY_ERR);
9635
9636 if (event != nullptr && err == CL_SUCCESS)
9637 *event = tmp;
9638
9639 return err;
9640 }
9641#endif // cl_khr_external_memory && CL_HPP_TARGET_OPENCL_VERSION >= 300
9642
9643#ifdef cl_khr_semaphore
9644 cl_int enqueueWaitSemaphores(
9645 const vector<Semaphore> &sema_objects,
9646 const vector<cl_semaphore_payload_khr> &sema_payloads = {},
9647 const vector<Event>* events_wait_list = nullptr,
9648 Event *event = nullptr) const;
9649
9650 cl_int enqueueSignalSemaphores(
9651 const vector<Semaphore> &sema_objects,
9652 const vector<cl_semaphore_payload_khr>& sema_payloads = {},
9653 const vector<Event>* events_wait_list = nullptr,
9654 Event* event = nullptr);
9655#endif // cl_khr_semaphore
9656}; // CommandQueue
9657
9658#ifdef cl_khr_external_memory
9659CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::ext_memory_initialized_;
9660#endif
9661
9662CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::default_initialized_;
9663CL_HPP_DEFINE_STATIC_MEMBER_ CommandQueue CommandQueue::default_;
9664CL_HPP_DEFINE_STATIC_MEMBER_ cl_int CommandQueue::default_error_ = CL_SUCCESS;
9665
9666
9667#if CL_HPP_TARGET_OPENCL_VERSION >= 200
9668enum class DeviceQueueProperties : cl_command_queue_properties
9669{
9670 None = 0,
9671 Profiling = CL_QUEUE_PROFILING_ENABLE,
9672};
9673
9674inline DeviceQueueProperties operator|(DeviceQueueProperties lhs, DeviceQueueProperties rhs)
9675{
9676 return static_cast<DeviceQueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
9677}
9678
9682class DeviceCommandQueue : public detail::Wrapper<cl_command_queue>
9683{
9684public:
9685
9689 DeviceCommandQueue() { }
9690
9694 DeviceCommandQueue(DeviceQueueProperties properties, cl_int* err = nullptr)
9695 {
9696 cl_int error;
9697 cl::Context context = cl::Context::getDefault();
9698 cl::Device device = cl::Device::getDefault();
9699
9700 cl_command_queue_properties mergedProperties =
9701 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
9702
9703 cl_queue_properties queue_properties[] = {
9704 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
9705 object_ = ::clCreateCommandQueueWithProperties(
9706 context(), device(), queue_properties, &error);
9707
9708 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9709 if (err != nullptr) {
9710 *err = error;
9711 }
9712 }
9713
9717 DeviceCommandQueue(
9718 const Context& context,
9719 const Device& device,
9720 DeviceQueueProperties properties = DeviceQueueProperties::None,
9721 cl_int* err = nullptr)
9722 {
9723 cl_int error;
9724
9725 cl_command_queue_properties mergedProperties =
9726 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
9727 cl_queue_properties queue_properties[] = {
9728 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
9729 object_ = ::clCreateCommandQueueWithProperties(
9730 context(), device(), queue_properties, &error);
9731
9732 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9733 if (err != nullptr) {
9734 *err = error;
9735 }
9736 }
9737
9741 DeviceCommandQueue(
9742 const Context& context,
9743 const Device& device,
9744 cl_uint queueSize,
9745 DeviceQueueProperties properties = DeviceQueueProperties::None,
9746 cl_int* err = nullptr)
9747 {
9748 cl_int error;
9749
9750 cl_command_queue_properties mergedProperties =
9751 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
9752 cl_queue_properties queue_properties[] = {
9753 CL_QUEUE_PROPERTIES, mergedProperties,
9754 CL_QUEUE_SIZE, queueSize,
9755 0 };
9756 object_ = ::clCreateCommandQueueWithProperties(
9757 context(), device(), queue_properties, &error);
9758
9759 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9760 if (err != nullptr) {
9761 *err = error;
9762 }
9763 }
9764
9771 explicit DeviceCommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
9772 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
9773
9774 DeviceCommandQueue& operator = (const cl_command_queue& rhs)
9775 {
9776 detail::Wrapper<cl_type>::operator=(rhs);
9777 return *this;
9778 }
9779
9780 template <typename T>
9781 cl_int getInfo(cl_command_queue_info name, T* param) const
9782 {
9783 return detail::errHandler(
9784 detail::getInfo(
9785 &::clGetCommandQueueInfo, object_, name, param),
9786 __GET_COMMAND_QUEUE_INFO_ERR);
9787 }
9788
9789 template <cl_command_queue_info name> typename
9790 detail::param_traits<detail::cl_command_queue_info, name>::param_type
9791 getInfo(cl_int* err = nullptr) const
9792 {
9793 typename detail::param_traits<
9794 detail::cl_command_queue_info, name>::param_type param;
9795 cl_int result = getInfo(name, &param);
9796 if (err != nullptr) {
9797 *err = result;
9798 }
9799 return param;
9800 }
9801
9808 static DeviceCommandQueue makeDefault(
9809 cl_int *err = nullptr)
9810 {
9811 cl_int error;
9812 cl::Context context = cl::Context::getDefault();
9813 cl::Device device = cl::Device::getDefault();
9814
9815 cl_command_queue_properties properties =
9816 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9817 cl_queue_properties queue_properties[] = {
9818 CL_QUEUE_PROPERTIES, properties,
9819 0 };
9820 DeviceCommandQueue deviceQueue(
9821 ::clCreateCommandQueueWithProperties(
9822 context(), device(), queue_properties, &error));
9823
9824 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9825 if (err != nullptr) {
9826 *err = error;
9827 }
9828
9829 return deviceQueue;
9830 }
9831
9838 static DeviceCommandQueue makeDefault(
9839 const Context &context, const Device &device, cl_int *err = nullptr)
9840 {
9841 cl_int error;
9842
9843 cl_command_queue_properties properties =
9844 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9845 cl_queue_properties queue_properties[] = {
9846 CL_QUEUE_PROPERTIES, properties,
9847 0 };
9848 DeviceCommandQueue deviceQueue(
9849 ::clCreateCommandQueueWithProperties(
9850 context(), device(), queue_properties, &error));
9851
9852 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9853 if (err != nullptr) {
9854 *err = error;
9855 }
9856
9857 return deviceQueue;
9858 }
9859
9866 static DeviceCommandQueue makeDefault(
9867 const Context &context, const Device &device, cl_uint queueSize, cl_int *err = nullptr)
9868 {
9869 cl_int error;
9870
9871 cl_command_queue_properties properties =
9872 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9873 cl_queue_properties queue_properties[] = {
9874 CL_QUEUE_PROPERTIES, properties,
9875 CL_QUEUE_SIZE, queueSize,
9876 0 };
9877 DeviceCommandQueue deviceQueue(
9878 ::clCreateCommandQueueWithProperties(
9879 context(), device(), queue_properties, &error));
9880
9881 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9882 if (err != nullptr) {
9883 *err = error;
9884 }
9885
9886 return deviceQueue;
9887 }
9888
9889
9890
9891#if CL_HPP_TARGET_OPENCL_VERSION >= 210
9898 static DeviceCommandQueue updateDefault(const Context &context, const Device &device, const DeviceCommandQueue &default_queue, cl_int *err = nullptr)
9899 {
9900 cl_int error;
9901 error = clSetDefaultDeviceCommandQueue(context.get(), device.get(), default_queue.get());
9902
9903 detail::errHandler(error, __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR);
9904 if (err != nullptr) {
9905 *err = error;
9906 }
9907 return default_queue;
9908 }
9909
9913 static DeviceCommandQueue getDefault(const CommandQueue &queue, cl_int * err = nullptr)
9914 {
9915 return queue.getInfo<CL_QUEUE_DEVICE_DEFAULT>(err);
9916 }
9917
9918#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
9919}; // DeviceCommandQueue
9920
9921 namespace detail
9922{
9923 // Specialization for device command queue
9924 template <>
9925 struct KernelArgumentHandler<cl::DeviceCommandQueue, void>
9926 {
9927 static size_type size(const cl::DeviceCommandQueue&) { return sizeof(cl_command_queue); }
9928 static const cl_command_queue* ptr(const cl::DeviceCommandQueue& value) { return &(value()); }
9929 };
9930} // namespace detail
9931
9932#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9933
9934
9935template< typename IteratorType >
9936 Buffer::Buffer(
9937 const Context &context,
9938 IteratorType startIterator,
9939 IteratorType endIterator,
9940 bool readOnly,
9941 bool useHostPtr,
9942 cl_int* err)
9943{
9944 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9945 cl_int error;
9946
9947 cl_mem_flags flags = 0;
9948 if( readOnly ) {
9949 flags |= CL_MEM_READ_ONLY;
9950 }
9951 else {
9952 flags |= CL_MEM_READ_WRITE;
9953 }
9954 if( useHostPtr ) {
9955 flags |= CL_MEM_USE_HOST_PTR;
9956 }
9957
9958 size_type size = sizeof(DataType)*(endIterator - startIterator);
9959
9960 if( useHostPtr ) {
9961 object_ = ::clCreateBuffer(context(), flags, size, const_cast<DataType*>(&*startIterator), &error);
9962 } else {
9963 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9964 }
9965
9966 detail::errHandler(error, __CREATE_BUFFER_ERR);
9967 if (err != nullptr) {
9968 *err = error;
9969 }
9970
9971 if( !useHostPtr ) {
9972 CommandQueue queue(context, 0, &error);
9973 detail::errHandler(error, __CREATE_BUFFER_ERR);
9974 if (err != nullptr) {
9975 *err = error;
9976 }
9977
9978 error = cl::copy(queue, startIterator, endIterator, *this);
9979 detail::errHandler(error, __CREATE_BUFFER_ERR);
9980 if (err != nullptr) {
9981 *err = error;
9982 }
9983 }
9984}
9985
9986template< typename IteratorType >
9987 Buffer::Buffer(
9988 const CommandQueue &queue,
9989 IteratorType startIterator,
9990 IteratorType endIterator,
9991 bool readOnly,
9992 bool useHostPtr,
9993 cl_int* err)
9994{
9995 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9996 cl_int error;
9997
9998 cl_mem_flags flags = 0;
9999 if (readOnly) {
10000 flags |= CL_MEM_READ_ONLY;
10001 }
10002 else {
10003 flags |= CL_MEM_READ_WRITE;
10004 }
10005 if (useHostPtr) {
10006 flags |= CL_MEM_USE_HOST_PTR;
10007 }
10008
10009 size_type size = sizeof(DataType)*(endIterator - startIterator);
10010
10011 Context context = queue.getInfo<CL_QUEUE_CONTEXT>();
10012
10013 if (useHostPtr) {
10014 object_ = ::clCreateBuffer(context(), flags, size, const_cast<DataType*>(&*startIterator), &error);
10015 }
10016 else {
10017 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
10018 }
10019
10020 detail::errHandler(error, __CREATE_BUFFER_ERR);
10021 if (err != nullptr) {
10022 *err = error;
10023 }
10024
10025 if (!useHostPtr) {
10026 error = cl::copy(queue, startIterator, endIterator, *this);
10027 detail::errHandler(error, __CREATE_BUFFER_ERR);
10028 if (err != nullptr) {
10029 *err = error;
10030 }
10031 }
10032}
10033
10034inline cl_int enqueueReadBuffer(
10035 const Buffer& buffer,
10036 cl_bool blocking,
10037 size_type offset,
10038 size_type size,
10039 void* ptr,
10040 const vector<Event>* events = nullptr,
10041 Event* event = nullptr)
10042{
10043 cl_int error;
10044 CommandQueue queue = CommandQueue::getDefault(&error);
10045
10046 if (error != CL_SUCCESS) {
10047 return error;
10048 }
10049
10050 return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event);
10051}
10052
10053inline cl_int enqueueWriteBuffer(
10054 const Buffer& buffer,
10055 cl_bool blocking,
10056 size_type offset,
10057 size_type size,
10058 const void* ptr,
10059 const vector<Event>* events = nullptr,
10060 Event* event = nullptr)
10061{
10062 cl_int error;
10063 CommandQueue queue = CommandQueue::getDefault(&error);
10064
10065 if (error != CL_SUCCESS) {
10066 return error;
10067 }
10068
10069 return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event);
10070}
10071
10072inline void* enqueueMapBuffer(
10073 const Buffer& buffer,
10074 cl_bool blocking,
10075 cl_map_flags flags,
10076 size_type offset,
10077 size_type size,
10078 const vector<Event>* events = nullptr,
10079 Event* event = nullptr,
10080 cl_int* err = nullptr)
10081{
10082 cl_int error;
10083 CommandQueue queue = CommandQueue::getDefault(&error);
10084 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
10085 if (err != nullptr) {
10086 *err = error;
10087 }
10088
10089 void * result = ::clEnqueueMapBuffer(
10090 queue(), buffer(), blocking, flags, offset, size,
10091 (events != nullptr) ? (cl_uint) events->size() : 0,
10092 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
10093 (cl_event*) event,
10094 &error);
10095
10096 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
10097 if (err != nullptr) {
10098 *err = error;
10099 }
10100 return result;
10101}
10102
10103
10104#if CL_HPP_TARGET_OPENCL_VERSION >= 200
10110template<typename T>
10111inline cl_int enqueueMapSVM(
10112 T* ptr,
10113 cl_bool blocking,
10114 cl_map_flags flags,
10115 size_type size,
10116 const vector<Event>* events,
10117 Event* event)
10118{
10119 cl_int error;
10120 CommandQueue queue = CommandQueue::getDefault(&error);
10121 if (error != CL_SUCCESS) {
10122 return detail::errHandler(error, __ENQUEUE_MAP_SVM_ERR);
10123 }
10124
10125 return queue.enqueueMapSVM(
10126 ptr, blocking, flags, size, events, event);
10127}
10128
10134template<typename T, class D>
10135inline cl_int enqueueMapSVM(
10136 cl::pointer<T, D> &ptr,
10137 cl_bool blocking,
10138 cl_map_flags flags,
10139 size_type size,
10140 const vector<Event>* events = nullptr,
10141 Event* event = nullptr)
10142{
10143 cl_int error;
10144 CommandQueue queue = CommandQueue::getDefault(&error);
10145 if (error != CL_SUCCESS) {
10146 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
10147 }
10148
10149 return queue.enqueueMapSVM(
10150 ptr, blocking, flags, size, events, event);
10151}
10152
10158template<typename T, class Alloc>
10159inline cl_int enqueueMapSVM(
10160 cl::vector<T, Alloc> &container,
10161 cl_bool blocking,
10162 cl_map_flags flags,
10163 const vector<Event>* events = nullptr,
10164 Event* event = nullptr)
10165{
10166 cl_int error;
10167 CommandQueue queue = CommandQueue::getDefault(&error);
10168 if (error != CL_SUCCESS) {
10169 return detail::errHandler(error, __ENQUEUE_MAP_SVM_ERR);
10170 }
10171
10172 return queue.enqueueMapSVM(
10173 container, blocking, flags, events, event);
10174}
10175
10176#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10177
10178inline cl_int enqueueUnmapMemObject(
10179 const Memory& memory,
10180 void* mapped_ptr,
10181 const vector<Event>* events = nullptr,
10182 Event* event = nullptr)
10183{
10184 cl_int error;
10185 CommandQueue queue = CommandQueue::getDefault(&error);
10186 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
10187 if (error != CL_SUCCESS) {
10188 return error;
10189 }
10190
10191 cl_event tmp;
10192 cl_int err = detail::errHandler(
10193 ::clEnqueueUnmapMemObject(
10194 queue(), memory(), mapped_ptr,
10195 (events != nullptr) ? (cl_uint)events->size() : 0,
10196 (events != nullptr && events->size() > 0) ? (cl_event*)&events->front() : nullptr,
10197 (event != nullptr) ? &tmp : nullptr),
10198 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
10199
10200 if (event != nullptr && err == CL_SUCCESS)
10201 *event = tmp;
10202
10203 return err;
10204}
10205
10206#if CL_HPP_TARGET_OPENCL_VERSION >= 200
10212template<typename T>
10213inline cl_int enqueueUnmapSVM(
10214 T* ptr,
10215 const vector<Event>* events = nullptr,
10216 Event* event = nullptr)
10217{
10218 cl_int error;
10219 CommandQueue queue = CommandQueue::getDefault(&error);
10220 if (error != CL_SUCCESS) {
10221 return detail::errHandler(error, __ENQUEUE_UNMAP_SVM_ERR);
10222 }
10223
10224 return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
10225 __ENQUEUE_UNMAP_SVM_ERR);
10226
10227}
10228
10234template<typename T, class D>
10235inline cl_int enqueueUnmapSVM(
10236 cl::pointer<T, D> &ptr,
10237 const vector<Event>* events = nullptr,
10238 Event* event = nullptr)
10239{
10240 cl_int error;
10241 CommandQueue queue = CommandQueue::getDefault(&error);
10242 if (error != CL_SUCCESS) {
10243 return detail::errHandler(error, __ENQUEUE_UNMAP_SVM_ERR);
10244 }
10245
10246 return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
10247 __ENQUEUE_UNMAP_SVM_ERR);
10248}
10249
10255template<typename T, class Alloc>
10256inline cl_int enqueueUnmapSVM(
10257 cl::vector<T, Alloc> &container,
10258 const vector<Event>* events = nullptr,
10259 Event* event = nullptr)
10260{
10261 cl_int error;
10262 CommandQueue queue = CommandQueue::getDefault(&error);
10263 if (error != CL_SUCCESS) {
10264 return detail::errHandler(error, __ENQUEUE_UNMAP_SVM_ERR);
10265 }
10266
10267 return detail::errHandler(queue.enqueueUnmapSVM(container, events, event),
10268 __ENQUEUE_UNMAP_SVM_ERR);
10269}
10270
10271#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10272
10273inline cl_int enqueueCopyBuffer(
10274 const Buffer& src,
10275 const Buffer& dst,
10276 size_type src_offset,
10277 size_type dst_offset,
10278 size_type size,
10279 const vector<Event>* events = nullptr,
10280 Event* event = nullptr)
10281{
10282 cl_int error;
10283 CommandQueue queue = CommandQueue::getDefault(&error);
10284
10285 if (error != CL_SUCCESS) {
10286 return error;
10287 }
10288
10289 return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event);
10290}
10291
10297template< typename IteratorType >
10298inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
10299{
10300 cl_int error;
10301 CommandQueue queue = CommandQueue::getDefault(&error);
10302 if (error != CL_SUCCESS)
10303 return error;
10304
10305 return cl::copy(queue, startIterator, endIterator, buffer);
10306}
10307
10313template< typename IteratorType >
10314inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
10315{
10316 cl_int error;
10317 CommandQueue queue = CommandQueue::getDefault(&error);
10318 if (error != CL_SUCCESS)
10319 return error;
10320
10321 return cl::copy(queue, buffer, startIterator, endIterator);
10322}
10323
10329template< typename IteratorType >
10330inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
10331{
10332 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
10333 cl_int error;
10334
10335 size_type length = endIterator-startIterator;
10336 size_type byteLength = length*sizeof(DataType);
10337
10338 DataType *pointer =
10339 static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error));
10340 // if exceptions enabled, enqueueMapBuffer will throw
10341 if( error != CL_SUCCESS ) {
10342 return error;
10343 }
10344#if defined(_MSC_VER) && _MSC_VER < 1920
10345 std::copy(
10346 startIterator,
10347 endIterator,
10348 stdext::checked_array_iterator<DataType*>(
10349 pointer, length));
10350#else
10351 std::copy(startIterator, endIterator, pointer);
10352#endif // defined(_MSC_VER) && _MSC_VER < 1920
10353 Event endEvent;
10354 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
10355 // if exceptions enabled, enqueueUnmapMemObject will throw
10356 if( error != CL_SUCCESS ) {
10357 return error;
10358 }
10359 endEvent.wait();
10360 return CL_SUCCESS;
10361}
10362
10368template< typename IteratorType >
10369inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
10370{
10371 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
10372 cl_int error;
10373
10374 size_type length = endIterator-startIterator;
10375 size_type byteLength = length*sizeof(DataType);
10376
10377 DataType *pointer =
10378 static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error));
10379 // if exceptions enabled, enqueueMapBuffer will throw
10380 if( error != CL_SUCCESS ) {
10381 return error;
10382 }
10383 std::copy(pointer, pointer + length, startIterator);
10384 Event endEvent;
10385 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
10386 // if exceptions enabled, enqueueUnmapMemObject will throw
10387 if( error != CL_SUCCESS ) {
10388 return error;
10389 }
10390 endEvent.wait();
10391 return CL_SUCCESS;
10392}
10393
10394
10395#if CL_HPP_TARGET_OPENCL_VERSION >= 200
10399template<typename T, class Alloc>
10400inline cl_int mapSVM(cl::vector<T, Alloc> &container)
10401{
10402 return enqueueMapSVM(container, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE);
10403}
10404
10408template<typename T, class Alloc>
10409inline cl_int unmapSVM(cl::vector<T, Alloc> &container)
10410{
10411 return enqueueUnmapSVM(container);
10412}
10413
10414#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10415
10416#if CL_HPP_TARGET_OPENCL_VERSION >= 110
10417inline cl_int enqueueReadBufferRect(
10418 const Buffer& buffer,
10419 cl_bool blocking,
10420 const array<size_type, 3>& buffer_offset,
10421 const array<size_type, 3>& host_offset,
10422 const array<size_type, 3>& region,
10423 size_type buffer_row_pitch,
10424 size_type buffer_slice_pitch,
10425 size_type host_row_pitch,
10426 size_type host_slice_pitch,
10427 void *ptr,
10428 const vector<Event>* events = nullptr,
10429 Event* event = nullptr)
10430{
10431 cl_int error;
10432 CommandQueue queue = CommandQueue::getDefault(&error);
10433
10434 if (error != CL_SUCCESS) {
10435 return error;
10436 }
10437
10438 return queue.enqueueReadBufferRect(
10439 buffer,
10440 blocking,
10441 buffer_offset,
10442 host_offset,
10443 region,
10444 buffer_row_pitch,
10445 buffer_slice_pitch,
10446 host_row_pitch,
10447 host_slice_pitch,
10448 ptr,
10449 events,
10450 event);
10451}
10452
10453inline cl_int enqueueReadBufferRect(
10454 const Buffer& buffer,
10455 cl_bool blocking,
10456 const array<size_type, 2>& buffer_offset,
10457 const array<size_type, 2>& host_offset,
10458 const array<size_type, 2>& region,
10459 size_type buffer_row_pitch,
10460 size_type buffer_slice_pitch,
10461 size_type host_row_pitch,
10462 size_type host_slice_pitch,
10463 void* ptr,
10464 const vector<Event>* events = nullptr,
10465 Event* event = nullptr)
10466{
10467 return enqueueReadBufferRect(
10468 buffer,
10469 blocking,
10470 { buffer_offset[0], buffer_offset[1], 0 },
10471 { host_offset[0], host_offset[1], 0 },
10472 { region[0], region[1], 1 },
10473 buffer_row_pitch,
10474 buffer_slice_pitch,
10475 host_row_pitch,
10476 host_slice_pitch,
10477 ptr,
10478 events,
10479 event);
10480}
10481
10482inline cl_int enqueueWriteBufferRect(
10483 const Buffer& buffer,
10484 cl_bool blocking,
10485 const array<size_type, 3>& buffer_offset,
10486 const array<size_type, 3>& host_offset,
10487 const array<size_type, 3>& region,
10488 size_type buffer_row_pitch,
10489 size_type buffer_slice_pitch,
10490 size_type host_row_pitch,
10491 size_type host_slice_pitch,
10492 const void *ptr,
10493 const vector<Event>* events = nullptr,
10494 Event* event = nullptr)
10495{
10496 cl_int error;
10497 CommandQueue queue = CommandQueue::getDefault(&error);
10498
10499 if (error != CL_SUCCESS) {
10500 return error;
10501 }
10502
10503 return queue.enqueueWriteBufferRect(
10504 buffer,
10505 blocking,
10506 buffer_offset,
10507 host_offset,
10508 region,
10509 buffer_row_pitch,
10510 buffer_slice_pitch,
10511 host_row_pitch,
10512 host_slice_pitch,
10513 ptr,
10514 events,
10515 event);
10516}
10517
10518inline cl_int enqueueWriteBufferRect(
10519 const Buffer& buffer,
10520 cl_bool blocking,
10521 const array<size_type, 2>& buffer_offset,
10522 const array<size_type, 2>& host_offset,
10523 const array<size_type, 2>& region,
10524 size_type buffer_row_pitch,
10525 size_type buffer_slice_pitch,
10526 size_type host_row_pitch,
10527 size_type host_slice_pitch,
10528 const void* ptr,
10529 const vector<Event>* events = nullptr,
10530 Event* event = nullptr)
10531{
10532 return enqueueWriteBufferRect(
10533 buffer,
10534 blocking,
10535 { buffer_offset[0], buffer_offset[1], 0 },
10536 { host_offset[0], host_offset[1], 0 },
10537 { region[0], region[1], 1 },
10538 buffer_row_pitch,
10539 buffer_slice_pitch,
10540 host_row_pitch,
10541 host_slice_pitch,
10542 ptr,
10543 events,
10544 event);
10545}
10546
10547inline cl_int enqueueCopyBufferRect(
10548 const Buffer& src,
10549 const Buffer& dst,
10550 const array<size_type, 3>& src_origin,
10551 const array<size_type, 3>& dst_origin,
10552 const array<size_type, 3>& region,
10553 size_type src_row_pitch,
10554 size_type src_slice_pitch,
10555 size_type dst_row_pitch,
10556 size_type dst_slice_pitch,
10557 const vector<Event>* events = nullptr,
10558 Event* event = nullptr)
10559{
10560 cl_int error;
10561 CommandQueue queue = CommandQueue::getDefault(&error);
10562
10563 if (error != CL_SUCCESS) {
10564 return error;
10565 }
10566
10567 return queue.enqueueCopyBufferRect(
10568 src,
10569 dst,
10570 src_origin,
10571 dst_origin,
10572 region,
10573 src_row_pitch,
10574 src_slice_pitch,
10575 dst_row_pitch,
10576 dst_slice_pitch,
10577 events,
10578 event);
10579}
10580
10581inline cl_int enqueueCopyBufferRect(
10582 const Buffer& src,
10583 const Buffer& dst,
10584 const array<size_type, 2>& src_origin,
10585 const array<size_type, 2>& dst_origin,
10586 const array<size_type, 2>& region,
10587 size_type src_row_pitch,
10588 size_type src_slice_pitch,
10589 size_type dst_row_pitch,
10590 size_type dst_slice_pitch,
10591 const vector<Event>* events = nullptr,
10592 Event* event = nullptr)
10593{
10594 return enqueueCopyBufferRect(
10595 src,
10596 dst,
10597 { src_origin[0], src_origin[1], 0 },
10598 { dst_origin[0], dst_origin[1], 0 },
10599 { region[0], region[1], 1 },
10600 src_row_pitch,
10601 src_slice_pitch,
10602 dst_row_pitch,
10603 dst_slice_pitch,
10604 events,
10605 event);
10606}
10607#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
10608
10609inline cl_int enqueueReadImage(
10610 const Image& image,
10611 cl_bool blocking,
10612 const array<size_type, 3>& origin,
10613 const array<size_type, 3>& region,
10614 size_type row_pitch,
10615 size_type slice_pitch,
10616 void* ptr,
10617 const vector<Event>* events = nullptr,
10618 Event* event = nullptr)
10619{
10620 cl_int error;
10621 CommandQueue queue = CommandQueue::getDefault(&error);
10622
10623 if (error != CL_SUCCESS) {
10624 return error;
10625 }
10626
10627 return queue.enqueueReadImage(
10628 image,
10629 blocking,
10630 origin,
10631 region,
10632 row_pitch,
10633 slice_pitch,
10634 ptr,
10635 events,
10636 event);
10637}
10638
10639inline cl_int enqueueReadImage(
10640 const Image& image,
10641 cl_bool blocking,
10642 const array<size_type, 2>& origin,
10643 const array<size_type, 2>& region,
10644 size_type row_pitch,
10645 size_type slice_pitch,
10646 void* ptr,
10647 const vector<Event>* events = nullptr,
10648 Event* event = nullptr)
10649{
10650 return enqueueReadImage(
10651 image,
10652 blocking,
10653 { origin[0], origin[1], 0 },
10654 { region[0], region[1], 1 },
10655 row_pitch,
10656 slice_pitch,
10657 ptr,
10658 events,
10659 event);
10660}
10661
10662inline cl_int enqueueWriteImage(
10663 const Image& image,
10664 cl_bool blocking,
10665 const array<size_type, 3>& origin,
10666 const array<size_type, 3>& region,
10667 size_type row_pitch,
10668 size_type slice_pitch,
10669 const void* ptr,
10670 const vector<Event>* events = nullptr,
10671 Event* event = nullptr)
10672{
10673 cl_int error;
10674 CommandQueue queue = CommandQueue::getDefault(&error);
10675
10676 if (error != CL_SUCCESS) {
10677 return error;
10678 }
10679
10680 return queue.enqueueWriteImage(
10681 image,
10682 blocking,
10683 origin,
10684 region,
10685 row_pitch,
10686 slice_pitch,
10687 ptr,
10688 events,
10689 event);
10690}
10691
10692inline cl_int enqueueWriteImage(
10693 const Image& image,
10694 cl_bool blocking,
10695 const array<size_type, 2>& origin,
10696 const array<size_type, 2>& region,
10697 size_type row_pitch,
10698 size_type slice_pitch,
10699 const void* ptr,
10700 const vector<Event>* events = nullptr,
10701 Event* event = nullptr)
10702{
10703 return enqueueWriteImage(
10704 image,
10705 blocking,
10706 { origin[0], origin[1], 0 },
10707 { region[0], region[1], 1 },
10708 row_pitch,
10709 slice_pitch,
10710 ptr,
10711 events,
10712 event);
10713}
10714
10715inline cl_int enqueueCopyImage(
10716 const Image& src,
10717 const Image& dst,
10718 const array<size_type, 3>& src_origin,
10719 const array<size_type, 3>& dst_origin,
10720 const array<size_type, 3>& region,
10721 const vector<Event>* events = nullptr,
10722 Event* event = nullptr)
10723{
10724 cl_int error;
10725 CommandQueue queue = CommandQueue::getDefault(&error);
10726
10727 if (error != CL_SUCCESS) {
10728 return error;
10729 }
10730
10731 return queue.enqueueCopyImage(
10732 src,
10733 dst,
10734 src_origin,
10735 dst_origin,
10736 region,
10737 events,
10738 event);
10739}
10740
10741inline cl_int enqueueCopyImage(
10742 const Image& src,
10743 const Image& dst,
10744 const array<size_type, 2>& src_origin,
10745 const array<size_type, 2>& dst_origin,
10746 const array<size_type, 2>& region,
10747 const vector<Event>* events = nullptr,
10748 Event* event = nullptr)
10749{
10750 return enqueueCopyImage(
10751 src,
10752 dst,
10753 { src_origin[0], src_origin[1], 0 },
10754 { dst_origin[0], dst_origin[1], 0 },
10755 { region[0], region[1], 1 },
10756 events,
10757 event);
10758}
10759
10760inline cl_int enqueueCopyImageToBuffer(
10761 const Image& src,
10762 const Buffer& dst,
10763 const array<size_type, 3>& src_origin,
10764 const array<size_type, 3>& region,
10765 size_type dst_offset,
10766 const vector<Event>* events = nullptr,
10767 Event* event = nullptr)
10768{
10769 cl_int error;
10770 CommandQueue queue = CommandQueue::getDefault(&error);
10771
10772 if (error != CL_SUCCESS) {
10773 return error;
10774 }
10775
10776 return queue.enqueueCopyImageToBuffer(
10777 src,
10778 dst,
10779 src_origin,
10780 region,
10781 dst_offset,
10782 events,
10783 event);
10784}
10785
10786inline cl_int enqueueCopyImageToBuffer(
10787 const Image& src,
10788 const Buffer& dst,
10789 const array<size_type, 2>& src_origin,
10790 const array<size_type, 2>& region,
10791 size_type dst_offset,
10792 const vector<Event>* events = nullptr,
10793 Event* event = nullptr)
10794{
10795 return enqueueCopyImageToBuffer(
10796 src,
10797 dst,
10798 { src_origin[0], src_origin[1], 0 },
10799 { region[0], region[1], 1 },
10800 dst_offset,
10801 events,
10802 event);
10803}
10804
10805inline cl_int enqueueCopyBufferToImage(
10806 const Buffer& src,
10807 const Image& dst,
10808 size_type src_offset,
10809 const array<size_type, 3>& dst_origin,
10810 const array<size_type, 3>& region,
10811 const vector<Event>* events = nullptr,
10812 Event* event = nullptr)
10813{
10814 cl_int error;
10815 CommandQueue queue = CommandQueue::getDefault(&error);
10816
10817 if (error != CL_SUCCESS) {
10818 return error;
10819 }
10820
10821 return queue.enqueueCopyBufferToImage(
10822 src,
10823 dst,
10824 src_offset,
10825 dst_origin,
10826 region,
10827 events,
10828 event);
10829}
10830
10831inline cl_int enqueueCopyBufferToImage(
10832 const Buffer& src,
10833 const Image& dst,
10834 size_type src_offset,
10835 const array<size_type, 2>& dst_origin,
10836 const array<size_type, 2>& region,
10837 const vector<Event>* events = nullptr,
10838 Event* event = nullptr)
10839{
10840 cl_int error;
10841 CommandQueue queue = CommandQueue::getDefault(&error);
10842
10843 if (error != CL_SUCCESS) {
10844 return error;
10845 }
10846
10847 return enqueueCopyBufferToImage(
10848 src,
10849 dst,
10850 src_offset,
10851 { dst_origin[0], dst_origin[1], 0 },
10852 { region[0], region[1], 1 },
10853 events,
10854 event);
10855}
10856
10857inline cl_int flush(void)
10858{
10859 cl_int error;
10860 CommandQueue queue = CommandQueue::getDefault(&error);
10861
10862 if (error != CL_SUCCESS) {
10863 return error;
10864 }
10865
10866 return queue.flush();
10867}
10868
10869inline cl_int finish(void)
10870{
10871 cl_int error;
10872 CommandQueue queue = CommandQueue::getDefault(&error);
10873
10874 if (error != CL_SUCCESS) {
10875 return error;
10876 }
10877
10878
10879 return queue.finish();
10880}
10881
10882class EnqueueArgs
10883{
10884private:
10885 CommandQueue queue_;
10886 const NDRange offset_;
10887 const NDRange global_;
10888 const NDRange local_;
10889 vector<Event> events_;
10890
10891 template<typename... Ts>
10892 friend class KernelFunctor;
10893
10894public:
10895 EnqueueArgs(NDRange global) :
10896 queue_(CommandQueue::getDefault()),
10897 offset_(NullRange),
10898 global_(global),
10899 local_(NullRange)
10900 {
10901
10902 }
10903
10904 EnqueueArgs(NDRange global, NDRange local) :
10905 queue_(CommandQueue::getDefault()),
10906 offset_(NullRange),
10907 global_(global),
10908 local_(local)
10909 {
10910
10911 }
10912
10913 EnqueueArgs(NDRange offset, NDRange global, NDRange local) :
10914 queue_(CommandQueue::getDefault()),
10915 offset_(offset),
10916 global_(global),
10917 local_(local)
10918 {
10919
10920 }
10921
10922 EnqueueArgs(Event e, NDRange global) :
10923 queue_(CommandQueue::getDefault()),
10924 offset_(NullRange),
10925 global_(global),
10926 local_(NullRange)
10927 {
10928 events_.push_back(e);
10929 }
10930
10931 EnqueueArgs(Event e, NDRange global, NDRange local) :
10932 queue_(CommandQueue::getDefault()),
10933 offset_(NullRange),
10934 global_(global),
10935 local_(local)
10936 {
10937 events_.push_back(e);
10938 }
10939
10940 EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) :
10941 queue_(CommandQueue::getDefault()),
10942 offset_(offset),
10943 global_(global),
10944 local_(local)
10945 {
10946 events_.push_back(e);
10947 }
10948
10949 EnqueueArgs(const vector<Event> &events, NDRange global) :
10950 queue_(CommandQueue::getDefault()),
10951 offset_(NullRange),
10952 global_(global),
10953 local_(NullRange),
10954 events_(events)
10955 {
10956
10957 }
10958
10959 EnqueueArgs(const vector<Event> &events, NDRange global, NDRange local) :
10960 queue_(CommandQueue::getDefault()),
10961 offset_(NullRange),
10962 global_(global),
10963 local_(local),
10964 events_(events)
10965 {
10966
10967 }
10968
10969 EnqueueArgs(const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
10970 queue_(CommandQueue::getDefault()),
10971 offset_(offset),
10972 global_(global),
10973 local_(local),
10974 events_(events)
10975 {
10976
10977 }
10978
10979 EnqueueArgs(CommandQueue &queue, NDRange global) :
10980 queue_(queue),
10981 offset_(NullRange),
10982 global_(global),
10983 local_(NullRange)
10984 {
10985
10986 }
10987
10988 EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) :
10989 queue_(queue),
10990 offset_(NullRange),
10991 global_(global),
10992 local_(local)
10993 {
10994
10995 }
10996
10997 EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) :
10998 queue_(queue),
10999 offset_(offset),
11000 global_(global),
11001 local_(local)
11002 {
11003
11004 }
11005
11006 EnqueueArgs(CommandQueue &queue, Event e, NDRange global) :
11007 queue_(queue),
11008 offset_(NullRange),
11009 global_(global),
11010 local_(NullRange)
11011 {
11012 events_.push_back(e);
11013 }
11014
11015 EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) :
11016 queue_(queue),
11017 offset_(NullRange),
11018 global_(global),
11019 local_(local)
11020 {
11021 events_.push_back(e);
11022 }
11023
11024 EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) :
11025 queue_(queue),
11026 offset_(offset),
11027 global_(global),
11028 local_(local)
11029 {
11030 events_.push_back(e);
11031 }
11032
11033 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global) :
11034 queue_(queue),
11035 offset_(NullRange),
11036 global_(global),
11037 local_(NullRange),
11038 events_(events)
11039 {
11040
11041 }
11042
11043 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global, NDRange local) :
11044 queue_(queue),
11045 offset_(NullRange),
11046 global_(global),
11047 local_(local),
11048 events_(events)
11049 {
11050
11051 }
11052
11053 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
11054 queue_(queue),
11055 offset_(offset),
11056 global_(global),
11057 local_(local),
11058 events_(events)
11059 {
11060
11061 }
11062};
11063
11064
11065//----------------------------------------------------------------------------------------------
11066
11067
11072template<typename... Ts>
11073class KernelFunctor
11074{
11075private:
11076 Kernel kernel_;
11077
11078 template<int index, typename T0, typename... T1s>
11079 void setArgs(T0&& t0, T1s&&... t1s)
11080 {
11081 kernel_.setArg(index, t0);
11082 setArgs<index + 1, T1s...>(std::forward<T1s>(t1s)...);
11083 }
11084
11085 template<int index, typename T0>
11086 void setArgs(T0&& t0)
11087 {
11088 kernel_.setArg(index, t0);
11089 }
11090
11091 template<int index>
11092 void setArgs()
11093 {
11094 }
11095
11096
11097public:
11098 KernelFunctor(Kernel kernel) : kernel_(kernel)
11099 {}
11100
11101 KernelFunctor(
11102 const Program& program,
11103 const string name,
11104 cl_int * err = nullptr) :
11105 kernel_(program, name.c_str(), err)
11106 {}
11107
11109 typedef Event result_type;
11110
11116 Event operator() (
11117 const EnqueueArgs& args,
11118 Ts... ts)
11119 {
11120 Event event;
11121 setArgs<0>(std::forward<Ts>(ts)...);
11122
11123 args.queue_.enqueueNDRangeKernel(
11124 kernel_,
11125 args.offset_,
11126 args.global_,
11127 args.local_,
11128 &args.events_,
11129 &event);
11130
11131 return event;
11132 }
11133
11140 Event operator() (
11141 const EnqueueArgs& args,
11142 Ts... ts,
11143 cl_int &error)
11144 {
11145 Event event;
11146 setArgs<0>(std::forward<Ts>(ts)...);
11147
11148 error = args.queue_.enqueueNDRangeKernel(
11149 kernel_,
11150 args.offset_,
11151 args.global_,
11152 args.local_,
11153 &args.events_,
11154 &event);
11155
11156 return event;
11157 }
11158
11159#if CL_HPP_TARGET_OPENCL_VERSION >= 200
11160 cl_int setSVMPointers(const vector<void*> &pointerList)
11161 {
11162 return kernel_.setSVMPointers(pointerList);
11163 }
11164
11165 template<typename T0, typename... T1s>
11166 cl_int setSVMPointers(const T0 &t0, T1s &... ts)
11167 {
11168 return kernel_.setSVMPointers(t0, ts...);
11169 }
11170#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
11171
11172 Kernel getKernel()
11173 {
11174 return kernel_;
11175 }
11176};
11177
11178namespace compatibility {
11183 template<typename... Ts>
11184 struct make_kernel
11185 {
11186 typedef KernelFunctor<Ts...> FunctorType;
11187
11188 FunctorType functor_;
11189
11190 make_kernel(
11191 const Program& program,
11192 const string name,
11193 cl_int * err = nullptr) :
11194 functor_(FunctorType(program, name, err))
11195 {}
11196
11197 make_kernel(
11198 const Kernel kernel) :
11199 functor_(FunctorType(kernel))
11200 {}
11201
11203 typedef Event result_type;
11204
11206 typedef Event type_(
11207 const EnqueueArgs&,
11208 Ts...);
11209
11210 Event operator()(
11211 const EnqueueArgs& enqueueArgs,
11212 Ts... args)
11213 {
11214 return functor_(
11215 enqueueArgs, args...);
11216 }
11217 };
11218} // namespace compatibility
11219
11220#ifdef cl_khr_semaphore
11221
11222#ifdef cl_khr_external_semaphore
11223enum ExternalSemaphoreType : cl_external_semaphore_handle_type_khr
11224{
11225 None = 0,
11226#ifdef cl_khr_external_semaphore_opaque_fd
11227 OpaqueFd = CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR,
11228#endif // cl_khr_external_semaphore_opaque_fd
11229#ifdef cl_khr_external_semaphore_sync_fd
11230 SyncFd = CL_SEMAPHORE_HANDLE_SYNC_FD_KHR,
11231#endif // cl_khr_external_semaphore_sync_fd
11232#ifdef cl_khr_external_semaphore_win32
11233 OpaqueWin32 = CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR,
11234 OpaqueWin32Kmt = CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KMT_KHR,
11235#endif // cl_khr_external_semaphore_win32
11236};
11237#endif // cl_khr_external_semaphore
11238
11239class Semaphore : public detail::Wrapper<cl_semaphore_khr>
11240{
11241public:
11242 Semaphore() : detail::Wrapper<cl_type>() {}
11243 Semaphore(
11244 const Context &context,
11245 const vector<cl_semaphore_properties_khr>& sema_props,
11246 cl_int *err = nullptr)
11247 {
11248 /* initialization of addresses to extension functions (it is done only once) */
11249 std::call_once(ext_init_, initExtensions, context);
11250
11251 cl_int error = CL_INVALID_OPERATION;
11252
11253 if (pfn_clCreateSemaphoreWithPropertiesKHR)
11254 {
11255 object_ = pfn_clCreateSemaphoreWithPropertiesKHR(
11256 context(),
11257 sema_props.data(),
11258 &error);
11259 }
11260
11261 detail::errHandler(error, __CREATE_SEMAPHORE_KHR_WITH_PROPERTIES_ERR);
11262
11263 if (err != nullptr) {
11264 *err = error;
11265 }
11266 }
11267 Semaphore(
11268 const vector<cl_semaphore_properties_khr>& sema_props,
11269 cl_int* err = nullptr):Semaphore(Context::getDefault(err), sema_props, err) {}
11270
11271 explicit Semaphore(const cl_semaphore_khr& semaphore, bool retainObject = false) :
11272 detail::Wrapper<cl_type>(semaphore, retainObject) {}
11273 Semaphore& operator = (const cl_semaphore_khr& rhs) {
11274 detail::Wrapper<cl_type>::operator=(rhs);
11275 return *this;
11276 }
11277 template <typename T>
11278 cl_int getInfo(cl_semaphore_info_khr name, T* param) const
11279 {
11280 if (pfn_clGetSemaphoreInfoKHR == nullptr) {
11281 return detail::errHandler(CL_INVALID_OPERATION,
11282 __GET_SEMAPHORE_KHR_INFO_ERR);
11283 }
11284
11285 return detail::errHandler(
11286 detail::getInfo(pfn_clGetSemaphoreInfoKHR, object_, name, param),
11287 __GET_SEMAPHORE_KHR_INFO_ERR);
11288 }
11289 template <cl_semaphore_info_khr name> typename
11290 detail::param_traits<detail::cl_semaphore_info_khr, name>::param_type
11291 getInfo(cl_int* err = nullptr) const
11292 {
11293 typename detail::param_traits<
11294 detail::cl_semaphore_info_khr, name>::param_type param;
11295 cl_int result = getInfo(name, &param);
11296 if (err != nullptr) {
11297 *err = result;
11298 }
11299 return param;
11300 }
11301
11302#ifdef cl_khr_external_semaphore
11303 template <typename T>
11304 cl_int getHandleForTypeKHR(
11305 const Device& device, cl_external_semaphore_handle_type_khr name, T* param) const
11306 {
11307 if (pfn_clGetSemaphoreHandleForTypeKHR == nullptr) {
11308 return detail::errHandler(CL_INVALID_OPERATION,
11309 __GET_SEMAPHORE_HANDLE_FOR_TYPE_KHR_ERR);
11310 }
11311
11312 return detail::errHandler(
11313 detail::getInfo(
11314 pfn_clGetSemaphoreHandleForTypeKHR, object_, device(), name, param),
11315 __GET_SEMAPHORE_HANDLE_FOR_TYPE_KHR_ERR);
11316 }
11317
11318 template <cl_external_semaphore_handle_type_khr type> typename
11319 detail::param_traits<detail::cl_external_semaphore_handle_type_khr, type>::param_type
11320 getHandleForTypeKHR(const Device& device, cl_int* err = nullptr) const
11321 {
11322 typename detail::param_traits<
11323 detail::cl_external_semaphore_handle_type_khr, type>::param_type param;
11324 cl_int result = getHandleForTypeKHR(device, type, &param);
11325 if (err != nullptr) {
11326 *err = result;
11327 }
11328 return param;
11329 }
11330#endif // cl_khr_external_semaphore
11331
11332 cl_int retain()
11333 {
11334 if (pfn_clRetainSemaphoreKHR == nullptr) {
11335 return detail::errHandler(CL_INVALID_OPERATION,
11336 __RETAIN_SEMAPHORE_KHR_ERR);
11337 }
11338 return pfn_clRetainSemaphoreKHR(object_);
11339 }
11340
11341 cl_int release()
11342 {
11343 if (pfn_clReleaseSemaphoreKHR == nullptr) {
11344 return detail::errHandler(CL_INVALID_OPERATION,
11345 __RELEASE_SEMAPHORE_KHR_ERR);
11346 }
11347 return pfn_clReleaseSemaphoreKHR(object_);
11348 }
11349
11350private:
11351 static std::once_flag ext_init_;
11352
11353 static void initExtensions(const Context& context)
11354 {
11355#if CL_HPP_TARGET_OPENCL_VERSION >= 120
11356 Device device = context.getInfo<CL_CONTEXT_DEVICES>().at(0);
11357 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>()();
11358 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateSemaphoreWithPropertiesKHR);
11359 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clReleaseSemaphoreKHR);
11360 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clRetainSemaphoreKHR);
11361 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueWaitSemaphoresKHR);
11362 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueSignalSemaphoresKHR);
11363 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clGetSemaphoreInfoKHR);
11364#ifdef cl_khr_external_semaphore
11365 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clGetSemaphoreHandleForTypeKHR);
11366#endif // cl_khr_external_semaphore
11367
11368#else
11369 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSemaphoreWithPropertiesKHR);
11370 CL_HPP_INIT_CL_EXT_FCN_PTR_(clReleaseSemaphoreKHR);
11371 CL_HPP_INIT_CL_EXT_FCN_PTR_(clRetainSemaphoreKHR);
11372 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueWaitSemaphoresKHR);
11373 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueSignalSemaphoresKHR);
11374 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetSemaphoreInfoKHR);
11375#ifdef cl_khr_external_semaphore
11376 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetSemaphoreHandleForTypeKHR);
11377#endif // cl_khr_external_semaphore
11378
11379#endif
11380 if ((pfn_clCreateSemaphoreWithPropertiesKHR == nullptr) &&
11381 (pfn_clReleaseSemaphoreKHR == nullptr) &&
11382 (pfn_clRetainSemaphoreKHR == nullptr) &&
11383 (pfn_clEnqueueWaitSemaphoresKHR == nullptr) &&
11384 (pfn_clEnqueueSignalSemaphoresKHR == nullptr) &&
11385#ifdef cl_khr_external_semaphore
11386 (pfn_clGetSemaphoreHandleForTypeKHR == nullptr) &&
11387#endif // cl_khr_external_semaphore
11388 (pfn_clGetSemaphoreInfoKHR == nullptr))
11389 {
11390 detail::errHandler(CL_INVALID_VALUE, __CREATE_SEMAPHORE_KHR_WITH_PROPERTIES_ERR);
11391 }
11392 }
11393
11394};
11395
11396CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Semaphore::ext_init_;
11397
11398inline cl_int CommandQueue::enqueueWaitSemaphores(
11399 const vector<Semaphore> &sema_objects,
11400 const vector<cl_semaphore_payload_khr> &sema_payloads,
11401 const vector<Event>* events_wait_list,
11402 Event *event) const
11403{
11404 cl_event tmp;
11405 cl_int err = CL_INVALID_OPERATION;
11406
11407 if (pfn_clEnqueueWaitSemaphoresKHR != nullptr) {
11408 err = pfn_clEnqueueWaitSemaphoresKHR(
11409 object_,
11410 (cl_uint)sema_objects.size(),
11411 (const cl_semaphore_khr *) &sema_objects.front(),
11412 (sema_payloads.size() > 0) ? &sema_payloads.front() : nullptr,
11413 (events_wait_list != nullptr) ? (cl_uint) events_wait_list->size() : 0,
11414 (events_wait_list != nullptr && events_wait_list->size() > 0) ? (cl_event*) &events_wait_list->front() : nullptr,
11415 (event != nullptr) ? &tmp : nullptr);
11416 }
11417
11418 detail::errHandler(err, __ENQUEUE_WAIT_SEMAPHORE_KHR_ERR);
11419
11420 if (event != nullptr && err == CL_SUCCESS)
11421 *event = tmp;
11422
11423 return err;
11424}
11425
11426inline cl_int CommandQueue::enqueueSignalSemaphores(
11427 const vector<Semaphore> &sema_objects,
11428 const vector<cl_semaphore_payload_khr>& sema_payloads,
11429 const vector<Event>* events_wait_list,
11430 Event* event)
11431{
11432 cl_event tmp;
11433 cl_int err = CL_INVALID_OPERATION;
11434
11435 if (pfn_clEnqueueSignalSemaphoresKHR != nullptr) {
11436 err = pfn_clEnqueueSignalSemaphoresKHR(
11437 object_,
11438 (cl_uint)sema_objects.size(),
11439 (const cl_semaphore_khr*) &sema_objects.front(),
11440 (sema_payloads.size() > 0) ? &sema_payloads.front() : nullptr,
11441 (events_wait_list != nullptr) ? (cl_uint) events_wait_list->size() : 0,
11442 (events_wait_list != nullptr && events_wait_list->size() > 0) ? (cl_event*) &events_wait_list->front() : nullptr,
11443 (event != nullptr) ? &tmp : nullptr);
11444 }
11445
11446 detail::errHandler(err, __ENQUEUE_SIGNAL_SEMAPHORE_KHR_ERR);
11447
11448 if (event != nullptr && err == CL_SUCCESS)
11449 *event = tmp;
11450
11451 return err;
11452}
11453
11454#endif // cl_khr_semaphore
11455
11456#if defined(cl_khr_command_buffer)
11460class CommandBufferKhr : public detail::Wrapper<cl_command_buffer_khr>
11461{
11462public:
11464 CommandBufferKhr() : detail::Wrapper<cl_type>() { }
11465
11466 explicit CommandBufferKhr(const vector<CommandQueue> &queues,
11467 cl_command_buffer_properties_khr properties = 0,
11468 cl_int* errcode_ret = nullptr)
11469 {
11470 cl_command_buffer_properties_khr command_buffer_properties[] = {
11471 CL_COMMAND_BUFFER_FLAGS_KHR, properties, 0
11472 };
11473
11474 /* initialization of addresses to extension functions (it is done only once) */
11475 std::call_once(ext_init_, [&] { initExtensions(queues[0].getInfo<CL_QUEUE_DEVICE>()); });
11476 cl_int error = CL_INVALID_OPERATION;
11477
11478 static_assert(sizeof(cl::CommandQueue) == sizeof(cl_command_queue),
11479 "Size of cl::CommandQueue must be equal to size of cl_command_queue");
11480
11481 if (pfn_clCreateCommandBufferKHR)
11482 {
11483 object_ = pfn_clCreateCommandBufferKHR((cl_uint) queues.size(),
11484 (cl_command_queue *) &queues.front(),
11485 command_buffer_properties,
11486 &error);
11487 }
11488
11489 detail::errHandler(error, __CREATE_COMMAND_BUFFER_KHR_ERR);
11490 if (errcode_ret != nullptr) {
11491 *errcode_ret = error;
11492 }
11493 }
11494
11495 explicit CommandBufferKhr(const cl_command_buffer_khr& commandBufferKhr, bool retainObject = false) :
11496 detail::Wrapper<cl_type>(commandBufferKhr, retainObject) { }
11497
11498 CommandBufferKhr& operator=(const cl_command_buffer_khr& rhs)
11499 {
11500 detail::Wrapper<cl_type>::operator=(rhs);
11501 return *this;
11502 }
11503
11504 template <typename T>
11505 cl_int getInfo(cl_command_buffer_info_khr name, T* param) const
11506 {
11507 if (pfn_clGetCommandBufferInfoKHR == nullptr) {
11508 return detail::errHandler(CL_INVALID_OPERATION,
11509 __GET_COMMAND_BUFFER_INFO_KHR_ERR);
11510 }
11511 return detail::errHandler(
11512 detail::getInfo(pfn_clGetCommandBufferInfoKHR, object_, name, param),
11513 __GET_COMMAND_BUFFER_INFO_KHR_ERR);
11514 }
11515
11516 template <cl_command_buffer_info_khr name> typename
11517 detail::param_traits<detail::cl_command_buffer_info_khr, name>::param_type
11518 getInfo(cl_int* err = nullptr) const
11519 {
11520 typename detail::param_traits<
11521 detail::cl_command_buffer_info_khr, name>::param_type param;
11522 cl_int result = getInfo(name, &param);
11523 if (err != nullptr) {
11524 *err = result;
11525 }
11526 return param;
11527 }
11528
11529 cl_int finalizeCommandBuffer() const
11530 {
11531 return detail::errHandler(::clFinalizeCommandBufferKHR(object_), __FINALIZE_COMMAND_BUFFER_KHR_ERR);
11532 }
11533
11534 cl_int enqueueCommandBuffer(vector<CommandQueue> &queues,
11535 const vector<Event>* events = nullptr,
11536 Event* event = nullptr)
11537 {
11538 if (pfn_clEnqueueCommandBufferKHR == nullptr) {
11539 return detail::errHandler(CL_INVALID_OPERATION,
11540 __ENQUEUE_COMMAND_BUFFER_KHR_ERR);
11541 }
11542
11543 static_assert(sizeof(cl::CommandQueue) == sizeof(cl_command_queue),
11544 "Size of cl::CommandQueue must be equal to size of cl_command_queue");
11545
11546 return detail::errHandler(pfn_clEnqueueCommandBufferKHR((cl_uint) queues.size(),
11547 (cl_command_queue *) &queues.front(),
11548 object_,
11549 (events != nullptr) ? (cl_uint) events->size() : 0,
11550 (events != nullptr && events->size() > 0) ? (cl_event*) &events->front() : nullptr,
11551 (cl_event*) event),
11552 __ENQUEUE_COMMAND_BUFFER_KHR_ERR);
11553 }
11554
11555 cl_int commandBarrierWithWaitList(const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11556 cl_sync_point_khr* sync_point = nullptr,
11557 MutableCommandKhr* mutable_handle = nullptr,
11558 const CommandQueue* command_queue = nullptr)
11559 {
11560 if (pfn_clCommandBarrierWithWaitListKHR == nullptr) {
11561 return detail::errHandler(CL_INVALID_OPERATION,
11562 __COMMAND_BARRIER_WITH_WAIT_LIST_KHR_ERR);
11563 }
11564
11565 cl_sync_point_khr tmp_sync_point;
11566 cl_int error = detail::errHandler(
11567 pfn_clCommandBarrierWithWaitListKHR(object_,
11568 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11569#if CL_KHR_COMMAND_BUFFER_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 4)
11570 nullptr, // Properties
11571#endif
11572 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11573 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11574 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11575 (cl_mutable_command_khr*) mutable_handle),
11576 __COMMAND_BARRIER_WITH_WAIT_LIST_KHR_ERR);
11577
11578 if (sync_point != nullptr && error == CL_SUCCESS)
11579 *sync_point = tmp_sync_point;
11580
11581 return error;
11582 }
11583
11584 cl_int commandCopyBuffer(const Buffer& src,
11585 const Buffer& dst,
11586 size_type src_offset,
11587 size_type dst_offset,
11588 size_type size,
11589 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11590 cl_sync_point_khr* sync_point = nullptr,
11591 MutableCommandKhr* mutable_handle = nullptr,
11592 const CommandQueue* command_queue = nullptr)
11593 {
11594 if (pfn_clCommandCopyBufferKHR == nullptr) {
11595 return detail::errHandler(CL_INVALID_OPERATION,
11596 __COMMAND_COPY_BUFFER_KHR_ERR);
11597 }
11598
11599 cl_sync_point_khr tmp_sync_point;
11600 cl_int error = detail::errHandler(
11601 pfn_clCommandCopyBufferKHR(object_,
11602 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11603#if CL_KHR_COMMAND_BUFFER_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 4)
11604 nullptr, // Properties
11605#endif
11606 src(),
11607 dst(),
11608 src_offset,
11609 dst_offset,
11610 size,
11611 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11612 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11613 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11614 (cl_mutable_command_khr*) mutable_handle),
11615 __COMMAND_COPY_BUFFER_KHR_ERR);
11616
11617 if (sync_point != nullptr && error == CL_SUCCESS)
11618 *sync_point = tmp_sync_point;
11619
11620 return error;
11621 }
11622
11623 cl_int commandCopyBufferRect(const Buffer& src,
11624 const Buffer& dst,
11625 const array<size_type, 3>& src_origin,
11626 const array<size_type, 3>& dst_origin,
11627 const array<size_type, 3>& region,
11628 size_type src_row_pitch,
11629 size_type src_slice_pitch,
11630 size_type dst_row_pitch,
11631 size_type dst_slice_pitch,
11632 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11633 cl_sync_point_khr* sync_point = nullptr,
11634 MutableCommandKhr* mutable_handle = nullptr,
11635 const CommandQueue* command_queue = nullptr)
11636 {
11637 if (pfn_clCommandCopyBufferRectKHR == nullptr) {
11638 return detail::errHandler(CL_INVALID_OPERATION,
11639 __COMMAND_COPY_BUFFER_RECT_KHR_ERR);
11640 }
11641
11642 cl_sync_point_khr tmp_sync_point;
11643 cl_int error = detail::errHandler(
11644 pfn_clCommandCopyBufferRectKHR(object_,
11645 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11646#if CL_KHR_COMMAND_BUFFER_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 4)
11647 nullptr, // Properties
11648#endif
11649 src(),
11650 dst(),
11651 src_origin.data(),
11652 dst_origin.data(),
11653 region.data(),
11654 src_row_pitch,
11655 src_slice_pitch,
11656 dst_row_pitch,
11657 dst_slice_pitch,
11658 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11659 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11660 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11661 (cl_mutable_command_khr*) mutable_handle),
11662 __COMMAND_COPY_BUFFER_RECT_KHR_ERR);
11663
11664 if (sync_point != nullptr && error == CL_SUCCESS)
11665 *sync_point = tmp_sync_point;
11666
11667 return error;
11668 }
11669
11670 cl_int commandCopyBufferToImage(const Buffer& src,
11671 const Image& dst,
11672 size_type src_offset,
11673 const array<size_type, 3>& dst_origin,
11674 const array<size_type, 3>& region,
11675 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11676 cl_sync_point_khr* sync_point = nullptr,
11677 MutableCommandKhr* mutable_handle = nullptr,
11678 const CommandQueue* command_queue = nullptr)
11679 {
11680 if (pfn_clCommandCopyBufferToImageKHR == nullptr) {
11681 return detail::errHandler(CL_INVALID_OPERATION,
11682 __COMMAND_COPY_BUFFER_TO_IMAGE_KHR_ERR);
11683 }
11684
11685 cl_sync_point_khr tmp_sync_point;
11686 cl_int error = detail::errHandler(
11687 pfn_clCommandCopyBufferToImageKHR(object_,
11688 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11689#if CL_KHR_COMMAND_BUFFER_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 4)
11690 nullptr, // Properties
11691#endif
11692 src(),
11693 dst(),
11694 src_offset,
11695 dst_origin.data(),
11696 region.data(),
11697 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11698 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11699 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11700 (cl_mutable_command_khr*) mutable_handle),
11701 __COMMAND_COPY_BUFFER_TO_IMAGE_KHR_ERR);
11702
11703 if (sync_point != nullptr && error == CL_SUCCESS)
11704 *sync_point = tmp_sync_point;
11705
11706 return error;
11707 }
11708
11709 cl_int commandCopyImage(const Image& src,
11710 const Image& dst,
11711 const array<size_type, 3>& src_origin,
11712 const array<size_type, 3>& dst_origin,
11713 const array<size_type, 3>& region,
11714 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11715 cl_sync_point_khr* sync_point = nullptr,
11716 MutableCommandKhr* mutable_handle = nullptr,
11717 const CommandQueue* command_queue = nullptr)
11718 {
11719 if (pfn_clCommandCopyImageKHR == nullptr) {
11720 return detail::errHandler(CL_INVALID_OPERATION,
11721 __COMMAND_COPY_IMAGE_KHR_ERR);
11722 }
11723
11724 cl_sync_point_khr tmp_sync_point;
11725 cl_int error = detail::errHandler(
11726 pfn_clCommandCopyImageKHR(object_,
11727 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11728#if CL_KHR_COMMAND_BUFFER_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 4)
11729 nullptr, // Properties
11730#endif
11731 src(),
11732 dst(),
11733 src_origin.data(),
11734 dst_origin.data(),
11735 region.data(),
11736 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11737 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11738 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11739 (cl_mutable_command_khr*) mutable_handle),
11740 __COMMAND_COPY_IMAGE_KHR_ERR);
11741
11742 if (sync_point != nullptr && error == CL_SUCCESS)
11743 *sync_point = tmp_sync_point;
11744
11745 return error;
11746 }
11747
11748 cl_int commandCopyImageToBuffer(const Image& src,
11749 const Buffer& dst,
11750 const array<size_type, 3>& src_origin,
11751 const array<size_type, 3>& region,
11752 size_type dst_offset,
11753 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11754 cl_sync_point_khr* sync_point = nullptr,
11755 MutableCommandKhr* mutable_handle = nullptr,
11756 const CommandQueue* command_queue = nullptr)
11757 {
11758 if (pfn_clCommandCopyImageToBufferKHR == nullptr) {
11759 return detail::errHandler(CL_INVALID_OPERATION,
11760 __COMMAND_COPY_IMAGE_TO_BUFFER_KHR_ERR);
11761 }
11762
11763 cl_sync_point_khr tmp_sync_point;
11764 cl_int error = detail::errHandler(
11765 pfn_clCommandCopyImageToBufferKHR(object_,
11766 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11767#if CL_KHR_COMMAND_BUFFER_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 4)
11768 nullptr, // Properties
11769#endif
11770 src(),
11771 dst(),
11772 src_origin.data(),
11773 region.data(),
11774 dst_offset,
11775 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11776 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11777 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11778 (cl_mutable_command_khr*) mutable_handle),
11779 __COMMAND_COPY_IMAGE_TO_BUFFER_KHR_ERR);
11780
11781 if (sync_point != nullptr && error == CL_SUCCESS)
11782 *sync_point = tmp_sync_point;
11783
11784 return error;
11785 }
11786
11787 template<typename PatternType>
11788 cl_int commandFillBuffer(const Buffer& buffer,
11789 PatternType pattern,
11790 size_type offset,
11791 size_type size,
11792 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11793 cl_sync_point_khr* sync_point = nullptr,
11794 MutableCommandKhr* mutable_handle = nullptr,
11795 const CommandQueue* command_queue = nullptr)
11796 {
11797 if (pfn_clCommandFillBufferKHR == nullptr) {
11798 return detail::errHandler(CL_INVALID_OPERATION,
11799 __COMMAND_FILL_BUFFER_KHR_ERR);
11800 }
11801
11802 cl_sync_point_khr tmp_sync_point;
11803 cl_int error = detail::errHandler(
11804 pfn_clCommandFillBufferKHR(object_,
11805 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11806#if CL_KHR_COMMAND_BUFFER_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 4)
11807 nullptr, // Properties
11808#endif
11809 buffer(),
11810 static_cast<void*>(&pattern),
11811 sizeof(PatternType),
11812 offset,
11813 size,
11814 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11815 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11816 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11817 (cl_mutable_command_khr*) mutable_handle),
11818 __COMMAND_FILL_BUFFER_KHR_ERR);
11819
11820 if (sync_point != nullptr && error == CL_SUCCESS)
11821 *sync_point = tmp_sync_point;
11822
11823 return error;
11824 }
11825
11826 cl_int commandFillImage(const Image& image,
11827 cl_float4 fillColor,
11828 const array<size_type, 3>& origin,
11829 const array<size_type, 3>& region,
11830 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11831 cl_sync_point_khr* sync_point = nullptr,
11832 MutableCommandKhr* mutable_handle = nullptr,
11833 const CommandQueue* command_queue = nullptr)
11834 {
11835 if (pfn_clCommandFillImageKHR == nullptr) {
11836 return detail::errHandler(CL_INVALID_OPERATION,
11837 __COMMAND_FILL_IMAGE_KHR_ERR);
11838 }
11839
11840 cl_sync_point_khr tmp_sync_point;
11841 cl_int error = detail::errHandler(
11842 pfn_clCommandFillImageKHR(object_,
11843 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11844#if CL_KHR_COMMAND_BUFFER_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 4)
11845 nullptr, // Properties
11846#endif
11847 image(),
11848 static_cast<void*>(&fillColor),
11849 origin.data(),
11850 region.data(),
11851 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11852 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11853 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11854 (cl_mutable_command_khr*) mutable_handle),
11855 __COMMAND_FILL_IMAGE_KHR_ERR);
11856
11857 if (sync_point != nullptr && error == CL_SUCCESS)
11858 *sync_point = tmp_sync_point;
11859
11860 return error;
11861 }
11862
11863 cl_int commandNDRangeKernel(
11864#if CL_KHR_COMMAND_BUFFER_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 4)
11865 const cl::vector<cl_command_properties_khr> &properties,
11866#else
11867 const cl::vector<cl_ndrange_kernel_command_properties_khr> &properties,
11868#endif
11869 const Kernel& kernel,
11870 const NDRange& offset,
11871 const NDRange& global,
11872 const NDRange& local = NullRange,
11873 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11874 cl_sync_point_khr* sync_point = nullptr,
11875 MutableCommandKhr* mutable_handle = nullptr,
11876 const CommandQueue* command_queue = nullptr)
11877 {
11878 if (pfn_clCommandNDRangeKernelKHR == nullptr) {
11879 return detail::errHandler(CL_INVALID_OPERATION,
11880 __COMMAND_NDRANGE_KERNEL_KHR_ERR);
11881 }
11882
11883 cl_sync_point_khr tmp_sync_point;
11884 cl_int error = detail::errHandler(
11885 pfn_clCommandNDRangeKernelKHR(object_,
11886 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11887 &properties[0],
11888 kernel(),
11889 (cl_uint) global.dimensions(),
11890 offset.dimensions() != 0 ? (const size_type*) offset : nullptr,
11891 (const size_type*) global,
11892 local.dimensions() != 0 ? (const size_type*) local : nullptr,
11893 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11894 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11895 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11896 (cl_mutable_command_khr*) mutable_handle),
11897 __COMMAND_NDRANGE_KERNEL_KHR_ERR);
11898
11899 if (sync_point != nullptr && error == CL_SUCCESS)
11900 *sync_point = tmp_sync_point;
11901
11902 return error;
11903 }
11904
11905#if defined(cl_khr_command_buffer_mutable_dispatch)
11906#if CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION < \
11907 CL_MAKE_VERSION(0, 9, 2)
11908 cl_int updateMutableCommands(const cl_mutable_base_config_khr* mutable_config)
11909 {
11910 if (pfn_clUpdateMutableCommandsKHR == nullptr) {
11911 return detail::errHandler(CL_INVALID_OPERATION,
11912 __UPDATE_MUTABLE_COMMANDS_KHR_ERR);
11913 }
11914 return detail::errHandler(pfn_clUpdateMutableCommandsKHR(object_, mutable_config),
11915 __UPDATE_MUTABLE_COMMANDS_KHR_ERR);
11916 }
11917#else
11918 template <int ArrayLength>
11919 cl_int updateMutableCommands(std::array<cl_command_buffer_update_type_khr,
11920 ArrayLength> &config_types,
11921 std::array<const void *, ArrayLength> &configs) {
11922 if (pfn_clUpdateMutableCommandsKHR == nullptr) {
11923 return detail::errHandler(CL_INVALID_OPERATION,
11924 __UPDATE_MUTABLE_COMMANDS_KHR_ERR);
11925 }
11926 return detail::errHandler(
11927 pfn_clUpdateMutableCommandsKHR(object_, static_cast<cl_uint>(configs.size()),
11928 config_types.data(), configs.data()),
11929 __UPDATE_MUTABLE_COMMANDS_KHR_ERR);
11930 }
11931#endif /* CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION */
11932#endif /* cl_khr_command_buffer_mutable_dispatch */
11933
11934private:
11935 static std::once_flag ext_init_;
11936
11937 static void initExtensions(const cl::Device& device)
11938 {
11939#if CL_HPP_TARGET_OPENCL_VERSION >= 120
11940 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>()();
11941 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateCommandBufferKHR);
11942 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clFinalizeCommandBufferKHR);
11943 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clRetainCommandBufferKHR);
11944 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clReleaseCommandBufferKHR);
11945 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clGetCommandBufferInfoKHR);
11946 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueCommandBufferKHR);
11947 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandBarrierWithWaitListKHR);
11948 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandCopyBufferKHR);
11949 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandCopyBufferRectKHR);
11950 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandCopyBufferToImageKHR);
11951 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandCopyImageKHR);
11952 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandCopyImageToBufferKHR);
11953 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandFillBufferKHR);
11954 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandFillImageKHR);
11955 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandNDRangeKernelKHR);
11956#if defined(cl_khr_command_buffer_mutable_dispatch)
11957 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clUpdateMutableCommandsKHR);
11958 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clGetMutableCommandInfoKHR);
11959#endif /* cl_khr_command_buffer_mutable_dispatch */
11960#elif CL_HPP_TARGET_OPENCL_VERSION >= 110
11961 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateCommandBufferKHR);
11962 CL_HPP_INIT_CL_EXT_FCN_PTR_(clFinalizeCommandBufferKHR);
11963 CL_HPP_INIT_CL_EXT_FCN_PTR_(clRetainCommandBufferKHR);
11964 CL_HPP_INIT_CL_EXT_FCN_PTR_(clReleaseCommandBufferKHR);
11965 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetCommandBufferInfoKHR);
11966 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueCommandBufferKHR);
11967 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandBarrierWithWaitListKHR);
11968 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandCopyBufferKHR);
11969 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandCopyBufferRectKHR);
11970 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandCopyBufferToImageKHR);
11971 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandCopyImageKHR);
11972 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandCopyImageToBufferKHR);
11973 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandFillBufferKHR);
11974 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandFillImageKHR);
11975 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandNDRangeKernelKHR);
11976#if defined(cl_khr_command_buffer_mutable_dispatch)
11977 CL_HPP_INIT_CL_EXT_FCN_PTR_(clUpdateMutableCommandsKHR);
11978 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetMutableCommandInfoKHR);
11979#endif /* cl_khr_command_buffer_mutable_dispatch */
11980#endif
11981 if ((pfn_clCreateCommandBufferKHR == nullptr) &&
11982 (pfn_clFinalizeCommandBufferKHR == nullptr) &&
11983 (pfn_clRetainCommandBufferKHR == nullptr) &&
11984 (pfn_clReleaseCommandBufferKHR == nullptr) &&
11985 (pfn_clGetCommandBufferInfoKHR == nullptr) &&
11986 (pfn_clEnqueueCommandBufferKHR == nullptr) &&
11987 (pfn_clCommandBarrierWithWaitListKHR == nullptr) &&
11988 (pfn_clCommandCopyBufferKHR == nullptr) &&
11989 (pfn_clCommandCopyBufferRectKHR == nullptr) &&
11990 (pfn_clCommandCopyBufferToImageKHR == nullptr) &&
11991 (pfn_clCommandCopyImageKHR == nullptr) &&
11992 (pfn_clCommandCopyImageToBufferKHR == nullptr) &&
11993 (pfn_clCommandFillBufferKHR == nullptr) &&
11994 (pfn_clCommandFillImageKHR == nullptr) &&
11995 (pfn_clCommandNDRangeKernelKHR == nullptr)
11996#if defined(cl_khr_command_buffer_mutable_dispatch)
11997 && (pfn_clUpdateMutableCommandsKHR == nullptr)
11998 && (pfn_clGetMutableCommandInfoKHR == nullptr)
11999#endif /* cl_khr_command_buffer_mutable_dispatch */
12000 )
12001 {
12002 detail::errHandler(CL_INVALID_VALUE, __CREATE_COMMAND_BUFFER_KHR_ERR);
12003 }
12004 }
12005}; // CommandBufferKhr
12006
12007CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandBufferKhr::ext_init_;
12008
12009#if defined(cl_khr_command_buffer_mutable_dispatch)
12013class MutableCommandKhr : public detail::Wrapper<cl_mutable_command_khr>
12014{
12015public:
12017 MutableCommandKhr() : detail::Wrapper<cl_type>() { }
12018
12019 explicit MutableCommandKhr(const cl_mutable_command_khr& mutableCommandKhr, bool retainObject = false) :
12020 detail::Wrapper<cl_type>(mutableCommandKhr, retainObject) { }
12021
12022 MutableCommandKhr& operator=(const cl_mutable_command_khr& rhs)
12023 {
12024 detail::Wrapper<cl_type>::operator=(rhs);
12025 return *this;
12026 }
12027
12028 template <typename T>
12029 cl_int getInfo(cl_mutable_command_info_khr name, T* param) const
12030 {
12031 if (pfn_clGetMutableCommandInfoKHR == nullptr) {
12032 return detail::errHandler(CL_INVALID_OPERATION,
12033 __GET_MUTABLE_COMMAND_INFO_KHR_ERR);
12034 }
12035 return detail::errHandler(
12036 detail::getInfo(pfn_clGetMutableCommandInfoKHR, object_, name, param),
12037 __GET_MUTABLE_COMMAND_INFO_KHR_ERR);
12038 }
12039
12040 template <cl_mutable_command_info_khr name> typename
12041 detail::param_traits<detail::cl_mutable_command_info_khr, name>::param_type
12042 getInfo(cl_int* err = nullptr) const
12043 {
12044 typename detail::param_traits<
12045 detail::cl_mutable_command_info_khr, name>::param_type param;
12046 cl_int result = getInfo(name, &param);
12047 if (err != nullptr) {
12048 *err = result;
12049 }
12050 return param;
12051 }
12052}; // MutableCommandKhr
12053#endif /* cl_khr_command_buffer_mutable_dispatch */
12054
12055#endif // cl_khr_command_buffer
12056//----------------------------------------------------------------------------------------------------------------------
12057
12058#undef CL_HPP_ERR_STR_
12059#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
12060#undef __GET_DEVICE_INFO_ERR
12061#undef __GET_PLATFORM_INFO_ERR
12062#undef __GET_DEVICE_IDS_ERR
12063#undef __GET_PLATFORM_IDS_ERR
12064#undef __GET_CONTEXT_INFO_ERR
12065#undef __GET_EVENT_INFO_ERR
12066#undef __GET_EVENT_PROFILE_INFO_ERR
12067#undef __GET_MEM_OBJECT_INFO_ERR
12068#undef __GET_IMAGE_INFO_ERR
12069#undef __GET_SAMPLER_INFO_ERR
12070#undef __GET_KERNEL_INFO_ERR
12071#undef __GET_KERNEL_ARG_INFO_ERR
12072#undef __GET_KERNEL_SUB_GROUP_INFO_ERR
12073#undef __GET_KERNEL_WORK_GROUP_INFO_ERR
12074#undef __GET_PROGRAM_INFO_ERR
12075#undef __GET_PROGRAM_BUILD_INFO_ERR
12076#undef __GET_COMMAND_QUEUE_INFO_ERR
12077#undef __CREATE_CONTEXT_ERR
12078#undef __CREATE_CONTEXT_FROM_TYPE_ERR
12079#undef __CREATE_COMMAND_BUFFER_KHR_ERR
12080#undef __GET_COMMAND_BUFFER_INFO_KHR_ERR
12081#undef __FINALIZE_COMMAND_BUFFER_KHR_ERR
12082#undef __ENQUEUE_COMMAND_BUFFER_KHR_ERR
12083#undef __COMMAND_BARRIER_WITH_WAIT_LIST_KHR_ERR
12084#undef __COMMAND_COPY_BUFFER_KHR_ERR
12085#undef __COMMAND_COPY_BUFFER_RECT_KHR_ERR
12086#undef __COMMAND_COPY_BUFFER_TO_IMAGE_KHR_ERR
12087#undef __COMMAND_COPY_IMAGE_KHR_ERR
12088#undef __COMMAND_COPY_IMAGE_TO_BUFFER_KHR_ERR
12089#undef __COMMAND_FILL_BUFFER_KHR_ERR
12090#undef __COMMAND_FILL_IMAGE_KHR_ERR
12091#undef __COMMAND_NDRANGE_KERNEL_KHR_ERR
12092#undef __UPDATE_MUTABLE_COMMANDS_KHR_ERR
12093#undef __GET_MUTABLE_COMMAND_INFO_KHR_ERR
12094#undef __RETAIN_COMMAND_BUFFER_KHR_ERR
12095#undef __RELEASE_COMMAND_BUFFER_KHR_ERR
12096#undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
12097#undef __SET_CONTEXT_DESCTRUCTOR_CALLBACK_ERR
12098#undef __CREATE_BUFFER_ERR
12099#undef __COPY_ERR
12100#undef __CREATE_SUBBUFFER_ERR
12101#undef __CREATE_GL_BUFFER_ERR
12102#undef __CREATE_GL_RENDER_BUFFER_ERR
12103#undef __GET_GL_OBJECT_INFO_ERR
12104#undef __CREATE_IMAGE_ERR
12105#undef __CREATE_GL_TEXTURE_ERR
12106#undef __IMAGE_DIMENSION_ERR
12107#undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
12108#undef __CREATE_USER_EVENT_ERR
12109#undef __SET_USER_EVENT_STATUS_ERR
12110#undef __SET_EVENT_CALLBACK_ERR
12111#undef __WAIT_FOR_EVENTS_ERR
12112#undef __CREATE_KERNEL_ERR
12113#undef __SET_KERNEL_ARGS_ERR
12114#undef __CREATE_PROGRAM_WITH_SOURCE_ERR
12115#undef __CREATE_PROGRAM_WITH_BINARY_ERR
12116#undef __CREATE_PROGRAM_WITH_IL_ERR
12117#undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR
12118#undef __BUILD_PROGRAM_ERR
12119#undef __COMPILE_PROGRAM_ERR
12120#undef __LINK_PROGRAM_ERR
12121#undef __CREATE_KERNELS_IN_PROGRAM_ERR
12122#undef __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR
12123#undef __CREATE_SAMPLER_WITH_PROPERTIES_ERR
12124#undef __SET_COMMAND_QUEUE_PROPERTY_ERR
12125#undef __ENQUEUE_READ_BUFFER_ERR
12126#undef __ENQUEUE_READ_BUFFER_RECT_ERR
12127#undef __ENQUEUE_WRITE_BUFFER_ERR
12128#undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
12129#undef __ENQEUE_COPY_BUFFER_ERR
12130#undef __ENQEUE_COPY_BUFFER_RECT_ERR
12131#undef __ENQUEUE_FILL_BUFFER_ERR
12132#undef __ENQUEUE_READ_IMAGE_ERR
12133#undef __ENQUEUE_WRITE_IMAGE_ERR
12134#undef __ENQUEUE_COPY_IMAGE_ERR
12135#undef __ENQUEUE_FILL_IMAGE_ERR
12136#undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
12137#undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
12138#undef __ENQUEUE_MAP_BUFFER_ERR
12139#undef __ENQUEUE_MAP_IMAGE_ERR
12140#undef __ENQUEUE_MAP_SVM_ERR
12141#undef __ENQUEUE_FILL_SVM_ERR
12142#undef __ENQUEUE_COPY_SVM_ERR
12143#undef __ENQUEUE_UNMAP_SVM_ERR
12144#undef __ENQUEUE_MAP_IMAGE_ERR
12145#undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
12146#undef __ENQUEUE_NDRANGE_KERNEL_ERR
12147#undef __ENQUEUE_NATIVE_KERNEL
12148#undef __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR
12149#undef __ENQUEUE_MIGRATE_SVM_ERR
12150#undef __ENQUEUE_ACQUIRE_GL_ERR
12151#undef __ENQUEUE_RELEASE_GL_ERR
12152#undef __CREATE_PIPE_ERR
12153#undef __GET_PIPE_INFO_ERR
12154#undef __RETAIN_ERR
12155#undef __RELEASE_ERR
12156#undef __FLUSH_ERR
12157#undef __FINISH_ERR
12158#undef __VECTOR_CAPACITY_ERR
12159#undef __CREATE_SUB_DEVICES_ERR
12160#undef __ENQUEUE_ACQUIRE_EXTERNAL_MEMORY_ERR
12161#undef __ENQUEUE_RELEASE_EXTERNAL_MEMORY_ERR
12162#undef __ENQUEUE_MARKER_ERR
12163#undef __ENQUEUE_WAIT_FOR_EVENTS_ERR
12164#undef __ENQUEUE_BARRIER_ERR
12165#undef __UNLOAD_COMPILER_ERR
12166#undef __CREATE_GL_TEXTURE_2D_ERR
12167#undef __CREATE_GL_TEXTURE_3D_ERR
12168#undef __CREATE_IMAGE2D_ERR
12169#undef __CREATE_IMAGE3D_ERR
12170#undef __CREATE_COMMAND_QUEUE_ERR
12171#undef __ENQUEUE_TASK_ERR
12172#undef __CREATE_SAMPLER_ERR
12173#undef __ENQUEUE_MARKER_WAIT_LIST_ERR
12174#undef __ENQUEUE_BARRIER_WAIT_LIST_ERR
12175#undef __CLONE_KERNEL_ERR
12176#undef __GET_HOST_TIMER_ERR
12177#undef __GET_DEVICE_AND_HOST_TIMER_ERR
12178#undef __GET_SEMAPHORE_KHR_INFO_ERR
12179#undef __CREATE_SEMAPHORE_KHR_WITH_PROPERTIES_ERR
12180#undef __GET_IMAGE_REQUIREMENT_INFO_EXT_ERR
12181#undef __ENQUEUE_WAIT_SEMAPHORE_KHR_ERR
12182#undef __ENQUEUE_SIGNAL_SEMAPHORE_KHR_ERR
12183#undef __RETAIN_SEMAPHORE_KHR_ERR
12184#undef __RELEASE_SEMAPHORE_KHR_ERR
12185#undef __GET_SEMAPHORE_HANDLE_FOR_TYPE_KHR_ERR
12186
12187#endif //CL_HPP_USER_OVERRIDE_ERROR_STRINGS
12188
12189// Extensions
12190#undef CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_
12191#undef CL_HPP_INIT_CL_EXT_FCN_PTR_
12192#undef CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_
12193
12194#undef CL_HPP_DEFINE_STATIC_MEMBER_
12195
12196} // namespace cl
12197
12198#endif // CL_HPP_
cl::BufferGL::operator=
BufferGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4695
cl::BufferGL::BufferGL
BufferGL()
Default constructor - initializes to nullptr.
Definition opencl.hpp:4679
cl::BufferGL::getObjectInfo
cl_int getObjectInfo(cl_gl_object_type *type, cl_GLuint *gl_object_name)
Wrapper for clGetGLObjectInfo().
Definition opencl.hpp:4703
cl::Buffer
Class interface for Buffer Memory Objects.
Definition opencl.hpp:4340
cl::Buffer::Buffer
Buffer()
Default constructor - initializes to nullptr.
Definition opencl.hpp:4508
cl::Buffer::createSubBuffer
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:4536
cl::Buffer::operator=
Buffer & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4524
cl::BufferRenderGL::getObjectInfo
cl_int getObjectInfo(cl_gl_object_type *type, cl_GLuint *gl_object_name)
Wrapper for clGetGLObjectInfo().
Definition opencl.hpp:4773
cl::BufferRenderGL::BufferRenderGL
BufferRenderGL()
Default constructor - initializes to nullptr.
Definition opencl.hpp:4749
cl::BufferRenderGL::operator=
BufferRenderGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4765
cl::CommandQueue
CommandQueue interface for cl_command_queue.
Definition opencl.hpp:7542
cl::CommandQueue::enqueueUnmapSVM
cl_int enqueueUnmapSVM(T *ptr, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:9038
cl::CommandQueue::enqueueMemcpySVM
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:8778
cl::CommandQueue::enqueueMigrateMemObjects
cl_int enqueueMigrateMemObjects(const vector< Memory > &memObjects, cl_mem_migration_flags flags, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:9174
cl::CommandQueue::enqueueMarkerWithWaitList
cl_int enqueueMarkerWithWaitList(const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:9121
cl::CommandQueue::enqueueMarker
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int enqueueMarker(Event *event=nullptr) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition opencl.hpp:9408
cl::CommandQueue::setDefault
static CommandQueue setDefault(const CommandQueue &default_queue)
Definition opencl.hpp:8002
cl::CommandQueue::enqueueFillImage
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:8539
cl::CommandQueue::enqueueMapSVM
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:8933
cl::CommandQueue::enqueueMigrateSVM
cl_int enqueueMigrateSVM(const cl::vector< T * > &svmRawPointers, const cl::vector< size_type > &sizes, cl_mem_migration_flags flags=0, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:9215
cl::CommandQueue::enqueueMemFillSVM
cl_int enqueueMemFillSVM(T *ptr, PatternType pattern, size_type size, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:8858
cl::CommandQueue::enqueueBarrier
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int enqueueBarrier() const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition opencl.hpp:9561
cl::CommandQueue::enqueueBarrierWithWaitList
cl_int enqueueBarrierWithWaitList(const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:9151
cl::CommandQueue::enqueueFillBuffer
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:8337
cl::Context
Class interface for cl_context.
Definition opencl.hpp:3190
cl::Context::operator=
Context & operator=(const cl_context &rhs)
Assignment operator from cl_context - takes ownership.
Definition opencl.hpp:3498
cl::Context::setDestructorCallback
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:3622
cl::Context::setDefault
static Context setDefault(const Context &default_context)
Definition opencl.hpp:3475
cl::Context::getDefault
static Context getDefault(cl_int *err=nullptr)
Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT.
Definition opencl.hpp:3458
cl::Context::getSupportedImageFormats
cl_int getSupportedImageFormats(cl_mem_flags flags, cl_mem_object_type type, vector< ImageFormat > *formats) const
Gets a list of supported image formats.
Definition opencl.hpp:3531
cl::Context::Context
Context()
Default constructor - initializes to nullptr.
Definition opencl.hpp:3483
cl::Context::getInfo
cl_int getInfo(cl_context_info name, T *param) const
Wrapper for clGetContextInfo().
Definition opencl.hpp:3506
cl::DeviceCommandQueue
DeviceCommandQueue interface for device cl_command_queues.
Definition opencl.hpp:9679
cl::DeviceCommandQueue::updateDefault
static DeviceCommandQueue updateDefault(const Context &context, const Device &device, const DeviceCommandQueue &default_queue, cl_int *err=nullptr)
Definition opencl.hpp:9894
cl::DeviceCommandQueue::getDefault
static DeviceCommandQueue getDefault(const CommandQueue &queue, cl_int *err=nullptr)
Definition opencl.hpp:9909
cl::DeviceCommandQueue::DeviceCommandQueue
DeviceCommandQueue()
Definition opencl.hpp:9685
cl::DeviceCommandQueue::makeDefault
static DeviceCommandQueue makeDefault(cl_int *err=nullptr)
Definition opencl.hpp:9804
cl::Device
Class interface for cl_device_id.
Definition opencl.hpp:2471
cl::Device::getDefault
static Device getDefault(cl_int *errResult=nullptr)
Returns the first device on the default context.
Definition opencl.hpp:2520
cl::Device::operator=
Device & operator=(const cl_device_id &rhs)
Assignment operator from cl_device_id.
Definition opencl.hpp:2549
cl::Device::getInfo
cl_int getInfo(cl_device_info name, T *param) const
Wrapper for clGetDeviceInfo().
Definition opencl.hpp:2558
cl::Device::Device
Device()
Default constructor - initializes to nullptr.
Definition opencl.hpp:2507
cl::Device::getHostTimer
cl_ulong getHostTimer(cl_int *error=nullptr)
Definition opencl.hpp:2586
cl::Device::getDeviceAndHostTimer
std::pair< cl_ulong, cl_ulong > getDeviceAndHostTimer(cl_int *error=nullptr)
Definition opencl.hpp:2610
cl::Device::createSubDevices
cl_int createSubDevices(const cl_device_partition_property *properties, vector< Device > *devices)
Wrapper for clCreateSubDevices().
Definition opencl.hpp:3054
cl::Device::setDefault
static Device setDefault(const Device &default_device)
Definition opencl.hpp:2538
cl::EnqueueArgs
Definition opencl.hpp:10879
cl::Event
Class interface for cl_event.
Definition opencl.hpp:3678
cl::Event::setCallback
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:3767
cl::Event::getProfilingInfo
cl_int getProfilingInfo(cl_profiling_info name, T *param) const
Wrapper for clGetEventProfilingInfo().
Definition opencl.hpp:3730
cl::Event::getInfo
cl_int getInfo(cl_event_info name, T *param) const
Wrapper for clGetEventInfo().
Definition opencl.hpp:3707
cl::Event::wait
cl_int wait() const
Blocks the calling thread until this event completes.
Definition opencl.hpp:3755
cl::Event::Event
Event()
Default constructor - initializes to nullptr.
Definition opencl.hpp:3681
cl::Event::operator=
Event & operator=(const cl_event &rhs)
Assignment operator from cl_event - takes ownership.
Definition opencl.hpp:3699
cl::Event::waitForEvents
static cl_int waitForEvents(const vector< Event > &events)
Blocks the calling thread until every event specified is complete.
Definition opencl.hpp:3787
cl::Image1DArray
Image interface for arrays of 1D images.
Definition opencl.hpp:5040
cl::Image1DBuffer
Image interface for 1D buffer images.
Definition opencl.hpp:4949
cl::Image1D::Image1D
Image1D()
Default constructor - initializes to nullptr.
Definition opencl.hpp:4884
cl::Image1D::operator=
Image1D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4936
cl::Image2DArray
Image interface for arrays of 2D images.
Definition opencl.hpp:5495
cl::Image2DGL
Class interface for GL 2D Image Memory objects.
Definition opencl.hpp:5431
cl::Image2D
Class interface for 2D Image Memory objects.
Definition opencl.hpp:5145
cl::Image2D::Image2D
Image2D()
Default constructor - initializes to nullptr.
Definition opencl.hpp:5396
cl::Image2D::operator=
Image2D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:5412
cl::Image3DGL::Image3DGL
Image3DGL()
Default constructor - initializes to nullptr.
Definition opencl.hpp:5784
cl::Image3DGL::operator=
Image3DGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:5800
cl::Image3D
Class interface for 3D Image Memory objects.
Definition opencl.hpp:5603
cl::Image3D::operator=
Image3D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:5735
cl::Image3D::Image3D
Image3D()
Default constructor - initializes to nullptr.
Definition opencl.hpp:5719
cl::Image
C++ base class for Image Memory objects.
Definition opencl.hpp:4790
cl::Image::getImageInfo
cl_int getImageInfo(cl_image_info name, T *param) const
Wrapper for clGetImageInfo().
Definition opencl.hpp:4819
cl::Image::operator=
Image & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4809
cl::Image::Image
Image()
Default constructor - initializes to nullptr.
Definition opencl.hpp:4793
cl::KernelFunctor
Definition opencl.hpp:11070
cl::KernelFunctor::operator()
Event operator()(const EnqueueArgs &args, Ts... ts)
Definition opencl.hpp:11112
cl::KernelFunctor::result_type
Event result_type
Return type of the functor.
Definition opencl.hpp:11105
cl::Kernel
Class interface for cl_kernel.
Definition opencl.hpp:6237
cl::Kernel::setSVMPointers
cl_int setSVMPointers(const vector< void * > &pointerList)
Definition opencl.hpp:6431
cl::Kernel::setArg
cl_int setArg(cl_uint index, const cl::pointer< T, D > &argPtr)
setArg overload taking a shared_ptr type
Definition opencl.hpp:6375
cl::Kernel::Kernel
Kernel()
Default constructor - initializes to nullptr.
Definition opencl.hpp:6243
cl::Kernel::operator=
Kernel & operator=(const cl_kernel &rhs)
Assignment operator from cl_kernel - takes ownership.
Definition opencl.hpp:6261
cl::Kernel::clone
Kernel clone()
Definition opencl.hpp:6547
cl::Kernel::enableFineGrainedSystemSVM
cl_int enableFineGrainedSystemSVM(bool svmEnabled)
Enable fine-grained system SVM.
Definition opencl.hpp:6467
cl::Memory
Class interface for cl_mem.
Definition opencl.hpp:3864
cl::Memory::Memory
Memory()
Default constructor - initializes to nullptr.
Definition opencl.hpp:3867
cl::Memory::operator=
Memory & operator=(const cl_mem &rhs)
Assignment operator from cl_mem - takes ownership.
Definition opencl.hpp:3888
cl::Memory::getInfo
cl_int getInfo(cl_mem_info name, T *param) const
Wrapper for clGetMemObjectInfo().
Definition opencl.hpp:3896
cl::Memory::setDestructorCallback
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:3931
cl::NDRange
Class interface for specifying NDRange values.
Definition opencl.hpp:6091
cl::NDRange::dimensions
size_type dimensions() const
Queries the number of dimensions in the range.
Definition opencl.hpp:6151
cl::NDRange::size
size_type size() const
Returns the size of the object in bytes based on the.
Definition opencl.hpp:6158
cl::NDRange::NDRange
NDRange()
Default constructor - resulting range has zero dimensions.
Definition opencl.hpp:6098
cl::Pipe::Pipe
Pipe()
Default constructor - initializes to nullptr.
Definition opencl.hpp:5929
cl::Pipe::getInfo
cl_int getInfo(cl_pipe_info name, T *param) const
Wrapper for clGetMemObjectInfo().
Definition opencl.hpp:5955
cl::Pipe::operator=
Pipe & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:5945
cl::Platform::Platform
Platform()
Default constructor - initializes to nullptr.
Definition opencl.hpp:2768
cl::Platform::unloadCompiler
cl_int unloadCompiler()
Wrapper for clUnloadCompiler().
Definition opencl.hpp:3045
cl::Platform::getDevices
cl_int getDevices(cl_device_type type, vector< Device > *devices) const
Gets a list of devices for this platform.
Definition opencl.hpp:2842
cl::Platform::operator=
Platform & operator=(const cl_platform_id &rhs)
Assignment operator from cl_platform_id.
Definition opencl.hpp:2784
cl::Platform::get
static cl_int get(vector< Platform > *platforms)
Gets a list of available platforms.
Definition opencl.hpp:2977
cl::Platform::getInfo
cl_int getInfo(cl_platform_info name, T *param) const
Wrapper for clGetPlatformInfo().
Definition opencl.hpp:2817
cl::Platform::setDefault
static Platform setDefault(const Platform &default_platform)
Definition opencl.hpp:2808
cl::Program
Program interface that implements cl_program.
Definition opencl.hpp:6562
cl::Program::setReleaseCallback
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:7280
cl::Program::setSpecializationConstant
std::enable_if<!std::is_pointer< T >::value, cl_int >::type setSpecializationConstant(cl_uint index, const T &value)
Sets a SPIR-V specialization constant.
Definition opencl.hpp:7299
cl::SVMAllocator
Definition opencl.hpp:4060
cl::SVMAllocator::operator==
bool operator==(SVMAllocator const &rhs)
Definition opencl.hpp:4199
cl::SVMAllocator::allocate
pointer allocate(size_type size, typename cl::SVMAllocator< void, SVMTrait >::const_pointer=0, bool map=true)
Definition opencl.hpp:4124
cl::SVMAllocator::max_size
size_type max_size() const noexcept
Definition opencl.hpp:4171
cl::Sampler
Class interface for cl_sampler.
Definition opencl.hpp:5988
cl::Sampler::Sampler
Sampler()
Default constructor - initializes to nullptr.
Definition opencl.hpp:5991
cl::Sampler::operator=
Sampler & operator=(const cl_sampler &rhs)
Assignment operator from cl_sampler - takes ownership.
Definition opencl.hpp:6052
cl::Sampler::getInfo
cl_int getInfo(cl_sampler_info name, T *param) const
Wrapper for clGetSamplerInfo().
Definition opencl.hpp:6062
cl::UserEvent::UserEvent
UserEvent()
Default constructor - initializes to nullptr.
Definition opencl.hpp:3827
cl::UserEvent::setStatus
cl_int setStatus(cl_int status)
Sets the execution status of a user event object.
Definition opencl.hpp:3833
cl::detail::Deleter
Definition opencl.hpp:4232
cl::detail::SVMTraitNull
Definition opencl.hpp:3962
cl::detail::Wrapper
Definition opencl.hpp:2193
cl
The OpenCL C++ bindings are defined within this namespace.
Definition opencl.hpp:575
cl::copy
cl_int copy(IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer)
Definition opencl.hpp:10294
cl::coarse_svm_vector
vector< T, cl::SVMAllocator< int, cl::SVMTraitCoarse<> > > coarse_svm_vector
Vector alias to simplify contruction of coarse-grained SVM containers.
Definition opencl.hpp:4316
cl::Local
LocalSpaceArg Local(size_type size)
Helper function for generating LocalSpaceArg objects.
Definition opencl.hpp:6222
cl::UnloadCompiler
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int UnloadCompiler() CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition opencl.hpp:3155
cl::fine_svm_vector
vector< T, cl::SVMAllocator< int, cl::SVMTraitFine<> > > fine_svm_vector
Vector alias to simplify contruction of fine-grained SVM containers.
Definition opencl.hpp:4322
cl::atomic_svm_vector
vector< T, cl::SVMAllocator< int, cl::SVMTraitAtomic<> > > atomic_svm_vector
Vector alias to simplify contruction of fine-grained SVM containers that support platform atomics.
Definition opencl.hpp:4328
cl::allocate_pointer
cl::pointer< T, detail::Deleter< Alloc > > allocate_pointer(const Alloc &alloc_, Args &&... args)
Definition opencl.hpp:4259
cl::enqueueUnmapSVM
cl_int enqueueUnmapSVM(T *ptr, const vector< Event > *events=nullptr, Event *event=nullptr)
Definition opencl.hpp:10209
cl::enqueueMapSVM
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:10107
cl::mapSVM
cl_int mapSVM(cl::vector< T, Alloc > &container)
Definition opencl.hpp:10396
cl::unmapSVM
cl_int unmapSVM(cl::vector< T, Alloc > &container)
Definition opencl.hpp:10405
cl::ImageFormat
Adds constructors and member functions for cl_image_format.
Definition opencl.hpp:2438
cl::ImageFormat::operator=
ImageFormat & operator=(const ImageFormat &rhs)
Assignment operator.
Definition opencl.hpp:2453
cl::ImageFormat::ImageFormat
ImageFormat()
Default constructor - performs no initialization.
Definition opencl.hpp:2440
cl::LocalSpaceArg
Local address wrapper for use with Kernel::setArg.
Definition opencl.hpp:6179
cl::SVMAllocator::rebind
Definition opencl.hpp:4075
cl::SVMAllocator< void, SVMTrait >::rebind
Definition opencl.hpp:4220
cl::compatibility::make_kernel::type_
Event type_(const EnqueueArgs &, Ts...)
Function signature of kernel functor with no event dependency.
Definition opencl.hpp:11202
cl::compatibility::make_kernel::result_type
Event result_type
Return type of the functor.
Definition opencl.hpp:11199
cl::detail::GetInfoFunctor0
Definition opencl.hpp:1924
cl::detail::KernelArgumentHandler
Definition opencl.hpp:6186
cl::detail::ReferenceHandler
Definition opencl.hpp:1959
cl::detail::param_traits
Definition opencl.hpp:1621