1 /*******************************************************************************
2 * Copyright (c) 2008-2016 The Khronos Group Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and/or associated documentation files (the
6 * "Materials"), to deal in the Materials without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Materials, and to
9 * permit persons to whom the Materials are furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Materials.
15 * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
16 * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
17 * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
18 * https://www.khronos.org/registry/
20 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
27 ******************************************************************************/
31 * \brief C++ bindings for OpenCL 1.0 (rev 48), OpenCL 1.1 (rev 33),
32 * OpenCL 1.2 (rev 15), OpenCL 2.0 (rev 29), OpenCL 2.1 (rev 17),
33 * and OpenCL 2.2 (V2.2-11).
34 * \author Lee Howes and Bruce Merry
36 * Derived from the OpenCL 1.x C++ bindings written by
37 * Benedict R. Gaster, Laurent Morichetti and Lee Howes
38 * With additions and fixes from:
39 * Brian Cole, March 3rd 2010 and April 2012
40 * Matt Gruenke, April 2012.
41 * Bruce Merry, February 2013.
42 * Tom Deakin and Simon McIntosh-Smith, July 2013
47 * Optional extension support
49 * cl_ext_device_fission
50 * #define CL_HPP_USE_CL_DEVICE_FISSION
51 * cl_khr_d3d10_sharing
52 * #define CL_HPP_USE_DX_INTEROP
54 * #define CL_HPP_USE_CL_SUB_GROUPS_KHR
55 * cl_khr_image2d_from_buffer
56 * #define CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR
58 * Doxygen documentation for this header is available here:
60 * http://khronosgroup.github.io/OpenCL-CLHPP/
62 * The latest version of this header can be found on the GitHub releases page:
64 * https://github.com/KhronosGroup/OpenCL-CLHPP/releases
66 * Bugs and patches can be submitted to the GitHub repository:
68 * https://github.com/KhronosGroup/OpenCL-CLHPP
72 * \section intro Introduction
73 * For many large applications C++ is the language of choice and so it seems
74 * reasonable to define C++ bindings for OpenCL.
76 * The interface is contained with a single C++ header file \em cl2.hpp and all
77 * definitions are contained within the namespace \em cl. There is no additional
78 * requirement to include \em cl.h and to use either the C++ or original C
79 * bindings; it is enough to simply include \em cl2.hpp.
81 * The bindings themselves are lightweight and correspond closely to the
82 * underlying C API. Using the C++ bindings introduces no additional execution
85 * There are numerous compatibility, portability and memory management
86 * fixes in the new header as well as additional OpenCL 2.0 features.
87 * As a result the header is not directly backward compatible and for this
88 * reason we release it as cl2.hpp rather than a new version of cl.hpp.
91 * \section compatibility Compatibility
92 * Due to the evolution of the underlying OpenCL API the 2.0 C++ bindings
93 * include an updated approach to defining supported feature versions
94 * and the range of valid underlying OpenCL runtime versions supported.
96 * The combination of preprocessor macros CL_HPP_TARGET_OPENCL_VERSION and
97 * CL_HPP_MINIMUM_OPENCL_VERSION control this range. These are three digit
98 * decimal values representing OpenCL runime versions. The default for
99 * the target is 200, representing OpenCL 2.0 and the minimum is also
100 * defined as 200. These settings would use 2.0 API calls only.
101 * If backward compatibility with a 1.2 runtime is required, the minimum
102 * version may be set to 120.
104 * Note that this is a compile-time setting, and so affects linking against
105 * a particular SDK version rather than the versioning of the loaded runtime.
107 * The earlier versions of the header included basic vector and string
108 * classes based loosely on STL versions. These were difficult to
109 * maintain and very rarely used. For the 2.0 header we now assume
110 * the presence of the standard library unless requested otherwise.
111 * We use std::array, std::vector, std::shared_ptr and std::string
112 * throughout to safely manage memory and reduce the chance of a
113 * recurrance of earlier memory management bugs.
115 * These classes are used through typedefs in the cl namespace:
116 * cl::array, cl::vector, cl::pointer and cl::string.
117 * In addition cl::allocate_pointer forwards to std::allocate_shared
119 * In all cases these standard library classes can be replaced with
120 * custom interface-compatible versions using the CL_HPP_NO_STD_ARRAY,
121 * CL_HPP_NO_STD_VECTOR, CL_HPP_NO_STD_UNIQUE_PTR and
122 * CL_HPP_NO_STD_STRING macros.
124 * The OpenCL 1.x versions of the C++ bindings included a size_t wrapper
125 * class to interface with kernel enqueue. This caused unpleasant interactions
126 * with the standard size_t declaration and led to namespacing bugs.
127 * In the 2.0 version we have replaced this with a std::array-based interface.
128 * However, the old behaviour can be regained for backward compatibility
129 * using the CL_HPP_ENABLE_SIZE_T_COMPATIBILITY macro.
131 * Finally, the program construction interface used a clumsy vector-of-pairs
132 * design in the earlier versions. We have replaced that with a cleaner
133 * vector-of-vectors and vector-of-strings design. However, for backward
134 * compatibility old behaviour can be regained with the
135 * CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY macro.
137 * In OpenCL 2.0 OpenCL C is not entirely backward compatibility with
138 * earlier versions. As a result a flag must be passed to the OpenCL C
139 * compiled to request OpenCL 2.0 compilation of kernels with 1.2 as
140 * the default in the absence of the flag.
141 * In some cases the C++ bindings automatically compile code for ease.
142 * For those cases the compilation defaults to OpenCL C 2.0.
143 * If this is not wanted, the CL_HPP_CL_1_2_DEFAULT_BUILD macro may
144 * be specified to assume 1.2 compilation.
145 * If more fine-grained decisions on a per-kernel bases are required
146 * then explicit build operations that take the flag should be used.
149 * \section parameterization Parameters
150 * This header may be parameterized by a set of preprocessor macros.
152 * - CL_HPP_TARGET_OPENCL_VERSION
154 * Defines the target OpenCL runtime version to build the header
155 * against. Defaults to 200, representing OpenCL 2.0.
157 * - CL_HPP_NO_STD_STRING
159 * Do not use the standard library string class. cl::string is not
160 * defined and may be defined by the user before cl2.hpp is
163 * - CL_HPP_NO_STD_VECTOR
165 * Do not use the standard library vector class. cl::vector is not
166 * defined and may be defined by the user before cl2.hpp is
169 * - CL_HPP_NO_STD_ARRAY
171 * Do not use the standard library array class. cl::array is not
172 * defined and may be defined by the user before cl2.hpp is
175 * - CL_HPP_NO_STD_UNIQUE_PTR
177 * Do not use the standard library unique_ptr class. cl::pointer and
178 * the cl::allocate_pointer functions are not defined and may be
179 * defined by the user before cl2.hpp is included.
181 * - CL_HPP_ENABLE_DEVICE_FISSION
183 * Enables device fission for OpenCL 1.2 platforms.
185 * - CL_HPP_ENABLE_EXCEPTIONS
187 * Enable exceptions for use in the C++ bindings header. This is the
188 * preferred error handling mechanism but is not required.
190 * - CL_HPP_ENABLE_SIZE_T_COMPATIBILITY
192 * Backward compatibility option to support cl.hpp-style size_t
193 * class. Replaces the updated std::array derived version and
194 * removal of size_t from the namespace. Note that in this case the
195 * new size_t class is placed in the cl::compatibility namespace and
196 * thus requires an additional using declaration for direct backward
199 * - CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY
201 * Enable older vector of pairs interface for construction of
204 * - CL_HPP_CL_1_2_DEFAULT_BUILD
206 * Default to OpenCL C 1.2 compilation rather than OpenCL C 2.0
207 * applies to use of cl::Program construction and other program
210 * - CL_HPP_USE_CL_SUB_GROUPS_KHR
212 * Enable the cl_khr_subgroups extension.
214 * - CL_HPP_USE_IL_KHR
216 * Enable the cl_khr_il_program extension.
219 * \section example Example
221 * The following example shows a general use case for the C++
222 * bindings, including support for the optional exception feature and
223 * also the supplied vector and string classes, see following sections for
224 * decriptions of these features.
227 #define CL_HPP_ENABLE_EXCEPTIONS
228 #define CL_HPP_TARGET_OPENCL_VERSION 200
230 #include <CL/cl2.hpp>
236 const int numElements = 32;
240 // Filter for a 2.0 platform and set it as the default
241 std::vector<cl::Platform> platforms;
242 cl::Platform::get(&platforms);
244 for (auto &p : platforms) {
245 std::string platver = p.getInfo<CL_PLATFORM_VERSION>();
246 if (platver.find("OpenCL 2.") != std::string::npos) {
251 std::cout << "No OpenCL 2.0 platform found.";
255 cl::Platform newP = cl::Platform::setDefault(plat);
257 std::cout << "Error setting default platform.";
261 // Use C++11 raw string literals for kernel source code
262 std::string kernel1{R"CLC(
264 kernel void updateGlobal()
269 std::string kernel2{R"CLC(
270 typedef struct { global int *bar; } Foo;
271 kernel void vectorAdd(global const Foo* aNum, global const int *inputA, global const int *inputB,
272 global int *output, int val, write_only pipe int outPipe, queue_t childQueue)
274 output[get_global_id(0)] = inputA[get_global_id(0)] + inputB[get_global_id(0)] + val + *(aNum->bar);
275 write_pipe(outPipe, &val);
276 queue_t default_queue = get_default_queue();
277 ndrange_t ndrange = ndrange_1D(get_global_size(0)/2, get_global_size(0)/2);
279 // Have a child kernel write into third quarter of output
280 enqueue_kernel(default_queue, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange,
282 output[get_global_size(0)*2 + get_global_id(0)] =
283 inputA[get_global_size(0)*2 + get_global_id(0)] + inputB[get_global_size(0)*2 + get_global_id(0)] + globalA;
286 // Have a child kernel write into last quarter of output
287 enqueue_kernel(childQueue, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange,
289 output[get_global_size(0)*3 + get_global_id(0)] =
290 inputA[get_global_size(0)*3 + get_global_id(0)] + inputB[get_global_size(0)*3 + get_global_id(0)] + globalA + 2;
295 // New simpler string interface style
296 std::vector<std::string> programStrings {kernel1, kernel2};
298 cl::Program vectorAddProgram(programStrings);
300 vectorAddProgram.build("-cl-std=CL2.0");
303 // Print build info for all devices
304 cl_int buildErr = CL_SUCCESS;
305 auto buildInfo = vectorAddProgram.getBuildInfo<CL_PROGRAM_BUILD_LOG>(&buildErr);
306 for (auto &pair : buildInfo) {
307 std::cerr << pair.second << std::endl << std::endl;
313 typedef struct { int *bar; } Foo;
315 // Get and run kernel that initializes the program-scope global
316 // A test for kernels that take no arguments
317 auto program2Kernel =
318 cl::KernelFunctor<>(vectorAddProgram, "updateGlobal");
326 auto anSVMInt = cl::allocate_svm<int, cl::SVMTraitCoarse<>>();
328 cl::SVMAllocator<Foo, cl::SVMTraitCoarse<cl::SVMTraitReadOnly<>>> svmAllocReadOnly;
329 auto fooPointer = cl::allocate_pointer<Foo>(svmAllocReadOnly);
330 fooPointer->bar = anSVMInt.get();
331 cl::SVMAllocator<int, cl::SVMTraitCoarse<>> svmAlloc;
332 std::vector<int, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>> inputA(numElements, 1, svmAlloc);
333 cl::coarse_svm_vector<int> inputB(numElements, 2, svmAlloc);
338 // Traditional cl_mem allocations
339 std::vector<int> output(numElements, 0xdeadbeef);
340 cl::Buffer outputBuffer(begin(output), end(output), false);
341 cl::Pipe aPipe(sizeof(cl_int), numElements / 2);
343 // Default command queue, also passed in as a parameter
344 cl::DeviceCommandQueue defaultDeviceQueue = cl::DeviceCommandQueue::makeDefault(
345 cl::Context::getDefault(), cl::Device::getDefault());
347 auto vectorAddKernel =
349 decltype(fooPointer)&,
351 cl::coarse_svm_vector<int>&,
355 cl::DeviceCommandQueue
356 >(vectorAddProgram, "vectorAdd");
358 // Ensure that the additional SVM pointer is available to the kernel
359 // This one was not passed as a parameter
360 vectorAddKernel.setSVMPointers(anSVMInt);
362 // Hand control of coarse allocations to runtime
363 cl::enqueueUnmapSVM(anSVMInt);
364 cl::enqueueUnmapSVM(fooPointer);
365 cl::unmapSVM(inputB);
366 cl::unmapSVM(output2);
371 cl::NDRange(numElements/2),
372 cl::NDRange(numElements/2)),
383 cl::copy(outputBuffer, begin(output), end(output));
384 // Grab the SVM output vector using a map
387 cl::Device d = cl::Device::getDefault();
389 std::cout << "Output:\n";
390 for (int i = 1; i < numElements; ++i) {
391 std::cout << "\t" << output[i] << "\n";
404 /* Handle deprecated preprocessor definitions. In each case, we only check for
405 * the old name if the new name is not defined, so that user code can define
406 * both and hence work with either version of the bindings.
408 #if !defined(CL_HPP_USE_DX_INTEROP) && defined(USE_DX_INTEROP)
409 # pragma message("cl2.hpp: USE_DX_INTEROP is deprecated. Define CL_HPP_USE_DX_INTEROP instead")
410 # define CL_HPP_USE_DX_INTEROP
412 #if !defined(CL_HPP_USE_CL_DEVICE_FISSION) && defined(USE_CL_DEVICE_FISSION)
413 # pragma message("cl2.hpp: USE_CL_DEVICE_FISSION is deprecated. Define CL_HPP_USE_CL_DEVICE_FISSION instead")
414 # define CL_HPP_USE_CL_DEVICE_FISSION
416 #if !defined(CL_HPP_ENABLE_EXCEPTIONS) && defined(__CL_ENABLE_EXCEPTIONS)
417 # pragma message("cl2.hpp: __CL_ENABLE_EXCEPTIONS is deprecated. Define CL_HPP_ENABLE_EXCEPTIONS instead")
418 # define CL_HPP_ENABLE_EXCEPTIONS
420 #if !defined(CL_HPP_NO_STD_VECTOR) && defined(__NO_STD_VECTOR)
421 # pragma message("cl2.hpp: __NO_STD_VECTOR is deprecated. Define CL_HPP_NO_STD_VECTOR instead")
422 # define CL_HPP_NO_STD_VECTOR
424 #if !defined(CL_HPP_NO_STD_STRING) && defined(__NO_STD_STRING)
425 # pragma message("cl2.hpp: __NO_STD_STRING is deprecated. Define CL_HPP_NO_STD_STRING instead")
426 # define CL_HPP_NO_STD_STRING
428 #if defined(VECTOR_CLASS)
429 # pragma message("cl2.hpp: VECTOR_CLASS is deprecated. Alias cl::vector instead")
431 #if defined(STRING_CLASS)
432 # pragma message("cl2.hpp: STRING_CLASS is deprecated. Alias cl::string instead.")
434 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) && defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
435 # pragma message("cl2.hpp: __CL_USER_OVERRIDE_ERROR_STRINGS is deprecated. Define CL_HPP_USER_OVERRIDE_ERROR_STRINGS instead")
436 # define CL_HPP_USER_OVERRIDE_ERROR_STRINGS
439 /* Warn about features that are no longer supported
441 #if defined(__USE_DEV_VECTOR)
442 # pragma message("cl2.hpp: __USE_DEV_VECTOR is no longer supported. Expect compilation errors")
444 #if defined(__USE_DEV_STRING)
445 # pragma message("cl2.hpp: __USE_DEV_STRING is no longer supported. Expect compilation errors")
448 /* Detect which version to target */
449 #if !defined(CL_HPP_TARGET_OPENCL_VERSION)
450 # pragma message("cl2.hpp: CL_HPP_TARGET_OPENCL_VERSION is not defined. It will default to 220 (OpenCL 2.2)")
451 # define CL_HPP_TARGET_OPENCL_VERSION 220
453 #if CL_HPP_TARGET_OPENCL_VERSION != 100 && \
454 CL_HPP_TARGET_OPENCL_VERSION != 110 && \
455 CL_HPP_TARGET_OPENCL_VERSION != 120 && \
456 CL_HPP_TARGET_OPENCL_VERSION != 200 && \
457 CL_HPP_TARGET_OPENCL_VERSION != 210 && \
458 CL_HPP_TARGET_OPENCL_VERSION != 220
459 # pragma message("cl2.hpp: CL_HPP_TARGET_OPENCL_VERSION is not a valid value (100, 110, 120, 200, 210 or 220). It will be set to 220")
460 # undef CL_HPP_TARGET_OPENCL_VERSION
461 # define CL_HPP_TARGET_OPENCL_VERSION 220
464 /* Forward target OpenCL version to C headers if necessary */
465 #if defined(CL_TARGET_OPENCL_VERSION)
466 /* Warn if prior definition of CL_TARGET_OPENCL_VERSION is lower than
467 * requested C++ bindings version */
468 #if CL_TARGET_OPENCL_VERSION < CL_HPP_TARGET_OPENCL_VERSION
469 # pragma message("CL_TARGET_OPENCL_VERSION is already defined as is lower than CL_HPP_TARGET_OPENCL_VERSION")
472 # define CL_TARGET_OPENCL_VERSION CL_HPP_TARGET_OPENCL_VERSION
475 #if !defined(CL_HPP_MINIMUM_OPENCL_VERSION)
476 # define CL_HPP_MINIMUM_OPENCL_VERSION 200
478 #if CL_HPP_MINIMUM_OPENCL_VERSION != 100 && \
479 CL_HPP_MINIMUM_OPENCL_VERSION != 110 && \
480 CL_HPP_MINIMUM_OPENCL_VERSION != 120 && \
481 CL_HPP_MINIMUM_OPENCL_VERSION != 200 && \
482 CL_HPP_MINIMUM_OPENCL_VERSION != 210 && \
483 CL_HPP_MINIMUM_OPENCL_VERSION != 220
484 # pragma message("cl2.hpp: CL_HPP_MINIMUM_OPENCL_VERSION is not a valid value (100, 110, 120, 200, 210 or 220). It will be set to 100")
485 # undef CL_HPP_MINIMUM_OPENCL_VERSION
486 # define CL_HPP_MINIMUM_OPENCL_VERSION 100
488 #if CL_HPP_MINIMUM_OPENCL_VERSION > CL_HPP_TARGET_OPENCL_VERSION
489 # error "CL_HPP_MINIMUM_OPENCL_VERSION must not be greater than CL_HPP_TARGET_OPENCL_VERSION"
492 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 100 && !defined(CL_USE_DEPRECATED_OPENCL_1_0_APIS)
493 # define CL_USE_DEPRECATED_OPENCL_1_0_APIS
495 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 110 && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
496 # define CL_USE_DEPRECATED_OPENCL_1_1_APIS
498 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 120 && !defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
499 # define CL_USE_DEPRECATED_OPENCL_1_2_APIS
501 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 200 && !defined(CL_USE_DEPRECATED_OPENCL_2_0_APIS)
502 # define CL_USE_DEPRECATED_OPENCL_2_0_APIS
504 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 210 && !defined(CL_USE_DEPRECATED_OPENCL_2_1_APIS)
505 # define CL_USE_DEPRECATED_OPENCL_2_1_APIS
507 #if CL_HPP_MINIMUM_OPENCL_VERSION <= 220 && !defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
508 # define CL_USE_DEPRECATED_OPENCL_2_2_APIS
515 #if defined(CL_HPP_USE_DX_INTEROP)
516 #include <CL/cl_d3d10.h>
517 #include <CL/cl_dx9_media_sharing.h>
521 #if defined(_MSC_VER)
525 // Check for a valid C++ version
527 // Need to do both tests here because for some reason __cplusplus is not
528 // updated in visual studio
529 #if (!defined(_MSC_VER) && __cplusplus < 201103L) || (defined(_MSC_VER) && _MSC_VER < 1700)
530 #error Visual studio 2013 or another C++11-supporting compiler required
534 #if defined(CL_HPP_USE_CL_DEVICE_FISSION) || defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)
535 #include <CL/cl_ext.h>
538 #if defined(__APPLE__) || defined(__MACOSX)
539 #include <OpenCL/opencl.h>
541 #include <CL/opencl.h>
544 #if (__cplusplus >= 201103L)
545 #define CL_HPP_NOEXCEPT_ noexcept
547 #define CL_HPP_NOEXCEPT_
550 #if defined(_MSC_VER)
551 # define CL_HPP_DEFINE_STATIC_MEMBER_ __declspec(selectany)
552 #elif defined(__MINGW32__)
553 # define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((selectany))
555 # define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((weak))
558 // Define deprecated prefixes and suffixes to ensure compilation
559 // in case they are not pre-defined
560 #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
561 #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
562 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
563 #if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED)
564 #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
565 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
567 #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED)
568 #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED
569 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED)
570 #if !defined(CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED)
571 #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED
572 #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_2_DEPRECATED)
574 #if !defined(CL_CALLBACK)
583 #include <functional>
586 // Define a size_type to represent a correctly resolved size_t
587 #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
589 using size_type = ::size_t;
591 #else // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
593 using size_type = size_t;
595 #endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
598 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
600 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
602 #if !defined(CL_HPP_NO_STD_VECTOR)
605 template < class T, class Alloc = std::allocator<T> >
606 using vector = std::vector<T, Alloc>;
608 #endif // #if !defined(CL_HPP_NO_STD_VECTOR)
610 #if !defined(CL_HPP_NO_STD_STRING)
613 using string = std::string;
615 #endif // #if !defined(CL_HPP_NO_STD_STRING)
617 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
619 #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
622 // Replace unique_ptr and allocate_pointer for internal use
623 // to allow user to replace them
624 template<class T, class D>
625 using pointer = std::unique_ptr<T, D>;
628 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
629 #if !defined(CL_HPP_NO_STD_ARRAY)
632 template < class T, size_type N >
633 using array = std::array<T, N>;
635 #endif // #if !defined(CL_HPP_NO_STD_ARRAY)
637 // Define size_type appropriately to allow backward-compatibility
638 // use of the old size_t interface class
639 #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
641 namespace compatibility {
642 /*! \brief class used to interface between C++ and
643 * OpenCL C calls that require arrays of size_t values, whose
644 * size is known statically.
653 //! \brief Initialize size_t to all 0s
656 for (int i = 0; i < N; ++i) {
661 size_t(const array<size_type, N> &rhs)
663 for (int i = 0; i < N; ++i) {
668 size_type& operator[](int index)
673 const size_type& operator[](int index) const
678 //! \brief Conversion operator to T*.
679 operator size_type* () { return data_; }
681 //! \brief Conversion operator to const T*.
682 operator const size_type* () const { return data_; }
684 operator array<size_type, N>() const
686 array<size_type, N> ret;
688 for (int i = 0; i < N; ++i) {
694 } // namespace compatibility
697 using size_t = compatibility::size_t<N>;
699 #endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
701 // Helper alias to avoid confusing the macros
704 using size_t_array = array<size_type, 3>;
705 } // namespace detail
711 * \brief The OpenCL C++ bindings are defined within this namespace.
717 #define CL_HPP_INIT_CL_EXT_FCN_PTR_(name) \
719 pfn_##name = (PFN_##name) \
720 clGetExtensionFunctionAddress(#name); \
725 #define CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, name) \
727 pfn_##name = (PFN_##name) \
728 clGetExtensionFunctionAddressForPlatform(platform, #name); \
737 class DeviceCommandQueue;
742 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
743 /*! \brief Exception class
745 * This may be thrown by API functions when CL_HPP_ENABLE_EXCEPTIONS is defined.
747 class Error : public std::exception
751 const char * errStr_;
753 /*! \brief Create a new CL error exception for a given error code
754 * and corresponding message.
756 * \param err error code value.
758 * \param errStr a descriptive string that must remain in scope until
759 * handling of the exception has concluded. If set, it
760 * will be returned by what().
762 Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr)
767 /*! \brief Get error string associated with exception
769 * \return A memory pointer to the error message string.
771 virtual const char * what() const throw ()
773 if (errStr_ == NULL) {
781 /*! \brief Get error code associated with exception
783 * \return The error code.
785 cl_int err(void) const { return err_; }
787 #define CL_HPP_ERR_STR_(x) #x
789 #define CL_HPP_ERR_STR_(x) NULL
790 #endif // CL_HPP_ENABLE_EXCEPTIONS
795 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
796 static inline cl_int errHandler (
798 const char * errStr = NULL)
800 if (err != CL_SUCCESS) {
801 throw Error(err, errStr);
806 static inline cl_int errHandler (cl_int err, const char * errStr = NULL)
808 (void) errStr; // suppress unused variable warning
811 #endif // CL_HPP_ENABLE_EXCEPTIONS
816 //! \cond DOXYGEN_DETAIL
817 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
818 #define __GET_DEVICE_INFO_ERR CL_HPP_ERR_STR_(clGetDeviceInfo)
819 #define __GET_PLATFORM_INFO_ERR CL_HPP_ERR_STR_(clGetPlatformInfo)
820 #define __GET_DEVICE_IDS_ERR CL_HPP_ERR_STR_(clGetDeviceIDs)
821 #define __GET_PLATFORM_IDS_ERR CL_HPP_ERR_STR_(clGetPlatformIDs)
822 #define __GET_CONTEXT_INFO_ERR CL_HPP_ERR_STR_(clGetContextInfo)
823 #define __GET_EVENT_INFO_ERR CL_HPP_ERR_STR_(clGetEventInfo)
824 #define __GET_EVENT_PROFILE_INFO_ERR CL_HPP_ERR_STR_(clGetEventProfileInfo)
825 #define __GET_MEM_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetMemObjectInfo)
826 #define __GET_IMAGE_INFO_ERR CL_HPP_ERR_STR_(clGetImageInfo)
827 #define __GET_SAMPLER_INFO_ERR CL_HPP_ERR_STR_(clGetSamplerInfo)
828 #define __GET_KERNEL_INFO_ERR CL_HPP_ERR_STR_(clGetKernelInfo)
829 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
830 #define __GET_KERNEL_ARG_INFO_ERR CL_HPP_ERR_STR_(clGetKernelArgInfo)
831 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
832 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
833 #define __GET_KERNEL_SUB_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelSubGroupInfo)
834 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
835 #define __GET_KERNEL_WORK_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelWorkGroupInfo)
836 #define __GET_PROGRAM_INFO_ERR CL_HPP_ERR_STR_(clGetProgramInfo)
837 #define __GET_PROGRAM_BUILD_INFO_ERR CL_HPP_ERR_STR_(clGetProgramBuildInfo)
838 #define __GET_COMMAND_QUEUE_INFO_ERR CL_HPP_ERR_STR_(clGetCommandQueueInfo)
840 #define __CREATE_CONTEXT_ERR CL_HPP_ERR_STR_(clCreateContext)
841 #define __CREATE_CONTEXT_FROM_TYPE_ERR CL_HPP_ERR_STR_(clCreateContextFromType)
842 #define __GET_SUPPORTED_IMAGE_FORMATS_ERR CL_HPP_ERR_STR_(clGetSupportedImageFormats)
844 #define __CREATE_BUFFER_ERR CL_HPP_ERR_STR_(clCreateBuffer)
845 #define __COPY_ERR CL_HPP_ERR_STR_(cl::copy)
846 #define __CREATE_SUBBUFFER_ERR CL_HPP_ERR_STR_(clCreateSubBuffer)
847 #define __CREATE_GL_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
848 #define __CREATE_GL_RENDER_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
849 #define __GET_GL_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetGLObjectInfo)
850 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
851 #define __CREATE_IMAGE_ERR CL_HPP_ERR_STR_(clCreateImage)
852 #define __CREATE_GL_TEXTURE_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture)
853 #define __IMAGE_DIMENSION_ERR CL_HPP_ERR_STR_(Incorrect image dimensions)
854 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
855 #define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR CL_HPP_ERR_STR_(clSetMemObjectDestructorCallback)
857 #define __CREATE_USER_EVENT_ERR CL_HPP_ERR_STR_(clCreateUserEvent)
858 #define __SET_USER_EVENT_STATUS_ERR CL_HPP_ERR_STR_(clSetUserEventStatus)
859 #define __SET_EVENT_CALLBACK_ERR CL_HPP_ERR_STR_(clSetEventCallback)
860 #define __WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clWaitForEvents)
862 #define __CREATE_KERNEL_ERR CL_HPP_ERR_STR_(clCreateKernel)
863 #define __SET_KERNEL_ARGS_ERR CL_HPP_ERR_STR_(clSetKernelArg)
864 #define __CREATE_PROGRAM_WITH_SOURCE_ERR CL_HPP_ERR_STR_(clCreateProgramWithSource)
865 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
866 #define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
867 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
868 #define __CREATE_PROGRAM_WITH_BINARY_ERR CL_HPP_ERR_STR_(clCreateProgramWithBinary)
869 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
870 #define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
871 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
872 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
873 #define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR CL_HPP_ERR_STR_(clCreateProgramWithBuiltInKernels)
874 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
875 #define __BUILD_PROGRAM_ERR CL_HPP_ERR_STR_(clBuildProgram)
876 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
877 #define __COMPILE_PROGRAM_ERR CL_HPP_ERR_STR_(clCompileProgram)
878 #define __LINK_PROGRAM_ERR CL_HPP_ERR_STR_(clLinkProgram)
879 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
880 #define __CREATE_KERNELS_IN_PROGRAM_ERR CL_HPP_ERR_STR_(clCreateKernelsInProgram)
882 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
883 #define __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateCommandQueueWithProperties)
884 #define __CREATE_SAMPLER_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateSamplerWithProperties)
885 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
886 #define __SET_COMMAND_QUEUE_PROPERTY_ERR CL_HPP_ERR_STR_(clSetCommandQueueProperty)
887 #define __ENQUEUE_READ_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueReadBuffer)
888 #define __ENQUEUE_READ_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueReadBufferRect)
889 #define __ENQUEUE_WRITE_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueWriteBuffer)
890 #define __ENQUEUE_WRITE_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueWriteBufferRect)
891 #define __ENQEUE_COPY_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyBuffer)
892 #define __ENQEUE_COPY_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferRect)
893 #define __ENQUEUE_FILL_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueFillBuffer)
894 #define __ENQUEUE_READ_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueReadImage)
895 #define __ENQUEUE_WRITE_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueWriteImage)
896 #define __ENQUEUE_COPY_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyImage)
897 #define __ENQUEUE_FILL_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueFillImage)
898 #define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyImageToBuffer)
899 #define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferToImage)
900 #define __ENQUEUE_MAP_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueMapBuffer)
901 #define __ENQUEUE_MAP_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueMapImage)
902 #define __ENQUEUE_UNMAP_MEM_OBJECT_ERR CL_HPP_ERR_STR_(clEnqueueUnMapMemObject)
903 #define __ENQUEUE_NDRANGE_KERNEL_ERR CL_HPP_ERR_STR_(clEnqueueNDRangeKernel)
904 #define __ENQUEUE_NATIVE_KERNEL CL_HPP_ERR_STR_(clEnqueueNativeKernel)
905 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
906 #define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR CL_HPP_ERR_STR_(clEnqueueMigrateMemObjects)
907 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
908 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
909 #define __ENQUEUE_MIGRATE_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMMigrateMem)
910 #define __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clSetDefaultDeviceCommandQueue)
911 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
914 #define __ENQUEUE_ACQUIRE_GL_ERR CL_HPP_ERR_STR_(clEnqueueAcquireGLObjects)
915 #define __ENQUEUE_RELEASE_GL_ERR CL_HPP_ERR_STR_(clEnqueueReleaseGLObjects)
917 #define __CREATE_PIPE_ERR CL_HPP_ERR_STR_(clCreatePipe)
918 #define __GET_PIPE_INFO_ERR CL_HPP_ERR_STR_(clGetPipeInfo)
921 #define __RETAIN_ERR CL_HPP_ERR_STR_(Retain Object)
922 #define __RELEASE_ERR CL_HPP_ERR_STR_(Release Object)
923 #define __FLUSH_ERR CL_HPP_ERR_STR_(clFlush)
924 #define __FINISH_ERR CL_HPP_ERR_STR_(clFinish)
925 #define __VECTOR_CAPACITY_ERR CL_HPP_ERR_STR_(Vector capacity error)
927 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
928 #define __GET_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetHostTimer)
929 #define __GET_DEVICE_AND_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetDeviceAndHostTimer)
931 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
932 #define __SET_PROGRAM_RELEASE_CALLBACK_ERR CL_HPP_ERR_STR_(clSetProgramReleaseCallback)
933 #define __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR CL_HPP_ERR_STR_(clSetProgramSpecializationConstant)
938 * CL 1.2 version that uses device fission.
940 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
941 #define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevices)
943 #define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevicesEXT)
944 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
947 * Deprecated APIs for 1.2
949 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
950 #define __ENQUEUE_MARKER_ERR CL_HPP_ERR_STR_(clEnqueueMarker)
951 #define __ENQUEUE_WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clEnqueueWaitForEvents)
952 #define __ENQUEUE_BARRIER_ERR CL_HPP_ERR_STR_(clEnqueueBarrier)
953 #define __UNLOAD_COMPILER_ERR CL_HPP_ERR_STR_(clUnloadCompiler)
954 #define __CREATE_GL_TEXTURE_2D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture2D)
955 #define __CREATE_GL_TEXTURE_3D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture3D)
956 #define __CREATE_IMAGE2D_ERR CL_HPP_ERR_STR_(clCreateImage2D)
957 #define __CREATE_IMAGE3D_ERR CL_HPP_ERR_STR_(clCreateImage3D)
958 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
961 * Deprecated APIs for 2.0
963 #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
964 #define __CREATE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clCreateCommandQueue)
965 #define __ENQUEUE_TASK_ERR CL_HPP_ERR_STR_(clEnqueueTask)
966 #define __CREATE_SAMPLER_ERR CL_HPP_ERR_STR_(clCreateSampler)
967 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
970 * CL 1.2 marker and barrier commands
972 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
973 #define __ENQUEUE_MARKER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueMarkerWithWaitList)
974 #define __ENQUEUE_BARRIER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueBarrierWithWaitList)
975 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
977 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
978 #define __CLONE_KERNEL_ERR CL_HPP_ERR_STR_(clCloneKernel)
979 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
981 #endif // CL_HPP_USER_OVERRIDE_ERROR_STRINGS
987 // Generic getInfoHelper. The final parameter is used to guide overload
988 // resolution: the actual parameter passed is an int, which makes this
989 // a worse conversion sequence than a specialization that declares the
990 // parameter as an int.
991 template<typename Functor, typename T>
992 inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long)
994 return f(name, sizeof(T), param, NULL);
997 // Specialized for getInfo<CL_PROGRAM_BINARIES>
998 // Assumes that the output vector was correctly resized on the way in
999 template <typename Func>
1000 inline cl_int getInfoHelper(Func f, cl_uint name, vector<vector<unsigned char>>* param, int)
1002 if (name != CL_PROGRAM_BINARIES) {
1003 return CL_INVALID_VALUE;
1006 // Create array of pointers, calculate total size and pass pointer array in
1007 size_type numBinaries = param->size();
1008 vector<unsigned char*> binariesPointers(numBinaries);
1010 for (size_type i = 0; i < numBinaries; ++i)
1012 binariesPointers[i] = (*param)[i].data();
1015 cl_int err = f(name, numBinaries * sizeof(unsigned char*), binariesPointers.data(), NULL);
1017 if (err != CL_SUCCESS) {
1026 // Specialized getInfoHelper for vector params
1027 template <typename Func, typename T>
1028 inline cl_int getInfoHelper(Func f, cl_uint name, vector<T>* param, long)
1031 cl_int err = f(name, 0, NULL, &required);
1032 if (err != CL_SUCCESS) {
1035 const size_type elements = required / sizeof(T);
1037 // Temporary to avoid changing param on an error
1038 vector<T> localData(elements);
1039 err = f(name, required, localData.data(), NULL);
1040 if (err != CL_SUCCESS) {
1044 *param = std::move(localData);
1050 /* Specialization for reference-counted types. This depends on the
1051 * existence of Wrapper<T>::cl_type, and none of the other types having the
1052 * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1053 * does not work, because when using a derived type (e.g. Context) the generic
1054 * template will provide a better match.
1056 template <typename Func, typename T>
1057 inline cl_int getInfoHelper(
1058 Func f, cl_uint name, vector<T>* param, int, typename T::cl_type = 0)
1061 cl_int err = f(name, 0, NULL, &required);
1062 if (err != CL_SUCCESS) {
1066 const size_type elements = required / sizeof(typename T::cl_type);
1068 vector<typename T::cl_type> value(elements);
1069 err = f(name, required, value.data(), NULL);
1070 if (err != CL_SUCCESS) {
1075 // Assign to convert CL type to T for each element
1076 param->resize(elements);
1078 // Assign to param, constructing with retain behaviour
1079 // to correctly capture each underlying CL object
1080 for (size_type i = 0; i < elements; i++) {
1081 (*param)[i] = T(value[i], true);
1087 // Specialized GetInfoHelper for string params
1088 template <typename Func>
1089 inline cl_int getInfoHelper(Func f, cl_uint name, string* param, long)
1092 cl_int err = f(name, 0, NULL, &required);
1093 if (err != CL_SUCCESS) {
1097 // std::string has a constant data member
1098 // a char vector does not
1100 vector<char> value(required);
1101 err = f(name, required, value.data(), NULL);
1102 if (err != CL_SUCCESS) {
1106 param->assign(begin(value), prev(end(value)));
1115 // Specialized GetInfoHelper for clsize_t params
1116 template <typename Func, size_type N>
1117 inline cl_int getInfoHelper(Func f, cl_uint name, array<size_type, N>* param, long)
1120 cl_int err = f(name, 0, NULL, &required);
1121 if (err != CL_SUCCESS) {
1125 size_type elements = required / sizeof(size_type);
1126 vector<size_type> value(elements, 0);
1128 err = f(name, required, value.data(), NULL);
1129 if (err != CL_SUCCESS) {
1133 // Bound the copy with N to prevent overruns
1134 // if passed N > than the amount copied
1138 for (size_type i = 0; i < elements; ++i) {
1139 (*param)[i] = value[i];
1145 template<typename T> struct ReferenceHandler;
1147 /* Specialization for reference-counted types. This depends on the
1148 * existence of Wrapper<T>::cl_type, and none of the other types having the
1149 * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1150 * does not work, because when using a derived type (e.g. Context) the generic
1151 * template will provide a better match.
1153 template<typename Func, typename T>
1154 inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0)
1156 typename T::cl_type value;
1157 cl_int err = f(name, sizeof(value), &value, NULL);
1158 if (err != CL_SUCCESS) {
1164 err = param->retain();
1165 if (err != CL_SUCCESS) {
1172 #define CL_HPP_PARAM_NAME_INFO_1_0_(F) \
1173 F(cl_platform_info, CL_PLATFORM_PROFILE, string) \
1174 F(cl_platform_info, CL_PLATFORM_VERSION, string) \
1175 F(cl_platform_info, CL_PLATFORM_NAME, string) \
1176 F(cl_platform_info, CL_PLATFORM_VENDOR, string) \
1177 F(cl_platform_info, CL_PLATFORM_EXTENSIONS, string) \
1179 F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
1180 F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
1181 F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
1182 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
1183 F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, size_type) \
1184 F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, cl::vector<size_type>) \
1185 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
1186 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
1187 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
1188 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
1189 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
1190 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
1191 F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
1192 F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \
1193 F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
1194 F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
1195 F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
1196 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, size_type) \
1197 F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, size_type) \
1198 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, size_type) \
1199 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, size_type) \
1200 F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, size_type) \
1201 F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \
1202 F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, size_type) \
1203 F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
1204 F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
1205 F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
1206 F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
1207 F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
1208 F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
1209 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
1210 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
1211 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
1212 F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
1213 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
1214 F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
1215 F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
1216 F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
1217 F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
1218 F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, size_type) \
1219 F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
1220 F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
1221 F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
1222 F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
1223 F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
1224 F(cl_device_info, CL_DEVICE_NAME, string) \
1225 F(cl_device_info, CL_DEVICE_VENDOR, string) \
1226 F(cl_device_info, CL_DRIVER_VERSION, string) \
1227 F(cl_device_info, CL_DEVICE_PROFILE, string) \
1228 F(cl_device_info, CL_DEVICE_VERSION, string) \
1229 F(cl_device_info, CL_DEVICE_EXTENSIONS, string) \
1231 F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
1232 F(cl_context_info, CL_CONTEXT_DEVICES, cl::vector<Device>) \
1233 F(cl_context_info, CL_CONTEXT_PROPERTIES, cl::vector<cl_context_properties>) \
1235 F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
1236 F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
1237 F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
1238 F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \
1240 F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
1241 F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
1242 F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
1243 F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
1245 F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
1246 F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
1247 F(cl_mem_info, CL_MEM_SIZE, size_type) \
1248 F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
1249 F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
1250 F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
1251 F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
1253 F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
1254 F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, size_type) \
1255 F(cl_image_info, CL_IMAGE_ROW_PITCH, size_type) \
1256 F(cl_image_info, CL_IMAGE_SLICE_PITCH, size_type) \
1257 F(cl_image_info, CL_IMAGE_WIDTH, size_type) \
1258 F(cl_image_info, CL_IMAGE_HEIGHT, size_type) \
1259 F(cl_image_info, CL_IMAGE_DEPTH, size_type) \
1261 F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
1262 F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
1263 F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \
1264 F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \
1265 F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \
1267 F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
1268 F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
1269 F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
1270 F(cl_program_info, CL_PROGRAM_DEVICES, cl::vector<Device>) \
1271 F(cl_program_info, CL_PROGRAM_SOURCE, string) \
1272 F(cl_program_info, CL_PROGRAM_BINARY_SIZES, cl::vector<size_type>) \
1273 F(cl_program_info, CL_PROGRAM_BINARIES, cl::vector<cl::vector<unsigned char>>) \
1275 F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
1276 F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, string) \
1277 F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, string) \
1279 F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, string) \
1280 F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
1281 F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
1282 F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
1283 F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
1285 F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, size_type) \
1286 F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::detail::size_t_array) \
1287 F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
1289 F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
1290 F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
1291 F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
1292 F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
1295 #define CL_HPP_PARAM_NAME_INFO_1_1_(F) \
1296 F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
1297 F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
1298 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
1299 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
1300 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
1301 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
1302 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
1303 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
1304 F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
1305 F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, string) \
1307 F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
1308 F(cl_mem_info, CL_MEM_OFFSET, size_type) \
1310 F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1311 F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
1313 F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
1315 #define CL_HPP_PARAM_NAME_INFO_1_2_(F) \
1316 F(cl_program_info, CL_PROGRAM_NUM_KERNELS, size_type) \
1317 F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, string) \
1319 F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \
1321 F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, string) \
1323 F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \
1324 F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \
1325 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, string) \
1326 F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, string) \
1327 F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \
1329 F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl::Device) \
1330 F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, cl::vector<cl_device_partition_property>) \
1331 F(cl_device_info, CL_DEVICE_PARTITION_TYPE, cl::vector<cl_device_partition_property>) \
1332 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \
1333 F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, size_type) \
1334 F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \
1335 F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, string) \
1337 F(cl_image_info, CL_IMAGE_ARRAY_SIZE, size_type) \
1338 F(cl_image_info, CL_IMAGE_NUM_MIP_LEVELS, cl_uint) \
1339 F(cl_image_info, CL_IMAGE_NUM_SAMPLES, cl_uint)
1341 #define CL_HPP_PARAM_NAME_INFO_2_0_(F) \
1342 F(cl_device_info, CL_DEVICE_QUEUE_ON_HOST_PROPERTIES, cl_command_queue_properties) \
1343 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES, cl_command_queue_properties) \
1344 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, cl_uint) \
1345 F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, cl_uint) \
1346 F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_QUEUES, cl_uint) \
1347 F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_EVENTS, cl_uint) \
1348 F(cl_device_info, CL_DEVICE_MAX_PIPE_ARGS, cl_uint) \
1349 F(cl_device_info, CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS, cl_uint) \
1350 F(cl_device_info, CL_DEVICE_PIPE_MAX_PACKET_SIZE, cl_uint) \
1351 F(cl_device_info, CL_DEVICE_SVM_CAPABILITIES, cl_device_svm_capabilities) \
1352 F(cl_device_info, CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT, cl_uint) \
1353 F(cl_device_info, CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT, cl_uint) \
1354 F(cl_device_info, CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT, cl_uint) \
1355 F(cl_command_queue_info, CL_QUEUE_SIZE, cl_uint) \
1356 F(cl_mem_info, CL_MEM_USES_SVM_POINTER, cl_bool) \
1357 F(cl_program_build_info, CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, size_type) \
1358 F(cl_pipe_info, CL_PIPE_PACKET_SIZE, cl_uint) \
1359 F(cl_pipe_info, CL_PIPE_MAX_PACKETS, cl_uint)
1361 #define CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(F) \
1362 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR, size_type) \
1363 F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR, size_type)
1365 #define CL_HPP_PARAM_NAME_INFO_IL_KHR_(F) \
1366 F(cl_device_info, CL_DEVICE_IL_VERSION_KHR, string) \
1367 F(cl_program_info, CL_PROGRAM_IL_KHR, cl::vector<unsigned char>)
1369 #define CL_HPP_PARAM_NAME_INFO_2_1_(F) \
1370 F(cl_platform_info, CL_PLATFORM_HOST_TIMER_RESOLUTION, size_type) \
1371 F(cl_program_info, CL_PROGRAM_IL, cl::vector<unsigned char>) \
1372 F(cl_kernel_info, CL_KERNEL_MAX_NUM_SUB_GROUPS, size_type) \
1373 F(cl_kernel_info, CL_KERNEL_COMPILE_NUM_SUB_GROUPS, size_type) \
1374 F(cl_device_info, CL_DEVICE_MAX_NUM_SUB_GROUPS, cl_uint) \
1375 F(cl_device_info, CL_DEVICE_IL_VERSION, string) \
1376 F(cl_device_info, CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS, cl_bool) \
1377 F(cl_command_queue_info, CL_QUEUE_DEVICE_DEFAULT, cl::DeviceCommandQueue) \
1378 F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE, size_type) \
1379 F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE, size_type) \
1380 F(cl_kernel_sub_group_info, CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT, cl::detail::size_t_array)
1382 #define CL_HPP_PARAM_NAME_INFO_2_2_(F) \
1383 F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_CTORS_PRESENT, cl_bool) \
1384 F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_DTORS_PRESENT, cl_bool)
1386 #define CL_HPP_PARAM_NAME_DEVICE_FISSION_(F) \
1387 F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
1388 F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, cl::vector<cl_device_partition_property_ext>) \
1389 F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, cl::vector<cl_device_partition_property_ext>) \
1390 F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
1391 F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, cl::vector<cl_device_partition_property_ext>)
1393 template <typename enum_type, cl_int Name>
1394 struct param_traits {};
1396 #define CL_HPP_DECLARE_PARAM_TRAITS_(token, param_name, T) \
1399 struct param_traits<detail:: token,param_name> \
1401 enum { value = param_name }; \
1402 typedef T param_type; \
1405 CL_HPP_PARAM_NAME_INFO_1_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1406 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
1407 CL_HPP_PARAM_NAME_INFO_1_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1408 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
1409 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1410 CL_HPP_PARAM_NAME_INFO_1_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1411 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1412 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
1413 CL_HPP_PARAM_NAME_INFO_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1414 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
1415 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
1416 CL_HPP_PARAM_NAME_INFO_2_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1417 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
1418 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
1419 CL_HPP_PARAM_NAME_INFO_2_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1420 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
1422 #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1423 CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1424 #endif // #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1426 #if defined(CL_HPP_USE_IL_KHR)
1427 CL_HPP_PARAM_NAME_INFO_IL_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1428 #endif // #if defined(CL_HPP_USE_IL_KHR)
1431 // Flags deprecated in OpenCL 2.0
1432 #define CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(F) \
1433 F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties)
1435 #define CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(F) \
1436 F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool)
1438 #define CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(F) \
1439 F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer)
1441 // Include deprecated query flags based on versions
1442 // Only include deprecated 1.0 flags if 2.0 not active as there is an enum clash
1443 #if CL_HPP_TARGET_OPENCL_VERSION > 100 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 && CL_HPP_TARGET_OPENCL_VERSION < 200
1444 CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1445 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 110
1446 #if CL_HPP_TARGET_OPENCL_VERSION > 110 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1447 CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1448 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1449 #if CL_HPP_TARGET_OPENCL_VERSION > 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1450 CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1451 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
1453 #if defined(CL_HPP_USE_CL_DEVICE_FISSION)
1454 CL_HPP_PARAM_NAME_DEVICE_FISSION_(CL_HPP_DECLARE_PARAM_TRAITS_);
1455 #endif // CL_HPP_USE_CL_DEVICE_FISSION
1457 #ifdef CL_PLATFORM_ICD_SUFFIX_KHR
1458 CL_HPP_DECLARE_PARAM_TRAITS_(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, string)
1461 #ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
1462 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong)
1465 #ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
1466 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, vector<size_type>)
1468 #ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
1469 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint)
1471 #ifdef CL_DEVICE_SIMD_WIDTH_AMD
1472 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint)
1474 #ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD
1475 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint)
1477 #ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD
1478 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint)
1480 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
1481 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint)
1483 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
1484 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint)
1486 #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
1487 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint)
1489 #ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
1490 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint)
1492 #ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
1493 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint)
1496 #ifdef CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM
1497 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM, cl_ulong)
1499 #ifdef CL_DEVICE_JOB_SLOTS_ARM
1500 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_JOB_SLOTS_ARM, cl_uint)
1503 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
1504 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint)
1506 #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV
1507 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint)
1509 #ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV
1510 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint)
1512 #ifdef CL_DEVICE_WARP_SIZE_NV
1513 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint)
1515 #ifdef CL_DEVICE_GPU_OVERLAP_NV
1516 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool)
1518 #ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV
1519 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool)
1521 #ifdef CL_DEVICE_INTEGRATED_MEMORY_NV
1522 CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool)
1525 // Convenience functions
1527 template <typename Func, typename T>
1529 getInfo(Func f, cl_uint name, T* param)
1531 return getInfoHelper(f, name, param, 0);
1534 template <typename Func, typename Arg0>
1535 struct GetInfoFunctor0
1537 Func f_; const Arg0& arg0_;
1539 cl_uint param, size_type size, void* value, size_type* size_ret)
1540 { return f_(arg0_, param, size, value, size_ret); }
1543 template <typename Func, typename Arg0, typename Arg1>
1544 struct GetInfoFunctor1
1546 Func f_; const Arg0& arg0_; const Arg1& arg1_;
1548 cl_uint param, size_type size, void* value, size_type* size_ret)
1549 { return f_(arg0_, arg1_, param, size, value, size_ret); }
1552 template <typename Func, typename Arg0, typename T>
1554 getInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
1556 GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
1557 return getInfoHelper(f0, name, param, 0);
1560 template <typename Func, typename Arg0, typename Arg1, typename T>
1562 getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
1564 GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
1565 return getInfoHelper(f0, name, param, 0);
1569 template<typename T>
1570 struct ReferenceHandler
1573 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1575 * OpenCL 1.2 devices do have retain/release.
1578 struct ReferenceHandler<cl_device_id>
1581 * Retain the device.
1582 * \param device A valid device created using createSubDevices
1584 * CL_SUCCESS if the function executed successfully.
1585 * CL_INVALID_DEVICE if device was not a valid subdevice
1586 * CL_OUT_OF_RESOURCES
1587 * CL_OUT_OF_HOST_MEMORY
1589 static cl_int retain(cl_device_id device)
1590 { return ::clRetainDevice(device); }
1592 * Retain the device.
1593 * \param device A valid device created using createSubDevices
1595 * CL_SUCCESS if the function executed successfully.
1596 * CL_INVALID_DEVICE if device was not a valid subdevice
1597 * CL_OUT_OF_RESOURCES
1598 * CL_OUT_OF_HOST_MEMORY
1600 static cl_int release(cl_device_id device)
1601 { return ::clReleaseDevice(device); }
1603 #else // CL_HPP_TARGET_OPENCL_VERSION >= 120
1605 * OpenCL 1.1 devices do not have retain/release.
1608 struct ReferenceHandler<cl_device_id>
1610 // cl_device_id does not have retain().
1611 static cl_int retain(cl_device_id)
1612 { return CL_SUCCESS; }
1613 // cl_device_id does not have release().
1614 static cl_int release(cl_device_id)
1615 { return CL_SUCCESS; }
1617 #endif // ! (CL_HPP_TARGET_OPENCL_VERSION >= 120)
1620 struct ReferenceHandler<cl_platform_id>
1622 // cl_platform_id does not have retain().
1623 static cl_int retain(cl_platform_id)
1624 { return CL_SUCCESS; }
1625 // cl_platform_id does not have release().
1626 static cl_int release(cl_platform_id)
1627 { return CL_SUCCESS; }
1631 struct ReferenceHandler<cl_context>
1633 static cl_int retain(cl_context context)
1634 { return ::clRetainContext(context); }
1635 static cl_int release(cl_context context)
1636 { return ::clReleaseContext(context); }
1640 struct ReferenceHandler<cl_command_queue>
1642 static cl_int retain(cl_command_queue queue)
1643 { return ::clRetainCommandQueue(queue); }
1644 static cl_int release(cl_command_queue queue)
1645 { return ::clReleaseCommandQueue(queue); }
1649 struct ReferenceHandler<cl_mem>
1651 static cl_int retain(cl_mem memory)
1652 { return ::clRetainMemObject(memory); }
1653 static cl_int release(cl_mem memory)
1654 { return ::clReleaseMemObject(memory); }
1658 struct ReferenceHandler<cl_sampler>
1660 static cl_int retain(cl_sampler sampler)
1661 { return ::clRetainSampler(sampler); }
1662 static cl_int release(cl_sampler sampler)
1663 { return ::clReleaseSampler(sampler); }
1667 struct ReferenceHandler<cl_program>
1669 static cl_int retain(cl_program program)
1670 { return ::clRetainProgram(program); }
1671 static cl_int release(cl_program program)
1672 { return ::clReleaseProgram(program); }
1676 struct ReferenceHandler<cl_kernel>
1678 static cl_int retain(cl_kernel kernel)
1679 { return ::clRetainKernel(kernel); }
1680 static cl_int release(cl_kernel kernel)
1681 { return ::clReleaseKernel(kernel); }
1685 struct ReferenceHandler<cl_event>
1687 static cl_int retain(cl_event event)
1688 { return ::clRetainEvent(event); }
1689 static cl_int release(cl_event event)
1690 { return ::clReleaseEvent(event); }
1694 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1695 // Extracts version number with major in the upper 16 bits, minor in the lower 16
1696 static cl_uint getVersion(const vector<char> &versionInfo)
1698 int highVersion = 0;
1701 while(versionInfo[index] != '.' ) {
1703 highVersion += versionInfo[index]-'0';
1707 while(versionInfo[index] != ' ' && versionInfo[index] != '\0') {
1709 lowVersion += versionInfo[index]-'0';
1712 return (highVersion << 16) | lowVersion;
1715 static cl_uint getPlatformVersion(cl_platform_id platform)
1718 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size);
1720 vector<char> versionInfo(size);
1721 clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, versionInfo.data(), &size);
1722 return getVersion(versionInfo);
1725 static cl_uint getDevicePlatformVersion(cl_device_id device)
1727 cl_platform_id platform;
1728 clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL);
1729 return getPlatformVersion(platform);
1732 static cl_uint getContextPlatformVersion(cl_context context)
1734 // The platform cannot be queried directly, so we first have to grab a
1735 // device and obtain its context
1737 clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size);
1740 vector<cl_device_id> devices(size/sizeof(cl_device_id));
1741 clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices.data(), NULL);
1742 return getDevicePlatformVersion(devices[0]);
1744 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1746 template <typename T>
1756 Wrapper() : object_(NULL) { }
1758 Wrapper(const cl_type &obj, bool retainObject) : object_(obj)
1761 detail::errHandler(retain(), __RETAIN_ERR);
1767 if (object_ != NULL) { release(); }
1770 Wrapper(const Wrapper<cl_type>& rhs)
1772 object_ = rhs.object_;
1773 detail::errHandler(retain(), __RETAIN_ERR);
1776 Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT_
1778 object_ = rhs.object_;
1782 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
1785 detail::errHandler(release(), __RELEASE_ERR);
1786 object_ = rhs.object_;
1787 detail::errHandler(retain(), __RETAIN_ERR);
1792 Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
1795 detail::errHandler(release(), __RELEASE_ERR);
1796 object_ = rhs.object_;
1802 Wrapper<cl_type>& operator = (const cl_type &rhs)
1804 detail::errHandler(release(), __RELEASE_ERR);
1809 const cl_type& operator ()() const { return object_; }
1811 cl_type& operator ()() { return object_; }
1813 cl_type get() const { return object_; }
1816 template<typename Func, typename U>
1817 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
1819 cl_int retain() const
1821 if (object_ != nullptr) {
1822 return ReferenceHandler<cl_type>::retain(object_);
1829 cl_int release() const
1831 if (object_ != nullptr) {
1832 return ReferenceHandler<cl_type>::release(object_);
1841 class Wrapper<cl_device_id>
1844 typedef cl_device_id cl_type;
1848 bool referenceCountable_;
1850 static bool isReferenceCountable(cl_device_id device)
1852 bool retVal = false;
1853 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1854 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
1855 if (device != NULL) {
1856 int version = getDevicePlatformVersion(device);
1857 if(version > ((1 << 16) + 1)) {
1861 #else // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1863 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1864 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1869 Wrapper() : object_(NULL), referenceCountable_(false)
1873 Wrapper(const cl_type &obj, bool retainObject) :
1875 referenceCountable_(false)
1877 referenceCountable_ = isReferenceCountable(obj);
1880 detail::errHandler(retain(), __RETAIN_ERR);
1889 Wrapper(const Wrapper<cl_type>& rhs)
1891 object_ = rhs.object_;
1892 referenceCountable_ = isReferenceCountable(object_);
1893 detail::errHandler(retain(), __RETAIN_ERR);
1896 Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT_
1898 object_ = rhs.object_;
1899 referenceCountable_ = rhs.referenceCountable_;
1901 rhs.referenceCountable_ = false;
1904 Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
1907 detail::errHandler(release(), __RELEASE_ERR);
1908 object_ = rhs.object_;
1909 referenceCountable_ = rhs.referenceCountable_;
1910 detail::errHandler(retain(), __RETAIN_ERR);
1915 Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
1918 detail::errHandler(release(), __RELEASE_ERR);
1919 object_ = rhs.object_;
1920 referenceCountable_ = rhs.referenceCountable_;
1922 rhs.referenceCountable_ = false;
1927 Wrapper<cl_type>& operator = (const cl_type &rhs)
1929 detail::errHandler(release(), __RELEASE_ERR);
1931 referenceCountable_ = isReferenceCountable(object_);
1935 const cl_type& operator ()() const { return object_; }
1937 cl_type& operator ()() { return object_; }
1939 cl_type get() const { return object_; }
1942 template<typename Func, typename U>
1943 friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
1945 template<typename Func, typename U>
1946 friend inline cl_int getInfoHelper(Func, cl_uint, vector<U>*, int, typename U::cl_type);
1948 cl_int retain() const
1950 if( object_ != nullptr && referenceCountable_ ) {
1951 return ReferenceHandler<cl_type>::retain(object_);
1958 cl_int release() const
1960 if (object_ != nullptr && referenceCountable_) {
1961 return ReferenceHandler<cl_type>::release(object_);
1969 template <typename T>
1970 inline bool operator==(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
1972 return lhs() == rhs();
1975 template <typename T>
1976 inline bool operator!=(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
1978 return !operator==(lhs, rhs);
1981 } // namespace detail
1985 using BuildLogType = vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, CL_PROGRAM_BUILD_LOG>::param_type>>;
1986 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
1988 * Exception class for build errors to carry build info
1990 class BuildError : public Error
1993 BuildLogType buildLogs;
1995 BuildError(cl_int err, const char * errStr, const BuildLogType &vec) : Error(err, errStr), buildLogs(vec)
1999 BuildLogType getBuildLog() const
2005 static inline cl_int buildErrHandler(
2007 const char * errStr,
2008 const BuildLogType &buildLogs)
2010 if (err != CL_SUCCESS) {
2011 throw BuildError(err, errStr, buildLogs);
2015 } // namespace detail
2019 static inline cl_int buildErrHandler(
2021 const char * errStr,
2022 const BuildLogType &buildLogs)
2024 (void)buildLogs; // suppress unused variable warning
2028 } // namespace detail
2029 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2032 /*! \stuct ImageFormat
2033 * \brief Adds constructors and member functions for cl_image_format.
2035 * \see cl_image_format
2037 struct ImageFormat : public cl_image_format
2039 //! \brief Default constructor - performs no initialization.
2042 //! \brief Initializing constructor.
2043 ImageFormat(cl_channel_order order, cl_channel_type type)
2045 image_channel_order = order;
2046 image_channel_data_type = type;
2049 //! \brief Assignment operator.
2050 ImageFormat& operator = (const ImageFormat& rhs)
2053 this->image_channel_data_type = rhs.image_channel_data_type;
2054 this->image_channel_order = rhs.image_channel_order;
2060 /*! \brief Class interface for cl_device_id.
2062 * \note Copies of these objects are inexpensive, since they don't 'own'
2063 * any underlying resources or data structures.
2067 class Device : public detail::Wrapper<cl_device_id>
2070 static std::once_flag default_initialized_;
2071 static Device default_;
2072 static cl_int default_error_;
2074 /*! \brief Create the default context.
2076 * This sets @c default_ and @c default_error_. It does not throw
2079 static void makeDefault();
2081 /*! \brief Create the default platform from a provided platform.
2083 * This sets @c default_. It does not throw
2086 static void makeDefaultProvided(const Device &p) {
2091 #ifdef CL_HPP_UNIT_TEST_ENABLE
2092 /*! \brief Reset the default.
2094 * This sets @c default_ to an empty value to support cleanup in
2095 * the unit test framework.
2096 * This function is not thread safe.
2098 static void unitTestClearDefault() {
2099 default_ = Device();
2101 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2103 //! \brief Default constructor - initializes to NULL.
2104 Device() : detail::Wrapper<cl_type>() { }
2106 /*! \brief Constructor from cl_device_id.
2108 * This simply copies the device ID value, which is an inexpensive operation.
2110 explicit Device(const cl_device_id &device, bool retainObject = false) :
2111 detail::Wrapper<cl_type>(device, retainObject) { }
2113 /*! \brief Returns the first device on the default context.
2115 * \see Context::getDefault()
2117 static Device getDefault(
2118 cl_int *errResult = NULL)
2120 std::call_once(default_initialized_, makeDefault);
2121 detail::errHandler(default_error_);
2122 if (errResult != NULL) {
2123 *errResult = default_error_;
2129 * Modify the default device to be used by
2130 * subsequent operations.
2131 * Will only set the default if no default was previously created.
2132 * @return updated default device.
2133 * Should be compared to the passed value to ensure that it was updated.
2135 static Device setDefault(const Device &default_device)
2137 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_device));
2138 detail::errHandler(default_error_);
2142 /*! \brief Assignment operator from cl_device_id.
2144 * This simply copies the device ID value, which is an inexpensive operation.
2146 Device& operator = (const cl_device_id& rhs)
2148 detail::Wrapper<cl_type>::operator=(rhs);
2152 /*! \brief Copy constructor to forward copy to the superclass correctly.
2153 * Required for MSVC.
2155 Device(const Device& dev) : detail::Wrapper<cl_type>(dev) {}
2157 /*! \brief Copy assignment to forward copy to the superclass correctly.
2158 * Required for MSVC.
2160 Device& operator = (const Device &dev)
2162 detail::Wrapper<cl_type>::operator=(dev);
2166 /*! \brief Move constructor to forward move to the superclass correctly.
2167 * Required for MSVC.
2169 Device(Device&& dev) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(dev)) {}
2171 /*! \brief Move assignment to forward move to the superclass correctly.
2172 * Required for MSVC.
2174 Device& operator = (Device &&dev)
2176 detail::Wrapper<cl_type>::operator=(std::move(dev));
2180 //! \brief Wrapper for clGetDeviceInfo().
2181 template <typename T>
2182 cl_int getInfo(cl_device_info name, T* param) const
2184 return detail::errHandler(
2185 detail::getInfo(&::clGetDeviceInfo, object_, name, param),
2186 __GET_DEVICE_INFO_ERR);
2189 //! \brief Wrapper for clGetDeviceInfo() that returns by value.
2190 template <cl_int name> typename
2191 detail::param_traits<detail::cl_device_info, name>::param_type
2192 getInfo(cl_int* err = NULL) const
2194 typename detail::param_traits<
2195 detail::cl_device_info, name>::param_type param;
2196 cl_int result = getInfo(name, ¶m);
2204 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2206 * Return the current value of the host clock as seen by the device.
2207 * The resolution of the device timer may be queried with the
2208 * CL_DEVICE_PROFILING_TIMER_RESOLUTION query.
2209 * @return The host timer value.
2211 cl_ulong getHostTimer(cl_int *error = nullptr)
2213 cl_ulong retVal = 0;
2215 clGetHostTimer(this->get(), &retVal);
2218 __GET_HOST_TIMER_ERR);
2226 * Return a synchronized pair of host and device timestamps as seen by device.
2227 * Use to correlate the clocks and get the host timer only using getHostTimer
2228 * as a lower cost mechanism in between calls.
2229 * The resolution of the host timer may be queried with the
2230 * CL_PLATFORM_HOST_TIMER_RESOLUTION query.
2231 * The resolution of the device timer may be queried with the
2232 * CL_DEVICE_PROFILING_TIMER_RESOLUTION query.
2233 * @return A pair of (device timer, host timer) timer values.
2235 std::pair<cl_ulong, cl_ulong> getDeviceAndHostTimer(cl_int *error = nullptr)
2237 std::pair<cl_ulong, cl_ulong> retVal;
2239 clGetDeviceAndHostTimer(this->get(), &(retVal.first), &(retVal.second));
2242 __GET_DEVICE_AND_HOST_TIMER_ERR);
2248 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2253 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
2254 //! \brief Wrapper for clCreateSubDevices().
2255 cl_int createSubDevices(
2256 const cl_device_partition_property * properties,
2257 vector<Device>* devices)
2260 cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n);
2261 if (err != CL_SUCCESS) {
2262 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2265 vector<cl_device_id> ids(n);
2266 err = clCreateSubDevices(object_, properties, n, ids.data(), NULL);
2267 if (err != CL_SUCCESS) {
2268 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2271 // Cannot trivially assign because we need to capture intermediates
2272 // with safe construction
2274 devices->resize(ids.size());
2276 // Assign to param, constructing with retain behaviour
2277 // to correctly capture each underlying CL object
2278 for (size_type i = 0; i < ids.size(); i++) {
2279 // We do not need to retain because this device is being created
2281 (*devices)[i] = Device(ids[i], false);
2287 #elif defined(CL_HPP_USE_CL_DEVICE_FISSION)
2290 * CL 1.1 version that uses device fission extension.
2292 cl_int createSubDevices(
2293 const cl_device_partition_property_ext * properties,
2294 vector<Device>* devices)
2296 typedef CL_API_ENTRY cl_int
2297 ( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
2298 cl_device_id /*in_device*/,
2299 const cl_device_partition_property_ext * /* properties */,
2300 cl_uint /*num_entries*/,
2301 cl_device_id * /*out_devices*/,
2302 cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1;
2304 static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
2305 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSubDevicesEXT);
2308 cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
2309 if (err != CL_SUCCESS) {
2310 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2313 vector<cl_device_id> ids(n);
2314 err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids.data(), NULL);
2315 if (err != CL_SUCCESS) {
2316 return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2318 // Cannot trivially assign because we need to capture intermediates
2319 // with safe construction
2321 devices->resize(ids.size());
2323 // Assign to param, constructing with retain behaviour
2324 // to correctly capture each underlying CL object
2325 for (size_type i = 0; i < ids.size(); i++) {
2326 // We do not need to retain because this device is being created
2328 (*devices)[i] = Device(ids[i], false);
2333 #endif // defined(CL_HPP_USE_CL_DEVICE_FISSION)
2336 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Device::default_initialized_;
2337 CL_HPP_DEFINE_STATIC_MEMBER_ Device Device::default_;
2338 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Device::default_error_ = CL_SUCCESS;
2340 /*! \brief Class interface for cl_platform_id.
2342 * \note Copies of these objects are inexpensive, since they don't 'own'
2343 * any underlying resources or data structures.
2345 * \see cl_platform_id
2347 class Platform : public detail::Wrapper<cl_platform_id>
2350 static std::once_flag default_initialized_;
2351 static Platform default_;
2352 static cl_int default_error_;
2354 /*! \brief Create the default context.
2356 * This sets @c default_ and @c default_error_. It does not throw
2359 static void makeDefault() {
2360 /* Throwing an exception from a call_once invocation does not do
2361 * what we wish, so we catch it and save the error.
2363 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2367 // If default wasn't passed ,generate one
2371 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2372 if (err != CL_SUCCESS) {
2373 default_error_ = err;
2377 default_error_ = CL_INVALID_PLATFORM;
2381 vector<cl_platform_id> ids(n);
2382 err = ::clGetPlatformIDs(n, ids.data(), NULL);
2383 if (err != CL_SUCCESS) {
2384 default_error_ = err;
2388 default_ = Platform(ids[0]);
2390 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2391 catch (cl::Error &e) {
2392 default_error_ = e.err();
2397 /*! \brief Create the default platform from a provided platform.
2399 * This sets @c default_. It does not throw
2402 static void makeDefaultProvided(const Platform &p) {
2407 #ifdef CL_HPP_UNIT_TEST_ENABLE
2408 /*! \brief Reset the default.
2410 * This sets @c default_ to an empty value to support cleanup in
2411 * the unit test framework.
2412 * This function is not thread safe.
2414 static void unitTestClearDefault() {
2415 default_ = Platform();
2417 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2419 //! \brief Default constructor - initializes to NULL.
2420 Platform() : detail::Wrapper<cl_type>() { }
2422 /*! \brief Constructor from cl_platform_id.
2424 * \param retainObject will cause the constructor to retain its cl object.
2425 * Defaults to false to maintain compatibility with
2427 * This simply copies the platform ID value, which is an inexpensive operation.
2429 explicit Platform(const cl_platform_id &platform, bool retainObject = false) :
2430 detail::Wrapper<cl_type>(platform, retainObject) { }
2432 /*! \brief Assignment operator from cl_platform_id.
2434 * This simply copies the platform ID value, which is an inexpensive operation.
2436 Platform& operator = (const cl_platform_id& rhs)
2438 detail::Wrapper<cl_type>::operator=(rhs);
2442 static Platform getDefault(
2443 cl_int *errResult = NULL)
2445 std::call_once(default_initialized_, makeDefault);
2446 detail::errHandler(default_error_);
2447 if (errResult != NULL) {
2448 *errResult = default_error_;
2454 * Modify the default platform to be used by
2455 * subsequent operations.
2456 * Will only set the default if no default was previously created.
2457 * @return updated default platform.
2458 * Should be compared to the passed value to ensure that it was updated.
2460 static Platform setDefault(const Platform &default_platform)
2462 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_platform));
2463 detail::errHandler(default_error_);
2467 //! \brief Wrapper for clGetPlatformInfo().
2468 cl_int getInfo(cl_platform_info name, string* param) const
2470 return detail::errHandler(
2471 detail::getInfo(&::clGetPlatformInfo, object_, name, param),
2472 __GET_PLATFORM_INFO_ERR);
2475 //! \brief Wrapper for clGetPlatformInfo() that returns by value.
2476 template <cl_int name> typename
2477 detail::param_traits<detail::cl_platform_info, name>::param_type
2478 getInfo(cl_int* err = NULL) const
2480 typename detail::param_traits<
2481 detail::cl_platform_info, name>::param_type param;
2482 cl_int result = getInfo(name, ¶m);
2489 /*! \brief Gets a list of devices for this platform.
2491 * Wraps clGetDeviceIDs().
2494 cl_device_type type,
2495 vector<Device>* devices) const
2498 if( devices == NULL ) {
2499 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2501 cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
2502 if (err != CL_SUCCESS) {
2503 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2506 vector<cl_device_id> ids(n);
2507 err = ::clGetDeviceIDs(object_, type, n, ids.data(), NULL);
2508 if (err != CL_SUCCESS) {
2509 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2512 // Cannot trivially assign because we need to capture intermediates
2513 // with safe construction
2514 // We must retain things we obtain from the API to avoid releasing
2515 // API-owned objects.
2517 devices->resize(ids.size());
2519 // Assign to param, constructing with retain behaviour
2520 // to correctly capture each underlying CL object
2521 for (size_type i = 0; i < ids.size(); i++) {
2522 (*devices)[i] = Device(ids[i], true);
2528 #if defined(CL_HPP_USE_DX_INTEROP)
2529 /*! \brief Get the list of available D3D10 devices.
2531 * \param d3d_device_source.
2533 * \param d3d_object.
2535 * \param d3d_device_set.
2537 * \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device
2538 * values returned in devices can be used to identify a specific OpenCL
2539 * device. If \a devices argument is NULL, this argument is ignored.
2541 * \return One of the following values:
2542 * - CL_SUCCESS if the function is executed successfully.
2544 * The application can query specific capabilities of the OpenCL device(s)
2545 * returned by cl::getDevices. This can be used by the application to
2546 * determine which device(s) to use.
2548 * \note In the case that exceptions are enabled and a return value
2549 * other than CL_SUCCESS is generated, then cl::Error exception is
2553 cl_d3d10_device_source_khr d3d_device_source,
2555 cl_d3d10_device_set_khr d3d_device_set,
2556 vector<Device>* devices) const
2558 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
2559 cl_platform_id platform,
2560 cl_d3d10_device_source_khr d3d_device_source,
2562 cl_d3d10_device_set_khr d3d_device_set,
2563 cl_uint num_entries,
2564 cl_device_id * devices,
2565 cl_uint* num_devices);
2567 if( devices == NULL ) {
2568 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2571 static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
2572 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(object_, clGetDeviceIDsFromD3D10KHR);
2575 cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
2583 if (err != CL_SUCCESS) {
2584 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2587 vector<cl_device_id> ids(n);
2588 err = pfn_clGetDeviceIDsFromD3D10KHR(
2596 if (err != CL_SUCCESS) {
2597 return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2600 // Cannot trivially assign because we need to capture intermediates
2601 // with safe construction
2602 // We must retain things we obtain from the API to avoid releasing
2603 // API-owned objects.
2605 devices->resize(ids.size());
2607 // Assign to param, constructing with retain behaviour
2608 // to correctly capture each underlying CL object
2609 for (size_type i = 0; i < ids.size(); i++) {
2610 (*devices)[i] = Device(ids[i], true);
2617 /*! \brief Gets a list of available platforms.
2619 * Wraps clGetPlatformIDs().
2622 vector<Platform>* platforms)
2626 if( platforms == NULL ) {
2627 return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
2630 cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2631 if (err != CL_SUCCESS) {
2632 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2635 vector<cl_platform_id> ids(n);
2636 err = ::clGetPlatformIDs(n, ids.data(), NULL);
2637 if (err != CL_SUCCESS) {
2638 return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2642 platforms->resize(ids.size());
2644 // Platforms don't reference count
2645 for (size_type i = 0; i < ids.size(); i++) {
2646 (*platforms)[i] = Platform(ids[i]);
2652 /*! \brief Gets the first available platform.
2654 * Wraps clGetPlatformIDs(), returning the first result.
2657 Platform * platform)
2660 Platform default_platform = Platform::getDefault(&err);
2662 *platform = default_platform;
2667 /*! \brief Gets the first available platform, returning it by value.
2669 * \return Returns a valid platform if one is available.
2670 * If no platform is available will return a null platform.
2671 * Throws an exception if no platforms are available
2672 * or an error condition occurs.
2673 * Wraps clGetPlatformIDs(), returning the first result.
2675 static Platform get(
2676 cl_int * errResult = NULL)
2679 Platform default_platform = Platform::getDefault(&err);
2683 return default_platform;
2686 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
2687 //! \brief Wrapper for clUnloadCompiler().
2691 return ::clUnloadPlatformCompiler(object_);
2693 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
2694 }; // class Platform
2696 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Platform::default_initialized_;
2697 CL_HPP_DEFINE_STATIC_MEMBER_ Platform Platform::default_;
2698 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Platform::default_error_ = CL_SUCCESS;
2702 * Deprecated APIs for 1.2
2704 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2706 * Unload the OpenCL compiler.
2707 * \note Deprecated for OpenCL 1.2. Use Platform::unloadCompiler instead.
2709 inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int
2710 UnloadCompiler() CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
2714 return ::clUnloadCompiler();
2716 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2718 /*! \brief Class interface for cl_context.
2720 * \note Copies of these objects are shallow, meaning that the copy will refer
2721 * to the same underlying cl_context as the original. For details, see
2722 * clRetainContext() and clReleaseContext().
2727 : public detail::Wrapper<cl_context>
2730 static std::once_flag default_initialized_;
2731 static Context default_;
2732 static cl_int default_error_;
2734 /*! \brief Create the default context from the default device type in the default platform.
2736 * This sets @c default_ and @c default_error_. It does not throw
2739 static void makeDefault() {
2740 /* Throwing an exception from a call_once invocation does not do
2741 * what we wish, so we catch it and save the error.
2743 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2747 #if !defined(__APPLE__) && !defined(__MACOS)
2748 const Platform &p = Platform::getDefault();
2749 cl_platform_id defaultPlatform = p();
2750 cl_context_properties properties[3] = {
2751 CL_CONTEXT_PLATFORM, (cl_context_properties)defaultPlatform, 0
2753 #else // #if !defined(__APPLE__) && !defined(__MACOS)
2754 cl_context_properties *properties = nullptr;
2755 #endif // #if !defined(__APPLE__) && !defined(__MACOS)
2758 CL_DEVICE_TYPE_DEFAULT,
2764 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2765 catch (cl::Error &e) {
2766 default_error_ = e.err();
2772 /*! \brief Create the default context from a provided Context.
2774 * This sets @c default_. It does not throw
2777 static void makeDefaultProvided(const Context &c) {
2782 #ifdef CL_HPP_UNIT_TEST_ENABLE
2783 /*! \brief Reset the default.
2785 * This sets @c default_ to an empty value to support cleanup in
2786 * the unit test framework.
2787 * This function is not thread safe.
2789 static void unitTestClearDefault() {
2790 default_ = Context();
2792 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2794 /*! \brief Constructs a context including a list of specified devices.
2796 * Wraps clCreateContext().
2799 const vector<Device>& devices,
2800 cl_context_properties* properties = NULL,
2801 void (CL_CALLBACK * notifyFptr)(
2811 size_type numDevices = devices.size();
2812 vector<cl_device_id> deviceIDs(numDevices);
2814 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
2815 deviceIDs[deviceIndex] = (devices[deviceIndex])();
2818 object_ = ::clCreateContext(
2819 properties, (cl_uint) numDevices,
2821 notifyFptr, data, &error);
2823 detail::errHandler(error, __CREATE_CONTEXT_ERR);
2830 const Device& device,
2831 cl_context_properties* properties = NULL,
2832 void (CL_CALLBACK * notifyFptr)(
2842 cl_device_id deviceID = device();
2844 object_ = ::clCreateContext(
2847 notifyFptr, data, &error);
2849 detail::errHandler(error, __CREATE_CONTEXT_ERR);
2855 /*! \brief Constructs a context including all or a subset of devices of a specified type.
2857 * Wraps clCreateContextFromType().
2860 cl_device_type type,
2861 cl_context_properties* properties = NULL,
2862 void (CL_CALLBACK * notifyFptr)(
2872 #if !defined(__APPLE__) && !defined(__MACOS)
2873 cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 };
2875 if (properties == NULL) {
2876 // Get a valid platform ID as we cannot send in a blank one
2877 vector<Platform> platforms;
2878 error = Platform::get(&platforms);
2879 if (error != CL_SUCCESS) {
2880 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2887 // Check the platforms we found for a device of our specified type
2888 cl_context_properties platform_id = 0;
2889 for (unsigned int i = 0; i < platforms.size(); i++) {
2891 vector<Device> devices;
2893 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2897 error = platforms[i].getDevices(type, &devices);
2899 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2900 } catch (cl::Error& e) {
2903 // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type
2904 // We do error checking next anyway, and can throw there if needed
2907 // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND
2908 if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) {
2909 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2915 if (devices.size() > 0) {
2916 platform_id = (cl_context_properties)platforms[i]();
2921 if (platform_id == 0) {
2922 detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR);
2924 *err = CL_DEVICE_NOT_FOUND;
2929 prop[1] = platform_id;
2930 properties = &prop[0];
2933 object_ = ::clCreateContextFromType(
2934 properties, type, notifyFptr, data, &error);
2936 detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2942 /*! \brief Copy constructor to forward copy to the superclass correctly.
2943 * Required for MSVC.
2945 Context(const Context& ctx) : detail::Wrapper<cl_type>(ctx) {}
2947 /*! \brief Copy assignment to forward copy to the superclass correctly.
2948 * Required for MSVC.
2950 Context& operator = (const Context &ctx)
2952 detail::Wrapper<cl_type>::operator=(ctx);
2956 /*! \brief Move constructor to forward move to the superclass correctly.
2957 * Required for MSVC.
2959 Context(Context&& ctx) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(ctx)) {}
2961 /*! \brief Move assignment to forward move to the superclass correctly.
2962 * Required for MSVC.
2964 Context& operator = (Context &&ctx)
2966 detail::Wrapper<cl_type>::operator=(std::move(ctx));
2971 /*! \brief Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT.
2973 * \note All calls to this function return the same cl_context as the first.
2975 static Context getDefault(cl_int * err = NULL)
2977 std::call_once(default_initialized_, makeDefault);
2978 detail::errHandler(default_error_);
2980 *err = default_error_;
2986 * Modify the default context to be used by
2987 * subsequent operations.
2988 * Will only set the default if no default was previously created.
2989 * @return updated default context.
2990 * Should be compared to the passed value to ensure that it was updated.
2992 static Context setDefault(const Context &default_context)
2994 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_context));
2995 detail::errHandler(default_error_);
2999 //! \brief Default constructor - initializes to NULL.
3000 Context() : detail::Wrapper<cl_type>() { }
3002 /*! \brief Constructor from cl_context - takes ownership.
3004 * This effectively transfers ownership of a refcount on the cl_context
3005 * into the new Context object.
3007 explicit Context(const cl_context& context, bool retainObject = false) :
3008 detail::Wrapper<cl_type>(context, retainObject) { }
3010 /*! \brief Assignment operator from cl_context - takes ownership.
3012 * This effectively transfers ownership of a refcount on the rhs and calls
3013 * clReleaseContext() on the value previously held by this instance.
3015 Context& operator = (const cl_context& rhs)
3017 detail::Wrapper<cl_type>::operator=(rhs);
3021 //! \brief Wrapper for clGetContextInfo().
3022 template <typename T>
3023 cl_int getInfo(cl_context_info name, T* param) const
3025 return detail::errHandler(
3026 detail::getInfo(&::clGetContextInfo, object_, name, param),
3027 __GET_CONTEXT_INFO_ERR);
3030 //! \brief Wrapper for clGetContextInfo() that returns by value.
3031 template <cl_int name> typename
3032 detail::param_traits<detail::cl_context_info, name>::param_type
3033 getInfo(cl_int* err = NULL) const
3035 typename detail::param_traits<
3036 detail::cl_context_info, name>::param_type param;
3037 cl_int result = getInfo(name, ¶m);
3044 /*! \brief Gets a list of supported image formats.
3046 * Wraps clGetSupportedImageFormats().
3048 cl_int getSupportedImageFormats(
3050 cl_mem_object_type type,
3051 vector<ImageFormat>* formats) const
3059 cl_int err = ::clGetSupportedImageFormats(
3066 if (err != CL_SUCCESS) {
3067 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3070 if (numEntries > 0) {
3071 vector<ImageFormat> value(numEntries);
3072 err = ::clGetSupportedImageFormats(
3077 (cl_image_format*)value.data(),
3079 if (err != CL_SUCCESS) {
3080 return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3083 formats->assign(begin(value), end(value));
3086 // If no values are being returned, ensure an empty vector comes back
3094 inline void Device::makeDefault()
3096 /* Throwing an exception from a call_once invocation does not do
3097 * what we wish, so we catch it and save the error.
3099 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3105 Context context = Context::getDefault(&error);
3106 detail::errHandler(error, __CREATE_CONTEXT_ERR);
3108 if (error != CL_SUCCESS) {
3109 default_error_ = error;
3112 default_ = context.getInfo<CL_CONTEXT_DEVICES>()[0];
3113 default_error_ = CL_SUCCESS;
3116 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3117 catch (cl::Error &e) {
3118 default_error_ = e.err();
3123 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Context::default_initialized_;
3124 CL_HPP_DEFINE_STATIC_MEMBER_ Context Context::default_;
3125 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Context::default_error_ = CL_SUCCESS;
3127 /*! \brief Class interface for cl_event.
3129 * \note Copies of these objects are shallow, meaning that the copy will refer
3130 * to the same underlying cl_event as the original. For details, see
3131 * clRetainEvent() and clReleaseEvent().
3135 class Event : public detail::Wrapper<cl_event>
3138 //! \brief Default constructor - initializes to NULL.
3139 Event() : detail::Wrapper<cl_type>() { }
3141 /*! \brief Constructor from cl_event - takes ownership.
3143 * \param retainObject will cause the constructor to retain its cl object.
3144 * Defaults to false to maintain compatibility with
3146 * This effectively transfers ownership of a refcount on the cl_event
3147 * into the new Event object.
3149 explicit Event(const cl_event& event, bool retainObject = false) :
3150 detail::Wrapper<cl_type>(event, retainObject) { }
3152 /*! \brief Assignment operator from cl_event - takes ownership.
3154 * This effectively transfers ownership of a refcount on the rhs and calls
3155 * clReleaseEvent() on the value previously held by this instance.
3157 Event& operator = (const cl_event& rhs)
3159 detail::Wrapper<cl_type>::operator=(rhs);
3163 //! \brief Wrapper for clGetEventInfo().
3164 template <typename T>
3165 cl_int getInfo(cl_event_info name, T* param) const
3167 return detail::errHandler(
3168 detail::getInfo(&::clGetEventInfo, object_, name, param),
3169 __GET_EVENT_INFO_ERR);
3172 //! \brief Wrapper for clGetEventInfo() that returns by value.
3173 template <cl_int name> typename
3174 detail::param_traits<detail::cl_event_info, name>::param_type
3175 getInfo(cl_int* err = NULL) const
3177 typename detail::param_traits<
3178 detail::cl_event_info, name>::param_type param;
3179 cl_int result = getInfo(name, ¶m);
3186 //! \brief Wrapper for clGetEventProfilingInfo().
3187 template <typename T>
3188 cl_int getProfilingInfo(cl_profiling_info name, T* param) const
3190 return detail::errHandler(detail::getInfo(
3191 &::clGetEventProfilingInfo, object_, name, param),
3192 __GET_EVENT_PROFILE_INFO_ERR);
3195 //! \brief Wrapper for clGetEventProfilingInfo() that returns by value.
3196 template <cl_int name> typename
3197 detail::param_traits<detail::cl_profiling_info, name>::param_type
3198 getProfilingInfo(cl_int* err = NULL) const
3200 typename detail::param_traits<
3201 detail::cl_profiling_info, name>::param_type param;
3202 cl_int result = getProfilingInfo(name, ¶m);
3209 /*! \brief Blocks the calling thread until this event completes.
3211 * Wraps clWaitForEvents().
3215 return detail::errHandler(
3216 ::clWaitForEvents(1, &object_),
3217 __WAIT_FOR_EVENTS_ERR);
3220 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3221 /*! \brief Registers a user callback function for a specific command execution status.
3223 * Wraps clSetEventCallback().
3227 void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
3228 void * user_data = NULL)
3230 return detail::errHandler(
3231 ::clSetEventCallback(
3236 __SET_EVENT_CALLBACK_ERR);
3238 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3240 /*! \brief Blocks the calling thread until every event specified is complete.
3242 * Wraps clWaitForEvents().
3245 waitForEvents(const vector<Event>& events)
3247 return detail::errHandler(
3249 (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3250 __WAIT_FOR_EVENTS_ERR);
3254 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3255 /*! \brief Class interface for user events (a subset of cl_event's).
3257 * See Event for details about copy semantics, etc.
3259 class UserEvent : public Event
3262 /*! \brief Constructs a user event on a given context.
3264 * Wraps clCreateUserEvent().
3267 const Context& context,
3268 cl_int * err = NULL)
3271 object_ = ::clCreateUserEvent(
3275 detail::errHandler(error, __CREATE_USER_EVENT_ERR);
3281 //! \brief Default constructor - initializes to NULL.
3282 UserEvent() : Event() { }
3284 /*! \brief Sets the execution status of a user event object.
3286 * Wraps clSetUserEventStatus().
3288 cl_int setStatus(cl_int status)
3290 return detail::errHandler(
3291 ::clSetUserEventStatus(object_,status),
3292 __SET_USER_EVENT_STATUS_ERR);
3295 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3297 /*! \brief Blocks the calling thread until every event specified is complete.
3299 * Wraps clWaitForEvents().
3301 inline static cl_int
3302 WaitForEvents(const vector<Event>& events)
3304 return detail::errHandler(
3306 (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3307 __WAIT_FOR_EVENTS_ERR);
3310 /*! \brief Class interface for cl_mem.
3312 * \note Copies of these objects are shallow, meaning that the copy will refer
3313 * to the same underlying cl_mem as the original. For details, see
3314 * clRetainMemObject() and clReleaseMemObject().
3318 class Memory : public detail::Wrapper<cl_mem>
3321 //! \brief Default constructor - initializes to NULL.
3322 Memory() : detail::Wrapper<cl_type>() { }
3324 /*! \brief Constructor from cl_mem - takes ownership.
3326 * Optionally transfer ownership of a refcount on the cl_mem
3327 * into the new Memory object.
3329 * \param retainObject will cause the constructor to retain its cl object.
3330 * Defaults to false to maintain compatibility with
3333 * See Memory for further details.
3335 explicit Memory(const cl_mem& memory, bool retainObject) :
3336 detail::Wrapper<cl_type>(memory, retainObject) { }
3338 /*! \brief Assignment operator from cl_mem - takes ownership.
3340 * This effectively transfers ownership of a refcount on the rhs and calls
3341 * clReleaseMemObject() on the value previously held by this instance.
3343 Memory& operator = (const cl_mem& rhs)
3345 detail::Wrapper<cl_type>::operator=(rhs);
3349 /*! \brief Copy constructor to forward copy to the superclass correctly.
3350 * Required for MSVC.
3352 Memory(const Memory& mem) : detail::Wrapper<cl_type>(mem) {}
3354 /*! \brief Copy assignment to forward copy to the superclass correctly.
3355 * Required for MSVC.
3357 Memory& operator = (const Memory &mem)
3359 detail::Wrapper<cl_type>::operator=(mem);
3363 /*! \brief Move constructor to forward move to the superclass correctly.
3364 * Required for MSVC.
3366 Memory(Memory&& mem) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(mem)) {}
3368 /*! \brief Move assignment to forward move to the superclass correctly.
3369 * Required for MSVC.
3371 Memory& operator = (Memory &&mem)
3373 detail::Wrapper<cl_type>::operator=(std::move(mem));
3378 //! \brief Wrapper for clGetMemObjectInfo().
3379 template <typename T>
3380 cl_int getInfo(cl_mem_info name, T* param) const
3382 return detail::errHandler(
3383 detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
3384 __GET_MEM_OBJECT_INFO_ERR);
3387 //! \brief Wrapper for clGetMemObjectInfo() that returns by value.
3388 template <cl_int name> typename
3389 detail::param_traits<detail::cl_mem_info, name>::param_type
3390 getInfo(cl_int* err = NULL) const
3392 typename detail::param_traits<
3393 detail::cl_mem_info, name>::param_type param;
3394 cl_int result = getInfo(name, ¶m);
3401 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3402 /*! \brief Registers a callback function to be called when the memory object
3403 * is no longer needed.
3405 * Wraps clSetMemObjectDestructorCallback().
3407 * Repeated calls to this function, for a given cl_mem value, will append
3408 * to the list of functions called (in reverse order) when memory object's
3409 * resources are freed and the memory object is deleted.
3412 * The registered callbacks are associated with the underlying cl_mem
3413 * value - not the Memory class instance.
3415 cl_int setDestructorCallback(
3416 void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
3417 void * user_data = NULL)
3419 return detail::errHandler(
3420 ::clSetMemObjectDestructorCallback(
3424 __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
3426 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3430 // Pre-declare copy functions
3432 template< typename IteratorType >
3433 cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3434 template< typename IteratorType >
3435 cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3436 template< typename IteratorType >
3437 cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3438 template< typename IteratorType >
3439 cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3442 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
3448 static cl_svm_mem_flags getSVMMemFlags()
3453 } // namespace detail
3455 template<class Trait = detail::SVMTraitNull>
3456 class SVMTraitReadWrite
3459 static cl_svm_mem_flags getSVMMemFlags()
3461 return CL_MEM_READ_WRITE |
3462 Trait::getSVMMemFlags();
3466 template<class Trait = detail::SVMTraitNull>
3467 class SVMTraitReadOnly
3470 static cl_svm_mem_flags getSVMMemFlags()
3472 return CL_MEM_READ_ONLY |
3473 Trait::getSVMMemFlags();
3477 template<class Trait = detail::SVMTraitNull>
3478 class SVMTraitWriteOnly
3481 static cl_svm_mem_flags getSVMMemFlags()
3483 return CL_MEM_WRITE_ONLY |
3484 Trait::getSVMMemFlags();
3488 template<class Trait = SVMTraitReadWrite<>>
3489 class SVMTraitCoarse
3492 static cl_svm_mem_flags getSVMMemFlags()
3494 return Trait::getSVMMemFlags();
3498 template<class Trait = SVMTraitReadWrite<>>
3502 static cl_svm_mem_flags getSVMMemFlags()
3504 return CL_MEM_SVM_FINE_GRAIN_BUFFER |
3505 Trait::getSVMMemFlags();
3509 template<class Trait = SVMTraitReadWrite<>>
3510 class SVMTraitAtomic
3513 static cl_svm_mem_flags getSVMMemFlags()
3516 CL_MEM_SVM_FINE_GRAIN_BUFFER |
3517 CL_MEM_SVM_ATOMICS |
3518 Trait::getSVMMemFlags();
3522 // Pre-declare SVM map function
3523 template<typename T>
3524 inline cl_int enqueueMapSVM(
3529 const vector<Event>* events = NULL,
3530 Event* event = NULL);
3533 * STL-like allocator class for managing SVM objects provided for convenience.
3535 * Note that while this behaves like an allocator for the purposes of constructing vectors and similar objects,
3536 * care must be taken when using with smart pointers.
3537 * The allocator should not be used to construct a unique_ptr if we are using coarse-grained SVM mode because
3538 * the coarse-grained management behaviour would behave incorrectly with respect to reference counting.
3540 * Instead the allocator embeds a Deleter which may be used with unique_ptr and is used
3541 * with the allocate_shared and allocate_ptr supplied operations.
3543 template<typename T, class SVMTrait>
3544 class SVMAllocator {
3549 typedef T value_type;
3550 typedef value_type* pointer;
3551 typedef const value_type* const_pointer;
3552 typedef value_type& reference;
3553 typedef const value_type& const_reference;
3554 typedef std::size_t size_type;
3555 typedef std::ptrdiff_t difference_type;
3557 template<typename U>
3560 typedef SVMAllocator<U, SVMTrait> other;
3563 template<typename U, typename V>
3564 friend class SVMAllocator;
3567 context_(Context::getDefault())
3571 explicit SVMAllocator(cl::Context context) :
3577 SVMAllocator(const SVMAllocator &other) :
3578 context_(other.context_)
3582 template<typename U>
3583 SVMAllocator(const SVMAllocator<U, SVMTrait> &other) :
3584 context_(other.context_)
3592 pointer address(reference r) CL_HPP_NOEXCEPT_
3594 return std::addressof(r);
3597 const_pointer address(const_reference r) CL_HPP_NOEXCEPT_
3599 return std::addressof(r);
3603 * Allocate an SVM pointer.
3605 * If the allocator is coarse-grained, this will take ownership to allow
3606 * containers to correctly construct data in place.
3610 typename cl::SVMAllocator<void, SVMTrait>::const_pointer = 0)
3612 // Allocate memory with default alignment matching the size of the type
3616 SVMTrait::getSVMMemFlags(),
3619 pointer retValue = reinterpret_cast<pointer>(
3621 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3623 std::bad_alloc excep;
3626 #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3628 // If allocation was coarse-grained then map it
3629 if (!(SVMTrait::getSVMMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) {
3630 cl_int err = enqueueMapSVM(retValue, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, size*sizeof(T));
3631 if (err != CL_SUCCESS) {
3632 std::bad_alloc excep;
3637 // If exceptions disabled, return null pointer from allocator
3641 void deallocate(pointer p, size_type)
3643 clSVMFree(context_(), p);
3647 * Return the maximum possible allocation size.
3648 * This is the minimum of the maximum sizes of all devices in the context.
3650 size_type max_size() const CL_HPP_NOEXCEPT_
3652 size_type maxSize = std::numeric_limits<size_type>::max() / sizeof(T);
3654 for (const Device &d : context_.getInfo<CL_CONTEXT_DEVICES>()) {
3657 static_cast<size_type>(d.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>()));
3663 template< class U, class... Args >
3664 void construct(U* p, Args&&... args)
3676 * Returns true if the contexts match.
3678 inline bool operator==(SVMAllocator const& rhs)
3680 return (context_==rhs.context_);
3683 inline bool operator!=(SVMAllocator const& a)
3685 return !operator==(a);
3687 }; // class SVMAllocator return cl::pointer<T>(tmp, detail::Deleter<T, Alloc>{alloc, copies});
3690 template<class SVMTrait>
3691 class SVMAllocator<void, SVMTrait> {
3693 typedef void value_type;
3694 typedef value_type* pointer;
3695 typedef const value_type* const_pointer;
3697 template<typename U>
3700 typedef SVMAllocator<U, SVMTrait> other;
3703 template<typename U, typename V>
3704 friend class SVMAllocator;
3707 #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3710 template<class Alloc>
3717 typedef typename std::allocator_traits<Alloc>::pointer pointer;
3719 Deleter(const Alloc &alloc, size_type copies) : alloc_{ alloc }, copies_{ copies }
3723 void operator()(pointer ptr) const {
3724 Alloc tmpAlloc{ alloc_ };
3725 std::allocator_traits<Alloc>::destroy(tmpAlloc, std::addressof(*ptr));
3726 std::allocator_traits<Alloc>::deallocate(tmpAlloc, ptr, copies_);
3729 } // namespace detail
3732 * Allocation operation compatible with std::allocate_ptr.
3733 * Creates a unique_ptr<T> by default.
3734 * This requirement is to ensure that the control block is not
3735 * allocated in memory inaccessible to the host.
3737 template <class T, class Alloc, class... Args>
3738 cl::pointer<T, detail::Deleter<Alloc>> allocate_pointer(const Alloc &alloc_, Args&&... args)
3740 Alloc alloc(alloc_);
3741 static const size_type copies = 1;
3743 // Ensure that creation of the management block and the
3744 // object are dealt with separately such that we only provide a deleter
3746 T* tmp = std::allocator_traits<Alloc>::allocate(alloc, copies);
3748 std::bad_alloc excep;
3752 std::allocator_traits<Alloc>::construct(
3754 std::addressof(*tmp),
3755 std::forward<Args>(args)...);
3757 return cl::pointer<T, detail::Deleter<Alloc>>(tmp, detail::Deleter<Alloc>{alloc, copies});
3759 catch (std::bad_alloc& b)
3761 std::allocator_traits<Alloc>::deallocate(alloc, tmp, copies);
3766 template< class T, class SVMTrait, class... Args >
3767 cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(Args... args)
3769 SVMAllocator<T, SVMTrait> alloc;
3770 return cl::allocate_pointer<T>(alloc, args...);
3773 template< class T, class SVMTrait, class... Args >
3774 cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(const cl::Context &c, Args... args)
3776 SVMAllocator<T, SVMTrait> alloc(c);
3777 return cl::allocate_pointer<T>(alloc, args...);
3779 #endif // #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3781 /*! \brief Vector alias to simplify contruction of coarse-grained SVM containers.
3784 template < class T >
3785 using coarse_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>>;
3787 /*! \brief Vector alias to simplify contruction of fine-grained SVM containers.
3790 template < class T >
3791 using fine_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitFine<>>>;
3793 /*! \brief Vector alias to simplify contruction of fine-grained SVM containers that support platform atomics.
3796 template < class T >
3797 using atomic_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitAtomic<>>>;
3799 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
3802 /*! \brief Class interface for Buffer Memory Objects.
3804 * See Memory for details about copy semantics, etc.
3808 class Buffer : public Memory
3812 /*! \brief Constructs a Buffer in a specified context.
3814 * Wraps clCreateBuffer().
3816 * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
3817 * specified. Note alignment & exclusivity requirements.
3820 const Context& context,
3823 void* host_ptr = NULL,
3827 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3829 detail::errHandler(error, __CREATE_BUFFER_ERR);
3835 /*! \brief Constructs a Buffer in the default context.
3837 * Wraps clCreateBuffer().
3839 * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
3840 * specified. Note alignment & exclusivity requirements.
3842 * \see Context::getDefault()
3847 void* host_ptr = NULL,
3852 Context context = Context::getDefault(err);
3854 object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3856 detail::errHandler(error, __CREATE_BUFFER_ERR);
3863 * \brief Construct a Buffer from a host container via iterators.
3864 * IteratorType must be random access.
3865 * If useHostPtr is specified iterators must represent contiguous data.
3867 template< typename IteratorType >
3869 IteratorType startIterator,
3870 IteratorType endIterator,
3872 bool useHostPtr = false,
3875 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
3878 cl_mem_flags flags = 0;
3880 flags |= CL_MEM_READ_ONLY;
3883 flags |= CL_MEM_READ_WRITE;
3886 flags |= CL_MEM_USE_HOST_PTR;
3889 size_type size = sizeof(DataType)*(endIterator - startIterator);
3891 Context context = Context::getDefault(err);
3894 object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
3896 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
3899 detail::errHandler(error, __CREATE_BUFFER_ERR);
3905 error = cl::copy(startIterator, endIterator, *this);
3906 detail::errHandler(error, __CREATE_BUFFER_ERR);
3914 * \brief Construct a Buffer from a host container via iterators using a specified context.
3915 * IteratorType must be random access.
3916 * If useHostPtr is specified iterators must represent contiguous data.
3918 template< typename IteratorType >
3919 Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator,
3920 bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
3923 * \brief Construct a Buffer from a host container via iterators using a specified queue.
3924 * If useHostPtr is specified iterators must be random access.
3926 template< typename IteratorType >
3927 Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator,
3928 bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
3930 //! \brief Default constructor - initializes to NULL.
3931 Buffer() : Memory() { }
3933 /*! \brief Constructor from cl_mem - takes ownership.
3935 * \param retainObject will cause the constructor to retain its cl object.
3936 * Defaults to false to maintain compatibility with earlier versions.
3938 * See Memory for further details.
3940 explicit Buffer(const cl_mem& buffer, bool retainObject = false) :
3941 Memory(buffer, retainObject) { }
3943 /*! \brief Assignment from cl_mem - performs shallow copy.
3945 * See Memory for further details.
3947 Buffer& operator = (const cl_mem& rhs)
3949 Memory::operator=(rhs);
3953 /*! \brief Copy constructor to forward copy to the superclass correctly.
3954 * Required for MSVC.
3956 Buffer(const Buffer& buf) : Memory(buf) {}
3958 /*! \brief Copy assignment to forward copy to the superclass correctly.
3959 * Required for MSVC.
3961 Buffer& operator = (const Buffer &buf)
3963 Memory::operator=(buf);
3967 /*! \brief Move constructor to forward move to the superclass correctly.
3968 * Required for MSVC.
3970 Buffer(Buffer&& buf) CL_HPP_NOEXCEPT_ : Memory(std::move(buf)) {}
3972 /*! \brief Move assignment to forward move to the superclass correctly.
3973 * Required for MSVC.
3975 Buffer& operator = (Buffer &&buf)
3977 Memory::operator=(std::move(buf));
3981 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3982 /*! \brief Creates a new buffer object from this.
3984 * Wraps clCreateSubBuffer().
3986 Buffer createSubBuffer(
3988 cl_buffer_create_type buffer_create_type,
3989 const void * buffer_create_info,
3990 cl_int * err = NULL)
3994 result.object_ = ::clCreateSubBuffer(
4001 detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
4008 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
4011 #if defined (CL_HPP_USE_DX_INTEROP)
4012 /*! \brief Class interface for creating OpenCL buffers from ID3D10Buffer's.
4014 * This is provided to facilitate interoperability with Direct3D.
4016 * See Memory for details about copy semantics, etc.
4020 class BufferD3D10 : public Buffer
4025 /*! \brief Constructs a BufferD3D10, in a specified context, from a
4026 * given ID3D10Buffer.
4028 * Wraps clCreateFromD3D10BufferKHR().
4031 const Context& context,
4033 ID3D10Buffer* bufobj,
4034 cl_int * err = NULL) : pfn_clCreateFromD3D10BufferKHR(nullptr)
4036 typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
4037 cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
4038 cl_int* errcode_ret);
4039 PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR;
4040 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4041 vector<cl_context_properties> props = context.getInfo<CL_CONTEXT_PROPERTIES>();
4042 cl_platform platform = -1;
4043 for( int i = 0; i < props.size(); ++i ) {
4044 if( props[i] == CL_CONTEXT_PLATFORM ) {
4045 platform = props[i+1];
4048 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateFromD3D10BufferKHR);
4049 #elif CL_HPP_TARGET_OPENCL_VERSION >= 110
4050 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateFromD3D10BufferKHR);
4054 object_ = pfn_clCreateFromD3D10BufferKHR(
4060 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4066 //! \brief Default constructor - initializes to NULL.
4067 BufferD3D10() : Buffer() { }
4069 /*! \brief Constructor from cl_mem - takes ownership.
4071 * \param retainObject will cause the constructor to retain its cl object.
4072 * Defaults to false to maintain compatibility with
4074 * See Memory for further details.
4076 explicit BufferD3D10(const cl_mem& buffer, bool retainObject = false) :
4077 Buffer(buffer, retainObject) { }
4079 /*! \brief Assignment from cl_mem - performs shallow copy.
4081 * See Memory for further details.
4083 BufferD3D10& operator = (const cl_mem& rhs)
4085 Buffer::operator=(rhs);
4089 /*! \brief Copy constructor to forward copy to the superclass correctly.
4090 * Required for MSVC.
4092 BufferD3D10(const BufferD3D10& buf) :
4095 /*! \brief Copy assignment to forward copy to the superclass correctly.
4096 * Required for MSVC.
4098 BufferD3D10& operator = (const BufferD3D10 &buf)
4100 Buffer::operator=(buf);
4104 /*! \brief Move constructor to forward move to the superclass correctly.
4105 * Required for MSVC.
4107 BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4109 /*! \brief Move assignment to forward move to the superclass correctly.
4110 * Required for MSVC.
4112 BufferD3D10& operator = (BufferD3D10 &&buf)
4114 Buffer::operator=(std::move(buf));
4120 /*! \brief Class interface for GL Buffer Memory Objects.
4122 * This is provided to facilitate interoperability with OpenGL.
4124 * See Memory for details about copy semantics, etc.
4128 class BufferGL : public Buffer
4131 /*! \brief Constructs a BufferGL in a specified context, from a given
4134 * Wraps clCreateFromGLBuffer().
4137 const Context& context,
4140 cl_int * err = NULL)
4143 object_ = ::clCreateFromGLBuffer(
4149 detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4155 //! \brief Default constructor - initializes to NULL.
4156 BufferGL() : Buffer() { }
4158 /*! \brief Constructor from cl_mem - takes ownership.
4160 * \param retainObject will cause the constructor to retain its cl object.
4161 * Defaults to false to maintain compatibility with
4163 * See Memory for further details.
4165 explicit BufferGL(const cl_mem& buffer, bool retainObject = false) :
4166 Buffer(buffer, retainObject) { }
4168 /*! \brief Assignment from cl_mem - performs shallow copy.
4170 * See Memory for further details.
4172 BufferGL& operator = (const cl_mem& rhs)
4174 Buffer::operator=(rhs);
4178 /*! \brief Copy constructor to forward copy to the superclass correctly.
4179 * Required for MSVC.
4181 BufferGL(const BufferGL& buf) : Buffer(buf) {}
4183 /*! \brief Copy assignment to forward copy to the superclass correctly.
4184 * Required for MSVC.
4186 BufferGL& operator = (const BufferGL &buf)
4188 Buffer::operator=(buf);
4192 /*! \brief Move constructor to forward move to the superclass correctly.
4193 * Required for MSVC.
4195 BufferGL(BufferGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4197 /*! \brief Move assignment to forward move to the superclass correctly.
4198 * Required for MSVC.
4200 BufferGL& operator = (BufferGL &&buf)
4202 Buffer::operator=(std::move(buf));
4206 //! \brief Wrapper for clGetGLObjectInfo().
4207 cl_int getObjectInfo(
4208 cl_gl_object_type *type,
4209 cl_GLuint * gl_object_name)
4211 return detail::errHandler(
4212 ::clGetGLObjectInfo(object_,type,gl_object_name),
4213 __GET_GL_OBJECT_INFO_ERR);
4217 /*! \brief Class interface for GL Render Buffer Memory Objects.
4219 * This is provided to facilitate interoperability with OpenGL.
4221 * See Memory for details about copy semantics, etc.
4225 class BufferRenderGL : public Buffer
4228 /*! \brief Constructs a BufferRenderGL in a specified context, from a given
4231 * Wraps clCreateFromGLRenderbuffer().
4234 const Context& context,
4237 cl_int * err = NULL)
4240 object_ = ::clCreateFromGLRenderbuffer(
4246 detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR);
4252 //! \brief Default constructor - initializes to NULL.
4253 BufferRenderGL() : Buffer() { }
4255 /*! \brief Constructor from cl_mem - takes ownership.
4257 * \param retainObject will cause the constructor to retain its cl object.
4258 * Defaults to false to maintain compatibility with
4260 * See Memory for further details.
4262 explicit BufferRenderGL(const cl_mem& buffer, bool retainObject = false) :
4263 Buffer(buffer, retainObject) { }
4265 /*! \brief Assignment from cl_mem - performs shallow copy.
4267 * See Memory for further details.
4269 BufferRenderGL& operator = (const cl_mem& rhs)
4271 Buffer::operator=(rhs);
4275 /*! \brief Copy constructor to forward copy to the superclass correctly.
4276 * Required for MSVC.
4278 BufferRenderGL(const BufferRenderGL& buf) : Buffer(buf) {}
4280 /*! \brief Copy assignment to forward copy to the superclass correctly.
4281 * Required for MSVC.
4283 BufferRenderGL& operator = (const BufferRenderGL &buf)
4285 Buffer::operator=(buf);
4289 /*! \brief Move constructor to forward move to the superclass correctly.
4290 * Required for MSVC.
4292 BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4294 /*! \brief Move assignment to forward move to the superclass correctly.
4295 * Required for MSVC.
4297 BufferRenderGL& operator = (BufferRenderGL &&buf)
4299 Buffer::operator=(std::move(buf));
4303 //! \brief Wrapper for clGetGLObjectInfo().
4304 cl_int getObjectInfo(
4305 cl_gl_object_type *type,
4306 cl_GLuint * gl_object_name)
4308 return detail::errHandler(
4309 ::clGetGLObjectInfo(object_,type,gl_object_name),
4310 __GET_GL_OBJECT_INFO_ERR);
4314 /*! \brief C++ base class for Image Memory objects.
4316 * See Memory for details about copy semantics, etc.
4320 class Image : public Memory
4323 //! \brief Default constructor - initializes to NULL.
4324 Image() : Memory() { }
4326 /*! \brief Constructor from cl_mem - takes ownership.
4328 * \param retainObject will cause the constructor to retain its cl object.
4329 * Defaults to false to maintain compatibility with
4331 * See Memory for further details.
4333 explicit Image(const cl_mem& image, bool retainObject = false) :
4334 Memory(image, retainObject) { }
4336 /*! \brief Assignment from cl_mem - performs shallow copy.
4338 * See Memory for further details.
4340 Image& operator = (const cl_mem& rhs)
4342 Memory::operator=(rhs);
4346 /*! \brief Copy constructor to forward copy to the superclass correctly.
4347 * Required for MSVC.
4349 Image(const Image& img) : Memory(img) {}
4351 /*! \brief Copy assignment to forward copy to the superclass correctly.
4352 * Required for MSVC.
4354 Image& operator = (const Image &img)
4356 Memory::operator=(img);
4360 /*! \brief Move constructor to forward move to the superclass correctly.
4361 * Required for MSVC.
4363 Image(Image&& img) CL_HPP_NOEXCEPT_ : Memory(std::move(img)) {}
4365 /*! \brief Move assignment to forward move to the superclass correctly.
4366 * Required for MSVC.
4368 Image& operator = (Image &&img)
4370 Memory::operator=(std::move(img));
4376 //! \brief Wrapper for clGetImageInfo().
4377 template <typename T>
4378 cl_int getImageInfo(cl_image_info name, T* param) const
4380 return detail::errHandler(
4381 detail::getInfo(&::clGetImageInfo, object_, name, param),
4382 __GET_IMAGE_INFO_ERR);
4385 //! \brief Wrapper for clGetImageInfo() that returns by value.
4386 template <cl_int name> typename
4387 detail::param_traits<detail::cl_image_info, name>::param_type
4388 getImageInfo(cl_int* err = NULL) const
4390 typename detail::param_traits<
4391 detail::cl_image_info, name>::param_type param;
4392 cl_int result = getImageInfo(name, ¶m);
4400 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4401 /*! \brief Class interface for 1D Image Memory objects.
4403 * See Memory for details about copy semantics, etc.
4407 class Image1D : public Image
4410 /*! \brief Constructs a 1D Image in a specified context.
4412 * Wraps clCreateImage().
4415 const Context& context,
4419 void* host_ptr = NULL,
4423 cl_image_desc desc =
4425 CL_MEM_OBJECT_IMAGE1D,
4427 0, 0, 0, 0, 0, 0, 0, 0
4429 object_ = ::clCreateImage(
4437 detail::errHandler(error, __CREATE_IMAGE_ERR);
4443 //! \brief Default constructor - initializes to NULL.
4446 /*! \brief Constructor from cl_mem - takes ownership.
4448 * \param retainObject will cause the constructor to retain its cl object.
4449 * Defaults to false to maintain compatibility with
4451 * See Memory for further details.
4453 explicit Image1D(const cl_mem& image1D, bool retainObject = false) :
4454 Image(image1D, retainObject) { }
4456 /*! \brief Assignment from cl_mem - performs shallow copy.
4458 * See Memory for further details.
4460 Image1D& operator = (const cl_mem& rhs)
4462 Image::operator=(rhs);
4466 /*! \brief Copy constructor to forward copy to the superclass correctly.
4467 * Required for MSVC.
4469 Image1D(const Image1D& img) : Image(img) {}
4471 /*! \brief Copy assignment to forward copy to the superclass correctly.
4472 * Required for MSVC.
4474 Image1D& operator = (const Image1D &img)
4476 Image::operator=(img);
4480 /*! \brief Move constructor to forward move to the superclass correctly.
4481 * Required for MSVC.
4483 Image1D(Image1D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4485 /*! \brief Move assignment to forward move to the superclass correctly.
4486 * Required for MSVC.
4488 Image1D& operator = (Image1D &&img)
4490 Image::operator=(std::move(img));
4496 /*! \class Image1DBuffer
4497 * \brief Image interface for 1D buffer images.
4499 class Image1DBuffer : public Image
4503 const Context& context,
4507 const Buffer &buffer,
4511 cl_image_desc desc =
4513 CL_MEM_OBJECT_IMAGE1D_BUFFER,
4515 0, 0, 0, 0, 0, 0, 0,
4518 object_ = ::clCreateImage(
4526 detail::errHandler(error, __CREATE_IMAGE_ERR);
4534 /*! \brief Constructor from cl_mem - takes ownership.
4536 * \param retainObject will cause the constructor to retain its cl object.
4537 * Defaults to false to maintain compatibility with
4539 * See Memory for further details.
4541 explicit Image1DBuffer(const cl_mem& image1D, bool retainObject = false) :
4542 Image(image1D, retainObject) { }
4544 Image1DBuffer& operator = (const cl_mem& rhs)
4546 Image::operator=(rhs);
4550 /*! \brief Copy constructor to forward copy to the superclass correctly.
4551 * Required for MSVC.
4553 Image1DBuffer(const Image1DBuffer& img) : Image(img) {}
4555 /*! \brief Copy assignment to forward copy to the superclass correctly.
4556 * Required for MSVC.
4558 Image1DBuffer& operator = (const Image1DBuffer &img)
4560 Image::operator=(img);
4564 /*! \brief Move constructor to forward move to the superclass correctly.
4565 * Required for MSVC.
4567 Image1DBuffer(Image1DBuffer&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4569 /*! \brief Move assignment to forward move to the superclass correctly.
4570 * Required for MSVC.
4572 Image1DBuffer& operator = (Image1DBuffer &&img)
4574 Image::operator=(std::move(img));
4580 /*! \class Image1DArray
4581 * \brief Image interface for arrays of 1D images.
4583 class Image1DArray : public Image
4587 const Context& context,
4590 size_type arraySize,
4593 void* host_ptr = NULL,
4597 cl_image_desc desc =
4599 CL_MEM_OBJECT_IMAGE1D_ARRAY,
4601 0, 0, // height, depth (unused)
4606 object_ = ::clCreateImage(
4614 detail::errHandler(error, __CREATE_IMAGE_ERR);
4622 /*! \brief Constructor from cl_mem - takes ownership.
4624 * \param retainObject will cause the constructor to retain its cl object.
4625 * Defaults to false to maintain compatibility with
4627 * See Memory for further details.
4629 explicit Image1DArray(const cl_mem& imageArray, bool retainObject = false) :
4630 Image(imageArray, retainObject) { }
4633 Image1DArray& operator = (const cl_mem& rhs)
4635 Image::operator=(rhs);
4639 /*! \brief Copy constructor to forward copy to the superclass correctly.
4640 * Required for MSVC.
4642 Image1DArray(const Image1DArray& img) : Image(img) {}
4644 /*! \brief Copy assignment to forward copy to the superclass correctly.
4645 * Required for MSVC.
4647 Image1DArray& operator = (const Image1DArray &img)
4649 Image::operator=(img);
4653 /*! \brief Move constructor to forward move to the superclass correctly.
4654 * Required for MSVC.
4656 Image1DArray(Image1DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4658 /*! \brief Move assignment to forward move to the superclass correctly.
4659 * Required for MSVC.
4661 Image1DArray& operator = (Image1DArray &&img)
4663 Image::operator=(std::move(img));
4668 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4671 /*! \brief Class interface for 2D Image Memory objects.
4673 * See Memory for details about copy semantics, etc.
4677 class Image2D : public Image
4680 /*! \brief Constructs a 2D Image in a specified context.
4682 * Wraps clCreateImage().
4685 const Context& context,
4690 size_type row_pitch = 0,
4691 void* host_ptr = NULL,
4695 bool useCreateImage;
4697 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
4698 // Run-time decision based on the actual platform
4700 cl_uint version = detail::getContextPlatformVersion(context());
4701 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
4703 #elif CL_HPP_TARGET_OPENCL_VERSION >= 120
4704 useCreateImage = true;
4706 useCreateImage = false;
4709 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4712 cl_image_desc desc =
4714 CL_MEM_OBJECT_IMAGE2D,
4717 0, 0, // depth, array size (unused)
4721 object_ = ::clCreateImage(
4729 detail::errHandler(error, __CREATE_IMAGE_ERR);
4734 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
4735 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
4736 if (!useCreateImage)
4738 object_ = ::clCreateImage2D(
4739 context(), flags,&format, width, height, row_pitch, host_ptr, &error);
4741 detail::errHandler(error, __CREATE_IMAGE2D_ERR);
4746 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
4749 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4750 /*! \brief Constructs a 2D Image from a buffer.
4751 * \note This will share storage with the underlying buffer.
4753 * Wraps clCreateImage().
4756 const Context& context,
4758 const Buffer &sourceBuffer,
4761 size_type row_pitch = 0,
4762 cl_int* err = nullptr)
4766 cl_image_desc desc =
4768 CL_MEM_OBJECT_IMAGE2D,
4771 0, 0, // depth, array size (unused)
4774 // Use buffer as input to image
4777 object_ = ::clCreateImage(
4779 0, // flags inherited from buffer
4785 detail::errHandler(error, __CREATE_IMAGE_ERR);
4786 if (err != nullptr) {
4790 #endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4792 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
4793 /*! \brief Constructs a 2D Image from an image.
4794 * \note This will share storage with the underlying image but may
4795 * reinterpret the channel order and type.
4797 * The image will be created matching with a descriptor matching the source.
4799 * \param order is the channel order to reinterpret the image data as.
4800 * The channel order may differ as described in the OpenCL
4801 * 2.0 API specification.
4803 * Wraps clCreateImage().
4806 const Context& context,
4807 cl_channel_order order,
4808 const Image &sourceImage,
4809 cl_int* err = nullptr)
4813 // Descriptor fields have to match source image
4814 size_type sourceWidth =
4815 sourceImage.getImageInfo<CL_IMAGE_WIDTH>();
4816 size_type sourceHeight =
4817 sourceImage.getImageInfo<CL_IMAGE_HEIGHT>();
4818 size_type sourceRowPitch =
4819 sourceImage.getImageInfo<CL_IMAGE_ROW_PITCH>();
4820 cl_uint sourceNumMIPLevels =
4821 sourceImage.getImageInfo<CL_IMAGE_NUM_MIP_LEVELS>();
4822 cl_uint sourceNumSamples =
4823 sourceImage.getImageInfo<CL_IMAGE_NUM_SAMPLES>();
4824 cl_image_format sourceFormat =
4825 sourceImage.getImageInfo<CL_IMAGE_FORMAT>();
4827 // Update only the channel order.
4828 // Channel format inherited from source.
4829 sourceFormat.image_channel_order = order;
4830 cl_image_desc desc =
4832 CL_MEM_OBJECT_IMAGE2D,
4835 0, 0, // depth (unused), array size (unused)
4837 0, // slice pitch (unused)
4840 // Use buffer as input to image
4843 object_ = ::clCreateImage(
4845 0, // flags should be inherited from mem_object
4851 detail::errHandler(error, __CREATE_IMAGE_ERR);
4852 if (err != nullptr) {
4856 #endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200
4858 //! \brief Default constructor - initializes to NULL.
4861 /*! \brief Constructor from cl_mem - takes ownership.
4863 * \param retainObject will cause the constructor to retain its cl object.
4864 * Defaults to false to maintain compatibility with
4866 * See Memory for further details.
4868 explicit Image2D(const cl_mem& image2D, bool retainObject = false) :
4869 Image(image2D, retainObject) { }
4871 /*! \brief Assignment from cl_mem - performs shallow copy.
4873 * See Memory for further details.
4875 Image2D& operator = (const cl_mem& rhs)
4877 Image::operator=(rhs);
4881 /*! \brief Copy constructor to forward copy to the superclass correctly.
4882 * Required for MSVC.
4884 Image2D(const Image2D& img) : Image(img) {}
4886 /*! \brief Copy assignment to forward copy to the superclass correctly.
4887 * Required for MSVC.
4889 Image2D& operator = (const Image2D &img)
4891 Image::operator=(img);
4895 /*! \brief Move constructor to forward move to the superclass correctly.
4896 * Required for MSVC.
4898 Image2D(Image2D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4900 /*! \brief Move assignment to forward move to the superclass correctly.
4901 * Required for MSVC.
4903 Image2D& operator = (Image2D &&img)
4905 Image::operator=(std::move(img));
4912 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
4913 /*! \brief Class interface for GL 2D Image Memory objects.
4915 * This is provided to facilitate interoperability with OpenGL.
4917 * See Memory for details about copy semantics, etc.
4920 * \note Deprecated for OpenCL 1.2. Please use ImageGL instead.
4922 class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED Image2DGL : public Image2D
4925 /*! \brief Constructs an Image2DGL in a specified context, from a given
4928 * Wraps clCreateFromGLTexture2D().
4931 const Context& context,
4936 cl_int * err = NULL)
4939 object_ = ::clCreateFromGLTexture2D(
4947 detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR);
4954 //! \brief Default constructor - initializes to NULL.
4955 Image2DGL() : Image2D() { }
4957 /*! \brief Constructor from cl_mem - takes ownership.
4959 * \param retainObject will cause the constructor to retain its cl object.
4960 * Defaults to false to maintain compatibility with
4962 * See Memory for further details.
4964 explicit Image2DGL(const cl_mem& image, bool retainObject = false) :
4965 Image2D(image, retainObject) { }
4967 /*! \brief Assignment from cl_mem - performs shallow copy.
4969 * See Memory for further details.
4971 Image2DGL& operator = (const cl_mem& rhs)
4973 Image2D::operator=(rhs);
4977 /*! \brief Copy constructor to forward copy to the superclass correctly.
4978 * Required for MSVC.
4980 Image2DGL(const Image2DGL& img) : Image2D(img) {}
4982 /*! \brief Copy assignment to forward copy to the superclass correctly.
4983 * Required for MSVC.
4985 Image2DGL& operator = (const Image2DGL &img)
4987 Image2D::operator=(img);
4991 /*! \brief Move constructor to forward move to the superclass correctly.
4992 * Required for MSVC.
4994 Image2DGL(Image2DGL&& img) CL_HPP_NOEXCEPT_ : Image2D(std::move(img)) {}
4996 /*! \brief Move assignment to forward move to the superclass correctly.
4997 * Required for MSVC.
4999 Image2DGL& operator = (Image2DGL &&img)
5001 Image2D::operator=(std::move(img));
5005 } CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
5006 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5008 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5009 /*! \class Image2DArray
5010 * \brief Image interface for arrays of 2D images.
5012 class Image2DArray : public Image
5016 const Context& context,
5019 size_type arraySize,
5023 size_type slicePitch,
5024 void* host_ptr = NULL,
5028 cl_image_desc desc =
5030 CL_MEM_OBJECT_IMAGE2D_ARRAY,
5033 0, // depth (unused)
5039 object_ = ::clCreateImage(
5047 detail::errHandler(error, __CREATE_IMAGE_ERR);
5055 /*! \brief Constructor from cl_mem - takes ownership.
5057 * \param retainObject will cause the constructor to retain its cl object.
5058 * Defaults to false to maintain compatibility with
5060 * See Memory for further details.
5062 explicit Image2DArray(const cl_mem& imageArray, bool retainObject = false) : Image(imageArray, retainObject) { }
5064 Image2DArray& operator = (const cl_mem& rhs)
5066 Image::operator=(rhs);
5070 /*! \brief Copy constructor to forward copy to the superclass correctly.
5071 * Required for MSVC.
5073 Image2DArray(const Image2DArray& img) : Image(img) {}
5075 /*! \brief Copy assignment to forward copy to the superclass correctly.
5076 * Required for MSVC.
5078 Image2DArray& operator = (const Image2DArray &img)
5080 Image::operator=(img);
5084 /*! \brief Move constructor to forward move to the superclass correctly.
5085 * Required for MSVC.
5087 Image2DArray(Image2DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5089 /*! \brief Move assignment to forward move to the superclass correctly.
5090 * Required for MSVC.
5092 Image2DArray& operator = (Image2DArray &&img)
5094 Image::operator=(std::move(img));
5098 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5100 /*! \brief Class interface for 3D Image Memory objects.
5102 * See Memory for details about copy semantics, etc.
5106 class Image3D : public Image
5109 /*! \brief Constructs a 3D Image in a specified context.
5111 * Wraps clCreateImage().
5114 const Context& context,
5120 size_type row_pitch = 0,
5121 size_type slice_pitch = 0,
5122 void* host_ptr = NULL,
5126 bool useCreateImage;
5128 #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
5129 // Run-time decision based on the actual platform
5131 cl_uint version = detail::getContextPlatformVersion(context());
5132 useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
5134 #elif CL_HPP_TARGET_OPENCL_VERSION >= 120
5135 useCreateImage = true;
5137 useCreateImage = false;
5140 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5143 cl_image_desc desc =
5145 CL_MEM_OBJECT_IMAGE3D,
5149 0, // array size (unused)
5154 object_ = ::clCreateImage(
5162 detail::errHandler(error, __CREATE_IMAGE_ERR);
5167 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5168 #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
5169 if (!useCreateImage)
5171 object_ = ::clCreateImage3D(
5172 context(), flags, &format, width, height, depth, row_pitch,
5173 slice_pitch, host_ptr, &error);
5175 detail::errHandler(error, __CREATE_IMAGE3D_ERR);
5180 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
5183 //! \brief Default constructor - initializes to NULL.
5184 Image3D() : Image() { }
5186 /*! \brief Constructor from cl_mem - takes ownership.
5188 * \param retainObject will cause the constructor to retain its cl object.
5189 * Defaults to false to maintain compatibility with
5191 * See Memory for further details.
5193 explicit Image3D(const cl_mem& image3D, bool retainObject = false) :
5194 Image(image3D, retainObject) { }
5196 /*! \brief Assignment from cl_mem - performs shallow copy.
5198 * See Memory for further details.
5200 Image3D& operator = (const cl_mem& rhs)
5202 Image::operator=(rhs);
5206 /*! \brief Copy constructor to forward copy to the superclass correctly.
5207 * Required for MSVC.
5209 Image3D(const Image3D& img) : Image(img) {}
5211 /*! \brief Copy assignment to forward copy to the superclass correctly.
5212 * Required for MSVC.
5214 Image3D& operator = (const Image3D &img)
5216 Image::operator=(img);
5220 /*! \brief Move constructor to forward move to the superclass correctly.
5221 * Required for MSVC.
5223 Image3D(Image3D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5225 /*! \brief Move assignment to forward move to the superclass correctly.
5226 * Required for MSVC.
5228 Image3D& operator = (Image3D &&img)
5230 Image::operator=(std::move(img));
5235 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
5236 /*! \brief Class interface for GL 3D Image Memory objects.
5238 * This is provided to facilitate interoperability with OpenGL.
5240 * See Memory for details about copy semantics, etc.
5244 class Image3DGL : public Image3D
5247 /*! \brief Constructs an Image3DGL in a specified context, from a given
5250 * Wraps clCreateFromGLTexture3D().
5253 const Context& context,
5258 cl_int * err = NULL)
5261 object_ = ::clCreateFromGLTexture3D(
5269 detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR);
5275 //! \brief Default constructor - initializes to NULL.
5276 Image3DGL() : Image3D() { }
5278 /*! \brief Constructor from cl_mem - takes ownership.
5280 * \param retainObject will cause the constructor to retain its cl object.
5281 * Defaults to false to maintain compatibility with
5283 * See Memory for further details.
5285 explicit Image3DGL(const cl_mem& image, bool retainObject = false) :
5286 Image3D(image, retainObject) { }
5288 /*! \brief Assignment from cl_mem - performs shallow copy.
5290 * See Memory for further details.
5292 Image3DGL& operator = (const cl_mem& rhs)
5294 Image3D::operator=(rhs);
5298 /*! \brief Copy constructor to forward copy to the superclass correctly.
5299 * Required for MSVC.
5301 Image3DGL(const Image3DGL& img) : Image3D(img) {}
5303 /*! \brief Copy assignment to forward copy to the superclass correctly.
5304 * Required for MSVC.
5306 Image3DGL& operator = (const Image3DGL &img)
5308 Image3D::operator=(img);
5312 /*! \brief Move constructor to forward move to the superclass correctly.
5313 * Required for MSVC.
5315 Image3DGL(Image3DGL&& img) CL_HPP_NOEXCEPT_ : Image3D(std::move(img)) {}
5317 /*! \brief Move assignment to forward move to the superclass correctly.
5318 * Required for MSVC.
5320 Image3DGL& operator = (Image3DGL &&img)
5322 Image3D::operator=(std::move(img));
5326 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5328 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5330 * \brief general image interface for GL interop.
5331 * We abstract the 2D and 3D GL images into a single instance here
5332 * that wraps all GL sourced images on the grounds that setup information
5333 * was performed by OpenCL anyway.
5335 class ImageGL : public Image
5339 const Context& context,
5344 cl_int * err = NULL)
5347 object_ = ::clCreateFromGLTexture(
5355 detail::errHandler(error, __CREATE_GL_TEXTURE_ERR);
5361 ImageGL() : Image() { }
5363 /*! \brief Constructor from cl_mem - takes ownership.
5365 * \param retainObject will cause the constructor to retain its cl object.
5366 * Defaults to false to maintain compatibility with
5368 * See Memory for further details.
5370 explicit ImageGL(const cl_mem& image, bool retainObject = false) :
5371 Image(image, retainObject) { }
5373 ImageGL& operator = (const cl_mem& rhs)
5375 Image::operator=(rhs);
5379 /*! \brief Copy constructor to forward copy to the superclass correctly.
5380 * Required for MSVC.
5382 ImageGL(const ImageGL& img) : Image(img) {}
5384 /*! \brief Copy assignment to forward copy to the superclass correctly.
5385 * Required for MSVC.
5387 ImageGL& operator = (const ImageGL &img)
5389 Image::operator=(img);
5393 /*! \brief Move constructor to forward move to the superclass correctly.
5394 * Required for MSVC.
5396 ImageGL(ImageGL&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5398 /*! \brief Move assignment to forward move to the superclass correctly.
5399 * Required for MSVC.
5401 ImageGL& operator = (ImageGL &&img)
5403 Image::operator=(std::move(img));
5407 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5411 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5412 /*! \brief Class interface for Pipe Memory Objects.
5414 * See Memory for details about copy semantics, etc.
5418 class Pipe : public Memory
5422 /*! \brief Constructs a Pipe in a specified context.
5424 * Wraps clCreatePipe().
5425 * @param context Context in which to create the pipe.
5426 * @param flags Bitfield. Only CL_MEM_READ_WRITE and CL_MEM_HOST_NO_ACCESS are valid.
5427 * @param packet_size Size in bytes of a single packet of the pipe.
5428 * @param max_packets Number of packets that may be stored in the pipe.
5432 const Context& context,
5433 cl_uint packet_size,
5434 cl_uint max_packets,
5439 cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5440 object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error);
5442 detail::errHandler(error, __CREATE_PIPE_ERR);
5448 /*! \brief Constructs a Pipe in a the default context.
5450 * Wraps clCreatePipe().
5451 * @param flags Bitfield. Only CL_MEM_READ_WRITE and CL_MEM_HOST_NO_ACCESS are valid.
5452 * @param packet_size Size in bytes of a single packet of the pipe.
5453 * @param max_packets Number of packets that may be stored in the pipe.
5457 cl_uint packet_size,
5458 cl_uint max_packets,
5463 Context context = Context::getDefault(err);
5465 cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5466 object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error);
5468 detail::errHandler(error, __CREATE_PIPE_ERR);
5474 //! \brief Default constructor - initializes to NULL.
5475 Pipe() : Memory() { }
5477 /*! \brief Constructor from cl_mem - takes ownership.
5479 * \param retainObject will cause the constructor to retain its cl object.
5480 * Defaults to false to maintain compatibility with earlier versions.
5482 * See Memory for further details.
5484 explicit Pipe(const cl_mem& pipe, bool retainObject = false) :
5485 Memory(pipe, retainObject) { }
5487 /*! \brief Assignment from cl_mem - performs shallow copy.
5489 * See Memory for further details.
5491 Pipe& operator = (const cl_mem& rhs)
5493 Memory::operator=(rhs);
5497 /*! \brief Copy constructor to forward copy to the superclass correctly.
5498 * Required for MSVC.
5500 Pipe(const Pipe& pipe) : Memory(pipe) {}
5502 /*! \brief Copy assignment to forward copy to the superclass correctly.
5503 * Required for MSVC.
5505 Pipe& operator = (const Pipe &pipe)
5507 Memory::operator=(pipe);
5511 /*! \brief Move constructor to forward move to the superclass correctly.
5512 * Required for MSVC.
5514 Pipe(Pipe&& pipe) CL_HPP_NOEXCEPT_ : Memory(std::move(pipe)) {}
5516 /*! \brief Move assignment to forward move to the superclass correctly.
5517 * Required for MSVC.
5519 Pipe& operator = (Pipe &&pipe)
5521 Memory::operator=(std::move(pipe));
5525 //! \brief Wrapper for clGetMemObjectInfo().
5526 template <typename T>
5527 cl_int getInfo(cl_pipe_info name, T* param) const
5529 return detail::errHandler(
5530 detail::getInfo(&::clGetPipeInfo, object_, name, param),
5531 __GET_PIPE_INFO_ERR);
5534 //! \brief Wrapper for clGetMemObjectInfo() that returns by value.
5535 template <cl_int name> typename
5536 detail::param_traits<detail::cl_pipe_info, name>::param_type
5537 getInfo(cl_int* err = NULL) const
5539 typename detail::param_traits<
5540 detail::cl_pipe_info, name>::param_type param;
5541 cl_int result = getInfo(name, ¶m);
5548 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
5551 /*! \brief Class interface for cl_sampler.
5553 * \note Copies of these objects are shallow, meaning that the copy will refer
5554 * to the same underlying cl_sampler as the original. For details, see
5555 * clRetainSampler() and clReleaseSampler().
5559 class Sampler : public detail::Wrapper<cl_sampler>
5562 //! \brief Default constructor - initializes to NULL.
5565 /*! \brief Constructs a Sampler in a specified context.
5567 * Wraps clCreateSampler().
5570 const Context& context,
5571 cl_bool normalized_coords,
5572 cl_addressing_mode addressing_mode,
5573 cl_filter_mode filter_mode,
5578 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5579 cl_sampler_properties sampler_properties[] = {
5580 CL_SAMPLER_NORMALIZED_COORDS, normalized_coords,
5581 CL_SAMPLER_ADDRESSING_MODE, addressing_mode,
5582 CL_SAMPLER_FILTER_MODE, filter_mode,
5584 object_ = ::clCreateSamplerWithProperties(
5589 detail::errHandler(error, __CREATE_SAMPLER_WITH_PROPERTIES_ERR);
5594 object_ = ::clCreateSampler(
5601 detail::errHandler(error, __CREATE_SAMPLER_ERR);
5608 /*! \brief Constructor from cl_sampler - takes ownership.
5610 * \param retainObject will cause the constructor to retain its cl object.
5611 * Defaults to false to maintain compatibility with
5613 * This effectively transfers ownership of a refcount on the cl_sampler
5614 * into the new Sampler object.
5616 explicit Sampler(const cl_sampler& sampler, bool retainObject = false) :
5617 detail::Wrapper<cl_type>(sampler, retainObject) { }
5619 /*! \brief Assignment operator from cl_sampler - takes ownership.
5621 * This effectively transfers ownership of a refcount on the rhs and calls
5622 * clReleaseSampler() on the value previously held by this instance.
5624 Sampler& operator = (const cl_sampler& rhs)
5626 detail::Wrapper<cl_type>::operator=(rhs);
5630 /*! \brief Copy constructor to forward copy to the superclass correctly.
5631 * Required for MSVC.
5633 Sampler(const Sampler& sam) : detail::Wrapper<cl_type>(sam) {}
5635 /*! \brief Copy assignment to forward copy to the superclass correctly.
5636 * Required for MSVC.
5638 Sampler& operator = (const Sampler &sam)
5640 detail::Wrapper<cl_type>::operator=(sam);
5644 /*! \brief Move constructor to forward move to the superclass correctly.
5645 * Required for MSVC.
5647 Sampler(Sampler&& sam) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(sam)) {}
5649 /*! \brief Move assignment to forward move to the superclass correctly.
5650 * Required for MSVC.
5652 Sampler& operator = (Sampler &&sam)
5654 detail::Wrapper<cl_type>::operator=(std::move(sam));
5658 //! \brief Wrapper for clGetSamplerInfo().
5659 template <typename T>
5660 cl_int getInfo(cl_sampler_info name, T* param) const
5662 return detail::errHandler(
5663 detail::getInfo(&::clGetSamplerInfo, object_, name, param),
5664 __GET_SAMPLER_INFO_ERR);
5667 //! \brief Wrapper for clGetSamplerInfo() that returns by value.
5668 template <cl_int name> typename
5669 detail::param_traits<detail::cl_sampler_info, name>::param_type
5670 getInfo(cl_int* err = NULL) const
5672 typename detail::param_traits<
5673 detail::cl_sampler_info, name>::param_type param;
5674 cl_int result = getInfo(name, ¶m);
5684 class DeviceCommandQueue;
5687 //! \brief Class interface for specifying NDRange values.
5691 size_type sizes_[3];
5692 cl_uint dimensions_;
5695 //! \brief Default constructor - resulting range has zero dimensions.
5704 //! \brief Constructs one-dimensional range.
5705 NDRange(size_type size0)
5713 //! \brief Constructs two-dimensional range.
5714 NDRange(size_type size0, size_type size1)
5722 //! \brief Constructs three-dimensional range.
5723 NDRange(size_type size0, size_type size1, size_type size2)
5731 /*! \brief Conversion operator to const size_type *.
5733 * \returns a pointer to the size of the first dimension.
5735 operator const size_type*() const {
5739 //! \brief Queries the number of dimensions in the range.
5740 size_type dimensions() const
5745 //! \brief Returns the size of the object in bytes based on the
5746 // runtime number of dimensions
5747 size_type size() const
5749 return dimensions_*sizeof(size_type);
5757 const size_type* get() const
5763 //! \brief A zero-dimensional range.
5764 static const NDRange NullRange;
5766 //! \brief Local address wrapper for use with Kernel::setArg
5767 struct LocalSpaceArg
5774 template <typename T, class Enable = void>
5775 struct KernelArgumentHandler;
5777 // Enable for objects that are not subclasses of memory
5778 // Pointers, constants etc
5779 template <typename T>
5780 struct KernelArgumentHandler<T, typename std::enable_if<!std::is_base_of<cl::Memory, T>::value>::type>
5782 static size_type size(const T&) { return sizeof(T); }
5783 static const T* ptr(const T& value) { return &value; }
5786 // Enable for subclasses of memory where we want to get a reference to the cl_mem out
5787 // and pass that in for safety
5788 template <typename T>
5789 struct KernelArgumentHandler<T, typename std::enable_if<std::is_base_of<cl::Memory, T>::value>::type>
5791 static size_type size(const T&) { return sizeof(cl_mem); }
5792 static const cl_mem* ptr(const T& value) { return &(value()); }
5795 // Specialization for DeviceCommandQueue defined later
5798 struct KernelArgumentHandler<LocalSpaceArg, void>
5800 static size_type size(const LocalSpaceArg& value) { return value.size_; }
5801 static const void* ptr(const LocalSpaceArg&) { return NULL; }
5808 * \brief Helper function for generating LocalSpaceArg objects.
5810 inline LocalSpaceArg
5811 Local(size_type size)
5813 LocalSpaceArg ret = { size };
5817 /*! \brief Class interface for cl_kernel.
5819 * \note Copies of these objects are shallow, meaning that the copy will refer
5820 * to the same underlying cl_kernel as the original. For details, see
5821 * clRetainKernel() and clReleaseKernel().
5825 class Kernel : public detail::Wrapper<cl_kernel>
5828 inline Kernel(const Program& program, const char* name, cl_int* err = NULL);
5830 //! \brief Default constructor - initializes to NULL.
5833 /*! \brief Constructor from cl_kernel - takes ownership.
5835 * \param retainObject will cause the constructor to retain its cl object.
5836 * Defaults to false to maintain compatibility with
5838 * This effectively transfers ownership of a refcount on the cl_kernel
5839 * into the new Kernel object.
5841 explicit Kernel(const cl_kernel& kernel, bool retainObject = false) :
5842 detail::Wrapper<cl_type>(kernel, retainObject) { }
5844 /*! \brief Assignment operator from cl_kernel - takes ownership.
5846 * This effectively transfers ownership of a refcount on the rhs and calls
5847 * clReleaseKernel() on the value previously held by this instance.
5849 Kernel& operator = (const cl_kernel& rhs)
5851 detail::Wrapper<cl_type>::operator=(rhs);
5855 /*! \brief Copy constructor to forward copy to the superclass correctly.
5856 * Required for MSVC.
5858 Kernel(const Kernel& kernel) : detail::Wrapper<cl_type>(kernel) {}
5860 /*! \brief Copy assignment to forward copy to the superclass correctly.
5861 * Required for MSVC.
5863 Kernel& operator = (const Kernel &kernel)
5865 detail::Wrapper<cl_type>::operator=(kernel);
5869 /*! \brief Move constructor to forward move to the superclass correctly.
5870 * Required for MSVC.
5872 Kernel(Kernel&& kernel) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(kernel)) {}
5874 /*! \brief Move assignment to forward move to the superclass correctly.
5875 * Required for MSVC.
5877 Kernel& operator = (Kernel &&kernel)
5879 detail::Wrapper<cl_type>::operator=(std::move(kernel));
5883 template <typename T>
5884 cl_int getInfo(cl_kernel_info name, T* param) const
5886 return detail::errHandler(
5887 detail::getInfo(&::clGetKernelInfo, object_, name, param),
5888 __GET_KERNEL_INFO_ERR);
5891 template <cl_int name> typename
5892 detail::param_traits<detail::cl_kernel_info, name>::param_type
5893 getInfo(cl_int* err = NULL) const
5895 typename detail::param_traits<
5896 detail::cl_kernel_info, name>::param_type param;
5897 cl_int result = getInfo(name, ¶m);
5904 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5905 template <typename T>
5906 cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const
5908 return detail::errHandler(
5909 detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param),
5910 __GET_KERNEL_ARG_INFO_ERR);
5913 template <cl_int name> typename
5914 detail::param_traits<detail::cl_kernel_arg_info, name>::param_type
5915 getArgInfo(cl_uint argIndex, cl_int* err = NULL) const
5917 typename detail::param_traits<
5918 detail::cl_kernel_arg_info, name>::param_type param;
5919 cl_int result = getArgInfo(argIndex, name, ¶m);
5925 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5927 template <typename T>
5928 cl_int getWorkGroupInfo(
5929 const Device& device, cl_kernel_work_group_info name, T* param) const
5931 return detail::errHandler(
5933 &::clGetKernelWorkGroupInfo, object_, device(), name, param),
5934 __GET_KERNEL_WORK_GROUP_INFO_ERR);
5937 template <cl_int name> typename
5938 detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
5939 getWorkGroupInfo(const Device& device, cl_int* err = NULL) const
5941 typename detail::param_traits<
5942 detail::cl_kernel_work_group_info, name>::param_type param;
5943 cl_int result = getWorkGroupInfo(device, name, ¶m);
5950 #if (CL_HPP_TARGET_OPENCL_VERSION >= 200 && defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)) || CL_HPP_TARGET_OPENCL_VERSION >= 210
5951 cl_int getSubGroupInfo(const cl::Device &dev, cl_kernel_sub_group_info name, const cl::NDRange &range, size_type* param) const
5953 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
5955 return detail::errHandler(
5956 clGetKernelSubGroupInfo(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
5957 __GET_KERNEL_SUB_GROUP_INFO_ERR);
5959 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
5961 typedef clGetKernelSubGroupInfoKHR_fn PFN_clGetKernelSubGroupInfoKHR;
5962 static PFN_clGetKernelSubGroupInfoKHR pfn_clGetKernelSubGroupInfoKHR = NULL;
5963 CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetKernelSubGroupInfoKHR);
5965 return detail::errHandler(
5966 pfn_clGetKernelSubGroupInfoKHR(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
5967 __GET_KERNEL_SUB_GROUP_INFO_ERR);
5969 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
5972 template <cl_int name>
5973 size_type getSubGroupInfo(const cl::Device &dev, const cl::NDRange &range, cl_int* err = NULL) const
5976 cl_int result = getSubGroupInfo(dev, name, range, ¶m);
5982 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5984 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5985 /*! \brief setArg overload taking a shared_ptr type
5987 template<typename T, class D>
5988 cl_int setArg(cl_uint index, const cl::pointer<T, D> &argPtr)
5990 return detail::errHandler(
5991 ::clSetKernelArgSVMPointer(object_, index, argPtr.get()),
5992 __SET_KERNEL_ARGS_ERR);
5995 /*! \brief setArg overload taking a vector type.
5997 template<typename T, class Alloc>
5998 cl_int setArg(cl_uint index, const cl::vector<T, Alloc> &argPtr)
6000 return detail::errHandler(
6001 ::clSetKernelArgSVMPointer(object_, index, argPtr.data()),
6002 __SET_KERNEL_ARGS_ERR);
6005 /*! \brief setArg overload taking a pointer type
6007 template<typename T>
6008 typename std::enable_if<std::is_pointer<T>::value, cl_int>::type
6009 setArg(cl_uint index, const T argPtr)
6011 return detail::errHandler(
6012 ::clSetKernelArgSVMPointer(object_, index, argPtr),
6013 __SET_KERNEL_ARGS_ERR);
6015 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6017 /*! \brief setArg overload taking a POD type
6019 template <typename T>
6020 typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6021 setArg(cl_uint index, const T &value)
6023 return detail::errHandler(
6027 detail::KernelArgumentHandler<T>::size(value),
6028 detail::KernelArgumentHandler<T>::ptr(value)),
6029 __SET_KERNEL_ARGS_ERR);
6032 cl_int setArg(cl_uint index, size_type size, const void* argPtr)
6034 return detail::errHandler(
6035 ::clSetKernelArg(object_, index, size, argPtr),
6036 __SET_KERNEL_ARGS_ERR);
6039 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6041 * Specify a vector of SVM pointers that the kernel may access in
6042 * addition to its arguments.
6044 cl_int setSVMPointers(const vector<void*> &pointerList)
6046 return detail::errHandler(
6047 ::clSetKernelExecInfo(
6049 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6050 sizeof(void*)*pointerList.size(),
6051 pointerList.data()));
6055 * Specify a std::array of SVM pointers that the kernel may access in
6056 * addition to its arguments.
6058 template<int ArrayLength>
6059 cl_int setSVMPointers(const std::array<void*, ArrayLength> &pointerList)
6061 return detail::errHandler(
6062 ::clSetKernelExecInfo(
6064 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6065 sizeof(void*)*pointerList.size(),
6066 pointerList.data()));
6069 /*! \brief Enable fine-grained system SVM.
6071 * \note It is only possible to enable fine-grained system SVM if all devices
6072 * in the context associated with kernel support it.
6074 * \param svmEnabled True if fine-grained system SVM is requested. False otherwise.
6075 * \return CL_SUCCESS if the function was executed succesfully. CL_INVALID_OPERATION
6076 * if no devices in the context support fine-grained system SVM.
6078 * \see clSetKernelExecInfo
6080 cl_int enableFineGrainedSystemSVM(bool svmEnabled)
6082 cl_bool svmEnabled_ = svmEnabled ? CL_TRUE : CL_FALSE;
6083 return detail::errHandler(
6084 ::clSetKernelExecInfo(
6086 CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM,
6093 template<int index, int ArrayLength, class D, typename T0, typename T1, typename... Ts>
6094 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0, const pointer<T1, D> &t1, Ts & ... ts)
6096 pointerList[index] = static_cast<void*>(t0.get());
6097 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6100 template<int index, int ArrayLength, typename T0, typename T1, typename... Ts>
6101 typename std::enable_if<std::is_pointer<T0>::value, void>::type
6102 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0, T1 t1, Ts... ts)
6104 pointerList[index] = static_cast<void*>(t0);
6105 setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6108 template<int index, int ArrayLength, typename T0, class D>
6109 void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0)
6111 pointerList[index] = static_cast<void*>(t0.get());
6115 template<int index, int ArrayLength, typename T0>
6116 typename std::enable_if<std::is_pointer<T0>::value, void>::type
6117 setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0)
6119 pointerList[index] = static_cast<void*>(t0);
6122 template<typename T0, typename... Ts>
6123 cl_int setSVMPointers(const T0 &t0, Ts & ... ts)
6125 std::array<void*, 1 + sizeof...(Ts)> pointerList;
6127 setSVMPointersHelper<0, 1 + sizeof...(Ts)>(pointerList, t0, ts...);
6128 return detail::errHandler(
6129 ::clSetKernelExecInfo(
6131 CL_KERNEL_EXEC_INFO_SVM_PTRS,
6132 sizeof(void*)*(1 + sizeof...(Ts)),
6133 pointerList.data()));
6135 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6137 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6139 * Make a deep copy of the kernel object including its arguments.
6140 * @return A new kernel object with internal state entirely separate from that
6141 * of the original but with any arguments set on the original intact.
6146 Kernel retValue(clCloneKernel(this->get(), &error));
6148 detail::errHandler(error, __CLONE_KERNEL_ERR);
6151 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6155 * \brief Program interface that implements cl_program.
6157 class Program : public detail::Wrapper<cl_program>
6160 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6161 typedef vector<vector<unsigned char>> Binaries;
6162 typedef vector<string> Sources;
6163 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6164 typedef vector<std::pair<const void*, size_type> > Binaries;
6165 typedef vector<std::pair<const char*, size_type> > Sources;
6166 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6169 const string& source,
6175 const char * strings = source.c_str();
6176 const size_type length = source.size();
6178 Context context = Context::getDefault(err);
6180 object_ = ::clCreateProgramWithSource(
6181 context(), (cl_uint)1, &strings, &length, &error);
6183 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6185 if (error == CL_SUCCESS && build) {
6187 error = ::clBuildProgram(
6191 #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6195 #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6199 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6208 const Context& context,
6209 const string& source,
6215 const char * strings = source.c_str();
6216 const size_type length = source.size();
6218 object_ = ::clCreateProgramWithSource(
6219 context(), (cl_uint)1, &strings, &length, &error);
6221 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6223 if (error == CL_SUCCESS && build) {
6224 error = ::clBuildProgram(
6228 #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6232 #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6236 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6245 * Create a program from a vector of source strings and the default context.
6246 * Does not compile or link the program.
6249 const Sources& sources,
6253 Context context = Context::getDefault(err);
6255 const size_type n = (size_type)sources.size();
6257 vector<size_type> lengths(n);
6258 vector<const char*> strings(n);
6260 for (size_type i = 0; i < n; ++i) {
6261 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6262 strings[i] = sources[(int)i].data();
6263 lengths[i] = sources[(int)i].length();
6264 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6265 strings[i] = sources[(int)i].first;
6266 lengths[i] = sources[(int)i].second;
6267 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6270 object_ = ::clCreateProgramWithSource(
6271 context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6273 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6280 * Create a program from a vector of source strings and a provided context.
6281 * Does not compile or link the program.
6284 const Context& context,
6285 const Sources& sources,
6290 const size_type n = (size_type)sources.size();
6292 vector<size_type> lengths(n);
6293 vector<const char*> strings(n);
6295 for (size_type i = 0; i < n; ++i) {
6296 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6297 strings[i] = sources[(int)i].data();
6298 lengths[i] = sources[(int)i].length();
6299 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6300 strings[i] = sources[(int)i].first;
6301 lengths[i] = sources[(int)i].second;
6302 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6305 object_ = ::clCreateProgramWithSource(
6306 context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6308 detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6315 #if CL_HPP_TARGET_OPENCL_VERSION >= 210 || (CL_HPP_TARGET_OPENCL_VERSION==200 && defined(CL_HPP_USE_IL_KHR))
6317 * Program constructor to allow construction of program from SPIR-V or another IL.
6318 * Valid for either OpenCL >= 2.1 or when CL_HPP_USE_IL_KHR is defined.
6321 const vector<char>& IL,
6327 Context context = Context::getDefault(err);
6329 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6331 object_ = ::clCreateProgramWithIL(
6332 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6334 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6336 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6337 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6338 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6340 return detail::errHandler(
6341 pfn_clCreateProgramWithILKHR(
6342 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6344 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6346 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6348 if (error == CL_SUCCESS && build) {
6350 error = ::clBuildProgram(
6354 #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6358 #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6362 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6371 * Program constructor to allow construction of program from SPIR-V or another IL
6372 * for a specific context.
6373 * Valid for either OpenCL >= 2.1 or when CL_HPP_USE_IL_KHR is defined.
6376 const Context& context,
6377 const vector<char>& IL,
6383 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6385 object_ = ::clCreateProgramWithIL(
6386 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6388 #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6390 typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6391 static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6392 CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6394 return detail::errHandler(
6395 pfn_clCreateProgramWithILKHR(
6396 context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6398 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6400 detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6402 if (error == CL_SUCCESS && build) {
6403 error = ::clBuildProgram(
6407 #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6411 #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6415 detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6422 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6425 * Construct a program object from a list of devices and a per-device list of binaries.
6426 * \param context A valid OpenCL context in which to construct the program.
6427 * \param devices A vector of OpenCL device objects for which the program will be created.
6428 * \param binaries A vector of pairs of a pointer to a binary object and its length.
6429 * \param binaryStatus An optional vector that on completion will be resized to
6430 * match the size of binaries and filled with values to specify if each binary
6431 * was successfully loaded.
6432 * Set to CL_SUCCESS if the binary was successfully loaded.
6433 * Set to CL_INVALID_VALUE if the length is 0 or the binary pointer is NULL.
6434 * Set to CL_INVALID_BINARY if the binary provided is not valid for the matching device.
6435 * \param err if non-NULL will be set to CL_SUCCESS on successful operation or one of the following errors:
6436 * CL_INVALID_CONTEXT if context is not a valid context.
6437 * CL_INVALID_VALUE if the length of devices is zero; or if the length of binaries does not match the length of devices;
6438 * or if any entry in binaries is NULL or has length 0.
6439 * CL_INVALID_DEVICE if OpenCL devices listed in devices are not in the list of devices associated with context.
6440 * CL_INVALID_BINARY if an invalid program binary was encountered for any device. binaryStatus will return specific status for each device.
6441 * CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host.
6444 const Context& context,
6445 const vector<Device>& devices,
6446 const Binaries& binaries,
6447 vector<cl_int>* binaryStatus = NULL,
6452 const size_type numDevices = devices.size();
6454 // Catch size mismatch early and return
6455 if(binaries.size() != numDevices) {
6456 error = CL_INVALID_VALUE;
6457 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6465 vector<size_type> lengths(numDevices);
6466 vector<const unsigned char*> images(numDevices);
6467 #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6468 for (size_type i = 0; i < numDevices; ++i) {
6469 images[i] = binaries[i].data();
6470 lengths[i] = binaries[(int)i].size();
6472 #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6473 for (size_type i = 0; i < numDevices; ++i) {
6474 images[i] = (const unsigned char*)binaries[i].first;
6475 lengths[i] = binaries[(int)i].second;
6477 #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6479 vector<cl_device_id> deviceIDs(numDevices);
6480 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6481 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6485 binaryStatus->resize(numDevices);
6488 object_ = ::clCreateProgramWithBinary(
6489 context(), (cl_uint) devices.size(),
6491 lengths.data(), images.data(), (binaryStatus != NULL && numDevices > 0)
6492 ? &binaryStatus->front()
6495 detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6502 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6504 * Create program using builtin kernels.
6505 * \param kernelNames Semi-colon separated list of builtin kernel names
6508 const Context& context,
6509 const vector<Device>& devices,
6510 const string& kernelNames,
6516 size_type numDevices = devices.size();
6517 vector<cl_device_id> deviceIDs(numDevices);
6518 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6519 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6522 object_ = ::clCreateProgramWithBuiltInKernels(
6524 (cl_uint) devices.size(),
6526 kernelNames.c_str(),
6529 detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR);
6534 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6539 /*! \brief Constructor from cl_mem - takes ownership.
6541 * \param retainObject will cause the constructor to retain its cl object.
6542 * Defaults to false to maintain compatibility with
6545 explicit Program(const cl_program& program, bool retainObject = false) :
6546 detail::Wrapper<cl_type>(program, retainObject) { }
6548 Program& operator = (const cl_program& rhs)
6550 detail::Wrapper<cl_type>::operator=(rhs);
6554 /*! \brief Copy constructor to forward copy to the superclass correctly.
6555 * Required for MSVC.
6557 Program(const Program& program) : detail::Wrapper<cl_type>(program) {}
6559 /*! \brief Copy assignment to forward copy to the superclass correctly.
6560 * Required for MSVC.
6562 Program& operator = (const Program &program)
6564 detail::Wrapper<cl_type>::operator=(program);
6568 /*! \brief Move constructor to forward move to the superclass correctly.
6569 * Required for MSVC.
6571 Program(Program&& program) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(program)) {}
6573 /*! \brief Move assignment to forward move to the superclass correctly.
6574 * Required for MSVC.
6576 Program& operator = (Program &&program)
6578 detail::Wrapper<cl_type>::operator=(std::move(program));
6583 const vector<Device>& devices,
6584 const char* options = NULL,
6585 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6586 void* data = NULL) const
6588 size_type numDevices = devices.size();
6589 vector<cl_device_id> deviceIDs(numDevices);
6591 for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6592 deviceIDs[deviceIndex] = (devices[deviceIndex])();
6595 cl_int buildError = ::clBuildProgram(
6604 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6608 const char* options = NULL,
6609 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6610 void* data = NULL) const
6612 cl_int buildError = ::clBuildProgram(
6621 return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6624 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6626 const char* options = NULL,
6627 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6628 void* data = NULL) const
6630 cl_int error = ::clCompileProgram(
6640 return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6642 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6644 template <typename T>
6645 cl_int getInfo(cl_program_info name, T* param) const
6647 return detail::errHandler(
6648 detail::getInfo(&::clGetProgramInfo, object_, name, param),
6649 __GET_PROGRAM_INFO_ERR);
6652 template <cl_int name> typename
6653 detail::param_traits<detail::cl_program_info, name>::param_type
6654 getInfo(cl_int* err = NULL) const
6656 typename detail::param_traits<
6657 detail::cl_program_info, name>::param_type param;
6658 cl_int result = getInfo(name, ¶m);
6665 template <typename T>
6666 cl_int getBuildInfo(
6667 const Device& device, cl_program_build_info name, T* param) const
6669 return detail::errHandler(
6671 &::clGetProgramBuildInfo, object_, device(), name, param),
6672 __GET_PROGRAM_BUILD_INFO_ERR);
6675 template <cl_int name> typename
6676 detail::param_traits<detail::cl_program_build_info, name>::param_type
6677 getBuildInfo(const Device& device, cl_int* err = NULL) const
6679 typename detail::param_traits<
6680 detail::cl_program_build_info, name>::param_type param;
6681 cl_int result = getBuildInfo(device, name, ¶m);
6689 * Build info function that returns a vector of device/info pairs for the specified
6690 * info type and for all devices in the program.
6691 * On an error reading the info for any device, an empty vector of info will be returned.
6693 template <cl_int name>
6694 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6695 getBuildInfo(cl_int *err = NULL) const
6697 cl_int result = CL_SUCCESS;
6699 auto devs = getInfo<CL_PROGRAM_DEVICES>(&result);
6700 vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6703 // If there was an initial error from getInfo return the error
6704 if (result != CL_SUCCESS) {
6711 for (const cl::Device &d : devs) {
6712 typename detail::param_traits<
6713 detail::cl_program_build_info, name>::param_type param;
6714 result = getBuildInfo(d, name, ¶m);
6716 std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>
6718 if (result != CL_SUCCESS) {
6719 // On error, leave the loop and return the error code
6726 if (result != CL_SUCCESS) {
6732 cl_int createKernels(vector<Kernel>* kernels)
6735 cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
6736 if (err != CL_SUCCESS) {
6737 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6740 vector<cl_kernel> value(numKernels);
6742 err = ::clCreateKernelsInProgram(
6743 object_, numKernels, value.data(), NULL);
6744 if (err != CL_SUCCESS) {
6745 return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6749 kernels->resize(value.size());
6751 // Assign to param, constructing with retain behaviour
6752 // to correctly capture each underlying CL object
6753 for (size_type i = 0; i < value.size(); i++) {
6754 // We do not need to retain because this kernel is being created
6756 (*kernels)[i] = Kernel(value[i], false);
6762 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
6763 /*! \brief Registers a callback function to be called when destructors for
6764 * program scope global variables are complete and before the
6765 * program is released.
6767 * Wraps clSetProgramReleaseCallback().
6769 * Each call to this function registers the specified user callback function
6770 * on a callback stack associated with program. The registered user callback
6771 * functions are called in the reverse order in which they were registered.
6773 cl_int setReleaseCallback(
6774 void (CL_CALLBACK * pfn_notify)(cl_program program, void * user_data),
6775 void * user_data = NULL)
6777 return detail::errHandler(
6778 ::clSetProgramReleaseCallback(
6782 __SET_PROGRAM_RELEASE_CALLBACK_ERR);
6785 /*! \brief Sets a SPIR-V specialization constant.
6787 * Wraps clSetProgramSpecializationConstant().
6789 template <typename T>
6790 typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6791 setSpecializationConstant(cl_uint index, const T &value)
6793 return detail::errHandler(
6794 ::clSetProgramSpecializationConstant(
6799 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6802 /*! \brief Sets a SPIR-V specialization constant.
6804 * Wraps clSetProgramSpecializationConstant().
6806 cl_int setSpecializationConstant(cl_uint index, size_type size, const void* value)
6808 return detail::errHandler(
6809 ::clSetProgramSpecializationConstant(
6814 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6816 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
6819 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6820 inline Program linkProgram(
6823 const char* options = NULL,
6824 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6828 cl_int error_local = CL_SUCCESS;
6830 cl_program programs[2] = { input1(), input2() };
6832 Context ctx = input1.getInfo<CL_PROGRAM_CONTEXT>(&error_local);
6833 if(error_local!=CL_SUCCESS) {
6834 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
6837 cl_program prog = ::clLinkProgram(
6848 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
6853 return Program(prog);
6856 inline Program linkProgram(
6857 vector<Program> inputPrograms,
6858 const char* options = NULL,
6859 void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6863 cl_int error_local = CL_SUCCESS;
6865 vector<cl_program> programs(inputPrograms.size());
6867 for (unsigned int i = 0; i < inputPrograms.size(); i++) {
6868 programs[i] = inputPrograms[i]();
6872 if(inputPrograms.size() > 0) {
6873 ctx = inputPrograms[0].getInfo<CL_PROGRAM_CONTEXT>(&error_local);
6874 if(error_local!=CL_SUCCESS) {
6875 detail::errHandler(error_local, __LINK_PROGRAM_ERR);
6878 cl_program prog = ::clLinkProgram(
6883 (cl_uint)inputPrograms.size(),
6889 detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
6894 return Program(prog, false);
6896 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6898 // Template specialization for CL_PROGRAM_BINARIES
6900 inline cl_int cl::Program::getInfo(cl_program_info name, vector<vector<unsigned char>>* param) const
6902 if (name != CL_PROGRAM_BINARIES) {
6903 return CL_INVALID_VALUE;
6906 // Resize the parameter array appropriately for each allocation
6907 // and pass down to the helper
6909 vector<size_type> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>();
6910 size_type numBinaries = sizes.size();
6912 // Resize the parameter array and constituent arrays
6913 param->resize(numBinaries);
6914 for (size_type i = 0; i < numBinaries; ++i) {
6915 (*param)[i].resize(sizes[i]);
6918 return detail::errHandler(
6919 detail::getInfo(&::clGetProgramInfo, object_, name, param),
6920 __GET_PROGRAM_INFO_ERR);
6927 inline vector<vector<unsigned char>> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err) const
6929 vector<vector<unsigned char>> binariesVectors;
6931 cl_int result = getInfo(CL_PROGRAM_BINARIES, &binariesVectors);
6935 return binariesVectors;
6938 #if CL_HPP_TARGET_OPENCL_VERSION >= 220
6939 // Template specialization for clSetProgramSpecializationConstant
6941 inline cl_int cl::Program::setSpecializationConstant(cl_uint index, const bool &value)
6943 cl_uchar ucValue = value ? CL_UCHAR_MAX : 0;
6944 return detail::errHandler(
6945 ::clSetProgramSpecializationConstant(
6950 __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6952 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
6954 inline Kernel::Kernel(const Program& program, const char* name, cl_int* err)
6958 object_ = ::clCreateKernel(program(), name, &error);
6959 detail::errHandler(error, __CREATE_KERNEL_ERR);
6967 enum class QueueProperties : cl_command_queue_properties
6970 Profiling = CL_QUEUE_PROFILING_ENABLE,
6971 OutOfOrder = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,
6974 inline QueueProperties operator|(QueueProperties lhs, QueueProperties rhs)
6976 return static_cast<QueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
6979 /*! \class CommandQueue
6980 * \brief CommandQueue interface for cl_command_queue.
6982 class CommandQueue : public detail::Wrapper<cl_command_queue>
6985 static std::once_flag default_initialized_;
6986 static CommandQueue default_;
6987 static cl_int default_error_;
6989 /*! \brief Create the default command queue returned by @ref getDefault.
6991 * It sets default_error_ to indicate success or failure. It does not throw
6994 static void makeDefault()
6996 /* We don't want to throw an error from this function, so we have to
6997 * catch and set the error flag.
6999 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
7004 Context context = Context::getDefault(&error);
7006 if (error != CL_SUCCESS) {
7007 default_error_ = error;
7010 Device device = Device::getDefault();
7011 default_ = CommandQueue(context, device, 0, &default_error_);
7014 #if defined(CL_HPP_ENABLE_EXCEPTIONS)
7015 catch (cl::Error &e) {
7016 default_error_ = e.err();
7021 /*! \brief Create the default command queue.
7023 * This sets @c default_. It does not throw
7026 static void makeDefaultProvided(const CommandQueue &c) {
7031 #ifdef CL_HPP_UNIT_TEST_ENABLE
7032 /*! \brief Reset the default.
7034 * This sets @c default_ to an empty value to support cleanup in
7035 * the unit test framework.
7036 * This function is not thread safe.
7038 static void unitTestClearDefault() {
7039 default_ = CommandQueue();
7041 #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
7045 * \brief Constructs a CommandQueue based on passed properties.
7046 * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
7049 cl_command_queue_properties properties,
7054 Context context = Context::getDefault(&error);
7055 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7057 if (error != CL_SUCCESS) {
7063 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7064 bool useWithProperties;
7066 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7067 // Run-time decision based on the actual platform
7069 cl_uint version = detail::getContextPlatformVersion(context());
7070 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7072 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7073 useWithProperties = true;
7075 useWithProperties = false;
7078 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7079 if (useWithProperties) {
7080 cl_queue_properties queue_properties[] = {
7081 CL_QUEUE_PROPERTIES, properties, 0 };
7082 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7083 object_ = ::clCreateCommandQueueWithProperties(
7084 context(), device(), queue_properties, &error);
7087 error = CL_INVALID_QUEUE_PROPERTIES;
7090 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7095 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7096 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7097 if (!useWithProperties) {
7098 object_ = ::clCreateCommandQueue(
7099 context(), device(), properties, &error);
7101 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7106 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7111 * \brief Constructs a CommandQueue based on passed properties.
7112 * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
7115 QueueProperties properties,
7120 Context context = Context::getDefault(&error);
7121 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7123 if (error != CL_SUCCESS) {
7129 Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7130 bool useWithProperties;
7132 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7133 // Run-time decision based on the actual platform
7135 cl_uint version = detail::getContextPlatformVersion(context());
7136 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7138 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7139 useWithProperties = true;
7141 useWithProperties = false;
7144 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7145 if (useWithProperties) {
7146 cl_queue_properties queue_properties[] = {
7147 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7149 object_ = ::clCreateCommandQueueWithProperties(
7150 context(), device(), queue_properties, &error);
7152 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7157 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7158 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7159 if (!useWithProperties) {
7160 object_ = ::clCreateCommandQueue(
7161 context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
7163 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7168 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7174 * \brief Constructs a CommandQueue for an implementation defined device in the given context
7175 * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
7177 explicit CommandQueue(
7178 const Context& context,
7179 cl_command_queue_properties properties = 0,
7183 bool useWithProperties;
7184 vector<cl::Device> devices;
7185 error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7187 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7189 if (error != CL_SUCCESS)
7197 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7198 // Run-time decision based on the actual platform
7200 cl_uint version = detail::getContextPlatformVersion(context());
7201 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7203 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7204 useWithProperties = true;
7206 useWithProperties = false;
7209 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7210 if (useWithProperties) {
7211 cl_queue_properties queue_properties[] = {
7212 CL_QUEUE_PROPERTIES, properties, 0 };
7213 if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7214 object_ = ::clCreateCommandQueueWithProperties(
7215 context(), devices[0](), queue_properties, &error);
7218 error = CL_INVALID_QUEUE_PROPERTIES;
7221 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7226 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7227 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7228 if (!useWithProperties) {
7229 object_ = ::clCreateCommandQueue(
7230 context(), devices[0](), properties, &error);
7232 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7237 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7241 * \brief Constructs a CommandQueue for an implementation defined device in the given context
7242 * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
7244 explicit CommandQueue(
7245 const Context& context,
7246 QueueProperties properties,
7250 bool useWithProperties;
7251 vector<cl::Device> devices;
7252 error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7254 detail::errHandler(error, __CREATE_CONTEXT_ERR);
7256 if (error != CL_SUCCESS)
7264 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7265 // Run-time decision based on the actual platform
7267 cl_uint version = detail::getContextPlatformVersion(context());
7268 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7270 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7271 useWithProperties = true;
7273 useWithProperties = false;
7276 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7277 if (useWithProperties) {
7278 cl_queue_properties queue_properties[] = {
7279 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7280 object_ = ::clCreateCommandQueueWithProperties(
7281 context(), devices[0](), queue_properties, &error);
7283 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7288 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7289 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7290 if (!useWithProperties) {
7291 object_ = ::clCreateCommandQueue(
7292 context(), devices[0](), static_cast<cl_command_queue_properties>(properties), &error);
7294 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7299 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7303 * \brief Constructs a CommandQueue for a passed device and context
7304 * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
7307 const Context& context,
7308 const Device& device,
7309 cl_command_queue_properties properties = 0,
7313 bool useWithProperties;
7315 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7316 // Run-time decision based on the actual platform
7318 cl_uint version = detail::getContextPlatformVersion(context());
7319 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7321 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7322 useWithProperties = true;
7324 useWithProperties = false;
7327 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7328 if (useWithProperties) {
7329 cl_queue_properties queue_properties[] = {
7330 CL_QUEUE_PROPERTIES, properties, 0 };
7331 object_ = ::clCreateCommandQueueWithProperties(
7332 context(), device(), queue_properties, &error);
7334 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7339 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7340 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7341 if (!useWithProperties) {
7342 object_ = ::clCreateCommandQueue(
7343 context(), device(), properties, &error);
7345 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7350 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7354 * \brief Constructs a CommandQueue for a passed device and context
7355 * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
7358 const Context& context,
7359 const Device& device,
7360 QueueProperties properties,
7364 bool useWithProperties;
7366 #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7367 // Run-time decision based on the actual platform
7369 cl_uint version = detail::getContextPlatformVersion(context());
7370 useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7372 #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7373 useWithProperties = true;
7375 useWithProperties = false;
7378 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7379 if (useWithProperties) {
7380 cl_queue_properties queue_properties[] = {
7381 CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7382 object_ = ::clCreateCommandQueueWithProperties(
7383 context(), device(), queue_properties, &error);
7385 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7390 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7391 #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7392 if (!useWithProperties) {
7393 object_ = ::clCreateCommandQueue(
7394 context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
7396 detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7401 #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7404 static CommandQueue getDefault(cl_int * err = NULL)
7406 std::call_once(default_initialized_, makeDefault);
7407 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7408 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7409 #else // CL_HPP_TARGET_OPENCL_VERSION >= 200
7410 detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_ERR);
7411 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7413 *err = default_error_;
7419 * Modify the default command queue to be used by
7420 * subsequent operations.
7421 * Will only set the default if no default was previously created.
7422 * @return updated default command queue.
7423 * Should be compared to the passed value to ensure that it was updated.
7425 static CommandQueue setDefault(const CommandQueue &default_queue)
7427 std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_queue));
7428 detail::errHandler(default_error_);
7435 /*! \brief Constructor from cl_mem - takes ownership.
7437 * \param retainObject will cause the constructor to retain its cl object.
7438 * Defaults to false to maintain compatibility with
7441 explicit CommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
7442 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
7444 CommandQueue& operator = (const cl_command_queue& rhs)
7446 detail::Wrapper<cl_type>::operator=(rhs);
7450 /*! \brief Copy constructor to forward copy to the superclass correctly.
7451 * Required for MSVC.
7453 CommandQueue(const CommandQueue& queue) : detail::Wrapper<cl_type>(queue) {}
7455 /*! \brief Copy assignment to forward copy to the superclass correctly.
7456 * Required for MSVC.
7458 CommandQueue& operator = (const CommandQueue &queue)
7460 detail::Wrapper<cl_type>::operator=(queue);
7464 /*! \brief Move constructor to forward move to the superclass correctly.
7465 * Required for MSVC.
7467 CommandQueue(CommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(queue)) {}
7469 /*! \brief Move assignment to forward move to the superclass correctly.
7470 * Required for MSVC.
7472 CommandQueue& operator = (CommandQueue &&queue)
7474 detail::Wrapper<cl_type>::operator=(std::move(queue));
7478 template <typename T>
7479 cl_int getInfo(cl_command_queue_info name, T* param) const
7481 return detail::errHandler(
7483 &::clGetCommandQueueInfo, object_, name, param),
7484 __GET_COMMAND_QUEUE_INFO_ERR);
7487 template <cl_int name> typename
7488 detail::param_traits<detail::cl_command_queue_info, name>::param_type
7489 getInfo(cl_int* err = NULL) const
7491 typename detail::param_traits<
7492 detail::cl_command_queue_info, name>::param_type param;
7493 cl_int result = getInfo(name, ¶m);
7500 cl_int enqueueReadBuffer(
7501 const Buffer& buffer,
7506 const vector<Event>* events = NULL,
7507 Event* event = NULL) const
7510 cl_int err = detail::errHandler(
7511 ::clEnqueueReadBuffer(
7512 object_, buffer(), blocking, offset, size,
7514 (events != NULL) ? (cl_uint) events->size() : 0,
7515 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7516 (event != NULL) ? &tmp : NULL),
7517 __ENQUEUE_READ_BUFFER_ERR);
7519 if (event != NULL && err == CL_SUCCESS)
7525 cl_int enqueueWriteBuffer(
7526 const Buffer& buffer,
7531 const vector<Event>* events = NULL,
7532 Event* event = NULL) const
7535 cl_int err = detail::errHandler(
7536 ::clEnqueueWriteBuffer(
7537 object_, buffer(), blocking, offset, size,
7539 (events != NULL) ? (cl_uint) events->size() : 0,
7540 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7541 (event != NULL) ? &tmp : NULL),
7542 __ENQUEUE_WRITE_BUFFER_ERR);
7544 if (event != NULL && err == CL_SUCCESS)
7550 cl_int enqueueCopyBuffer(
7553 size_type src_offset,
7554 size_type dst_offset,
7556 const vector<Event>* events = NULL,
7557 Event* event = NULL) const
7560 cl_int err = detail::errHandler(
7561 ::clEnqueueCopyBuffer(
7562 object_, src(), dst(), src_offset, dst_offset, size,
7563 (events != NULL) ? (cl_uint) events->size() : 0,
7564 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7565 (event != NULL) ? &tmp : NULL),
7566 __ENQEUE_COPY_BUFFER_ERR);
7568 if (event != NULL && err == CL_SUCCESS)
7573 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
7574 cl_int enqueueReadBufferRect(
7575 const Buffer& buffer,
7577 const array<size_type, 3>& buffer_offset,
7578 const array<size_type, 3>& host_offset,
7579 const array<size_type, 3>& region,
7580 size_type buffer_row_pitch,
7581 size_type buffer_slice_pitch,
7582 size_type host_row_pitch,
7583 size_type host_slice_pitch,
7585 const vector<Event>* events = NULL,
7586 Event* event = NULL) const
7589 cl_int err = detail::errHandler(
7590 ::clEnqueueReadBufferRect(
7594 buffer_offset.data(),
7602 (events != NULL) ? (cl_uint) events->size() : 0,
7603 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7604 (event != NULL) ? &tmp : NULL),
7605 __ENQUEUE_READ_BUFFER_RECT_ERR);
7607 if (event != NULL && err == CL_SUCCESS)
7613 cl_int enqueueWriteBufferRect(
7614 const Buffer& buffer,
7616 const array<size_type, 3>& buffer_offset,
7617 const array<size_type, 3>& host_offset,
7618 const array<size_type, 3>& region,
7619 size_type buffer_row_pitch,
7620 size_type buffer_slice_pitch,
7621 size_type host_row_pitch,
7622 size_type host_slice_pitch,
7624 const vector<Event>* events = NULL,
7625 Event* event = NULL) const
7628 cl_int err = detail::errHandler(
7629 ::clEnqueueWriteBufferRect(
7633 buffer_offset.data(),
7641 (events != NULL) ? (cl_uint) events->size() : 0,
7642 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7643 (event != NULL) ? &tmp : NULL),
7644 __ENQUEUE_WRITE_BUFFER_RECT_ERR);
7646 if (event != NULL && err == CL_SUCCESS)
7652 cl_int enqueueCopyBufferRect(
7655 const array<size_type, 3>& src_origin,
7656 const array<size_type, 3>& dst_origin,
7657 const array<size_type, 3>& region,
7658 size_type src_row_pitch,
7659 size_type src_slice_pitch,
7660 size_type dst_row_pitch,
7661 size_type dst_slice_pitch,
7662 const vector<Event>* events = NULL,
7663 Event* event = NULL) const
7666 cl_int err = detail::errHandler(
7667 ::clEnqueueCopyBufferRect(
7678 (events != NULL) ? (cl_uint) events->size() : 0,
7679 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7680 (event != NULL) ? &tmp : NULL),
7681 __ENQEUE_COPY_BUFFER_RECT_ERR);
7683 if (event != NULL && err == CL_SUCCESS)
7688 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
7689 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
7691 * Enqueue a command to fill a buffer object with a pattern
7692 * of a given size. The pattern is specified as a vector type.
7693 * \tparam PatternType The datatype of the pattern field.
7694 * The pattern type must be an accepted OpenCL data type.
7695 * \tparam offset Is the offset in bytes into the buffer at
7696 * which to start filling. This must be a multiple of
7698 * \tparam size Is the size in bytes of the region to fill.
7699 * This must be a multiple of the pattern size.
7701 template<typename PatternType>
7702 cl_int enqueueFillBuffer(
7703 const Buffer& buffer,
7704 PatternType pattern,
7707 const vector<Event>* events = NULL,
7708 Event* event = NULL) const
7711 cl_int err = detail::errHandler(
7712 ::clEnqueueFillBuffer(
7715 static_cast<void*>(&pattern),
7716 sizeof(PatternType),
7719 (events != NULL) ? (cl_uint) events->size() : 0,
7720 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7721 (event != NULL) ? &tmp : NULL),
7722 __ENQUEUE_FILL_BUFFER_ERR);
7724 if (event != NULL && err == CL_SUCCESS)
7729 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7731 cl_int enqueueReadImage(
7734 const array<size_type, 3>& origin,
7735 const array<size_type, 3>& region,
7736 size_type row_pitch,
7737 size_type slice_pitch,
7739 const vector<Event>* events = NULL,
7740 Event* event = NULL) const
7743 cl_int err = detail::errHandler(
7744 ::clEnqueueReadImage(
7753 (events != NULL) ? (cl_uint) events->size() : 0,
7754 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7755 (event != NULL) ? &tmp : NULL),
7756 __ENQUEUE_READ_IMAGE_ERR);
7758 if (event != NULL && err == CL_SUCCESS)
7764 cl_int enqueueWriteImage(
7767 const array<size_type, 3>& origin,
7768 const array<size_type, 3>& region,
7769 size_type row_pitch,
7770 size_type slice_pitch,
7772 const vector<Event>* events = NULL,
7773 Event* event = NULL) const
7776 cl_int err = detail::errHandler(
7777 ::clEnqueueWriteImage(
7786 (events != NULL) ? (cl_uint) events->size() : 0,
7787 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7788 (event != NULL) ? &tmp : NULL),
7789 __ENQUEUE_WRITE_IMAGE_ERR);
7791 if (event != NULL && err == CL_SUCCESS)
7797 cl_int enqueueCopyImage(
7800 const array<size_type, 3>& src_origin,
7801 const array<size_type, 3>& dst_origin,
7802 const array<size_type, 3>& region,
7803 const vector<Event>* events = NULL,
7804 Event* event = NULL) const
7807 cl_int err = detail::errHandler(
7808 ::clEnqueueCopyImage(
7815 (events != NULL) ? (cl_uint) events->size() : 0,
7816 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7817 (event != NULL) ? &tmp : NULL),
7818 __ENQUEUE_COPY_IMAGE_ERR);
7820 if (event != NULL && err == CL_SUCCESS)
7826 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
7828 * Enqueue a command to fill an image object with a specified color.
7829 * \param fillColor is the color to use to fill the image.
7830 * This is a four component RGBA floating-point color value if
7831 * the image channel data type is not an unnormalized signed or
7832 * unsigned data type.
7834 cl_int enqueueFillImage(
7836 cl_float4 fillColor,
7837 const array<size_type, 3>& origin,
7838 const array<size_type, 3>& region,
7839 const vector<Event>* events = NULL,
7840 Event* event = NULL) const
7843 cl_int err = detail::errHandler(
7844 ::clEnqueueFillImage(
7847 static_cast<void*>(&fillColor),
7850 (events != NULL) ? (cl_uint) events->size() : 0,
7851 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7852 (event != NULL) ? &tmp : NULL),
7853 __ENQUEUE_FILL_IMAGE_ERR);
7855 if (event != NULL && err == CL_SUCCESS)
7862 * Enqueue a command to fill an image object with a specified color.
7863 * \param fillColor is the color to use to fill the image.
7864 * This is a four component RGBA signed integer color value if
7865 * the image channel data type is an unnormalized signed integer
7868 cl_int enqueueFillImage(
7871 const array<size_type, 3>& origin,
7872 const array<size_type, 3>& region,
7873 const vector<Event>* events = NULL,
7874 Event* event = NULL) const
7877 cl_int err = detail::errHandler(
7878 ::clEnqueueFillImage(
7881 static_cast<void*>(&fillColor),
7884 (events != NULL) ? (cl_uint) events->size() : 0,
7885 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7886 (event != NULL) ? &tmp : NULL),
7887 __ENQUEUE_FILL_IMAGE_ERR);
7889 if (event != NULL && err == CL_SUCCESS)
7896 * Enqueue a command to fill an image object with a specified color.
7897 * \param fillColor is the color to use to fill the image.
7898 * This is a four component RGBA unsigned integer color value if
7899 * the image channel data type is an unnormalized unsigned integer
7902 cl_int enqueueFillImage(
7905 const array<size_type, 3>& origin,
7906 const array<size_type, 3>& region,
7907 const vector<Event>* events = NULL,
7908 Event* event = NULL) const
7911 cl_int err = detail::errHandler(
7912 ::clEnqueueFillImage(
7915 static_cast<void*>(&fillColor),
7918 (events != NULL) ? (cl_uint) events->size() : 0,
7919 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7920 (event != NULL) ? &tmp : NULL),
7921 __ENQUEUE_FILL_IMAGE_ERR);
7923 if (event != NULL && err == CL_SUCCESS)
7928 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7930 cl_int enqueueCopyImageToBuffer(
7933 const array<size_type, 3>& src_origin,
7934 const array<size_type, 3>& region,
7935 size_type dst_offset,
7936 const vector<Event>* events = NULL,
7937 Event* event = NULL) const
7940 cl_int err = detail::errHandler(
7941 ::clEnqueueCopyImageToBuffer(
7948 (events != NULL) ? (cl_uint) events->size() : 0,
7949 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7950 (event != NULL) ? &tmp : NULL),
7951 __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
7953 if (event != NULL && err == CL_SUCCESS)
7959 cl_int enqueueCopyBufferToImage(
7962 size_type src_offset,
7963 const array<size_type, 3>& dst_origin,
7964 const array<size_type, 3>& region,
7965 const vector<Event>* events = NULL,
7966 Event* event = NULL) const
7969 cl_int err = detail::errHandler(
7970 ::clEnqueueCopyBufferToImage(
7977 (events != NULL) ? (cl_uint) events->size() : 0,
7978 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7979 (event != NULL) ? &tmp : NULL),
7980 __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
7982 if (event != NULL && err == CL_SUCCESS)
7988 void* enqueueMapBuffer(
7989 const Buffer& buffer,
7994 const vector<Event>* events = NULL,
7995 Event* event = NULL,
7996 cl_int* err = NULL) const
8000 void * result = ::clEnqueueMapBuffer(
8001 object_, buffer(), blocking, flags, offset, size,
8002 (events != NULL) ? (cl_uint) events->size() : 0,
8003 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8004 (event != NULL) ? &tmp : NULL,
8007 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
8011 if (event != NULL && error == CL_SUCCESS)
8017 void* enqueueMapImage(
8018 const Image& buffer,
8021 const array<size_type, 3>& origin,
8022 const array<size_type, 3>& region,
8023 size_type * row_pitch,
8024 size_type * slice_pitch,
8025 const vector<Event>* events = NULL,
8026 Event* event = NULL,
8027 cl_int* err = NULL) const
8031 void * result = ::clEnqueueMapImage(
8032 object_, buffer(), blocking, flags,
8035 row_pitch, slice_pitch,
8036 (events != NULL) ? (cl_uint) events->size() : 0,
8037 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8038 (event != NULL) ? &tmp : NULL,
8041 detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
8045 if (event != NULL && error == CL_SUCCESS)
8050 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8052 * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer.
8053 * This variant takes a raw SVM pointer.
8055 template<typename T>
8056 cl_int enqueueMapSVM(
8061 const vector<Event>* events = NULL,
8062 Event* event = NULL) const
8065 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8066 object_, blocking, flags, static_cast<void*>(ptr), size,
8067 (events != NULL) ? (cl_uint)events->size() : 0,
8068 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8069 (event != NULL) ? &tmp : NULL),
8070 __ENQUEUE_MAP_BUFFER_ERR);
8072 if (event != NULL && err == CL_SUCCESS)
8080 * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer.
8081 * This variant takes a cl::pointer instance.
8083 template<typename T, class D>
8084 cl_int enqueueMapSVM(
8085 cl::pointer<T, D> &ptr,
8089 const vector<Event>* events = NULL,
8090 Event* event = NULL) const
8093 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8094 object_, blocking, flags, static_cast<void*>(ptr.get()), size,
8095 (events != NULL) ? (cl_uint)events->size() : 0,
8096 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8097 (event != NULL) ? &tmp : NULL),
8098 __ENQUEUE_MAP_BUFFER_ERR);
8100 if (event != NULL && err == CL_SUCCESS)
8107 * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer.
8108 * This variant takes a cl::vector instance.
8110 template<typename T, class Alloc>
8111 cl_int enqueueMapSVM(
8112 cl::vector<T, Alloc> &container,
8115 const vector<Event>* events = NULL,
8116 Event* event = NULL) const
8119 cl_int err = detail::errHandler(::clEnqueueSVMMap(
8120 object_, blocking, flags, static_cast<void*>(container.data()), container.size(),
8121 (events != NULL) ? (cl_uint)events->size() : 0,
8122 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8123 (event != NULL) ? &tmp : NULL),
8124 __ENQUEUE_MAP_BUFFER_ERR);
8126 if (event != NULL && err == CL_SUCCESS)
8131 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8133 cl_int enqueueUnmapMemObject(
8134 const Memory& memory,
8136 const vector<Event>* events = NULL,
8137 Event* event = NULL) const
8140 cl_int err = detail::errHandler(
8141 ::clEnqueueUnmapMemObject(
8142 object_, memory(), mapped_ptr,
8143 (events != NULL) ? (cl_uint) events->size() : 0,
8144 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8145 (event != NULL) ? &tmp : NULL),
8146 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8148 if (event != NULL && err == CL_SUCCESS)
8155 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8157 * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime.
8158 * This variant takes a raw SVM pointer.
8160 template<typename T>
8161 cl_int enqueueUnmapSVM(
8163 const vector<Event>* events = NULL,
8164 Event* event = NULL) const
8167 cl_int err = detail::errHandler(
8168 ::clEnqueueSVMUnmap(
8169 object_, static_cast<void*>(ptr),
8170 (events != NULL) ? (cl_uint)events->size() : 0,
8171 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8172 (event != NULL) ? &tmp : NULL),
8173 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8175 if (event != NULL && err == CL_SUCCESS)
8182 * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime.
8183 * This variant takes a cl::pointer instance.
8185 template<typename T, class D>
8186 cl_int enqueueUnmapSVM(
8187 cl::pointer<T, D> &ptr,
8188 const vector<Event>* events = NULL,
8189 Event* event = NULL) const
8192 cl_int err = detail::errHandler(
8193 ::clEnqueueSVMUnmap(
8194 object_, static_cast<void*>(ptr.get()),
8195 (events != NULL) ? (cl_uint)events->size() : 0,
8196 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8197 (event != NULL) ? &tmp : NULL),
8198 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8200 if (event != NULL && err == CL_SUCCESS)
8207 * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime.
8208 * This variant takes a cl::vector instance.
8210 template<typename T, class Alloc>
8211 cl_int enqueueUnmapSVM(
8212 cl::vector<T, Alloc> &container,
8213 const vector<Event>* events = NULL,
8214 Event* event = NULL) const
8217 cl_int err = detail::errHandler(
8218 ::clEnqueueSVMUnmap(
8219 object_, static_cast<void*>(container.data()),
8220 (events != NULL) ? (cl_uint)events->size() : 0,
8221 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8222 (event != NULL) ? &tmp : NULL),
8223 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8225 if (event != NULL && err == CL_SUCCESS)
8230 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8232 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8234 * Enqueues a marker command which waits for either a list of events to complete,
8235 * or all previously enqueued commands to complete.
8237 * Enqueues a marker command which waits for either a list of events to complete,
8238 * or if the list is empty it waits for all commands previously enqueued in command_queue
8239 * to complete before it completes. This command returns an event which can be waited on,
8240 * i.e. this event can be waited on to insure that all events either in the event_wait_list
8241 * or all previously enqueued commands, queued before this command to command_queue,
8244 cl_int enqueueMarkerWithWaitList(
8245 const vector<Event> *events = 0,
8246 Event *event = 0) const
8249 cl_int err = detail::errHandler(
8250 ::clEnqueueMarkerWithWaitList(
8252 (events != NULL) ? (cl_uint) events->size() : 0,
8253 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8254 (event != NULL) ? &tmp : NULL),
8255 __ENQUEUE_MARKER_WAIT_LIST_ERR);
8257 if (event != NULL && err == CL_SUCCESS)
8264 * A synchronization point that enqueues a barrier operation.
8266 * Enqueues a barrier command which waits for either a list of events to complete,
8267 * or if the list is empty it waits for all commands previously enqueued in command_queue
8268 * to complete before it completes. This command blocks command execution, that is, any
8269 * following commands enqueued after it do not execute until it completes. This command
8270 * returns an event which can be waited on, i.e. this event can be waited on to insure that
8271 * all events either in the event_wait_list or all previously enqueued commands, queued
8272 * before this command to command_queue, have completed.
8274 cl_int enqueueBarrierWithWaitList(
8275 const vector<Event> *events = 0,
8276 Event *event = 0) const
8279 cl_int err = detail::errHandler(
8280 ::clEnqueueBarrierWithWaitList(
8282 (events != NULL) ? (cl_uint) events->size() : 0,
8283 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8284 (event != NULL) ? &tmp : NULL),
8285 __ENQUEUE_BARRIER_WAIT_LIST_ERR);
8287 if (event != NULL && err == CL_SUCCESS)
8294 * Enqueues a command to indicate with which device a set of memory objects
8295 * should be associated.
8297 cl_int enqueueMigrateMemObjects(
8298 const vector<Memory> &memObjects,
8299 cl_mem_migration_flags flags,
8300 const vector<Event>* events = NULL,
8306 vector<cl_mem> localMemObjects(memObjects.size());
8308 for( int i = 0; i < (int)memObjects.size(); ++i ) {
8309 localMemObjects[i] = memObjects[i]();
8312 cl_int err = detail::errHandler(
8313 ::clEnqueueMigrateMemObjects(
8315 (cl_uint)memObjects.size(),
8316 localMemObjects.data(),
8318 (events != NULL) ? (cl_uint) events->size() : 0,
8319 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8320 (event != NULL) ? &tmp : NULL),
8321 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8323 if (event != NULL && err == CL_SUCCESS)
8328 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8331 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8333 * Enqueues a command that will allow the host associate ranges within a set of
8334 * SVM allocations with a device.
8335 * @param sizes - The length from each pointer to migrate.
8337 template<typename T>
8338 cl_int enqueueMigrateSVM(
8339 const cl::vector<T*> &svmRawPointers,
8340 const cl::vector<size_type> &sizes,
8341 cl_mem_migration_flags flags = 0,
8342 const vector<Event>* events = NULL,
8343 Event* event = NULL) const
8346 cl_int err = detail::errHandler(::clEnqueueSVMMigrateMem(
8348 svmRawPointers.size(), static_cast<void**>(svmRawPointers.data()),
8349 sizes.data(), // array of sizes not passed
8351 (events != NULL) ? (cl_uint)events->size() : 0,
8352 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8353 (event != NULL) ? &tmp : NULL),
8354 __ENQUEUE_MIGRATE_SVM_ERR);
8356 if (event != NULL && err == CL_SUCCESS)
8363 * Enqueues a command that will allow the host associate a set of SVM allocations with
8366 template<typename T>
8367 cl_int enqueueMigrateSVM(
8368 const cl::vector<T*> &svmRawPointers,
8369 cl_mem_migration_flags flags = 0,
8370 const vector<Event>* events = NULL,
8371 Event* event = NULL) const
8373 return enqueueMigrateSVM(svmRawPointers, cl::vector<size_type>(svmRawPointers.size()), flags, events, event);
8378 * Enqueues a command that will allow the host associate ranges within a set of
8379 * SVM allocations with a device.
8380 * @param sizes - The length from each pointer to migrate.
8382 template<typename T, class D>
8383 cl_int enqueueMigrateSVM(
8384 const cl::vector<cl::pointer<T, D>> &svmPointers,
8385 const cl::vector<size_type> &sizes,
8386 cl_mem_migration_flags flags = 0,
8387 const vector<Event>* events = NULL,
8388 Event* event = NULL) const
8390 cl::vector<void*> svmRawPointers;
8391 svmRawPointers.reserve(svmPointers.size());
8392 for (auto p : svmPointers) {
8393 svmRawPointers.push_back(static_cast<void*>(p.get()));
8396 return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
8401 * Enqueues a command that will allow the host associate a set of SVM allocations with
8404 template<typename T, class D>
8405 cl_int enqueueMigrateSVM(
8406 const cl::vector<cl::pointer<T, D>> &svmPointers,
8407 cl_mem_migration_flags flags = 0,
8408 const vector<Event>* events = NULL,
8409 Event* event = NULL) const
8411 return enqueueMigrateSVM(svmPointers, cl::vector<size_type>(svmPointers.size()), flags, events, event);
8415 * Enqueues a command that will allow the host associate ranges within a set of
8416 * SVM allocations with a device.
8417 * @param sizes - The length from the beginning of each container to migrate.
8419 template<typename T, class Alloc>
8420 cl_int enqueueMigrateSVM(
8421 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8422 const cl::vector<size_type> &sizes,
8423 cl_mem_migration_flags flags = 0,
8424 const vector<Event>* events = NULL,
8425 Event* event = NULL) const
8427 cl::vector<void*> svmRawPointers;
8428 svmRawPointers.reserve(svmContainers.size());
8429 for (auto p : svmContainers) {
8430 svmRawPointers.push_back(static_cast<void*>(p.data()));
8433 return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
8437 * Enqueues a command that will allow the host associate a set of SVM allocations with
8440 template<typename T, class Alloc>
8441 cl_int enqueueMigrateSVM(
8442 const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8443 cl_mem_migration_flags flags = 0,
8444 const vector<Event>* events = NULL,
8445 Event* event = NULL) const
8447 return enqueueMigrateSVM(svmContainers, cl::vector<size_type>(svmContainers.size()), flags, events, event);
8450 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8452 cl_int enqueueNDRangeKernel(
8453 const Kernel& kernel,
8454 const NDRange& offset,
8455 const NDRange& global,
8456 const NDRange& local = NullRange,
8457 const vector<Event>* events = NULL,
8458 Event* event = NULL) const
8461 cl_int err = detail::errHandler(
8462 ::clEnqueueNDRangeKernel(
8463 object_, kernel(), (cl_uint) global.dimensions(),
8464 offset.dimensions() != 0 ? (const size_type*) offset : NULL,
8465 (const size_type*) global,
8466 local.dimensions() != 0 ? (const size_type*) local : NULL,
8467 (events != NULL) ? (cl_uint) events->size() : 0,
8468 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8469 (event != NULL) ? &tmp : NULL),
8470 __ENQUEUE_NDRANGE_KERNEL_ERR);
8472 if (event != NULL && err == CL_SUCCESS)
8478 #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8479 CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_int enqueueTask(
8480 const Kernel& kernel,
8481 const vector<Event>* events = NULL,
8482 Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED
8485 cl_int err = detail::errHandler(
8488 (events != NULL) ? (cl_uint) events->size() : 0,
8489 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8490 (event != NULL) ? &tmp : NULL),
8491 __ENQUEUE_TASK_ERR);
8493 if (event != NULL && err == CL_SUCCESS)
8498 #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8500 cl_int enqueueNativeKernel(
8501 void (CL_CALLBACK *userFptr)(void *),
8502 std::pair<void*, size_type> args,
8503 const vector<Memory>* mem_objects = NULL,
8504 const vector<const void*>* mem_locs = NULL,
8505 const vector<Event>* events = NULL,
8506 Event* event = NULL) const
8508 size_type elements = 0;
8509 if (mem_objects != NULL) {
8510 elements = mem_objects->size();
8512 vector<cl_mem> mems(elements);
8513 for (unsigned int i = 0; i < elements; i++) {
8514 mems[i] = ((*mem_objects)[i])();
8518 cl_int err = detail::errHandler(
8519 ::clEnqueueNativeKernel(
8520 object_, userFptr, args.first, args.second,
8521 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8523 (mem_locs != NULL && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : NULL,
8524 (events != NULL) ? (cl_uint) events->size() : 0,
8525 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8526 (event != NULL) ? &tmp : NULL),
8527 __ENQUEUE_NATIVE_KERNEL);
8529 if (event != NULL && err == CL_SUCCESS)
8536 * Deprecated APIs for 1.2
8538 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8539 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
8540 cl_int enqueueMarker(Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
8543 cl_int err = detail::errHandler(
8546 (event != NULL) ? &tmp : NULL),
8547 __ENQUEUE_MARKER_ERR);
8549 if (event != NULL && err == CL_SUCCESS)
8555 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
8556 cl_int enqueueWaitForEvents(const vector<Event>& events) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
8558 return detail::errHandler(
8559 ::clEnqueueWaitForEvents(
8561 (cl_uint) events.size(),
8562 events.size() > 0 ? (const cl_event*) &events.front() : NULL),
8563 __ENQUEUE_WAIT_FOR_EVENTS_ERR);
8565 #endif // defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8567 cl_int enqueueAcquireGLObjects(
8568 const vector<Memory>* mem_objects = NULL,
8569 const vector<Event>* events = NULL,
8570 Event* event = NULL) const
8573 cl_int err = detail::errHandler(
8574 ::clEnqueueAcquireGLObjects(
8576 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8577 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8578 (events != NULL) ? (cl_uint) events->size() : 0,
8579 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8580 (event != NULL) ? &tmp : NULL),
8581 __ENQUEUE_ACQUIRE_GL_ERR);
8583 if (event != NULL && err == CL_SUCCESS)
8589 cl_int enqueueReleaseGLObjects(
8590 const vector<Memory>* mem_objects = NULL,
8591 const vector<Event>* events = NULL,
8592 Event* event = NULL) const
8595 cl_int err = detail::errHandler(
8596 ::clEnqueueReleaseGLObjects(
8598 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8599 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8600 (events != NULL) ? (cl_uint) events->size() : 0,
8601 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8602 (event != NULL) ? &tmp : NULL),
8603 __ENQUEUE_RELEASE_GL_ERR);
8605 if (event != NULL && err == CL_SUCCESS)
8611 #if defined (CL_HPP_USE_DX_INTEROP)
8612 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
8613 cl_command_queue command_queue, cl_uint num_objects,
8614 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8615 const cl_event* event_wait_list, cl_event* event);
8616 typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
8617 cl_command_queue command_queue, cl_uint num_objects,
8618 const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8619 const cl_event* event_wait_list, cl_event* event);
8621 cl_int enqueueAcquireD3D10Objects(
8622 const vector<Memory>* mem_objects = NULL,
8623 const vector<Event>* events = NULL,
8624 Event* event = NULL) const
8626 static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
8627 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8628 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8629 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8630 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8631 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireD3D10ObjectsKHR);
8633 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
8634 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueAcquireD3D10ObjectsKHR);
8638 cl_int err = detail::errHandler(
8639 pfn_clEnqueueAcquireD3D10ObjectsKHR(
8641 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8642 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8643 (events != NULL) ? (cl_uint) events->size() : 0,
8644 (events != NULL) ? (cl_event*) &events->front() : NULL,
8645 (event != NULL) ? &tmp : NULL),
8646 __ENQUEUE_ACQUIRE_GL_ERR);
8648 if (event != NULL && err == CL_SUCCESS)
8654 cl_int enqueueReleaseD3D10Objects(
8655 const vector<Memory>* mem_objects = NULL,
8656 const vector<Event>* events = NULL,
8657 Event* event = NULL) const
8659 static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL;
8660 #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8661 cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8662 cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8663 cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8664 CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseD3D10ObjectsKHR);
8665 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8666 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
8667 CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueReleaseD3D10ObjectsKHR);
8668 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
8671 cl_int err = detail::errHandler(
8672 pfn_clEnqueueReleaseD3D10ObjectsKHR(
8674 (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8675 (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8676 (events != NULL) ? (cl_uint) events->size() : 0,
8677 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8678 (event != NULL) ? &tmp : NULL),
8679 __ENQUEUE_RELEASE_GL_ERR);
8681 if (event != NULL && err == CL_SUCCESS)
8689 * Deprecated APIs for 1.2
8691 #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8692 CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
8693 cl_int enqueueBarrier() const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
8695 return detail::errHandler(
8696 ::clEnqueueBarrier(object_),
8697 __ENQUEUE_BARRIER_ERR);
8699 #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
8701 cl_int flush() const
8703 return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
8706 cl_int finish() const
8708 return detail::errHandler(::clFinish(object_), __FINISH_ERR);
8712 CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::default_initialized_;
8713 CL_HPP_DEFINE_STATIC_MEMBER_ CommandQueue CommandQueue::default_;
8714 CL_HPP_DEFINE_STATIC_MEMBER_ cl_int CommandQueue::default_error_ = CL_SUCCESS;
8717 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8718 enum class DeviceQueueProperties : cl_command_queue_properties
8721 Profiling = CL_QUEUE_PROFILING_ENABLE,
8724 inline DeviceQueueProperties operator|(DeviceQueueProperties lhs, DeviceQueueProperties rhs)
8726 return static_cast<DeviceQueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
8729 /*! \class DeviceCommandQueue
8730 * \brief DeviceCommandQueue interface for device cl_command_queues.
8732 class DeviceCommandQueue : public detail::Wrapper<cl_command_queue>
8737 * Trivial empty constructor to create a null queue.
8739 DeviceCommandQueue() { }
8742 * Default construct device command queue on default context and device
8744 DeviceCommandQueue(DeviceQueueProperties properties, cl_int* err = NULL)
8747 cl::Context context = cl::Context::getDefault();
8748 cl::Device device = cl::Device::getDefault();
8750 cl_command_queue_properties mergedProperties =
8751 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8753 cl_queue_properties queue_properties[] = {
8754 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8755 object_ = ::clCreateCommandQueueWithProperties(
8756 context(), device(), queue_properties, &error);
8758 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8765 * Create a device command queue for a specified device in the passed context.
8768 const Context& context,
8769 const Device& device,
8770 DeviceQueueProperties properties = DeviceQueueProperties::None,
8775 cl_command_queue_properties mergedProperties =
8776 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8777 cl_queue_properties queue_properties[] = {
8778 CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8779 object_ = ::clCreateCommandQueueWithProperties(
8780 context(), device(), queue_properties, &error);
8782 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8789 * Create a device command queue for a specified device in the passed context.
8792 const Context& context,
8793 const Device& device,
8795 DeviceQueueProperties properties = DeviceQueueProperties::None,
8800 cl_command_queue_properties mergedProperties =
8801 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8802 cl_queue_properties queue_properties[] = {
8803 CL_QUEUE_PROPERTIES, mergedProperties,
8804 CL_QUEUE_SIZE, queueSize,
8806 object_ = ::clCreateCommandQueueWithProperties(
8807 context(), device(), queue_properties, &error);
8809 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8815 /*! \brief Constructor from cl_command_queue - takes ownership.
8817 * \param retainObject will cause the constructor to retain its cl object.
8818 * Defaults to false to maintain compatibility with
8821 explicit DeviceCommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
8822 detail::Wrapper<cl_type>(commandQueue, retainObject) { }
8824 DeviceCommandQueue& operator = (const cl_command_queue& rhs)
8826 detail::Wrapper<cl_type>::operator=(rhs);
8830 /*! \brief Copy constructor to forward copy to the superclass correctly.
8831 * Required for MSVC.
8833 DeviceCommandQueue(const DeviceCommandQueue& queue) : detail::Wrapper<cl_type>(queue) {}
8835 /*! \brief Copy assignment to forward copy to the superclass correctly.
8836 * Required for MSVC.
8838 DeviceCommandQueue& operator = (const DeviceCommandQueue &queue)
8840 detail::Wrapper<cl_type>::operator=(queue);
8844 /*! \brief Move constructor to forward move to the superclass correctly.
8845 * Required for MSVC.
8847 DeviceCommandQueue(DeviceCommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(queue)) {}
8849 /*! \brief Move assignment to forward move to the superclass correctly.
8850 * Required for MSVC.
8852 DeviceCommandQueue& operator = (DeviceCommandQueue &&queue)
8854 detail::Wrapper<cl_type>::operator=(std::move(queue));
8858 template <typename T>
8859 cl_int getInfo(cl_command_queue_info name, T* param) const
8861 return detail::errHandler(
8863 &::clGetCommandQueueInfo, object_, name, param),
8864 __GET_COMMAND_QUEUE_INFO_ERR);
8867 template <cl_int name> typename
8868 detail::param_traits<detail::cl_command_queue_info, name>::param_type
8869 getInfo(cl_int* err = NULL) const
8871 typename detail::param_traits<
8872 detail::cl_command_queue_info, name>::param_type param;
8873 cl_int result = getInfo(name, ¶m);
8881 * Create a new default device command queue for the default device,
8882 * in the default context and of the default size.
8883 * If there is already a default queue for the specified device this
8884 * function will return the pre-existing queue.
8886 static DeviceCommandQueue makeDefault(
8887 cl_int *err = nullptr)
8890 cl::Context context = cl::Context::getDefault();
8891 cl::Device device = cl::Device::getDefault();
8893 cl_command_queue_properties properties =
8894 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
8895 cl_queue_properties queue_properties[] = {
8896 CL_QUEUE_PROPERTIES, properties,
8898 DeviceCommandQueue deviceQueue(
8899 ::clCreateCommandQueueWithProperties(
8900 context(), device(), queue_properties, &error));
8902 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8911 * Create a new default device command queue for the specified device
8912 * and of the default size.
8913 * If there is already a default queue for the specified device this
8914 * function will return the pre-existing queue.
8916 static DeviceCommandQueue makeDefault(
8917 const Context &context, const Device &device, cl_int *err = nullptr)
8921 cl_command_queue_properties properties =
8922 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
8923 cl_queue_properties queue_properties[] = {
8924 CL_QUEUE_PROPERTIES, properties,
8926 DeviceCommandQueue deviceQueue(
8927 ::clCreateCommandQueueWithProperties(
8928 context(), device(), queue_properties, &error));
8930 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8939 * Create a new default device command queue for the specified device
8940 * and of the requested size in bytes.
8941 * If there is already a default queue for the specified device this
8942 * function will return the pre-existing queue.
8944 static DeviceCommandQueue makeDefault(
8945 const Context &context, const Device &device, cl_uint queueSize, cl_int *err = nullptr)
8949 cl_command_queue_properties properties =
8950 CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
8951 cl_queue_properties queue_properties[] = {
8952 CL_QUEUE_PROPERTIES, properties,
8953 CL_QUEUE_SIZE, queueSize,
8955 DeviceCommandQueue deviceQueue(
8956 ::clCreateCommandQueueWithProperties(
8957 context(), device(), queue_properties, &error));
8959 detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8969 #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8971 * Modify the default device command queue to be used for subsequent kernels.
8972 * This can update the default command queue for a device repeatedly to account
8973 * for kernels that rely on the default.
8974 * @return updated default device command queue.
8976 static DeviceCommandQueue updateDefault(const Context &context, const Device &device, const DeviceCommandQueue &default_queue, cl_int *err = nullptr)
8979 error = clSetDefaultDeviceCommandQueue(context.get(), device.get(), default_queue.get());
8981 detail::errHandler(error, __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR);
8985 return default_queue;
8989 * Return the current default command queue for the specified command queue
8991 static DeviceCommandQueue getDefault(const CommandQueue &queue, cl_int * err = NULL)
8993 return queue.getInfo<CL_QUEUE_DEVICE_DEFAULT>(err);
8996 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8997 }; // DeviceCommandQueue
9001 // Specialization for device command queue
9003 struct KernelArgumentHandler<cl::DeviceCommandQueue, void>
9005 static size_type size(const cl::DeviceCommandQueue&) { return sizeof(cl_command_queue); }
9006 static const cl_command_queue* ptr(const cl::DeviceCommandQueue& value) { return &(value()); }
9008 } // namespace detail
9010 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9013 template< typename IteratorType >
9015 const Context &context,
9016 IteratorType startIterator,
9017 IteratorType endIterator,
9022 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9025 cl_mem_flags flags = 0;
9027 flags |= CL_MEM_READ_ONLY;
9030 flags |= CL_MEM_READ_WRITE;
9033 flags |= CL_MEM_USE_HOST_PTR;
9036 size_type size = sizeof(DataType)*(endIterator - startIterator);
9039 object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
9041 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9044 detail::errHandler(error, __CREATE_BUFFER_ERR);
9050 CommandQueue queue(context, 0, &error);
9051 detail::errHandler(error, __CREATE_BUFFER_ERR);
9056 error = cl::copy(queue, startIterator, endIterator, *this);
9057 detail::errHandler(error, __CREATE_BUFFER_ERR);
9064 template< typename IteratorType >
9066 const CommandQueue &queue,
9067 IteratorType startIterator,
9068 IteratorType endIterator,
9073 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9076 cl_mem_flags flags = 0;
9078 flags |= CL_MEM_READ_ONLY;
9081 flags |= CL_MEM_READ_WRITE;
9084 flags |= CL_MEM_USE_HOST_PTR;
9087 size_type size = sizeof(DataType)*(endIterator - startIterator);
9089 Context context = queue.getInfo<CL_QUEUE_CONTEXT>();
9092 object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
9095 object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9098 detail::errHandler(error, __CREATE_BUFFER_ERR);
9104 error = cl::copy(queue, startIterator, endIterator, *this);
9105 detail::errHandler(error, __CREATE_BUFFER_ERR);
9112 inline cl_int enqueueReadBuffer(
9113 const Buffer& buffer,
9118 const vector<Event>* events = NULL,
9119 Event* event = NULL)
9122 CommandQueue queue = CommandQueue::getDefault(&error);
9124 if (error != CL_SUCCESS) {
9128 return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event);
9131 inline cl_int enqueueWriteBuffer(
9132 const Buffer& buffer,
9137 const vector<Event>* events = NULL,
9138 Event* event = NULL)
9141 CommandQueue queue = CommandQueue::getDefault(&error);
9143 if (error != CL_SUCCESS) {
9147 return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event);
9150 inline void* enqueueMapBuffer(
9151 const Buffer& buffer,
9156 const vector<Event>* events = NULL,
9157 Event* event = NULL,
9161 CommandQueue queue = CommandQueue::getDefault(&error);
9162 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9167 void * result = ::clEnqueueMapBuffer(
9168 queue(), buffer(), blocking, flags, offset, size,
9169 (events != NULL) ? (cl_uint) events->size() : 0,
9170 (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
9174 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9182 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9184 * Enqueues to the default queue a command that will allow the host to
9185 * update a region of a coarse-grained SVM buffer.
9186 * This variant takes a raw SVM pointer.
9188 template<typename T>
9189 inline cl_int enqueueMapSVM(
9194 const vector<Event>* events,
9198 CommandQueue queue = CommandQueue::getDefault(&error);
9199 if (error != CL_SUCCESS) {
9200 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9203 return queue.enqueueMapSVM(
9204 ptr, blocking, flags, size, events, event);
9208 * Enqueues to the default queue a command that will allow the host to
9209 * update a region of a coarse-grained SVM buffer.
9210 * This variant takes a cl::pointer instance.
9212 template<typename T, class D>
9213 inline cl_int enqueueMapSVM(
9214 cl::pointer<T, D> ptr,
9218 const vector<Event>* events = NULL,
9219 Event* event = NULL)
9222 CommandQueue queue = CommandQueue::getDefault(&error);
9223 if (error != CL_SUCCESS) {
9224 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9227 return queue.enqueueMapSVM(
9228 ptr, blocking, flags, size, events, event);
9232 * Enqueues to the default queue a command that will allow the host to
9233 * update a region of a coarse-grained SVM buffer.
9234 * This variant takes a cl::vector instance.
9236 template<typename T, class Alloc>
9237 inline cl_int enqueueMapSVM(
9238 cl::vector<T, Alloc> container,
9241 const vector<Event>* events = NULL,
9242 Event* event = NULL)
9245 CommandQueue queue = CommandQueue::getDefault(&error);
9246 if (error != CL_SUCCESS) {
9247 return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9250 return queue.enqueueMapSVM(
9251 container, blocking, flags, events, event);
9254 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9256 inline cl_int enqueueUnmapMemObject(
9257 const Memory& memory,
9259 const vector<Event>* events = NULL,
9260 Event* event = NULL)
9263 CommandQueue queue = CommandQueue::getDefault(&error);
9264 detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9265 if (error != CL_SUCCESS) {
9270 cl_int err = detail::errHandler(
9271 ::clEnqueueUnmapMemObject(
9272 queue(), memory(), mapped_ptr,
9273 (events != NULL) ? (cl_uint)events->size() : 0,
9274 (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
9275 (event != NULL) ? &tmp : NULL),
9276 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9278 if (event != NULL && err == CL_SUCCESS)
9284 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9286 * Enqueues to the default queue a command that will release a coarse-grained
9287 * SVM buffer back to the OpenCL runtime.
9288 * This variant takes a raw SVM pointer.
9290 template<typename T>
9291 inline cl_int enqueueUnmapSVM(
9293 const vector<Event>* events = NULL,
9294 Event* event = NULL)
9297 CommandQueue queue = CommandQueue::getDefault(&error);
9298 if (error != CL_SUCCESS) {
9299 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9302 return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
9303 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9308 * Enqueues to the default queue a command that will release a coarse-grained
9309 * SVM buffer back to the OpenCL runtime.
9310 * This variant takes a cl::pointer instance.
9312 template<typename T, class D>
9313 inline cl_int enqueueUnmapSVM(
9314 cl::pointer<T, D> &ptr,
9315 const vector<Event>* events = NULL,
9316 Event* event = NULL)
9319 CommandQueue queue = CommandQueue::getDefault(&error);
9320 if (error != CL_SUCCESS) {
9321 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9324 return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
9325 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9329 * Enqueues to the default queue a command that will release a coarse-grained
9330 * SVM buffer back to the OpenCL runtime.
9331 * This variant takes a cl::vector instance.
9333 template<typename T, class Alloc>
9334 inline cl_int enqueueUnmapSVM(
9335 cl::vector<T, Alloc> &container,
9336 const vector<Event>* events = NULL,
9337 Event* event = NULL)
9340 CommandQueue queue = CommandQueue::getDefault(&error);
9341 if (error != CL_SUCCESS) {
9342 return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9345 return detail::errHandler(queue.enqueueUnmapSVM(container, events, event),
9346 __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9349 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9351 inline cl_int enqueueCopyBuffer(
9354 size_type src_offset,
9355 size_type dst_offset,
9357 const vector<Event>* events = NULL,
9358 Event* event = NULL)
9361 CommandQueue queue = CommandQueue::getDefault(&error);
9363 if (error != CL_SUCCESS) {
9367 return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event);
9371 * Blocking copy operation between iterators and a buffer.
9373 * Uses default command queue.
9375 template< typename IteratorType >
9376 inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
9379 CommandQueue queue = CommandQueue::getDefault(&error);
9380 if (error != CL_SUCCESS)
9383 return cl::copy(queue, startIterator, endIterator, buffer);
9387 * Blocking copy operation between iterators and a buffer.
9389 * Uses default command queue.
9391 template< typename IteratorType >
9392 inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
9395 CommandQueue queue = CommandQueue::getDefault(&error);
9396 if (error != CL_SUCCESS)
9399 return cl::copy(queue, buffer, startIterator, endIterator);
9403 * Blocking copy operation between iterators and a buffer.
9405 * Uses specified queue.
9407 template< typename IteratorType >
9408 inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
9410 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9413 size_type length = endIterator-startIterator;
9414 size_type byteLength = length*sizeof(DataType);
9417 static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error));
9418 // if exceptions enabled, enqueueMapBuffer will throw
9419 if( error != CL_SUCCESS ) {
9422 #if defined(_MSC_VER)
9426 stdext::checked_array_iterator<DataType*>(
9429 std::copy(startIterator, endIterator, pointer);
9432 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9433 // if exceptions enabled, enqueueUnmapMemObject will throw
9434 if( error != CL_SUCCESS ) {
9442 * Blocking copy operation between iterators and a buffer.
9444 * Uses specified queue.
9446 template< typename IteratorType >
9447 inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
9449 typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9452 size_type length = endIterator-startIterator;
9453 size_type byteLength = length*sizeof(DataType);
9456 static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error));
9457 // if exceptions enabled, enqueueMapBuffer will throw
9458 if( error != CL_SUCCESS ) {
9461 std::copy(pointer, pointer + length, startIterator);
9463 error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9464 // if exceptions enabled, enqueueUnmapMemObject will throw
9465 if( error != CL_SUCCESS ) {
9473 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9475 * Blocking SVM map operation - performs a blocking map underneath.
9477 template<typename T, class Alloc>
9478 inline cl_int mapSVM(cl::vector<T, Alloc> &container)
9480 return enqueueMapSVM(container, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE);
9484 * Blocking SVM map operation - performs a blocking map underneath.
9486 template<typename T, class Alloc>
9487 inline cl_int unmapSVM(cl::vector<T, Alloc> &container)
9489 return enqueueUnmapSVM(container);
9492 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9494 #if CL_HPP_TARGET_OPENCL_VERSION >= 110
9495 inline cl_int enqueueReadBufferRect(
9496 const Buffer& buffer,
9498 const array<size_type, 3>& buffer_offset,
9499 const array<size_type, 3>& host_offset,
9500 const array<size_type, 3>& region,
9501 size_type buffer_row_pitch,
9502 size_type buffer_slice_pitch,
9503 size_type host_row_pitch,
9504 size_type host_slice_pitch,
9506 const vector<Event>* events = NULL,
9507 Event* event = NULL)
9510 CommandQueue queue = CommandQueue::getDefault(&error);
9512 if (error != CL_SUCCESS) {
9516 return queue.enqueueReadBufferRect(
9531 inline cl_int enqueueWriteBufferRect(
9532 const Buffer& buffer,
9534 const array<size_type, 3>& buffer_offset,
9535 const array<size_type, 3>& host_offset,
9536 const array<size_type, 3>& region,
9537 size_type buffer_row_pitch,
9538 size_type buffer_slice_pitch,
9539 size_type host_row_pitch,
9540 size_type host_slice_pitch,
9542 const vector<Event>* events = NULL,
9543 Event* event = NULL)
9546 CommandQueue queue = CommandQueue::getDefault(&error);
9548 if (error != CL_SUCCESS) {
9552 return queue.enqueueWriteBufferRect(
9567 inline cl_int enqueueCopyBufferRect(
9570 const array<size_type, 3>& src_origin,
9571 const array<size_type, 3>& dst_origin,
9572 const array<size_type, 3>& region,
9573 size_type src_row_pitch,
9574 size_type src_slice_pitch,
9575 size_type dst_row_pitch,
9576 size_type dst_slice_pitch,
9577 const vector<Event>* events = NULL,
9578 Event* event = NULL)
9581 CommandQueue queue = CommandQueue::getDefault(&error);
9583 if (error != CL_SUCCESS) {
9587 return queue.enqueueCopyBufferRect(
9600 #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
9602 inline cl_int enqueueReadImage(
9605 const array<size_type, 3>& origin,
9606 const array<size_type, 3>& region,
9607 size_type row_pitch,
9608 size_type slice_pitch,
9610 const vector<Event>* events = NULL,
9611 Event* event = NULL)
9614 CommandQueue queue = CommandQueue::getDefault(&error);
9616 if (error != CL_SUCCESS) {
9620 return queue.enqueueReadImage(
9632 inline cl_int enqueueWriteImage(
9635 const array<size_type, 3>& origin,
9636 const array<size_type, 3>& region,
9637 size_type row_pitch,
9638 size_type slice_pitch,
9640 const vector<Event>* events = NULL,
9641 Event* event = NULL)
9644 CommandQueue queue = CommandQueue::getDefault(&error);
9646 if (error != CL_SUCCESS) {
9650 return queue.enqueueWriteImage(
9662 inline cl_int enqueueCopyImage(
9665 const array<size_type, 3>& src_origin,
9666 const array<size_type, 3>& dst_origin,
9667 const array<size_type, 3>& region,
9668 const vector<Event>* events = NULL,
9669 Event* event = NULL)
9672 CommandQueue queue = CommandQueue::getDefault(&error);
9674 if (error != CL_SUCCESS) {
9678 return queue.enqueueCopyImage(
9688 inline cl_int enqueueCopyImageToBuffer(
9691 const array<size_type, 3>& src_origin,
9692 const array<size_type, 3>& region,
9693 size_type dst_offset,
9694 const vector<Event>* events = NULL,
9695 Event* event = NULL)
9698 CommandQueue queue = CommandQueue::getDefault(&error);
9700 if (error != CL_SUCCESS) {
9704 return queue.enqueueCopyImageToBuffer(
9714 inline cl_int enqueueCopyBufferToImage(
9717 size_type src_offset,
9718 const array<size_type, 3>& dst_origin,
9719 const array<size_type, 3>& region,
9720 const vector<Event>* events = NULL,
9721 Event* event = NULL)
9724 CommandQueue queue = CommandQueue::getDefault(&error);
9726 if (error != CL_SUCCESS) {
9730 return queue.enqueueCopyBufferToImage(
9741 inline cl_int flush(void)
9744 CommandQueue queue = CommandQueue::getDefault(&error);
9746 if (error != CL_SUCCESS) {
9750 return queue.flush();
9753 inline cl_int finish(void)
9756 CommandQueue queue = CommandQueue::getDefault(&error);
9758 if (error != CL_SUCCESS) {
9763 return queue.finish();
9769 CommandQueue queue_;
9770 const NDRange offset_;
9771 const NDRange global_;
9772 const NDRange local_;
9773 vector<Event> events_;
9775 template<typename... Ts>
9776 friend class KernelFunctor;
9779 EnqueueArgs(NDRange global) :
9780 queue_(CommandQueue::getDefault()),
9788 EnqueueArgs(NDRange global, NDRange local) :
9789 queue_(CommandQueue::getDefault()),
9797 EnqueueArgs(NDRange offset, NDRange global, NDRange local) :
9798 queue_(CommandQueue::getDefault()),
9806 EnqueueArgs(Event e, NDRange global) :
9807 queue_(CommandQueue::getDefault()),
9812 events_.push_back(e);
9815 EnqueueArgs(Event e, NDRange global, NDRange local) :
9816 queue_(CommandQueue::getDefault()),
9821 events_.push_back(e);
9824 EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) :
9825 queue_(CommandQueue::getDefault()),
9830 events_.push_back(e);
9833 EnqueueArgs(const vector<Event> &events, NDRange global) :
9834 queue_(CommandQueue::getDefault()),
9843 EnqueueArgs(const vector<Event> &events, NDRange global, NDRange local) :
9844 queue_(CommandQueue::getDefault()),
9853 EnqueueArgs(const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
9854 queue_(CommandQueue::getDefault()),
9863 EnqueueArgs(CommandQueue &queue, NDRange global) :
9872 EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) :
9881 EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) :
9890 EnqueueArgs(CommandQueue &queue, Event e, NDRange global) :
9896 events_.push_back(e);
9899 EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) :
9905 events_.push_back(e);
9908 EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) :
9914 events_.push_back(e);
9917 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global) :
9927 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global, NDRange local) :
9937 EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
9949 //----------------------------------------------------------------------------------------------
9953 * Type safe kernel functor.
9956 template<typename... Ts>
9962 template<int index, typename T0, typename... T1s>
9963 void setArgs(T0&& t0, T1s&&... t1s)
9965 kernel_.setArg(index, t0);
9966 setArgs<index + 1, T1s...>(std::forward<T1s>(t1s)...);
9969 template<int index, typename T0>
9970 void setArgs(T0&& t0)
9972 kernel_.setArg(index, t0);
9982 KernelFunctor(Kernel kernel) : kernel_(kernel)
9986 const Program& program,
9988 cl_int * err = NULL) :
9989 kernel_(program, name.c_str(), err)
9992 //! \brief Return type of the functor
9993 typedef Event result_type;
9997 * @param args Launch parameters of the kernel.
9998 * @param t0... List of kernel arguments based on the template type of the functor.
10001 const EnqueueArgs& args,
10005 setArgs<0>(std::forward<Ts>(ts)...);
10007 args.queue_.enqueueNDRangeKernel(
10019 * Enqueue kernel with support for error code.
10020 * @param args Launch parameters of the kernel.
10021 * @param t0... List of kernel arguments based on the template type of the functor.
10022 * @param error Out parameter returning the error code from the execution.
10025 const EnqueueArgs& args,
10030 setArgs<0>(std::forward<Ts>(ts)...);
10032 error = args.queue_.enqueueNDRangeKernel(
10043 #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10044 cl_int setSVMPointers(const vector<void*> &pointerList)
10046 return kernel_.setSVMPointers(pointerList);
10049 template<typename T0, typename... T1s>
10050 cl_int setSVMPointers(const T0 &t0, T1s &... ts)
10052 return kernel_.setSVMPointers(t0, ts...);
10054 #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10062 namespace compatibility {
10064 * Backward compatibility class to ensure that cl.hpp code works with cl2.hpp.
10065 * Please use KernelFunctor directly.
10067 template<typename... Ts>
10070 typedef KernelFunctor<Ts...> FunctorType;
10072 FunctorType functor_;
10075 const Program& program,
10077 cl_int * err = NULL) :
10078 functor_(FunctorType(program, name, err))
10082 const Kernel kernel) :
10083 functor_(FunctorType(kernel))
10086 //! \brief Return type of the functor
10087 typedef Event result_type;
10089 //! \brief Function signature of kernel functor with no event dependency.
10090 typedef Event type_(
10091 const EnqueueArgs&,
10095 const EnqueueArgs& enqueueArgs,
10099 enqueueArgs, args...);
10102 } // namespace compatibility
10105 //----------------------------------------------------------------------------------------------------------------------
10107 #undef CL_HPP_ERR_STR_
10108 #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
10109 #undef __GET_DEVICE_INFO_ERR
10110 #undef __GET_PLATFORM_INFO_ERR
10111 #undef __GET_DEVICE_IDS_ERR
10112 #undef __GET_PLATFORM_IDS_ERR
10113 #undef __GET_CONTEXT_INFO_ERR
10114 #undef __GET_EVENT_INFO_ERR
10115 #undef __GET_EVENT_PROFILE_INFO_ERR
10116 #undef __GET_MEM_OBJECT_INFO_ERR
10117 #undef __GET_IMAGE_INFO_ERR
10118 #undef __GET_SAMPLER_INFO_ERR
10119 #undef __GET_KERNEL_INFO_ERR
10120 #undef __GET_KERNEL_ARG_INFO_ERR
10121 #undef __GET_KERNEL_SUB_GROUP_INFO_ERR
10122 #undef __GET_KERNEL_WORK_GROUP_INFO_ERR
10123 #undef __GET_PROGRAM_INFO_ERR
10124 #undef __GET_PROGRAM_BUILD_INFO_ERR
10125 #undef __GET_COMMAND_QUEUE_INFO_ERR
10126 #undef __CREATE_CONTEXT_ERR
10127 #undef __CREATE_CONTEXT_FROM_TYPE_ERR
10128 #undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
10129 #undef __CREATE_BUFFER_ERR
10131 #undef __CREATE_SUBBUFFER_ERR
10132 #undef __CREATE_GL_BUFFER_ERR
10133 #undef __CREATE_GL_RENDER_BUFFER_ERR
10134 #undef __GET_GL_OBJECT_INFO_ERR
10135 #undef __CREATE_IMAGE_ERR
10136 #undef __CREATE_GL_TEXTURE_ERR
10137 #undef __IMAGE_DIMENSION_ERR
10138 #undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
10139 #undef __CREATE_USER_EVENT_ERR
10140 #undef __SET_USER_EVENT_STATUS_ERR
10141 #undef __SET_EVENT_CALLBACK_ERR
10142 #undef __WAIT_FOR_EVENTS_ERR
10143 #undef __CREATE_KERNEL_ERR
10144 #undef __SET_KERNEL_ARGS_ERR
10145 #undef __CREATE_PROGRAM_WITH_SOURCE_ERR
10146 #undef __CREATE_PROGRAM_WITH_IL_ERR
10147 #undef __CREATE_PROGRAM_WITH_BINARY_ERR
10148 #undef __CREATE_PROGRAM_WITH_IL_ERR
10149 #undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR
10150 #undef __BUILD_PROGRAM_ERR
10151 #undef __COMPILE_PROGRAM_ERR
10152 #undef __LINK_PROGRAM_ERR
10153 #undef __CREATE_KERNELS_IN_PROGRAM_ERR
10154 #undef __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR
10155 #undef __CREATE_SAMPLER_WITH_PROPERTIES_ERR
10156 #undef __SET_COMMAND_QUEUE_PROPERTY_ERR
10157 #undef __ENQUEUE_READ_BUFFER_ERR
10158 #undef __ENQUEUE_READ_BUFFER_RECT_ERR
10159 #undef __ENQUEUE_WRITE_BUFFER_ERR
10160 #undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
10161 #undef __ENQEUE_COPY_BUFFER_ERR
10162 #undef __ENQEUE_COPY_BUFFER_RECT_ERR
10163 #undef __ENQUEUE_FILL_BUFFER_ERR
10164 #undef __ENQUEUE_READ_IMAGE_ERR
10165 #undef __ENQUEUE_WRITE_IMAGE_ERR
10166 #undef __ENQUEUE_COPY_IMAGE_ERR
10167 #undef __ENQUEUE_FILL_IMAGE_ERR
10168 #undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
10169 #undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
10170 #undef __ENQUEUE_MAP_BUFFER_ERR
10171 #undef __ENQUEUE_MAP_IMAGE_ERR
10172 #undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
10173 #undef __ENQUEUE_NDRANGE_KERNEL_ERR
10174 #undef __ENQUEUE_NATIVE_KERNEL
10175 #undef __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR
10176 #undef __ENQUEUE_MIGRATE_SVM_ERR
10177 #undef __ENQUEUE_ACQUIRE_GL_ERR
10178 #undef __ENQUEUE_RELEASE_GL_ERR
10179 #undef __CREATE_PIPE_ERR
10180 #undef __GET_PIPE_INFO_ERR
10181 #undef __RETAIN_ERR
10182 #undef __RELEASE_ERR
10184 #undef __FINISH_ERR
10185 #undef __VECTOR_CAPACITY_ERR
10186 #undef __CREATE_SUB_DEVICES_ERR
10187 #undef __CREATE_SUB_DEVICES_ERR
10188 #undef __ENQUEUE_MARKER_ERR
10189 #undef __ENQUEUE_WAIT_FOR_EVENTS_ERR
10190 #undef __ENQUEUE_BARRIER_ERR
10191 #undef __UNLOAD_COMPILER_ERR
10192 #undef __CREATE_GL_TEXTURE_2D_ERR
10193 #undef __CREATE_GL_TEXTURE_3D_ERR
10194 #undef __CREATE_IMAGE2D_ERR
10195 #undef __CREATE_IMAGE3D_ERR
10196 #undef __CREATE_COMMAND_QUEUE_ERR
10197 #undef __ENQUEUE_TASK_ERR
10198 #undef __CREATE_SAMPLER_ERR
10199 #undef __ENQUEUE_MARKER_WAIT_LIST_ERR
10200 #undef __ENQUEUE_BARRIER_WAIT_LIST_ERR
10201 #undef __CLONE_KERNEL_ERR
10202 #undef __GET_HOST_TIMER_ERR
10203 #undef __GET_DEVICE_AND_HOST_TIMER_ERR
10205 #endif //CL_HPP_USER_OVERRIDE_ERROR_STRINGS
10208 #undef CL_HPP_INIT_CL_EXT_FCN_PTR_
10209 #undef CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_
10211 #if defined(CL_HPP_USE_CL_DEVICE_FISSION)
10212 #undef CL_HPP_PARAM_NAME_DEVICE_FISSION_
10213 #endif // CL_HPP_USE_CL_DEVICE_FISSION
10215 #undef CL_HPP_NOEXCEPT_
10216 #undef CL_HPP_DEFINE_STATIC_MEMBER_