OpenCL C++ Bindings
Loading...
Searching...
No Matches
opencl.hpp
Go to the documentation of this file.
1//
2// Copyright (c) 2008-2026 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
55
334 // SVM allocations
335
336 auto anSVMInt = cl::allocate_svm<int, cl::SVMTraitCoarse<>>();
337 *anSVMInt = 5;
338 cl::SVMAllocator<Foo, cl::SVMTraitCoarse<cl::SVMTraitReadOnly<>>> svmAllocReadOnly;
339 auto fooPointer = cl::allocate_pointer<Foo>(svmAllocReadOnly);
340 fooPointer->bar = anSVMInt.get();
341 cl::SVMAllocator<int, cl::SVMTraitCoarse<>> svmAlloc;
342 std::vector<int, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>> inputA(numElements, 1, svmAlloc);
343 cl::coarse_svm_vector<int> inputB(numElements, 2, svmAlloc);
344
346 // Traditional cl_mem allocations
347
348 std::vector<int> output(numElements, 0xdeadbeef);
349 cl::Buffer outputBuffer(output.begin(), output.end(), false);
350 cl::Pipe aPipe(sizeof(cl_int), numElements / 2);
351
352 // Default command queue, also passed in as a parameter
353 cl::DeviceCommandQueue defaultDeviceQueue = cl::DeviceCommandQueue::makeDefault(
354 cl::Context::getDefault(), cl::Device::getDefault());
355
356 auto vectorAddKernel =
357 cl::KernelFunctor<
358 decltype(fooPointer)&,
359 int*,
360 cl::coarse_svm_vector<int>&,
361 cl::Buffer,
362 int,
363 cl::Pipe&,
364 cl::DeviceCommandQueue
365 >(vectorAddProgram, "vectorAdd");
366
367 // Ensure that the additional SVM pointer is available to the kernel
368 // This one was not passed as a parameter
369 vectorAddKernel.setSVMPointers(anSVMInt);
370
371 cl_int error;
372 vectorAddKernel(
373 cl::EnqueueArgs(
374 cl::NDRange(numElements/2),
375 cl::NDRange(numElements/2)),
376 fooPointer,
377 inputA.data(),
378 inputB,
379 outputBuffer,
380 3,
381 aPipe,
382 defaultDeviceQueue,
383 error
384 );
385
386 cl::copy(outputBuffer, output.begin(), output.end());
387
388 cl::Device d = cl::Device::getDefault();
389
390 std::cout << "Output:\n";
391 for (int i = 1; i < numElements; ++i) {
392 std::cout << "\t" << output[i] << "\n";
393 }
394 std::cout << "\n\n";
395
396 return 0;
397 }
398 *
399 * \endcode
400 *
401 */
402#ifndef CL_HPP_
403#define CL_HPP_
404
405#ifdef CL_HPP_OPENCL_API_WRAPPER
406#define CL_(name) CL_HPP_OPENCL_API_WRAPPER(name)
407#else
408#define CL_(name) ::name
409#endif
410
411/* Handle deprecated preprocessor definitions. In each case, we only check for
412 * the old name if the new name is not defined, so that user code can define
413 * both and hence work with either version of the bindings.
414 */
415#if !defined(CL_HPP_USE_DX_INTEROP) && defined(USE_DX_INTEROP)
416# pragma message("opencl.hpp: USE_DX_INTEROP is deprecated. Define CL_HPP_USE_DX_INTEROP instead")
417# define CL_HPP_USE_DX_INTEROP
418#endif
419#if !defined(CL_HPP_ENABLE_EXCEPTIONS) && defined(__CL_ENABLE_EXCEPTIONS)
420# pragma message("opencl.hpp: __CL_ENABLE_EXCEPTIONS is deprecated. Define CL_HPP_ENABLE_EXCEPTIONS instead")
421# define CL_HPP_ENABLE_EXCEPTIONS
422#endif
423#if !defined(CL_HPP_NO_STD_VECTOR) && defined(__NO_STD_VECTOR)
424# pragma message("opencl.hpp: __NO_STD_VECTOR is deprecated. Define CL_HPP_NO_STD_VECTOR instead")
425# define CL_HPP_NO_STD_VECTOR
426#endif
427#if !defined(CL_HPP_NO_STD_STRING) && defined(__NO_STD_STRING)
428# pragma message("opencl.hpp: __NO_STD_STRING is deprecated. Define CL_HPP_NO_STD_STRING instead")
429# define CL_HPP_NO_STD_STRING
430#endif
431#if defined(VECTOR_CLASS)
432# pragma message("opencl.hpp: VECTOR_CLASS is deprecated. Alias cl::vector instead")
433#endif
434#if defined(STRING_CLASS)
435# pragma message("opencl.hpp: STRING_CLASS is deprecated. Alias cl::string instead.")
436#endif
437#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) && defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
438# pragma message("opencl.hpp: __CL_USER_OVERRIDE_ERROR_STRINGS is deprecated. Define CL_HPP_USER_OVERRIDE_ERROR_STRINGS instead")
439# define CL_HPP_USER_OVERRIDE_ERROR_STRINGS
440#endif
441
442/* Warn about features that are no longer supported
443 */
444#if defined(__USE_DEV_VECTOR)
445# pragma message("opencl.hpp: __USE_DEV_VECTOR is no longer supported. Expect compilation errors")
446#endif
447#if defined(__USE_DEV_STRING)
448# pragma message("opencl.hpp: __USE_DEV_STRING is no longer supported. Expect compilation errors")
449#endif
450
451/* Detect which version to target */
452#if !defined(CL_HPP_TARGET_OPENCL_VERSION)
453# pragma message("opencl.hpp: CL_HPP_TARGET_OPENCL_VERSION is not defined. It will default to 310 (OpenCL 3.1)")
454# define CL_HPP_TARGET_OPENCL_VERSION 310
455#endif
456#if CL_HPP_TARGET_OPENCL_VERSION != 100 && \
457 CL_HPP_TARGET_OPENCL_VERSION != 110 && \
458 CL_HPP_TARGET_OPENCL_VERSION != 120 && \
459 CL_HPP_TARGET_OPENCL_VERSION != 200 && \
460 CL_HPP_TARGET_OPENCL_VERSION != 210 && \
461 CL_HPP_TARGET_OPENCL_VERSION != 220 && \
462 CL_HPP_TARGET_OPENCL_VERSION != 300 && \
463 CL_HPP_TARGET_OPENCL_VERSION != 310
464# pragma message("opencl.hpp: CL_HPP_TARGET_OPENCL_VERSION is not a valid value (100, 110, 120, 200, 210, 220, 300 or 310). It will be set to 310 (OpenCL 3.1).")
465# undef CL_HPP_TARGET_OPENCL_VERSION
466# define CL_HPP_TARGET_OPENCL_VERSION 310
467#endif
468
469/* Forward target OpenCL version to C headers if necessary */
470#if defined(CL_TARGET_OPENCL_VERSION)
471/* Warn if prior definition of CL_TARGET_OPENCL_VERSION is lower than
472 * requested C++ bindings version */
473#if CL_TARGET_OPENCL_VERSION < CL_HPP_TARGET_OPENCL_VERSION
474# pragma message("CL_TARGET_OPENCL_VERSION is already defined as is lower than CL_HPP_TARGET_OPENCL_VERSION")
475#endif
476#else
477# define CL_TARGET_OPENCL_VERSION CL_HPP_TARGET_OPENCL_VERSION
478#endif
479
480#if !defined(CL_HPP_MINIMUM_OPENCL_VERSION)
481# define CL_HPP_MINIMUM_OPENCL_VERSION 200
482#endif
483#if CL_HPP_MINIMUM_OPENCL_VERSION != 100 && \
484 CL_HPP_MINIMUM_OPENCL_VERSION != 110 && \
485 CL_HPP_MINIMUM_OPENCL_VERSION != 120 && \
486 CL_HPP_MINIMUM_OPENCL_VERSION != 200 && \
487 CL_HPP_MINIMUM_OPENCL_VERSION != 210 && \
488 CL_HPP_MINIMUM_OPENCL_VERSION != 220 && \
489 CL_HPP_MINIMUM_OPENCL_VERSION != 300 && \
490 CL_HPP_MINIMUM_OPENCL_VERSION != 310
491# pragma message("opencl.hpp: CL_HPP_MINIMUM_OPENCL_VERSION is not a valid value (100, 110, 120, 200, 210, 220, 300 or 310). It will be set to 100")
492# undef CL_HPP_MINIMUM_OPENCL_VERSION
493# define CL_HPP_MINIMUM_OPENCL_VERSION 100
494#endif
495#if CL_HPP_MINIMUM_OPENCL_VERSION > CL_HPP_TARGET_OPENCL_VERSION
496# error "CL_HPP_MINIMUM_OPENCL_VERSION must not be greater than CL_HPP_TARGET_OPENCL_VERSION"
497#endif
498
499#if CL_HPP_MINIMUM_OPENCL_VERSION <= 100 && !defined(CL_USE_DEPRECATED_OPENCL_1_0_APIS)
500# define CL_USE_DEPRECATED_OPENCL_1_0_APIS
501#endif
502#if CL_HPP_MINIMUM_OPENCL_VERSION <= 110 && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
503# define CL_USE_DEPRECATED_OPENCL_1_1_APIS
504#endif
505#if CL_HPP_MINIMUM_OPENCL_VERSION <= 120 && !defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
506# define CL_USE_DEPRECATED_OPENCL_1_2_APIS
507#endif
508#if CL_HPP_MINIMUM_OPENCL_VERSION <= 200 && !defined(CL_USE_DEPRECATED_OPENCL_2_0_APIS)
509# define CL_USE_DEPRECATED_OPENCL_2_0_APIS
510#endif
511#if CL_HPP_MINIMUM_OPENCL_VERSION <= 210 && !defined(CL_USE_DEPRECATED_OPENCL_2_1_APIS)
512# define CL_USE_DEPRECATED_OPENCL_2_1_APIS
513#endif
514#if CL_HPP_MINIMUM_OPENCL_VERSION <= 220 && !defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
515# define CL_USE_DEPRECATED_OPENCL_2_2_APIS
516#endif
517
518#ifdef _WIN32
519
520#include <malloc.h>
521
522#if defined(CL_HPP_USE_DX_INTEROP)
523#include <CL/cl_d3d10.h>
524#include <CL/cl_dx9_media_sharing.h>
525#endif
526#endif // _WIN32
527
528#if defined(_MSC_VER)
529#include <intrin.h>
530#endif // _MSC_VER
531
532 // Check for a valid C++ version
533
534// Need to do both tests here because for some reason __cplusplus is not
535// updated in visual studio
536#if (!defined(_MSC_VER) && __cplusplus < 201103L) || (defined(_MSC_VER) && _MSC_VER < 1700)
537#error Visual studio 2013 or another C++11-supporting compiler required
538#endif
539
540#if defined(__APPLE__) || defined(__MACOSX)
541#include <OpenCL/opencl.h>
542#else
543#include <CL/opencl.h>
544#endif // !__APPLE__
545
546#if __cplusplus >= 201703L
547# define CL_HPP_DEFINE_STATIC_MEMBER_ inline
548#elif defined(_MSC_VER)
549# define CL_HPP_DEFINE_STATIC_MEMBER_ __declspec(selectany)
550#elif defined(__MINGW32__)
551# define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((selectany))
552#else
553# define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((weak))
554#endif // !_MSC_VER
555
556// Define deprecated prefixes and suffixes to ensure compilation
557// in case they are not pre-defined
558#if !defined(CL_API_PREFIX__VERSION_1_1_DEPRECATED)
559#define CL_API_PREFIX__VERSION_1_1_DEPRECATED
560#endif // #if !defined(CL_API_PREFIX__VERSION_1_1_DEPRECATED)
561#if !defined(CL_API_SUFFIX__VERSION_1_1_DEPRECATED)
562#define CL_API_SUFFIX__VERSION_1_1_DEPRECATED
563#endif // #if !defined(CL_API_SUFFIX__VERSION_1_1_DEPRECATED)
564
565#if !defined(CL_API_PREFIX__VERSION_1_2_DEPRECATED)
566#define CL_API_PREFIX__VERSION_1_2_DEPRECATED
567#endif // #if !defined(CL_API_PREFIX__VERSION_1_2_DEPRECATED)
568#if !defined(CL_API_SUFFIX__VERSION_1_2_DEPRECATED)
569#define CL_API_SUFFIX__VERSION_1_2_DEPRECATED
570#endif // #if !defined(CL_API_SUFFIX__VERSION_1_2_DEPRECATED)
571
572#if !defined(CL_API_PREFIX__VERSION_2_2_DEPRECATED)
573#define CL_API_PREFIX__VERSION_2_2_DEPRECATED
574#endif // #if !defined(CL_API_PREFIX__VERSION_2_2_DEPRECATED)
575#if !defined(CL_API_SUFFIX__VERSION_2_2_DEPRECATED)
576#define CL_API_SUFFIX__VERSION_2_2_DEPRECATED
577#endif // #if !defined(CL_API_SUFFIX__VERSION_2_2_DEPRECATED)
578
579#if !defined(CL_CALLBACK)
580#define CL_CALLBACK
581#endif //CL_CALLBACK
582
583#include <utility>
584#include <limits>
585#include <iterator>
586#include <mutex>
587#include <cstring>
588#include <functional>
589
590
591// Define a size_type to represent a correctly resolved size_t
592#if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
593namespace cl {
594 using size_type = ::size_t;
595} // namespace cl
596#else // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
597namespace cl {
598 using size_type = size_t;
599} // namespace cl
600#endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
601
602
603#if defined(CL_HPP_ENABLE_EXCEPTIONS)
604#include <exception>
605#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
606
607#if !defined(CL_HPP_NO_STD_VECTOR)
608#include <vector>
609namespace cl {
610 template < class T, class Alloc = std::allocator<T> >
611 using vector = std::vector<T, Alloc>;
612} // namespace cl
613#endif // #if !defined(CL_HPP_NO_STD_VECTOR)
614
615#if !defined(CL_HPP_NO_STD_STRING)
616#include <string>
617namespace cl {
618 using string = std::string;
619} // namespace cl
620#endif // #if !defined(CL_HPP_NO_STD_STRING)
621
622#if CL_HPP_TARGET_OPENCL_VERSION >= 200
623
624#if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
625#include <memory>
626namespace cl {
627 // Replace unique_ptr and allocate_pointer for internal use
628 // to allow user to replace them
629 template<class T, class D>
630 using pointer = std::unique_ptr<T, D>;
631} // namespace cl
632#endif
633#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
634#if !defined(CL_HPP_NO_STD_ARRAY)
635#include <array>
636namespace cl {
637 template < class T, size_type N >
638 using array = std::array<T, N>;
639} // namespace cl
640#endif // #if !defined(CL_HPP_NO_STD_ARRAY)
641
642// Define size_type appropriately to allow backward-compatibility
643// use of the old size_t interface class
644#if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
645namespace cl {
646 namespace compatibility {
651 template <int N>
652 class size_t
653 {
654 private:
655 size_type data_[N];
656
657 public:
659 size_t()
660 {
661 for (int i = 0; i < N; ++i) {
662 data_[i] = 0;
663 }
664 }
665
666 size_t(const array<size_type, N> &rhs)
667 {
668 for (int i = 0; i < N; ++i) {
669 data_[i] = rhs[i];
670 }
671 }
672
673 size_type& operator[](int index)
674 {
675 return data_[index];
676 }
677
678 const size_type& operator[](int index) const
679 {
680 return data_[index];
681 }
682
684 operator size_type* () { return data_; }
685
687 operator const size_type* () const { return data_; }
688
689 operator array<size_type, N>() const
690 {
691 array<size_type, N> ret;
692
693 for (int i = 0; i < N; ++i) {
694 ret[i] = data_[i];
695 }
696 return ret;
697 }
698 };
699 } // namespace compatibility
700
701 template<int N>
702 using size_t = compatibility::size_t<N>;
703} // namespace cl
704#endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
705
706// Helper alias to avoid confusing the macros
707namespace cl {
708 namespace detail {
709 using size_t_array = array<size_type, 3>;
710 } // namespace detail
711} // namespace cl
712
713
719namespace cl {
720
721#define CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(name) \
722 using PFN_##name = name##_fn
723
724#define CL_HPP_INIT_CL_EXT_FCN_PTR_(name) \
725 if (!pfn_##name) { \
726 pfn_##name = (PFN_##name)CL_(clGetExtensionFunctionAddress)(#name); \
727 }
728
729#define CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, name) \
730 if (!pfn_##name) { \
731 pfn_##name = (PFN_##name) \
732 CL_(clGetExtensionFunctionAddressForPlatform)(platform, #name); \
733 }
734
735#ifdef cl_khr_external_memory
736 enum class ExternalMemoryType : cl_external_memory_handle_type_khr;
737#endif
738
739 class Memory;
740 class Platform;
741 class Program;
742 class Device;
743 class Context;
744 class CommandQueue;
745 class DeviceCommandQueue;
746 class Memory;
747 class Buffer;
748 class Pipe;
749#ifdef cl_khr_semaphore
750 class Semaphore;
751#endif
752#if defined(cl_khr_command_buffer)
753 class CommandBufferKhr;
754 class MutableCommandKhr;
755#endif // cl_khr_command_buffer
756
757#if defined(CL_HPP_ENABLE_EXCEPTIONS)
758#if !defined(CL_HPP_CUSTOM_EXCEPTION_TYPE)
763 class Error : public std::exception
764 {
765 private:
766 cl_int err_;
767 const char * errStr_;
768 public:
778 Error(cl_int err, const char * errStr = nullptr) : err_(err), errStr_(errStr)
779 {}
780
785 const char * what() const noexcept override
786 {
787 if (errStr_ == nullptr) {
788 return "empty";
789 }
790 else {
791 return errStr_;
792 }
793 }
794
799 cl_int err(void) const { return err_; }
800 };
801#else
802 using Error = CL_HPP_CUSTOM_EXCEPTION_TYPE;
803#endif
804#define CL_HPP_ERR_STR_(x) #x
805#else
806#define CL_HPP_ERR_STR_(x) nullptr
807#endif // CL_HPP_ENABLE_EXCEPTIONS
808
809
810namespace detail
811{
812#if defined(CL_HPP_ENABLE_EXCEPTIONS)
813static inline cl_int errHandler (
814 cl_int err,
815 const char * errStr = nullptr)
816{
817 if (err != CL_SUCCESS) {
818 throw Error(err, errStr);
819 }
820 return err;
821}
822#else
823static inline cl_int errHandler (cl_int err, const char * errStr = nullptr)
824{
825 (void) errStr; // suppress unused variable warning
826 return err;
827}
828#endif // CL_HPP_ENABLE_EXCEPTIONS
829}
830
831
832
834#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
835#define __GET_DEVICE_INFO_ERR CL_HPP_ERR_STR_(clGetDeviceInfo)
836#define __GET_PLATFORM_INFO_ERR CL_HPP_ERR_STR_(clGetPlatformInfo)
837#define __GET_DEVICE_IDS_ERR CL_HPP_ERR_STR_(clGetDeviceIDs)
838#define __GET_PLATFORM_IDS_ERR CL_HPP_ERR_STR_(clGetPlatformIDs)
839#define __GET_CONTEXT_INFO_ERR CL_HPP_ERR_STR_(clGetContextInfo)
840#define __GET_EVENT_INFO_ERR CL_HPP_ERR_STR_(clGetEventInfo)
841#define __GET_EVENT_PROFILE_INFO_ERR CL_HPP_ERR_STR_(clGetEventProfileInfo)
842#define __GET_MEM_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetMemObjectInfo)
843#define __GET_IMAGE_INFO_ERR CL_HPP_ERR_STR_(clGetImageInfo)
844#define __GET_SAMPLER_INFO_ERR CL_HPP_ERR_STR_(clGetSamplerInfo)
845#define __GET_KERNEL_INFO_ERR CL_HPP_ERR_STR_(clGetKernelInfo)
846#if CL_HPP_TARGET_OPENCL_VERSION >= 120
847#define __GET_KERNEL_ARG_INFO_ERR CL_HPP_ERR_STR_(clGetKernelArgInfo)
848#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
849#if CL_HPP_TARGET_OPENCL_VERSION >= 210
850#define __GET_KERNEL_SUB_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelSubGroupInfo)
851#else
852#define __GET_KERNEL_SUB_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelSubGroupInfoKHR)
853#endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
854#define __GET_KERNEL_WORK_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelWorkGroupInfo)
855#if CL_HPP_TARGET_OPENCL_VERSION >= 310
856#define __GET_KERNEL_SUGGESTED_LWS_ERR CL_HPP_ERR_STR_(clGetKernelSuggestedLocalWorkSize)
857#endif // CL_HPP_TARGET_OPENCL_VERSION >= 310
858#define __GET_PROGRAM_INFO_ERR CL_HPP_ERR_STR_(clGetProgramInfo)
859#define __GET_PROGRAM_BUILD_INFO_ERR CL_HPP_ERR_STR_(clGetProgramBuildInfo)
860#define __GET_COMMAND_QUEUE_INFO_ERR CL_HPP_ERR_STR_(clGetCommandQueueInfo)
861
862#define __CREATE_CONTEXT_ERR CL_HPP_ERR_STR_(clCreateContext)
863#define __CREATE_CONTEXT_FROM_TYPE_ERR CL_HPP_ERR_STR_(clCreateContextFromType)
864#define __GET_SUPPORTED_IMAGE_FORMATS_ERR CL_HPP_ERR_STR_(clGetSupportedImageFormats)
865#if CL_HPP_TARGET_OPENCL_VERSION >= 300
866#define __SET_CONTEXT_DESTRUCTOR_CALLBACK_ERR CL_HPP_ERR_STR_(clSetContextDestructorCallback)
867#endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
868
869#define __CREATE_BUFFER_ERR CL_HPP_ERR_STR_(clCreateBuffer)
870#define __COPY_ERR CL_HPP_ERR_STR_(cl::copy)
871#define __CREATE_SUBBUFFER_ERR CL_HPP_ERR_STR_(clCreateSubBuffer)
872#define __CREATE_GL_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
873#define __CREATE_GL_RENDER_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLRenderbuffer)
874#define __GET_GL_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetGLObjectInfo)
875#if CL_HPP_TARGET_OPENCL_VERSION >= 120
876#define __CREATE_IMAGE_ERR CL_HPP_ERR_STR_(clCreateImage)
877#define __CREATE_GL_TEXTURE_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture)
878#define __IMAGE_DIMENSION_ERR CL_HPP_ERR_STR_(Incorrect image dimensions)
879#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
880#define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR CL_HPP_ERR_STR_(clSetMemObjectDestructorCallback)
881
882#define __CREATE_USER_EVENT_ERR CL_HPP_ERR_STR_(clCreateUserEvent)
883#define __SET_USER_EVENT_STATUS_ERR CL_HPP_ERR_STR_(clSetUserEventStatus)
884#define __SET_EVENT_CALLBACK_ERR CL_HPP_ERR_STR_(clSetEventCallback)
885#define __WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clWaitForEvents)
886
887#define __CREATE_KERNEL_ERR CL_HPP_ERR_STR_(clCreateKernel)
888#define __SET_KERNEL_ARGS_ERR CL_HPP_ERR_STR_(clSetKernelArg)
889#define __CREATE_PROGRAM_WITH_SOURCE_ERR CL_HPP_ERR_STR_(clCreateProgramWithSource)
890#define __CREATE_PROGRAM_WITH_BINARY_ERR CL_HPP_ERR_STR_(clCreateProgramWithBinary)
891#if CL_HPP_TARGET_OPENCL_VERSION >= 210
892#define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
893#else
894#define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithILKHR)
895#endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
896#if CL_HPP_TARGET_OPENCL_VERSION >= 120
897#define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR CL_HPP_ERR_STR_(clCreateProgramWithBuiltInKernels)
898#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
899#define __BUILD_PROGRAM_ERR CL_HPP_ERR_STR_(clBuildProgram)
900#if CL_HPP_TARGET_OPENCL_VERSION >= 120
901#define __COMPILE_PROGRAM_ERR CL_HPP_ERR_STR_(clCompileProgram)
902#define __LINK_PROGRAM_ERR CL_HPP_ERR_STR_(clLinkProgram)
903#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
904#define __CREATE_KERNELS_IN_PROGRAM_ERR CL_HPP_ERR_STR_(clCreateKernelsInProgram)
905
906#if CL_HPP_TARGET_OPENCL_VERSION >= 200
907#define __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateCommandQueueWithProperties)
908#define __CREATE_SAMPLER_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateSamplerWithProperties)
909#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
910#define __SET_COMMAND_QUEUE_PROPERTY_ERR CL_HPP_ERR_STR_(clSetCommandQueueProperty)
911#define __ENQUEUE_READ_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueReadBuffer)
912#define __ENQUEUE_READ_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueReadBufferRect)
913#define __ENQUEUE_WRITE_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueWriteBuffer)
914#define __ENQUEUE_WRITE_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueWriteBufferRect)
915#define __ENQEUE_COPY_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyBuffer)
916#define __ENQEUE_COPY_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferRect)
917#define __ENQUEUE_FILL_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueFillBuffer)
918#define __ENQUEUE_READ_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueReadImage)
919#define __ENQUEUE_WRITE_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueWriteImage)
920#define __ENQUEUE_COPY_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyImage)
921#define __ENQUEUE_FILL_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueFillImage)
922#define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyImageToBuffer)
923#define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferToImage)
924#define __ENQUEUE_MAP_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueMapBuffer)
925#define __ENQUEUE_MAP_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMMap)
926#define __ENQUEUE_FILL_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMMemFill)
927#define __ENQUEUE_COPY_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMMemcpy)
928#define __ENQUEUE_UNMAP_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMUnmap)
929#define __ENQUEUE_MAP_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueMapImage)
930#define __ENQUEUE_UNMAP_MEM_OBJECT_ERR CL_HPP_ERR_STR_(clEnqueueUnMapMemObject)
931#define __ENQUEUE_NDRANGE_KERNEL_ERR CL_HPP_ERR_STR_(clEnqueueNDRangeKernel)
932#define __ENQUEUE_NATIVE_KERNEL CL_HPP_ERR_STR_(clEnqueueNativeKernel)
933#if CL_HPP_TARGET_OPENCL_VERSION >= 120
934#define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR CL_HPP_ERR_STR_(clEnqueueMigrateMemObjects)
935#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
936#if CL_HPP_TARGET_OPENCL_VERSION >= 210
937#define __ENQUEUE_MIGRATE_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMMigrateMem)
938#define __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clSetDefaultDeviceCommandQueue)
939#endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
940
941
942#define __ENQUEUE_ACQUIRE_GL_ERR CL_HPP_ERR_STR_(clEnqueueAcquireGLObjects)
943#define __ENQUEUE_RELEASE_GL_ERR CL_HPP_ERR_STR_(clEnqueueReleaseGLObjects)
944
945#define __CREATE_PIPE_ERR CL_HPP_ERR_STR_(clCreatePipe)
946#define __GET_PIPE_INFO_ERR CL_HPP_ERR_STR_(clGetPipeInfo)
947
948#define __RETAIN_ERR CL_HPP_ERR_STR_(Retain Object)
949#define __RELEASE_ERR CL_HPP_ERR_STR_(Release Object)
950#define __FLUSH_ERR CL_HPP_ERR_STR_(clFlush)
951#define __FINISH_ERR CL_HPP_ERR_STR_(clFinish)
952#define __VECTOR_CAPACITY_ERR CL_HPP_ERR_STR_(Vector capacity error)
953
954#if CL_HPP_TARGET_OPENCL_VERSION >= 210
955#define __GET_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetHostTimer)
956#define __GET_DEVICE_AND_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetDeviceAndHostTimer)
957#endif
958#if CL_HPP_TARGET_OPENCL_VERSION >= 220
959#define __SET_PROGRAM_RELEASE_CALLBACK_ERR CL_HPP_ERR_STR_(clSetProgramReleaseCallback)
960#define __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR CL_HPP_ERR_STR_(clSetProgramSpecializationConstant)
961#endif
962
963#ifdef cl_khr_external_memory
964#define __ENQUEUE_ACQUIRE_EXTERNAL_MEMORY_ERR CL_HPP_ERR_STR_(clEnqueueAcquireExternalMemObjectsKHR)
965#define __ENQUEUE_RELEASE_EXTERNAL_MEMORY_ERR CL_HPP_ERR_STR_(clEnqueueReleaseExternalMemObjectsKHR)
966#endif
967
968#ifdef cl_khr_semaphore
969#define __GET_SEMAPHORE_KHR_INFO_ERR CL_HPP_ERR_STR_(clGetSemaphoreInfoKHR)
970#define __CREATE_SEMAPHORE_KHR_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateSemaphoreWithPropertiesKHR)
971#define __ENQUEUE_WAIT_SEMAPHORE_KHR_ERR CL_HPP_ERR_STR_(clEnqueueWaitSemaphoresKHR)
972#define __ENQUEUE_SIGNAL_SEMAPHORE_KHR_ERR CL_HPP_ERR_STR_(clEnqueueSignalSemaphoresKHR)
973#define __RETAIN_SEMAPHORE_KHR_ERR CL_HPP_ERR_STR_(clRetainSemaphoreKHR)
974#define __RELEASE_SEMAPHORE_KHR_ERR CL_HPP_ERR_STR_(clReleaseSemaphoreKHR)
975#endif
976
977#ifdef cl_khr_external_semaphore
978#define __GET_SEMAPHORE_HANDLE_FOR_TYPE_KHR_ERR CL_HPP_ERR_STR_(clGetSemaphoreHandleForTypeKHR)
979#endif // cl_khr_external_semaphore
980
981#if defined(cl_khr_command_buffer)
982#define __CREATE_COMMAND_BUFFER_KHR_ERR CL_HPP_ERR_STR_(clCreateCommandBufferKHR)
983#define __GET_COMMAND_BUFFER_INFO_KHR_ERR CL_HPP_ERR_STR_(clGetCommandBufferInfoKHR)
984#define __FINALIZE_COMMAND_BUFFER_KHR_ERR CL_HPP_ERR_STR_(clFinalizeCommandBufferKHR)
985#define __ENQUEUE_COMMAND_BUFFER_KHR_ERR CL_HPP_ERR_STR_(clEnqueueCommandBufferKHR)
986#define __COMMAND_BARRIER_WITH_WAIT_LIST_KHR_ERR CL_HPP_ERR_STR_(clCommandBarrierWithWaitListKHR)
987#define __COMMAND_COPY_BUFFER_KHR_ERR CL_HPP_ERR_STR_(clCommandCopyBufferKHR)
988#define __COMMAND_COPY_BUFFER_RECT_KHR_ERR CL_HPP_ERR_STR_(clCommandCopyBufferRectKHR)
989#define __COMMAND_COPY_BUFFER_TO_IMAGE_KHR_ERR CL_HPP_ERR_STR_(clCommandCopyBufferToImageKHR)
990#define __COMMAND_COPY_IMAGE_KHR_ERR CL_HPP_ERR_STR_(clCommandCopyImageKHR)
991#define __COMMAND_COPY_IMAGE_TO_BUFFER_KHR_ERR CL_HPP_ERR_STR_(clCommandCopyImageToBufferKHR)
992#define __COMMAND_FILL_BUFFER_KHR_ERR CL_HPP_ERR_STR_(clCommandFillBufferKHR)
993#define __COMMAND_FILL_IMAGE_KHR_ERR CL_HPP_ERR_STR_(clCommandFillImageKHR)
994#define __COMMAND_NDRANGE_KERNEL_KHR_ERR CL_HPP_ERR_STR_(clCommandNDRangeKernelKHR)
995#define __UPDATE_MUTABLE_COMMANDS_KHR_ERR CL_HPP_ERR_STR_(clUpdateMutableCommandsKHR)
996#define __GET_MUTABLE_COMMAND_INFO_KHR_ERR CL_HPP_ERR_STR_(clGetMutableCommandInfoKHR)
997#define __RETAIN_COMMAND_BUFFER_KHR_ERR CL_HPP_ERR_STR_(clRetainCommandBufferKHR)
998#define __RELEASE_COMMAND_BUFFER_KHR_ERR CL_HPP_ERR_STR_(clReleaseCommandBufferKHR)
999#endif // cl_khr_command_buffer
1000
1001#if defined(cl_ext_image_requirements_info)
1002#define __GET_IMAGE_REQUIREMENT_INFO_EXT_ERR CL_HPP_ERR_STR_(clGetImageRequirementsInfoEXT)
1003#endif //cl_ext_image_requirements_info
1004
1008#if CL_HPP_TARGET_OPENCL_VERSION >= 120
1009#define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevices)
1010#else
1011#define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevicesEXT)
1012#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1013
1017#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
1018#define __ENQUEUE_MARKER_ERR CL_HPP_ERR_STR_(clEnqueueMarker)
1019#define __ENQUEUE_WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clEnqueueWaitForEvents)
1020#define __ENQUEUE_BARRIER_ERR CL_HPP_ERR_STR_(clEnqueueBarrier)
1021#define __UNLOAD_COMPILER_ERR CL_HPP_ERR_STR_(clUnloadCompiler)
1022#define __CREATE_GL_TEXTURE_2D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture2D)
1023#define __CREATE_GL_TEXTURE_3D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture3D)
1024#define __CREATE_IMAGE2D_ERR CL_HPP_ERR_STR_(clCreateImage2D)
1025#define __CREATE_IMAGE3D_ERR CL_HPP_ERR_STR_(clCreateImage3D)
1026#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
1027
1031#if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
1032#define __CREATE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clCreateCommandQueue)
1033#define __ENQUEUE_TASK_ERR CL_HPP_ERR_STR_(clEnqueueTask)
1034#define __CREATE_SAMPLER_ERR CL_HPP_ERR_STR_(clCreateSampler)
1035#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
1036
1040#if CL_HPP_TARGET_OPENCL_VERSION >= 120
1041#define __ENQUEUE_MARKER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueMarkerWithWaitList)
1042#define __ENQUEUE_BARRIER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueBarrierWithWaitList)
1043#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1044
1045#if CL_HPP_TARGET_OPENCL_VERSION >= 210
1046#define __CLONE_KERNEL_ERR CL_HPP_ERR_STR_(clCloneKernel)
1047#endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
1048
1049#endif // CL_HPP_USER_OVERRIDE_ERROR_STRINGS
1051
1052#ifdef cl_khr_external_memory
1053CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clEnqueueAcquireExternalMemObjectsKHR);
1054CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clEnqueueReleaseExternalMemObjectsKHR);
1055
1056CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clEnqueueAcquireExternalMemObjectsKHR pfn_clEnqueueAcquireExternalMemObjectsKHR = nullptr;
1057CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clEnqueueReleaseExternalMemObjectsKHR pfn_clEnqueueReleaseExternalMemObjectsKHR = nullptr;
1058#endif // cl_khr_external_memory
1059
1060#ifdef cl_khr_semaphore
1061CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCreateSemaphoreWithPropertiesKHR);
1062CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clReleaseSemaphoreKHR);
1063CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clRetainSemaphoreKHR);
1064CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clEnqueueWaitSemaphoresKHR);
1065CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clEnqueueSignalSemaphoresKHR);
1066CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clGetSemaphoreInfoKHR);
1067
1068CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCreateSemaphoreWithPropertiesKHR pfn_clCreateSemaphoreWithPropertiesKHR = nullptr;
1069CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clReleaseSemaphoreKHR pfn_clReleaseSemaphoreKHR = nullptr;
1070CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clRetainSemaphoreKHR pfn_clRetainSemaphoreKHR = nullptr;
1071CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clEnqueueWaitSemaphoresKHR pfn_clEnqueueWaitSemaphoresKHR = nullptr;
1072CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clEnqueueSignalSemaphoresKHR pfn_clEnqueueSignalSemaphoresKHR = nullptr;
1073CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clGetSemaphoreInfoKHR pfn_clGetSemaphoreInfoKHR = nullptr;
1074#endif // cl_khr_semaphore
1075
1076#ifdef cl_khr_external_semaphore
1077CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clGetSemaphoreHandleForTypeKHR);
1078CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clGetSemaphoreHandleForTypeKHR pfn_clGetSemaphoreHandleForTypeKHR = nullptr;
1079#endif // cl_khr_external_semaphore
1080
1081#if defined(cl_khr_command_buffer)
1082CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCreateCommandBufferKHR);
1083CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clFinalizeCommandBufferKHR);
1084CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clRetainCommandBufferKHR);
1085CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clReleaseCommandBufferKHR);
1086CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clGetCommandBufferInfoKHR);
1087CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clEnqueueCommandBufferKHR);
1088CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCommandBarrierWithWaitListKHR);
1089CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCommandCopyBufferKHR);
1090CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCommandCopyBufferRectKHR);
1091CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCommandCopyBufferToImageKHR);
1092CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCommandCopyImageKHR);
1093CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCommandCopyImageToBufferKHR);
1094CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCommandFillBufferKHR);
1095CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCommandFillImageKHR);
1096CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCommandNDRangeKernelKHR);
1097
1098CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCreateCommandBufferKHR pfn_clCreateCommandBufferKHR = nullptr;
1099CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clFinalizeCommandBufferKHR pfn_clFinalizeCommandBufferKHR = nullptr;
1100CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clRetainCommandBufferKHR pfn_clRetainCommandBufferKHR = nullptr;
1101CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clReleaseCommandBufferKHR pfn_clReleaseCommandBufferKHR = nullptr;
1102CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clGetCommandBufferInfoKHR pfn_clGetCommandBufferInfoKHR = nullptr;
1103CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clEnqueueCommandBufferKHR pfn_clEnqueueCommandBufferKHR = nullptr;
1104CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCommandBarrierWithWaitListKHR pfn_clCommandBarrierWithWaitListKHR = nullptr;
1105CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCommandCopyBufferKHR pfn_clCommandCopyBufferKHR = nullptr;
1106CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCommandCopyBufferRectKHR pfn_clCommandCopyBufferRectKHR = nullptr;
1107CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCommandCopyBufferToImageKHR pfn_clCommandCopyBufferToImageKHR = nullptr;
1108CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCommandCopyImageKHR pfn_clCommandCopyImageKHR = nullptr;
1109CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCommandCopyImageToBufferKHR pfn_clCommandCopyImageToBufferKHR = nullptr;
1110CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCommandFillBufferKHR pfn_clCommandFillBufferKHR = nullptr;
1111CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCommandFillImageKHR pfn_clCommandFillImageKHR = nullptr;
1112CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCommandNDRangeKernelKHR pfn_clCommandNDRangeKernelKHR = nullptr;
1113#endif /* cl_khr_command_buffer */
1114
1115#if defined(cl_khr_command_buffer_mutable_dispatch)
1116CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clUpdateMutableCommandsKHR);
1117CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clGetMutableCommandInfoKHR);
1118
1119CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clUpdateMutableCommandsKHR pfn_clUpdateMutableCommandsKHR = nullptr;
1120CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clGetMutableCommandInfoKHR pfn_clGetMutableCommandInfoKHR = nullptr;
1121#endif /* cl_khr_command_buffer_mutable_dispatch */
1122
1123#if defined(cl_ext_image_requirements_info)
1124CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clGetImageRequirementsInfoEXT);
1125CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clGetImageRequirementsInfoEXT pfn_clGetImageRequirementsInfoEXT = nullptr;
1126#endif
1127
1128#if defined(cl_ext_device_fission)
1129CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_(clCreateSubDevicesEXT);
1130CL_HPP_DEFINE_STATIC_MEMBER_ PFN_clCreateSubDevicesEXT
1131 pfn_clCreateSubDevicesEXT = nullptr;
1132#endif
1133
1134namespace detail {
1135
1136// Generic getInfoHelper. The final parameter is used to guide overload
1137// resolution: the actual parameter passed is an int, which makes this
1138// a worse conversion sequence than a specialization that declares the
1139// parameter as an int.
1140template<typename Functor, typename T>
1141inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long)
1142{
1143 return f(name, sizeof(T), param, nullptr);
1144}
1145
1146// Specialized for getInfo<CL_PROGRAM_BINARIES>
1147// Assumes that the output vector was correctly resized on the way in
1148template <typename Func>
1149inline cl_int getInfoHelper(Func f, cl_uint name, vector<vector<unsigned char>>* param, int)
1150{
1151 if (name != CL_PROGRAM_BINARIES) {
1152 return CL_INVALID_VALUE;
1153 }
1154 if (param) {
1155 // Create array of pointers, calculate total size and pass pointer array in
1156 size_type numBinaries = param->size();
1157 vector<unsigned char*> binariesPointers(numBinaries);
1158
1159 for (size_type i = 0; i < numBinaries; ++i)
1160 {
1161 binariesPointers[i] = (*param)[i].data();
1162 }
1163
1164 cl_int err = f(name, numBinaries * sizeof(unsigned char*), binariesPointers.data(), nullptr);
1165
1166 if (err != CL_SUCCESS) {
1167 return err;
1168 }
1169 }
1170
1171 return CL_SUCCESS;
1172}
1173
1174// Specialized getInfoHelper for vector params
1175template <typename Func, typename T>
1176inline cl_int getInfoHelper(Func f, cl_uint name, vector<T>* param, long)
1177{
1178 size_type required;
1179 cl_int err = f(name, 0, nullptr, &required);
1180 if (err != CL_SUCCESS) {
1181 return err;
1182 }
1183 const size_type elements = required / sizeof(T);
1184
1185 // Temporary to avoid changing param on an error
1186 vector<T> localData(elements);
1187 err = f(name, required, localData.data(), nullptr);
1188 if (err != CL_SUCCESS) {
1189 return err;
1190 }
1191 if (param) {
1192 *param = std::move(localData);
1193 }
1194
1195 return CL_SUCCESS;
1196}
1197
1198/* Specialization for reference-counted types. This depends on the
1199 * existence of Wrapper<T>::cl_type, and none of the other types having the
1200 * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1201 * does not work, because when using a derived type (e.g. Context) the generic
1202 * template will provide a better match.
1203 */
1204template <typename Func, typename T>
1205inline cl_int getInfoHelper(
1206 Func f, cl_uint name, vector<T>* param, int, typename T::cl_type = 0)
1207{
1208 size_type required;
1209 cl_int err = f(name, 0, nullptr, &required);
1210 if (err != CL_SUCCESS) {
1211 return err;
1212 }
1213
1214 const size_type elements = required / sizeof(typename T::cl_type);
1215
1216 vector<typename T::cl_type> value(elements);
1217 err = f(name, required, value.data(), nullptr);
1218 if (err != CL_SUCCESS) {
1219 return err;
1220 }
1221
1222 if (param) {
1223 // Assign to convert CL type to T for each element
1224 param->resize(elements);
1225
1226 // Assign to param, constructing with retain behaviour
1227 // to correctly capture each underlying CL object
1228 for (size_type i = 0; i < elements; i++) {
1229 (*param)[i] = T(value[i], true);
1230 }
1231 }
1232 return CL_SUCCESS;
1233}
1234
1235// Specialized GetInfoHelper for string params
1236template <typename Func>
1237inline cl_int getInfoHelper(Func f, cl_uint name, string* param, long)
1238{
1239 size_type required;
1240 cl_int err = f(name, 0, nullptr, &required);
1241 if (err != CL_SUCCESS) {
1242 return err;
1243 }
1244
1245 // std::string has a constant data member
1246 // a char vector does not
1247 if (required > 0) {
1248 vector<char> value(required);
1249 err = f(name, required, value.data(), nullptr);
1250 if (err != CL_SUCCESS) {
1251 return err;
1252 }
1253 if (param) {
1254 param->assign(value.begin(), value.end() - 1);
1255 }
1256 }
1257 else if (param) {
1258 param->assign("");
1259 }
1260 return CL_SUCCESS;
1261}
1262
1263// Specialized GetInfoHelper for clsize_t params
1264template <typename Func, size_type N>
1265inline cl_int getInfoHelper(Func f, cl_uint name, array<size_type, N>* param, long)
1266{
1267 size_type required;
1268 cl_int err = f(name, 0, nullptr, &required);
1269 if (err != CL_SUCCESS) {
1270 return err;
1271 }
1272
1273 size_type elements = required / sizeof(size_type);
1274 vector<size_type> value(elements, 0);
1275
1276 err = f(name, required, value.data(), nullptr);
1277 if (err != CL_SUCCESS) {
1278 return err;
1279 }
1280
1281 // Bound the copy with N to prevent overruns
1282 // if passed N > than the amount copied
1283 if (elements > N) {
1284 elements = N;
1285 }
1286 for (size_type i = 0; i < elements; ++i) {
1287 (*param)[i] = value[i];
1288 }
1289
1290 return CL_SUCCESS;
1291}
1292
1293template<typename T> struct ReferenceHandler;
1294
1295/* Specialization for reference-counted types. This depends on the
1296 * existence of Wrapper<T>::cl_type, and none of the other types having the
1297 * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1298 * does not work, because when using a derived type (e.g. Context) the generic
1299 * template will provide a better match.
1300 */
1301template<typename Func, typename T>
1302inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0)
1303{
1304 typename T::cl_type value;
1305 cl_int err = f(name, sizeof(value), &value, nullptr);
1306 if (err != CL_SUCCESS) {
1307 return err;
1308 }
1309 *param = value;
1310 if (value != nullptr)
1311 {
1312 err = param->retain();
1313 if (err != CL_SUCCESS) {
1314 return err;
1315 }
1316 }
1317 return CL_SUCCESS;
1318}
1319
1320#define CL_HPP_PARAM_NAME_INFO_1_0_(F) \
1321 F(cl_platform_info, CL_PLATFORM_PROFILE, string) \
1322 F(cl_platform_info, CL_PLATFORM_VERSION, string) \
1323 F(cl_platform_info, CL_PLATFORM_NAME, string) \
1324 F(cl_platform_info, CL_PLATFORM_VENDOR, string) \
1325 F(cl_platform_info, CL_PLATFORM_EXTENSIONS, string) \
1326 \
1327 F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
1328 F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
1329 F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
1330 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
1331 F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, size_type) \
1332 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, cl::vector<size_type>) \
1333 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
1334 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
1335 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
1336 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
1337 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
1338 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
1339 F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
1340 F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \
1341 F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
1342 F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
1343 F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
1344 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, size_type) \
1345 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, size_type) \
1346 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, size_type) \
1347 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, size_type) \
1348 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, size_type) \
1349 F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \
1350 F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, size_type) \
1351 F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
1352 F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
1353 F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
1354 F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
1355 F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
1356 F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
1357 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
1358 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
1359 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
1360 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
1361 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
1362 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
1363 F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
1364 F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
1365 F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
1366 F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, size_type) \
1367 F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
1368 F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
1369 F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
1370 F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
1371 F(cl_device_info, CL_DEVICE_PLATFORM, cl::Platform) \
1372 F(cl_device_info, CL_DEVICE_NAME, string) \
1373 F(cl_device_info, CL_DEVICE_VENDOR, string) \
1374 F(cl_device_info, CL_DRIVER_VERSION, string) \
1375 F(cl_device_info, CL_DEVICE_PROFILE, string) \
1376 F(cl_device_info, CL_DEVICE_VERSION, string) \
1377 F(cl_device_info, CL_DEVICE_EXTENSIONS, string) \
1378 \
1379 F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
1380 F(cl_context_info, CL_CONTEXT_DEVICES, cl::vector<Device>) \
1381 F(cl_context_info, CL_CONTEXT_PROPERTIES, cl::vector<cl_context_properties>) \
1382 \
1383 F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
1384 F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
1385 F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
1386 F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \
1387 \
1388 F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
1389 F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
1390 F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
1391 F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
1392 \
1393 F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
1394 F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
1395 F(cl_mem_info, CL_MEM_SIZE, size_type) \
1396 F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
1397 F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
1398 F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
1399 F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
1400 \
1401 F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
1402 F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, size_type) \
1403 F(cl_image_info, CL_IMAGE_ROW_PITCH, size_type) \
1404 F(cl_image_info, CL_IMAGE_SLICE_PITCH, size_type) \
1405 F(cl_image_info, CL_IMAGE_WIDTH, size_type) \
1406 F(cl_image_info, CL_IMAGE_HEIGHT, size_type) \
1407 F(cl_image_info, CL_IMAGE_DEPTH, size_type) \
1408 \
1409 F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
1410 F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
1411 F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \
1412 F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \
1413 F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \
1414 \
1415 F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
1416 F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
1417 F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
1418 F(cl_program_info, CL_PROGRAM_DEVICES, cl::vector<Device>) \
1419 F(cl_program_info, CL_PROGRAM_SOURCE, string) \
1420 F(cl_program_info, CL_PROGRAM_BINARY_SIZES, cl::vector<size_type>) \
1421 F(cl_program_info, CL_PROGRAM_BINARIES, cl::vector<cl::vector<unsigned char>>) \
1422 \
1423 F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
1424 F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, string) \
1425 F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, string) \
1426 \
1427 F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, string) \
1428 F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
1429 F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
1430 F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
1431 F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
1432 \
1433 F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, size_type) \
1434 F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::detail::size_t_array) \
1435 F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
1436 \
1437 F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
1438 F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
1439 F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
1440 F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
1441
1442
1443#define CL_HPP_PARAM_NAME_INFO_1_1_(F) \
1444 F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
1445 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
1446 F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) \
1447 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
1448 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
1449 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
1450 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
1451 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
1452 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
1453 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
1454 F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, string) \
1455 \
1456 F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
1457 F(cl_mem_info, CL_MEM_OFFSET, size_type) \
1458 \
1459 F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1460 F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
1461 \
1462 F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
1463
1464#define CL_HPP_PARAM_NAME_INFO_1_2_(F) \
1465 F(cl_program_info, CL_PROGRAM_NUM_KERNELS, size_type) \
1466 F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, string) \
1467 \
1468 F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \
1469 \
1470 F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, string) \
1471 \
1472 F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \
1473 F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \
1474 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, string) \
1475 F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, string) \
1476 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \
1477 \
1478 F(cl_kernel_work_group_info, CL_KERNEL_GLOBAL_WORK_SIZE, cl::detail::size_t_array) \
1479 \
1480 F(cl_device_info, CL_DEVICE_LINKER_AVAILABLE, cl_bool) \
1481 F(cl_device_info, CL_DEVICE_IMAGE_MAX_BUFFER_SIZE, size_type) \
1482 F(cl_device_info, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, size_type) \
1483 F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl::Device) \
1484 F(cl_device_info, CL_DEVICE_PARTITION_MAX_SUB_DEVICES, cl_uint) \
1485 F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, cl::vector<cl_device_partition_property>) \
1486 F(cl_device_info, CL_DEVICE_PARTITION_TYPE, cl::vector<cl_device_partition_property>) \
1487 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \
1488 F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, cl_bool) \
1489 F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \
1490 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, string) \
1491 F(cl_device_info, CL_DEVICE_PRINTF_BUFFER_SIZE, size_type) \
1492 \
1493 F(cl_image_info, CL_IMAGE_ARRAY_SIZE, size_type) \
1494 F(cl_image_info, CL_IMAGE_NUM_MIP_LEVELS, cl_uint) \
1495 F(cl_image_info, CL_IMAGE_NUM_SAMPLES, cl_uint)
1496
1497#define CL_HPP_PARAM_NAME_INFO_2_0_(F) \
1498 F(cl_device_info, CL_DEVICE_QUEUE_ON_HOST_PROPERTIES, cl_command_queue_properties) \
1499 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES, cl_command_queue_properties) \
1500 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, cl_uint) \
1501 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, cl_uint) \
1502 F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_QUEUES, cl_uint) \
1503 F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_EVENTS, cl_uint) \
1504 F(cl_device_info, CL_DEVICE_MAX_PIPE_ARGS, cl_uint) \
1505 F(cl_device_info, CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS, cl_uint) \
1506 F(cl_device_info, CL_DEVICE_PIPE_MAX_PACKET_SIZE, cl_uint) \
1507 F(cl_device_info, CL_DEVICE_SVM_CAPABILITIES, cl_device_svm_capabilities) \
1508 F(cl_device_info, CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT, cl_uint) \
1509 F(cl_device_info, CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT, cl_uint) \
1510 F(cl_device_info, CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT, cl_uint) \
1511 F(cl_device_info, CL_DEVICE_IMAGE_PITCH_ALIGNMENT, cl_uint) \
1512 F(cl_device_info, CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT, cl_uint) \
1513 F(cl_device_info, CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS, cl_uint ) \
1514 F(cl_device_info, CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE, size_type ) \
1515 F(cl_device_info, CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE, size_type ) \
1516 F(cl_profiling_info, CL_PROFILING_COMMAND_COMPLETE, cl_ulong) \
1517 F(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM, cl_bool) \
1518 F(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_SVM_PTRS, void**) \
1519 F(cl_command_queue_info, CL_QUEUE_SIZE, cl_uint) \
1520 F(cl_mem_info, CL_MEM_USES_SVM_POINTER, cl_bool) \
1521 F(cl_program_build_info, CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, size_type) \
1522 F(cl_pipe_info, CL_PIPE_PACKET_SIZE, cl_uint) \
1523 F(cl_pipe_info, CL_PIPE_MAX_PACKETS, cl_uint)
1524
1525#define CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(F) \
1526 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR, size_type) \
1527 F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR, size_type)
1528
1529#define CL_HPP_PARAM_NAME_INFO_IL_KHR_(F) \
1530 F(cl_device_info, CL_DEVICE_IL_VERSION_KHR, string) \
1531 F(cl_program_info, CL_PROGRAM_IL_KHR, cl::vector<unsigned char>)
1532
1533#define CL_HPP_PARAM_NAME_INFO_2_1_(F) \
1534 F(cl_platform_info, CL_PLATFORM_HOST_TIMER_RESOLUTION, cl_ulong) \
1535 F(cl_program_info, CL_PROGRAM_IL, cl::vector<unsigned char>) \
1536 F(cl_device_info, CL_DEVICE_MAX_NUM_SUB_GROUPS, cl_uint) \
1537 F(cl_device_info, CL_DEVICE_IL_VERSION, string) \
1538 F(cl_device_info, CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS, cl_bool) \
1539 F(cl_command_queue_info, CL_QUEUE_DEVICE_DEFAULT, cl::DeviceCommandQueue) \
1540 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE, size_type) \
1541 F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE, size_type) \
1542 F(cl_kernel_sub_group_info, CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT, cl::detail::size_t_array) \
1543 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_NUM_SUB_GROUPS, size_type) \
1544 F(cl_kernel_sub_group_info, CL_KERNEL_COMPILE_NUM_SUB_GROUPS, size_type)
1545
1546#define CL_HPP_PARAM_NAME_INFO_2_2_(F) \
1547 F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_CTORS_PRESENT, cl_bool) \
1548 F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_DTORS_PRESENT, cl_bool)
1549
1550#define CL_HPP_PARAM_NAME_DEVICE_FISSION_EXT_(F) \
1551 F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl::Device) \
1552 F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, cl::vector<cl_device_partition_property_ext>) \
1553 F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, cl::vector<cl_device_partition_property_ext>) \
1554 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
1555 F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, cl::vector<cl_device_partition_property_ext>)
1556
1557#define CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_CL3_SHARED_(F) \
1558 F(cl_platform_info, CL_PLATFORM_NUMERIC_VERSION_KHR, cl_version_khr) \
1559 F(cl_platform_info, CL_PLATFORM_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1560 \
1561 F(cl_device_info, CL_DEVICE_NUMERIC_VERSION_KHR, cl_version_khr) \
1562 F(cl_device_info, CL_DEVICE_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1563 F(cl_device_info, CL_DEVICE_ILS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1564 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>)
1565
1566#define CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_KHRONLY_(F) \
1567 F(cl_device_info, CL_DEVICE_OPENCL_C_NUMERIC_VERSION_KHR, cl_version_khr)
1568
1569// Note: the query for CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR is handled specially!
1570#define CL_HPP_PARAM_NAME_CL_KHR_SEMAPHORE_(F) \
1571 F(cl_semaphore_info_khr, CL_SEMAPHORE_CONTEXT_KHR, cl::Context) \
1572 F(cl_semaphore_info_khr, CL_SEMAPHORE_REFERENCE_COUNT_KHR, cl_uint) \
1573 F(cl_semaphore_info_khr, CL_SEMAPHORE_PROPERTIES_KHR, cl::vector<cl_semaphore_properties_khr>) \
1574 F(cl_semaphore_info_khr, CL_SEMAPHORE_TYPE_KHR, cl_semaphore_type_khr) \
1575 F(cl_semaphore_info_khr, CL_SEMAPHORE_PAYLOAD_KHR, cl_semaphore_payload_khr) \
1576 F(cl_platform_info, CL_PLATFORM_SEMAPHORE_TYPES_KHR, cl::vector<cl_semaphore_type_khr>) \
1577 F(cl_device_info, CL_DEVICE_SEMAPHORE_TYPES_KHR, cl::vector<cl_semaphore_type_khr>) \
1578
1579#define CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_MEMORY_(F) \
1580 F(cl_device_info, CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR, cl::vector<cl::ExternalMemoryType>) \
1581 F(cl_platform_info, CL_PLATFORM_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR, cl::vector<cl::ExternalMemoryType>)
1582
1583#define CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_(F) \
1584 F(cl_platform_info, CL_PLATFORM_SEMAPHORE_IMPORT_HANDLE_TYPES_KHR, cl::vector<cl_external_semaphore_handle_type_khr>) \
1585 F(cl_platform_info, CL_PLATFORM_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR, cl::vector<cl_external_semaphore_handle_type_khr>) \
1586 F(cl_device_info, CL_DEVICE_SEMAPHORE_IMPORT_HANDLE_TYPES_KHR, cl::vector<cl_external_semaphore_handle_type_khr>) \
1587 F(cl_device_info, CL_DEVICE_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR, cl::vector<cl_external_semaphore_handle_type_khr>) \
1588 F(cl_semaphore_info_khr, CL_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR, cl::vector<cl_external_semaphore_handle_type_khr>) \
1589
1590#define CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_DX_FENCE_EXT(F) \
1591 F(cl_external_semaphore_handle_type_khr, CL_SEMAPHORE_HANDLE_D3D12_FENCE_KHR, void*) \
1592
1593#define CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_OPAQUE_FD_EXT(F) \
1594 F(cl_external_semaphore_handle_type_khr, CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR, int) \
1595
1596#define CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_SYNC_FD_EXT(F) \
1597 F(cl_external_semaphore_handle_type_khr, CL_SEMAPHORE_HANDLE_SYNC_FD_KHR, int) \
1598
1599#define CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_WIN32_EXT(F) \
1600 F(cl_external_semaphore_handle_type_khr, CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR, void*) \
1601 F(cl_external_semaphore_handle_type_khr, CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KMT_KHR, void*) \
1602
1603#define CL_HPP_PARAM_NAME_INFO_3_0_(F) \
1604 F(cl_platform_info, CL_PLATFORM_NUMERIC_VERSION, cl_version) \
1605 F(cl_platform_info, CL_PLATFORM_EXTENSIONS_WITH_VERSION, cl::vector<cl_name_version>) \
1606 \
1607 F(cl_device_info, CL_DEVICE_NUMERIC_VERSION, cl_version) \
1608 F(cl_device_info, CL_DEVICE_EXTENSIONS_WITH_VERSION, cl::vector<cl_name_version>) \
1609 F(cl_device_info, CL_DEVICE_ILS_WITH_VERSION, cl::vector<cl_name_version>) \
1610 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION, cl::vector<cl_name_version>) \
1611 F(cl_device_info, CL_DEVICE_ATOMIC_MEMORY_CAPABILITIES, cl_device_atomic_capabilities) \
1612 F(cl_device_info, CL_DEVICE_ATOMIC_FENCE_CAPABILITIES, cl_device_atomic_capabilities) \
1613 F(cl_device_info, CL_DEVICE_NON_UNIFORM_WORK_GROUP_SUPPORT, cl_bool) \
1614 F(cl_device_info, CL_DEVICE_OPENCL_C_ALL_VERSIONS, cl::vector<cl_name_version>) \
1615 F(cl_device_info, CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1616 F(cl_device_info, CL_DEVICE_WORK_GROUP_COLLECTIVE_FUNCTIONS_SUPPORT, cl_bool) \
1617 F(cl_device_info, CL_DEVICE_GENERIC_ADDRESS_SPACE_SUPPORT, cl_bool) \
1618 F(cl_device_info, CL_DEVICE_OPENCL_C_FEATURES, cl::vector<cl_name_version>) \
1619 F(cl_device_info, CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES, cl_device_device_enqueue_capabilities) \
1620 F(cl_device_info, CL_DEVICE_PIPE_SUPPORT, cl_bool) \
1621 F(cl_device_info, CL_DEVICE_LATEST_CONFORMANCE_VERSION_PASSED, string) \
1622 \
1623 F(cl_command_queue_info, CL_QUEUE_PROPERTIES_ARRAY, cl::vector<cl_queue_properties>) \
1624 F(cl_mem_info, CL_MEM_PROPERTIES, cl::vector<cl_mem_properties>) \
1625 F(cl_pipe_info, CL_PIPE_PROPERTIES, cl::vector<cl_pipe_properties>) \
1626 F(cl_sampler_info, CL_SAMPLER_PROPERTIES, cl::vector<cl_sampler_properties>) \
1627
1628#define CL_HPP_PARAM_NAME_CL_IMAGE_REQUIREMENTS_EXT(F) \
1629 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_ROW_PITCH_ALIGNMENT_EXT, size_type) \
1630 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_BASE_ADDRESS_ALIGNMENT_EXT, size_type) \
1631 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_SIZE_EXT, size_type) \
1632 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_MAX_WIDTH_EXT, cl_uint) \
1633 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_MAX_HEIGHT_EXT, cl_uint) \
1634 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_MAX_DEPTH_EXT, cl_uint) \
1635 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_MAX_ARRAY_SIZE_EXT, cl_uint) \
1636
1637#define CL_HPP_PARAM_NAME_CL_IMAGE_REQUIREMENTS_SLICE_PITCH_ALIGNMENT_EXT(F) \
1638 F(cl_image_requirements_info_ext, CL_IMAGE_REQUIREMENTS_SLICE_PITCH_ALIGNMENT_EXT, size_type) \
1639
1640#define CL_HPP_PARAM_NAME_CL_INTEL_COMMAND_QUEUE_FAMILIES_(F) \
1641 F(cl_device_info, CL_DEVICE_QUEUE_FAMILY_PROPERTIES_INTEL, cl::vector<cl_queue_family_properties_intel>) \
1642 \
1643 F(cl_command_queue_info, CL_QUEUE_FAMILY_INTEL, cl_uint) \
1644 F(cl_command_queue_info, CL_QUEUE_INDEX_INTEL, cl_uint)
1645
1646#define CL_HPP_PARAM_NAME_CL_INTEL_UNIFIED_SHARED_MEMORY_(F) \
1647 F(cl_device_info, CL_DEVICE_HOST_MEM_CAPABILITIES_INTEL, cl_device_unified_shared_memory_capabilities_intel ) \
1648 F(cl_device_info, CL_DEVICE_DEVICE_MEM_CAPABILITIES_INTEL, cl_device_unified_shared_memory_capabilities_intel ) \
1649 F(cl_device_info, CL_DEVICE_SINGLE_DEVICE_SHARED_MEM_CAPABILITIES_INTEL, cl_device_unified_shared_memory_capabilities_intel ) \
1650 F(cl_device_info, CL_DEVICE_CROSS_DEVICE_SHARED_MEM_CAPABILITIES_INTEL, cl_device_unified_shared_memory_capabilities_intel ) \
1651 F(cl_device_info, CL_DEVICE_SHARED_SYSTEM_MEM_CAPABILITIES_INTEL, cl_device_unified_shared_memory_capabilities_intel )
1652
1653template <typename enum_type, cl_int Name>
1654struct param_traits {};
1655
1656#define CL_HPP_DECLARE_PARAM_TRAITS_(token, param_name, T) \
1657struct token; \
1658template<> \
1659struct param_traits<detail:: token,param_name> \
1660{ \
1661 enum { value = param_name }; \
1662 typedef T param_type; \
1663};
1664
1665CL_HPP_PARAM_NAME_INFO_1_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1666#if CL_HPP_TARGET_OPENCL_VERSION >= 110
1667CL_HPP_PARAM_NAME_INFO_1_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1668#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
1669#if CL_HPP_TARGET_OPENCL_VERSION >= 120
1670CL_HPP_PARAM_NAME_INFO_1_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1671#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1672#if CL_HPP_TARGET_OPENCL_VERSION >= 200
1673CL_HPP_PARAM_NAME_INFO_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1674#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
1675#if CL_HPP_TARGET_OPENCL_VERSION >= 210
1676CL_HPP_PARAM_NAME_INFO_2_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1677#endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
1678#if CL_HPP_TARGET_OPENCL_VERSION >= 220
1679CL_HPP_PARAM_NAME_INFO_2_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1680#endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
1681#if CL_HPP_TARGET_OPENCL_VERSION >= 300
1682CL_HPP_PARAM_NAME_INFO_3_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1683#endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
1684
1685#if defined(cl_khr_subgroups) && CL_HPP_TARGET_OPENCL_VERSION < 210
1686CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1687#endif // #if defined(cl_khr_subgroups) && CL_HPP_TARGET_OPENCL_VERSION < 210
1688
1689#if defined(cl_khr_il_program) && CL_HPP_TARGET_OPENCL_VERSION < 210
1690CL_HPP_PARAM_NAME_INFO_IL_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1691#endif // #if defined(cl_khr_il_program) && CL_HPP_TARGET_OPENCL_VERSION < 210
1692
1693
1694// Flags deprecated in OpenCL 2.0
1695#define CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(F) \
1696 F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties)
1697
1698#define CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(F) \
1699 F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer)
1700
1701// Include deprecated query flags based on versions
1702// Only include deprecated 1.0 flags if 2.0 not active as there is an enum clash
1703#if CL_HPP_TARGET_OPENCL_VERSION > 100 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 && CL_HPP_TARGET_OPENCL_VERSION < 200
1704CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1705#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 110
1706#if CL_HPP_TARGET_OPENCL_VERSION > 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1707CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1708#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
1709
1710#if defined(cl_ext_device_fission)
1711CL_HPP_PARAM_NAME_DEVICE_FISSION_EXT_(CL_HPP_DECLARE_PARAM_TRAITS_)
1712#endif // cl_ext_device_fission
1713
1714#if defined(cl_khr_extended_versioning)
1715#if CL_HPP_TARGET_OPENCL_VERSION < 300
1716CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_CL3_SHARED_(CL_HPP_DECLARE_PARAM_TRAITS_)
1717#endif // CL_HPP_TARGET_OPENCL_VERSION < 300
1718CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_KHRONLY_(CL_HPP_DECLARE_PARAM_TRAITS_)
1719#endif // cl_khr_extended_versioning
1720
1721#if defined(cl_khr_semaphore)
1722CL_HPP_PARAM_NAME_CL_KHR_SEMAPHORE_(CL_HPP_DECLARE_PARAM_TRAITS_)
1723#if defined(CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR)
1724CL_HPP_DECLARE_PARAM_TRAITS_(cl_semaphore_info_khr, CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR, cl::vector<cl::Device>)
1725#endif // defined(CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR)
1726#endif // defined(cl_khr_semaphore)
1727
1728#ifdef cl_khr_external_memory
1729CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_MEMORY_(CL_HPP_DECLARE_PARAM_TRAITS_)
1730#endif // cl_khr_external_memory
1731
1732#if defined(cl_khr_external_semaphore)
1733CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_(CL_HPP_DECLARE_PARAM_TRAITS_)
1734#endif // cl_khr_external_semaphore
1735
1736#if defined(cl_khr_external_semaphore_dx_fence)
1737CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_DX_FENCE_EXT(CL_HPP_DECLARE_PARAM_TRAITS_)
1738#endif // cl_khr_external_semaphore_dx_fence
1739#if defined(cl_khr_external_semaphore_opaque_fd)
1740CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_OPAQUE_FD_EXT(CL_HPP_DECLARE_PARAM_TRAITS_)
1741#endif // cl_khr_external_semaphore_opaque_fd
1742#if defined(cl_khr_external_semaphore_sync_fd)
1743CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_SYNC_FD_EXT(CL_HPP_DECLARE_PARAM_TRAITS_)
1744#endif // cl_khr_external_semaphore_sync_fd
1745#if defined(cl_khr_external_semaphore_win32)
1746CL_HPP_PARAM_NAME_CL_KHR_EXTERNAL_SEMAPHORE_WIN32_EXT(CL_HPP_DECLARE_PARAM_TRAITS_)
1747#endif // cl_khr_external_semaphore_win32
1748
1749#if defined(cl_khr_device_uuid)
1750using uuid_array = array<cl_uchar, CL_UUID_SIZE_KHR>;
1751using luid_array = array<cl_uchar, CL_LUID_SIZE_KHR>;
1752CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_UUID_KHR, uuid_array)
1753CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DRIVER_UUID_KHR, uuid_array)
1754CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LUID_VALID_KHR, cl_bool)
1755CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LUID_KHR, luid_array)
1756CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_NODE_MASK_KHR, cl_uint)
1757#endif
1758
1759#if defined(cl_khr_pci_bus_info)
1760CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PCI_BUS_INFO_KHR, cl_device_pci_bus_info_khr)
1761#endif
1762
1763// Note: some headers do not define cl_khr_image2d_from_buffer
1764#if CL_HPP_TARGET_OPENCL_VERSION < 200
1765#if defined(CL_DEVICE_IMAGE_PITCH_ALIGNMENT_KHR)
1766CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_IMAGE_PITCH_ALIGNMENT_KHR, cl_uint)
1767#endif
1768#if defined(CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT_KHR)
1769CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT_KHR, cl_uint)
1770#endif
1771#endif // CL_HPP_TARGET_OPENCL_VERSION < 200
1772
1773#if defined(cl_khr_integer_dot_product)
1774CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGER_DOT_PRODUCT_CAPABILITIES_KHR, cl_device_integer_dot_product_capabilities_khr)
1775#if defined(CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_8BIT_KHR)
1776CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_8BIT_KHR, cl_device_integer_dot_product_acceleration_properties_khr)
1777CL_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)
1778#endif // defined(CL_DEVICE_INTEGER_DOT_PRODUCT_ACCELERATION_PROPERTIES_8BIT_KHR)
1779#endif // defined(cl_khr_integer_dot_product)
1780
1781#if defined(cl_ext_image_requirements_info)
1782CL_HPP_PARAM_NAME_CL_IMAGE_REQUIREMENTS_EXT(CL_HPP_DECLARE_PARAM_TRAITS_)
1783#endif // cl_ext_image_requirements_info
1784
1785#if defined(cl_ext_image_from_buffer)
1786CL_HPP_PARAM_NAME_CL_IMAGE_REQUIREMENTS_SLICE_PITCH_ALIGNMENT_EXT(CL_HPP_DECLARE_PARAM_TRAITS_)
1787#endif // cl_ext_image_from_buffer
1788
1789#ifdef CL_PLATFORM_ICD_SUFFIX_KHR
1790CL_HPP_DECLARE_PARAM_TRAITS_(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, string)
1791#endif
1792
1793#ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
1794CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong)
1795#endif
1796#ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
1797CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, vector<size_type>)
1798#endif
1799#ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
1800CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint)
1801#endif
1802#ifdef CL_DEVICE_SIMD_WIDTH_AMD
1803CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint)
1804#endif
1805#ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD
1806CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint)
1807#endif
1808#ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD
1809CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint)
1810#endif
1811#ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
1812CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint)
1813#endif
1814#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
1815CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint)
1816#endif
1817#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
1818CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint)
1819#endif
1820#ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
1821CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint)
1822#endif
1823#ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
1824CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint)
1825#endif
1826#ifdef CL_DEVICE_BOARD_NAME_AMD
1827CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_BOARD_NAME_AMD, string)
1828#endif
1829
1830#ifdef CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM
1831CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM, cl_ulong)
1832#endif
1833#ifdef CL_DEVICE_JOB_SLOTS_ARM
1834CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_JOB_SLOTS_ARM, cl_uint)
1835#endif
1836#ifdef CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM
1837CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM, cl_bitfield)
1838#endif
1839#ifdef CL_DEVICE_SUPPORTED_REGISTER_ALLOCATIONS_ARM
1840CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SUPPORTED_REGISTER_ALLOCATIONS_ARM, vector<cl_uint>)
1841#endif
1842#ifdef CL_DEVICE_MAX_WARP_COUNT_ARM
1843CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_MAX_WARP_COUNT_ARM, cl_uint)
1844#endif
1845#ifdef CL_KERNEL_MAX_WARP_COUNT_ARM
1846CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_info, CL_KERNEL_MAX_WARP_COUNT_ARM, cl_uint)
1847#endif
1848#ifdef CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_ARM
1849CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_ARM, cl_uint)
1850#endif
1851#ifdef CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM
1852CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM, cl_int)
1853#endif
1854#ifdef CL_KERNEL_EXEC_INFO_WARP_COUNT_LIMIT_ARM
1855CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WARP_COUNT_LIMIT_ARM, cl_uint)
1856#endif
1857#ifdef CL_KERNEL_EXEC_INFO_COMPUTE_UNIT_MAX_QUEUED_BATCHES_ARM
1858CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_COMPUTE_UNIT_MAX_QUEUED_BATCHES_ARM, cl_uint)
1859#endif
1860
1861#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
1862CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint)
1863#endif
1864#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV
1865CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint)
1866#endif
1867#ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV
1868CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint)
1869#endif
1870#ifdef CL_DEVICE_WARP_SIZE_NV
1871CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint)
1872#endif
1873#ifdef CL_DEVICE_GPU_OVERLAP_NV
1874CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool)
1875#endif
1876#ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV
1877CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool)
1878#endif
1879#ifdef CL_DEVICE_INTEGRATED_MEMORY_NV
1880CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool)
1881#endif
1882
1883#if defined(cl_khr_command_buffer)
1884CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMMAND_BUFFER_CAPABILITIES_KHR, cl_device_command_buffer_capabilities_khr)
1885#if CL_KHR_COMMAND_BUFFER_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 5)
1886CL_HPP_DECLARE_PARAM_TRAITS_(
1887 cl_device_info, CL_DEVICE_COMMAND_BUFFER_SUPPORTED_QUEUE_PROPERTIES_KHR,
1888 cl_command_queue_properties)
1889#endif
1890CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMMAND_BUFFER_REQUIRED_QUEUE_PROPERTIES_KHR, cl_command_queue_properties)
1891CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_QUEUES_KHR, cl::vector<CommandQueue>)
1892CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_NUM_QUEUES_KHR, cl_uint)
1893CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_REFERENCE_COUNT_KHR, cl_uint)
1894CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_STATE_KHR, cl_command_buffer_state_khr)
1895CL_HPP_DECLARE_PARAM_TRAITS_(cl_command_buffer_info_khr, CL_COMMAND_BUFFER_PROPERTIES_ARRAY_KHR, cl::vector<cl_command_buffer_properties_khr>)
1896#endif /* cl_khr_command_buffer */
1897
1898#if defined(cl_khr_command_buffer_mutable_dispatch)
1899CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_COMMAND_COMMAND_QUEUE_KHR, CommandQueue)
1900CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_COMMAND_COMMAND_BUFFER_KHR, CommandBufferKhr)
1901CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_COMMAND_COMMAND_TYPE_KHR, cl_command_type)
1902
1903#if CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 2)
1904CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_COMMAND_PROPERTIES_ARRAY_KHR, cl::vector<cl_command_properties_khr>)
1905#else
1906CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_PROPERTIES_ARRAY_KHR, cl::vector<cl_ndrange_kernel_command_properties_khr>)
1907#endif
1908CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_KERNEL_KHR, cl_kernel)
1909CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_DIMENSIONS_KHR, cl_uint)
1910CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_GLOBAL_WORK_OFFSET_KHR, cl::vector<size_type>)
1911CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_GLOBAL_WORK_SIZE_KHR, cl::vector<size_type>)
1912CL_HPP_DECLARE_PARAM_TRAITS_(cl_mutable_command_info_khr, CL_MUTABLE_DISPATCH_LOCAL_WORK_SIZE_KHR, cl::vector<size_type>)
1913#endif /* cl_khr_command_buffer_mutable_dispatch */
1914
1915#if defined(cl_khr_kernel_clock)
1916CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_CLOCK_CAPABILITIES_KHR, cl_device_kernel_clock_capabilities_khr)
1917#endif /* cl_khr_kernel_clock */
1918
1919#if defined(cl_khr_spirv_queries)
1920CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SPIRV_EXTENDED_INSTRUCTION_SETS_KHR, cl::vector<const char*>)
1921CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SPIRV_EXTENSIONS_KHR, cl::vector<const char*>)
1922CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SPIRV_CAPABILITIES_KHR, cl::vector<cl_uint>)
1923#endif /* cl_khr_spirv_queries */
1924
1925#if defined(cl_ext_float_atomics)
1926CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SINGLE_FP_ATOMIC_CAPABILITIES_EXT, cl_device_fp_atomic_capabilities_ext)
1927CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_DOUBLE_FP_ATOMIC_CAPABILITIES_EXT, cl_device_fp_atomic_capabilities_ext)
1928CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_HALF_FP_ATOMIC_CAPABILITIES_EXT, cl_device_fp_atomic_capabilities_ext)
1929#endif /* cl_ext_float_atomics */
1930
1931#if defined(cl_intel_command_queue_families)
1932CL_HPP_PARAM_NAME_CL_INTEL_COMMAND_QUEUE_FAMILIES_(CL_HPP_DECLARE_PARAM_TRAITS_)
1933#endif // cl_intel_command_queue_families
1934
1935#if defined(cl_intel_device_attribute_query)
1936CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_IP_VERSION_INTEL, cl_uint)
1937CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_ID_INTEL, cl_uint)
1938CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_NUM_SLICES_INTEL, cl_uint)
1939CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_NUM_SUB_SLICES_PER_SLICE_INTEL, cl_uint)
1940CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_NUM_EUS_PER_SUB_SLICE_INTEL, cl_uint)
1941CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_NUM_THREADS_PER_EU_INTEL, cl_uint)
1942CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_FEATURE_CAPABILITIES_INTEL, cl_device_feature_capabilities_intel)
1943#endif // cl_intel_device_attribute_query
1944
1945#if defined(cl_intel_required_subgroup_size)
1946CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SUB_GROUP_SIZES_INTEL, cl::vector<size_type>)
1947CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_work_group_info, CL_KERNEL_SPILL_MEM_SIZE_INTEL, cl_ulong)
1948#endif // cl_intel_required_subgroup_size
1949
1950#if defined(cl_intel_unified_shared_memory)
1951CL_HPP_PARAM_NAME_CL_INTEL_UNIFIED_SHARED_MEMORY_(CL_HPP_DECLARE_PARAM_TRAITS_)
1952#endif // cl_intel_unified_shared_memory
1953
1954// Convenience functions
1955
1956template <typename Func, typename T>
1957inline cl_int
1958getInfo(Func f, cl_uint name, T* param)
1959{
1960 return getInfoHelper(f, name, param, 0);
1961}
1962
1963template <typename Func, typename Arg0>
1964struct GetInfoFunctor0
1965{
1966 Func f_; const Arg0& arg0_;
1967 cl_int operator ()(
1968 cl_uint param, size_type size, void* value, size_type* size_ret)
1969 { return f_(arg0_, param, size, value, size_ret); }
1970};
1971
1972template <typename Func, typename Arg0, typename Arg1>
1973struct GetInfoFunctor1
1974{
1975 Func f_; const Arg0& arg0_; const Arg1& arg1_;
1976 cl_int operator ()(
1977 cl_uint param, size_type size, void* value, size_type* size_ret)
1978 { return f_(arg0_, arg1_, param, size, value, size_ret); }
1979};
1980
1981template <typename Func, typename Arg0, typename T>
1982inline cl_int
1983getInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
1984{
1985 GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
1986 return getInfoHelper(f0, name, param, 0);
1987}
1988
1989template <typename Func, typename Arg0, typename Arg1, typename T>
1990inline cl_int
1991getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
1992{
1993 GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
1994 return getInfoHelper(f0, name, param, 0);
1996
1997
1998template<typename T>
1999struct ReferenceHandler
2000{ };
2001
2002#if CL_HPP_TARGET_OPENCL_VERSION >= 120
2004 * OpenCL 1.2 devices do have retain/release.
2005 */
2006template <>
2007struct ReferenceHandler<cl_device_id>
2008{
2014 * CL_INVALID_DEVICE if device was not a valid subdevice
2015 * CL_OUT_OF_RESOURCES
2016 * CL_OUT_OF_HOST_MEMORY
2017 */
2018 static cl_int retain(cl_device_id device)
2019 { return CL_(clRetainDevice)(device); }
2025 * CL_INVALID_DEVICE if device was not a valid subdevice
2026 * CL_OUT_OF_RESOURCES
2027 * CL_OUT_OF_HOST_MEMORY
2028 */
2029 static cl_int release(cl_device_id device)
2030 { return CL_(clReleaseDevice)(device); }
2031};
2032#else // CL_HPP_TARGET_OPENCL_VERSION >= 120
2036template <>
2037struct ReferenceHandler<cl_device_id>
2038{
2039 // cl_device_id does not have retain().
2040 static cl_int retain(cl_device_id)
2041 { return CL_SUCCESS; }
2042 // cl_device_id does not have release().
2043 static cl_int release(cl_device_id)
2044 { return CL_SUCCESS; }
2046#endif // ! (CL_HPP_TARGET_OPENCL_VERSION >= 120)
2047
2048template <>
2049struct ReferenceHandler<cl_platform_id>
2050{
2051 // cl_platform_id does not have retain().
2052 static cl_int retain(cl_platform_id)
2053 { return CL_SUCCESS; }
2054 // cl_platform_id does not have release().
2055 static cl_int release(cl_platform_id)
2056 { return CL_SUCCESS; }
2057};
2058
2059template <>
2060struct ReferenceHandler<cl_context>
2061{
2062 static cl_int retain(cl_context context)
2063 { return CL_(clRetainContext)(context); }
2064 static cl_int release(cl_context context)
2065 { return CL_(clReleaseContext)(context); }
2066};
2067
2068template <>
2069struct ReferenceHandler<cl_command_queue>
2070{
2071 static cl_int retain(cl_command_queue queue)
2072 { return CL_(clRetainCommandQueue)(queue); }
2073 static cl_int release(cl_command_queue queue)
2074 { return CL_(clReleaseCommandQueue)(queue); }
2075};
2076
2077template <>
2078struct ReferenceHandler<cl_mem>
2079{
2080 static cl_int retain(cl_mem memory)
2081 { return CL_(clRetainMemObject)(memory); }
2082 static cl_int release(cl_mem memory)
2083 { return CL_(clReleaseMemObject)(memory); }
2084};
2085
2086template <>
2087struct ReferenceHandler<cl_sampler>
2088{
2089 static cl_int retain(cl_sampler sampler)
2090 { return CL_(clRetainSampler)(sampler); }
2091 static cl_int release(cl_sampler sampler)
2092 { return CL_(clReleaseSampler)(sampler); }
2093};
2094
2095template <>
2096struct ReferenceHandler<cl_program>
2097{
2098 static cl_int retain(cl_program program)
2099 { return CL_(clRetainProgram)(program); }
2100 static cl_int release(cl_program program)
2101 { return CL_(clReleaseProgram)(program); }
2102};
2103
2104template <>
2105struct ReferenceHandler<cl_kernel>
2106{
2107 static cl_int retain(cl_kernel kernel)
2108 { return CL_(clRetainKernel)(kernel); }
2109 static cl_int release(cl_kernel kernel)
2110 { return CL_(clReleaseKernel)(kernel); }
2111};
2112
2113template <>
2114struct ReferenceHandler<cl_event>
2115{
2116 static cl_int retain(cl_event event)
2117 { return CL_(clRetainEvent)(event); }
2118 static cl_int release(cl_event event)
2119 { return CL_(clReleaseEvent)(event); }
2120};
2121
2122#ifdef cl_khr_semaphore
2123template <>
2124struct ReferenceHandler<cl_semaphore_khr>
2125{
2126 static cl_int retain(cl_semaphore_khr semaphore)
2127 {
2128 if (pfn_clRetainSemaphoreKHR != nullptr) {
2129 return pfn_clRetainSemaphoreKHR(semaphore);
2130 }
2131
2132 return CL_INVALID_OPERATION;
2133 }
2134
2135 static cl_int release(cl_semaphore_khr semaphore)
2136 {
2137 if (pfn_clReleaseSemaphoreKHR != nullptr) {
2138 return pfn_clReleaseSemaphoreKHR(semaphore);
2139 }
2140
2141 return CL_INVALID_OPERATION;
2142 }
2143};
2144#endif // cl_khr_semaphore
2145#if defined(cl_khr_command_buffer)
2146template <>
2147struct ReferenceHandler<cl_command_buffer_khr>
2148{
2149 static cl_int retain(cl_command_buffer_khr cmdBufferKhr)
2150 {
2151 if (pfn_clRetainCommandBufferKHR == nullptr) {
2152 return detail::errHandler(CL_INVALID_OPERATION, __RETAIN_COMMAND_BUFFER_KHR_ERR);
2153 }
2154 return pfn_clRetainCommandBufferKHR(cmdBufferKhr);
2155 }
2156
2157 static cl_int release(cl_command_buffer_khr cmdBufferKhr)
2158 {
2159 if (pfn_clReleaseCommandBufferKHR == nullptr) {
2160 return detail::errHandler(CL_INVALID_OPERATION, __RELEASE_COMMAND_BUFFER_KHR_ERR);
2161 }
2162 return pfn_clReleaseCommandBufferKHR(cmdBufferKhr);
2163 }
2164};
2165
2166template <>
2167struct ReferenceHandler<cl_mutable_command_khr>
2168{
2169 // cl_mutable_command_khr does not have retain().
2170 static cl_int retain(cl_mutable_command_khr)
2171 { return CL_SUCCESS; }
2172 // cl_mutable_command_khr does not have release().
2173 static cl_int release(cl_mutable_command_khr)
2174 { return CL_SUCCESS; }
2175};
2176#endif // cl_khr_command_buffer
2177
2178
2179#if (CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120) || \
2180 (CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200)
2181// Extracts version number with major in the upper 16 bits, minor in the lower 16
2182static cl_uint getVersion(const vector<char> &versionInfo)
2183{
2184 int highVersion = 0;
2185 int lowVersion = 0;
2186 int index = 7;
2187 while(versionInfo[index] != '.' ) {
2188 highVersion *= 10;
2189 highVersion += versionInfo[index]-'0';
2190 ++index;
2191 }
2192 ++index;
2193 while(versionInfo[index] != ' ' && versionInfo[index] != '\0') {
2194 lowVersion *= 10;
2195 lowVersion += versionInfo[index]-'0';
2196 ++index;
2197 }
2198 return (highVersion << 16) | lowVersion;
2199}
2200
2201static cl_uint getPlatformVersion(cl_platform_id platform)
2202{
2203 size_type size = 0;
2204 CL_(clGetPlatformInfo)(platform, CL_PLATFORM_VERSION, 0, nullptr, &size);
2205
2206 vector<char> versionInfo(size);
2207 CL_(clGetPlatformInfo)(platform, CL_PLATFORM_VERSION, size, versionInfo.data(), &size);
2208 return getVersion(versionInfo);
2209}
2210
2211static cl_uint getDevicePlatformVersion(cl_device_id device)
2212{
2213 cl_platform_id platform;
2214 CL_(clGetDeviceInfo)(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, nullptr);
2215 return getPlatformVersion(platform);
2216}
2217
2218static cl_uint getContextPlatformVersion(cl_context context)
2219{
2220 // The platform cannot be queried directly, so we first have to grab a
2221 // device and obtain its context
2222 size_type size = 0;
2223 CL_(clGetContextInfo)(context, CL_CONTEXT_DEVICES, 0, nullptr, &size);
2224 if (size == 0)
2225 return 0;
2226 vector<cl_device_id> devices(size/sizeof(cl_device_id));
2227 CL_(clGetContextInfo)(context, CL_CONTEXT_DEVICES, size, devices.data(), nullptr);
2228 return getDevicePlatformVersion(devices[0]);
2230#endif // CL_HPP_TARGET_OPENCL_VERSION && CL_HPP_MINIMUM_OPENCL_VERSION
2231
2232template <typename T>
2233class Wrapper
2234{
2235public:
2236 typedef T cl_type;
2237
2238protected:
2239 cl_type object_;
2240
2241public:
2242 Wrapper() : object_(nullptr) { }
2243
2244 Wrapper(const cl_type &obj, bool retainObject) : object_(obj)
2245 {
2246 if (retainObject) {
2247 detail::errHandler(retain(), __RETAIN_ERR);
2248 }
2249 }
2250
2251 ~Wrapper()
2252 {
2253 if (object_ != nullptr) { release(); }
2254 }
2255
2256 Wrapper(const Wrapper<cl_type>& rhs)
2257 {
2258 object_ = rhs.object_;
2259 detail::errHandler(retain(), __RETAIN_ERR);
2260 }
2261
2262 Wrapper(Wrapper<cl_type>&& rhs) noexcept
2263 {
2264 object_ = rhs.object_;
2265 rhs.object_ = nullptr;
2266 }
2267
2268 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
2269 {
2270 if (this != &rhs) {
2271 detail::errHandler(release(), __RELEASE_ERR);
2272 object_ = rhs.object_;
2273 detail::errHandler(retain(), __RETAIN_ERR);
2274 }
2275 return *this;
2276 }
2277
2278 Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
2279 {
2280 if (this != &rhs) {
2281 detail::errHandler(release(), __RELEASE_ERR);
2282 object_ = rhs.object_;
2283 rhs.object_ = nullptr;
2284 }
2285 return *this;
2286 }
2287
2288 Wrapper<cl_type>& operator = (const cl_type &rhs)
2289 {
2290 detail::errHandler(release(), __RELEASE_ERR);
2291 object_ = rhs;
2292 return *this;
2293 }
2294
2295 const cl_type& operator ()() const { return object_; }
2296
2297 cl_type& operator ()() { return object_; }
2298
2299 cl_type get() const { return object_; }
2300
2301protected:
2302 template<typename Func, typename U>
2303 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
2304
2305 cl_int retain() const
2306 {
2307 if (object_ != nullptr) {
2308 return ReferenceHandler<cl_type>::retain(object_);
2309 }
2310 else {
2311 return CL_SUCCESS;
2312 }
2313 }
2314
2315 cl_int release() const
2316 {
2317 if (object_ != nullptr) {
2318 return ReferenceHandler<cl_type>::release(object_);
2319 }
2320 else {
2321 return CL_SUCCESS;
2322 }
2324};
2325
2326template <>
2327class Wrapper<cl_device_id>
2328{
2329public:
2330 typedef cl_device_id cl_type;
2331
2332protected:
2333 cl_type object_;
2334 bool referenceCountable_;
2335
2336 static bool isReferenceCountable(cl_device_id device)
2337 {
2338 bool retVal = false;
2339#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
2340 if (device != nullptr) {
2341 int version = getDevicePlatformVersion(device);
2342 if(version > ((1 << 16) + 1)) {
2343 retVal = true;
2344 }
2345 }
2346#elif CL_HPP_TARGET_OPENCL_VERSION >= 120
2347 retVal = true;
2348#endif // CL_HPP_TARGET_OPENCL_VERSION
2349 (void)device;
2350 return retVal;
2351 }
2352
2353public:
2354 Wrapper() : object_(nullptr), referenceCountable_(false)
2355 {
2356 }
2357
2358 Wrapper(const cl_type &obj, bool retainObject) :
2359 object_(obj),
2360 referenceCountable_(false)
2361 {
2362 referenceCountable_ = isReferenceCountable(obj);
2363
2364 if (retainObject) {
2365 detail::errHandler(retain(), __RETAIN_ERR);
2366 }
2367 }
2368
2369 ~Wrapper()
2370 {
2371 release();
2372 }
2373
2374 Wrapper(const Wrapper<cl_type>& rhs)
2375 {
2376 object_ = rhs.object_;
2377 referenceCountable_ = isReferenceCountable(object_);
2378 detail::errHandler(retain(), __RETAIN_ERR);
2379 }
2380
2381 Wrapper(Wrapper<cl_type>&& rhs) noexcept
2382 {
2383 object_ = rhs.object_;
2384 referenceCountable_ = rhs.referenceCountable_;
2385 rhs.object_ = nullptr;
2386 rhs.referenceCountable_ = false;
2387 }
2388
2389 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
2390 {
2391 if (this != &rhs) {
2392 detail::errHandler(release(), __RELEASE_ERR);
2393 object_ = rhs.object_;
2394 referenceCountable_ = rhs.referenceCountable_;
2395 detail::errHandler(retain(), __RETAIN_ERR);
2396 }
2397 return *this;
2398 }
2399
2400 Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
2401 {
2402 if (this != &rhs) {
2403 detail::errHandler(release(), __RELEASE_ERR);
2404 object_ = rhs.object_;
2405 referenceCountable_ = rhs.referenceCountable_;
2406 rhs.object_ = nullptr;
2407 rhs.referenceCountable_ = false;
2408 }
2409 return *this;
2410 }
2411
2412 Wrapper<cl_type>& operator = (const cl_type &rhs)
2413 {
2414 detail::errHandler(release(), __RELEASE_ERR);
2415 object_ = rhs;
2416 referenceCountable_ = isReferenceCountable(object_);
2417 return *this;
2418 }
2419
2420 const cl_type& operator ()() const { return object_; }
2421
2422 cl_type& operator ()() { return object_; }
2423
2424 cl_type get() const { return object_; }
2425
2426protected:
2427 template<typename Func, typename U>
2428 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
2429
2430 template<typename Func, typename U>
2431 friend inline cl_int getInfoHelper(Func, cl_uint, vector<U>*, int, typename U::cl_type);
2432
2433 cl_int retain() const
2434 {
2435 if( object_ != nullptr && referenceCountable_ ) {
2436 return ReferenceHandler<cl_type>::retain(object_);
2437 }
2438 else {
2439 return CL_SUCCESS;
2440 }
2441 }
2442
2443 cl_int release() const
2444 {
2445 if (object_ != nullptr && referenceCountable_) {
2446 return ReferenceHandler<cl_type>::release(object_);
2447 }
2448 else {
2449 return CL_SUCCESS;
2450 }
2451 }
2452};
2453
2454template <typename T>
2455inline bool operator==(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
2456{
2457 return lhs() == rhs();
2458}
2459
2460template <typename T>
2461inline bool operator!=(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
2462{
2463 return !operator==(lhs, rhs);
2464}
2465
2466} // namespace detail
2468
2469
2470
2471
2472
2474 * \brief Adds constructors and member functions for cl_image_format.
2475 *
2476 * \see cl_image_format
2478struct ImageFormat : public cl_image_format
2479{
2480 //! \brief Default constructor - performs no initialization.
2481 ImageFormat(){}
2482
2484 ImageFormat(cl_channel_order order, cl_channel_type type)
2485 {
2486 image_channel_order = order;
2487 image_channel_data_type = type;
2488 }
2489
2490 //! \brief Copy constructor.
2491 ImageFormat(const ImageFormat &other) { *this = other; }
2492
2495 {
2496 if (this != &rhs) {
2497 this->image_channel_data_type = rhs.image_channel_data_type;
2498 this->image_channel_order = rhs.image_channel_order;
2499 }
2500 return *this;
2501 }
2502};
2503
2507 * any underlying resources or data structures.
2508 *
2509 * \see cl_device_id
2510 */
2511class Device : public detail::Wrapper<cl_device_id>
2512{
2513private:
2514 static std::once_flag default_initialized_;
2515 static Device default_;
2516 static cl_int default_error_;
2517
2523 static void makeDefault();
2524
2530 static void makeDefaultProvided(const Device &p) {
2531 default_ = p;
2532 }
2533
2534public:
2535#ifdef CL_HPP_UNIT_TEST_ENABLE
2542 static void unitTestClearDefault() {
2543 default_ = Device();
2545#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2546
2548 Device() : detail::Wrapper<cl_type>() { }
2549
2550 /*! \brief Constructor from cl_device_id.
2551 *
2552 * This simply copies the device ID value, which is an inexpensive operation.
2553 */
2554 explicit Device(const cl_device_id &device, bool retainObject = false) :
2555 detail::Wrapper<cl_type>(device, retainObject) { }
2556
2557 /*! \brief Returns the first device on the default context.
2558 *
2559 * \see Context::getDefault()
2560 */
2561 static Device getDefault(
2562 cl_int *errResult = nullptr)
2563 {
2564 std::call_once(default_initialized_, makeDefault);
2565 detail::errHandler(default_error_);
2566 if (errResult != nullptr) {
2567 *errResult = default_error_;
2568 }
2569 return default_;
2570 }
2571
2575 * Will only set the default if no default was previously created.
2576 * @return updated default device.
2577 * Should be compared to the passed value to ensure that it was updated.
2578 */
2579 static Device setDefault(const Device &default_device)
2580 {
2581 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_device));
2582 detail::errHandler(default_error_);
2583 return default_;
2584 }
2585
2586 /*! \brief Assignment operator from cl_device_id.
2587 *
2588 * This simply copies the device ID value, which is an inexpensive operation.
2589 */
2590 Device& operator = (const cl_device_id& rhs)
2591 {
2592 detail::Wrapper<cl_type>::operator=(rhs);
2593 return *this;
2594 }
2596
2598 template <typename T>
2599 cl_int getInfo(cl_device_info name, T* param) const
2600 {
2601 return detail::errHandler(
2602 detail::getInfo(CL_(clGetDeviceInfo), object_, name, param),
2603 __GET_DEVICE_INFO_ERR);
2604 }
2607 template <cl_device_info name> typename
2609 getInfo(cl_int* err = nullptr) const
2610 {
2611 typename detail::param_traits<
2612 detail::cl_device_info, name>::param_type param{};
2613 cl_int result = getInfo(name, &param);
2614 if (err != nullptr) {
2615 *err = result;
2616 }
2617 return param;
2618 }
2619
2620#if CL_HPP_TARGET_OPENCL_VERSION >= 210
2623 * The resolution of the device timer may be queried with the
2624 * CL_DEVICE_PROFILING_TIMER_RESOLUTION query.
2625 * @return The host timer value.
2626 */
2627 cl_ulong getHostTimer(cl_int *error = nullptr)
2628 {
2629 cl_ulong retVal = 0;
2630 cl_int err =
2631 CL_(clGetHostTimer)(this->get(), &retVal);
2632 detail::errHandler(
2633 err,
2634 __GET_HOST_TIMER_ERR);
2635 if (error) {
2636 *error = err;
2637 }
2638 return retVal;
2639 }
2640
2647 * The resolution of the device timer may be queried with the
2648 * CL_DEVICE_PROFILING_TIMER_RESOLUTION query.
2649 * @return A pair of (device timer, host timer) timer values.
2650 */
2651 std::pair<cl_ulong, cl_ulong> getDeviceAndHostTimer(cl_int *error = nullptr)
2652 {
2653 std::pair<cl_ulong, cl_ulong> retVal;
2654 cl_int err =
2655 CL_(clGetDeviceAndHostTimer)(this->get(), &(retVal.first), &(retVal.second));
2656 detail::errHandler(
2657 err,
2658 __GET_DEVICE_AND_HOST_TIMER_ERR);
2659 if (error) {
2660 *error = err;
2661 }
2662 return retVal;
2663 }
2664#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2665
2666#if CL_HPP_TARGET_OPENCL_VERSION >= 120
2668 cl_int createSubDevices(const cl_device_partition_property* properties,
2669 vector<Device>* devices);
2670#endif // defined (CL_HPP_TARGET_OPENCL_VERSION >= 120)
2671
2672#if defined(cl_ext_device_fission)
2674 cl_int createSubDevices(const cl_device_partition_property_ext* properties,
2675 vector<Device>* devices);
2676#endif // defined(cl_ext_device_fission)
2677};
2678
2679using BuildLogType = vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, CL_PROGRAM_BUILD_LOG>::param_type>>;
2680#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2684class BuildError : public Error
2685{
2686private:
2687 BuildLogType buildLogs;
2688public:
2689 BuildError(cl_int err, const char * errStr, const BuildLogType &vec) : Error(err, errStr), buildLogs(vec)
2690 {
2691 }
2692
2693 BuildLogType getBuildLog() const
2694 {
2695 return buildLogs;
2696 }
2697};
2698namespace detail {
2699 static inline cl_int buildErrHandler(
2700 cl_int err,
2701 const char * errStr,
2702 const BuildLogType &buildLogs)
2703 {
2704 if (err != CL_SUCCESS) {
2705 throw BuildError(err, errStr, buildLogs);
2706 }
2707 return err;
2708 }
2709} // namespace detail
2710
2711#else
2712namespace detail {
2713 static inline cl_int buildErrHandler(
2714 cl_int err,
2715 const char * errStr,
2716 const BuildLogType &buildLogs)
2717 {
2718 (void)buildLogs; // suppress unused variable warning
2719 (void)errStr;
2720 return err;
2721 }
2722} // namespace detail
2723#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2724
2725CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Device::default_initialized_;
2726CL_HPP_DEFINE_STATIC_MEMBER_ Device Device::default_;
2727CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Device::default_error_ = CL_SUCCESS;
2728
2732 * any underlying resources or data structures.
2733 *
2734 * \see cl_platform_id
2735 */
2736class Platform : public detail::Wrapper<cl_platform_id>
2737{
2738private:
2739 static std::once_flag default_initialized_;
2740 static Platform default_;
2741 static cl_int default_error_;
2742
2748 static void makeDefault() {
2749 /* Throwing an exception from a call_once invocation does not do
2750 * what we wish, so we catch it and save the error.
2751 */
2752#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2753 try
2754#endif
2755 {
2756 // If default wasn't passed ,generate one
2757 // Otherwise set it
2758 cl_uint n = 0;
2759
2760 cl_int err = CL_(clGetPlatformIDs)(0, nullptr, &n);
2761 if (err != CL_SUCCESS) {
2762 default_error_ = err;
2763 return;
2764 }
2765 if (n == 0) {
2766 default_error_ = CL_INVALID_PLATFORM;
2767 return;
2768 }
2769
2770 vector<cl_platform_id> ids(n);
2771 err = CL_(clGetPlatformIDs)(n, ids.data(), nullptr);
2772 if (err != CL_SUCCESS) {
2773 default_error_ = err;
2774 return;
2775 }
2776
2777 default_ = Platform(ids[0]);
2778 }
2779#if defined(CL_HPP_ENABLE_EXCEPTIONS)
2780 catch (cl::Error &e) {
2781 default_error_ = e.err();
2782 }
2783#endif
2784 }
2785
2791 static void makeDefaultProvided(const Platform &p) {
2792 default_ = p;
2793 }
2794
2795public:
2796#ifdef CL_HPP_UNIT_TEST_ENABLE
2803 static void unitTestClearDefault() {
2804 default_ = Platform();
2806#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2807
2809 Platform() : detail::Wrapper<cl_type>() { }
2810
2814 * Defaults to false to maintain compatibility with
2815 * earlier versions.
2816 * This simply copies the platform ID value, which is an inexpensive operation.
2817 */
2818 explicit Platform(const cl_platform_id &platform, bool retainObject = false) :
2819 detail::Wrapper<cl_type>(platform, retainObject) { }
2820
2821 /*! \brief Assignment operator from cl_platform_id.
2822 *
2823 * This simply copies the platform ID value, which is an inexpensive operation.
2824 */
2825 Platform& operator = (const cl_platform_id& rhs)
2826 {
2827 detail::Wrapper<cl_type>::operator=(rhs);
2828 return *this;
2829 }
2830
2831 static Platform getDefault(
2832 cl_int *errResult = nullptr)
2833 {
2834 std::call_once(default_initialized_, makeDefault);
2835 detail::errHandler(default_error_);
2836 if (errResult != nullptr) {
2837 *errResult = default_error_;
2838 }
2839 return default_;
2840 }
2841
2845 * Will only set the default if no default was previously created.
2846 * @return updated default platform.
2847 * Should be compared to the passed value to ensure that it was updated.
2848 */
2849 static Platform setDefault(const Platform &default_platform)
2850 {
2851 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_platform));
2852 detail::errHandler(default_error_);
2853 return default_;
2855
2857 template <typename T>
2858 cl_int getInfo(cl_platform_info name, T* param) const
2859 {
2860 return detail::errHandler(
2861 detail::getInfo(CL_(clGetPlatformInfo), object_, name, param),
2862 __GET_PLATFORM_INFO_ERR);
2863 }
2866 template <cl_platform_info name> typename
2868 getInfo(cl_int* err = nullptr) const
2869 {
2870 typename detail::param_traits<
2871 detail::cl_platform_info, name>::param_type param{};
2872 cl_int result = getInfo(name, &param);
2873 if (err != nullptr) {
2874 *err = result;
2875 }
2876 return param;
2877 }
2878
2879 /*! \brief Gets a list of devices for this platform.
2880 *
2881 * Wraps clGetDeviceIDs().
2882 */
2883 cl_int getDevices(
2884 cl_device_type type,
2885 vector<Device>& devices) const
2886 {
2887 cl_uint n = 0;
2888 cl_int err = CL_(clGetDeviceIDs)(object_, type, 0, nullptr, &n);
2889 if (err != CL_SUCCESS && err != CL_DEVICE_NOT_FOUND) {
2890 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2891 }
2892
2893 vector<cl_device_id> ids(n);
2894 if (n>0) {
2895 err = CL_(clGetDeviceIDs)(object_, type, n, ids.data(), nullptr);
2896 if (err != CL_SUCCESS) {
2897 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2898 }
2899 }
2900
2901 // Cannot trivially assign because we need to capture intermediates
2902 // with safe construction
2903 // We must retain things we obtain from the API to avoid releasing
2904 // API-owned objects.
2905 devices.resize(ids.size());
2906
2907 // Assign to param, constructing with retain behaviour
2908 // to correctly capture each underlying CL object
2909 for (size_type i = 0; i < ids.size(); i++) {
2910 devices[i] = Device(ids[i], true);
2911 }
2912 return CL_SUCCESS;
2913 }
2914
2915 /*! \brief Gets a list of devices for this platform.
2916 *
2917 * Pointer overload for backwards compatibility.
2918 */
2919 cl_int getDevices(
2920 cl_device_type type,
2921 vector<Device>* devices) const
2922 {
2923 if( devices == nullptr ) {
2924 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2925 }
2926
2927 return getDevices(type, *devices);
2928 }
2929
2930#if defined(CL_HPP_USE_DX_INTEROP)
2954 cl_int getDevices(
2955 cl_d3d10_device_source_khr d3d_device_source,
2956 void * d3d_object,
2957 cl_d3d10_device_set_khr d3d_device_set,
2958 vector<Device>& devices) const
2959 {
2960 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
2961 cl_platform_id platform,
2962 cl_d3d10_device_source_khr d3d_device_source,
2963 void * d3d_object,
2964 cl_d3d10_device_set_khr d3d_device_set,
2965 cl_uint num_entries,
2966 cl_device_id * devices,
2967 cl_uint* num_devices);
2968
2969 static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = nullptr;
2970#if CL_HPP_TARGET_OPENCL_VERSION >= 120
2971 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(object_, clGetDeviceIDsFromD3D10KHR);
2972#endif
2973#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
2974 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetDeviceIDsFromD3D10KHR);
2975#endif
2976
2977 cl_uint n = 0;
2978 cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
2979 object_,
2980 d3d_device_source,
2981 d3d_object,
2982 d3d_device_set,
2983 0,
2984 nullptr,
2985 &n);
2986 if (err != CL_SUCCESS) {
2987 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2988 }
2989
2990 vector<cl_device_id> ids(n);
2991 err = pfn_clGetDeviceIDsFromD3D10KHR(
2992 object_,
2993 d3d_device_source,
2994 d3d_object,
2995 d3d_device_set,
2996 n,
2997 ids.data(),
2998 nullptr);
2999 if (err != CL_SUCCESS) {
3000 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
3001 }
3002
3003 // Cannot trivially assign because we need to capture intermediates
3004 // with safe construction
3005 // We must retain things we obtain from the API to avoid releasing
3006 // API-owned objects.
3007 devices.resize(ids.size());
3008
3009 // Assign to param, constructing with retain behaviour
3010 // to correctly capture each underlying CL object
3011 for (size_type i = 0; i < ids.size(); i++) {
3012 devices[i] = Device(ids[i], true);
3013 }
3014 return CL_SUCCESS;
3015 }
3016
3021 cl_int getDevices(
3022 cl_d3d10_device_source_khr d3d_device_source,
3023 void * d3d_object,
3024 cl_d3d10_device_set_khr d3d_device_set,
3025 vector<Device>* devices) const
3026 {
3027 if( devices == nullptr ) {
3028 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
3029 }
3030
3031 return getDevices(d3d_device_source, d3d_object, d3d_device_set, *devices);
3032 }
3033#endif
3034
3035 /*! \brief Gets a list of available platforms.
3036 *
3037 * Wraps clGetPlatformIDs().
3038 */
3039 static cl_int get(
3040 vector<Platform>& platforms)
3041 {
3042 cl_uint n = 0;
3043
3044 cl_int err = CL_(clGetPlatformIDs)(0, nullptr, &n);
3045 if (err != CL_SUCCESS) {
3046 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
3047 }
3048
3049 vector<cl_platform_id> ids(n);
3050 err = CL_(clGetPlatformIDs)(n, ids.data(), nullptr);
3051 if (err != CL_SUCCESS) {
3052 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
3053 }
3054
3055 platforms.resize(ids.size());
3056
3057 // Platforms don't reference count
3058 for (size_type i = 0; i < ids.size(); i++) {
3059 platforms[i] = Platform(ids[i]);
3060 }
3061 return CL_SUCCESS;
3062 }
3063
3064 /*! \brief Gets a list of available platforms.
3065 *
3066 * Pointer overload for backwards compatibility.
3067 */
3068 static cl_int get(
3069 vector<Platform>* platforms)
3070 {
3071 if( platforms == nullptr ) {
3072 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
3073 }
3074
3075 return get(*platforms);
3076 }
3077
3078 /*! \brief Gets the first available platform.
3079 *
3080 * Wraps clGetPlatformIDs(), returning the first result.
3081 */
3082 static cl_int get(
3083 Platform * platform)
3084 {
3085 cl_int err;
3086 Platform default_platform = Platform::getDefault(&err);
3087 if (platform) {
3088 *platform = default_platform;
3089 }
3090 return err;
3091 }
3092
3097 * Throws an exception if no platforms are available
3098 * or an error condition occurs.
3099 * Wraps clGetPlatformIDs(), returning the first result.
3100 */
3101 static Platform get(
3102 cl_int * errResult = nullptr)
3103 {
3104 cl_int err;
3105 Platform default_platform = Platform::getDefault(&err);
3106 if (errResult) {
3107 *errResult = err;
3108 }
3109 return default_platform;
3110 }
3112#if CL_HPP_TARGET_OPENCL_VERSION >= 120
3114 cl_int
3116 {
3117 return CL_(clUnloadPlatformCompiler)(object_);
3118 }
3119#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
3120}; // class Platform
3121
3122#if CL_HPP_TARGET_OPENCL_VERSION >= 120
3124inline cl_int Device::createSubDevices(const cl_device_partition_property* properties,
3125 vector<Device>* devices)
3126{
3127 cl_uint n = 0;
3128 cl_int err = CL_(clCreateSubDevices)(object_, properties, 0, nullptr, &n);
3129 if (err != CL_SUCCESS)
3130 {
3131 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
3132 }
3133
3134 vector<cl_device_id> ids(n);
3135 err = CL_(clCreateSubDevices)(object_, properties, n, ids.data(), nullptr);
3136 if (err != CL_SUCCESS)
3137 {
3138 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
3139 }
3140
3141 // Cannot trivially assign because we need to capture intermediates
3142 // with safe construction
3143 if (devices)
3144 {
3145 devices->resize(ids.size());
3146
3147 // Assign to param, constructing with retain behaviour
3148 // to correctly capture each underlying CL object
3149 for (size_type i = 0; i < ids.size(); i++)
3150 {
3151 // We do not need to retain because this device is being created
3152 // by the runtime
3153 (*devices)[i] = Device(ids[i], false);
3154 }
3155 }
3156
3157 return CL_SUCCESS;
3158}
3159#endif // defined (CL_HPP_TARGET_OPENCL_VERSION >= 120)
3160
3161#if defined(cl_ext_device_fission)
3163inline cl_int Device::createSubDevices(const cl_device_partition_property_ext* properties,
3164 vector<Device>* devices)
3165{
3166#if CL_HPP_TARGET_OPENCL_VERSION >= 120
3167 cl::Device device(object_);
3168 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>()();
3169 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateSubDevicesEXT);
3170#endif
3171#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
3172 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSubDevicesEXT);
3173#endif
3174
3175 cl_uint n = 0;
3176 cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, nullptr, &n);
3177 if (err != CL_SUCCESS)
3178 {
3179 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
3180 }
3181
3182 vector<cl_device_id> ids(n);
3183 err =
3184 pfn_clCreateSubDevicesEXT(object_, properties, n, ids.data(), nullptr);
3185 if (err != CL_SUCCESS)
3186 {
3187 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
3188 }
3189 // Cannot trivially assign because we need to capture intermediates
3190 // with safe construction
3191 if (devices)
3192 {
3193 devices->resize(ids.size());
3194
3195 // Assign to param, constructing with retain behaviour
3196 // to correctly capture each underlying CL object
3197 for (size_type i = 0; i < ids.size(); i++)
3198 {
3199 // We do not need to retain because this device is being created
3200 // by the runtime
3201 (*devices)[i] = Device(ids[i], false);
3202 }
3203 }
3204
3205 return CL_SUCCESS;
3206}
3207#endif // defined(cl_ext_device_fission)
3208
3209CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Platform::default_initialized_;
3210CL_HPP_DEFINE_STATIC_MEMBER_ Platform Platform::default_;
3211CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Platform::default_error_ = CL_SUCCESS;
3212
3213
3217#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
3222inline CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int
3223UnloadCompiler() CL_API_SUFFIX__VERSION_1_1_DEPRECATED;
3224inline cl_int
3226{
3227 return CL_(clUnloadCompiler)();
3228}
3229#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
3230
3231
3232#if defined(cl_ext_image_requirements_info)
3233enum ImageRequirementsInfoExt : cl_image_requirements_info_ext
3234{
3235 RowPitchAlign = CL_IMAGE_REQUIREMENTS_ROW_PITCH_ALIGNMENT_EXT,
3236 BaseAddAlign = CL_IMAGE_REQUIREMENTS_BASE_ADDRESS_ALIGNMENT_EXT,
3237 Size = CL_IMAGE_REQUIREMENTS_SIZE_EXT,
3238 MaxWidth = CL_IMAGE_REQUIREMENTS_MAX_WIDTH_EXT,
3239 MaxHeight = CL_IMAGE_REQUIREMENTS_MAX_HEIGHT_EXT,
3240 MaxDepth = CL_IMAGE_REQUIREMENTS_MAX_DEPTH_EXT,
3241 MaxArraySize = CL_IMAGE_REQUIREMENTS_MAX_ARRAY_SIZE_EXT,
3242#if defined(cl_ext_image_from_buffer)
3243 SlicePitchAlign = CL_IMAGE_REQUIREMENTS_SLICE_PITCH_ALIGNMENT_EXT,
3244#endif
3245};
3246
3247#endif // cl_ext_image_requirements_info
3248
3249
3254 * clRetainContext() and clReleaseContext().
3255 *
3256 * \see cl_context
3257 */
3258class Context
3259 : public detail::Wrapper<cl_context>
3260{
3261private:
3262 static std::once_flag default_initialized_;
3263 static Context default_;
3264 static cl_int default_error_;
3265
3271 static void makeDefault() {
3272 /* Throwing an exception from a call_once invocation does not do
3273 * what we wish, so we catch it and save the error.
3274 */
3275#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3276 try
3277#endif
3278 {
3279#if !defined(__APPLE__) && !defined(__MACOS)
3280 const Platform &p = Platform::getDefault();
3281 cl_platform_id defaultPlatform = p();
3282 cl_context_properties properties[3] = {
3283 CL_CONTEXT_PLATFORM, (cl_context_properties)defaultPlatform, 0
3284 };
3285#else // #if !defined(__APPLE__) && !defined(__MACOS)
3286 cl_context_properties *properties = nullptr;
3287#endif // #if !defined(__APPLE__) && !defined(__MACOS)
3288
3289 default_ = Context(
3290 CL_DEVICE_TYPE_DEFAULT,
3291 properties,
3292 nullptr,
3293 nullptr,
3294 &default_error_);
3295 }
3296#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3297 catch (cl::Error &e) {
3298 default_error_ = e.err();
3299 }
3300#endif
3301 }
3302
3303
3309 static void makeDefaultProvided(const Context &c) {
3310 default_ = c;
3311 }
3312
3313#if defined(cl_ext_image_requirements_info)
3314 struct ImageRequirementsInfo {
3315
3316 ImageRequirementsInfo(cl_mem_flags f, const cl_mem_properties* mem_properties, const ImageFormat* format, const cl_image_desc* desc)
3317 {
3318 flags = f;
3319 properties = mem_properties;
3320 image_format = format;
3321 image_desc = desc;
3322 }
3323
3324 cl_mem_flags flags = 0;
3325 const cl_mem_properties* properties;
3326 const ImageFormat* image_format;
3327 const cl_image_desc* image_desc;
3328 };
3329
3330 static cl_int getImageRequirementsInfoExtHelper(const Context &context,
3331 const ImageRequirementsInfo &info,
3332 cl_image_requirements_info_ext param_name,
3333 size_type param_value_size,
3334 void* param_value,
3335 size_type* param_value_size_ret)
3336 {
3337
3338#if CL_HPP_TARGET_OPENCL_VERSION >= 120
3339 Device device = context.getInfo<CL_CONTEXT_DEVICES>().at(0);
3340 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>()();
3341 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clGetImageRequirementsInfoEXT);
3342#else
3343 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetImageRequirementsInfoEXT);
3344#endif
3345
3346 if (pfn_clGetImageRequirementsInfoEXT == nullptr) {
3347 return detail::errHandler(CL_INVALID_OPERATION, __GET_IMAGE_REQUIREMENT_INFO_EXT_ERR);
3348 }
3349
3350 return detail::errHandler(
3351 pfn_clGetImageRequirementsInfoEXT(context(), info.properties,
3352 info.flags, info.image_format, info.image_desc, param_name,
3353 param_value_size, param_value, param_value_size_ret),
3354 __GET_IMAGE_REQUIREMENT_INFO_EXT_ERR);
3355 }
3356#endif // cl_ext_image_requirements_info
3357
3358public:
3359#ifdef CL_HPP_UNIT_TEST_ENABLE
3366 static void unitTestClearDefault() {
3367 default_ = Context();
3368 }
3369#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
3370
3371 /*! \brief Constructs a context including a list of specified devices.
3372 *
3373 * Wraps clCreateContext().
3374 */
3375 Context(
3376 const vector<Device>& devices,
3377 const cl_context_properties* properties = nullptr,
3378 void (CL_CALLBACK * notifyFptr)(
3379 const char *,
3380 const void *,
3381 size_type,
3382 void *) = nullptr,
3383 void* data = nullptr,
3384 cl_int* err = nullptr)
3385 {
3386 cl_int error;
3387
3388 size_type numDevices = devices.size();
3389 vector<cl_device_id> deviceIDs(numDevices);
3390
3391 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
3392 deviceIDs[deviceIndex] = (devices[deviceIndex])();
3393 }
3394
3395 object_ = CL_(clCreateContext)(
3396 properties,
3397 (cl_uint)deviceIDs.size(),
3398 deviceIDs.empty() ? nullptr : deviceIDs.data(),
3399 notifyFptr, data, &error);
3400
3401 detail::errHandler(error, __CREATE_CONTEXT_ERR);
3402 if (err != nullptr) {
3403 *err = error;
3404 }
3405 }
3406
3407 /*! \brief Constructs a context including a specific device.
3408 *
3409 * Wraps clCreateContext().
3410 */
3411 Context(
3412 const Device& device,
3413 const cl_context_properties* properties = nullptr,
3414 void (CL_CALLBACK * notifyFptr)(
3415 const char *,
3416 const void *,
3417 size_type,
3418 void *) = nullptr,
3419 void* data = nullptr,
3420 cl_int* err = nullptr)
3421 {
3422 cl_int error;
3423
3424 cl_device_id deviceID = device();
3425
3426 object_ = CL_(clCreateContext)(
3427 properties, 1,
3428 &deviceID,
3429 notifyFptr, data, &error);
3430
3431 detail::errHandler(error, __CREATE_CONTEXT_ERR);
3432 if (err != nullptr) {
3433 *err = error;
3434 }
3435 }
3436
3437 /*! \brief Constructs a context including all or a subset of devices of a specified type.
3438 *
3439 * Wraps clCreateContextFromType().
3440 */
3441 Context(
3442 cl_device_type type,
3443 const cl_context_properties* properties = nullptr,
3444 void (CL_CALLBACK * notifyFptr)(
3445 const char *,
3446 const void *,
3447 size_type,
3448 void *) = nullptr,
3449 void* data = nullptr,
3450 cl_int* err = nullptr)
3451 {
3452 cl_int error;
3453
3454#if !defined(__APPLE__) && !defined(__MACOS)
3455 cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 };
3456
3457 if (properties == nullptr) {
3458 // Get a valid platform ID as we cannot send in a blank one
3459 vector<Platform> platforms;
3460 error = Platform::get(&platforms);
3461 if (error != CL_SUCCESS) {
3462 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
3463 if (err != nullptr) {
3464 *err = error;
3465 }
3466 return;
3467 }
3468
3469 // Check the platforms we found for a device of our specified type
3470 cl_context_properties platform_id = 0;
3471 for (unsigned int i = 0; i < platforms.size(); i++) {
3472
3473 vector<Device> devices;
3474
3475#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3476 try {
3477#endif
3478
3479 error = platforms[i].getDevices(type, &devices);
3480
3481#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3482 } catch (cl::Error& e) {
3483 error = e.err();
3484 }
3485 // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type
3486 // We do error checking next anyway, and can throw there if needed
3487#endif
3488
3489 // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND
3490 if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) {
3491 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
3492 if (err != nullptr) {
3493 *err = error;
3494 }
3495 }
3496
3497 if (devices.size() > 0) {
3498 platform_id = (cl_context_properties)platforms[i]();
3499 break;
3500 }
3501 }
3502
3503 if (platform_id == 0) {
3504 detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR);
3505 if (err != nullptr) {
3506 *err = CL_DEVICE_NOT_FOUND;
3507 }
3508 return;
3509 }
3510
3511 prop[1] = platform_id;
3512 properties = &prop[0];
3513 }
3514#endif
3515 object_ = CL_(clCreateContextFromType)(
3516 properties, type, notifyFptr, data, &error);
3517
3518 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
3519 if (err != nullptr) {
3520 *err = error;
3521 }
3522 }
3523
3524
3525 /*! \brief Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT.
3526 *
3527 * \note All calls to this function return the same cl_context as the first.
3528 */
3529 static Context getDefault(cl_int * err = nullptr)
3530 {
3531 std::call_once(default_initialized_, makeDefault);
3532 detail::errHandler(default_error_);
3533 if (err != nullptr) {
3534 *err = default_error_;
3535 }
3536 return default_;
3537 }
3538
3542 * Will only set the default if no default was previously created.
3543 * @return updated default context.
3544 * Should be compared to the passed value to ensure that it was updated.
3545 */
3546 static Context setDefault(const Context &default_context)
3547 {
3548 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_context));
3549 detail::errHandler(default_error_);
3550 return default_;
3551 }
3552
3554 Context() : detail::Wrapper<cl_type>() { }
3555
3558 * This effectively transfers ownership of a refcount on the cl_context
3559 * into the new Context object.
3560 */
3561 explicit Context(const cl_context& context, bool retainObject = false) :
3562 detail::Wrapper<cl_type>(context, retainObject) { }
3563
3566 * This effectively transfers ownership of a refcount on the rhs and calls
3567 * clReleaseContext() on the value previously held by this instance.
3568 */
3569 Context& operator = (const cl_context& rhs)
3570 {
3571 detail::Wrapper<cl_type>::operator=(rhs);
3572 return *this;
3574
3576 template <typename T>
3577 cl_int getInfo(cl_context_info name, T* param) const
3578 {
3579 return detail::errHandler(
3580 detail::getInfo(CL_(clGetContextInfo), object_, name, param),
3581 __GET_CONTEXT_INFO_ERR);
3582 }
3585 template <cl_context_info name> typename
3587 getInfo(cl_int* err = nullptr) const
3588 {
3589 typename detail::param_traits<
3590 detail::cl_context_info, name>::param_type param{};
3591 cl_int result = getInfo(name, &param);
3592 if (err != nullptr) {
3593 *err = result;
3594 }
3595 return param;
3596 }
3597
3598 /*! \brief Gets a list of supported image formats.
3599 *
3600 * Wraps clGetSupportedImageFormats().
3601 */
3603 cl_mem_flags flags,
3604 cl_mem_object_type type,
3605 vector<ImageFormat>& formats) const
3606 {
3607 cl_uint numEntries;
3608
3609 cl_int err = CL_(clGetSupportedImageFormats)(
3610 object_,
3611 flags,
3612 type,
3613 0,
3614 nullptr,
3615 &numEntries);
3616 if (err != CL_SUCCESS) {
3617 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3618 }
3619
3620 if (numEntries > 0) {
3621 vector<ImageFormat> value(numEntries);
3622 err = CL_(clGetSupportedImageFormats)(
3623 object_,
3624 flags,
3625 type,
3626 numEntries,
3627 (cl_image_format*)value.data(),
3628 nullptr);
3629 if (err != CL_SUCCESS) {
3630 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3631 }
3632
3633 formats.assign(value.begin(), value.end());
3634 }
3635 else {
3636 // If no values are being returned, ensure an empty vector comes back
3637 formats.clear();
3638 }
3639
3640 return CL_SUCCESS;
3641 }
3642
3643 /*! \brief Gets a list of supported image formats.
3644 *
3645 * Pointer overload for backwards compatibility.
3646 */
3648 cl_mem_flags flags,
3649 cl_mem_object_type type,
3650 vector<ImageFormat>* formats) const
3651 {
3652 if( formats == nullptr ) {
3653 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3654 }
3655 return getSupportedImageFormats(flags, type, *formats);
3656 }
3657
3658#if defined(cl_ext_image_requirements_info)
3659 template <typename T>
3660 cl_int getImageRequirementsInfoExt(cl_image_requirements_info_ext name,
3661 T* param,
3662 cl_mem_flags flags = 0,
3663 const cl_mem_properties* properties = nullptr,
3664 const ImageFormat* image_format = nullptr,
3665 const cl_image_desc* image_desc = nullptr) const
3666 {
3667 ImageRequirementsInfo imageInfo = {flags, properties, image_format, image_desc};
3668
3669 return detail::errHandler(
3670 detail::getInfo(
3671 Context::getImageRequirementsInfoExtHelper, *this, imageInfo, name, param),
3672 __GET_IMAGE_REQUIREMENT_INFO_EXT_ERR);
3673 }
3674
3675 template <cl_image_requirements_info_ext type> typename
3676 detail::param_traits<detail::cl_image_requirements_info_ext, type>::param_type
3677 getImageRequirementsInfoExt(cl_mem_flags flags = 0,
3678 const cl_mem_properties* properties = nullptr,
3679 const ImageFormat* image_format = nullptr,
3680 const cl_image_desc* image_desc = nullptr,
3681 cl_int* err = nullptr) const
3682 {
3683 typename detail::param_traits<
3684 detail::cl_image_requirements_info_ext, type>::param_type param{};
3685 cl_int result = getImageRequirementsInfoExt(type, &param, flags, properties, image_format, image_desc);
3686 if (err != nullptr) {
3687 *err = result;
3688 }
3689 return param;
3690 }
3691#endif // cl_ext_image_requirements_info
3692
3693#if CL_HPP_TARGET_OPENCL_VERSION >= 300
3700 * callback functions are called in the reverse order in which they were registered.
3701 * If a context callback function was specified when context was created,
3702 * it will not be called after any context destructor callback is called.
3703 */
3704 cl_int setDestructorCallback(
3705 void (CL_CALLBACK * pfn_notify)(cl_context, void *),
3706 void * user_data = nullptr)
3707 {
3708 return detail::errHandler(
3709 CL_(clSetContextDestructorCallback)(
3710 object_,
3711 pfn_notify,
3712 user_data),
3713 __SET_CONTEXT_DESTRUCTOR_CALLBACK_ERR);
3714 }
3715#endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
3716};
3717
3718inline void Device::makeDefault()
3719{
3720 /* Throwing an exception from a call_once invocation does not do
3721 * what we wish, so we catch it and save the error.
3722 */
3723#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3724 try
3725#endif
3726 {
3727 cl_int error = 0;
3728
3729 Context context = Context::getDefault(&error);
3730 detail::errHandler(error, __CREATE_CONTEXT_ERR);
3731
3732 if (error != CL_SUCCESS) {
3733 default_error_ = error;
3734 }
3735 else {
3736 default_ = context.getInfo<CL_CONTEXT_DEVICES>()[0];
3737 default_error_ = CL_SUCCESS;
3738 }
3739 }
3740#if defined(CL_HPP_ENABLE_EXCEPTIONS)
3741 catch (cl::Error &e) {
3742 default_error_ = e.err();
3743 }
3744#endif
3745}
3746
3747CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Context::default_initialized_;
3748CL_HPP_DEFINE_STATIC_MEMBER_ Context Context::default_;
3749CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Context::default_error_ = CL_SUCCESS;
3750
3755 * clRetainEvent() and clReleaseEvent().
3756 *
3757 * \see cl_event
3758 */
3759class Event : public detail::Wrapper<cl_event>
3760{
3761public:
3764
3769 * earlier versions.
3770 * This effectively transfers ownership of a refcount on the cl_event
3771 * into the new Event object.
3772 */
3773 explicit Event(const cl_event& event, bool retainObject = false) :
3774 detail::Wrapper<cl_type>(event, retainObject) { }
3775
3778 * This effectively transfers ownership of a refcount on the rhs and calls
3779 * clReleaseEvent() on the value previously held by this instance.
3780 */
3781 Event& operator = (const cl_event& rhs)
3782 {
3783 detail::Wrapper<cl_type>::operator=(rhs);
3784 return *this;
3786
3788 template <typename T>
3789 cl_int getInfo(cl_event_info name, T* param) const
3790 {
3791 return detail::errHandler(
3792 detail::getInfo(CL_(clGetEventInfo), object_, name, param),
3793 __GET_EVENT_INFO_ERR);
3794 }
3797 template <cl_event_info name> typename
3799 getInfo(cl_int* err = nullptr) const
3800 {
3801 typename detail::param_traits<
3802 detail::cl_event_info, name>::param_type param{};
3803 cl_int result = getInfo(name, &param);
3804 if (err != nullptr) {
3805 *err = result;
3806 }
3807 return param;
3809
3811 template <typename T>
3812 cl_int getProfilingInfo(cl_profiling_info name, T* param) const
3813 {
3814 return detail::errHandler(detail::getInfo(
3815 CL_(clGetEventProfilingInfo), object_, name, param),
3816 __GET_EVENT_PROFILE_INFO_ERR);
3817 }
3820 template <cl_profiling_info name> typename
3822 getProfilingInfo(cl_int* err = nullptr) const
3823 {
3824 typename detail::param_traits<
3825 detail::cl_profiling_info, name>::param_type param{};
3826 cl_int result = getProfilingInfo(name, &param);
3827 if (err != nullptr) {
3828 *err = result;
3829 }
3830 return param;
3831 }
3832
3833 /*! \brief Blocks the calling thread until this event completes.
3834 *
3835 * Wraps clWaitForEvents().
3836 */
3837 cl_int wait() const
3838 {
3839 return detail::errHandler(
3840 CL_(clWaitForEvents)(1, &object_),
3841 __WAIT_FOR_EVENTS_ERR);
3842 }
3843
3844#if CL_HPP_TARGET_OPENCL_VERSION >= 110
3845 /*! \brief Registers a user callback function for a specific command execution status.
3846 *
3847 * Wraps clSetEventCallback().
3848 */
3849 cl_int setCallback(
3850 cl_int type,
3851 void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
3852 void * user_data = nullptr)
3853 {
3854 return detail::errHandler(
3855 CL_(clSetEventCallback)(
3856 object_,
3857 type,
3858 pfn_notify,
3859 user_data),
3860 __SET_EVENT_CALLBACK_ERR);
3861 }
3862#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3863
3866 * Wraps clWaitForEvents().
3867 */
3868 static cl_int
3869 waitForEvents(const vector<Event>& events)
3870 {
3871 static_assert(sizeof(cl::Event) == sizeof(cl_event),
3872 "Size of cl::Event must be equal to size of cl_event");
3873
3874 return detail::errHandler(
3875 CL_(clWaitForEvents)(
3876 (cl_uint) events.size(), (events.size() > 0) ? (const cl_event*)&events.front() : nullptr),
3877 __WAIT_FOR_EVENTS_ERR);
3878 }
3879};
3880
3881#if CL_HPP_TARGET_OPENCL_VERSION >= 110
3882/*! \brief Class interface for user events (a subset of cl_event's).
3883 *
3884 * See Event for details about copy semantics, etc.
3885 */
3886class UserEvent : public Event
3887{
3888public:
3889 /*! \brief Constructs a user event on a given context.
3890 *
3891 * Wraps clCreateUserEvent().
3892 */
3893 UserEvent(
3894 const Context& context,
3895 cl_int * err = nullptr)
3896 {
3897 cl_int error;
3898 object_ = CL_(clCreateUserEvent)(
3899 context(),
3900 &error);
3901
3902 detail::errHandler(error, __CREATE_USER_EVENT_ERR);
3903 if (err != nullptr) {
3904 *err = error;
3906 }
3907
3909 UserEvent() : Event() { }
3910
3911 /*! \brief Sets the execution status of a user event object.
3912 *
3913 * Wraps clSetUserEventStatus().
3914 */
3915 cl_int setStatus(cl_int status)
3916 {
3917 return detail::errHandler(
3918 CL_(clSetUserEventStatus)(object_,status),
3919 __SET_USER_EVENT_STATUS_ERR);
3920 }
3921};
3922#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3923
3928inline static cl_int
3929WaitForEvents(const vector<Event>& events)
3930{
3931 return detail::errHandler(
3932 CL_(clWaitForEvents)(
3933 (cl_uint) events.size(), (events.size() > 0) ? (const cl_event*)&events.front() : nullptr),
3934 __WAIT_FOR_EVENTS_ERR);
3935}
3936
3941 * clRetainMemObject() and clReleaseMemObject().
3942 *
3943 * \see cl_mem
3944 */
3945class Memory : public detail::Wrapper<cl_mem>
3946{
3947public:
3950
3958 * earlier versions.
3959 *
3960 * See Memory for further details.
3961 */
3962 explicit Memory(const cl_mem& memory, bool retainObject) :
3963 detail::Wrapper<cl_type>(memory, retainObject) { }
3964
3967 * This effectively transfers ownership of a refcount on the rhs and calls
3968 * clReleaseMemObject() on the value previously held by this instance.
3969 */
3970 Memory& operator = (const cl_mem& rhs)
3971 {
3972 detail::Wrapper<cl_type>::operator=(rhs);
3973 return *this;
3975
3977 template <typename T>
3978 cl_int getInfo(cl_mem_info name, T* param) const
3979 {
3980 return detail::errHandler(
3981 detail::getInfo(CL_(clGetMemObjectInfo), object_, name, param),
3982 __GET_MEM_OBJECT_INFO_ERR);
3983 }
3986 template <cl_mem_info name> typename
3988 getInfo(cl_int* err = nullptr) const
3989 {
3990 typename detail::param_traits<
3991 detail::cl_mem_info, name>::param_type param{};
3992 cl_int result = getInfo(name, &param);
3993 if (err != nullptr) {
3994 *err = result;
3995 }
3996 return param;
3997 }
3998
3999#if CL_HPP_TARGET_OPENCL_VERSION >= 110
4009 * \note
4010 * The registered callbacks are associated with the underlying cl_mem
4011 * value - not the Memory class instance.
4012 */
4013 cl_int setDestructorCallback(
4014 void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
4015 void * user_data = nullptr)
4016 {
4017 return detail::errHandler(
4018 CL_(clSetMemObjectDestructorCallback)(
4019 object_,
4020 pfn_notify,
4021 user_data),
4022 __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
4023 }
4024#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
4025
4026};
4027
4028// Pre-declare copy functions
4029class Buffer;
4030template< typename IteratorType >
4031cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
4032template< typename IteratorType >
4033cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
4034template< typename IteratorType >
4035cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
4036template< typename IteratorType >
4037cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
4038
4040#if CL_HPP_TARGET_OPENCL_VERSION >= 200
4041namespace detail
4042{
4043 class SVMTraitNull
4044 {
4045 public:
4046 static cl_svm_mem_flags getSVMMemFlags()
4047 {
4048 return 0;
4049 }
4051} // namespace detail
4052
4053template<class Trait = detail::SVMTraitNull>
4054class SVMTraitReadWrite
4055{
4056public:
4057 static cl_svm_mem_flags getSVMMemFlags()
4058 {
4059 return CL_MEM_READ_WRITE |
4060 Trait::getSVMMemFlags();
4062};
4063
4064template<class Trait = detail::SVMTraitNull>
4065class SVMTraitReadOnly
4066{
4067public:
4068 static cl_svm_mem_flags getSVMMemFlags()
4069 {
4070 return CL_MEM_READ_ONLY |
4071 Trait::getSVMMemFlags();
4073};
4074
4075template<class Trait = detail::SVMTraitNull>
4076class SVMTraitWriteOnly
4077{
4078public:
4079 static cl_svm_mem_flags getSVMMemFlags()
4080 {
4081 return CL_MEM_WRITE_ONLY |
4082 Trait::getSVMMemFlags();
4084};
4085
4086template<class Trait = SVMTraitReadWrite<>>
4087class SVMTraitCoarse
4088{
4089public:
4090 static cl_svm_mem_flags getSVMMemFlags()
4091 {
4092 return Trait::getSVMMemFlags();
4094};
4095
4096template<class Trait = SVMTraitReadWrite<>>
4097class SVMTraitFine
4098{
4099public:
4100 static cl_svm_mem_flags getSVMMemFlags()
4101 {
4102 return CL_MEM_SVM_FINE_GRAIN_BUFFER |
4103 Trait::getSVMMemFlags();
4105};
4106
4107template<class Trait = SVMTraitReadWrite<>>
4108class SVMTraitAtomic
4109{
4110public:
4111 static cl_svm_mem_flags getSVMMemFlags()
4112 {
4113 return
4114 CL_MEM_SVM_FINE_GRAIN_BUFFER |
4115 CL_MEM_SVM_ATOMICS |
4116 Trait::getSVMMemFlags();
4117 }
4118};
4119
4120// Pre-declare SVM map function
4121template<typename T>
4122inline cl_int enqueueMapSVM(
4123 T* ptr,
4124 cl_bool blocking,
4125 cl_map_flags flags,
4126 size_type size,
4127 const vector<Event>* events = nullptr,
4128 Event* event = nullptr);
4129
4138 * Instead the allocator embeds a Deleter which may be used with unique_ptr and is used
4139 * with the allocate_shared and allocate_ptr supplied operations.
4140 */
4141template<typename T, class SVMTrait>
4142class SVMAllocator {
4143private:
4144 Context context_;
4145
4146public:
4147 typedef T value_type;
4148 typedef value_type* pointer;
4149 typedef const value_type* const_pointer;
4150 typedef value_type& reference;
4151 typedef const value_type& const_reference;
4152 typedef std::size_t size_type;
4153 typedef std::ptrdiff_t difference_type;
4154
4155 template<typename U>
4156 struct rebind
4157 {
4158 typedef SVMAllocator<U, SVMTrait> other;
4159 };
4160
4161 template<typename U, typename V>
4162 friend class SVMAllocator;
4163
4164 SVMAllocator() :
4165 context_(Context::getDefault())
4166 {
4167 }
4168
4169 explicit SVMAllocator(cl::Context context) :
4170 context_(context)
4171 {
4172 }
4173
4174
4175 SVMAllocator(const SVMAllocator &other) :
4176 context_(other.context_)
4177 {
4178 }
4179
4180 template<typename U>
4181 SVMAllocator(const SVMAllocator<U, SVMTrait> &other) :
4182 context_(other.context_)
4183 {
4184 }
4185
4186 ~SVMAllocator()
4187 {
4188 }
4189
4190 pointer address(reference r) noexcept
4191 {
4192 return std::addressof(r);
4193 }
4194
4195 const_pointer address(const_reference r) noexcept
4196 {
4197 return std::addressof(r);
4198 }
4199
4203 * If the allocator is coarse-grained, this will take ownership to allow
4204 * containers to correctly construct data in place.
4205 */
4206 pointer allocate(
4207 size_type size,
4208 typename cl::SVMAllocator<void, SVMTrait>::const_pointer = 0,
4209 bool map = true)
4210 {
4211 // Allocate memory with default alignment matching the size of the type
4212 void* voidPointer =
4213 CL_(clSVMAlloc)(
4214 context_(),
4215 SVMTrait::getSVMMemFlags(),
4216 size*sizeof(T),
4217 0);
4218 pointer retValue = reinterpret_cast<pointer>(
4219 voidPointer);
4220#if defined(CL_HPP_ENABLE_EXCEPTIONS)
4221 if (!retValue) {
4222 std::bad_alloc excep;
4223 throw excep;
4224 }
4225#endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
4226
4227 // If allocation was coarse-grained then map it
4228 if (map && !(SVMTrait::getSVMMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) {
4229 cl_int err = enqueueMapSVM(retValue, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, size*sizeof(T));
4230 if (err != CL_SUCCESS) {
4231 CL_(clSVMFree)(context_(), retValue);
4232 retValue = nullptr;
4233#if defined(CL_HPP_ENABLE_EXCEPTIONS)
4234 std::bad_alloc excep;
4235 throw excep;
4236#endif
4237 }
4238 }
4239
4240 // If exceptions disabled, return null pointer from allocator
4241 return retValue;
4242 }
4243
4244 void deallocate(pointer p, size_type)
4245 {
4246 CL_(clSVMFree)(context_(), p);
4247 }
4248
4249 /**
4250 * Return the maximum possible allocation size.
4251 * This is the minimum of the maximum sizes of all devices in the context.
4252 */
4253 size_type max_size() const noexcept
4254 {
4255 size_type maxSize = std::numeric_limits<size_type>::max() / sizeof(T);
4256
4257 for (const Device &d : context_.getInfo<CL_CONTEXT_DEVICES>()) {
4258 maxSize = std::min(
4259 maxSize,
4260 static_cast<size_type>(d.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>()));
4261 }
4262
4263 return maxSize;
4264 }
4265
4266 template< class U, class... Args >
4267 void construct(U* p, Args&&... args)
4268 {
4269 new(p)T(args...);
4270 }
4271
4272 template< class U >
4273 void destroy(U* p)
4274 {
4275 p->~U();
4276 }
4281 inline bool operator==(SVMAllocator const& rhs)
4282 {
4283 return (context_==rhs.context_);
4284 }
4285
4286 inline bool operator!=(SVMAllocator const& a)
4287 {
4288 return !operator==(a);
4289 }
4290}; // class SVMAllocator return cl::pointer<T>(tmp, detail::Deleter<T, Alloc>{alloc, copies});
4291
4292
4293template<class SVMTrait>
4294class SVMAllocator<void, SVMTrait> {
4295public:
4296 typedef void value_type;
4297 typedef value_type* pointer;
4298 typedef const value_type* const_pointer;
4299
4300 template<typename U>
4301 struct rebind
4302 {
4303 typedef SVMAllocator<U, SVMTrait> other;
4304 };
4305
4306 template<typename U, typename V>
4307 friend class SVMAllocator;
4308};
4309
4310#if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
4311namespace detail
4312{
4313 template<class Alloc>
4314 class Deleter {
4315 private:
4316 Alloc alloc_;
4317 size_type copies_;
4318
4319 public:
4320 typedef typename std::allocator_traits<Alloc>::pointer pointer;
4321
4322 Deleter(const Alloc &alloc, size_type copies) : alloc_{ alloc }, copies_{ copies }
4323 {
4324 }
4325
4326 void operator()(pointer ptr) const {
4327 Alloc tmpAlloc{ alloc_ };
4328 std::allocator_traits<Alloc>::destroy(tmpAlloc, std::addressof(*ptr));
4329 std::allocator_traits<Alloc>::deallocate(tmpAlloc, ptr, copies_);
4330 }
4331 };
4332} // namespace detail
4333
4337 * This requirement is to ensure that the control block is not
4338 * allocated in memory inaccessible to the host.
4339 */
4340template <class T, class Alloc, class... Args>
4341cl::pointer<T, detail::Deleter<Alloc>> allocate_pointer(const Alloc &alloc_, Args&&... args)
4342{
4343 Alloc alloc(alloc_);
4344 static const size_type copies = 1;
4345
4346 // Ensure that creation of the management block and the
4347 // object are dealt with separately such that we only provide a deleter
4348
4349 T* tmp = std::allocator_traits<Alloc>::allocate(alloc, copies);
4350 if (!tmp) {
4351#if defined(CL_HPP_ENABLE_EXCEPTIONS)
4352 std::bad_alloc excep;
4353 throw excep;
4354#else
4355 return nullptr;
4356#endif
4357 }
4358
4359#if defined(CL_HPP_ENABLE_EXCEPTIONS)
4360 try
4361#endif
4362 {
4363 std::allocator_traits<Alloc>::construct(
4364 alloc,
4365 std::addressof(*tmp),
4366 std::forward<Args>(args)...);
4367
4368 return cl::pointer<T, detail::Deleter<Alloc>>(tmp, detail::Deleter<Alloc>{alloc, copies});
4369 }
4370#if defined(CL_HPP_ENABLE_EXCEPTIONS)
4371 catch (std::bad_alloc&)
4372 {
4373 std::allocator_traits<Alloc>::deallocate(alloc, tmp, copies);
4374 throw;
4375 }
4376#endif
4377}
4378
4379template< class T, class SVMTrait, class... Args >
4380cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(Args... args)
4381{
4382 SVMAllocator<T, SVMTrait> alloc;
4383 return cl::allocate_pointer<T>(alloc, args...);
4384}
4385
4386template< class T, class SVMTrait, class... Args >
4387cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(const cl::Context &c, Args... args)
4388{
4390 return cl::allocate_pointer<T>(alloc, args...);
4391}
4392#endif // #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
4393
4397template < class T >
4398using coarse_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>>;
4399
4403template < class T >
4404using fine_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitFine<>>>;
4405
4409template < class T >
4410using atomic_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitAtomic<>>>;
4411
4412#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
4413
4414
4417 * See Memory for details about copy semantics, etc.
4418 *
4419 * \see Memory
4420 */
4421class Buffer : public Memory
4422{
4423public:
4424
4429 * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
4430 * specified. Note alignment & exclusivity requirements.
4431 */
4432 Buffer(
4433 const Context& context,
4434 cl_mem_flags flags,
4435 size_type size,
4436 void* host_ptr = nullptr,
4437 cl_int* err = nullptr)
4438 {
4439 cl_int error;
4440 object_ = CL_(clCreateBuffer)(context(), flags, size, host_ptr, &error);
4441
4442 detail::errHandler(error, __CREATE_BUFFER_ERR);
4443 if (err != nullptr) {
4444 *err = error;
4445 }
4446 }
4447
4448#if CL_HPP_TARGET_OPENCL_VERSION >= 300
4455 * end with 0.
4456 * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
4457 * specified. Note alignment & exclusivity requirements.
4458 */
4459 Buffer(
4460 const Context& context,
4461 const vector<cl_mem_properties>& properties,
4462 cl_mem_flags flags,
4463 size_type size,
4464 void* host_ptr = nullptr,
4465 cl_int* err = nullptr)
4466 {
4467 cl_int error;
4468
4469 object_ = CL_(clCreateBufferWithProperties)(
4470 context(),
4471 properties.empty() ? nullptr : properties.data(),
4472 flags, size, host_ptr, &error);
4473
4474 detail::errHandler(error, __CREATE_BUFFER_ERR);
4475 if (err != nullptr) {
4476 *err = error;
4477 }
4478 }
4479#endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
4480
4486 * specified. Note alignment & exclusivity requirements.
4487 *
4488 * \see Context::getDefault()
4489 */
4490 Buffer(
4491 cl_mem_flags flags,
4492 size_type size,
4493 void* host_ptr = nullptr,
4494 cl_int* err = nullptr) : Buffer(Context::getDefault(err), flags, size, host_ptr, err) { }
4495
4496#if CL_HPP_TARGET_OPENCL_VERSION >= 300
4505 * specified. Note alignment & exclusivity requirements.
4506 *
4507 * \see Context::getDefault()
4508 */
4509 Buffer(
4510 const vector<cl_mem_properties>& properties,
4511 cl_mem_flags flags,
4512 size_type size,
4513 void* host_ptr = nullptr,
4514 cl_int* err = nullptr) : Buffer(Context::getDefault(err), properties, flags, size, host_ptr, err) { }
4515#endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
4516
4519 * IteratorType must be random access.
4520 * If useHostPtr is specified iterators must represent contiguous data.
4521 */
4522 template< typename IteratorType >
4523 Buffer(
4524 IteratorType startIterator,
4525 IteratorType endIterator,
4526 bool readOnly,
4527 bool useHostPtr = false,
4528 cl_int* err = nullptr)
4529 {
4530 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
4531 cl_int error;
4532
4533 cl_mem_flags flags = 0;
4534 if( readOnly ) {
4535 flags |= CL_MEM_READ_ONLY;
4536 }
4537 else {
4538 flags |= CL_MEM_READ_WRITE;
4539 }
4540 if( useHostPtr ) {
4541 flags |= CL_MEM_USE_HOST_PTR;
4542 }
4543
4544 size_type size = sizeof(DataType)*(endIterator - startIterator);
4545
4546 Context context = Context::getDefault(err);
4547
4548 if( useHostPtr ) {
4549 object_ = CL_(clCreateBuffer)(context(), flags, size, const_cast<DataType*>(&*startIterator), &error);
4550 } else {
4551 object_ = CL_(clCreateBuffer)(context(), flags, size, 0, &error);
4552 }
4553
4554 detail::errHandler(error, __CREATE_BUFFER_ERR);
4555 if (err != nullptr) {
4556 *err = error;
4557 }
4558
4559 if( !useHostPtr ) {
4560 error = cl::copy(startIterator, endIterator, *this);
4561 detail::errHandler(error, __CREATE_BUFFER_ERR);
4562 if (err != nullptr) {
4563 *err = error;
4564 }
4565 }
4566 }
4567
4573 template< typename IteratorType >
4574 Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator,
4575 bool readOnly, bool useHostPtr = false, cl_int* err = nullptr);
4576
4581 template< typename IteratorType >
4582 Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator,
4583 bool readOnly, bool useHostPtr = false, cl_int* err = nullptr);
4584
4586 Buffer() : Memory() { }
4587
4591 * Defaults to false to maintain compatibility with earlier versions.
4592 *
4593 * See Memory for further details.
4594 */
4595 explicit Buffer(const cl_mem& buffer, bool retainObject = false) :
4596 Memory(buffer, retainObject) { }
4597
4598 /*! \brief Assignment from cl_mem - performs shallow copy.
4599 *
4600 * See Memory for further details.
4601 */
4602 Buffer& operator = (const cl_mem& rhs)
4603 {
4604 Memory::operator=(rhs);
4605 return *this;
4606 }
4607
4608
4609#if CL_HPP_TARGET_OPENCL_VERSION >= 110
4610 /*! \brief Creates a new buffer object from this.
4611 *
4612 * Wraps clCreateSubBuffer().
4613 */
4615 cl_mem_flags flags,
4616 cl_buffer_create_type buffer_create_type,
4617 const void * buffer_create_info,
4618 cl_int * err = nullptr)
4619 {
4620 Buffer result;
4621 cl_int error;
4622 result.object_ = CL_(clCreateSubBuffer)(
4623 object_,
4624 flags,
4625 buffer_create_type,
4626 buffer_create_info,
4627 &error);
4628
4629 detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
4630 if (err != nullptr) {
4631 *err = error;
4632 }
4633
4634 return result;
4635 }
4636#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
4637};
4638
4639#if defined (CL_HPP_USE_DX_INTEROP)
4648class BufferD3D10 : public Buffer
4649{
4650public:
4651
4652
4658 BufferD3D10(
4659 const Context& context,
4660 cl_mem_flags flags,
4661 ID3D10Buffer* bufobj,
4662 cl_int * err = nullptr) : pfn_clCreateFromD3D10BufferKHR(nullptr)
4663 {
4664 typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
4665 cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
4666 cl_int* errcode_ret);
4667 PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR;
4668#if CL_HPP_TARGET_OPENCL_VERSION >= 120
4669 vector<cl_context_properties> props = context.getInfo<CL_CONTEXT_PROPERTIES>();
4670 cl_platform platform = nullptr;
4671 for( int i = 0; i < props.size(); ++i ) {
4672 if( props[i] == CL_CONTEXT_PLATFORM ) {
4673 platform = props[i+1];
4674 }
4675 }
4676 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateFromD3D10BufferKHR);
4677#endif
4678#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
4679 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateFromD3D10BufferKHR);
4680#endif
4681
4682 cl_int error;
4683 object_ = pfn_clCreateFromD3D10BufferKHR(
4684 context(),
4685 flags,
4686 bufobj,
4687 &error);
4688
4689 // TODO: This should really have a D3D10 rerror code!
4690 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4691 if (err != nullptr) {
4692 *err = error;
4693 }
4694 }
4695
4697 BufferD3D10() : Buffer() { }
4698
4706 explicit BufferD3D10(const cl_mem& buffer, bool retainObject = false) :
4707 Buffer(buffer, retainObject) { }
4708
4713 BufferD3D10& operator = (const cl_mem& rhs)
4714 {
4715 Buffer::operator=(rhs);
4716 return *this;
4717 }
4718};
4719#endif
4720
4725 * See Memory for details about copy semantics, etc.
4726 *
4727 * \see Memory
4728 */
4729class BufferGL : public Buffer
4730{
4731public:
4733 * GL buffer.
4734 *
4735 * Wraps clCreateFromGLBuffer().
4736 */
4737 BufferGL(
4738 const Context& context,
4739 cl_mem_flags flags,
4740 cl_GLuint bufobj,
4741 cl_int * err = nullptr)
4742 {
4743 cl_int error;
4744 object_ = CL_(clCreateFromGLBuffer)(
4745 context(),
4746 flags,
4747 bufobj,
4748 &error);
4749
4750 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4751 if (err != nullptr) {
4752 *err = error;
4754 }
4755
4757 BufferGL() : Buffer() { }
4758
4762 * Defaults to false to maintain compatibility with
4763 * earlier versions.
4764 * See Memory for further details.
4765 */
4766 explicit BufferGL(const cl_mem& buffer, bool retainObject = false) :
4767 Buffer(buffer, retainObject) { }
4768
4769 /*! \brief Assignment from cl_mem - performs shallow copy.
4770 *
4771 * See Memory for further details.
4772 */
4773 BufferGL& operator = (const cl_mem& rhs)
4774 {
4775 Buffer::operator=(rhs);
4776 return *this;
4778
4779
4781 cl_int getObjectInfo(
4782 cl_gl_object_type *type,
4783 cl_GLuint * gl_object_name)
4784 {
4785 return detail::errHandler(
4786 CL_(clGetGLObjectInfo)(object_,type,gl_object_name),
4787 __GET_GL_OBJECT_INFO_ERR);
4788 }
4789};
4790
4795 * See Memory for details about copy semantics, etc.
4796 *
4797 * \see Memory
4798 */
4799class BufferRenderGL : public Buffer
4800{
4801public:
4803 * GL Renderbuffer.
4804 *
4805 * Wraps clCreateFromGLRenderbuffer().
4806 */
4808 const Context& context,
4809 cl_mem_flags flags,
4810 cl_GLuint bufobj,
4811 cl_int * err = nullptr)
4812 {
4813 cl_int error;
4814 object_ = CL_(clCreateFromGLRenderbuffer)(
4815 context(),
4816 flags,
4817 bufobj,
4818 &error);
4819
4820 detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR);
4821 if (err != nullptr) {
4822 *err = error;
4824 }
4825
4827 BufferRenderGL() : Buffer() { }
4828
4832 * Defaults to false to maintain compatibility with
4833 * earlier versions.
4834 * See Memory for further details.
4835 */
4836 explicit BufferRenderGL(const cl_mem& buffer, bool retainObject = false) :
4837 Buffer(buffer, retainObject) { }
4838
4839 /*! \brief Assignment from cl_mem - performs shallow copy.
4840 *
4841 * See Memory for further details.
4842 */
4843 BufferRenderGL& operator = (const cl_mem& rhs)
4844 {
4845 Buffer::operator=(rhs);
4846 return *this;
4848
4849
4851 cl_int getObjectInfo(
4852 cl_gl_object_type *type,
4853 cl_GLuint * gl_object_name)
4854 {
4855 return detail::errHandler(
4856 CL_(clGetGLObjectInfo)(object_,type,gl_object_name),
4857 __GET_GL_OBJECT_INFO_ERR);
4858 }
4859};
4860
4863 * See Memory for details about copy semantics, etc.
4864 *
4865 * \see Memory
4866 */
4867class Image : public Memory
4868{
4869protected:
4871 Image() : Memory() { }
4872
4876 * Defaults to false to maintain compatibility with
4877 * earlier versions.
4878 * See Memory for further details.
4879 */
4880 explicit Image(const cl_mem& image, bool retainObject = false) :
4881 Memory(image, retainObject) { }
4882
4883 /*! \brief Assignment from cl_mem - performs shallow copy.
4884 *
4885 * See Memory for further details.
4886 */
4887 Image& operator = (const cl_mem& rhs)
4888 {
4889 Memory::operator=(rhs);
4890 return *this;
4891 }
4892
4894public:
4896 template <typename T>
4897 cl_int getImageInfo(cl_image_info name, T* param) const
4898 {
4899 return detail::errHandler(
4900 detail::getInfo(CL_(clGetImageInfo), object_, name, param),
4901 __GET_IMAGE_INFO_ERR);
4902 }
4905 template <cl_image_info name> typename
4907 getImageInfo(cl_int* err = nullptr) const
4908 {
4909 typename detail::param_traits<
4910 detail::cl_image_info, name>::param_type param{};
4911 cl_int result = getImageInfo(name, &param);
4912 if (err != nullptr) {
4913 *err = result;
4914 }
4915 return param;
4916 }
4917};
4918
4919#if CL_HPP_TARGET_OPENCL_VERSION >= 120
4922 * See Memory for details about copy semantics, etc.
4923 *
4924 * \see Memory
4925 */
4926class Image1D : public Image
4927{
4928public:
4929 /*! \brief Constructs a 1D Image in a specified context.
4930 *
4931 * Wraps clCreateImage().
4932 */
4933 Image1D(
4934 const Context& context,
4935 cl_mem_flags flags,
4936 ImageFormat format,
4937 size_type width,
4938 void* host_ptr = nullptr,
4939 cl_int* err = nullptr)
4940 {
4941 cl_int error;
4942
4943 cl_image_desc desc = {};
4944 desc.image_type = CL_MEM_OBJECT_IMAGE1D;
4945 desc.image_width = width;
4946
4947 object_ = CL_(clCreateImage)(
4948 context(),
4949 flags,
4950 &format,
4951 &desc,
4952 host_ptr,
4953 &error);
4954
4955 detail::errHandler(error, __CREATE_IMAGE_ERR);
4956 if (err != nullptr) {
4957 *err = error;
4959 }
4960
4962 Image1D() { }
4963
4964#if CL_HPP_TARGET_OPENCL_VERSION >= 300
4971 * end with 0.
4972 * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
4973 * specified. Note alignment & exclusivity requirements.
4974 */
4975 Image1D(const Context &context, const vector<cl_mem_properties> &properties,
4976 cl_mem_flags flags, ImageFormat format, size_type width,
4977 void *host_ptr = nullptr, cl_int *err = nullptr)
4978 {
4979 cl_int error;
4980
4981 cl_image_desc desc = {};
4982 desc.image_type = CL_MEM_OBJECT_IMAGE1D;
4983 desc.image_width = width;
4984
4985 object_ = CL_(clCreateImageWithProperties)(
4986 context(),
4987 properties.empty() ? nullptr : properties.data(),
4988 flags, &format, &desc, host_ptr, &error);
4989
4990 detail::errHandler(error, __CREATE_IMAGE_ERR);
4991 if (err != nullptr) {
4992 *err = error;
4993 }
4994 }
4995#endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
4996
5000 * Defaults to false to maintain compatibility with
5001 * earlier versions.
5002 * See Memory for further details.
5003 */
5004 explicit Image1D(const cl_mem& image1D, bool retainObject = false) :
5005 Image(image1D, retainObject) { }
5006
5007 /*! \brief Assignment from cl_mem - performs shallow copy.
5008 *
5009 * See Memory for further details.
5010 */
5011 Image1D& operator = (const cl_mem& rhs)
5012 {
5013 Image::operator=(rhs);
5014 return *this;
5015 }
5016
5017
5018};
5023class Image1DBuffer : public Image
5024{
5025public:
5026 Image1DBuffer(
5027 const Context& context,
5028 cl_mem_flags flags,
5029 ImageFormat format,
5030 size_type width,
5031 const Buffer &buffer,
5032 cl_int* err = nullptr)
5033 {
5034 cl_int error;
5035
5036 cl_image_desc desc = {};
5037 desc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER;
5038 desc.image_width = width;
5039 desc.buffer = buffer();
5040
5041 object_ = CL_(clCreateImage)(
5042 context(),
5043 flags,
5044 &format,
5045 &desc,
5046 nullptr,
5047 &error);
5048
5049 detail::errHandler(error, __CREATE_IMAGE_ERR);
5050 if (err != nullptr) {
5051 *err = error;
5052 }
5053 }
5054
5055 Image1DBuffer() { }
5056
5057#if CL_HPP_TARGET_OPENCL_VERSION >= 300
5063 * their corresponding values. The non-empty list must
5064 * end with 0.
5065 * \param buffer Refer to a valid buffer or image memory object.
5066 */
5067 Image1DBuffer(const Context &context,
5068 const vector<cl_mem_properties> &properties,
5069 cl_mem_flags flags, ImageFormat format, size_type width,
5070 const Buffer &buffer, cl_int *err = nullptr)
5071 {
5072 cl_int error;
5073
5074 cl_image_desc desc = {};
5075 desc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER;
5076 desc.image_width = width;
5077 desc.buffer = buffer();
5078
5079 object_ = CL_(clCreateImageWithProperties)(
5080 context(),
5081 properties.empty() ? nullptr : properties.data(),
5082 flags, &format, &desc, nullptr, &error);
5083
5084 detail::errHandler(error, __CREATE_IMAGE_ERR);
5085 if (err != nullptr) {
5086 *err = error;
5087 }
5088 }
5089#endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
5090
5094 * Defaults to false to maintain compatibility with
5095 * earlier versions.
5096 * See Memory for further details.
5097 */
5098 explicit Image1DBuffer(const cl_mem& image1D, bool retainObject = false) :
5099 Image(image1D, retainObject) { }
5100
5101 Image1DBuffer& operator = (const cl_mem& rhs)
5102 {
5103 Image::operator=(rhs);
5104 return *this;
5105 }
5106};
5111class Image1DArray : public Image
5112{
5113public:
5114 Image1DArray(
5115 const Context& context,
5116 cl_mem_flags flags,
5117 ImageFormat format,
5118 size_type arraySize,
5119 size_type width,
5120 size_type rowPitch,
5121 void* host_ptr = nullptr,
5122 cl_int* err = nullptr)
5123 {
5124 cl_int error;
5125
5126 cl_image_desc desc = {};
5127 desc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
5128 desc.image_width = width;
5129 desc.image_array_size = arraySize;
5130 desc.image_row_pitch = rowPitch;
5131
5132 object_ = CL_(clCreateImage)(
5133 context(),
5134 flags,
5135 &format,
5136 &desc,
5137 host_ptr,
5138 &error);
5139
5140 detail::errHandler(error, __CREATE_IMAGE_ERR);
5141 if (err != nullptr) {
5142 *err = error;
5143 }
5144 }
5145
5146 Image1DArray() { }
5147
5148#if CL_HPP_TARGET_OPENCL_VERSION >= 300
5155 * end with 0.
5156 * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
5157 * specified. Note alignment & exclusivity requirements.
5158 */
5159 Image1DArray(const Context &context,
5160 const vector<cl_mem_properties> &properties,
5161 cl_mem_flags flags, ImageFormat format, size_type arraySize,
5162 size_type width, size_type rowPitch = 0,
5163 void *host_ptr = nullptr, cl_int *err = nullptr)
5164 {
5165 cl_int error;
5166
5167 cl_image_desc desc = {};
5168 desc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
5169 desc.image_width = width;
5170 desc.image_array_size = arraySize;
5171 desc.image_row_pitch = rowPitch;
5172
5173 object_ = CL_(clCreateImageWithProperties)(
5174 context(),
5175 properties.empty() ? nullptr : properties.data(),
5176 flags, &format, &desc, host_ptr, &error);
5177
5178 detail::errHandler(error, __CREATE_IMAGE_ERR);
5179 if (err != nullptr) {
5180 *err = error;
5181 }
5182 }
5183#endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
5184
5188 * Defaults to false to maintain compatibility with
5189 * earlier versions.
5190 * See Memory for further details.
5191 */
5192 explicit Image1DArray(const cl_mem& imageArray, bool retainObject = false) :
5193 Image(imageArray, retainObject) { }
5194
5195
5196 Image1DArray& operator = (const cl_mem& rhs)
5197 {
5198 Image::operator=(rhs);
5199 return *this;
5200 }
5201
5202
5203};
5204#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5205
5206
5209 * See Memory for details about copy semantics, etc.
5210 *
5211 * \see Memory
5212 */
5213class Image2D : public Image
5214{
5215public:
5216 /*! \brief Constructs a 2D Image in a specified context.
5217 *
5218 * Wraps clCreateImage().
5219 */
5220 Image2D(
5221 const Context& context,
5222 cl_mem_flags flags,
5223 ImageFormat format,
5224 size_type width,
5225 size_type height,
5226 size_type row_pitch = 0,
5227 void* host_ptr = nullptr,
5228 cl_int* err = nullptr)
5229 {
5230 cl_int error;
5231 bool useCreateImage;
5232
5233#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
5234 // Run-time decision based on the actual platform
5235 {
5236 cl_uint version = detail::getContextPlatformVersion(context());
5237 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
5238 }
5239#elif CL_HPP_TARGET_OPENCL_VERSION >= 120
5240 useCreateImage = true;
5241#else
5242 useCreateImage = false;
5243#endif
5244
5245#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5246 if (useCreateImage)
5247 {
5248 cl_image_desc desc = {};
5249 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
5250 desc.image_width = width;
5251 desc.image_height = height;
5252 desc.image_row_pitch = row_pitch;
5253
5254 object_ = CL_(clCreateImage)(
5255 context(),
5256 flags,
5257 &format,
5258 &desc,
5259 host_ptr,
5260 &error);
5261
5262 detail::errHandler(error, __CREATE_IMAGE_ERR);
5263 if (err != nullptr) {
5264 *err = error;
5265 }
5266 }
5267#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5268#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
5269 if (!useCreateImage)
5270 {
5271 object_ = CL_(clCreateImage2D)(
5272 context(), flags,&format, width, height, row_pitch, host_ptr, &error);
5273
5274 detail::errHandler(error, __CREATE_IMAGE2D_ERR);
5275 if (err != nullptr) {
5276 *err = error;
5277 }
5278 }
5279#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
5280 }
5281
5282#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5287 * cl_khr_image2d_from_buffer extension.
5288 *
5289 * Wraps clCreateImage().
5290 */
5291 Image2D(
5292 const Context& context,
5293 ImageFormat format,
5294 const Buffer &sourceBuffer,
5295 size_type width,
5296 size_type height,
5297 size_type row_pitch = 0,
5298 cl_int* err = nullptr)
5299 {
5300 cl_int error;
5301
5302 cl_image_desc desc = {};
5303 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
5304 desc.image_width = width;
5305 desc.image_height = height;
5306 desc.image_row_pitch = row_pitch;
5307 desc.buffer = sourceBuffer();
5308
5309 object_ = CL_(clCreateImage)(
5310 context(),
5311 0, // flags inherited from buffer
5312 &format,
5313 &desc,
5314 nullptr,
5315 &error);
5316
5317 detail::errHandler(error, __CREATE_IMAGE_ERR);
5318 if (err != nullptr) {
5319 *err = error;
5320 }
5321 }
5322#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5323
5324#if CL_HPP_TARGET_OPENCL_VERSION >= 200
5333 * 2.0 API specification.
5334 *
5335 * Wraps clCreateImage().
5336 */
5337 Image2D(
5338 const Context& context,
5339 cl_channel_order order,
5340 const Image &sourceImage,
5341 cl_int* err = nullptr)
5342 {
5343 cl_int error;
5344
5345 // Descriptor fields have to match source image
5346 size_type sourceWidth =
5347 sourceImage.getImageInfo<CL_IMAGE_WIDTH>();
5348 size_type sourceHeight =
5349 sourceImage.getImageInfo<CL_IMAGE_HEIGHT>();
5350 size_type sourceRowPitch =
5351 sourceImage.getImageInfo<CL_IMAGE_ROW_PITCH>();
5352 cl_uint sourceNumMIPLevels =
5353 sourceImage.getImageInfo<CL_IMAGE_NUM_MIP_LEVELS>();
5354 cl_uint sourceNumSamples =
5355 sourceImage.getImageInfo<CL_IMAGE_NUM_SAMPLES>();
5356 cl_image_format sourceFormat =
5357 sourceImage.getImageInfo<CL_IMAGE_FORMAT>();
5358
5359 // Update only the channel order.
5360 // Channel format inherited from source.
5361 sourceFormat.image_channel_order = order;
5362
5363 cl_image_desc desc = {};
5364 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
5365 desc.image_width = sourceWidth;
5366 desc.image_height = sourceHeight;
5367 desc.image_row_pitch = sourceRowPitch;
5368 desc.num_mip_levels = sourceNumMIPLevels;
5369 desc.num_samples = sourceNumSamples;
5370 desc.buffer = sourceImage();
5371
5372 object_ = CL_(clCreateImage)(
5373 context(),
5374 0, // flags should be inherited from mem_object
5375 &sourceFormat,
5376 &desc,
5377 nullptr,
5378 &error);
5379
5380 detail::errHandler(error, __CREATE_IMAGE_ERR);
5381 if (err != nullptr) {
5382 *err = error;
5383 }
5384 }
5385#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
5386
5387#if CL_HPP_TARGET_OPENCL_VERSION >= 300
5394 * end with 0.
5395 * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
5396 * specified. Note alignment & exclusivity requirements.
5397 */
5398 Image2D(const Context &context, const vector<cl_mem_properties> &properties,
5399 cl_mem_flags flags, ImageFormat format, size_type width,
5400 size_type height, size_type row_pitch = 0, void *host_ptr = nullptr,
5401 cl_int *err = nullptr)
5402 {
5403 cl_int error;
5404
5405 cl_image_desc desc = {};
5406 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
5407 desc.image_width = width;
5408 desc.image_height = height;
5409 desc.image_row_pitch = row_pitch;
5410
5411 object_ = CL_(clCreateImageWithProperties)(
5412 context(),
5413 properties.empty() ? nullptr : properties.data(),
5414 flags, &format, &desc, host_ptr, &error);
5415
5416 detail::errHandler(error, __CREATE_IMAGE_ERR);
5417 if (err != nullptr) {
5418 *err = error;
5419 }
5420 }
5421
5427 * their corresponding values. The non-empty list must
5428 * end with 0.
5429 * \param buffer Refer to a valid buffer or image memory object.
5430 */
5431 Image2D(const Context &context, const vector<cl_mem_properties> &properties,
5432 cl_mem_flags flags, ImageFormat format, const Buffer &buffer,
5433 size_type width, size_type height, size_type row_pitch = 0,
5434 cl_int *err = nullptr)
5435 {
5436 cl_int error;
5437
5438 cl_image_desc desc = {};
5439 desc.image_type = CL_MEM_OBJECT_IMAGE2D;
5440 desc.image_width = width;
5441 desc.image_height = height;
5442 desc.image_row_pitch = row_pitch;
5443 desc.buffer = buffer();
5444
5445 object_ = CL_(clCreateImageWithProperties)(
5446 context(),
5447 properties.empty() ? nullptr : properties.data(),
5448 flags, &format, &desc, nullptr, &error);
5449
5450 detail::errHandler(error, __CREATE_IMAGE_ERR);
5451 if (err != nullptr) {
5452 *err = error;
5453 }
5454 }
5456#endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
5457
5459 Image2D() { }
5460
5464 * Defaults to false to maintain compatibility with
5465 * earlier versions.
5466 * See Memory for further details.
5467 */
5468 explicit Image2D(const cl_mem& image2D, bool retainObject = false) :
5469 Image(image2D, retainObject) { }
5470
5471 /*! \brief Assignment from cl_mem - performs shallow copy.
5472 *
5473 * See Memory for further details.
5474 */
5475 Image2D& operator = (const cl_mem& rhs)
5476 {
5477 Image::operator=(rhs);
5478 return *this;
5479 }
5480};
5481
5482
5483#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
5490 * \see Memory
5491 * \note Deprecated for OpenCL 1.2. Please use ImageGL instead.
5492 */
5493class CL_API_PREFIX__VERSION_1_1_DEPRECATED Image2DGL : public Image2D
5494{
5495public:
5497 * GL Texture.
5498 *
5499 * Wraps clCreateFromGLTexture2D().
5500 */
5501 Image2DGL(
5502 const Context& context,
5503 cl_mem_flags flags,
5504 cl_GLenum target,
5505 cl_GLint miplevel,
5506 cl_GLuint texobj,
5507 cl_int * err = nullptr)
5508 {
5509 cl_int error;
5510 object_ = CL_(clCreateFromGLTexture2D)(
5511 context(),
5512 flags,
5513 target,
5514 miplevel,
5515 texobj,
5516 &error);
5517
5518 detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR);
5519 if (err != nullptr) {
5520 *err = error;
5521 }
5523 }
5524
5526 Image2DGL() : Image2D() { }
5527
5531 * Defaults to false to maintain compatibility with
5532 * earlier versions.
5533 * See Memory for further details.
5534 */
5535 explicit Image2DGL(const cl_mem& image, bool retainObject = false) :
5536 Image2D(image, retainObject) { }
5537
5538 /*! \brief Assignment from cl_mem - performs shallow copy.
5539 *c
5540 * See Memory for further details.
5541 */
5542 Image2DGL& operator = (const cl_mem& rhs)
5543 {
5544 Image2D::operator=(rhs);
5545 return *this;
5546 }
5547
5548
5549
5550} CL_API_SUFFIX__VERSION_1_1_DEPRECATED;
5551#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5552
5553#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5557class Image2DArray : public Image
5558{
5559public:
5560 Image2DArray(
5561 const Context& context,
5562 cl_mem_flags flags,
5563 ImageFormat format,
5564 size_type arraySize,
5565 size_type width,
5566 size_type height,
5567 size_type rowPitch,
5568 size_type slicePitch,
5569 void* host_ptr = nullptr,
5570 cl_int* err = nullptr)
5571 {
5572 cl_int error;
5573
5574 cl_image_desc desc = {};
5575 desc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
5576 desc.image_width = width;
5577 desc.image_height = height;
5578 desc.image_array_size = arraySize;
5579 desc.image_row_pitch = rowPitch;
5580 desc.image_slice_pitch = slicePitch;
5581
5582 object_ = CL_(clCreateImage)(
5583 context(),
5584 flags,
5585 &format,
5586 &desc,
5587 host_ptr,
5588 &error);
5589
5590 detail::errHandler(error, __CREATE_IMAGE_ERR);
5591 if (err != nullptr) {
5592 *err = error;
5593 }
5594 }
5595
5596#if CL_HPP_TARGET_OPENCL_VERSION >= 300
5603 * end with 0.
5604 * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
5605 * specified. Note alignment & exclusivity requirements.
5606 */
5607 Image2DArray(const Context &context,
5608 const vector<cl_mem_properties> &properties,
5609 cl_mem_flags flags, ImageFormat format, size_type arraySize,
5610 size_type width, size_type height, size_type rowPitch = 0,
5611 size_type slicePitch = 0, void *host_ptr = nullptr,
5612 cl_int *err = nullptr)
5613 {
5614 cl_int error;
5615
5616 cl_image_desc desc = {};
5617 desc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
5618 desc.image_width = width;
5619 desc.image_height = height;
5620 desc.image_array_size = arraySize;
5621 desc.image_row_pitch = rowPitch;
5622 desc.image_slice_pitch = slicePitch;
5623
5624 object_ = CL_(clCreateImageWithProperties)(
5625 context(),
5626 properties.empty() ? nullptr : properties.data(),
5627 flags, &format, &desc, host_ptr, &error);
5628
5629 detail::errHandler(error, __CREATE_IMAGE_ERR);
5630 if (err != nullptr) {
5631 *err = error;
5632 }
5633 }
5634#endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
5635
5636 Image2DArray() { }
5637
5645 explicit Image2DArray(const cl_mem& imageArray, bool retainObject = false) : Image(imageArray, retainObject) { }
5646
5647 Image2DArray& operator = (const cl_mem& rhs)
5648 {
5649 Image::operator=(rhs);
5650 return *this;
5651 }
5652
5653};
5654#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5655
5658 * See Memory for details about copy semantics, etc.
5659 *
5660 * \see Memory
5661 */
5662class Image3D : public Image
5663{
5664public:
5665 /*! \brief Constructs a 3D Image in a specified context.
5666 *
5667 * Wraps clCreateImage().
5668 */
5669 Image3D(
5670 const Context& context,
5671 cl_mem_flags flags,
5672 ImageFormat format,
5673 size_type width,
5674 size_type height,
5675 size_type depth,
5676 size_type row_pitch = 0,
5677 size_type slice_pitch = 0,
5678 void* host_ptr = nullptr,
5679 cl_int* err = nullptr)
5680 {
5681 cl_int error;
5682 bool useCreateImage;
5683
5684#if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
5685 // Run-time decision based on the actual platform
5686 {
5687 cl_uint version = detail::getContextPlatformVersion(context());
5688 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
5689 }
5690#elif CL_HPP_TARGET_OPENCL_VERSION >= 120
5691 useCreateImage = true;
5692#else
5693 useCreateImage = false;
5694#endif
5695
5696#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5697 if (useCreateImage)
5698 {
5699 cl_image_desc desc = {};
5700 desc.image_type = CL_MEM_OBJECT_IMAGE3D;
5701 desc.image_width = width;
5702 desc.image_height = height;
5703 desc.image_depth = depth;
5704 desc.image_row_pitch = row_pitch;
5705 desc.image_slice_pitch = slice_pitch;
5706
5707 object_ = CL_(clCreateImage)(
5708 context(),
5709 flags,
5710 &format,
5711 &desc,
5712 host_ptr,
5713 &error);
5714
5715 detail::errHandler(error, __CREATE_IMAGE_ERR);
5716 if (err != nullptr) {
5717 *err = error;
5718 }
5719 }
5720#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5721#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
5722 if (!useCreateImage)
5723 {
5724 object_ = CL_(clCreateImage3D)(
5725 context(), flags, &format, width, height, depth, row_pitch,
5726 slice_pitch, host_ptr, &error);
5727
5728 detail::errHandler(error, __CREATE_IMAGE3D_ERR);
5729 if (err != nullptr) {
5730 *err = error;
5731 }
5732 }
5733#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
5734 }
5735
5736#if CL_HPP_TARGET_OPENCL_VERSION >= 300
5743 * end with 0.
5744 * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
5745 * specified. Note alignment & exclusivity requirements.
5746 */
5747 Image3D(const Context &context, const vector<cl_mem_properties> &properties,
5748 cl_mem_flags flags, ImageFormat format, size_type width,
5749 size_type height, size_type depth, size_type row_pitch = 0,
5750 size_type slice_pitch = 0, void *host_ptr = nullptr,
5751 cl_int *err = nullptr)
5752 {
5753 cl_int error;
5754
5755 cl_image_desc desc = {};
5756 desc.image_type = CL_MEM_OBJECT_IMAGE3D;
5757 desc.image_width = width;
5758 desc.image_height = height;
5759 desc.image_depth = depth;
5760 desc.image_row_pitch = row_pitch;
5761 desc.image_slice_pitch = slice_pitch;
5762
5763 object_ = CL_(clCreateImageWithProperties)(
5764 context(),
5765 properties.empty() ? nullptr : properties.data(),
5766 flags, &format, &desc, host_ptr, &error);
5767
5768 detail::errHandler(error, __CREATE_IMAGE_ERR);
5769 if (err != nullptr) {
5770 *err = error;
5771 }
5773#endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
5774
5776 Image3D() : Image() { }
5777
5781 * Defaults to false to maintain compatibility with
5782 * earlier versions.
5783 * See Memory for further details.
5784 */
5785 explicit Image3D(const cl_mem& image3D, bool retainObject = false) :
5786 Image(image3D, retainObject) { }
5787
5788 /*! \brief Assignment from cl_mem - performs shallow copy.
5789 *
5790 * See Memory for further details.
5791 */
5792 Image3D& operator = (const cl_mem& rhs)
5793 {
5794 Image::operator=(rhs);
5795 return *this;
5796 }
5797
5798};
5799
5800#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
5805 * See Memory for details about copy semantics, etc.
5806 *
5807 * \see Memory
5808 */
5809class Image3DGL : public Image3D
5810{
5811public:
5813 * GL Texture.
5814 *
5815 * Wraps clCreateFromGLTexture3D().
5816 */
5817 Image3DGL(
5818 const Context& context,
5819 cl_mem_flags flags,
5820 cl_GLenum target,
5821 cl_GLint miplevel,
5822 cl_GLuint texobj,
5823 cl_int * err = nullptr)
5824 {
5825 cl_int error;
5826 object_ = CL_(clCreateFromGLTexture3D)(
5827 context(),
5828 flags,
5829 target,
5830 miplevel,
5831 texobj,
5832 &error);
5833
5834 detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR);
5835 if (err != nullptr) {
5836 *err = error;
5838 }
5839
5841 Image3DGL() : Image3D() { }
5842
5846 * Defaults to false to maintain compatibility with
5847 * earlier versions.
5848 * See Memory for further details.
5849 */
5850 explicit Image3DGL(const cl_mem& image, bool retainObject = false) :
5851 Image3D(image, retainObject) { }
5852
5853 /*! \brief Assignment from cl_mem - performs shallow copy.
5854 *
5855 * See Memory for further details.
5856 */
5857 Image3DGL& operator = (const cl_mem& rhs)
5858 {
5859 Image3D::operator=(rhs);
5860 return *this;
5861 }
5862
5863};
5864#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5865
5866#if CL_HPP_TARGET_OPENCL_VERSION >= 120
5869 * We abstract the 2D and 3D GL images into a single instance here
5870 * that wraps all GL sourced images on the grounds that setup information
5871 * was performed by OpenCL anyway.
5872 */
5873class ImageGL : public Image
5874{
5875public:
5876 ImageGL(
5877 const Context& context,
5878 cl_mem_flags flags,
5879 cl_GLenum target,
5880 cl_GLint miplevel,
5881 cl_GLuint texobj,
5882 cl_int * err = nullptr)
5883 {
5884 cl_int error;
5885 object_ = CL_(clCreateFromGLTexture)(
5886 context(),
5887 flags,
5888 target,
5889 miplevel,
5890 texobj,
5891 &error);
5892
5893 detail::errHandler(error, __CREATE_GL_TEXTURE_ERR);
5894 if (err != nullptr) {
5895 *err = error;
5896 }
5897 }
5898
5899 ImageGL() : Image() { }
5900
5904 * Defaults to false to maintain compatibility with
5905 * earlier versions.
5906 * See Memory for further details.
5907 */
5908 explicit ImageGL(const cl_mem& image, bool retainObject = false) :
5909 Image(image, retainObject) { }
5910
5911 ImageGL& operator = (const cl_mem& rhs)
5912 {
5913 Image::operator=(rhs);
5914 return *this;
5915 }
5916
5917};
5918#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5919
5920
5921
5922#if CL_HPP_TARGET_OPENCL_VERSION >= 200
5925* See Memory for details about copy semantics, etc.
5926*
5927* \see Memory
5928*/
5929class Pipe : public Memory
5930{
5931public:
5932
5938 * @param packet_size Size in bytes of a single packet of the pipe.
5939 * @param max_packets Number of packets that may be stored in the pipe.
5940 *
5941 */
5942 Pipe(
5943 const Context& context,
5944 cl_uint packet_size,
5945 cl_uint max_packets,
5946 cl_int* err = nullptr)
5947 {
5948 cl_int error;
5949
5950 cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5951 object_ = CL_(clCreatePipe)(context(), flags, packet_size, max_packets, nullptr, &error);
5952
5953 detail::errHandler(error, __CREATE_PIPE_ERR);
5954 if (err != nullptr) {
5955 *err = error;
5956 }
5957 }
5958
5963 * @param packet_size Size in bytes of a single packet of the pipe.
5964 * @param max_packets Number of packets that may be stored in the pipe.
5965 *
5966 */
5967 Pipe(
5968 cl_uint packet_size,
5969 cl_uint max_packets,
5970 cl_int* err = nullptr)
5971 {
5972 cl_int error;
5973
5974 Context context = Context::getDefault(err);
5975
5976 cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5977 object_ = CL_(clCreatePipe)(context(), flags, packet_size, max_packets, nullptr, &error);
5978
5979 detail::errHandler(error, __CREATE_PIPE_ERR);
5980 if (err != nullptr) {
5981 *err = error;
5983 }
5984
5986 Pipe() : Memory() { }
5987
5991 * Defaults to false to maintain compatibility with earlier versions.
5992 *
5993 * See Memory for further details.
5994 */
5995 explicit Pipe(const cl_mem& pipe, bool retainObject = false) :
5996 Memory(pipe, retainObject) { }
5997
5998 /*! \brief Assignment from cl_mem - performs shallow copy.
5999 *
6000 * See Memory for further details.
6001 */
6002 Pipe& operator = (const cl_mem& rhs)
6003 {
6004 Memory::operator=(rhs);
6005 return *this;
6006 }
6007
6009
6011 template <typename T>
6012 cl_int getInfo(cl_pipe_info name, T* param) const
6013 {
6014 return detail::errHandler(
6015 detail::getInfo(CL_(clGetPipeInfo), object_, name, param),
6016 __GET_PIPE_INFO_ERR);
6017 }
6020 template <cl_pipe_info name> typename
6022 getInfo(cl_int* err = nullptr) const
6023 {
6024 typename detail::param_traits<
6025 detail::cl_pipe_info, name>::param_type param{};
6026 cl_int result = getInfo(name, &param);
6027 if (err != nullptr) {
6028 *err = result;
6029 }
6030 return param;
6031 }
6032}; // class Pipe
6033#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
6034
6035
6040 * clRetainSampler() and clReleaseSampler().
6041 *
6042 * \see cl_sampler
6043 */
6044class Sampler : public detail::Wrapper<cl_sampler>
6045{
6046public:
6048 Sampler() { }
6049
6050 /*! \brief Constructs a Sampler in a specified context.
6051 *
6052 * Wraps clCreateSampler().
6053 */
6054 Sampler(
6055 const Context& context,
6056 cl_bool normalized_coords,
6057 cl_addressing_mode addressing_mode,
6058 cl_filter_mode filter_mode,
6059 cl_int* err = nullptr)
6060 {
6061 cl_int error;
6062
6063#if CL_HPP_TARGET_OPENCL_VERSION >= 200
6064 cl_sampler_properties sampler_properties[] = {
6065 CL_SAMPLER_NORMALIZED_COORDS, normalized_coords,
6066 CL_SAMPLER_ADDRESSING_MODE, addressing_mode,
6067 CL_SAMPLER_FILTER_MODE, filter_mode,
6068 0 };
6069 object_ = CL_(clCreateSamplerWithProperties)(
6070 context(),
6071 sampler_properties,
6072 &error);
6073
6074 detail::errHandler(error, __CREATE_SAMPLER_WITH_PROPERTIES_ERR);
6075 if (err != nullptr) {
6076 *err = error;
6077 }
6078#else
6079 object_ = CL_(clCreateSampler)(
6080 context(),
6081 normalized_coords,
6082 addressing_mode,
6083 filter_mode,
6084 &error);
6085
6086 detail::errHandler(error, __CREATE_SAMPLER_ERR);
6087 if (err != nullptr) {
6088 *err = error;
6089 }
6090#endif
6091 }
6092
6097 * earlier versions.
6098 * This effectively transfers ownership of a refcount on the cl_sampler
6099 * into the new Sampler object.
6100 */
6101 explicit Sampler(const cl_sampler& sampler, bool retainObject = false) :
6102 detail::Wrapper<cl_type>(sampler, retainObject) { }
6103
6106 * This effectively transfers ownership of a refcount on the rhs and calls
6107 * clReleaseSampler() on the value previously held by this instance.
6108 */
6109 Sampler& operator = (const cl_sampler& rhs)
6110 {
6111 detail::Wrapper<cl_type>::operator=(rhs);
6112 return *this;
6113 }
6114
6116
6118 template <typename T>
6119 cl_int getInfo(cl_sampler_info name, T* param) const
6120 {
6121 return detail::errHandler(
6122 detail::getInfo(CL_(clGetSamplerInfo), object_, name, param),
6123 __GET_SAMPLER_INFO_ERR);
6124 }
6127 template <cl_sampler_info name> typename
6129 getInfo(cl_int* err = nullptr) const
6130 {
6131 typename detail::param_traits<
6132 detail::cl_sampler_info, name>::param_type param{};
6133 cl_int result = getInfo(name, &param);
6134 if (err != nullptr) {
6135 *err = result;
6136 }
6137 return param;
6138 }
6139};
6140
6141class Program;
6142class CommandQueue;
6144class Kernel;
6145
6147class NDRange
6148{
6149private:
6150 size_type sizes_[3];
6151 cl_uint dimensions_;
6152
6153public:
6155 NDRange()
6156 : dimensions_(0)
6157 {
6158 sizes_[0] = 0;
6159 sizes_[1] = 0;
6160 sizes_[2] = 0;
6161 }
6162
6164 NDRange(size_type size0)
6165 : dimensions_(1)
6166 {
6167 sizes_[0] = size0;
6168 sizes_[1] = 1;
6169 sizes_[2] = 1;
6170 }
6171
6173 NDRange(size_type size0, size_type size1)
6174 : dimensions_(2)
6175 {
6176 sizes_[0] = size0;
6177 sizes_[1] = size1;
6178 sizes_[2] = 1;
6179 }
6180
6182 NDRange(size_type size0, size_type size1, size_type size2)
6183 : dimensions_(3)
6184 {
6185 sizes_[0] = size0;
6186 sizes_[1] = size1;
6187 sizes_[2] = size2;
6188 }
6189
6191 NDRange(array<size_type, 1> a) : NDRange(a[0]){}
6192
6194 NDRange(array<size_type, 2> a) : NDRange(a[0], a[1]){}
6195
6197 NDRange(array<size_type, 3> a) : NDRange(a[0], a[1], a[2]){}
6198
6199 /*! \brief Conversion operator to const size_type *.
6200 *
6201 * \returns a pointer to the size of the first dimension.
6202 */
6203 operator const size_type*() const {
6204 return sizes_;
6205 }
6206
6208 size_type dimensions() const
6209 {
6210 return dimensions_;
6212
6214 // runtime number of dimensions
6215 size_type size() const
6216 {
6217 return dimensions_*sizeof(size_type);
6218 }
6219
6220 size_type* get()
6221 {
6222 return sizes_;
6223 }
6224
6225 const size_type* get() const
6226 {
6227 return sizes_;
6228 }
6229};
6230
6231//! \brief A zero-dimensional range.
6232static const NDRange NullRange;
6233
6235struct LocalSpaceArg
6236{
6237 size_type size_;
6238};
6240namespace detail {
6241
6242template <typename T, class Enable = void>
6245// Enable for objects that are not subclasses of memory
6246// Pointers, constants etc
6247template <typename T>
6248struct KernelArgumentHandler<T, typename std::enable_if<!std::is_base_of<cl::Memory, T>::value>::type>
6249{
6250 static size_type size(const T&) { return sizeof(T); }
6251 static const T* ptr(const T& value) { return &value; }
6252};
6254// Enable for subclasses of memory where we want to get a reference to the cl_mem out
6255// and pass that in for safety
6256template <typename T>
6257struct KernelArgumentHandler<T, typename std::enable_if<std::is_base_of<cl::Memory, T>::value>::type>
6258{
6259 static size_type size(const T&) { return sizeof(cl_mem); }
6260 static const cl_mem* ptr(const T& value) { return &(value()); }
6261};
6263// Specialization for DeviceCommandQueue defined later
6264
6265template <>
6267{
6268 static size_type size(const LocalSpaceArg& value) { return value.size_; }
6269 static const void* ptr(const LocalSpaceArg&) { return nullptr; }
6270};
6271
6272}
6274
6275/*! Local
6276 * \brief Helper function for generating LocalSpaceArg objects.
6277 */
6278inline LocalSpaceArg
6279Local(size_type size)
6280{
6281 LocalSpaceArg ret = { size };
6282 return ret;
6283}
6284
6289 * clRetainKernel() and clReleaseKernel().
6290 *
6291 * \see cl_kernel
6292 */
6293class Kernel : public detail::Wrapper<cl_kernel>
6294{
6295public:
6296 inline Kernel(const Program& program, const string& name, cl_int* err = nullptr);
6297 inline Kernel(const Program& program, const char* name, cl_int* err = nullptr);
6298
6300 Kernel() { }
6301
6306 * earlier versions.
6307 * This effectively transfers ownership of a refcount on the cl_kernel
6308 * into the new Kernel object.
6309 */
6310 explicit Kernel(const cl_kernel& kernel, bool retainObject = false) :
6311 detail::Wrapper<cl_type>(kernel, retainObject) { }
6312
6315 * This effectively transfers ownership of a refcount on the rhs and calls
6316 * clReleaseKernel() on the value previously held by this instance.
6317 */
6318 Kernel& operator = (const cl_kernel& rhs)
6319 {
6320 detail::Wrapper<cl_type>::operator=(rhs);
6321 return *this;
6322 }
6323
6324
6325
6326
6327 template <typename T>
6328 cl_int getInfo(cl_kernel_info name, T* param) const
6329 {
6330 return detail::errHandler(
6331 detail::getInfo(CL_(clGetKernelInfo), object_, name, param),
6332 __GET_KERNEL_INFO_ERR);
6333 }
6334
6335 template <cl_kernel_info name> typename
6336 detail::param_traits<detail::cl_kernel_info, name>::param_type
6337 getInfo(cl_int* err = nullptr) const
6338 {
6339 typename detail::param_traits<
6340 detail::cl_kernel_info, name>::param_type param{};
6341 cl_int result = getInfo(name, &param);
6342 if (err != nullptr) {
6343 *err = result;
6344 }
6345 return param;
6346 }
6347
6348#if CL_HPP_TARGET_OPENCL_VERSION >= 120
6349 template <typename T>
6350 cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const
6351 {
6352 return detail::errHandler(
6353 detail::getInfo(CL_(clGetKernelArgInfo), object_, argIndex, name, param),
6354 __GET_KERNEL_ARG_INFO_ERR);
6355 }
6356
6357 template <cl_kernel_arg_info name> typename
6358 detail::param_traits<detail::cl_kernel_arg_info, name>::param_type
6359 getArgInfo(cl_uint argIndex, cl_int* err = nullptr) const
6360 {
6361 typename detail::param_traits<
6362 detail::cl_kernel_arg_info, name>::param_type param{};
6363 cl_int result = getArgInfo(argIndex, name, &param);
6364 if (err != nullptr) {
6365 *err = result;
6366 }
6367 return param;
6368 }
6369#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6370
6371 template <typename T>
6372 cl_int getWorkGroupInfo(
6373 const Device& device, cl_kernel_work_group_info name, T* param) const
6374 {
6375 return detail::errHandler(
6376 detail::getInfo(
6377 CL_(clGetKernelWorkGroupInfo), object_, device(), name, param),
6378 __GET_KERNEL_WORK_GROUP_INFO_ERR);
6379 }
6380
6381 template <cl_kernel_work_group_info name> typename
6382 detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
6383 getWorkGroupInfo(const Device& device, cl_int* err = nullptr) const
6384 {
6385 typename detail::param_traits<
6386 detail::cl_kernel_work_group_info, name>::param_type param{};
6387 cl_int result = getWorkGroupInfo(device, name, &param);
6388 if (err != nullptr) {
6389 *err = result;
6390 }
6391 return param;
6392 }
6393
6394#if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) || CL_HPP_TARGET_OPENCL_VERSION >= 210
6395 cl_int getSubGroupInfo(const cl::Device &dev, cl_kernel_sub_group_info name, const cl::NDRange &range, size_type* param) const
6396 {
6397#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6398
6399 return detail::errHandler(
6400 CL_(clGetKernelSubGroupInfo)(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
6401 __GET_KERNEL_SUB_GROUP_INFO_ERR);
6402
6403#else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6404
6405 typedef clGetKernelSubGroupInfoKHR_fn PFN_clGetKernelSubGroupInfoKHR;
6406 static PFN_clGetKernelSubGroupInfoKHR pfn_clGetKernelSubGroupInfoKHR = nullptr;
6407 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetKernelSubGroupInfoKHR);
6408
6409 return detail::errHandler(
6410 pfn_clGetKernelSubGroupInfoKHR(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
6411 __GET_KERNEL_SUB_GROUP_INFO_ERR);
6412
6413#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6414 }
6415
6416 template <cl_kernel_sub_group_info name>
6417 size_type getSubGroupInfo(const cl::Device &dev, const cl::NDRange &range, cl_int* err = nullptr) const
6418 {
6419 size_type param;
6420 cl_int result = getSubGroupInfo(dev, name, range, &param);
6421 if (err != nullptr) {
6422 *err = result;
6423 }
6424 return param;
6425 }
6426#endif // defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) || CL_HPP_TARGET_OPENCL_VERSION >= 210
6427
6428#if CL_HPP_TARGET_OPENCL_VERSION >= 200
6431 template<typename T, class D>
6432 cl_int setArg(cl_uint index, const cl::pointer<T, D> &argPtr)
6433 {
6434 return detail::errHandler(
6435 CL_(clSetKernelArgSVMPointer)(object_, index, argPtr.get()),
6436 __SET_KERNEL_ARGS_ERR);
6437 }
6441 template<typename T, class Alloc>
6442 cl_int setArg(cl_uint index, const cl::vector<T, Alloc> &arg)
6443 {
6444 return detail::errHandler(
6445 CL_(clSetKernelArgSVMPointer)(object_, index,
6446 arg.empty() ? nullptr : arg.data()),
6447 __SET_KERNEL_ARGS_ERR);
6448 }
6449
6450 /*! \brief setArg overload taking a pointer type
6451 */
6452 template<typename T>
6453 typename std::enable_if<std::is_pointer<T>::value, cl_int>::type
6454 setArg(cl_uint index, const T argPtr)
6455 {
6456 return detail::errHandler(
6457 CL_(clSetKernelArgSVMPointer)(object_, index, argPtr),
6458 __SET_KERNEL_ARGS_ERR);
6459 }
6460#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6461
6462 /*! \brief setArg overload taking a POD type
6463 */
6464 template <typename T>
6465 typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6466 setArg(cl_uint index, const T &value)
6467 {
6468 return detail::errHandler(
6469 CL_(clSetKernelArg)(
6470 object_,
6471 index,
6474 __SET_KERNEL_ARGS_ERR);
6475 }
6476
6477 cl_int setArg(cl_uint index, size_type size, const void* argPtr)
6478 {
6479 return detail::errHandler(
6480 CL_(clSetKernelArg)(object_, index, size, argPtr),
6481 __SET_KERNEL_ARGS_ERR);
6482 }
6483
6484#if CL_HPP_TARGET_OPENCL_VERSION >= 200
6485 /*!
6486 * Specify a vector of SVM pointers that the kernel may access in
6487 * addition to its arguments.
6488 */
6489 cl_int setSVMPointers(const vector<void*> &pointerList)
6490 {
6491 return detail::errHandler(
6492 CL_(clSetKernelExecInfo)(
6493 object_,
6494 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6495 sizeof(void*) * pointerList.size(),
6496 pointerList.empty() ? nullptr : pointerList.data()));
6497 }
6498
6500 * Specify a std::array of SVM pointers that the kernel may access in
6501 * addition to its arguments.
6502 */
6503 template<int ArrayLength>
6504 cl_int setSVMPointers(const std::array<void*, ArrayLength> &pointerList)
6505 {
6506 return detail::errHandler(
6507 CL_(clSetKernelExecInfo)(
6508 object_,
6509 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6510 sizeof(void*) * pointerList.size(),
6511 pointerList.empty() ? nullptr : pointerList.data()));
6512 }
6513
6521 * if no devices in the context support fine-grained system SVM.
6522 *
6523 * \see clSetKernelExecInfo
6524 */
6525 cl_int enableFineGrainedSystemSVM(bool svmEnabled)
6526 {
6527 cl_bool svmEnabled_ = svmEnabled ? CL_TRUE : CL_FALSE;
6528 return detail::errHandler(
6529 CL_(clSetKernelExecInfo)(
6530 object_,
6531 CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM,
6532 sizeof(cl_bool),
6533 &svmEnabled_
6534 )
6535 );
6536 }
6537
6538 template<int index, int ArrayLength, class D, typename T0, typename T1, typename... Ts>
6539 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0, const pointer<T1, D> &t1, Ts & ... ts)
6540 {
6541 pointerList[index] = static_cast<void*>(t0.get());
6542 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6543 }
6544
6545 template<int index, int ArrayLength, typename T0, typename T1, typename... Ts>
6546 typename std::enable_if<std::is_pointer<T0>::value, void>::type
6547 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0, T1 t1, Ts... ts)
6548 {
6549 pointerList[index] = static_cast<void*>(t0);
6550 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6551 }
6552
6553 template<int index, int ArrayLength, typename T0, class D>
6554 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0)
6555 {
6556 pointerList[index] = static_cast<void*>(t0.get());
6557 }
6558
6559
6560 template<int index, int ArrayLength, typename T0>
6561 typename std::enable_if<std::is_pointer<T0>::value, void>::type
6562 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0)
6563 {
6564 pointerList[index] = static_cast<void*>(t0);
6565 }
6566
6567 template<typename T0, typename... Ts>
6568 cl_int setSVMPointers(const T0 &t0, Ts & ... ts)
6569 {
6570 std::array<void*, 1 + sizeof...(Ts)> pointerList;
6571
6572 setSVMPointersHelper<0, 1 + sizeof...(Ts)>(pointerList, t0, ts...);
6573 return detail::errHandler(
6574 CL_(clSetKernelExecInfo)(
6575 object_,
6576 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6577 sizeof(void*) * (1 + sizeof...(Ts)),
6578 pointerList.data()));
6579 }
6580
6581 template<typename T>
6582 cl_int setExecInfo(cl_kernel_exec_info param_name, const T& val)
6583 {
6584 return detail::errHandler(
6585 CL_(clSetKernelExecInfo)(
6586 object_,
6587 param_name,
6588 sizeof(T),
6589 &val));
6590 }
6591
6592 template<cl_kernel_exec_info name>
6593 cl_int setExecInfo(typename detail::param_traits<detail::cl_kernel_exec_info, name>::param_type& val)
6594 {
6595 return setExecInfo(name, val);
6596 }
6597#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6598
6599#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6601 * Make a deep copy of the kernel object including its arguments.
6602 * @return A new kernel object with internal state entirely separate from that
6603 * of the original but with any arguments set on the original intact.
6604 */
6605 Kernel clone()
6606 {
6607 cl_int error;
6608 Kernel retValue(CL_(clCloneKernel)(this->get(), &error));
6609
6610 detail::errHandler(error, __CLONE_KERNEL_ERR);
6611 return retValue;
6612 }
6613#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6614};
6619class Program : public detail::Wrapper<cl_program>
6620{
6621public:
6622#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6623 typedef vector<vector<unsigned char>> Binaries;
6624 typedef vector<string> Sources;
6625#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6626 typedef vector<std::pair<const void*, size_type> > Binaries;
6627 typedef vector<std::pair<const char*, size_type> > Sources;
6628#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6629
6630 Program(
6631 const string& source,
6632 bool build = false,
6633 cl_int* err = nullptr)
6634 {
6635 cl_int error;
6636
6637 const char * strings = source.c_str();
6638 const size_type length = source.size();
6639
6640 Context context = Context::getDefault(err);
6641
6642 object_ = CL_(clCreateProgramWithSource)(
6643 context(), (cl_uint)1, &strings, &length, &error);
6644
6645 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6646
6647 if (error == CL_SUCCESS && build) {
6648
6649 error = CL_(clBuildProgram)(
6650 object_,
6651 0,
6652 nullptr,
6653#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6654 "-cl-std=CL2.0",
6655#else
6656 "",
6657#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6658 nullptr,
6659 nullptr);
6660
6661 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6662 }
6663
6664 if (err != nullptr) {
6665 *err = error;
6666 }
6667 }
6668
6669 Program(
6670 const Context& context,
6671 const string& source,
6672 bool build = false,
6673 cl_int* err = nullptr)
6674 {
6675 cl_int error;
6676
6677 const char * strings = source.c_str();
6678 const size_type length = source.size();
6679
6680 object_ = CL_(clCreateProgramWithSource)(
6681 context(), (cl_uint)1, &strings, &length, &error);
6682
6683 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6684
6685 if (error == CL_SUCCESS && build) {
6686 error = CL_(clBuildProgram)(
6687 object_,
6688 0,
6689 nullptr,
6690#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6691 "-cl-std=CL2.0",
6692#else
6693 "",
6694#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6695 nullptr,
6696 nullptr);
6697
6698 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6699 }
6700
6701 if (err != nullptr) {
6702 *err = error;
6703 }
6704 }
6705
6706 /**
6707 * Create a program from a vector of source strings and the default context.
6708 * Does not compile or link the program.
6709 */
6710 Program(
6711 const Sources& sources,
6712 cl_int* err = nullptr)
6713 {
6714 cl_int error;
6715 Context context = Context::getDefault(err);
6716
6717 const size_type n = (size_type)sources.size();
6718
6719 vector<size_type> lengths(n);
6720 vector<const char*> strings(n);
6721
6722 for (size_type i = 0; i < n; ++i) {
6723#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6724 strings[i] = sources[(int)i].data();
6725 lengths[i] = sources[(int)i].length();
6726#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6727 strings[i] = sources[(int)i].first;
6728 lengths[i] = sources[(int)i].second;
6729#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6730 }
6731
6732 object_ = CL_(clCreateProgramWithSource)(
6733 context(), (cl_uint)n,
6734 strings.empty() ? nullptr : strings.data(),
6735 lengths.empty() ? nullptr : lengths.data(),
6736 &error);
6737
6738 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6739 if (err != nullptr) {
6740 *err = error;
6741 }
6742 }
6743
6744 /**
6745 * Create a program from a vector of source strings and a provided context.
6746 * Does not compile or link the program.
6747 */
6748 Program(
6749 const Context& context,
6750 const Sources& sources,
6751 cl_int* err = nullptr)
6752 {
6753 cl_int error;
6754
6755 const size_type n = (size_type)sources.size();
6756
6757 vector<size_type> lengths(n);
6758 vector<const char*> strings(n);
6759
6760 for (size_type i = 0; i < n; ++i) {
6761#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6762 strings[i] = sources[(int)i].data();
6763 lengths[i] = sources[(int)i].length();
6764#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6765 strings[i] = sources[(int)i].first;
6766 lengths[i] = sources[(int)i].second;
6767#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6768 }
6769
6770 object_ = CL_(clCreateProgramWithSource)(
6771 context(), (cl_uint)n,
6772 strings.empty() ? nullptr : strings.data(),
6773 lengths.empty() ? nullptr : lengths.data(),
6774 &error);
6775
6776 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6777 if (err != nullptr) {
6778 *err = error;
6779 }
6780 }
6781
6782#if defined(CL_HPP_USE_IL_KHR) || CL_HPP_TARGET_OPENCL_VERSION >= 210
6784 * Program constructor to allow construction of program from SPIR-V or another IL.
6785 *
6786 * Requires OpenCL 2.1 or newer or the cl_khr_il_program extension.
6787 */
6788 Program(
6789 const vector<char>& IL,
6790 bool build = false,
6791 cl_int* err = nullptr)
6792 {
6793 cl_int error;
6794
6795 Context context = Context::getDefault(err);
6796
6797#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6798
6799 object_ = CL_(clCreateProgramWithIL)(
6800 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6801
6802#else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6803
6804 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6805 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = nullptr;
6806 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6807
6808 object_ = pfn_clCreateProgramWithILKHR(
6809 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6810
6811#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6812
6813 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6814
6815 if (error == CL_SUCCESS && build) {
6816
6817 error = CL_(clBuildProgram)(
6818 object_,
6819 0,
6820 nullptr,
6821#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6822 "-cl-std=CL2.0",
6823#else
6824 "",
6825#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6826 nullptr,
6827 nullptr);
6828
6829 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6830 }
6831
6832 if (err != nullptr) {
6833 *err = error;
6834 }
6835 }
6836
6839 * for a specific context.
6840 *
6841 * Requires OpenCL 2.1 or newer or the cl_khr_il_program extension.
6842 */
6843 Program(
6844 const Context& context,
6845 const vector<char>& IL,
6846 bool build = false,
6847 cl_int* err = nullptr)
6848 {
6849 cl_int error;
6850
6851#if CL_HPP_TARGET_OPENCL_VERSION >= 210
6852
6853 object_ = CL_(clCreateProgramWithIL)(
6854 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6855
6856#else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6857
6858 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6859 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = nullptr;
6860 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6861
6862 object_ = pfn_clCreateProgramWithILKHR(
6863 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6864
6865#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6866
6867 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6868
6869 if (error == CL_SUCCESS && build) {
6870 error = CL_(clBuildProgram)(
6871 object_,
6872 0,
6873 nullptr,
6874#if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6875 "-cl-std=CL2.0",
6876#else
6877 "",
6878#endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6879 nullptr,
6880 nullptr);
6881
6882 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6883 }
6884
6885 if (err != nullptr) {
6886 *err = error;
6887 }
6888 }
6889#endif // defined(CL_HPP_USE_IL_KHR) || CL_HPP_TARGET_OPENCL_VERSION >= 210
6890
6906 * CL_INVALID_DEVICE if OpenCL devices listed in devices are not in the list of devices associated with context.
6907 * CL_INVALID_BINARY if an invalid program binary was encountered for any device. binaryStatus will return specific status for each device.
6908 * CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host.
6909 */
6910 Program(
6911 const Context& context,
6912 const vector<Device>& devices,
6913 const Binaries& binaries,
6914 vector<cl_int>* binaryStatus = nullptr,
6915 cl_int* err = nullptr)
6916 {
6917 cl_int error;
6918
6919 const size_type numDevices = devices.size();
6920
6921 // Catch size mismatch early and return
6922 if(binaries.size() != numDevices) {
6923 error = CL_INVALID_VALUE;
6924 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6925 if (err != nullptr) {
6926 *err = error;
6927 }
6928 return;
6929 }
6930
6931 vector<size_type> lengths(numDevices);
6932 vector<const unsigned char*> images(numDevices);
6933#if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6934 for (size_type i = 0; i < numDevices; ++i) {
6935 images[i] = binaries[i].data();
6936 lengths[i] = binaries[(int)i].size();
6937 }
6938#else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6939 for (size_type i = 0; i < numDevices; ++i) {
6940 images[i] = (const unsigned char*)binaries[i].first;
6941 lengths[i] = binaries[(int)i].second;
6942 }
6943#endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6944
6945 vector<cl_device_id> deviceIDs(numDevices);
6946 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6947 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6948 }
6949
6950 if(binaryStatus) {
6951 binaryStatus->resize(numDevices);
6952 }
6953
6954 object_ = CL_(clCreateProgramWithBinary)(
6955 context(),
6956 (cl_uint)deviceIDs.size(),
6957 deviceIDs.empty() ? nullptr : deviceIDs.data(),
6958 lengths.empty() ? nullptr : lengths.data(),
6959 images.empty() ? nullptr : images.data(),
6960 (binaryStatus != nullptr && numDevices > 0)
6961 ? &binaryStatus->front()
6962 : nullptr,
6963 &error);
6964
6965 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6966 if (err != nullptr) {
6967 *err = error;
6968 }
6969 }
6970
6971
6972#if CL_HPP_TARGET_OPENCL_VERSION >= 120
6973 /**
6974 * Create program using builtin kernels.
6975 * \param kernelNames Semi-colon separated list of builtin kernel names
6976 */
6977 Program(
6978 const Context& context,
6979 const vector<Device>& devices,
6980 const string& kernelNames,
6981 cl_int* err = nullptr)
6982 {
6983 cl_int error;
6984
6985 size_type numDevices = devices.size();
6986 vector<cl_device_id> deviceIDs(numDevices);
6987 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6988 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6989 }
6990
6991 object_ = CL_(clCreateProgramWithBuiltInKernels)(
6992 context(),
6993 (cl_uint)deviceIDs.size(),
6994 deviceIDs.empty() ? nullptr : deviceIDs.data(),
6995 kernelNames.c_str(),
6996 &error);
6997
6998 detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR);
6999 if (err != nullptr) {
7000 *err = error;
7001 }
7002 }
7003#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7004
7005 Program() { }
7006
7007
7010 * \param retainObject will cause the constructor to retain its cl object.
7011 * Defaults to false to maintain compatibility with
7012 * earlier versions.
7013 */
7014 explicit Program(const cl_program& program, bool retainObject = false) :
7015 detail::Wrapper<cl_type>(program, retainObject) { }
7016
7017 Program& operator = (const cl_program& rhs)
7018 {
7019 detail::Wrapper<cl_type>::operator=(rhs);
7020 return *this;
7021 }
7022
7023 cl_int build(
7024 const vector<Device>& devices,
7025 const string& options,
7026 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7027 void* data = nullptr) const
7028 {
7029 return build(devices, options.c_str(), notifyFptr, data);
7030 }
7031
7032 cl_int build(
7033 const vector<Device>& devices,
7034 const char* options = nullptr,
7035 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7036 void* data = nullptr) const
7037 {
7038 size_type numDevices = devices.size();
7039 vector<cl_device_id> deviceIDs(numDevices);
7040
7041 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
7042 deviceIDs[deviceIndex] = (devices[deviceIndex])();
7043 }
7044
7045 cl_int buildError = CL_(clBuildProgram)(
7046 object_,
7047 (cl_uint)deviceIDs.size(),
7048 deviceIDs.empty() ? nullptr : deviceIDs.data(),
7049 options,
7050 notifyFptr,
7051 data);
7052
7053 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
7054 }
7055
7056 cl_int build(
7057 const Device& device,
7058 const string& options,
7059 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7060 void* data = nullptr) const
7061 {
7062 return build(device, options.c_str(), notifyFptr, data);
7063 }
7064
7065 cl_int build(
7066 const Device& device,
7067 const char* options = nullptr,
7068 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7069 void* data = nullptr) const
7070 {
7071 cl_device_id deviceID = device();
7072
7073 cl_int buildError = CL_(clBuildProgram)(
7074 object_,
7075 1,
7076 &deviceID,
7077 options,
7078 notifyFptr,
7079 data);
7080
7081 BuildLogType buildLog(0);
7082 buildLog.push_back(std::make_pair(device, getBuildInfo<CL_PROGRAM_BUILD_LOG>(device)));
7083 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, buildLog);
7084 }
7085
7086 cl_int build(
7087 const string& options,
7088 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7089 void* data = nullptr) const
7090 {
7091 return build(options.c_str(), notifyFptr, data);
7092 }
7093
7094 cl_int build(
7095 const char* options = nullptr,
7096 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7097 void* data = nullptr) const
7098 {
7099 cl_int buildError = CL_(clBuildProgram)(
7100 object_,
7101 0,
7102 nullptr,
7103 options,
7104 notifyFptr,
7105 data);
7106
7107 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
7108 }
7109
7110#if CL_HPP_TARGET_OPENCL_VERSION >= 120
7111 cl_int compile(
7112 const string& options,
7113 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7114 void* data = nullptr) const
7115 {
7116 return compile(options.c_str(), notifyFptr, data);
7117 }
7118
7119 cl_int compile(
7120 const char* options = nullptr,
7121 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7122 void* data = nullptr) const
7123 {
7124 cl_int error = CL_(clCompileProgram)(
7125 object_,
7126 0,
7127 nullptr,
7128 options,
7129 0,
7130 nullptr,
7131 nullptr,
7132 notifyFptr,
7133 data);
7134 return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
7135 }
7136
7137 cl_int compile(
7138 const string& options,
7139 const vector<Program>& inputHeaders,
7140 const vector<string>& headerIncludeNames,
7141 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7142 void* data = nullptr) const
7143 {
7144 return compile(options.c_str(), inputHeaders, headerIncludeNames, notifyFptr, data);
7145 }
7146
7147 cl_int compile(
7148 const char* options,
7149 const vector<Program>& inputHeaders,
7150 const vector<string>& headerIncludeNames,
7151 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7152 void* data = nullptr) const
7153 {
7154 static_assert(sizeof(cl::Program) == sizeof(cl_program),
7155 "Size of cl::Program must be equal to size of cl_program");
7156
7157 vector<const char*> headerIncludeNamesCStr;
7158 for(const string& name: headerIncludeNames) {
7159 headerIncludeNamesCStr.push_back(name.c_str());
7160 }
7161
7162 cl_int error = CL_(clCompileProgram)(
7163 object_,
7164 0,
7165 nullptr,
7166 options,
7167 static_cast<cl_uint>(inputHeaders.size()),
7168 reinterpret_cast<const cl_program*>(inputHeaders.empty() ? nullptr : inputHeaders.data()),
7169 reinterpret_cast<const char**>(headerIncludeNamesCStr.empty() ? nullptr : headerIncludeNamesCStr.data()),
7170 notifyFptr,
7171 data);
7172 return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
7173 }
7174
7175 cl_int compile(
7176 const string& options,
7177 const vector<Device>& deviceList,
7178 const vector<Program>& inputHeaders = vector<Program>(),
7179 const vector<string>& headerIncludeNames = vector<string>(),
7180 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7181 void* data = nullptr) const
7182 {
7183 return compile(options.c_str(), deviceList, inputHeaders, headerIncludeNames, notifyFptr, data);
7184 }
7185
7186 cl_int compile(
7187 const char* options,
7188 const vector<Device>& devices,
7189 const vector<Program>& inputHeaders = vector<Program>(),
7190 const vector<string>& headerIncludeNames = vector<string>(),
7191 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7192 void* data = nullptr) const
7193 {
7194 static_assert(sizeof(cl::Program) == sizeof(cl_program),
7195 "Size of cl::Program must be equal to size of cl_program");
7196
7197 vector<cl_device_id> deviceIDs;
7198 for(const Device& device: devices) {
7199 deviceIDs.push_back(device());
7200 }
7201
7202 vector<const char*> headerIncludeNamesCStr;
7203 for(const string& name: headerIncludeNames) {
7204 headerIncludeNamesCStr.push_back(name.c_str());
7205 }
7206
7207 cl_int error = CL_(clCompileProgram)(
7208 object_,
7209 static_cast<cl_uint>(deviceIDs.size()),
7210 reinterpret_cast<const cl_device_id*>(deviceIDs.empty() ? nullptr : deviceIDs.data()),
7211 options,
7212 static_cast<cl_uint>(inputHeaders.size()),
7213 reinterpret_cast<const cl_program*>(inputHeaders.empty() ? nullptr : inputHeaders.data()),
7214 reinterpret_cast<const char**>(headerIncludeNamesCStr.empty() ? nullptr : headerIncludeNamesCStr.data()),
7215 notifyFptr,
7216 data);
7217 return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
7218 }
7219#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7220
7221 template <typename T>
7222 cl_int getInfo(cl_program_info name, T* param) const
7223 {
7224 return detail::errHandler(
7225 detail::getInfo(CL_(clGetProgramInfo), object_, name, param),
7226 __GET_PROGRAM_INFO_ERR);
7227 }
7228
7229 template <cl_program_info name> typename
7230 detail::param_traits<detail::cl_program_info, name>::param_type
7231 getInfo(cl_int* err = nullptr) const
7232 {
7233 typename detail::param_traits<
7234 detail::cl_program_info, name>::param_type param{};
7235 cl_int result = getInfo(name, &param);
7236 if (err != nullptr) {
7237 *err = result;
7238 }
7239 return param;
7240 }
7241
7242 template <typename T>
7243 cl_int getBuildInfo(
7244 const Device& device, cl_program_build_info name, T* param) const
7245 {
7246 return detail::errHandler(
7247 detail::getInfo(
7248 CL_(clGetProgramBuildInfo), object_, device(), name, param),
7249 __GET_PROGRAM_BUILD_INFO_ERR);
7250 }
7251
7252 template <cl_program_build_info name> typename
7253 detail::param_traits<detail::cl_program_build_info, name>::param_type
7254 getBuildInfo(const Device& device, cl_int* err = nullptr) const
7255 {
7256 typename detail::param_traits<
7257 detail::cl_program_build_info, name>::param_type param{};
7258 cl_int result = getBuildInfo(device, name, &param);
7259 if (err != nullptr) {
7260 *err = result;
7261 }
7262 return param;
7263 }
7264
7268 * On an error reading the info for any device, an empty vector of info will be returned.
7269 */
7270 template <cl_program_build_info name>
7271 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
7272 getBuildInfo(cl_int *err = nullptr) const
7273 {
7274 cl_int result = CL_SUCCESS;
7275
7276 auto devs = getInfo<CL_PROGRAM_DEVICES>(&result);
7277 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
7278 devInfo;
7279
7280 // If there was an initial error from getInfo return the error
7281 if (result != CL_SUCCESS) {
7282 if (err != nullptr) {
7283 *err = result;
7284 }
7285 return devInfo;
7286 }
7287
7288 for (const cl::Device &d : devs) {
7289 typename detail::param_traits<
7290 detail::cl_program_build_info, name>::param_type param{};
7291 result = getBuildInfo(d, name, &param);
7292 devInfo.push_back(
7294 (d, param));
7295 if (result != CL_SUCCESS) {
7296 // On error, leave the loop and return the error code
7297 break;
7298 }
7299 }
7300 if (err != nullptr) {
7301 *err = result;
7302 }
7303 if (result != CL_SUCCESS) {
7304 devInfo.clear();
7305 }
7306 return devInfo;
7307 }
7308
7309 cl_int createKernels(vector<Kernel>* kernels)
7310 {
7311 cl_uint numKernels;
7312 cl_int err = CL_(clCreateKernelsInProgram)(object_, 0, nullptr, &numKernels);
7313 if (err != CL_SUCCESS) {
7314 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
7315 }
7316
7317 vector<cl_kernel> value(numKernels);
7318 err = CL_(clCreateKernelsInProgram)(
7319 object_,
7320 numKernels,
7321 value.empty() ? nullptr : value.data(),
7322 nullptr);
7323 if (err != CL_SUCCESS) {
7324 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
7325 }
7326
7327 if (kernels) {
7328 kernels->resize(value.size());
7329
7330 // Assign to param, constructing with retain behaviour
7331 // to correctly capture each underlying CL object
7332 for (size_type i = 0; i < value.size(); i++) {
7333 // We do not need to retain because this kernel is being created
7334 // by the runtime
7335 (*kernels)[i] = Kernel(value[i], false);
7336 }
7337 }
7338 return CL_SUCCESS;
7339 }
7340
7341#if CL_HPP_TARGET_OPENCL_VERSION >= 220
7342#if defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
7349 * Each call to this function registers the specified user callback function
7350 * on a callback stack associated with program. The registered user callback
7351 * functions are called in the reverse order in which they were registered.
7352 */
7353 CL_API_PREFIX__VERSION_2_2_DEPRECATED cl_int setReleaseCallback(
7354 void (CL_CALLBACK * pfn_notify)(cl_program program, void * user_data),
7355 void * user_data = nullptr) CL_API_SUFFIX__VERSION_2_2_DEPRECATED
7356 {
7357 return detail::errHandler(
7358 CL_(clSetProgramReleaseCallback)(
7359 object_,
7360 pfn_notify,
7361 user_data),
7362 __SET_PROGRAM_RELEASE_CALLBACK_ERR);
7363 }
7364#endif // #if defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
7365
7368 * Wraps clSetProgramSpecializationConstant().
7369 */
7370 template <typename T>
7371 typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
7372 setSpecializationConstant(cl_uint index, const T &value)
7373 {
7374 return detail::errHandler(
7375 CL_(clSetProgramSpecializationConstant)(
7376 object_,
7377 index,
7378 sizeof(value),
7379 &value),
7380 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
7381 }
7382
7383 /*! \brief Sets a SPIR-V specialization constant.
7384 *
7385 * Wraps clSetProgramSpecializationConstant().
7386 */
7387 cl_int setSpecializationConstant(cl_uint index, size_type size, const void* value)
7388 {
7389 return detail::errHandler(
7390 CL_(clSetProgramSpecializationConstant)(
7391 object_,
7392 index,
7393 size,
7394 value),
7395 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
7396 }
7397#endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
7398};
7399
7400#if CL_HPP_TARGET_OPENCL_VERSION >= 120
7401inline Program linkProgram(
7402 const Program& input1,
7403 const Program& input2,
7404 const char* options = nullptr,
7405 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7406 void* data = nullptr,
7407 cl_int* err = nullptr)
7408{
7409 cl_int error_local = CL_SUCCESS;
7410 cl_program programs[2] = { input1(), input2() };
7411
7412 Context ctx = input1.getInfo<CL_PROGRAM_CONTEXT>(&error_local);
7413 if(error_local!=CL_SUCCESS) {
7414 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
7415 }
7416
7417 cl_program prog = CL_(clLinkProgram)(
7418 ctx(),
7419 0,
7420 nullptr,
7421 options,
7422 2,
7423 programs,
7424 notifyFptr,
7425 data,
7426 &error_local);
7427
7428 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
7429 if (err != nullptr) {
7430 *err = error_local;
7431 }
7432
7433 return Program(prog);
7434}
7435
7436inline Program linkProgram(
7437 const Program& input1,
7438 const Program& input2,
7439 const string& options,
7440 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7441 void* data = nullptr,
7442 cl_int* err = nullptr)
7443{
7444 return linkProgram(input1, input2, options.c_str(), notifyFptr, data, err);
7445}
7446
7447inline Program linkProgram(
7448 const vector<Program>& inputPrograms,
7449 const char* options = nullptr,
7450 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7451 void* data = nullptr,
7452 cl_int* err = nullptr)
7453{
7454 cl_int error_local = CL_SUCCESS;
7455 Context ctx;
7456
7457 static_assert(sizeof(cl::Program) == sizeof(cl_program),
7458 "Size of cl::Program must be equal to size of cl_program");
7459
7460 if(inputPrograms.size() > 0) {
7461 ctx = inputPrograms[0].getInfo<CL_PROGRAM_CONTEXT>(&error_local);
7462 if(error_local!=CL_SUCCESS) {
7463 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
7464 }
7465 }
7466
7467 cl_program prog = CL_(clLinkProgram)(
7468 ctx(),
7469 0,
7470 nullptr,
7471 options,
7472 static_cast<cl_uint>(inputPrograms.size()),
7473 reinterpret_cast<const cl_program *>(inputPrograms.empty() ? nullptr : inputPrograms.data()),
7474 notifyFptr,
7475 data,
7476 &error_local);
7477
7478 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
7479 if (err != nullptr) {
7480 *err = error_local;
7481 }
7482
7483 return Program(prog);
7484}
7485
7486inline Program linkProgram(
7487 const vector<Program>& inputPrograms,
7488 const string& options,
7489 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = nullptr,
7490 void* data = nullptr,
7491 cl_int* err = nullptr)
7492{
7493 return linkProgram(inputPrograms, options.c_str(), notifyFptr, data, err);
7494}
7495#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7496
7497// Template specialization for CL_PROGRAM_BINARIES
7498template <>
7499inline cl_int cl::Program::getInfo(cl_program_info name, vector<vector<unsigned char>>* param) const
7500{
7501 if (name != CL_PROGRAM_BINARIES) {
7502 return CL_INVALID_VALUE;
7503 }
7504 if (param) {
7505 // Resize the parameter array appropriately for each allocation
7506 // and pass down to the helper
7507
7508 vector<size_type> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>();
7509 size_type numBinaries = sizes.size();
7510
7511 // Resize the parameter array and constituent arrays
7512 param->resize(numBinaries);
7513 for (size_type i = 0; i < numBinaries; ++i) {
7514 (*param)[i].resize(sizes[i]);
7515 }
7516
7517 return detail::errHandler(
7518 detail::getInfo(CL_(clGetProgramInfo), object_, name, param),
7519 __GET_PROGRAM_INFO_ERR);
7520 }
7521
7522 return CL_SUCCESS;
7523}
7524
7525template<>
7526inline vector<vector<unsigned char>> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err) const
7527{
7528 vector<vector<unsigned char>> binariesVectors;
7529
7530 cl_int result = getInfo(CL_PROGRAM_BINARIES, &binariesVectors);
7531 if (err != nullptr) {
7532 *err = result;
7533 }
7534 return binariesVectors;
7535}
7536
7537#if CL_HPP_TARGET_OPENCL_VERSION >= 220
7538// Template specialization for clSetProgramSpecializationConstant
7539template <>
7540inline cl_int cl::Program::setSpecializationConstant(cl_uint index, const bool &value)
7541{
7542 cl_uchar ucValue = value ? CL_UCHAR_MAX : 0;
7543 return detail::errHandler(
7544 CL_(clSetProgramSpecializationConstant)(
7545 object_,
7546 index,
7547 sizeof(ucValue),
7548 &ucValue),
7549 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
7550}
7551#endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
7552
7553inline Kernel::Kernel(const Program& program, const string& name, cl_int* err)
7554{
7555 cl_int error;
7556
7557 object_ = CL_(clCreateKernel)(program(), name.c_str(), &error);
7558 detail::errHandler(error, __CREATE_KERNEL_ERR);
7559
7560 if (err != nullptr) {
7561 *err = error;
7562 }
7563}
7564
7565inline Kernel::Kernel(const Program& program, const char* name, cl_int* err)
7566{
7567 cl_int error;
7568
7569 object_ = CL_(clCreateKernel)(program(), name, &error);
7570 detail::errHandler(error, __CREATE_KERNEL_ERR);
7571
7572 if (err != nullptr) {
7573 *err = error;
7574 }
7575}
7576
7577#ifdef cl_khr_external_memory
7578enum class ExternalMemoryType : cl_external_memory_handle_type_khr
7579{
7580 None = 0,
7581#ifdef cl_khr_external_memory_android_hardware_buffer
7582 AndroidHardwareBuffer = CL_EXTERNAL_MEMORY_HANDLE_ANDROID_HARDWARE_BUFFER_KHR,
7583#endif // cl_khr_external_memory_android_hardware_buffer
7584#ifdef cl_khr_external_memory_opaque_fd
7585 OpaqueFd = CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR,
7586#endif // cl_khr_external_memory_opaque_fd
7587#ifdef cl_khr_external_memory_win32
7588 OpaqueWin32 = CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR,
7589 OpaqueWin32Kmt = CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR,
7590#endif // cl_khr_external_memory_win32
7591#ifdef cl_khr_external_memory_dma_buf
7592 DmaBuf = CL_EXTERNAL_MEMORY_HANDLE_DMA_BUF_KHR,
7593#endif // cl_khr_external_memory_dma_buf
7594};
7595#endif // cl_khr_external_memory
7596
7597enum class QueueProperties : cl_command_queue_properties
7598{
7599 None = 0,
7600 Profiling = CL_QUEUE_PROFILING_ENABLE,
7601 OutOfOrder = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,
7602};
7603
7604inline QueueProperties operator|(QueueProperties lhs, QueueProperties rhs)
7605{
7606 return static_cast<QueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
7607}
7608
7609inline QueueProperties operator&(QueueProperties lhs, QueueProperties rhs)
7610{
7611 return static_cast<QueueProperties>(static_cast<cl_command_queue_properties>(lhs) & static_cast<cl_command_queue_properties>(rhs));
7612}
7617class CommandQueue : public detail::Wrapper<cl_command_queue>
7618{
7619private:
7620 static std::once_flag default_initialized_;
7621 static CommandQueue default_;
7622 static cl_int default_error_;
7623
7629 static void makeDefault()
7630 {
7631 /* We don't want to throw an error from this function, so we have to
7632 * catch and set the error flag.
7633 */
7634#if defined(CL_HPP_ENABLE_EXCEPTIONS)
7635 try
7636#endif
7637 {
7638 int error;
7639 Context context = Context::getDefault(&error);
7640
7641 if (error != CL_SUCCESS) {
7642 default_error_ = error;
7643 }
7644 else {
7645 Device device = Device::getDefault();
7646 default_ = CommandQueue(context, device, 0, &default_error_);
7647 }
7648 }
7649#if defined(CL_HPP_ENABLE_EXCEPTIONS)
7650 catch (cl::Error &e) {
7651 default_error_ = e.err();
7652 }
7653#endif
7654 }
7655
7661 static void makeDefaultProvided(const CommandQueue &c) {
7662 default_ = c;
7663 }
7664
7665#ifdef cl_khr_external_memory
7666 static std::once_flag ext_memory_initialized_;
7667
7668 static void initMemoryExtension(const cl::Device& device)
7669 {
7670 auto platform = device.getInfo<CL_DEVICE_PLATFORM>()();
7671
7672 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireExternalMemObjectsKHR);
7673 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseExternalMemObjectsKHR);
7674
7675 if ((pfn_clEnqueueAcquireExternalMemObjectsKHR == nullptr)
7676 && (pfn_clEnqueueReleaseExternalMemObjectsKHR == nullptr))
7677 {
7678 detail::errHandler(CL_INVALID_VALUE, __ENQUEUE_ACQUIRE_EXTERNAL_MEMORY_ERR);
7679 }
7680 }
7681#endif // cl_khr_external_memory
7682
7683public:
7684#ifdef CL_HPP_UNIT_TEST_ENABLE
7691 static void unitTestClearDefault() {
7692 default_ = CommandQueue();
7693 }
7694#endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
7695
7696
7697 /*!
7698 * \brief Constructs a CommandQueue based on passed properties.
7699 * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
7700 */
7702 cl_command_queue_properties properties,
7703 cl_int* err = nullptr)
7704 {
7705 cl_int error;
7706
7707 Context context = Context::getDefault(&error);
7708 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7709
7710 if (error != CL_SUCCESS) {
7711 if (err != nullptr) {
7712 *err = error;
7713 }
7714 }
7715 else {
7716 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7717 bool useWithProperties;
7718
7719#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7720 // Run-time decision based on the actual platform
7721 {
7722 cl_uint version = detail::getContextPlatformVersion(context());
7723 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7724 }
7725#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7726 useWithProperties = true;
7727#else
7728 useWithProperties = false;
7729#endif
7730
7731#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7732 if (useWithProperties) {
7733 cl_queue_properties queue_properties[] = {
7734 CL_QUEUE_PROPERTIES, properties, 0 };
7735 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7736 object_ = CL_(clCreateCommandQueueWithProperties)(
7737 context(), device(), queue_properties, &error);
7738 }
7739 else {
7740 error = CL_INVALID_QUEUE_PROPERTIES;
7741 }
7742
7743 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7744 if (err != nullptr) {
7745 *err = error;
7746 }
7747 }
7748#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7749#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7750 if (!useWithProperties) {
7751 object_ = CL_(clCreateCommandQueue)(
7752 context(), device(), properties, &error);
7753
7754 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7755 if (err != nullptr) {
7756 *err = error;
7757 }
7758 }
7759#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7760 }
7761 }
7762
7763 /*!
7764 * \brief Constructs a CommandQueue based on passed properties.
7765 * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
7766 */
7768 QueueProperties properties,
7769 cl_int* err = nullptr)
7770 {
7771 cl_int error;
7772
7773 Context context = Context::getDefault(&error);
7774 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7775
7776 if (error != CL_SUCCESS) {
7777 if (err != nullptr) {
7778 *err = error;
7779 }
7780 }
7781 else {
7782 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7783 bool useWithProperties;
7784
7785#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7786 // Run-time decision based on the actual platform
7787 {
7788 cl_uint version = detail::getContextPlatformVersion(context());
7789 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7790 }
7791#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7792 useWithProperties = true;
7793#else
7794 useWithProperties = false;
7795#endif
7796
7797#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7798 if (useWithProperties) {
7799 cl_queue_properties queue_properties[] = {
7800 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7801
7802 object_ = CL_(clCreateCommandQueueWithProperties)(
7803 context(), device(), queue_properties, &error);
7804
7805 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7806 if (err != nullptr) {
7807 *err = error;
7808 }
7809 }
7810#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7811#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7812 if (!useWithProperties) {
7813 object_ = CL_(clCreateCommandQueue)(
7814 context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
7815
7816 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7817 if (err != nullptr) {
7818 *err = error;
7819 }
7820 }
7821#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7822
7823 }
7824 }
7825
7826 /*!
7827 * \brief Constructs a CommandQueue for an implementation defined device in the given context
7828 * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
7829 */
7830 explicit CommandQueue(
7831 const Context& context,
7832 cl_command_queue_properties properties = 0,
7833 cl_int* err = nullptr)
7834 {
7835 cl_int error;
7836 bool useWithProperties;
7837 vector<cl::Device> devices;
7838 error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7839
7840 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7841
7842 if (error != CL_SUCCESS)
7843 {
7844 if (err != nullptr) {
7845 *err = error;
7846 }
7847 return;
7848 }
7849
7850#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7851 // Run-time decision based on the actual platform
7852 {
7853 cl_uint version = detail::getContextPlatformVersion(context());
7854 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7855 }
7856#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7857 useWithProperties = true;
7858#else
7859 useWithProperties = false;
7860#endif
7861
7862#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7863 if (useWithProperties) {
7864 cl_queue_properties queue_properties[] = {
7865 CL_QUEUE_PROPERTIES, properties, 0 };
7866 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7867 object_ = CL_(clCreateCommandQueueWithProperties)(
7868 context(), devices[0](), queue_properties, &error);
7869 }
7870 else {
7871 error = CL_INVALID_QUEUE_PROPERTIES;
7872 }
7873
7874 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7875 if (err != nullptr) {
7876 *err = error;
7877 }
7878 }
7879#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7880#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7881 if (!useWithProperties) {
7882 object_ = CL_(clCreateCommandQueue)(
7883 context(), devices[0](), properties, &error);
7884
7885 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7886 if (err != nullptr) {
7887 *err = error;
7888 }
7889 }
7890#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7891 }
7892
7893 /*!
7894 * \brief Constructs a CommandQueue for an implementation defined device in the given context
7895 * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
7896 */
7897 explicit CommandQueue(
7898 const Context& context,
7899 QueueProperties properties,
7900 cl_int* err = nullptr)
7901 {
7902 cl_int error;
7903 bool useWithProperties;
7904 vector<cl::Device> devices;
7905 error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7906
7907 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7908
7909 if (error != CL_SUCCESS)
7910 {
7911 if (err != nullptr) {
7912 *err = error;
7913 }
7914 return;
7915 }
7916
7917#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7918 // Run-time decision based on the actual platform
7919 {
7920 cl_uint version = detail::getContextPlatformVersion(context());
7921 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7922 }
7923#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7924 useWithProperties = true;
7925#else
7926 useWithProperties = false;
7927#endif
7928
7929#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7930 if (useWithProperties) {
7931 cl_queue_properties queue_properties[] = {
7932 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7933 object_ = CL_(clCreateCommandQueueWithProperties)(
7934 context(), devices[0](), queue_properties, &error);
7935
7936 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7937 if (err != nullptr) {
7938 *err = error;
7939 }
7940 }
7941#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7942#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7943 if (!useWithProperties) {
7944 object_ = CL_(clCreateCommandQueue)(
7945 context(), devices[0](), static_cast<cl_command_queue_properties>(properties), &error);
7946
7947 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7948 if (err != nullptr) {
7949 *err = error;
7950 }
7951 }
7952#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7953 }
7954
7955 /*!
7956 * \brief Constructs a CommandQueue for a passed device and context
7957 * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
7958 */
7960 const Context& context,
7961 const Device& device,
7962 cl_command_queue_properties properties = 0,
7963 cl_int* err = nullptr)
7964 {
7965 cl_int error;
7966 bool useWithProperties;
7967
7968#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7969 // Run-time decision based on the actual platform
7970 {
7971 cl_uint version = detail::getContextPlatformVersion(context());
7972 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7973 }
7974#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7975 useWithProperties = true;
7976#else
7977 useWithProperties = false;
7978#endif
7979
7980#if CL_HPP_TARGET_OPENCL_VERSION >= 200
7981 if (useWithProperties) {
7982 cl_queue_properties queue_properties[] = {
7983 CL_QUEUE_PROPERTIES, properties, 0 };
7984 object_ = CL_(clCreateCommandQueueWithProperties)(
7985 context(), device(), queue_properties, &error);
7986
7987 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7988 if (err != nullptr) {
7989 *err = error;
7990 }
7991 }
7992#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7993#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7994 if (!useWithProperties) {
7995 object_ = CL_(clCreateCommandQueue)(
7996 context(), device(), properties, &error);
7997
7998 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7999 if (err != nullptr) {
8000 *err = error;
8001 }
8002 }
8003#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
8004 }
8005
8006 /*!
8007 * \brief Constructs a CommandQueue for a passed device and context
8008 * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
8009 */
8011 const Context& context,
8012 const Device& device,
8013 QueueProperties properties,
8014 cl_int* err = nullptr)
8015 {
8016 cl_int error;
8017 bool useWithProperties;
8018
8019#if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
8020 // Run-time decision based on the actual platform
8021 {
8022 cl_uint version = detail::getContextPlatformVersion(context());
8023 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
8024 }
8025#elif CL_HPP_TARGET_OPENCL_VERSION >= 200
8026 useWithProperties = true;
8027#else
8028 useWithProperties = false;
8029#endif
8030
8031#if CL_HPP_TARGET_OPENCL_VERSION >= 200
8032 if (useWithProperties) {
8033 cl_queue_properties queue_properties[] = {
8034 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
8035 object_ = CL_(clCreateCommandQueueWithProperties)(
8036 context(), device(), queue_properties, &error);
8037
8038 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8039 if (err != nullptr) {
8040 *err = error;
8041 }
8042 }
8043#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
8044#if CL_HPP_MINIMUM_OPENCL_VERSION < 200
8045 if (!useWithProperties) {
8046 object_ = CL_(clCreateCommandQueue)(
8047 context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
8048
8049 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
8050 if (err != nullptr) {
8051 *err = error;
8052 }
8053 }
8054#endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
8055 }
8056
8057 static CommandQueue getDefault(cl_int * err = nullptr)
8058 {
8059 std::call_once(default_initialized_, makeDefault);
8060#if CL_HPP_TARGET_OPENCL_VERSION >= 200
8061 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8062#else // CL_HPP_TARGET_OPENCL_VERSION >= 200
8063 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_ERR);
8064#endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
8065 if (err != nullptr) {
8066 *err = default_error_;
8067 }
8068 return default_;
8069 }
8070
8074 * Will only set the default if no default was previously created.
8075 * @return updated default command queue.
8076 * Should be compared to the passed value to ensure that it was updated.
8077 */
8078 static CommandQueue setDefault(const CommandQueue &default_queue)
8079 {
8080 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_queue));
8081 detail::errHandler(default_error_);
8082 return default_;
8083 }
8084
8085 CommandQueue() { }
8086
8087
8090 * \param retainObject will cause the constructor to retain its cl object.
8091 * Defaults to false to maintain compatibility with
8092 * earlier versions.
8093 */
8094 explicit CommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
8095 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
8096
8097 CommandQueue& operator = (const cl_command_queue& rhs)
8098 {
8099 detail::Wrapper<cl_type>::operator=(rhs);
8100 return *this;
8101 }
8102
8103 template <typename T>
8104 cl_int getInfo(cl_command_queue_info name, T* param) const
8105 {
8106 return detail::errHandler(
8107 detail::getInfo(
8108 CL_(clGetCommandQueueInfo), object_, name, param),
8109 __GET_COMMAND_QUEUE_INFO_ERR);
8110 }
8111
8112 template <cl_command_queue_info name> typename
8113 detail::param_traits<detail::cl_command_queue_info, name>::param_type
8114 getInfo(cl_int* err = nullptr) const
8115 {
8116 typename detail::param_traits<
8117 detail::cl_command_queue_info, name>::param_type param{};
8118 cl_int result = getInfo(name, &param);
8119 if (err != nullptr) {
8120 *err = result;
8121 }
8122 return param;
8123 }
8124
8125 cl_int enqueueReadBuffer(
8126 const Buffer& buffer,
8127 cl_bool blocking,
8128 size_type offset,
8129 size_type size,
8130 void* ptr,
8131 const vector<Event>* events = nullptr,
8132 Event* event = nullptr) const
8133 {
8134 cl_event tmp;
8135 cl_int err = detail::errHandler(
8136 CL_(clEnqueueReadBuffer)(
8137 object_, buffer(), blocking, offset, size,
8138 ptr,
8139 (events != nullptr) ? (cl_uint) events->size() : 0,
8140 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
8141 (event != nullptr) ? &tmp : nullptr),
8142 __ENQUEUE_READ_BUFFER_ERR);
8143
8144 if (event != nullptr && err == CL_SUCCESS)
8145 *event = tmp;
8146
8147 return err;
8148 }
8149
8150 cl_int enqueueWriteBuffer(
8151 const Buffer& buffer,
8152 cl_bool blocking,
8153 size_type offset,
8154 size_type size,
8155 const void* ptr,
8156 const vector<Event>* events = nullptr,
8157 Event* event = nullptr) const
8158 {
8159 cl_event tmp;
8160 cl_int err = detail::errHandler(
8161 CL_(clEnqueueWriteBuffer)(
8162 object_, buffer(), blocking, offset, size,
8163 ptr,
8164 (events != nullptr) ? (cl_uint) events->size() : 0,
8165 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
8166 (event != nullptr) ? &tmp : nullptr),
8167 __ENQUEUE_WRITE_BUFFER_ERR);
8168
8169 if (event != nullptr && err == CL_SUCCESS)
8170 *event = tmp;
8171
8172 return err;
8173 }
8174
8175 cl_int enqueueCopyBuffer(
8176 const Buffer& src,
8177 const Buffer& dst,
8178 size_type src_offset,
8179 size_type dst_offset,
8180 size_type size,
8181 const vector<Event>* events = nullptr,
8182 Event* event = nullptr) const
8183 {
8184 cl_event tmp;
8185 cl_int err = detail::errHandler(
8186 CL_(clEnqueueCopyBuffer)(
8187 object_, src(), dst(), src_offset, dst_offset, size,
8188 (events != nullptr) ? (cl_uint) events->size() : 0,
8189 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
8190 (event != nullptr) ? &tmp : nullptr),
8191 __ENQEUE_COPY_BUFFER_ERR);
8192
8193 if (event != nullptr && err == CL_SUCCESS)
8194 *event = tmp;
8195
8196 return err;
8197 }
8198#if CL_HPP_TARGET_OPENCL_VERSION >= 110
8199 cl_int enqueueReadBufferRect(
8200 const Buffer& buffer,
8201 cl_bool blocking,
8202 const array<size_type, 3>& buffer_offset,
8203 const array<size_type, 3>& host_offset,
8204 const array<size_type, 3>& region,
8205 size_type buffer_row_pitch,
8206 size_type buffer_slice_pitch,
8207 size_type host_row_pitch,
8208 size_type host_slice_pitch,
8209 void *ptr,
8210 const vector<Event>* events = nullptr,
8211 Event* event = nullptr) const
8212 {
8213 cl_event tmp;
8214 cl_int err = detail::errHandler(
8215 CL_(clEnqueueReadBufferRect)(
8216 object_,
8217 buffer(),
8218 blocking,
8219 buffer_offset.data(),
8220 host_offset.data(),
8221 region.data(),
8222 buffer_row_pitch,
8223 buffer_slice_pitch,
8224 host_row_pitch,
8225 host_slice_pitch,
8226 ptr,
8227 (events != nullptr) ? (cl_uint) events->size() : 0,
8228 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
8229 (event != nullptr) ? &tmp : nullptr),
8230 __ENQUEUE_READ_BUFFER_RECT_ERR);
8231
8232 if (event != nullptr && err == CL_SUCCESS)
8233 *event = tmp;
8234
8235 return err;
8236 }
8237
8238 cl_int enqueueReadBufferRect(
8239 const Buffer& buffer,
8240 cl_bool blocking,
8241 const array<size_type, 2>& buffer_offset,
8242 const array<size_type, 2>& host_offset,
8243 const array<size_type, 2>& region,
8244 size_type buffer_row_pitch,
8245 size_type buffer_slice_pitch,
8246 size_type host_row_pitch,
8247 size_type host_slice_pitch,
8248 void* ptr,
8249 const vector<Event>* events = nullptr,
8250 Event* event = nullptr) const
8251 {
8252 return enqueueReadBufferRect(
8253 buffer,
8254 blocking,
8255 { buffer_offset[0], buffer_offset[1], 0 },
8256 { host_offset[0], host_offset[1], 0 },
8257 { region[0], region[1], 1 },
8258 buffer_row_pitch,
8259 buffer_slice_pitch,
8260 host_row_pitch,
8261 host_slice_pitch,
8262 ptr,
8263 events,
8264 event);
8265 }
8266
8267 cl_int enqueueWriteBufferRect(
8268 const Buffer& buffer,
8269 cl_bool blocking,
8270 const array<size_type, 3>& buffer_offset,
8271 const array<size_type, 3>& host_offset,
8272 const array<size_type, 3>& region,
8273 size_type buffer_row_pitch,
8274 size_type buffer_slice_pitch,
8275 size_type host_row_pitch,
8276 size_type host_slice_pitch,
8277 const void *ptr,
8278 const vector<Event>* events = nullptr,
8279 Event* event = nullptr) const
8280 {
8281 cl_event tmp;
8282 cl_int err = detail::errHandler(
8283 CL_(clEnqueueWriteBufferRect)(
8284 object_,
8285 buffer(),
8286 blocking,
8287 buffer_offset.data(),
8288 host_offset.data(),
8289 region.data(),
8290 buffer_row_pitch,
8291 buffer_slice_pitch,
8292 host_row_pitch,
8293 host_slice_pitch,
8294 ptr,
8295 (events != nullptr) ? (cl_uint) events->size() : 0,
8296 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
8297 (event != nullptr) ? &tmp : nullptr),
8298 __ENQUEUE_WRITE_BUFFER_RECT_ERR);
8299
8300 if (event != nullptr && err == CL_SUCCESS)
8301 *event = tmp;
8302
8303 return err;
8304 }
8305
8306 cl_int enqueueWriteBufferRect(
8307 const Buffer& buffer,
8308 cl_bool blocking,
8309 const array<size_type, 2>& buffer_offset,
8310 const array<size_type, 2>& host_offset,
8311 const array<size_type, 2>& region,
8312 size_type buffer_row_pitch,
8313 size_type buffer_slice_pitch,
8314 size_type host_row_pitch,
8315 size_type host_slice_pitch,
8316 const void* ptr,
8317 const vector<Event>* events = nullptr,
8318 Event* event = nullptr) const
8319 {
8320 return enqueueWriteBufferRect(
8321 buffer,
8322 blocking,
8323 { buffer_offset[0], buffer_offset[1], 0 },
8324 { host_offset[0], host_offset[1], 0 },
8325 { region[0], region[1], 1 },
8326 buffer_row_pitch,
8327 buffer_slice_pitch,
8328 host_row_pitch,
8329 host_slice_pitch,
8330 ptr,
8331 events,
8332 event);
8333 }
8334
8335 cl_int enqueueCopyBufferRect(
8336 const Buffer& src,
8337 const Buffer& dst,
8338 const array<size_type, 3>& src_origin,
8339 const array<size_type, 3>& dst_origin,
8340 const array<size_type, 3>& region,
8341 size_type src_row_pitch,
8342 size_type src_slice_pitch,
8343 size_type dst_row_pitch,
8344 size_type dst_slice_pitch,
8345 const vector<Event>* events = nullptr,
8346 Event* event = nullptr) const
8347 {
8348 cl_event tmp;
8349 cl_int err = detail::errHandler(
8350 CL_(clEnqueueCopyBufferRect)(
8351 object_,
8352 src(),
8353 dst(),
8354 src_origin.data(),
8355 dst_origin.data(),
8356 region.data(),
8357 src_row_pitch,
8358 src_slice_pitch,
8359 dst_row_pitch,
8360 dst_slice_pitch,
8361 (events != nullptr) ? (cl_uint) events->size() : 0,
8362 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
8363 (event != nullptr) ? &tmp : nullptr),
8364 __ENQEUE_COPY_BUFFER_RECT_ERR);
8365
8366 if (event != nullptr && err == CL_SUCCESS)
8367 *event = tmp;
8368
8369 return err;
8370 }
8371
8372 cl_int enqueueCopyBufferRect(
8373 const Buffer& src,
8374 const Buffer& dst,
8375 const array<size_type, 2>& src_origin,
8376 const array<size_type, 2>& dst_origin,
8377 const array<size_type, 2>& region,
8378 size_type src_row_pitch,
8379 size_type src_slice_pitch,
8380 size_type dst_row_pitch,
8381 size_type dst_slice_pitch,
8382 const vector<Event>* events = nullptr,
8383 Event* event = nullptr) const
8384 {
8385 return enqueueCopyBufferRect(
8386 src,
8387 dst,
8388 { src_origin[0], src_origin[1], 0 },
8389 { dst_origin[0], dst_origin[1], 0 },
8390 { region[0], region[1], 1 },
8391 src_row_pitch,
8392 src_slice_pitch,
8393 dst_row_pitch,
8394 dst_slice_pitch,
8395 events,
8396 event);
8397 }
8398
8399#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
8400#if CL_HPP_TARGET_OPENCL_VERSION >= 120
8409 * \tparam size Is the size in bytes of the region to fill.
8410 * This must be a multiple of the pattern size.
8411 */
8412 template<typename PatternType>
8413 cl_int enqueueFillBuffer(
8414 const Buffer& buffer,
8415 PatternType pattern,
8416 size_type offset,
8417 size_type size,
8418 const vector<Event>* events = nullptr,
8419 Event* event = nullptr) const
8420 {
8421 cl_event tmp;
8422 cl_int err = detail::errHandler(
8423 CL_(clEnqueueFillBuffer)(
8424 object_,
8425 buffer(),
8426 static_cast<void*>(&pattern),
8427 sizeof(PatternType),
8428 offset,
8429 size,
8430 (events != nullptr) ? (cl_uint) events->size() : 0,
8431 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
8432 (event != nullptr) ? &tmp : nullptr),
8433 __ENQUEUE_FILL_BUFFER_ERR);
8434
8435 if (event != nullptr && err == CL_SUCCESS)
8436 *event = tmp;
8437
8438 return err;
8439 }
8440#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8441
8442 cl_int enqueueReadImage(
8443 const Image& image,
8444 cl_bool blocking,
8445 const array<size_type, 3>& origin,
8446 const array<size_type, 3>& region,
8447 size_type row_pitch,
8448 size_type slice_pitch,
8449 void* ptr,
8450 const vector<Event>* events = nullptr,
8451 Event* event = nullptr) const
8452 {
8453 cl_event tmp;
8454 cl_int err = detail::errHandler(
8455 CL_(clEnqueueReadImage)(
8456 object_,
8457 image(),
8458 blocking,
8459 origin.data(),
8460 region.data(),
8461 row_pitch,
8462 slice_pitch,
8463 ptr,
8464 (events != nullptr) ? (cl_uint) events->size() : 0,
8465 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
8466 (event != nullptr) ? &tmp : nullptr),
8467 __ENQUEUE_READ_IMAGE_ERR);
8468
8469 if (event != nullptr && err == CL_SUCCESS)
8470 *event = tmp;
8471
8472 return err;
8473 }
8474
8475 cl_int enqueueReadImage(
8476 const Image& image,
8477 cl_bool blocking,
8478 const array<size_type, 2>& origin,
8479 const array<size_type, 2>& region,
8480 size_type row_pitch,
8481 size_type slice_pitch,
8482 void* ptr,
8483 const vector<Event>* events = nullptr,
8484 Event* event = nullptr) const
8485 {
8486 return enqueueReadImage(
8487 image,
8488 blocking,
8489 { origin[0], origin[1], 0 },
8490 { region[0], region[1], 1 },
8491 row_pitch,
8492 slice_pitch,
8493 ptr,
8494 events,
8495 event);
8496 }
8497
8498 cl_int enqueueWriteImage(
8499 const Image& image,
8500 cl_bool blocking,
8501 const array<size_type, 3>& origin,
8502 const array<size_type, 3>& region,
8503 size_type row_pitch,
8504 size_type slice_pitch,
8505 const void* ptr,
8506 const vector<Event>* events = nullptr,
8507 Event* event = nullptr) const
8508 {
8509 cl_event tmp;
8510 cl_int err = detail::errHandler(
8511 CL_(clEnqueueWriteImage)(
8512 object_,
8513 image(),
8514 blocking,
8515 origin.data(),
8516 region.data(),
8517 row_pitch,
8518 slice_pitch,
8519 ptr,
8520 (events != nullptr) ? (cl_uint) events->size() : 0,
8521 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
8522 (event != nullptr) ? &tmp : nullptr),
8523 __ENQUEUE_WRITE_IMAGE_ERR);
8524
8525 if (event != nullptr && err == CL_SUCCESS)
8526 *event = tmp;
8527
8528 return err;
8529 }
8530
8531 cl_int enqueueWriteImage(
8532 const Image& image,
8533 cl_bool blocking,
8534 const array<size_type, 2>& origin,
8535 const array<size_type, 2>& region,
8536 size_type row_pitch,
8537 size_type slice_pitch,
8538 const void* ptr,
8539 const vector<Event>* events = nullptr,
8540 Event* event = nullptr) const
8541 {
8542 return enqueueWriteImage(
8543 image,
8544 blocking,
8545 { origin[0], origin[1], 0 },
8546 { region[0], region[1], 1 },
8547 row_pitch,
8548 slice_pitch,
8549 ptr,
8550 events,
8551 event);
8552 }
8553
8554 cl_int enqueueCopyImage(
8555 const Image& src,
8556 const Image& dst,
8557 const array<size_type, 3>& src_origin,
8558 const array<size_type, 3>& dst_origin,
8559 const array<size_type, 3>& region,
8560 const vector<Event>* events = nullptr,
8561 Event* event = nullptr) const
8562 {
8563 cl_event tmp;
8564 cl_int err = detail::errHandler(
8565 CL_(clEnqueueCopyImage)(
8566 object_,
8567 src(),
8568 dst(),
8569 src_origin.data(),
8570 dst_origin.data(),
8571 region.data(),
8572 (events != nullptr) ? (cl_uint) events->size() : 0,
8573 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
8574 (event != nullptr) ? &tmp : nullptr),
8575 __ENQUEUE_COPY_IMAGE_ERR);
8576
8577 if (event != nullptr && err == CL_SUCCESS)
8578 *event = tmp;
8579
8580 return err;
8581 }
8582
8583 cl_int enqueueCopyImage(
8584 const Image& src,
8585 const Image& dst,
8586 const array<size_type, 2>& src_origin,
8587 const array<size_type, 2>& dst_origin,
8588 const array<size_type, 2>& region,
8589 const vector<Event>* events = nullptr,
8590 Event* event = nullptr) const
8591 {
8592 return enqueueCopyImage(
8593 src,
8594 dst,
8595 { src_origin[0], src_origin[1], 0 },
8596 { dst_origin[0], dst_origin[1], 0 },
8597 { region[0], region[1], 1 },
8598 events,
8599 event);
8600 }
8601
8602#if CL_HPP_TARGET_OPENCL_VERSION >= 120
8610 template <typename T>
8611 typename std::enable_if<std::is_same<T, cl_float4>::value ||
8612 std::is_same<T, cl_int4 >::value ||
8613 std::is_same<T, cl_uint4 >::value,
8614 cl_int>::type
8616 const Image& image,
8617 T fillColor,
8618 const array<size_type, 3>& origin,
8619 const array<size_type, 3>& region,
8620 const vector<Event>* events = nullptr,
8621 Event* event = nullptr) const
8622 {
8623 cl_event tmp;
8624 cl_int err = detail::errHandler(
8625 CL_(clEnqueueFillImage)(
8626 object_,
8627 image(),
8628 static_cast<void*>(&fillColor),
8629 origin.data(),
8630 region.data(),
8631 (events != nullptr) ? (cl_uint)events->size() : 0,
8632 (events != nullptr && events->size() > 0) ? (const cl_event*)&events->front() : NULL,
8633 (event != NULL) ? &tmp : nullptr),
8634 __ENQUEUE_FILL_IMAGE_ERR);
8635
8636 if (event != nullptr && err == CL_SUCCESS) *event = tmp;
8637
8638 return err;
8639 }
8640
8648 template <typename T>
8649 typename std::enable_if<std::is_same<T, cl_float4>::value ||
8650 std::is_same<T, cl_int4 >::value ||
8651 std::is_same<T, cl_uint4 >::value, cl_int>::type
8653 const Image& image,
8654 T fillColor,
8655 const array<size_type, 2>& origin,
8656 const array<size_type, 2>& region,
8657 const vector<Event>* events = nullptr,
8658 Event* event = nullptr) const
8659 {
8660 return enqueueFillImage(
8661 image,
8662 fillColor,
8663 { origin[0], origin[1], 0 },
8664 { region[0], region[1], 1 },
8665 events,
8666 event
8667 );
8668 }
8669#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8670
8671 cl_int enqueueCopyImageToBuffer(
8672 const Image& src,
8673 const Buffer& dst,
8674 const array<size_type, 3>& src_origin,
8675 const array<size_type, 3>& region,
8676 size_type dst_offset,
8677 const vector<Event>* events = nullptr,
8678 Event* event = nullptr) const
8679 {
8680 cl_event tmp;
8681 cl_int err = detail::errHandler(
8682 CL_(clEnqueueCopyImageToBuffer)(
8683 object_,
8684 src(),
8685 dst(),
8686 src_origin.data(),
8687 region.data(),
8688 dst_offset,
8689 (events != nullptr) ? (cl_uint) events->size() : 0,
8690 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
8691 (event != nullptr) ? &tmp : nullptr),
8692 __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
8693
8694 if (event != nullptr && err == CL_SUCCESS)
8695 *event = tmp;
8696
8697 return err;
8698 }
8699
8700 cl_int enqueueCopyImageToBuffer(
8701 const Image& src,
8702 const Buffer& dst,
8703 const array<size_type, 2>& src_origin,
8704 const array<size_type, 2>& region,
8705 size_type dst_offset,
8706 const vector<Event>* events = nullptr,
8707 Event* event = nullptr) const
8708 {
8709 return enqueueCopyImageToBuffer(
8710 src,
8711 dst,
8712 { src_origin[0], src_origin[1], 0 },
8713 { region[0], region[1], 1 },
8714 dst_offset,
8715 events,
8716 event);
8717 }
8718
8719 cl_int enqueueCopyBufferToImage(
8720 const Buffer& src,
8721 const Image& dst,
8722 size_type src_offset,
8723 const array<size_type, 3>& dst_origin,
8724 const array<size_type, 3>& region,
8725 const vector<Event>* events = nullptr,
8726 Event* event = nullptr) const
8727 {
8728 cl_event tmp;
8729 cl_int err = detail::errHandler(
8730 CL_(clEnqueueCopyBufferToImage)(
8731 object_,
8732 src(),
8733 dst(),
8734 src_offset,
8735 dst_origin.data(),
8736 region.data(),
8737 (events != nullptr) ? (cl_uint) events->size() : 0,
8738 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
8739 (event != nullptr) ? &tmp : nullptr),
8740 __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
8741
8742 if (event != nullptr && err == CL_SUCCESS)
8743 *event = tmp;
8744
8745 return err;
8746 }
8747
8748 cl_int enqueueCopyBufferToImage(
8749 const Buffer& src,
8750 const Image& dst,
8751 size_type src_offset,
8752 const array<size_type, 2>& dst_origin,
8753 const array<size_type, 2>& region,
8754 const vector<Event>* events = nullptr,
8755 Event* event = nullptr) const
8756 {
8757 return enqueueCopyBufferToImage(
8758 src,
8759 dst,
8760 src_offset,
8761 { dst_origin[0], dst_origin[1], 0 },
8762 { region[0], region[1], 1 },
8763 events,
8764 event);
8765 }
8766
8767 void* enqueueMapBuffer(
8768 const Buffer& buffer,
8769 cl_bool blocking,
8770 cl_map_flags flags,
8771 size_type offset,
8772 size_type size,
8773 const vector<Event>* events = nullptr,
8774 Event* event = nullptr,
8775 cl_int* err = nullptr) const
8776 {
8777 cl_event tmp;
8778 cl_int error;
8779 void * result = CL_(clEnqueueMapBuffer)(
8780 object_, buffer(), blocking, flags, offset, size,
8781 (events != nullptr) ? (cl_uint) events->size() : 0,
8782 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
8783 (event != nullptr) ? &tmp : nullptr,
8784 &error);
8785
8786 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
8787 if (err != nullptr) {
8788 *err = error;
8789 }
8790 if (event != nullptr && error == CL_SUCCESS)
8791 *event = tmp;
8792
8793 return result;
8794 }
8795
8796 void* enqueueMapImage(
8797 const Image& image,
8798 cl_bool blocking,
8799 cl_map_flags flags,
8800 const array<size_type, 3>& origin,
8801 const array<size_type, 3>& region,
8802 size_type * row_pitch,
8803 size_type * slice_pitch,
8804 const vector<Event>* events = nullptr,
8805 Event* event = nullptr,
8806 cl_int* err = nullptr) const
8807 {
8808 cl_event tmp;
8809 cl_int error;
8810 void * result = CL_(clEnqueueMapImage)(
8811 object_, image(), blocking, flags,
8812 origin.data(),
8813 region.data(),
8814 row_pitch, slice_pitch,
8815 (events != nullptr) ? (cl_uint) events->size() : 0,
8816 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
8817 (event != nullptr) ? &tmp : nullptr,
8818 &error);
8819
8820 detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
8821 if (err != nullptr) {
8822 *err = error;
8823 }
8824 if (event != nullptr && error == CL_SUCCESS)
8825 *event = tmp;
8826 return result;
8827 }
8828
8829 void* enqueueMapImage(
8830 const Image& image,
8831 cl_bool blocking,
8832 cl_map_flags flags,
8833 const array<size_type, 2>& origin,
8834 const array<size_type, 2>& region,
8835 size_type* row_pitch,
8836 size_type* slice_pitch,
8837 const vector<Event>* events = nullptr,
8838 Event* event = nullptr,
8839 cl_int* err = nullptr) const
8840 {
8841 return enqueueMapImage(image, blocking, flags,
8842 { origin[0], origin[1], 0 },
8843 { region[0], region[1], 1 }, row_pitch,
8844 slice_pitch, events, event, err);
8845 }
8846
8847#if CL_HPP_TARGET_OPENCL_VERSION >= 200
8848
8850 * Enqueues a command that copies a region of memory from the source pointer to the destination pointer.
8851 * This function is specifically for transferring data between the host and a coarse-grained SVM buffer.
8852 */
8853 template<typename T>
8854 cl_int enqueueMemcpySVM(
8855 T *dst_ptr,
8856 const T *src_ptr,
8857 cl_bool blocking,
8858 size_type size,
8859 const vector<Event> *events = nullptr,
8860 Event *event = nullptr) const {
8861 cl_event tmp;
8862 cl_int err = detail::errHandler(CL_(clEnqueueSVMMemcpy)(
8863 object_, blocking, static_cast<void *>(dst_ptr), static_cast<const void *>(src_ptr), size,
8864 (events != nullptr) ? (cl_uint) events->size() : 0,
8865 (events != nullptr && events->size() > 0) ? (const cl_event *) &events->front() : nullptr,
8866 (event != nullptr) ? &tmp : nullptr), __ENQUEUE_COPY_SVM_ERR);
8867
8868 if (event != nullptr && err == CL_SUCCESS)
8869 *event = tmp;
8870
8871 return err;
8872 }
8873
8875 *Enqueues a command that will copy data from one coarse-grained SVM buffer to another.
8876 *This function takes two cl::pointer instances representing the destination and source buffers.
8877 */
8878 template<typename T, class D>
8879 cl_int enqueueMemcpySVM(
8880 cl::pointer<T, D> &dst_ptr,
8881 const cl::pointer<T, D> &src_ptr,
8882 cl_bool blocking,
8883 size_type size,
8884 const vector<Event> *events = nullptr,
8885 Event *event = nullptr) const {
8886 cl_event tmp;
8887 cl_int err = detail::errHandler(CL_(clEnqueueSVMMemcpy)(
8888 object_, blocking, static_cast<void *>(dst_ptr.get()), static_cast<const void *>(src_ptr.get()),
8889 size,
8890 (events != nullptr) ? (cl_uint) events->size() : 0,
8891 (events != nullptr && events->size() > 0) ? (const cl_event *) &events->front() : nullptr,
8892 (event != nullptr) ? &tmp : nullptr), __ENQUEUE_COPY_SVM_ERR);
8893
8894 if (event != nullptr && err == CL_SUCCESS)
8895 *event = tmp;
8896
8897 return err;
8898 }
8899
8901 * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer.
8902 * This variant takes a cl::vector instance.
8903 */
8904 template<typename T, class Alloc>
8905 cl_int enqueueMemcpySVM(
8906 cl::vector<T, Alloc> &dst_container,
8907 const cl::vector<T, Alloc> &src_container,
8908 cl_bool blocking,
8909 const vector<Event> *events = nullptr,
8910 Event *event = nullptr) const {
8911 cl_event tmp;
8912 if(src_container.size() != dst_container.size()){
8913 return detail::errHandler(CL_INVALID_VALUE,__ENQUEUE_COPY_SVM_ERR);
8914 }
8915 cl_int err = detail::errHandler(CL_(clEnqueueSVMMemcpy)(
8916 object_, blocking,
8917 dst_container.empty() ? nullptr : dst_container.data(),
8918 src_container.empty() ? nullptr : src_container.data(),
8919 dst_container.size() * sizeof(T),
8920 (events != nullptr) ? (cl_uint) events->size() : 0,
8921 (events != nullptr && events->size() > 0) ? (const cl_event *) &events->front() : nullptr,
8922 (event != nullptr) ? &tmp : nullptr), __ENQUEUE_COPY_SVM_ERR);
8923
8924 if (event != nullptr && err == CL_SUCCESS)
8925 *event = tmp;
8926
8927 return err;
8928 }
8929
8931 * Enqueues a command to fill a SVM buffer with a pattern.
8932 *
8933 */
8934 template<typename T, typename PatternType>
8935 cl_int enqueueMemFillSVM(
8936 T *ptr,
8937 PatternType pattern,
8938 size_type size,
8939 const vector<Event> *events = nullptr,
8940 Event *event = nullptr) const {
8941 cl_event tmp;
8942 cl_int err = detail::errHandler(CL_(clEnqueueSVMMemFill)(
8943 object_, static_cast<void *>(ptr), static_cast<void *>(&pattern),
8944 sizeof(PatternType), size,
8945 (events != nullptr) ? (cl_uint) events->size() : 0,
8946 (events != nullptr && events->size() > 0) ? (const cl_event *) &events->front() : nullptr,
8947 (event != nullptr) ? &tmp : nullptr), __ENQUEUE_FILL_SVM_ERR);
8948
8949 if (event != nullptr && err == CL_SUCCESS)
8950 *event = tmp;
8951
8952 return err;
8953 }
8954
8956 * Enqueues a command that fills a region of a coarse-grained SVM buffer with a specified pattern.
8957 * This variant takes a cl::pointer instance.
8958 */
8959 template<typename T, class D, typename PatternType>
8960 cl_int enqueueMemFillSVM(
8961 cl::pointer<T, D> &ptr,
8962 PatternType pattern,
8963 size_type size,
8964 const vector<Event> *events = nullptr,
8965 Event *event = nullptr) const {
8966 cl_event tmp;
8967 cl_int err = detail::errHandler(CL_(clEnqueueSVMMemFill)(
8968 object_, static_cast<void *>(ptr.get()), static_cast<void *>(&pattern),
8969 sizeof(PatternType), size,
8970 (events != nullptr) ? (cl_uint) events->size() : 0,
8971 (events != nullptr && events->size() > 0) ? (const cl_event *) &events->front() : nullptr,
8972 (event != nullptr) ? &tmp : nullptr), __ENQUEUE_FILL_SVM_ERR);
8973
8974 if (event != nullptr && err == CL_SUCCESS)
8975 *event = tmp;
8976
8977 return err;
8978 }
8979
8981 * Enqueues a command that will allow the host to fill a region of a coarse-grained SVM buffer with a specified pattern.
8982 * This variant takes a cl::vector instance.
8983 */
8984 template<typename T, class Alloc, typename PatternType>
8985 cl_int enqueueMemFillSVM(
8986 cl::vector<T, Alloc> &container,
8987 PatternType pattern,
8988 const vector<Event> *events = nullptr,
8989 Event* event = nullptr) const
8990 {
8991 cl_event tmp;
8992 cl_int err = detail::errHandler(CL_(clEnqueueSVMMemFill)(
8993 object_,
8994 container.empty() ? nullptr : container.data(),
8995 &pattern,
8996 sizeof(PatternType),
8997 container.size() * sizeof(T),
8998 (events != nullptr) ? (cl_uint) events->size() : 0,
8999 (events != nullptr && events->size() > 0) ? (const cl_event *) &events->front() : nullptr,
9000 (event != nullptr) ? &tmp : NULL), __ENQUEUE_FILL_SVM_ERR);
9001
9002 if (event != nullptr && err == CL_SUCCESS)
9003 *event = tmp;
9004
9005 return err;
9006 }
9007
9009 * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer.
9010 * This variant takes a raw SVM pointer.
9011 */
9012 template<typename T>
9013 cl_int enqueueMapSVM(
9014 T* ptr,
9015 cl_bool blocking,
9016 cl_map_flags flags,
9017 size_type size,
9018 const vector<Event>* events = nullptr,
9019 Event* event = nullptr) const
9020 {
9021 cl_event tmp;
9022 cl_int err = detail::errHandler(CL_(clEnqueueSVMMap)(
9023 object_, blocking, flags, static_cast<void*>(ptr), size,
9024 (events != nullptr) ? (cl_uint)events->size() : 0,
9025 (events != nullptr && events->size() > 0) ? (const cl_event*)&events->front() : nullptr,
9026 (event != nullptr) ? &tmp : nullptr),
9027 __ENQUEUE_MAP_SVM_ERR);
9028
9029 if (event != nullptr && err == CL_SUCCESS)
9030 *event = tmp;
9031
9032 return err;
9033 }
9034
9035
9037 * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer.
9038 * This variant takes a cl::pointer instance.
9039 */
9040 template<typename T, class D>
9041 cl_int enqueueMapSVM(
9042 cl::pointer<T, D> &ptr,
9043 cl_bool blocking,
9044 cl_map_flags flags,
9045 size_type size,
9046 const vector<Event>* events = nullptr,
9047 Event* event = nullptr) const
9048 {
9049 cl_event tmp;
9050 cl_int err = detail::errHandler(CL_(clEnqueueSVMMap)(
9051 object_, blocking, flags, static_cast<void*>(ptr.get()), size,
9052 (events != nullptr) ? (cl_uint)events->size() : 0,
9053 (events != nullptr && events->size() > 0) ? (const cl_event*)&events->front() : nullptr,
9054 (event != nullptr) ? &tmp : nullptr),
9055 __ENQUEUE_MAP_SVM_ERR);
9056
9057 if (event != nullptr && err == CL_SUCCESS)
9058 *event = tmp;
9059
9060 return err;
9061 }
9062
9064 * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer.
9065 * This variant takes a cl::vector instance.
9066 */
9067 template<typename T, class Alloc>
9068 cl_int enqueueMapSVM(
9069 cl::vector<T, Alloc> &container,
9070 cl_bool blocking,
9071 cl_map_flags flags,
9072 const vector<Event>* events = nullptr,
9073 Event* event = nullptr) const
9074 {
9075 cl_event tmp;
9076 cl_int err = detail::errHandler(CL_(clEnqueueSVMMap)(
9077 object_, blocking, flags,
9078 container.empty() ? nullptr : container.data(),
9079 container.size() * sizeof(T),
9080 (events != nullptr) ? (cl_uint)events->size() : 0,
9081 (events != nullptr && events->size() > 0) ? (const cl_event*)&events->front() : nullptr,
9082 (event != nullptr) ? &tmp : nullptr),
9083 __ENQUEUE_MAP_SVM_ERR);
9084
9085 if (event != nullptr && err == CL_SUCCESS)
9086 *event = tmp;
9087
9088 return err;
9089 }
9090#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9091
9092 cl_int enqueueUnmapMemObject(
9093 const Memory& memory,
9094 void* mapped_ptr,
9095 const vector<Event>* events = nullptr,
9096 Event* event = nullptr) const
9097 {
9098 cl_event tmp;
9099 cl_int err = detail::errHandler(
9100 CL_(clEnqueueUnmapMemObject)(
9101 object_, memory(), mapped_ptr,
9102 (events != nullptr) ? (cl_uint) events->size() : 0,
9103 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
9104 (event != nullptr) ? &tmp : nullptr),
9105 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9106
9107 if (event != nullptr && err == CL_SUCCESS)
9108 *event = tmp;
9109
9110 return err;
9111 }
9112
9113
9114#if CL_HPP_TARGET_OPENCL_VERSION >= 200
9116 * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime.
9117 * This variant takes a raw SVM pointer.
9118 */
9119 template<typename T>
9120 cl_int enqueueUnmapSVM(
9121 T* ptr,
9122 const vector<Event>* events = nullptr,
9123 Event* event = nullptr) const
9124 {
9125 cl_event tmp;
9126 cl_int err = detail::errHandler(
9127 CL_(clEnqueueSVMUnmap)(
9128 object_, static_cast<void*>(ptr),
9129 (events != nullptr) ? (cl_uint)events->size() : 0,
9130 (events != nullptr && events->size() > 0) ? (const cl_event*)&events->front() : nullptr,
9131 (event != nullptr) ? &tmp : nullptr),
9132 __ENQUEUE_UNMAP_SVM_ERR);
9133
9134 if (event != nullptr && err == CL_SUCCESS)
9135 *event = tmp;
9136
9137 return err;
9138 }
9139
9141 * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime.
9142 * This variant takes a cl::pointer instance.
9143 */
9144 template<typename T, class D>
9145 cl_int enqueueUnmapSVM(
9146 cl::pointer<T, D> &ptr,
9147 const vector<Event>* events = nullptr,
9148 Event* event = nullptr) const
9149 {
9150 cl_event tmp;
9151 cl_int err = detail::errHandler(
9152 CL_(clEnqueueSVMUnmap)(
9153 object_, static_cast<void*>(ptr.get()),
9154 (events != nullptr) ? (cl_uint)events->size() : 0,
9155 (events != nullptr && events->size() > 0) ? (const cl_event*)&events->front() : nullptr,
9156 (event != nullptr) ? &tmp : nullptr),
9157 __ENQUEUE_UNMAP_SVM_ERR);
9158
9159 if (event != nullptr && err == CL_SUCCESS)
9160 *event = tmp;
9161
9162 return err;
9163 }
9164
9166 * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime.
9167 * This variant takes a cl::vector instance.
9168 */
9169 template<typename T, class Alloc>
9170 cl_int enqueueUnmapSVM(
9171 cl::vector<T, Alloc> &container,
9172 const vector<Event>* events = nullptr,
9173 Event* event = nullptr) const
9174 {
9175 cl_event tmp;
9176 cl_int err = detail::errHandler(
9177 CL_(clEnqueueSVMUnmap)(
9178 object_,
9179 container.empty() ? nullptr : container.data(),
9180 (events != nullptr) ? (cl_uint)events->size() : 0,
9181 (events != nullptr && events->size() > 0) ? (const cl_event*)&events->front() : nullptr,
9182 (event != nullptr) ? &tmp : nullptr),
9183 __ENQUEUE_UNMAP_SVM_ERR);
9184
9185 if (event != nullptr && err == CL_SUCCESS)
9186 *event = tmp;
9187
9188 return err;
9189 }
9190#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9191
9192#if CL_HPP_TARGET_OPENCL_VERSION >= 120
9200 * i.e. this event can be waited on to insure that all events either in the event_wait_list
9201 * or all previously enqueued commands, queued before this command to command_queue,
9202 * have completed.
9203 */
9205 const vector<Event> *events = nullptr,
9206 Event *event = nullptr) const
9207 {
9208 cl_event tmp;
9209 cl_int err = detail::errHandler(
9210 CL_(clEnqueueMarkerWithWaitList)(
9211 object_,
9212 (events != nullptr) ? (cl_uint) events->size() : 0,
9213 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
9214 (event != nullptr) ? &tmp : nullptr),
9215 __ENQUEUE_MARKER_WAIT_LIST_ERR);
9216
9217 if (event != nullptr && err == CL_SUCCESS)
9218 *event = tmp;
9219
9220 return err;
9221 }
9222
9230 * returns an event which can be waited on, i.e. this event can be waited on to insure that
9231 * all events either in the event_wait_list or all previously enqueued commands, queued
9232 * before this command to command_queue, have completed.
9233 */
9235 const vector<Event> *events = nullptr,
9236 Event *event = nullptr) const
9237 {
9238 cl_event tmp;
9239 cl_int err = detail::errHandler(
9240 CL_(clEnqueueBarrierWithWaitList)(
9241 object_,
9242 (events != nullptr) ? (cl_uint) events->size() : 0,
9243 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
9244 (event != nullptr) ? &tmp : nullptr),
9245 __ENQUEUE_BARRIER_WAIT_LIST_ERR);
9246
9247 if (event != nullptr && err == CL_SUCCESS)
9248 *event = tmp;
9249
9250 return err;
9251 }
9252
9253 /**
9254 * Enqueues a command to indicate with which device a set of memory objects
9255 * should be associated.
9256 */
9258 const vector<Memory> &memObjects,
9259 cl_mem_migration_flags flags,
9260 const vector<Event>* events = nullptr,
9261 Event* event = nullptr
9262 ) const
9263 {
9264 cl_event tmp;
9265
9266 vector<cl_mem> localMemObjects(memObjects.size());
9267
9268 for( int i = 0; i < (int)memObjects.size(); ++i ) {
9269 localMemObjects[i] = memObjects[i]();
9270 }
9271
9272 cl_int err = detail::errHandler(
9273 CL_(clEnqueueMigrateMemObjects)(
9274 object_,
9275 (cl_uint)memObjects.size(),
9276 localMemObjects.empty() ? nullptr : localMemObjects.data(),
9277 flags,
9278 (events != nullptr) ? (cl_uint) events->size() : 0,
9279 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
9280 (event != nullptr) ? &tmp : nullptr),
9281 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9282
9283 if (event != nullptr && err == CL_SUCCESS)
9284 *event = tmp;
9285
9286 return err;
9287 }
9288#endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
9289
9290
9291#if CL_HPP_TARGET_OPENCL_VERSION >= 210
9294 * SVM allocations with a device.
9295 * @param sizes - The length from each pointer to migrate.
9296 */
9297 template<typename T>
9298 cl_int enqueueMigrateSVM(
9299 const cl::vector<T*> &svmRawPointers,
9300 const cl::vector<size_type> &sizes,
9301 cl_mem_migration_flags flags = 0,
9302 const vector<Event>* events = nullptr,
9303 Event* event = nullptr) const
9304 {
9305 cl_event tmp;
9306 cl_int err = detail::errHandler(CL_(clEnqueueSVMMigrateMem)(
9307 object_,
9308 svmRawPointers.size(),
9309 svmRawPointers.empty() ? nullptr : svmRawPointers.data(),
9310 sizes.empty() ? nullptr : sizes.data(),
9311 flags,
9312 (events != nullptr) ? (cl_uint)events->size() : 0,
9313 (events != nullptr && events->size() > 0) ? (const cl_event*)&events->front() : nullptr,
9314 (event != nullptr) ? &tmp : nullptr),
9315 __ENQUEUE_MIGRATE_SVM_ERR);
9316
9317 if (event != nullptr && err == CL_SUCCESS)
9318 *event = tmp;
9319
9320 return err;
9321 }
9322
9324 * Enqueues a command that will allow the host associate a set of SVM allocations with
9325 * a device.
9326 */
9327 template<typename T>
9328 cl_int enqueueMigrateSVM(
9329 const cl::vector<T*> &svmRawPointers,
9330 cl_mem_migration_flags flags = 0,
9331 const vector<Event>* events = nullptr,
9332 Event* event = nullptr) const
9333 {
9334 return enqueueMigrateSVM(svmRawPointers, cl::vector<size_type>(svmRawPointers.size()), flags, events, event);
9335 }
9336
9337
9340 * SVM allocations with a device.
9341 * @param sizes - The length from each pointer to migrate.
9342 */
9343 template<typename T, class D>
9344 cl_int enqueueMigrateSVM(
9345 const cl::vector<cl::pointer<T, D>> &svmPointers,
9346 const cl::vector<size_type> &sizes,
9347 cl_mem_migration_flags flags = 0,
9348 const vector<Event>* events = nullptr,
9349 Event* event = nullptr) const
9350 {
9351 cl::vector<void*> svmRawPointers;
9352 svmRawPointers.reserve(svmPointers.size());
9353 for (auto p : svmPointers) {
9354 svmRawPointers.push_back(static_cast<void*>(p.get()));
9355 }
9356
9357 return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
9358 }
9359
9360
9362 * Enqueues a command that will allow the host associate a set of SVM allocations with
9363 * a device.
9364 */
9365 template<typename T, class D>
9366 cl_int enqueueMigrateSVM(
9367 const cl::vector<cl::pointer<T, D>> &svmPointers,
9368 cl_mem_migration_flags flags = 0,
9369 const vector<Event>* events = nullptr,
9370 Event* event = nullptr) const
9371 {
9372 return enqueueMigrateSVM(svmPointers, cl::vector<size_type>(svmPointers.size()), flags, events, event);
9373 }
9374
9377 * SVM allocations with a device.
9378 * @param sizes - The length from the beginning of each container to migrate.
9379 */
9380 template<typename T, class Alloc>
9381 cl_int enqueueMigrateSVM(
9382 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
9383 const cl::vector<size_type> &sizes,
9384 cl_mem_migration_flags flags = 0,
9385 const vector<Event>* events = nullptr,
9386 Event* event = nullptr) const
9387 {
9388 cl::vector<void*> svmRawPointers;
9389 svmRawPointers.reserve(svmContainers.size());
9390 for (auto p : svmContainers) {
9391 svmRawPointers.push_back(static_cast<void*>(p.data()));
9392 }
9393
9394 return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
9395 }
9396
9398 * Enqueues a command that will allow the host associate a set of SVM allocations with
9399 * a device.
9400 */
9401 template<typename T, class Alloc>
9402 cl_int enqueueMigrateSVM(
9403 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
9404 cl_mem_migration_flags flags = 0,
9405 const vector<Event>* events = nullptr,
9406 Event* event = nullptr) const
9407 {
9408 return enqueueMigrateSVM(svmContainers, cl::vector<size_type>(svmContainers.size()), flags, events, event);
9409 }
9410
9411#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
9412
9413 cl_int enqueueNDRangeKernel(
9414 const Kernel& kernel,
9415 const NDRange& offset,
9416 const NDRange& global,
9417 const NDRange& local = NullRange,
9418 const vector<Event>* events = nullptr,
9419 Event* event = nullptr) const
9420 {
9421 cl_event tmp;
9422 cl_int err = detail::errHandler(
9423 CL_(clEnqueueNDRangeKernel)(
9424 object_, kernel(), (cl_uint) global.dimensions(),
9425 offset.dimensions() != 0 ? (const size_type*) offset : nullptr,
9426 (const size_type*) global,
9427 local.dimensions() != 0 ? (const size_type*) local : nullptr,
9428 (events != nullptr) ? (cl_uint) events->size() : 0,
9429 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
9430 (event != nullptr) ? &tmp : nullptr),
9431 __ENQUEUE_NDRANGE_KERNEL_ERR);
9432
9433 if (event != nullptr && err == CL_SUCCESS)
9434 *event = tmp;
9435
9436 return err;
9437 }
9438
9439#if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
9440 CL_API_PREFIX__VERSION_1_2_DEPRECATED cl_int enqueueTask(
9441 const Kernel& kernel,
9442 const vector<Event>* events = nullptr,
9443 Event* event = nullptr) const CL_API_SUFFIX__VERSION_1_2_DEPRECATED
9444 {
9445 cl_event tmp;
9446 cl_int err = detail::errHandler(
9447 CL_(clEnqueueTask)(
9448 object_, kernel(),
9449 (events != nullptr) ? (cl_uint) events->size() : 0,
9450 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
9451 (event != nullptr) ? &tmp : nullptr),
9452 __ENQUEUE_TASK_ERR);
9453
9454 if (event != nullptr && err == CL_SUCCESS)
9455 *event = tmp;
9456
9457 return err;
9458 }
9459#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
9460
9461 cl_int enqueueNativeKernel(
9462 void (CL_CALLBACK *userFptr)(void *),
9463 std::pair<void*, size_type> args,
9464 const vector<Memory>* mem_objects = nullptr,
9465 const vector<const void*>* mem_locs = nullptr,
9466 const vector<Event>* events = nullptr,
9467 Event* event = nullptr) const
9468 {
9469 cl_event tmp;
9470 cl_int err = detail::errHandler(
9471 CL_(clEnqueueNativeKernel)(
9472 object_, userFptr, args.first, args.second,
9473 (mem_objects != nullptr) ? (cl_uint) mem_objects->size() : 0,
9474 (mem_objects->size() > 0 ) ? reinterpret_cast<const cl_mem *>(mem_objects->data()) : nullptr,
9475 (mem_locs != nullptr && mem_locs->size() > 0) ? const_cast<const void**>(&mem_locs->front()) : nullptr,
9476 (events != nullptr) ? (cl_uint) events->size() : 0,
9477 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
9478 (event != nullptr) ? &tmp : nullptr),
9479 __ENQUEUE_NATIVE_KERNEL);
9480
9481 if (event != nullptr && err == CL_SUCCESS)
9482 *event = tmp;
9483
9484 return err;
9485 }
9486
9488 * Deprecated APIs for 1.2
9489 */
9490#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
9491 CL_API_PREFIX__VERSION_1_1_DEPRECATED
9492 cl_int enqueueMarker(Event* event = nullptr) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
9493 {
9494 cl_event tmp;
9495 cl_int err = detail::errHandler(
9496 CL_(clEnqueueMarker)(
9497 object_,
9498 (event != nullptr) ? &tmp : nullptr),
9499 __ENQUEUE_MARKER_ERR);
9500
9501 if (event != nullptr && err == CL_SUCCESS)
9502 *event = tmp;
9503
9504 return err;
9505 }
9506
9507 CL_API_PREFIX__VERSION_1_1_DEPRECATED
9508 cl_int enqueueWaitForEvents(const vector<Event>& events) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
9509 {
9510 return detail::errHandler(
9511 CL_(clEnqueueWaitForEvents)(
9512 object_,
9513 (cl_uint) events.size(),
9514 events.size() > 0 ? (const cl_event*) &events.front() : nullptr),
9515 __ENQUEUE_WAIT_FOR_EVENTS_ERR);
9516 }
9517#endif // defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
9518
9519 cl_int enqueueAcquireGLObjects(
9520 const vector<Memory>* mem_objects = nullptr,
9521 const vector<Event>* events = nullptr,
9522 Event* event = nullptr) const
9523 {
9524 cl_event tmp;
9525 cl_int err = detail::errHandler(
9526 CL_(clEnqueueAcquireGLObjects)(
9527 object_,
9528 (mem_objects != nullptr) ? (cl_uint) mem_objects->size() : 0,
9529 (mem_objects != nullptr && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): nullptr,
9530 (events != nullptr) ? (cl_uint) events->size() : 0,
9531 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
9532 (event != nullptr) ? &tmp : nullptr),
9533 __ENQUEUE_ACQUIRE_GL_ERR);
9534
9535 if (event != nullptr && err == CL_SUCCESS)
9536 *event = tmp;
9537
9538 return err;
9539 }
9540
9541 cl_int enqueueReleaseGLObjects(
9542 const vector<Memory>* mem_objects = nullptr,
9543 const vector<Event>* events = nullptr,
9544 Event* event = nullptr) const
9545 {
9546 cl_event tmp;
9547 cl_int err = detail::errHandler(
9548 CL_(clEnqueueReleaseGLObjects)(
9549 object_,
9550 (mem_objects != nullptr) ? (cl_uint) mem_objects->size() : 0,
9551 (mem_objects != nullptr && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): nullptr,
9552 (events != nullptr) ? (cl_uint) events->size() : 0,
9553 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
9554 (event != nullptr) ? &tmp : nullptr),
9555 __ENQUEUE_RELEASE_GL_ERR);
9556
9557 if (event != nullptr && err == CL_SUCCESS)
9558 *event = tmp;
9559
9560 return err;
9561 }
9562
9563#if defined (CL_HPP_USE_DX_INTEROP)
9564typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
9565 cl_command_queue command_queue, cl_uint num_objects,
9566 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
9567 const cl_event* event_wait_list, cl_event* event);
9568typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
9569 cl_command_queue command_queue, cl_uint num_objects,
9570 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
9571 const cl_event* event_wait_list, cl_event* event);
9572
9573 cl_int enqueueAcquireD3D10Objects(
9574 const vector<Memory>* mem_objects = nullptr,
9575 const vector<Event>* events = nullptr,
9576 Event* event = nullptr) const
9577 {
9578 static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = nullptr;
9579#if CL_HPP_TARGET_OPENCL_VERSION >= 120
9580 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
9581 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
9582 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
9583 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireD3D10ObjectsKHR);
9584#endif
9585#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
9586 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueAcquireD3D10ObjectsKHR);
9587#endif
9588
9589 cl_event tmp;
9590 cl_int err = detail::errHandler(
9591 pfn_clEnqueueAcquireD3D10ObjectsKHR(
9592 object_,
9593 (mem_objects != nullptr) ? (cl_uint) mem_objects->size() : 0,
9594 (mem_objects != nullptr && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): nullptr,
9595 (events != nullptr) ? (cl_uint) events->size() : 0,
9596 (events != nullptr) ? (const cl_event*) &events->front() : nullptr,
9597 (event != nullptr) ? &tmp : nullptr),
9598 __ENQUEUE_ACQUIRE_GL_ERR);
9599
9600 if (event != nullptr && err == CL_SUCCESS)
9601 *event = tmp;
9602
9603 return err;
9604 }
9605
9606 cl_int enqueueReleaseD3D10Objects(
9607 const vector<Memory>* mem_objects = nullptr,
9608 const vector<Event>* events = nullptr,
9609 Event* event = nullptr) const
9610 {
9611 static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = nullptr;
9612#if CL_HPP_TARGET_OPENCL_VERSION >= 120
9613 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
9614 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
9615 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
9616 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseD3D10ObjectsKHR);
9617#endif
9618#if CL_HPP_MINIMUM_OPENCL_VERSION < 120
9619 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueReleaseD3D10ObjectsKHR);
9620#endif
9621
9622 cl_event tmp;
9623 cl_int err = detail::errHandler(
9624 pfn_clEnqueueReleaseD3D10ObjectsKHR(
9625 object_,
9626 (mem_objects != nullptr) ? (cl_uint) mem_objects->size() : 0,
9627 (mem_objects != nullptr && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): nullptr,
9628 (events != nullptr) ? (cl_uint) events->size() : 0,
9629 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
9630 (event != nullptr) ? &tmp : nullptr),
9631 __ENQUEUE_RELEASE_GL_ERR);
9632
9633 if (event != nullptr && err == CL_SUCCESS)
9634 *event = tmp;
9635
9636 return err;
9637 }
9638#endif
9639
9641 * Deprecated APIs for 1.2
9642 */
9643#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
9644 CL_API_PREFIX__VERSION_1_1_DEPRECATED
9645 cl_int enqueueBarrier() const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
9646 {
9647 return detail::errHandler(
9648 CL_(clEnqueueBarrier)(object_),
9649 __ENQUEUE_BARRIER_ERR);
9650 }
9651#endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
9652
9653 cl_int flush() const
9654 {
9655 return detail::errHandler(CL_(clFlush)(object_), __FLUSH_ERR);
9656 }
9657
9658 cl_int finish() const
9659 {
9660 return detail::errHandler(CL_(clFinish)(object_), __FINISH_ERR);
9661 }
9662
9663#ifdef cl_khr_external_memory
9664 cl_int enqueueAcquireExternalMemObjects(
9665 const vector<Memory>& mem_objects,
9666 const vector<Event>* events_wait = nullptr,
9667 Event *event = nullptr)
9668 {
9669 cl_int err = CL_INVALID_OPERATION;
9670 cl_event tmp;
9671
9672 std::call_once(ext_memory_initialized_, initMemoryExtension, this->getInfo<CL_QUEUE_DEVICE>());
9673
9674 if (pfn_clEnqueueAcquireExternalMemObjectsKHR)
9675 {
9676 err = pfn_clEnqueueAcquireExternalMemObjectsKHR(
9677 object_,
9678 static_cast<cl_uint>(mem_objects.size()),
9679 reinterpret_cast<const cl_mem *>(mem_objects.empty() ? nullptr : mem_objects.data()),
9680 (events_wait != nullptr) ? static_cast<cl_uint>(events_wait->size()) : 0,
9681 (events_wait != nullptr && events_wait->size() > 0) ? reinterpret_cast<const cl_event*>(events_wait->data()) : nullptr,
9682 &tmp);
9683 }
9684
9685 detail::errHandler(err, __ENQUEUE_ACQUIRE_EXTERNAL_MEMORY_ERR);
9686
9687 if (event != nullptr && err == CL_SUCCESS)
9688 *event = tmp;
9689
9690 return err;
9691 }
9692
9693 cl_int enqueueReleaseExternalMemObjects(
9694 const vector<Memory>& mem_objects,
9695 const vector<Event>* events_wait = nullptr,
9696 Event *event = nullptr)
9697 {
9698 cl_int err = CL_INVALID_OPERATION;
9699 cl_event tmp;
9700
9701 std::call_once(ext_memory_initialized_, initMemoryExtension, this->getInfo<CL_QUEUE_DEVICE>());
9702
9703 if (pfn_clEnqueueReleaseExternalMemObjectsKHR)
9704 {
9705 err = pfn_clEnqueueReleaseExternalMemObjectsKHR(
9706 object_,
9707 static_cast<cl_uint>(mem_objects.size()),
9708 reinterpret_cast<const cl_mem *>(mem_objects.empty() ? nullptr : mem_objects.data()),
9709 (events_wait != nullptr) ? static_cast<cl_uint>(events_wait->size()) : 0,
9710 (events_wait != nullptr && events_wait->size() > 0) ? reinterpret_cast<const cl_event*>(events_wait->data()) : nullptr,
9711 &tmp);
9712 }
9713
9714 detail::errHandler(err, __ENQUEUE_RELEASE_EXTERNAL_MEMORY_ERR);
9715
9716 if (event != nullptr && err == CL_SUCCESS)
9717 *event = tmp;
9718
9719 return err;
9720 }
9721#endif // cl_khr_external_memory
9722
9723#ifdef cl_khr_semaphore
9724 cl_int enqueueWaitSemaphores(
9725 const vector<Semaphore> &sema_objects,
9726 const vector<cl_semaphore_payload_khr> &sema_payloads = {},
9727 const vector<Event>* events_wait_list = nullptr,
9728 Event *event = nullptr) const;
9729
9730 cl_int enqueueSignalSemaphores(
9731 const vector<Semaphore> &sema_objects,
9732 const vector<cl_semaphore_payload_khr>& sema_payloads = {},
9733 const vector<Event>* events_wait_list = nullptr,
9734 Event* event = nullptr);
9735#endif // cl_khr_semaphore
9736
9737#if CL_HPP_TARGET_OPENCL_VERSION >= 310
9738 NDRange getKernelSuggestedLocalWorkSize(
9739 const Kernel& kernel,
9740 const NDRange& offset,
9741 const NDRange& global,
9742 cl_int* err = nullptr) const
9743 {
9744 // Initialize the local work-group size to the global work size
9745 // so it has the right dimensionality. The contents will be
9746 // overwritten by the call to clGetKernelSuggestedLocalWorkSize.
9747 NDRange local = global;
9748 cl_int error = detail::errHandler(
9749 CL_(clGetKernelSuggestedLocalWorkSize)(
9750 object_,
9751 kernel(),
9752 (cl_uint) global.dimensions(),
9753 offset.dimensions() != 0 ? offset.get() : nullptr,
9754 global.get(),
9755 local.get()),
9756 __GET_KERNEL_SUGGESTED_LWS_ERR);
9757 if (err != nullptr) {
9758 *err = error;
9759 }
9760 return local;
9761 }
9762#endif // CL_HPP_TARGET_OPENCL_VERSION >= 310
9763}; // CommandQueue
9764
9765#ifdef cl_khr_external_memory
9766CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::ext_memory_initialized_;
9767#endif
9768
9769CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::default_initialized_;
9770CL_HPP_DEFINE_STATIC_MEMBER_ CommandQueue CommandQueue::default_;
9771CL_HPP_DEFINE_STATIC_MEMBER_ cl_int CommandQueue::default_error_ = CL_SUCCESS;
9772
9773
9774#if CL_HPP_TARGET_OPENCL_VERSION >= 200
9775enum class DeviceQueueProperties : cl_command_queue_properties
9776{
9777 None = 0,
9778 Profiling = CL_QUEUE_PROFILING_ENABLE,
9779};
9780
9781inline DeviceQueueProperties operator|(DeviceQueueProperties lhs, DeviceQueueProperties rhs)
9782{
9783 return static_cast<DeviceQueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
9784}
9789class DeviceCommandQueue : public detail::Wrapper<cl_command_queue>
9790{
9791public:
9796 DeviceCommandQueue() { }
9801 DeviceCommandQueue(DeviceQueueProperties properties, cl_int* err = nullptr)
9802 {
9803 cl_int error;
9806
9807 cl_command_queue_properties mergedProperties =
9808 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
9809
9810 cl_queue_properties queue_properties[] = {
9811 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
9812 object_ = CL_(clCreateCommandQueueWithProperties)(
9813 context(), device(), queue_properties, &error);
9814
9815 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9816 if (err != nullptr) {
9817 *err = error;
9818 }
9819 }
9825 const Context& context,
9826 const Device& device,
9827 DeviceQueueProperties properties = DeviceQueueProperties::None,
9828 cl_int* err = nullptr)
9829 {
9830 cl_int error;
9831
9832 cl_command_queue_properties mergedProperties =
9833 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
9834 cl_queue_properties queue_properties[] = {
9835 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
9836 object_ = CL_(clCreateCommandQueueWithProperties)(
9837 context(), device(), queue_properties, &error);
9838
9839 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9840 if (err != nullptr) {
9841 *err = error;
9842 }
9843 }
9849 const Context& context,
9850 const Device& device,
9851 cl_uint queueSize,
9852 DeviceQueueProperties properties = DeviceQueueProperties::None,
9853 cl_int* err = nullptr)
9854 {
9855 cl_int error;
9856
9857 cl_command_queue_properties mergedProperties =
9858 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
9859 cl_queue_properties queue_properties[] = {
9860 CL_QUEUE_PROPERTIES, mergedProperties,
9861 CL_QUEUE_SIZE, queueSize,
9862 0 };
9863 object_ = CL_(clCreateCommandQueueWithProperties)(
9864 context(), device(), queue_properties, &error);
9865
9866 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9867 if (err != nullptr) {
9868 *err = error;
9869 }
9870 }
9871
9874 * \param retainObject will cause the constructor to retain its cl object.
9875 * Defaults to false to maintain compatibility with
9876 * earlier versions.
9877 */
9878 explicit DeviceCommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
9879 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
9880
9881 DeviceCommandQueue& operator = (const cl_command_queue& rhs)
9882 {
9883 detail::Wrapper<cl_type>::operator=(rhs);
9884 return *this;
9885 }
9886
9887 template <typename T>
9888 cl_int getInfo(cl_command_queue_info name, T* param) const
9889 {
9890 return detail::errHandler(
9891 detail::getInfo(
9892 CL_(clGetCommandQueueInfo), object_, name, param),
9893 __GET_COMMAND_QUEUE_INFO_ERR);
9894 }
9895
9896 template <cl_command_queue_info name> typename
9897 detail::param_traits<detail::cl_command_queue_info, name>::param_type
9898 getInfo(cl_int* err = nullptr) const
9899 {
9900 typename detail::param_traits<
9901 detail::cl_command_queue_info, name>::param_type param{};
9902 cl_int result = getInfo(name, &param);
9903 if (err != nullptr) {
9904 *err = result;
9905 }
9906 return param;
9907 }
9908
9911 * in the default context and of the default size.
9912 * If there is already a default queue for the specified device this
9913 * function will return the pre-existing queue.
9914 */
9916 cl_int *err = nullptr)
9917 {
9918 cl_int error;
9921
9922 cl_command_queue_properties properties =
9923 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9924 cl_queue_properties queue_properties[] = {
9925 CL_QUEUE_PROPERTIES, properties,
9926 0 };
9927 DeviceCommandQueue deviceQueue(
9928 CL_(clCreateCommandQueueWithProperties)(
9929 context(), device(), queue_properties, &error));
9930
9931 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9932 if (err != nullptr) {
9933 *err = error;
9934 }
9935
9936 return deviceQueue;
9937 }
9938
9941 * and of the default size.
9942 * If there is already a default queue for the specified device this
9943 * function will return the pre-existing queue.
9944 */
9946 const Context &context, const Device &device, cl_int *err = nullptr)
9947 {
9948 cl_int error;
9949
9950 cl_command_queue_properties properties =
9951 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9952 cl_queue_properties queue_properties[] = {
9953 CL_QUEUE_PROPERTIES, properties,
9954 0 };
9955 DeviceCommandQueue deviceQueue(
9956 CL_(clCreateCommandQueueWithProperties)(
9957 context(), device(), queue_properties, &error));
9958
9959 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9960 if (err != nullptr) {
9961 *err = error;
9962 }
9963
9964 return deviceQueue;
9965 }
9966
9969 * and of the requested size in bytes.
9970 * If there is already a default queue for the specified device this
9971 * function will return the pre-existing queue.
9972 */
9974 const Context &context, const Device &device, cl_uint queueSize, cl_int *err = nullptr)
9975 {
9976 cl_int error;
9977
9978 cl_command_queue_properties properties =
9979 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9980 cl_queue_properties queue_properties[] = {
9981 CL_QUEUE_PROPERTIES, properties,
9982 CL_QUEUE_SIZE, queueSize,
9983 0 };
9984 DeviceCommandQueue deviceQueue(
9985 CL_(clCreateCommandQueueWithProperties)(
9986 context(), device(), queue_properties, &error));
9987
9988 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9989 if (err != nullptr) {
9990 *err = error;
9991 }
9992
9993 return deviceQueue;
9994 }
9995
9996
9997
9998#if CL_HPP_TARGET_OPENCL_VERSION >= 210
10001 * This can update the default command queue for a device repeatedly to account
10002 * for kernels that rely on the default.
10003 * @return updated default device command queue.
10004 */
10005 static DeviceCommandQueue updateDefault(const Context &context, const Device &device, const DeviceCommandQueue &default_queue, cl_int *err = nullptr)
10006 {
10007 cl_int error;
10008 error = CL_(clSetDefaultDeviceCommandQueue)(context.get(), device.get(), default_queue.get());
10009
10010 detail::errHandler(error, __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR);
10011 if (err != nullptr) {
10012 *err = error;
10013 }
10014 return default_queue;
10015 }
10020 static DeviceCommandQueue getDefault(const CommandQueue &queue, cl_int * err = nullptr)
10021 {
10022 return queue.getInfo<CL_QUEUE_DEVICE_DEFAULT>(err);
10023 }
10024
10025#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
10026}; // DeviceCommandQueue
10027
10028namespace detail
10029{
10030 // Specialization for device command queue
10031 template <>
10033 {
10034 static size_type size(const cl::DeviceCommandQueue&) { return sizeof(cl_command_queue); }
10035 static const cl_command_queue* ptr(const cl::DeviceCommandQueue& value) { return &(value()); }
10036 };
10037} // namespace detail
10038
10039#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10040
10041
10042template< typename IteratorType >
10044 const Context &context,
10045 IteratorType startIterator,
10046 IteratorType endIterator,
10047 bool readOnly,
10048 bool useHostPtr,
10049 cl_int* err)
10050{
10051 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
10052 cl_int error;
10053
10054 cl_mem_flags flags = 0;
10055 if( readOnly ) {
10056 flags |= CL_MEM_READ_ONLY;
10057 }
10058 else {
10059 flags |= CL_MEM_READ_WRITE;
10060 }
10061 if( useHostPtr ) {
10062 flags |= CL_MEM_USE_HOST_PTR;
10063 }
10064
10065 size_type size = sizeof(DataType)*(endIterator - startIterator);
10066
10067 if( useHostPtr ) {
10068 object_ = CL_(clCreateBuffer)(context(), flags, size, const_cast<DataType*>(&*startIterator), &error);
10069 } else {
10070 object_ = CL_(clCreateBuffer)(context(), flags, size, 0, &error);
10071 }
10072
10073 detail::errHandler(error, __CREATE_BUFFER_ERR);
10074 if (err != nullptr) {
10075 *err = error;
10076 }
10077
10078 if( !useHostPtr ) {
10079 CommandQueue queue(context, 0, &error);
10080 detail::errHandler(error, __CREATE_BUFFER_ERR);
10081 if (err != nullptr) {
10082 *err = error;
10083 }
10084
10085 error = cl::copy(queue, startIterator, endIterator, *this);
10086 detail::errHandler(error, __CREATE_BUFFER_ERR);
10087 if (err != nullptr) {
10088 *err = error;
10089 }
10091}
10092
10093template< typename IteratorType >
10095 const CommandQueue &queue,
10096 IteratorType startIterator,
10097 IteratorType endIterator,
10098 bool readOnly,
10099 bool useHostPtr,
10100 cl_int* err)
10101{
10102 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
10103 cl_int error;
10104
10105 cl_mem_flags flags = 0;
10106 if (readOnly) {
10107 flags |= CL_MEM_READ_ONLY;
10108 }
10109 else {
10110 flags |= CL_MEM_READ_WRITE;
10111 }
10112 if (useHostPtr) {
10113 flags |= CL_MEM_USE_HOST_PTR;
10114 }
10115
10116 size_type size = sizeof(DataType)*(endIterator - startIterator);
10117
10118 Context context = queue.getInfo<CL_QUEUE_CONTEXT>();
10119
10120 if (useHostPtr) {
10121 object_ = CL_(clCreateBuffer)(context(), flags, size, const_cast<DataType*>(&*startIterator), &error);
10122 }
10123 else {
10124 object_ = CL_(clCreateBuffer)(context(), flags, size, 0, &error);
10125 }
10126
10127 detail::errHandler(error, __CREATE_BUFFER_ERR);
10128 if (err != nullptr) {
10129 *err = error;
10130 }
10131
10132 if (!useHostPtr) {
10133 error = cl::copy(queue, startIterator, endIterator, *this);
10134 detail::errHandler(error, __CREATE_BUFFER_ERR);
10135 if (err != nullptr) {
10136 *err = error;
10137 }
10138 }
10139}
10140
10141inline cl_int enqueueReadBuffer(
10142 const Buffer& buffer,
10143 cl_bool blocking,
10144 size_type offset,
10145 size_type size,
10146 void* ptr,
10147 const vector<Event>* events = nullptr,
10148 Event* event = nullptr)
10149{
10150 cl_int error;
10151 CommandQueue queue = CommandQueue::getDefault(&error);
10152
10153 if (error != CL_SUCCESS) {
10154 return error;
10155 }
10156
10157 return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event);
10158}
10159
10160inline cl_int enqueueWriteBuffer(
10161 const Buffer& buffer,
10162 cl_bool blocking,
10163 size_type offset,
10164 size_type size,
10165 const void* ptr,
10166 const vector<Event>* events = nullptr,
10167 Event* event = nullptr)
10168{
10169 cl_int error;
10170 CommandQueue queue = CommandQueue::getDefault(&error);
10171
10172 if (error != CL_SUCCESS) {
10173 return error;
10174 }
10175
10176 return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event);
10177}
10178
10179inline void* enqueueMapBuffer(
10180 const Buffer& buffer,
10181 cl_bool blocking,
10182 cl_map_flags flags,
10183 size_type offset,
10184 size_type size,
10185 const vector<Event>* events = nullptr,
10186 Event* event = nullptr,
10187 cl_int* err = nullptr)
10188{
10189 cl_int error;
10190 CommandQueue queue = CommandQueue::getDefault(&error);
10191 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
10192 if (err != nullptr) {
10193 *err = error;
10194 }
10195
10196 void * result = CL_(clEnqueueMapBuffer)(
10197 queue(), buffer(), blocking, flags, offset, size,
10198 (events != nullptr) ? (cl_uint) events->size() : 0,
10199 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
10200 (cl_event*) event,
10201 &error);
10202
10203 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
10204 if (err != nullptr) {
10205 *err = error;
10206 }
10207 return result;
10208}
10209
10210
10211#if CL_HPP_TARGET_OPENCL_VERSION >= 200
10214 * update a region of a coarse-grained SVM buffer.
10215 * This variant takes a raw SVM pointer.
10216 */
10217template<typename T>
10218inline cl_int enqueueMapSVM(
10219 T* ptr,
10220 cl_bool blocking,
10221 cl_map_flags flags,
10222 size_type size,
10223 const vector<Event>* events,
10224 Event* event)
10225{
10226 cl_int error;
10227 CommandQueue queue = CommandQueue::getDefault(&error);
10228 if (error != CL_SUCCESS) {
10229 return detail::errHandler(error, __ENQUEUE_MAP_SVM_ERR);
10230 }
10231
10232 return queue.enqueueMapSVM(
10233 ptr, blocking, flags, size, events, event);
10234}
10235
10238 * update a region of a coarse-grained SVM buffer.
10239 * This variant takes a cl::pointer instance.
10240 */
10241template<typename T, class D>
10242inline cl_int enqueueMapSVM(
10243 cl::pointer<T, D> &ptr,
10244 cl_bool blocking,
10245 cl_map_flags flags,
10246 size_type size,
10247 const vector<Event>* events = nullptr,
10248 Event* event = nullptr)
10249{
10250 cl_int error;
10251 CommandQueue queue = CommandQueue::getDefault(&error);
10252 if (error != CL_SUCCESS) {
10253 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
10254 }
10255
10256 return queue.enqueueMapSVM(
10257 ptr, blocking, flags, size, events, event);
10258}
10259
10262 * update a region of a coarse-grained SVM buffer.
10263 * This variant takes a cl::vector instance.
10264 */
10265template<typename T, class Alloc>
10266inline cl_int enqueueMapSVM(
10267 cl::vector<T, Alloc> &container,
10268 cl_bool blocking,
10269 cl_map_flags flags,
10270 const vector<Event>* events = nullptr,
10271 Event* event = nullptr)
10272{
10273 cl_int error;
10274 CommandQueue queue = CommandQueue::getDefault(&error);
10275 if (error != CL_SUCCESS) {
10276 return detail::errHandler(error, __ENQUEUE_MAP_SVM_ERR);
10277 }
10278
10279 return queue.enqueueMapSVM(
10280 container, blocking, flags, events, event);
10281}
10282
10283#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10284
10285inline cl_int enqueueUnmapMemObject(
10286 const Memory& memory,
10287 void* mapped_ptr,
10288 const vector<Event>* events = nullptr,
10289 Event* event = nullptr)
10290{
10291 cl_int error;
10292 CommandQueue queue = CommandQueue::getDefault(&error);
10293 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
10294 if (error != CL_SUCCESS) {
10295 return error;
10296 }
10297
10298 cl_event tmp;
10299 cl_int err = detail::errHandler(
10300 CL_(clEnqueueUnmapMemObject)(
10301 queue(), memory(), mapped_ptr,
10302 (events != nullptr) ? (cl_uint)events->size() : 0,
10303 (events != nullptr && events->size() > 0) ? (const cl_event*)&events->front() : nullptr,
10304 (event != nullptr) ? &tmp : nullptr),
10305 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
10306
10307 if (event != nullptr && err == CL_SUCCESS)
10308 *event = tmp;
10309
10310 return err;
10311}
10312
10313#if CL_HPP_TARGET_OPENCL_VERSION >= 200
10316 * SVM buffer back to the OpenCL runtime.
10317 * This variant takes a raw SVM pointer.
10318 */
10319template<typename T>
10320inline cl_int enqueueUnmapSVM(
10321 T* ptr,
10322 const vector<Event>* events = nullptr,
10323 Event* event = nullptr)
10324{
10325 cl_int error;
10326 CommandQueue queue = CommandQueue::getDefault(&error);
10327 if (error != CL_SUCCESS) {
10328 return detail::errHandler(error, __ENQUEUE_UNMAP_SVM_ERR);
10329 }
10330
10331 return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
10332 __ENQUEUE_UNMAP_SVM_ERR);
10333
10334}
10335
10338 * SVM buffer back to the OpenCL runtime.
10339 * This variant takes a cl::pointer instance.
10340 */
10341template<typename T, class D>
10342inline cl_int enqueueUnmapSVM(
10343 cl::pointer<T, D> &ptr,
10344 const vector<Event>* events = nullptr,
10345 Event* event = nullptr)
10346{
10347 cl_int error;
10348 CommandQueue queue = CommandQueue::getDefault(&error);
10349 if (error != CL_SUCCESS) {
10350 return detail::errHandler(error, __ENQUEUE_UNMAP_SVM_ERR);
10351 }
10352
10353 return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
10354 __ENQUEUE_UNMAP_SVM_ERR);
10355}
10356
10359 * SVM buffer back to the OpenCL runtime.
10360 * This variant takes a cl::vector instance.
10361 */
10362template<typename T, class Alloc>
10363inline cl_int enqueueUnmapSVM(
10364 cl::vector<T, Alloc> &container,
10365 const vector<Event>* events = nullptr,
10366 Event* event = nullptr)
10367{
10368 cl_int error;
10369 CommandQueue queue = CommandQueue::getDefault(&error);
10370 if (error != CL_SUCCESS) {
10371 return detail::errHandler(error, __ENQUEUE_UNMAP_SVM_ERR);
10372 }
10373
10374 return detail::errHandler(queue.enqueueUnmapSVM(container, events, event),
10375 __ENQUEUE_UNMAP_SVM_ERR);
10376}
10377
10378#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10379
10380inline cl_int enqueueCopyBuffer(
10381 const Buffer& src,
10382 const Buffer& dst,
10383 size_type src_offset,
10384 size_type dst_offset,
10385 size_type size,
10386 const vector<Event>* events = nullptr,
10387 Event* event = nullptr)
10388{
10389 cl_int error;
10390 CommandQueue queue = CommandQueue::getDefault(&error);
10391
10392 if (error != CL_SUCCESS) {
10393 return error;
10394 }
10395
10396 return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event);
10397}
10398
10401 * Host to Device.
10402 * Uses default command queue.
10403 */
10404template< typename IteratorType >
10405inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
10406{
10407 cl_int error;
10408 CommandQueue queue = CommandQueue::getDefault(&error);
10409 if (error != CL_SUCCESS)
10410 return error;
10411
10412 return cl::copy(queue, startIterator, endIterator, buffer);
10413}
10414
10417 * Device to Host.
10418 * Uses default command queue.
10419 */
10420template< typename IteratorType >
10421inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
10422{
10423 cl_int error;
10424 CommandQueue queue = CommandQueue::getDefault(&error);
10425 if (error != CL_SUCCESS)
10426 return error;
10427
10428 return cl::copy(queue, buffer, startIterator, endIterator);
10429}
10430
10433 * Host to Device.
10434 * Uses specified queue.
10435 */
10436template< typename IteratorType >
10437inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
10438{
10439 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
10440 cl_int error;
10441
10442 size_type length = endIterator-startIterator;
10443 size_type byteLength = length*sizeof(DataType);
10444
10445 DataType *pointer =
10446 static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error));
10447 // if exceptions enabled, enqueueMapBuffer will throw
10448 if( error != CL_SUCCESS ) {
10449 return error;
10450 }
10451#if defined(_MSC_VER) && _MSC_VER < 1920
10452 std::copy(
10453 startIterator,
10454 endIterator,
10455 stdext::checked_array_iterator<DataType*>(
10456 pointer, length));
10457#else
10458 std::copy(startIterator, endIterator, pointer);
10459#endif // defined(_MSC_VER) && _MSC_VER < 1920
10460 Event endEvent;
10461 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
10462 // if exceptions enabled, enqueueUnmapMemObject will throw
10463 if( error != CL_SUCCESS ) {
10464 return error;
10465 }
10466 endEvent.wait();
10467 return CL_SUCCESS;
10468}
10469
10472 * Device to Host.
10473 * Uses specified queue.
10474 */
10475template< typename IteratorType >
10476inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
10477{
10478 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
10479 cl_int error;
10480
10481 size_type length = endIterator-startIterator;
10482 size_type byteLength = length*sizeof(DataType);
10483
10484 DataType *pointer =
10485 static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error));
10486 // if exceptions enabled, enqueueMapBuffer will throw
10487 if( error != CL_SUCCESS ) {
10488 return error;
10489 }
10490 std::copy(pointer, pointer + length, startIterator);
10491 Event endEvent;
10492 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
10493 // if exceptions enabled, enqueueUnmapMemObject will throw
10494 if( error != CL_SUCCESS ) {
10495 return error;
10496 }
10497 endEvent.wait();
10498 return CL_SUCCESS;
10499}
10500
10501
10502#if CL_HPP_TARGET_OPENCL_VERSION >= 200
10504 * Blocking SVM map operation - performs a blocking map underneath.
10505 */
10506template<typename T, class Alloc>
10507inline cl_int mapSVM(cl::vector<T, Alloc> &container)
10508{
10509 return enqueueMapSVM(container, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE);
10510}
10511
10513* Blocking SVM map operation - performs a blocking map underneath.
10514*/
10515template<typename T, class Alloc>
10516inline cl_int unmapSVM(cl::vector<T, Alloc> &container)
10517{
10518 return enqueueUnmapSVM(container);
10519}
10520
10521#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10522
10523#if CL_HPP_TARGET_OPENCL_VERSION >= 110
10524inline cl_int enqueueReadBufferRect(
10525 const Buffer& buffer,
10526 cl_bool blocking,
10527 const array<size_type, 3>& buffer_offset,
10528 const array<size_type, 3>& host_offset,
10529 const array<size_type, 3>& region,
10530 size_type buffer_row_pitch,
10531 size_type buffer_slice_pitch,
10532 size_type host_row_pitch,
10533 size_type host_slice_pitch,
10534 void *ptr,
10535 const vector<Event>* events = nullptr,
10536 Event* event = nullptr)
10537{
10538 cl_int error;
10539 CommandQueue queue = CommandQueue::getDefault(&error);
10540
10541 if (error != CL_SUCCESS) {
10542 return error;
10543 }
10544
10545 return queue.enqueueReadBufferRect(
10546 buffer,
10547 blocking,
10548 buffer_offset,
10549 host_offset,
10550 region,
10551 buffer_row_pitch,
10552 buffer_slice_pitch,
10553 host_row_pitch,
10554 host_slice_pitch,
10555 ptr,
10556 events,
10557 event);
10558}
10559
10560inline cl_int enqueueReadBufferRect(
10561 const Buffer& buffer,
10562 cl_bool blocking,
10563 const array<size_type, 2>& buffer_offset,
10564 const array<size_type, 2>& host_offset,
10565 const array<size_type, 2>& region,
10566 size_type buffer_row_pitch,
10567 size_type buffer_slice_pitch,
10568 size_type host_row_pitch,
10569 size_type host_slice_pitch,
10570 void* ptr,
10571 const vector<Event>* events = nullptr,
10572 Event* event = nullptr)
10573{
10574 return enqueueReadBufferRect(
10575 buffer,
10576 blocking,
10577 { buffer_offset[0], buffer_offset[1], 0 },
10578 { host_offset[0], host_offset[1], 0 },
10579 { region[0], region[1], 1 },
10580 buffer_row_pitch,
10581 buffer_slice_pitch,
10582 host_row_pitch,
10583 host_slice_pitch,
10584 ptr,
10585 events,
10586 event);
10587}
10588
10589inline cl_int enqueueWriteBufferRect(
10590 const Buffer& buffer,
10591 cl_bool blocking,
10592 const array<size_type, 3>& buffer_offset,
10593 const array<size_type, 3>& host_offset,
10594 const array<size_type, 3>& region,
10595 size_type buffer_row_pitch,
10596 size_type buffer_slice_pitch,
10597 size_type host_row_pitch,
10598 size_type host_slice_pitch,
10599 const void *ptr,
10600 const vector<Event>* events = nullptr,
10601 Event* event = nullptr)
10602{
10603 cl_int error;
10604 CommandQueue queue = CommandQueue::getDefault(&error);
10605
10606 if (error != CL_SUCCESS) {
10607 return error;
10608 }
10609
10610 return queue.enqueueWriteBufferRect(
10611 buffer,
10612 blocking,
10613 buffer_offset,
10614 host_offset,
10615 region,
10616 buffer_row_pitch,
10617 buffer_slice_pitch,
10618 host_row_pitch,
10619 host_slice_pitch,
10620 ptr,
10621 events,
10622 event);
10623}
10624
10625inline cl_int enqueueWriteBufferRect(
10626 const Buffer& buffer,
10627 cl_bool blocking,
10628 const array<size_type, 2>& buffer_offset,
10629 const array<size_type, 2>& host_offset,
10630 const array<size_type, 2>& region,
10631 size_type buffer_row_pitch,
10632 size_type buffer_slice_pitch,
10633 size_type host_row_pitch,
10634 size_type host_slice_pitch,
10635 const void* ptr,
10636 const vector<Event>* events = nullptr,
10637 Event* event = nullptr)
10638{
10639 return enqueueWriteBufferRect(
10640 buffer,
10641 blocking,
10642 { buffer_offset[0], buffer_offset[1], 0 },
10643 { host_offset[0], host_offset[1], 0 },
10644 { region[0], region[1], 1 },
10645 buffer_row_pitch,
10646 buffer_slice_pitch,
10647 host_row_pitch,
10648 host_slice_pitch,
10649 ptr,
10650 events,
10651 event);
10652}
10653
10654inline cl_int enqueueCopyBufferRect(
10655 const Buffer& src,
10656 const Buffer& dst,
10657 const array<size_type, 3>& src_origin,
10658 const array<size_type, 3>& dst_origin,
10659 const array<size_type, 3>& region,
10660 size_type src_row_pitch,
10661 size_type src_slice_pitch,
10662 size_type dst_row_pitch,
10663 size_type dst_slice_pitch,
10664 const vector<Event>* events = nullptr,
10665 Event* event = nullptr)
10666{
10667 cl_int error;
10668 CommandQueue queue = CommandQueue::getDefault(&error);
10669
10670 if (error != CL_SUCCESS) {
10671 return error;
10672 }
10673
10674 return queue.enqueueCopyBufferRect(
10675 src,
10676 dst,
10677 src_origin,
10678 dst_origin,
10679 region,
10680 src_row_pitch,
10681 src_slice_pitch,
10682 dst_row_pitch,
10683 dst_slice_pitch,
10684 events,
10685 event);
10686}
10687
10688inline cl_int enqueueCopyBufferRect(
10689 const Buffer& src,
10690 const Buffer& dst,
10691 const array<size_type, 2>& src_origin,
10692 const array<size_type, 2>& dst_origin,
10693 const array<size_type, 2>& region,
10694 size_type src_row_pitch,
10695 size_type src_slice_pitch,
10696 size_type dst_row_pitch,
10697 size_type dst_slice_pitch,
10698 const vector<Event>* events = nullptr,
10699 Event* event = nullptr)
10700{
10701 return enqueueCopyBufferRect(
10702 src,
10703 dst,
10704 { src_origin[0], src_origin[1], 0 },
10705 { dst_origin[0], dst_origin[1], 0 },
10706 { region[0], region[1], 1 },
10707 src_row_pitch,
10708 src_slice_pitch,
10709 dst_row_pitch,
10710 dst_slice_pitch,
10711 events,
10712 event);
10713}
10714#endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
10715
10716inline cl_int enqueueReadImage(
10717 const Image& image,
10718 cl_bool blocking,
10719 const array<size_type, 3>& origin,
10720 const array<size_type, 3>& region,
10721 size_type row_pitch,
10722 size_type slice_pitch,
10723 void* ptr,
10724 const vector<Event>* events = nullptr,
10725 Event* event = nullptr)
10726{
10727 cl_int error;
10728 CommandQueue queue = CommandQueue::getDefault(&error);
10729
10730 if (error != CL_SUCCESS) {
10731 return error;
10732 }
10733
10734 return queue.enqueueReadImage(
10735 image,
10736 blocking,
10737 origin,
10738 region,
10739 row_pitch,
10740 slice_pitch,
10741 ptr,
10742 events,
10743 event);
10744}
10745
10746inline cl_int enqueueReadImage(
10747 const Image& image,
10748 cl_bool blocking,
10749 const array<size_type, 2>& origin,
10750 const array<size_type, 2>& region,
10751 size_type row_pitch,
10752 size_type slice_pitch,
10753 void* ptr,
10754 const vector<Event>* events = nullptr,
10755 Event* event = nullptr)
10756{
10757 return enqueueReadImage(
10758 image,
10759 blocking,
10760 { origin[0], origin[1], 0 },
10761 { region[0], region[1], 1 },
10762 row_pitch,
10763 slice_pitch,
10764 ptr,
10765 events,
10766 event);
10767}
10768
10769inline cl_int enqueueWriteImage(
10770 const Image& image,
10771 cl_bool blocking,
10772 const array<size_type, 3>& origin,
10773 const array<size_type, 3>& region,
10774 size_type row_pitch,
10775 size_type slice_pitch,
10776 const void* ptr,
10777 const vector<Event>* events = nullptr,
10778 Event* event = nullptr)
10779{
10780 cl_int error;
10781 CommandQueue queue = CommandQueue::getDefault(&error);
10782
10783 if (error != CL_SUCCESS) {
10784 return error;
10785 }
10786
10787 return queue.enqueueWriteImage(
10788 image,
10789 blocking,
10790 origin,
10791 region,
10792 row_pitch,
10793 slice_pitch,
10794 ptr,
10795 events,
10796 event);
10797}
10798
10799inline cl_int enqueueWriteImage(
10800 const Image& image,
10801 cl_bool blocking,
10802 const array<size_type, 2>& origin,
10803 const array<size_type, 2>& region,
10804 size_type row_pitch,
10805 size_type slice_pitch,
10806 const void* ptr,
10807 const vector<Event>* events = nullptr,
10808 Event* event = nullptr)
10809{
10810 return enqueueWriteImage(
10811 image,
10812 blocking,
10813 { origin[0], origin[1], 0 },
10814 { region[0], region[1], 1 },
10815 row_pitch,
10816 slice_pitch,
10817 ptr,
10818 events,
10819 event);
10820}
10821
10822inline cl_int enqueueCopyImage(
10823 const Image& src,
10824 const Image& dst,
10825 const array<size_type, 3>& src_origin,
10826 const array<size_type, 3>& dst_origin,
10827 const array<size_type, 3>& region,
10828 const vector<Event>* events = nullptr,
10829 Event* event = nullptr)
10830{
10831 cl_int error;
10832 CommandQueue queue = CommandQueue::getDefault(&error);
10833
10834 if (error != CL_SUCCESS) {
10835 return error;
10836 }
10837
10838 return queue.enqueueCopyImage(
10839 src,
10840 dst,
10841 src_origin,
10842 dst_origin,
10843 region,
10844 events,
10845 event);
10846}
10847
10848inline cl_int enqueueCopyImage(
10849 const Image& src,
10850 const Image& dst,
10851 const array<size_type, 2>& src_origin,
10852 const array<size_type, 2>& dst_origin,
10853 const array<size_type, 2>& region,
10854 const vector<Event>* events = nullptr,
10855 Event* event = nullptr)
10856{
10857 return enqueueCopyImage(
10858 src,
10859 dst,
10860 { src_origin[0], src_origin[1], 0 },
10861 { dst_origin[0], dst_origin[1], 0 },
10862 { region[0], region[1], 1 },
10863 events,
10864 event);
10865}
10866
10867inline cl_int enqueueCopyImageToBuffer(
10868 const Image& src,
10869 const Buffer& dst,
10870 const array<size_type, 3>& src_origin,
10871 const array<size_type, 3>& region,
10872 size_type dst_offset,
10873 const vector<Event>* events = nullptr,
10874 Event* event = nullptr)
10875{
10876 cl_int error;
10877 CommandQueue queue = CommandQueue::getDefault(&error);
10878
10879 if (error != CL_SUCCESS) {
10880 return error;
10881 }
10882
10883 return queue.enqueueCopyImageToBuffer(
10884 src,
10885 dst,
10886 src_origin,
10887 region,
10888 dst_offset,
10889 events,
10890 event);
10891}
10892
10893inline cl_int enqueueCopyImageToBuffer(
10894 const Image& src,
10895 const Buffer& dst,
10896 const array<size_type, 2>& src_origin,
10897 const array<size_type, 2>& region,
10898 size_type dst_offset,
10899 const vector<Event>* events = nullptr,
10900 Event* event = nullptr)
10901{
10902 return enqueueCopyImageToBuffer(
10903 src,
10904 dst,
10905 { src_origin[0], src_origin[1], 0 },
10906 { region[0], region[1], 1 },
10907 dst_offset,
10908 events,
10909 event);
10910}
10911
10912inline cl_int enqueueCopyBufferToImage(
10913 const Buffer& src,
10914 const Image& dst,
10915 size_type src_offset,
10916 const array<size_type, 3>& dst_origin,
10917 const array<size_type, 3>& region,
10918 const vector<Event>* events = nullptr,
10919 Event* event = nullptr)
10920{
10921 cl_int error;
10922 CommandQueue queue = CommandQueue::getDefault(&error);
10923
10924 if (error != CL_SUCCESS) {
10925 return error;
10926 }
10927
10928 return queue.enqueueCopyBufferToImage(
10929 src,
10930 dst,
10931 src_offset,
10932 dst_origin,
10933 region,
10934 events,
10935 event);
10936}
10937
10938inline cl_int enqueueCopyBufferToImage(
10939 const Buffer& src,
10940 const Image& dst,
10941 size_type src_offset,
10942 const array<size_type, 2>& dst_origin,
10943 const array<size_type, 2>& region,
10944 const vector<Event>* events = nullptr,
10945 Event* event = nullptr)
10946{
10947 cl_int error;
10948 CommandQueue queue = CommandQueue::getDefault(&error);
10949
10950 if (error != CL_SUCCESS) {
10951 return error;
10952 }
10953
10954 return enqueueCopyBufferToImage(
10955 src,
10956 dst,
10957 src_offset,
10958 { dst_origin[0], dst_origin[1], 0 },
10959 { region[0], region[1], 1 },
10960 events,
10961 event);
10962}
10963
10964inline cl_int flush(void)
10965{
10966 cl_int error;
10967 CommandQueue queue = CommandQueue::getDefault(&error);
10968
10969 if (error != CL_SUCCESS) {
10970 return error;
10971 }
10972
10973 return queue.flush();
10974}
10975
10976inline cl_int finish(void)
10977{
10978 cl_int error;
10979 CommandQueue queue = CommandQueue::getDefault(&error);
10980
10981 if (error != CL_SUCCESS) {
10982 return error;
10983 }
10984
10986 return queue.finish();
10987}
10988
10989class EnqueueArgs
10990{
10991private:
10992 CommandQueue queue_;
10993 const NDRange offset_;
10994 const NDRange global_;
10995 const NDRange local_;
10996 vector<Event> events_;
10997
10998 template<typename... Ts>
10999 friend class KernelFunctor;
11000
11001public:
11002 EnqueueArgs(NDRange global) :
11003 queue_(CommandQueue::getDefault()),
11004 offset_(NullRange),
11005 global_(global),
11006 local_(NullRange)
11007 {
11008
11009 }
11010
11011 EnqueueArgs(NDRange global, NDRange local) :
11012 queue_(CommandQueue::getDefault()),
11013 offset_(NullRange),
11014 global_(global),
11015 local_(local)
11016 {
11017
11018 }
11019
11020 EnqueueArgs(NDRange offset, NDRange global, NDRange local) :
11021 queue_(CommandQueue::getDefault()),
11022 offset_(offset),
11023 global_(global),
11024 local_(local)
11025 {
11026
11027 }
11028
11029 EnqueueArgs(Event e, NDRange global) :
11030 queue_(CommandQueue::getDefault()),
11031 offset_(NullRange),
11032 global_(global),
11033 local_(NullRange)
11034 {
11035 events_.push_back(e);
11036 }
11037
11038 EnqueueArgs(Event e, NDRange global, NDRange local) :
11039 queue_(CommandQueue::getDefault()),
11040 offset_(NullRange),
11041 global_(global),
11042 local_(local)
11043 {
11044 events_.push_back(e);
11045 }
11046
11047 EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) :
11048 queue_(CommandQueue::getDefault()),
11049 offset_(offset),
11050 global_(global),
11051 local_(local)
11052 {
11053 events_.push_back(e);
11054 }
11055
11056 EnqueueArgs(const vector<Event> &events, NDRange global) :
11057 queue_(CommandQueue::getDefault()),
11058 offset_(NullRange),
11059 global_(global),
11060 local_(NullRange),
11061 events_(events)
11062 {
11063
11064 }
11065
11066 EnqueueArgs(const vector<Event> &events, NDRange global, NDRange local) :
11067 queue_(CommandQueue::getDefault()),
11068 offset_(NullRange),
11069 global_(global),
11070 local_(local),
11071 events_(events)
11072 {
11073
11074 }
11075
11076 EnqueueArgs(const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
11077 queue_(CommandQueue::getDefault()),
11078 offset_(offset),
11079 global_(global),
11080 local_(local),
11081 events_(events)
11082 {
11083
11084 }
11085
11086 EnqueueArgs(CommandQueue &queue, NDRange global) :
11087 queue_(queue),
11088 offset_(NullRange),
11089 global_(global),
11090 local_(NullRange)
11091 {
11092
11093 }
11094
11095 EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) :
11096 queue_(queue),
11097 offset_(NullRange),
11098 global_(global),
11099 local_(local)
11100 {
11101
11102 }
11103
11104 EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) :
11105 queue_(queue),
11106 offset_(offset),
11107 global_(global),
11108 local_(local)
11109 {
11110
11111 }
11112
11113 EnqueueArgs(CommandQueue &queue, Event e, NDRange global) :
11114 queue_(queue),
11115 offset_(NullRange),
11116 global_(global),
11117 local_(NullRange)
11118 {
11119 events_.push_back(e);
11120 }
11121
11122 EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) :
11123 queue_(queue),
11124 offset_(NullRange),
11125 global_(global),
11126 local_(local)
11127 {
11128 events_.push_back(e);
11129 }
11130
11131 EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) :
11132 queue_(queue),
11133 offset_(offset),
11134 global_(global),
11135 local_(local)
11136 {
11137 events_.push_back(e);
11138 }
11139
11140 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global) :
11141 queue_(queue),
11142 offset_(NullRange),
11143 global_(global),
11144 local_(NullRange),
11145 events_(events)
11146 {
11147
11148 }
11149
11150 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global, NDRange local) :
11151 queue_(queue),
11152 offset_(NullRange),
11153 global_(global),
11154 local_(local),
11155 events_(events)
11156 {
11157
11158 }
11159
11160 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
11161 queue_(queue),
11162 offset_(offset),
11163 global_(global),
11164 local_(local),
11165 events_(events)
11166 {
11167
11168 }
11169};
11170
11171
11172//----------------------------------------------------------------------------------------------
11173
11174
11176 * Type safe kernel functor.
11177 *
11178 */
11179template<typename... Ts>
11180class KernelFunctor
11181{
11182private:
11183 Kernel kernel_;
11184
11185 template<int index, typename T0, typename... T1s>
11186 void setArgs(T0&& t0, T1s&&... t1s)
11187 {
11188 kernel_.setArg(index, t0);
11189 setArgs<index + 1, T1s...>(std::forward<T1s>(t1s)...);
11190 }
11191
11192 template<int index, typename T0>
11193 void setArgs(T0&& t0)
11194 {
11195 kernel_.setArg(index, t0);
11196 }
11197
11198 template<int index>
11199 void setArgs()
11200 {
11201 }
11202
11203
11204public:
11205 KernelFunctor(Kernel kernel) : kernel_(kernel)
11206 {}
11207
11208 KernelFunctor(
11209 const Program& program,
11210 const string name,
11211 cl_int * err = nullptr) :
11212 kernel_(program, name.c_str(), err)
11213 {}
11214
11216 typedef Event result_type;
11217
11219 * Enqueue kernel.
11220 * @param args Launch parameters of the kernel.
11221 * @param t0... List of kernel arguments based on the template type of the functor.
11222 */
11224 const EnqueueArgs& args,
11225 Ts... ts)
11226 {
11227 Event event;
11228 setArgs<0>(std::forward<Ts>(ts)...);
11229
11230 args.queue_.enqueueNDRangeKernel(
11231 kernel_,
11232 args.offset_,
11233 args.global_,
11234 args.local_,
11235 &args.events_,
11236 &event);
11237
11238 return event;
11239 }
11240
11243 * @param args Launch parameters of the kernel.
11244 * @param t0... List of kernel arguments based on the template type of the functor.
11245 * @param error Out parameter returning the error code from the execution.
11246 */
11248 const EnqueueArgs& args,
11249 Ts... ts,
11250 cl_int &error)
11251 {
11252 Event event;
11253 setArgs<0>(std::forward<Ts>(ts)...);
11254
11255 error = args.queue_.enqueueNDRangeKernel(
11256 kernel_,
11257 args.offset_,
11258 args.global_,
11259 args.local_,
11260 &args.events_,
11261 &event);
11262
11263 return event;
11264 }
11265
11266#if CL_HPP_TARGET_OPENCL_VERSION >= 200
11267 cl_int setSVMPointers(const vector<void*> &pointerList)
11268 {
11269 return kernel_.setSVMPointers(pointerList);
11270 }
11271
11272 template<typename T0, typename... T1s>
11273 cl_int setSVMPointers(const T0 &t0, T1s &... ts)
11274 {
11275 return kernel_.setSVMPointers(t0, ts...);
11276 }
11277#endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
11278
11279 Kernel getKernel()
11280 {
11281 return kernel_;
11282 }
11283};
11284
11285namespace compatibility {
11287 * Backward compatibility class to ensure that cl.hpp code works with opencl.hpp.
11288 * Please use KernelFunctor directly.
11289 */
11290 template<typename... Ts>
11291 struct make_kernel
11292 {
11293 typedef KernelFunctor<Ts...> FunctorType;
11294
11295 FunctorType functor_;
11296
11297 make_kernel(
11298 const Program& program,
11299 const string name,
11300 cl_int * err = nullptr) :
11301 functor_(FunctorType(program, name, err))
11302 {}
11303
11304 make_kernel(
11305 const Kernel kernel) :
11306 functor_(FunctorType(kernel))
11307 {}
11308
11310 typedef Event result_type;
11311
11313 typedef Event type_(
11314 const EnqueueArgs&,
11315 Ts...);
11316
11317 Event operator()(
11318 const EnqueueArgs& enqueueArgs,
11319 Ts... args)
11320 {
11321 return functor_(
11322 enqueueArgs, args...);
11323 }
11324 };
11325} // namespace compatibility
11326
11327#ifdef cl_khr_semaphore
11328
11329#ifdef cl_khr_external_semaphore
11330enum ExternalSemaphoreType : cl_external_semaphore_handle_type_khr
11331{
11332 None = 0,
11333#ifdef cl_khr_external_semaphore_dx_fence
11334 D3D12Fence = CL_SEMAPHORE_HANDLE_D3D12_FENCE_KHR,
11335#endif // cl_khr_external_semaphore_dx_fence
11336#ifdef cl_khr_external_semaphore_opaque_fd
11337 OpaqueFd = CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR,
11338#endif // cl_khr_external_semaphore_opaque_fd
11339#ifdef cl_khr_external_semaphore_sync_fd
11340 SyncFd = CL_SEMAPHORE_HANDLE_SYNC_FD_KHR,
11341#endif // cl_khr_external_semaphore_sync_fd
11342#ifdef cl_khr_external_semaphore_win32
11343 OpaqueWin32 = CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR,
11344 OpaqueWin32Kmt = CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KMT_KHR,
11345#endif // cl_khr_external_semaphore_win32
11346};
11347#endif // cl_khr_external_semaphore
11348
11349class Semaphore : public detail::Wrapper<cl_semaphore_khr>
11350{
11351public:
11352 Semaphore() : detail::Wrapper<cl_type>() {}
11353 Semaphore(
11354 const Context &context,
11355 const vector<cl_semaphore_properties_khr>& sema_props,
11356 cl_int *err = nullptr)
11357 {
11358 /* initialization of addresses to extension functions (it is done only once) */
11359 std::call_once(ext_init_, initExtensions, context);
11360
11361 cl_int error = CL_INVALID_OPERATION;
11362
11363 if (pfn_clCreateSemaphoreWithPropertiesKHR)
11364 {
11365 object_ = pfn_clCreateSemaphoreWithPropertiesKHR(
11366 context(),
11367 sema_props.empty() ? nullptr : sema_props.data(),
11368 &error);
11369 }
11370
11371 detail::errHandler(error, __CREATE_SEMAPHORE_KHR_WITH_PROPERTIES_ERR);
11372
11373 if (err != nullptr) {
11374 *err = error;
11375 }
11376 }
11377 Semaphore(
11378 const vector<cl_semaphore_properties_khr>& sema_props,
11379 cl_int* err = nullptr):Semaphore(Context::getDefault(err), sema_props, err) {}
11380
11381 explicit Semaphore(const cl_semaphore_khr& semaphore, bool retainObject = false) :
11382 detail::Wrapper<cl_type>(semaphore, retainObject) {}
11383 Semaphore& operator = (const cl_semaphore_khr& rhs) {
11384 detail::Wrapper<cl_type>::operator=(rhs);
11385 return *this;
11386 }
11387 template <typename T>
11388 cl_int getInfo(cl_semaphore_info_khr name, T* param) const
11389 {
11390 if (pfn_clGetSemaphoreInfoKHR == nullptr) {
11391 return detail::errHandler(CL_INVALID_OPERATION,
11392 __GET_SEMAPHORE_KHR_INFO_ERR);
11393 }
11394
11395 return detail::errHandler(
11396 detail::getInfo(pfn_clGetSemaphoreInfoKHR, object_, name, param),
11397 __GET_SEMAPHORE_KHR_INFO_ERR);
11398 }
11399 template <cl_semaphore_info_khr name> typename
11400 detail::param_traits<detail::cl_semaphore_info_khr, name>::param_type
11401 getInfo(cl_int* err = nullptr) const
11402 {
11403 typename detail::param_traits<
11404 detail::cl_semaphore_info_khr, name>::param_type param{};
11405 cl_int result = getInfo(name, &param);
11406 if (err != nullptr) {
11407 *err = result;
11408 }
11409 return param;
11410 }
11411
11412#ifdef cl_khr_external_semaphore
11413 template <typename T>
11414 cl_int getHandleForTypeKHR(
11415 const Device& device, cl_external_semaphore_handle_type_khr name, T* param) const
11416 {
11417 if (pfn_clGetSemaphoreHandleForTypeKHR == nullptr) {
11418 return detail::errHandler(CL_INVALID_OPERATION,
11419 __GET_SEMAPHORE_HANDLE_FOR_TYPE_KHR_ERR);
11420 }
11421
11422 return detail::errHandler(
11423 detail::getInfo(
11424 pfn_clGetSemaphoreHandleForTypeKHR, object_, device(), name, param),
11425 __GET_SEMAPHORE_HANDLE_FOR_TYPE_KHR_ERR);
11426 }
11427
11428 template <cl_external_semaphore_handle_type_khr type> typename
11429 detail::param_traits<detail::cl_external_semaphore_handle_type_khr, type>::param_type
11430 getHandleForTypeKHR(const Device& device, cl_int* err = nullptr) const
11431 {
11432 typename detail::param_traits<
11433 detail::cl_external_semaphore_handle_type_khr, type>::param_type param;
11434 cl_int result = getHandleForTypeKHR(device, type, &param);
11435 if (err != nullptr) {
11436 *err = result;
11437 }
11438 return param;
11439 }
11440#endif // cl_khr_external_semaphore
11441
11442 cl_int retain()
11443 {
11444 if (pfn_clRetainSemaphoreKHR == nullptr) {
11445 return detail::errHandler(CL_INVALID_OPERATION,
11446 __RETAIN_SEMAPHORE_KHR_ERR);
11447 }
11448 return pfn_clRetainSemaphoreKHR(object_);
11449 }
11450
11451 cl_int release()
11452 {
11453 if (pfn_clReleaseSemaphoreKHR == nullptr) {
11454 return detail::errHandler(CL_INVALID_OPERATION,
11455 __RELEASE_SEMAPHORE_KHR_ERR);
11456 }
11457 return pfn_clReleaseSemaphoreKHR(object_);
11458 }
11459
11460private:
11461 static std::once_flag ext_init_;
11462
11463 static void initExtensions(const Context& context)
11464 {
11465#if CL_HPP_TARGET_OPENCL_VERSION >= 120
11466 Device device = context.getInfo<CL_CONTEXT_DEVICES>().at(0);
11467 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>()();
11468 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateSemaphoreWithPropertiesKHR);
11469 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clReleaseSemaphoreKHR);
11470 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clRetainSemaphoreKHR);
11471 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueWaitSemaphoresKHR);
11472 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueSignalSemaphoresKHR);
11473 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clGetSemaphoreInfoKHR);
11474#ifdef cl_khr_external_semaphore
11475 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clGetSemaphoreHandleForTypeKHR);
11476#endif // cl_khr_external_semaphore
11477
11478#else
11479 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSemaphoreWithPropertiesKHR);
11480 CL_HPP_INIT_CL_EXT_FCN_PTR_(clReleaseSemaphoreKHR);
11481 CL_HPP_INIT_CL_EXT_FCN_PTR_(clRetainSemaphoreKHR);
11482 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueWaitSemaphoresKHR);
11483 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueSignalSemaphoresKHR);
11484 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetSemaphoreInfoKHR);
11485#ifdef cl_khr_external_semaphore
11486 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetSemaphoreHandleForTypeKHR);
11487#endif // cl_khr_external_semaphore
11488
11489#endif
11490 if ((pfn_clCreateSemaphoreWithPropertiesKHR == nullptr) &&
11491 (pfn_clReleaseSemaphoreKHR == nullptr) &&
11492 (pfn_clRetainSemaphoreKHR == nullptr) &&
11493 (pfn_clEnqueueWaitSemaphoresKHR == nullptr) &&
11494 (pfn_clEnqueueSignalSemaphoresKHR == nullptr) &&
11495#ifdef cl_khr_external_semaphore
11496 (pfn_clGetSemaphoreHandleForTypeKHR == nullptr) &&
11497#endif // cl_khr_external_semaphore
11498 (pfn_clGetSemaphoreInfoKHR == nullptr))
11499 {
11500 detail::errHandler(CL_INVALID_VALUE, __CREATE_SEMAPHORE_KHR_WITH_PROPERTIES_ERR);
11501 }
11502 }
11503
11504};
11505
11506CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Semaphore::ext_init_;
11507
11508inline cl_int CommandQueue::enqueueWaitSemaphores(
11509 const vector<Semaphore> &sema_objects,
11510 const vector<cl_semaphore_payload_khr> &sema_payloads,
11511 const vector<Event>* events_wait_list,
11512 Event *event) const
11513{
11514 cl_event tmp;
11515 cl_int err = CL_INVALID_OPERATION;
11516
11517 if (pfn_clEnqueueWaitSemaphoresKHR != nullptr) {
11518 err = pfn_clEnqueueWaitSemaphoresKHR(
11519 object_,
11520 (cl_uint)sema_objects.size(),
11521 (const cl_semaphore_khr *) &sema_objects.front(),
11522 (sema_payloads.size() > 0) ? &sema_payloads.front() : nullptr,
11523 (events_wait_list != nullptr) ? (cl_uint) events_wait_list->size() : 0,
11524 (events_wait_list != nullptr && events_wait_list->size() > 0) ? (const cl_event*) &events_wait_list->front() : nullptr,
11525 (event != nullptr) ? &tmp : nullptr);
11526 }
11527
11528 detail::errHandler(err, __ENQUEUE_WAIT_SEMAPHORE_KHR_ERR);
11529
11530 if (event != nullptr && err == CL_SUCCESS)
11531 *event = tmp;
11532
11533 return err;
11534}
11535
11536inline cl_int CommandQueue::enqueueSignalSemaphores(
11537 const vector<Semaphore> &sema_objects,
11538 const vector<cl_semaphore_payload_khr>& sema_payloads,
11539 const vector<Event>* events_wait_list,
11540 Event* event)
11541{
11542 cl_event tmp;
11543 cl_int err = CL_INVALID_OPERATION;
11544
11545 if (pfn_clEnqueueSignalSemaphoresKHR != nullptr) {
11546 err = pfn_clEnqueueSignalSemaphoresKHR(
11547 object_,
11548 (cl_uint)sema_objects.size(),
11549 (const cl_semaphore_khr*) &sema_objects.front(),
11550 (sema_payloads.size() > 0) ? &sema_payloads.front() : nullptr,
11551 (events_wait_list != nullptr) ? (cl_uint) events_wait_list->size() : 0,
11552 (events_wait_list != nullptr && events_wait_list->size() > 0) ? (const cl_event*) &events_wait_list->front() : nullptr,
11553 (event != nullptr) ? &tmp : nullptr);
11554 }
11555
11556 detail::errHandler(err, __ENQUEUE_SIGNAL_SEMAPHORE_KHR_ERR);
11557
11558 if (event != nullptr && err == CL_SUCCESS)
11559 *event = tmp;
11560
11561 return err;
11562}
11563
11564#endif // cl_khr_semaphore
11565
11566#if defined(cl_khr_command_buffer)
11570class CommandBufferKhr : public detail::Wrapper<cl_command_buffer_khr>
11571{
11572public:
11574 CommandBufferKhr() : detail::Wrapper<cl_type>() { }
11575
11576 explicit CommandBufferKhr(const vector<CommandQueue> &queues,
11577 cl_command_buffer_properties_khr properties = 0,
11578 cl_int* errcode_ret = nullptr)
11579 {
11580 cl_command_buffer_properties_khr command_buffer_properties[] = {
11581 CL_COMMAND_BUFFER_FLAGS_KHR, properties, 0
11582 };
11583
11584 /* initialization of addresses to extension functions (it is done only once) */
11585 std::call_once(ext_init_, [&] { initExtensions(queues[0].getInfo<CL_QUEUE_DEVICE>()); });
11586 cl_int error = CL_INVALID_OPERATION;
11587
11588 static_assert(sizeof(cl::CommandQueue) == sizeof(cl_command_queue),
11589 "Size of cl::CommandQueue must be equal to size of cl_command_queue");
11590
11591 if (pfn_clCreateCommandBufferKHR)
11592 {
11593 object_ = pfn_clCreateCommandBufferKHR((cl_uint) queues.size(),
11594 (const cl_command_queue *) &queues.front(),
11595 command_buffer_properties,
11596 &error);
11597 }
11598
11599 detail::errHandler(error, __CREATE_COMMAND_BUFFER_KHR_ERR);
11600 if (errcode_ret != nullptr) {
11601 *errcode_ret = error;
11602 }
11603 }
11604
11605 explicit CommandBufferKhr(const cl_command_buffer_khr& commandBufferKhr, bool retainObject = false) :
11606 detail::Wrapper<cl_type>(commandBufferKhr, retainObject) { }
11607
11608 CommandBufferKhr& operator=(const cl_command_buffer_khr& rhs)
11609 {
11610 detail::Wrapper<cl_type>::operator=(rhs);
11611 return *this;
11612 }
11613
11614 template <typename T>
11615 cl_int getInfo(cl_command_buffer_info_khr name, T* param) const
11616 {
11617 if (pfn_clGetCommandBufferInfoKHR == nullptr) {
11618 return detail::errHandler(CL_INVALID_OPERATION,
11619 __GET_COMMAND_BUFFER_INFO_KHR_ERR);
11620 }
11621 return detail::errHandler(
11622 detail::getInfo(pfn_clGetCommandBufferInfoKHR, object_, name, param),
11623 __GET_COMMAND_BUFFER_INFO_KHR_ERR);
11624 }
11625
11626 template <cl_command_buffer_info_khr name> typename
11627 detail::param_traits<detail::cl_command_buffer_info_khr, name>::param_type
11628 getInfo(cl_int* err = nullptr) const
11629 {
11630 typename detail::param_traits<
11631 detail::cl_command_buffer_info_khr, name>::param_type param{};
11632 cl_int result = getInfo(name, &param);
11633 if (err != nullptr) {
11634 *err = result;
11635 }
11636 return param;
11637 }
11638
11639 cl_int finalizeCommandBuffer() const
11640 {
11641 if (pfn_clFinalizeCommandBufferKHR == nullptr) {
11642 return detail::errHandler(CL_INVALID_OPERATION, __FINALIZE_COMMAND_BUFFER_KHR_ERR);
11643 }
11644 return detail::errHandler(pfn_clFinalizeCommandBufferKHR(object_), __FINALIZE_COMMAND_BUFFER_KHR_ERR);
11645 }
11646
11647 cl_int enqueueCommandBuffer(vector<CommandQueue> &queues,
11648 const vector<Event>* events = nullptr,
11649 Event* event = nullptr)
11650 {
11651 if (pfn_clEnqueueCommandBufferKHR == nullptr) {
11652 return detail::errHandler(CL_INVALID_OPERATION,
11653 __ENQUEUE_COMMAND_BUFFER_KHR_ERR);
11654 }
11655
11656 static_assert(sizeof(cl::CommandQueue) == sizeof(cl_command_queue),
11657 "Size of cl::CommandQueue must be equal to size of cl_command_queue");
11658
11659 return detail::errHandler(pfn_clEnqueueCommandBufferKHR((cl_uint) queues.size(),
11660 (cl_command_queue *) &queues.front(),
11661 object_,
11662 (events != nullptr) ? (cl_uint) events->size() : 0,
11663 (events != nullptr && events->size() > 0) ? (const cl_event*) &events->front() : nullptr,
11664 (cl_event*) event),
11665 __ENQUEUE_COMMAND_BUFFER_KHR_ERR);
11666 }
11667
11668 cl_int commandBarrierWithWaitList(const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11669 cl_sync_point_khr* sync_point = nullptr,
11670 MutableCommandKhr* mutable_handle = nullptr,
11671 const CommandQueue* command_queue = nullptr)
11672 {
11673 if (pfn_clCommandBarrierWithWaitListKHR == nullptr) {
11674 return detail::errHandler(CL_INVALID_OPERATION,
11675 __COMMAND_BARRIER_WITH_WAIT_LIST_KHR_ERR);
11676 }
11677
11678 cl_sync_point_khr tmp_sync_point;
11679 cl_int error = detail::errHandler(
11680 pfn_clCommandBarrierWithWaitListKHR(object_,
11681 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11682#if CL_KHR_COMMAND_BUFFER_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 4)
11683 nullptr, // Properties
11684#endif
11685 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11686 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11687 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11688 (cl_mutable_command_khr*) mutable_handle),
11689 __COMMAND_BARRIER_WITH_WAIT_LIST_KHR_ERR);
11690
11691 if (sync_point != nullptr && error == CL_SUCCESS)
11692 *sync_point = tmp_sync_point;
11693
11694 return error;
11695 }
11696
11697 cl_int commandCopyBuffer(const Buffer& src,
11698 const Buffer& dst,
11699 size_type src_offset,
11700 size_type dst_offset,
11701 size_type size,
11702 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11703 cl_sync_point_khr* sync_point = nullptr,
11704 MutableCommandKhr* mutable_handle = nullptr,
11705 const CommandQueue* command_queue = nullptr)
11706 {
11707 if (pfn_clCommandCopyBufferKHR == nullptr) {
11708 return detail::errHandler(CL_INVALID_OPERATION,
11709 __COMMAND_COPY_BUFFER_KHR_ERR);
11710 }
11711
11712 cl_sync_point_khr tmp_sync_point;
11713 cl_int error = detail::errHandler(
11714 pfn_clCommandCopyBufferKHR(object_,
11715 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11716#if CL_KHR_COMMAND_BUFFER_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 4)
11717 nullptr, // Properties
11718#endif
11719 src(),
11720 dst(),
11721 src_offset,
11722 dst_offset,
11723 size,
11724 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11725 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11726 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11727 (cl_mutable_command_khr*) mutable_handle),
11728 __COMMAND_COPY_BUFFER_KHR_ERR);
11729
11730 if (sync_point != nullptr && error == CL_SUCCESS)
11731 *sync_point = tmp_sync_point;
11732
11733 return error;
11734 }
11735
11736 cl_int commandCopyBufferRect(const Buffer& src,
11737 const Buffer& dst,
11738 const array<size_type, 3>& src_origin,
11739 const array<size_type, 3>& dst_origin,
11740 const array<size_type, 3>& region,
11741 size_type src_row_pitch,
11742 size_type src_slice_pitch,
11743 size_type dst_row_pitch,
11744 size_type dst_slice_pitch,
11745 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11746 cl_sync_point_khr* sync_point = nullptr,
11747 MutableCommandKhr* mutable_handle = nullptr,
11748 const CommandQueue* command_queue = nullptr)
11749 {
11750 if (pfn_clCommandCopyBufferRectKHR == nullptr) {
11751 return detail::errHandler(CL_INVALID_OPERATION,
11752 __COMMAND_COPY_BUFFER_RECT_KHR_ERR);
11753 }
11754
11755 cl_sync_point_khr tmp_sync_point;
11756 cl_int error = detail::errHandler(
11757 pfn_clCommandCopyBufferRectKHR(object_,
11758 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11759#if CL_KHR_COMMAND_BUFFER_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 4)
11760 nullptr, // Properties
11761#endif
11762 src(),
11763 dst(),
11764 src_origin.data(),
11765 dst_origin.data(),
11766 region.data(),
11767 src_row_pitch,
11768 src_slice_pitch,
11769 dst_row_pitch,
11770 dst_slice_pitch,
11771 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11772 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11773 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11774 (cl_mutable_command_khr*) mutable_handle),
11775 __COMMAND_COPY_BUFFER_RECT_KHR_ERR);
11776
11777 if (sync_point != nullptr && error == CL_SUCCESS)
11778 *sync_point = tmp_sync_point;
11779
11780 return error;
11781 }
11782
11783 cl_int commandCopyBufferToImage(const Buffer& src,
11784 const Image& dst,
11785 size_type src_offset,
11786 const array<size_type, 3>& dst_origin,
11787 const array<size_type, 3>& region,
11788 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11789 cl_sync_point_khr* sync_point = nullptr,
11790 MutableCommandKhr* mutable_handle = nullptr,
11791 const CommandQueue* command_queue = nullptr)
11792 {
11793 if (pfn_clCommandCopyBufferToImageKHR == nullptr) {
11794 return detail::errHandler(CL_INVALID_OPERATION,
11795 __COMMAND_COPY_BUFFER_TO_IMAGE_KHR_ERR);
11796 }
11797
11798 cl_sync_point_khr tmp_sync_point;
11799 cl_int error = detail::errHandler(
11800 pfn_clCommandCopyBufferToImageKHR(object_,
11801 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11802#if CL_KHR_COMMAND_BUFFER_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 4)
11803 nullptr, // Properties
11804#endif
11805 src(),
11806 dst(),
11807 src_offset,
11808 dst_origin.data(),
11809 region.data(),
11810 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11811 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11812 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11813 (cl_mutable_command_khr*) mutable_handle),
11814 __COMMAND_COPY_BUFFER_TO_IMAGE_KHR_ERR);
11815
11816 if (sync_point != nullptr && error == CL_SUCCESS)
11817 *sync_point = tmp_sync_point;
11818
11819 return error;
11820 }
11821
11822 cl_int commandCopyImage(const Image& src,
11823 const Image& dst,
11824 const array<size_type, 3>& src_origin,
11825 const array<size_type, 3>& dst_origin,
11826 const array<size_type, 3>& region,
11827 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11828 cl_sync_point_khr* sync_point = nullptr,
11829 MutableCommandKhr* mutable_handle = nullptr,
11830 const CommandQueue* command_queue = nullptr)
11831 {
11832 if (pfn_clCommandCopyImageKHR == nullptr) {
11833 return detail::errHandler(CL_INVALID_OPERATION,
11834 __COMMAND_COPY_IMAGE_KHR_ERR);
11835 }
11836
11837 cl_sync_point_khr tmp_sync_point;
11838 cl_int error = detail::errHandler(
11839 pfn_clCommandCopyImageKHR(object_,
11840 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11841#if CL_KHR_COMMAND_BUFFER_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 4)
11842 nullptr, // Properties
11843#endif
11844 src(),
11845 dst(),
11846 src_origin.data(),
11847 dst_origin.data(),
11848 region.data(),
11849 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11850 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11851 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11852 (cl_mutable_command_khr*) mutable_handle),
11853 __COMMAND_COPY_IMAGE_KHR_ERR);
11854
11855 if (sync_point != nullptr && error == CL_SUCCESS)
11856 *sync_point = tmp_sync_point;
11857
11858 return error;
11859 }
11860
11861 cl_int commandCopyImageToBuffer(const Image& src,
11862 const Buffer& dst,
11863 const array<size_type, 3>& src_origin,
11864 const array<size_type, 3>& region,
11865 size_type dst_offset,
11866 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11867 cl_sync_point_khr* sync_point = nullptr,
11868 MutableCommandKhr* mutable_handle = nullptr,
11869 const CommandQueue* command_queue = nullptr)
11870 {
11871 if (pfn_clCommandCopyImageToBufferKHR == nullptr) {
11872 return detail::errHandler(CL_INVALID_OPERATION,
11873 __COMMAND_COPY_IMAGE_TO_BUFFER_KHR_ERR);
11874 }
11875
11876 cl_sync_point_khr tmp_sync_point;
11877 cl_int error = detail::errHandler(
11878 pfn_clCommandCopyImageToBufferKHR(object_,
11879 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11880#if CL_KHR_COMMAND_BUFFER_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 4)
11881 nullptr, // Properties
11882#endif
11883 src(),
11884 dst(),
11885 src_origin.data(),
11886 region.data(),
11887 dst_offset,
11888 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11889 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11890 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11891 (cl_mutable_command_khr*) mutable_handle),
11892 __COMMAND_COPY_IMAGE_TO_BUFFER_KHR_ERR);
11893
11894 if (sync_point != nullptr && error == CL_SUCCESS)
11895 *sync_point = tmp_sync_point;
11896
11897 return error;
11898 }
11899
11900 template<typename PatternType>
11901 cl_int commandFillBuffer(const Buffer& buffer,
11902 PatternType pattern,
11903 size_type offset,
11904 size_type size,
11905 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11906 cl_sync_point_khr* sync_point = nullptr,
11907 MutableCommandKhr* mutable_handle = nullptr,
11908 const CommandQueue* command_queue = nullptr)
11909 {
11910 if (pfn_clCommandFillBufferKHR == nullptr) {
11911 return detail::errHandler(CL_INVALID_OPERATION,
11912 __COMMAND_FILL_BUFFER_KHR_ERR);
11913 }
11914
11915 cl_sync_point_khr tmp_sync_point;
11916 cl_int error = detail::errHandler(
11917 pfn_clCommandFillBufferKHR(object_,
11918 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11919#if CL_KHR_COMMAND_BUFFER_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 4)
11920 nullptr, // Properties
11921#endif
11922 buffer(),
11923 static_cast<void*>(&pattern),
11924 sizeof(PatternType),
11925 offset,
11926 size,
11927 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11928 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11929 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11930 (cl_mutable_command_khr*) mutable_handle),
11931 __COMMAND_FILL_BUFFER_KHR_ERR);
11932
11933 if (sync_point != nullptr && error == CL_SUCCESS)
11934 *sync_point = tmp_sync_point;
11935
11936 return error;
11937 }
11938
11939 cl_int commandFillImage(const Image& image,
11940 cl_float4 fillColor,
11941 const array<size_type, 3>& origin,
11942 const array<size_type, 3>& region,
11943 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11944 cl_sync_point_khr* sync_point = nullptr,
11945 MutableCommandKhr* mutable_handle = nullptr,
11946 const CommandQueue* command_queue = nullptr)
11947 {
11948 if (pfn_clCommandFillImageKHR == nullptr) {
11949 return detail::errHandler(CL_INVALID_OPERATION,
11950 __COMMAND_FILL_IMAGE_KHR_ERR);
11951 }
11952
11953 cl_sync_point_khr tmp_sync_point;
11954 cl_int error = detail::errHandler(
11955 pfn_clCommandFillImageKHR(object_,
11956 (command_queue != nullptr) ? (*command_queue)() : nullptr,
11957#if CL_KHR_COMMAND_BUFFER_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 4)
11958 nullptr, // Properties
11959#endif
11960 image(),
11961 &fillColor,
11962 origin.data(),
11963 region.data(),
11964 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
11965 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
11966 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
11967 (cl_mutable_command_khr*) mutable_handle),
11968 __COMMAND_FILL_IMAGE_KHR_ERR);
11969
11970 if (sync_point != nullptr && error == CL_SUCCESS)
11971 *sync_point = tmp_sync_point;
11972
11973 return error;
11974 }
11975
11976 cl_int commandNDRangeKernel(
11977#if CL_KHR_COMMAND_BUFFER_EXTENSION_VERSION > CL_MAKE_VERSION(0, 9, 4)
11978 const cl::vector<cl_command_properties_khr> &properties,
11979#else
11980 const cl::vector<cl_ndrange_kernel_command_properties_khr> &properties,
11981#endif
11982 const Kernel& kernel,
11983 const NDRange& offset,
11984 const NDRange& global,
11985 const NDRange& local = NullRange,
11986 const vector<cl_sync_point_khr>* sync_points_vec = nullptr,
11987 cl_sync_point_khr* sync_point = nullptr,
11988 MutableCommandKhr* mutable_handle = nullptr,
11989 const CommandQueue* command_queue = nullptr)
11990 {
11991 if (pfn_clCommandNDRangeKernelKHR == nullptr) {
11992 return detail::errHandler(CL_INVALID_OPERATION,
11993 __COMMAND_NDRANGE_KERNEL_KHR_ERR);
11994 }
11995
11996 cl_sync_point_khr tmp_sync_point;
11997 cl_int error = detail::errHandler(
11998 pfn_clCommandNDRangeKernelKHR(object_,
11999 (command_queue != nullptr) ? (*command_queue)() : nullptr,
12000 properties.empty() ? nullptr : properties.data(),
12001 kernel(),
12002 (cl_uint) global.dimensions(),
12003 offset.dimensions() != 0 ? (const size_type*) offset : nullptr,
12004 (const size_type*) global,
12005 local.dimensions() != 0 ? (const size_type*) local : nullptr,
12006 (sync_points_vec != nullptr) ? (cl_uint) sync_points_vec->size() : 0,
12007 (sync_points_vec != nullptr && sync_points_vec->size() > 0) ? &sync_points_vec->front() : nullptr,
12008 (sync_point != nullptr) ? &tmp_sync_point : nullptr,
12009 (cl_mutable_command_khr*) mutable_handle),
12010 __COMMAND_NDRANGE_KERNEL_KHR_ERR);
12011
12012 if (sync_point != nullptr && error == CL_SUCCESS)
12013 *sync_point = tmp_sync_point;
12014
12015 return error;
12016 }
12017
12018#if defined(cl_khr_command_buffer_mutable_dispatch)
12019#if CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION < \
12020 CL_MAKE_VERSION(0, 9, 2)
12021 cl_int updateMutableCommands(const cl_mutable_base_config_khr* mutable_config)
12022 {
12023 if (pfn_clUpdateMutableCommandsKHR == nullptr) {
12024 return detail::errHandler(CL_INVALID_OPERATION,
12025 __UPDATE_MUTABLE_COMMANDS_KHR_ERR);
12026 }
12027 return detail::errHandler(pfn_clUpdateMutableCommandsKHR(object_, mutable_config),
12028 __UPDATE_MUTABLE_COMMANDS_KHR_ERR);
12029 }
12030#else
12031 template <int ArrayLength>
12032 cl_int updateMutableCommands(std::array<cl_command_buffer_update_type_khr,
12033 ArrayLength> &config_types,
12034 std::array<const void *, ArrayLength> &configs) {
12035 if (pfn_clUpdateMutableCommandsKHR == nullptr) {
12036 return detail::errHandler(CL_INVALID_OPERATION,
12037 __UPDATE_MUTABLE_COMMANDS_KHR_ERR);
12038 }
12039 return detail::errHandler(
12040 pfn_clUpdateMutableCommandsKHR(
12041 object_,
12042 static_cast<cl_uint>(configs.size()),
12043 config_types.empty() ? nullptr : config_types.data(),
12044 configs.empty() ? nullptr : configs.data()),
12045 __UPDATE_MUTABLE_COMMANDS_KHR_ERR);
12046 }
12047#endif /* CL_KHR_COMMAND_BUFFER_MUTABLE_DISPATCH_EXTENSION_VERSION */
12048#endif /* cl_khr_command_buffer_mutable_dispatch */
12049
12050private:
12051 static std::once_flag ext_init_;
12052
12053 static void initExtensions(const cl::Device& device)
12054 {
12055#if CL_HPP_TARGET_OPENCL_VERSION >= 120
12056 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>()();
12057 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateCommandBufferKHR);
12058 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clFinalizeCommandBufferKHR);
12059 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clRetainCommandBufferKHR);
12060 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clReleaseCommandBufferKHR);
12061 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clGetCommandBufferInfoKHR);
12062 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueCommandBufferKHR);
12063 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandBarrierWithWaitListKHR);
12064 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandCopyBufferKHR);
12065 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandCopyBufferRectKHR);
12066 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandCopyBufferToImageKHR);
12067 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandCopyImageKHR);
12068 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandCopyImageToBufferKHR);
12069 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandFillBufferKHR);
12070 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandFillImageKHR);
12071 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCommandNDRangeKernelKHR);
12072#if defined(cl_khr_command_buffer_mutable_dispatch)
12073 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clUpdateMutableCommandsKHR);
12074 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clGetMutableCommandInfoKHR);
12075#endif /* cl_khr_command_buffer_mutable_dispatch */
12076#elif CL_HPP_TARGET_OPENCL_VERSION >= 110
12077 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateCommandBufferKHR);
12078 CL_HPP_INIT_CL_EXT_FCN_PTR_(clFinalizeCommandBufferKHR);
12079 CL_HPP_INIT_CL_EXT_FCN_PTR_(clRetainCommandBufferKHR);
12080 CL_HPP_INIT_CL_EXT_FCN_PTR_(clReleaseCommandBufferKHR);
12081 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetCommandBufferInfoKHR);
12082 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueCommandBufferKHR);
12083 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandBarrierWithWaitListKHR);
12084 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandCopyBufferKHR);
12085 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandCopyBufferRectKHR);
12086 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandCopyBufferToImageKHR);
12087 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandCopyImageKHR);
12088 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandCopyImageToBufferKHR);
12089 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandFillBufferKHR);
12090 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandFillImageKHR);
12091 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCommandNDRangeKernelKHR);
12092#if defined(cl_khr_command_buffer_mutable_dispatch)
12093 CL_HPP_INIT_CL_EXT_FCN_PTR_(clUpdateMutableCommandsKHR);
12094 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetMutableCommandInfoKHR);
12095#endif /* cl_khr_command_buffer_mutable_dispatch */
12096#endif
12097 if ((pfn_clCreateCommandBufferKHR == nullptr) &&
12098 (pfn_clFinalizeCommandBufferKHR == nullptr) &&
12099 (pfn_clRetainCommandBufferKHR == nullptr) &&
12100 (pfn_clReleaseCommandBufferKHR == nullptr) &&
12101 (pfn_clGetCommandBufferInfoKHR == nullptr) &&
12102 (pfn_clEnqueueCommandBufferKHR == nullptr) &&
12103 (pfn_clCommandBarrierWithWaitListKHR == nullptr) &&
12104 (pfn_clCommandCopyBufferKHR == nullptr) &&
12105 (pfn_clCommandCopyBufferRectKHR == nullptr) &&
12106 (pfn_clCommandCopyBufferToImageKHR == nullptr) &&
12107 (pfn_clCommandCopyImageKHR == nullptr) &&
12108 (pfn_clCommandCopyImageToBufferKHR == nullptr) &&
12109 (pfn_clCommandFillBufferKHR == nullptr) &&
12110 (pfn_clCommandFillImageKHR == nullptr) &&
12111 (pfn_clCommandNDRangeKernelKHR == nullptr)
12112#if defined(cl_khr_command_buffer_mutable_dispatch)
12113 && (pfn_clUpdateMutableCommandsKHR == nullptr)
12114 && (pfn_clGetMutableCommandInfoKHR == nullptr)
12115#endif /* cl_khr_command_buffer_mutable_dispatch */
12116 )
12117 {
12118 detail::errHandler(CL_INVALID_VALUE, __CREATE_COMMAND_BUFFER_KHR_ERR);
12119 }
12120 }
12121}; // CommandBufferKhr
12122
12123CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandBufferKhr::ext_init_;
12124
12125#if defined(cl_khr_command_buffer_mutable_dispatch)
12129class MutableCommandKhr : public detail::Wrapper<cl_mutable_command_khr>
12130{
12131public:
12133 MutableCommandKhr() : detail::Wrapper<cl_type>() { }
12134
12135 explicit MutableCommandKhr(const cl_mutable_command_khr& mutableCommandKhr, bool retainObject = false) :
12136 detail::Wrapper<cl_type>(mutableCommandKhr, retainObject) { }
12137
12138 MutableCommandKhr& operator=(const cl_mutable_command_khr& rhs)
12139 {
12140 detail::Wrapper<cl_type>::operator=(rhs);
12141 return *this;
12142 }
12143
12144 template <typename T>
12145 cl_int getInfo(cl_mutable_command_info_khr name, T* param) const
12146 {
12147 if (pfn_clGetMutableCommandInfoKHR == nullptr) {
12148 return detail::errHandler(CL_INVALID_OPERATION,
12149 __GET_MUTABLE_COMMAND_INFO_KHR_ERR);
12150 }
12151 return detail::errHandler(
12152 detail::getInfo(pfn_clGetMutableCommandInfoKHR, object_, name, param),
12153 __GET_MUTABLE_COMMAND_INFO_KHR_ERR);
12154 }
12155
12156 template <cl_mutable_command_info_khr name> typename
12157 detail::param_traits<detail::cl_mutable_command_info_khr, name>::param_type
12158 getInfo(cl_int* err = nullptr) const
12159 {
12160 typename detail::param_traits<
12161 detail::cl_mutable_command_info_khr, name>::param_type param{};
12162 cl_int result = getInfo(name, &param);
12163 if (err != nullptr) {
12164 *err = result;
12165 }
12166 return param;
12167 }
12168}; // MutableCommandKhr
12169#endif /* cl_khr_command_buffer_mutable_dispatch */
12170
12171#endif // cl_khr_command_buffer
12172//----------------------------------------------------------------------------------------------------------------------
12173
12174#undef CL_HPP_ERR_STR_
12175#if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
12176#undef __GET_DEVICE_INFO_ERR
12177#undef __GET_PLATFORM_INFO_ERR
12178#undef __GET_DEVICE_IDS_ERR
12179#undef __GET_PLATFORM_IDS_ERR
12180#undef __GET_CONTEXT_INFO_ERR
12181#undef __GET_EVENT_INFO_ERR
12182#undef __GET_EVENT_PROFILE_INFO_ERR
12183#undef __GET_MEM_OBJECT_INFO_ERR
12184#undef __GET_IMAGE_INFO_ERR
12185#undef __GET_SAMPLER_INFO_ERR
12186#undef __GET_KERNEL_INFO_ERR
12187#undef __GET_KERNEL_ARG_INFO_ERR
12188#undef __GET_KERNEL_SUB_GROUP_INFO_ERR
12189#undef __GET_KERNEL_WORK_GROUP_INFO_ERR
12190#undef __GET_KERNEL_SUGGESTED_LWS_ERR
12191#undef __GET_PROGRAM_INFO_ERR
12192#undef __GET_PROGRAM_BUILD_INFO_ERR
12193#undef __GET_COMMAND_QUEUE_INFO_ERR
12194#undef __CREATE_CONTEXT_ERR
12195#undef __CREATE_CONTEXT_FROM_TYPE_ERR
12196#undef __CREATE_COMMAND_BUFFER_KHR_ERR
12197#undef __GET_COMMAND_BUFFER_INFO_KHR_ERR
12198#undef __FINALIZE_COMMAND_BUFFER_KHR_ERR
12199#undef __ENQUEUE_COMMAND_BUFFER_KHR_ERR
12200#undef __COMMAND_BARRIER_WITH_WAIT_LIST_KHR_ERR
12201#undef __COMMAND_COPY_BUFFER_KHR_ERR
12202#undef __COMMAND_COPY_BUFFER_RECT_KHR_ERR
12203#undef __COMMAND_COPY_BUFFER_TO_IMAGE_KHR_ERR
12204#undef __COMMAND_COPY_IMAGE_KHR_ERR
12205#undef __COMMAND_COPY_IMAGE_TO_BUFFER_KHR_ERR
12206#undef __COMMAND_FILL_BUFFER_KHR_ERR
12207#undef __COMMAND_FILL_IMAGE_KHR_ERR
12208#undef __COMMAND_NDRANGE_KERNEL_KHR_ERR
12209#undef __UPDATE_MUTABLE_COMMANDS_KHR_ERR
12210#undef __GET_MUTABLE_COMMAND_INFO_KHR_ERR
12211#undef __RETAIN_COMMAND_BUFFER_KHR_ERR
12212#undef __RELEASE_COMMAND_BUFFER_KHR_ERR
12213#undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
12214#undef __SET_CONTEXT_DESTRUCTOR_CALLBACK_ERR
12215#undef __CREATE_BUFFER_ERR
12216#undef __COPY_ERR
12217#undef __CREATE_SUBBUFFER_ERR
12218#undef __CREATE_GL_BUFFER_ERR
12219#undef __CREATE_GL_RENDER_BUFFER_ERR
12220#undef __GET_GL_OBJECT_INFO_ERR
12221#undef __CREATE_IMAGE_ERR
12222#undef __CREATE_GL_TEXTURE_ERR
12223#undef __IMAGE_DIMENSION_ERR
12224#undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
12225#undef __CREATE_USER_EVENT_ERR
12226#undef __SET_USER_EVENT_STATUS_ERR
12227#undef __SET_EVENT_CALLBACK_ERR
12228#undef __WAIT_FOR_EVENTS_ERR
12229#undef __CREATE_KERNEL_ERR
12230#undef __SET_KERNEL_ARGS_ERR
12231#undef __CREATE_PROGRAM_WITH_SOURCE_ERR
12232#undef __CREATE_PROGRAM_WITH_BINARY_ERR
12233#undef __CREATE_PROGRAM_WITH_IL_ERR
12234#undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR
12235#undef __BUILD_PROGRAM_ERR
12236#undef __COMPILE_PROGRAM_ERR
12237#undef __LINK_PROGRAM_ERR
12238#undef __CREATE_KERNELS_IN_PROGRAM_ERR
12239#undef __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR
12240#undef __CREATE_SAMPLER_WITH_PROPERTIES_ERR
12241#undef __SET_COMMAND_QUEUE_PROPERTY_ERR
12242#undef __ENQUEUE_READ_BUFFER_ERR
12243#undef __ENQUEUE_READ_BUFFER_RECT_ERR
12244#undef __ENQUEUE_WRITE_BUFFER_ERR
12245#undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
12246#undef __ENQEUE_COPY_BUFFER_ERR
12247#undef __ENQEUE_COPY_BUFFER_RECT_ERR
12248#undef __ENQUEUE_FILL_BUFFER_ERR
12249#undef __ENQUEUE_READ_IMAGE_ERR
12250#undef __ENQUEUE_WRITE_IMAGE_ERR
12251#undef __ENQUEUE_COPY_IMAGE_ERR
12252#undef __ENQUEUE_FILL_IMAGE_ERR
12253#undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
12254#undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
12255#undef __ENQUEUE_MAP_BUFFER_ERR
12256#undef __ENQUEUE_MAP_IMAGE_ERR
12257#undef __ENQUEUE_MAP_SVM_ERR
12258#undef __ENQUEUE_FILL_SVM_ERR
12259#undef __ENQUEUE_COPY_SVM_ERR
12260#undef __ENQUEUE_UNMAP_SVM_ERR
12261#undef __ENQUEUE_MAP_IMAGE_ERR
12262#undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
12263#undef __ENQUEUE_NDRANGE_KERNEL_ERR
12264#undef __ENQUEUE_NATIVE_KERNEL
12265#undef __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR
12266#undef __ENQUEUE_MIGRATE_SVM_ERR
12267#undef __ENQUEUE_ACQUIRE_GL_ERR
12268#undef __ENQUEUE_RELEASE_GL_ERR
12269#undef __CREATE_PIPE_ERR
12270#undef __GET_PIPE_INFO_ERR
12271#undef __RETAIN_ERR
12272#undef __RELEASE_ERR
12273#undef __FLUSH_ERR
12274#undef __FINISH_ERR
12275#undef __VECTOR_CAPACITY_ERR
12276#undef __CREATE_SUB_DEVICES_ERR
12277#undef __ENQUEUE_ACQUIRE_EXTERNAL_MEMORY_ERR
12278#undef __ENQUEUE_RELEASE_EXTERNAL_MEMORY_ERR
12279#undef __ENQUEUE_MARKER_ERR
12280#undef __ENQUEUE_WAIT_FOR_EVENTS_ERR
12281#undef __ENQUEUE_BARRIER_ERR
12282#undef __UNLOAD_COMPILER_ERR
12283#undef __CREATE_GL_TEXTURE_2D_ERR
12284#undef __CREATE_GL_TEXTURE_3D_ERR
12285#undef __CREATE_IMAGE2D_ERR
12286#undef __CREATE_IMAGE3D_ERR
12287#undef __CREATE_COMMAND_QUEUE_ERR
12288#undef __ENQUEUE_TASK_ERR
12289#undef __CREATE_SAMPLER_ERR
12290#undef __ENQUEUE_MARKER_WAIT_LIST_ERR
12291#undef __ENQUEUE_BARRIER_WAIT_LIST_ERR
12292#undef __CLONE_KERNEL_ERR
12293#undef __GET_HOST_TIMER_ERR
12294#undef __GET_DEVICE_AND_HOST_TIMER_ERR
12295#undef __GET_SEMAPHORE_KHR_INFO_ERR
12296#undef __CREATE_SEMAPHORE_KHR_WITH_PROPERTIES_ERR
12297#undef __GET_IMAGE_REQUIREMENT_INFO_EXT_ERR
12298#undef __ENQUEUE_WAIT_SEMAPHORE_KHR_ERR
12299#undef __ENQUEUE_SIGNAL_SEMAPHORE_KHR_ERR
12300#undef __RETAIN_SEMAPHORE_KHR_ERR
12301#undef __RELEASE_SEMAPHORE_KHR_ERR
12302#undef __GET_SEMAPHORE_HANDLE_FOR_TYPE_KHR_ERR
12303
12304#endif //CL_HPP_USER_OVERRIDE_ERROR_STRINGS
12305
12306// Extensions
12307#undef CL_HPP_CREATE_CL_EXT_FCN_PTR_ALIAS_
12308#undef CL_HPP_INIT_CL_EXT_FCN_PTR_
12309#undef CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_
12310
12311#undef CL_HPP_DEFINE_STATIC_MEMBER_
12312
12313#undef CL_
12314
12315} // namespace cl
12316
12317#endif // CL_HPP_
BufferGL(const Context &context, cl_mem_flags flags, cl_GLuint bufobj, cl_int *err=nullptr)
Constructs a BufferGL in a specified context, from a given GL buffer.
Definition opencl.hpp:4733
BufferGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4769
BufferGL()
Default constructor - initializes to nullptr.
Definition opencl.hpp:4753
cl_int getObjectInfo(cl_gl_object_type *type, cl_GLuint *gl_object_name)
Wrapper for clGetGLObjectInfo().
Definition opencl.hpp:4777
Class interface for Buffer Memory Objects.
Definition opencl.hpp:4418
Buffer()
Default constructor - initializes to nullptr.
Definition opencl.hpp:4582
Buffer createSubBuffer(cl_mem_flags flags, cl_buffer_create_type buffer_create_type, const void *buffer_create_info, cl_int *err=nullptr)
Creates a new buffer object from this.
Definition opencl.hpp:4610
Buffer & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4598
Buffer(const Context &context, cl_mem_flags flags, size_type size, void *host_ptr=nullptr, cl_int *err=nullptr)
Constructs a Buffer in a specified context.
Definition opencl.hpp:4428
cl_int getObjectInfo(cl_gl_object_type *type, cl_GLuint *gl_object_name)
Wrapper for clGetGLObjectInfo().
Definition opencl.hpp:4847
BufferRenderGL()
Default constructor - initializes to nullptr.
Definition opencl.hpp:4823
BufferRenderGL(const Context &context, cl_mem_flags flags, cl_GLuint bufobj, cl_int *err=nullptr)
Constructs a BufferRenderGL in a specified context, from a given GL Renderbuffer.
Definition opencl.hpp:4803
BufferRenderGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4839
CommandQueue interface for cl_command_queue.
Definition opencl.hpp:7614
cl_int enqueueUnmapSVM(T *ptr, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:9116
CommandQueue(cl_command_queue_properties properties, cl_int *err=nullptr)
Constructs a CommandQueue based on passed properties. Will return an CL_INVALID_QUEUE_PROPERTIES erro...
Definition opencl.hpp:7697
cl_int enqueueMemcpySVM(T *dst_ptr, const T *src_ptr, cl_bool blocking, size_type size, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:8850
cl_int enqueueMigrateMemObjects(const vector< Memory > &memObjects, cl_mem_migration_flags flags, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:9253
cl_int enqueueMarkerWithWaitList(const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:9200
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int enqueueMarker(Event *event=nullptr) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition opencl.hpp:9488
static CommandQueue setDefault(const CommandQueue &default_queue)
Definition opencl.hpp:8074
std::enable_if< std::is_same< T, cl_float4 >::value||std::is_same< T, cl_int4 >::value||std::is_same< T, cl_uint4 >::value, cl_int >::type enqueueFillImage(const Image &image, T fillColor, const array< size_type, 3 > &origin, const array< size_type, 3 > &region, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:8611
cl_int enqueueMapSVM(T *ptr, cl_bool blocking, cl_map_flags flags, size_type size, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:9009
cl_int enqueueMigrateSVM(const cl::vector< T * > &svmRawPointers, const cl::vector< size_type > &sizes, cl_mem_migration_flags flags=0, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:9294
cl_int enqueueMemFillSVM(T *ptr, PatternType pattern, size_type size, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:8931
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int enqueueBarrier() const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition opencl.hpp:9641
cl_int enqueueBarrierWithWaitList(const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:9230
cl_int enqueueFillBuffer(const Buffer &buffer, PatternType pattern, size_type offset, size_type size, const vector< Event > *events=nullptr, Event *event=nullptr) const
Definition opencl.hpp:8409
Class interface for cl_context.
Definition opencl.hpp:3256
Context & operator=(const cl_context &rhs)
Assignment operator from cl_context - takes ownership.
Definition opencl.hpp:3565
cl_int setDestructorCallback(void(CL_CALLBACK *pfn_notify)(cl_context, void *), void *user_data=nullptr)
Registers a destructor callback function with a context.
Definition opencl.hpp:3700
static Context setDefault(const Context &default_context)
Definition opencl.hpp:3542
static Context getDefault(cl_int *err=nullptr)
Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT.
Definition opencl.hpp:3525
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:3598
Context()
Default constructor - initializes to nullptr.
Definition opencl.hpp:3550
cl_int getInfo(cl_context_info name, T *param) const
Wrapper for clGetContextInfo().
Definition opencl.hpp:3573
Context(const vector< Device > &devices, const cl_context_properties *properties=nullptr, void(CL_CALLBACK *notifyFptr)(const char *, const void *, size_type, void *)=nullptr, void *data=nullptr, cl_int *err=nullptr)
Constructs a context including a list of specified devices.
Definition opencl.hpp:3371
DeviceCommandQueue interface for device cl_command_queues.
Definition opencl.hpp:9786
static DeviceCommandQueue updateDefault(const Context &context, const Device &device, const DeviceCommandQueue &default_queue, cl_int *err=nullptr)
Definition opencl.hpp:10001
static DeviceCommandQueue getDefault(const CommandQueue &queue, cl_int *err=nullptr)
Definition opencl.hpp:10016
static DeviceCommandQueue makeDefault(cl_int *err=nullptr)
Definition opencl.hpp:9911
Class interface for cl_device_id.
Definition opencl.hpp:2508
static Device getDefault(cl_int *errResult=nullptr)
Returns the first device on the default context.
Definition opencl.hpp:2557
Device & operator=(const cl_device_id &rhs)
Assignment operator from cl_device_id.
Definition opencl.hpp:2586
cl_int getInfo(cl_device_info name, T *param) const
Wrapper for clGetDeviceInfo().
Definition opencl.hpp:2595
Device()
Default constructor - initializes to nullptr.
Definition opencl.hpp:2544
cl_ulong getHostTimer(cl_int *error=nullptr)
Definition opencl.hpp:2623
std::pair< cl_ulong, cl_ulong > getDeviceAndHostTimer(cl_int *error=nullptr)
Definition opencl.hpp:2647
cl_int createSubDevices(const cl_device_partition_property *properties, vector< Device > *devices)
Wrapper for clCreateSubDevices().
Definition opencl.hpp:3120
static Device setDefault(const Device &default_device)
Definition opencl.hpp:2575
Class interface for cl_event.
Definition opencl.hpp:3756
cl_int setCallback(cl_int type, void(CL_CALLBACK *pfn_notify)(cl_event, cl_int, void *), void *user_data=nullptr)
Registers a user callback function for a specific command execution status.
Definition opencl.hpp:3845
cl_int getProfilingInfo(cl_profiling_info name, T *param) const
Wrapper for clGetEventProfilingInfo().
Definition opencl.hpp:3808
cl_int getInfo(cl_event_info name, T *param) const
Wrapper for clGetEventInfo().
Definition opencl.hpp:3785
cl_int wait() const
Blocks the calling thread until this event completes.
Definition opencl.hpp:3833
Event()
Default constructor - initializes to nullptr.
Definition opencl.hpp:3759
Event & operator=(const cl_event &rhs)
Assignment operator from cl_event - takes ownership.
Definition opencl.hpp:3777
static cl_int waitForEvents(const vector< Event > &events)
Blocks the calling thread until every event specified is complete.
Definition opencl.hpp:3865
Image interface for arrays of 1D images.
Definition opencl.hpp:5108
Image interface for 1D buffer images.
Definition opencl.hpp:5020
Image1D()
Default constructor - initializes to nullptr.
Definition opencl.hpp:4958
Image1D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:5007
Image1D(const Context &context, cl_mem_flags flags, ImageFormat format, size_type width, void *host_ptr=nullptr, cl_int *err=nullptr)
Constructs a 1D Image in a specified context.
Definition opencl.hpp:4929
Image interface for arrays of 2D images.
Definition opencl.hpp:5554
Class interface for GL 2D Image Memory objects.
Definition opencl.hpp:5490
Image2DGL(const Context &context, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texobj, cl_int *err=nullptr)
Constructs an Image2DGL in a specified context, from a given GL Texture.
Definition opencl.hpp:5497
Class interface for 2D Image Memory objects.
Definition opencl.hpp:5210
Image2D(const Context &context, cl_mem_flags flags, ImageFormat format, size_type width, size_type height, size_type row_pitch=0, void *host_ptr=nullptr, cl_int *err=nullptr)
Constructs a 2D Image in a specified context.
Definition opencl.hpp:5216
Image2D()
Default constructor - initializes to nullptr.
Definition opencl.hpp:5455
Image2D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:5471
Image3DGL()
Default constructor - initializes to nullptr.
Definition opencl.hpp:5837
Image3DGL & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:5853
Image3DGL(const Context &context, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texobj, cl_int *err=nullptr)
Constructs an Image3DGL in a specified context, from a given GL Texture.
Definition opencl.hpp:5813
Image3D & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:5788
Image3D()
Default constructor - initializes to nullptr.
Definition opencl.hpp:5772
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=nullptr, cl_int *err=nullptr)
Constructs a 3D Image in a specified context.
Definition opencl.hpp:5665
general image interface for GL interop. We abstract the 2D and 3D GL images into a single instance he...
Definition opencl.hpp:5870
C++ base class for Image Memory objects.
Definition opencl.hpp:4864
cl_int getImageInfo(cl_image_info name, T *param) const
Wrapper for clGetImageInfo().
Definition opencl.hpp:4893
Image & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:4883
Image()
Default constructor - initializes to nullptr.
Definition opencl.hpp:4867
Event operator()(const EnqueueArgs &args, Ts... ts)
Definition opencl.hpp:11219
Event result_type
Return type of the functor.
Definition opencl.hpp:11212
Class interface for cl_kernel.
Definition opencl.hpp:6290
cl_int setSVMPointers(const vector< void * > &pointerList)
Definition opencl.hpp:6485
cl_int setArg(cl_uint index, const cl::pointer< T, D > &argPtr)
setArg overload taking a shared_ptr type
Definition opencl.hpp:6428
Kernel()
Default constructor - initializes to nullptr.
Definition opencl.hpp:6296
Kernel & operator=(const cl_kernel &rhs)
Assignment operator from cl_kernel - takes ownership.
Definition opencl.hpp:6314
Kernel clone()
Definition opencl.hpp:6601
cl_int enableFineGrainedSystemSVM(bool svmEnabled)
Enable fine-grained system SVM.
Definition opencl.hpp:6521
Class interface for cl_mem.
Definition opencl.hpp:3942
Memory()
Default constructor - initializes to nullptr.
Definition opencl.hpp:3945
Memory & operator=(const cl_mem &rhs)
Assignment operator from cl_mem - takes ownership.
Definition opencl.hpp:3966
cl_int getInfo(cl_mem_info name, T *param) const
Wrapper for clGetMemObjectInfo().
Definition opencl.hpp:3974
cl_int setDestructorCallback(void(CL_CALLBACK *pfn_notify)(cl_mem, void *), void *user_data=nullptr)
Registers a callback function to be called when the memory object is no longer needed.
Definition opencl.hpp:4009
Class interface for specifying NDRange values.
Definition opencl.hpp:6144
size_type dimensions() const
Queries the number of dimensions in the range.
Definition opencl.hpp:6204
size_type size() const
Returns the size of the object in bytes based on the.
Definition opencl.hpp:6211
NDRange()
Default constructor - resulting range has zero dimensions.
Definition opencl.hpp:6151
Class interface for Pipe Memory Objects.
Definition opencl.hpp:5926
Pipe()
Default constructor - initializes to nullptr.
Definition opencl.hpp:5982
cl_int getInfo(cl_pipe_info name, T *param) const
Wrapper for clGetMemObjectInfo().
Definition opencl.hpp:6008
Pipe & operator=(const cl_mem &rhs)
Assignment from cl_mem - performs shallow copy.
Definition opencl.hpp:5998
Pipe(const Context &context, cl_uint packet_size, cl_uint max_packets, cl_int *err=nullptr)
Constructs a Pipe in a specified context.
Definition opencl.hpp:5938
Class interface for cl_platform_id.
Definition opencl.hpp:2733
static cl_int get(vector< Platform > &platforms)
Gets a list of available platforms.
Definition opencl.hpp:3035
Platform()
Default constructor - initializes to nullptr.
Definition opencl.hpp:2805
cl_int unloadCompiler()
Wrapper for clUnloadCompiler().
Definition opencl.hpp:3111
cl_int getDevices(cl_device_type type, vector< Device > &devices) const
Gets a list of devices for this platform.
Definition opencl.hpp:2879
Platform & operator=(const cl_platform_id &rhs)
Assignment operator from cl_platform_id.
Definition opencl.hpp:2821
cl_int getInfo(cl_platform_info name, T *param) const
Wrapper for clGetPlatformInfo().
Definition opencl.hpp:2854
static Platform setDefault(const Platform &default_platform)
Definition opencl.hpp:2845
Program interface that implements cl_program.
Definition opencl.hpp:6616
CL_API_PREFIX__VERSION_2_2_DEPRECATED cl_int setReleaseCallback(void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data), void *user_data=nullptr) CL_API_SUFFIX__VERSION_2_2_DEPRECATED
Registers a callback function to be called when destructors for program scope global variables are co...
Definition opencl.hpp:7349
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:7368
bool operator==(SVMAllocator const &rhs)
Definition opencl.hpp:4277
pointer allocate(size_type size, typename cl::SVMAllocator< void, SVMTrait >::const_pointer=0, bool map=true)
Definition opencl.hpp:4202
size_type max_size() const noexcept
Definition opencl.hpp:4249
Sampler()
Default constructor - initializes to nullptr.
Definition opencl.hpp:6044
Sampler & operator=(const cl_sampler &rhs)
Assignment operator from cl_sampler - takes ownership.
Definition opencl.hpp:6105
cl_int getInfo(cl_sampler_info name, T *param) const
Wrapper for clGetSamplerInfo().
Definition opencl.hpp:6115
UserEvent()
Default constructor - initializes to nullptr.
Definition opencl.hpp:3905
UserEvent(const Context &context, cl_int *err=nullptr)
Constructs a user event on a given context.
Definition opencl.hpp:3889
cl_int setStatus(cl_int status)
Sets the execution status of a user event object.
Definition opencl.hpp:3911
The OpenCL C++ bindings are defined within this namespace.
Definition opencl.hpp:593
cl_int copy(IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer)
Definition opencl.hpp:10401
vector< T, cl::SVMAllocator< int, cl::SVMTraitCoarse<> > > coarse_svm_vector
Vector alias to simplify contruction of coarse-grained SVM containers.
Definition opencl.hpp:4394
LocalSpaceArg Local(size_type size)
Helper function for generating LocalSpaceArg objects.
Definition opencl.hpp:6275
CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int UnloadCompiler() CL_API_SUFFIX__VERSION_1_1_DEPRECATED
Definition opencl.hpp:3221
vector< T, cl::SVMAllocator< int, cl::SVMTraitFine<> > > fine_svm_vector
Vector alias to simplify contruction of fine-grained SVM containers.
Definition opencl.hpp:4400
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:4406
cl::pointer< T, detail::Deleter< Alloc > > allocate_pointer(const Alloc &alloc_, Args &&... args)
Definition opencl.hpp:4337
cl_int enqueueUnmapSVM(T *ptr, const vector< Event > *events=nullptr, Event *event=nullptr)
Definition opencl.hpp:10316
cl_int enqueueMapSVM(T *ptr, cl_bool blocking, cl_map_flags flags, size_type size, const vector< Event > *events=nullptr, Event *event=nullptr)
Definition opencl.hpp:10214
cl_int mapSVM(cl::vector< T, Alloc > &container)
Definition opencl.hpp:10503
cl_int unmapSVM(cl::vector< T, Alloc > &container)
Definition opencl.hpp:10512
Adds constructors and member functions for cl_image_format.
Definition opencl.hpp:2475
ImageFormat & operator=(const ImageFormat &rhs)
Assignment operator.
Definition opencl.hpp:2490
ImageFormat()
Default constructor - performs no initialization.
Definition opencl.hpp:2477
Local address wrapper for use with Kernel::setArg.
Definition opencl.hpp:6232
Event type_(const EnqueueArgs &, Ts...)
Function signature of kernel functor with no event dependency.
Definition opencl.hpp:11309
Event result_type
Return type of the functor.
Definition opencl.hpp:11306
static cl_int release(cl_device_id device)
Definition opencl.hpp:2025
static cl_int retain(cl_device_id device)
Definition opencl.hpp:2014