OpenCL C++ Bindings: opencl.hpp Source File

OpenCL C++ Bindings

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