1*c217d954SCole Faust //
2*c217d954SCole Faust // Copyright (c) 2008-2020 The Khronos Group Inc.
3*c217d954SCole Faust //
4*c217d954SCole Faust // Licensed under the Apache License, Version 2.0 (the "License");
5*c217d954SCole Faust // you may not use this file except in compliance with the License.
6*c217d954SCole Faust // You may obtain a copy of the License at
7*c217d954SCole Faust //
8*c217d954SCole Faust // http://www.apache.org/licenses/LICENSE-2.0
9*c217d954SCole Faust //
10*c217d954SCole Faust // Unless required by applicable law or agreed to in writing, software
11*c217d954SCole Faust // distributed under the License is distributed on an "AS IS" BASIS,
12*c217d954SCole Faust // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*c217d954SCole Faust // See the License for the specific language governing permissions and
14*c217d954SCole Faust // limitations under the License.
15*c217d954SCole Faust //
16*c217d954SCole Faust
17*c217d954SCole Faust /*! \file
18*c217d954SCole Faust *
19*c217d954SCole Faust * \brief C++ bindings for OpenCL 1.0, OpenCL 1.1, OpenCL 1.2,
20*c217d954SCole Faust * OpenCL 2.0, OpenCL 2.1, OpenCL 2.2, and OpenCL 3.0.
21*c217d954SCole Faust * \author Lee Howes and Bruce Merry
22*c217d954SCole Faust *
23*c217d954SCole Faust * Derived from the OpenCL 1.x C++ bindings written by
24*c217d954SCole Faust * Benedict R. Gaster, Laurent Morichetti and Lee Howes
25*c217d954SCole Faust * With additions and fixes from:
26*c217d954SCole Faust * Brian Cole, March 3rd 2010 and April 2012
27*c217d954SCole Faust * Matt Gruenke, April 2012.
28*c217d954SCole Faust * Bruce Merry, February 2013.
29*c217d954SCole Faust * Tom Deakin and Simon McIntosh-Smith, July 2013
30*c217d954SCole Faust * James Price, 2015-
31*c217d954SCole Faust * \version 2.2.0
32*c217d954SCole Faust * \date 2019-09-18
33*c217d954SCole Faust *
34*c217d954SCole Faust * Optional extension support
35*c217d954SCole Faust *
36*c217d954SCole Faust * cl_ext_device_fission
37*c217d954SCole Faust * #define CL_HPP_USE_CL_DEVICE_FISSION
38*c217d954SCole Faust * cl_khr_d3d10_sharing
39*c217d954SCole Faust * #define CL_HPP_USE_DX_INTEROP
40*c217d954SCole Faust * cl_khr_sub_groups
41*c217d954SCole Faust * #define CL_HPP_USE_CL_SUB_GROUPS_KHR
42*c217d954SCole Faust * cl_khr_image2d_from_buffer
43*c217d954SCole Faust * #define CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR
44*c217d954SCole Faust *
45*c217d954SCole Faust * Doxygen documentation for this header is available here:
46*c217d954SCole Faust *
47*c217d954SCole Faust * http://khronosgroup.github.io/OpenCL-CLHPP/
48*c217d954SCole Faust *
49*c217d954SCole Faust * The latest version of this header can be found on the GitHub releases page:
50*c217d954SCole Faust *
51*c217d954SCole Faust * https://github.com/KhronosGroup/OpenCL-CLHPP/releases
52*c217d954SCole Faust *
53*c217d954SCole Faust * Bugs and patches can be submitted to the GitHub repository:
54*c217d954SCole Faust *
55*c217d954SCole Faust * https://github.com/KhronosGroup/OpenCL-CLHPP
56*c217d954SCole Faust */
57*c217d954SCole Faust
58*c217d954SCole Faust /*! \mainpage
59*c217d954SCole Faust * \section intro Introduction
60*c217d954SCole Faust * For many large applications C++ is the language of choice and so it seems
61*c217d954SCole Faust * reasonable to define C++ bindings for OpenCL.
62*c217d954SCole Faust *
63*c217d954SCole Faust * The interface is contained with a single C++ header file \em opencl.hpp and all
64*c217d954SCole Faust * definitions are contained within the namespace \em cl. There is no additional
65*c217d954SCole Faust * requirement to include \em cl.h and to use either the C++ or original C
66*c217d954SCole Faust * bindings; it is enough to simply include \em opencl.hpp.
67*c217d954SCole Faust *
68*c217d954SCole Faust * The bindings themselves are lightweight and correspond closely to the
69*c217d954SCole Faust * underlying C API. Using the C++ bindings introduces no additional execution
70*c217d954SCole Faust * overhead.
71*c217d954SCole Faust *
72*c217d954SCole Faust * There are numerous compatibility, portability and memory management
73*c217d954SCole Faust * fixes in the new header as well as additional OpenCL 2.0 features.
74*c217d954SCole Faust * As a result the header is not directly backward compatible and for this
75*c217d954SCole Faust * reason we release it as opencl.hpp rather than a new version of cl.hpp.
76*c217d954SCole Faust *
77*c217d954SCole Faust *
78*c217d954SCole Faust * \section compatibility Compatibility
79*c217d954SCole Faust * Due to the evolution of the underlying OpenCL API the 2.0 C++ bindings
80*c217d954SCole Faust * include an updated approach to defining supported feature versions
81*c217d954SCole Faust * and the range of valid underlying OpenCL runtime versions supported.
82*c217d954SCole Faust *
83*c217d954SCole Faust * The combination of preprocessor macros CL_HPP_TARGET_OPENCL_VERSION and
84*c217d954SCole Faust * CL_HPP_MINIMUM_OPENCL_VERSION control this range. These are three digit
85*c217d954SCole Faust * decimal values representing OpenCL runime versions. The default for
86*c217d954SCole Faust * the target is 200, representing OpenCL 2.0 and the minimum is also
87*c217d954SCole Faust * defined as 200. These settings would use 2.0 API calls only.
88*c217d954SCole Faust * If backward compatibility with a 1.2 runtime is required, the minimum
89*c217d954SCole Faust * version may be set to 120.
90*c217d954SCole Faust *
91*c217d954SCole Faust * Note that this is a compile-time setting, and so affects linking against
92*c217d954SCole Faust * a particular SDK version rather than the versioning of the loaded runtime.
93*c217d954SCole Faust *
94*c217d954SCole Faust * The earlier versions of the header included basic vector and string
95*c217d954SCole Faust * classes based loosely on STL versions. These were difficult to
96*c217d954SCole Faust * maintain and very rarely used. For the 2.0 header we now assume
97*c217d954SCole Faust * the presence of the standard library unless requested otherwise.
98*c217d954SCole Faust * We use std::array, std::vector, std::shared_ptr and std::string
99*c217d954SCole Faust * throughout to safely manage memory and reduce the chance of a
100*c217d954SCole Faust * recurrance of earlier memory management bugs.
101*c217d954SCole Faust *
102*c217d954SCole Faust * These classes are used through typedefs in the cl namespace:
103*c217d954SCole Faust * cl::array, cl::vector, cl::pointer and cl::string.
104*c217d954SCole Faust * In addition cl::allocate_pointer forwards to std::allocate_shared
105*c217d954SCole Faust * by default.
106*c217d954SCole Faust * In all cases these standard library classes can be replaced with
107*c217d954SCole Faust * custom interface-compatible versions using the CL_HPP_NO_STD_ARRAY,
108*c217d954SCole Faust * CL_HPP_NO_STD_VECTOR, CL_HPP_NO_STD_UNIQUE_PTR and
109*c217d954SCole Faust * CL_HPP_NO_STD_STRING macros.
110*c217d954SCole Faust *
111*c217d954SCole Faust * The OpenCL 1.x versions of the C++ bindings included a size_t wrapper
112*c217d954SCole Faust * class to interface with kernel enqueue. This caused unpleasant interactions
113*c217d954SCole Faust * with the standard size_t declaration and led to namespacing bugs.
114*c217d954SCole Faust * In the 2.0 version we have replaced this with a std::array-based interface.
115*c217d954SCole Faust * However, the old behaviour can be regained for backward compatibility
116*c217d954SCole Faust * using the CL_HPP_ENABLE_SIZE_T_COMPATIBILITY macro.
117*c217d954SCole Faust *
118*c217d954SCole Faust * Finally, the program construction interface used a clumsy vector-of-pairs
119*c217d954SCole Faust * design in the earlier versions. We have replaced that with a cleaner
120*c217d954SCole Faust * vector-of-vectors and vector-of-strings design. However, for backward
121*c217d954SCole Faust * compatibility old behaviour can be regained with the
122*c217d954SCole Faust * CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY macro.
123*c217d954SCole Faust *
124*c217d954SCole Faust * In OpenCL 2.0 OpenCL C is not entirely backward compatibility with
125*c217d954SCole Faust * earlier versions. As a result a flag must be passed to the OpenCL C
126*c217d954SCole Faust * compiled to request OpenCL 2.0 compilation of kernels with 1.2 as
127*c217d954SCole Faust * the default in the absence of the flag.
128*c217d954SCole Faust * In some cases the C++ bindings automatically compile code for ease.
129*c217d954SCole Faust * For those cases the compilation defaults to OpenCL C 2.0.
130*c217d954SCole Faust * If this is not wanted, the CL_HPP_CL_1_2_DEFAULT_BUILD macro may
131*c217d954SCole Faust * be specified to assume 1.2 compilation.
132*c217d954SCole Faust * If more fine-grained decisions on a per-kernel bases are required
133*c217d954SCole Faust * then explicit build operations that take the flag should be used.
134*c217d954SCole Faust *
135*c217d954SCole Faust *
136*c217d954SCole Faust * \section parameterization Parameters
137*c217d954SCole Faust * This header may be parameterized by a set of preprocessor macros.
138*c217d954SCole Faust *
139*c217d954SCole Faust * - CL_HPP_TARGET_OPENCL_VERSION
140*c217d954SCole Faust *
141*c217d954SCole Faust * Defines the target OpenCL runtime version to build the header
142*c217d954SCole Faust * against. Defaults to 200, representing OpenCL 2.0.
143*c217d954SCole Faust *
144*c217d954SCole Faust * - CL_HPP_NO_STD_STRING
145*c217d954SCole Faust *
146*c217d954SCole Faust * Do not use the standard library string class. cl::string is not
147*c217d954SCole Faust * defined and may be defined by the user before opencl.hpp is
148*c217d954SCole Faust * included.
149*c217d954SCole Faust *
150*c217d954SCole Faust * - CL_HPP_NO_STD_VECTOR
151*c217d954SCole Faust *
152*c217d954SCole Faust * Do not use the standard library vector class. cl::vector is not
153*c217d954SCole Faust * defined and may be defined by the user before opencl.hpp is
154*c217d954SCole Faust * included.
155*c217d954SCole Faust *
156*c217d954SCole Faust * - CL_HPP_NO_STD_ARRAY
157*c217d954SCole Faust *
158*c217d954SCole Faust * Do not use the standard library array class. cl::array is not
159*c217d954SCole Faust * defined and may be defined by the user before opencl.hpp is
160*c217d954SCole Faust * included.
161*c217d954SCole Faust *
162*c217d954SCole Faust * - CL_HPP_NO_STD_UNIQUE_PTR
163*c217d954SCole Faust *
164*c217d954SCole Faust * Do not use the standard library unique_ptr class. cl::pointer and
165*c217d954SCole Faust * the cl::allocate_pointer functions are not defined and may be
166*c217d954SCole Faust * defined by the user before opencl.hpp is included.
167*c217d954SCole Faust *
168*c217d954SCole Faust * - CL_HPP_ENABLE_DEVICE_FISSION
169*c217d954SCole Faust *
170*c217d954SCole Faust * Enables device fission for OpenCL 1.2 platforms.
171*c217d954SCole Faust *
172*c217d954SCole Faust * - CL_HPP_ENABLE_EXCEPTIONS
173*c217d954SCole Faust *
174*c217d954SCole Faust * Enable exceptions for use in the C++ bindings header. This is the
175*c217d954SCole Faust * preferred error handling mechanism but is not required.
176*c217d954SCole Faust *
177*c217d954SCole Faust * - CL_HPP_ENABLE_SIZE_T_COMPATIBILITY
178*c217d954SCole Faust *
179*c217d954SCole Faust * Backward compatibility option to support cl.hpp-style size_t
180*c217d954SCole Faust * class. Replaces the updated std::array derived version and
181*c217d954SCole Faust * removal of size_t from the namespace. Note that in this case the
182*c217d954SCole Faust * new size_t class is placed in the cl::compatibility namespace and
183*c217d954SCole Faust * thus requires an additional using declaration for direct backward
184*c217d954SCole Faust * compatibility.
185*c217d954SCole Faust *
186*c217d954SCole Faust * - CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY
187*c217d954SCole Faust *
188*c217d954SCole Faust * Enable older vector of pairs interface for construction of
189*c217d954SCole Faust * programs.
190*c217d954SCole Faust *
191*c217d954SCole Faust * - CL_HPP_CL_1_2_DEFAULT_BUILD
192*c217d954SCole Faust *
193*c217d954SCole Faust * Default to OpenCL C 1.2 compilation rather than OpenCL C 2.0
194*c217d954SCole Faust * applies to use of cl::Program construction and other program
195*c217d954SCole Faust * build variants.
196*c217d954SCole Faust *
197*c217d954SCole Faust * - CL_HPP_USE_CL_SUB_GROUPS_KHR
198*c217d954SCole Faust *
199*c217d954SCole Faust * Enable the cl_khr_subgroups extension.
200*c217d954SCole Faust *
201*c217d954SCole Faust * - CL_HPP_USE_IL_KHR
202*c217d954SCole Faust *
203*c217d954SCole Faust * Enable the cl_khr_il_program extension.
204*c217d954SCole Faust *
205*c217d954SCole Faust *
206*c217d954SCole Faust * \section example Example
207*c217d954SCole Faust *
208*c217d954SCole Faust * The following example shows a general use case for the C++
209*c217d954SCole Faust * bindings, including support for the optional exception feature and
210*c217d954SCole Faust * also the supplied vector and string classes, see following sections for
211*c217d954SCole Faust * decriptions of these features.
212*c217d954SCole Faust *
213*c217d954SCole Faust * \code
214*c217d954SCole Faust #define CL_HPP_ENABLE_EXCEPTIONS
215*c217d954SCole Faust #define CL_HPP_TARGET_OPENCL_VERSION 200
216*c217d954SCole Faust
217*c217d954SCole Faust #include <CL/opencl.hpp>
218*c217d954SCole Faust #include <iostream>
219*c217d954SCole Faust #include <vector>
220*c217d954SCole Faust #include <memory>
221*c217d954SCole Faust #include <algorithm>
222*c217d954SCole Faust
223*c217d954SCole Faust const int numElements = 32;
224*c217d954SCole Faust
225*c217d954SCole Faust int main(void)
226*c217d954SCole Faust {
227*c217d954SCole Faust // Filter for a 2.0 platform and set it as the default
228*c217d954SCole Faust std::vector<cl::Platform> platforms;
229*c217d954SCole Faust cl::Platform::get(&platforms);
230*c217d954SCole Faust cl::Platform plat;
231*c217d954SCole Faust for (auto &p : platforms) {
232*c217d954SCole Faust std::string platver = p.getInfo<CL_PLATFORM_VERSION>();
233*c217d954SCole Faust if (platver.find("OpenCL 2.") != std::string::npos) {
234*c217d954SCole Faust plat = p;
235*c217d954SCole Faust }
236*c217d954SCole Faust }
237*c217d954SCole Faust if (plat() == 0) {
238*c217d954SCole Faust std::cout << "No OpenCL 2.0 platform found.";
239*c217d954SCole Faust return -1;
240*c217d954SCole Faust }
241*c217d954SCole Faust
242*c217d954SCole Faust cl::Platform newP = cl::Platform::setDefault(plat);
243*c217d954SCole Faust if (newP != plat) {
244*c217d954SCole Faust std::cout << "Error setting default platform.";
245*c217d954SCole Faust return -1;
246*c217d954SCole Faust }
247*c217d954SCole Faust
248*c217d954SCole Faust // Use C++11 raw string literals for kernel source code
249*c217d954SCole Faust std::string kernel1{R"CLC(
250*c217d954SCole Faust global int globalA;
251*c217d954SCole Faust kernel void updateGlobal()
252*c217d954SCole Faust {
253*c217d954SCole Faust globalA = 75;
254*c217d954SCole Faust }
255*c217d954SCole Faust )CLC"};
256*c217d954SCole Faust std::string kernel2{R"CLC(
257*c217d954SCole Faust typedef struct { global int *bar; } Foo;
258*c217d954SCole Faust kernel void vectorAdd(global const Foo* aNum, global const int *inputA, global const int *inputB,
259*c217d954SCole Faust global int *output, int val, write_only pipe int outPipe, queue_t childQueue)
260*c217d954SCole Faust {
261*c217d954SCole Faust output[get_global_id(0)] = inputA[get_global_id(0)] + inputB[get_global_id(0)] + val + *(aNum->bar);
262*c217d954SCole Faust write_pipe(outPipe, &val);
263*c217d954SCole Faust queue_t default_queue = get_default_queue();
264*c217d954SCole Faust ndrange_t ndrange = ndrange_1D(get_global_size(0)/2, get_global_size(0)/2);
265*c217d954SCole Faust
266*c217d954SCole Faust // Have a child kernel write into third quarter of output
267*c217d954SCole Faust enqueue_kernel(default_queue, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange,
268*c217d954SCole Faust ^{
269*c217d954SCole Faust output[get_global_size(0)*2 + get_global_id(0)] =
270*c217d954SCole Faust inputA[get_global_size(0)*2 + get_global_id(0)] + inputB[get_global_size(0)*2 + get_global_id(0)] + globalA;
271*c217d954SCole Faust });
272*c217d954SCole Faust
273*c217d954SCole Faust // Have a child kernel write into last quarter of output
274*c217d954SCole Faust enqueue_kernel(childQueue, CLK_ENQUEUE_FLAGS_WAIT_KERNEL, ndrange,
275*c217d954SCole Faust ^{
276*c217d954SCole Faust output[get_global_size(0)*3 + get_global_id(0)] =
277*c217d954SCole Faust inputA[get_global_size(0)*3 + get_global_id(0)] + inputB[get_global_size(0)*3 + get_global_id(0)] + globalA + 2;
278*c217d954SCole Faust });
279*c217d954SCole Faust }
280*c217d954SCole Faust )CLC"};
281*c217d954SCole Faust
282*c217d954SCole Faust // New simpler string interface style
283*c217d954SCole Faust std::vector<std::string> programStrings {kernel1, kernel2};
284*c217d954SCole Faust
285*c217d954SCole Faust cl::Program vectorAddProgram(programStrings);
286*c217d954SCole Faust try {
287*c217d954SCole Faust vectorAddProgram.build("-cl-std=CL2.0");
288*c217d954SCole Faust }
289*c217d954SCole Faust catch (...) {
290*c217d954SCole Faust // Print build info for all devices
291*c217d954SCole Faust cl_int buildErr = CL_SUCCESS;
292*c217d954SCole Faust auto buildInfo = vectorAddProgram.getBuildInfo<CL_PROGRAM_BUILD_LOG>(&buildErr);
293*c217d954SCole Faust for (auto &pair : buildInfo) {
294*c217d954SCole Faust std::cerr << pair.second << std::endl << std::endl;
295*c217d954SCole Faust }
296*c217d954SCole Faust
297*c217d954SCole Faust return 1;
298*c217d954SCole Faust }
299*c217d954SCole Faust
300*c217d954SCole Faust typedef struct { int *bar; } Foo;
301*c217d954SCole Faust
302*c217d954SCole Faust // Get and run kernel that initializes the program-scope global
303*c217d954SCole Faust // A test for kernels that take no arguments
304*c217d954SCole Faust auto program2Kernel =
305*c217d954SCole Faust cl::KernelFunctor<>(vectorAddProgram, "updateGlobal");
306*c217d954SCole Faust program2Kernel(
307*c217d954SCole Faust cl::EnqueueArgs(
308*c217d954SCole Faust cl::NDRange(1)));
309*c217d954SCole Faust
310*c217d954SCole Faust //////////////////
311*c217d954SCole Faust // SVM allocations
312*c217d954SCole Faust
313*c217d954SCole Faust auto anSVMInt = cl::allocate_svm<int, cl::SVMTraitCoarse<>>();
314*c217d954SCole Faust *anSVMInt = 5;
315*c217d954SCole Faust cl::SVMAllocator<Foo, cl::SVMTraitCoarse<cl::SVMTraitReadOnly<>>> svmAllocReadOnly;
316*c217d954SCole Faust auto fooPointer = cl::allocate_pointer<Foo>(svmAllocReadOnly);
317*c217d954SCole Faust fooPointer->bar = anSVMInt.get();
318*c217d954SCole Faust cl::SVMAllocator<int, cl::SVMTraitCoarse<>> svmAlloc;
319*c217d954SCole Faust std::vector<int, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>> inputA(numElements, 1, svmAlloc);
320*c217d954SCole Faust cl::coarse_svm_vector<int> inputB(numElements, 2, svmAlloc);
321*c217d954SCole Faust
322*c217d954SCole Faust //
323*c217d954SCole Faust //////////////
324*c217d954SCole Faust
325*c217d954SCole Faust // Traditional cl_mem allocations
326*c217d954SCole Faust std::vector<int> output(numElements, 0xdeadbeef);
327*c217d954SCole Faust cl::Buffer outputBuffer(begin(output), end(output), false);
328*c217d954SCole Faust cl::Pipe aPipe(sizeof(cl_int), numElements / 2);
329*c217d954SCole Faust
330*c217d954SCole Faust // Default command queue, also passed in as a parameter
331*c217d954SCole Faust cl::DeviceCommandQueue defaultDeviceQueue = cl::DeviceCommandQueue::makeDefault(
332*c217d954SCole Faust cl::Context::getDefault(), cl::Device::getDefault());
333*c217d954SCole Faust
334*c217d954SCole Faust auto vectorAddKernel =
335*c217d954SCole Faust cl::KernelFunctor<
336*c217d954SCole Faust decltype(fooPointer)&,
337*c217d954SCole Faust int*,
338*c217d954SCole Faust cl::coarse_svm_vector<int>&,
339*c217d954SCole Faust cl::Buffer,
340*c217d954SCole Faust int,
341*c217d954SCole Faust cl::Pipe&,
342*c217d954SCole Faust cl::DeviceCommandQueue
343*c217d954SCole Faust >(vectorAddProgram, "vectorAdd");
344*c217d954SCole Faust
345*c217d954SCole Faust // Ensure that the additional SVM pointer is available to the kernel
346*c217d954SCole Faust // This one was not passed as a parameter
347*c217d954SCole Faust vectorAddKernel.setSVMPointers(anSVMInt);
348*c217d954SCole Faust
349*c217d954SCole Faust // Hand control of coarse allocations to runtime
350*c217d954SCole Faust cl::enqueueUnmapSVM(anSVMInt);
351*c217d954SCole Faust cl::enqueueUnmapSVM(fooPointer);
352*c217d954SCole Faust cl::unmapSVM(inputB);
353*c217d954SCole Faust cl::unmapSVM(output2);
354*c217d954SCole Faust
355*c217d954SCole Faust cl_int error;
356*c217d954SCole Faust vectorAddKernel(
357*c217d954SCole Faust cl::EnqueueArgs(
358*c217d954SCole Faust cl::NDRange(numElements/2),
359*c217d954SCole Faust cl::NDRange(numElements/2)),
360*c217d954SCole Faust fooPointer,
361*c217d954SCole Faust inputA.data(),
362*c217d954SCole Faust inputB,
363*c217d954SCole Faust outputBuffer,
364*c217d954SCole Faust 3,
365*c217d954SCole Faust aPipe,
366*c217d954SCole Faust defaultDeviceQueue,
367*c217d954SCole Faust error
368*c217d954SCole Faust );
369*c217d954SCole Faust
370*c217d954SCole Faust cl::copy(outputBuffer, begin(output), end(output));
371*c217d954SCole Faust // Grab the SVM output vector using a map
372*c217d954SCole Faust cl::mapSVM(output2);
373*c217d954SCole Faust
374*c217d954SCole Faust cl::Device d = cl::Device::getDefault();
375*c217d954SCole Faust
376*c217d954SCole Faust std::cout << "Output:\n";
377*c217d954SCole Faust for (int i = 1; i < numElements; ++i) {
378*c217d954SCole Faust std::cout << "\t" << output[i] << "\n";
379*c217d954SCole Faust }
380*c217d954SCole Faust std::cout << "\n\n";
381*c217d954SCole Faust
382*c217d954SCole Faust return 0;
383*c217d954SCole Faust }
384*c217d954SCole Faust *
385*c217d954SCole Faust * \endcode
386*c217d954SCole Faust *
387*c217d954SCole Faust */
388*c217d954SCole Faust #ifndef CL_HPP_
389*c217d954SCole Faust #define CL_HPP_
390*c217d954SCole Faust
391*c217d954SCole Faust /* Handle deprecated preprocessor definitions. In each case, we only check for
392*c217d954SCole Faust * the old name if the new name is not defined, so that user code can define
393*c217d954SCole Faust * both and hence work with either version of the bindings.
394*c217d954SCole Faust */
395*c217d954SCole Faust #if !defined(CL_HPP_USE_DX_INTEROP) && defined(USE_DX_INTEROP)
396*c217d954SCole Faust # pragma message("opencl.hpp: USE_DX_INTEROP is deprecated. Define CL_HPP_USE_DX_INTEROP instead")
397*c217d954SCole Faust # define CL_HPP_USE_DX_INTEROP
398*c217d954SCole Faust #endif
399*c217d954SCole Faust #if !defined(CL_HPP_USE_CL_DEVICE_FISSION) && defined(USE_CL_DEVICE_FISSION)
400*c217d954SCole Faust # pragma message("opencl.hpp: USE_CL_DEVICE_FISSION is deprecated. Define CL_HPP_USE_CL_DEVICE_FISSION instead")
401*c217d954SCole Faust # define CL_HPP_USE_CL_DEVICE_FISSION
402*c217d954SCole Faust #endif
403*c217d954SCole Faust #if !defined(CL_HPP_ENABLE_EXCEPTIONS) && defined(__CL_ENABLE_EXCEPTIONS)
404*c217d954SCole Faust # pragma message("opencl.hpp: __CL_ENABLE_EXCEPTIONS is deprecated. Define CL_HPP_ENABLE_EXCEPTIONS instead")
405*c217d954SCole Faust # define CL_HPP_ENABLE_EXCEPTIONS
406*c217d954SCole Faust #endif
407*c217d954SCole Faust #if !defined(CL_HPP_NO_STD_VECTOR) && defined(__NO_STD_VECTOR)
408*c217d954SCole Faust # pragma message("opencl.hpp: __NO_STD_VECTOR is deprecated. Define CL_HPP_NO_STD_VECTOR instead")
409*c217d954SCole Faust # define CL_HPP_NO_STD_VECTOR
410*c217d954SCole Faust #endif
411*c217d954SCole Faust #if !defined(CL_HPP_NO_STD_STRING) && defined(__NO_STD_STRING)
412*c217d954SCole Faust # pragma message("opencl.hpp: __NO_STD_STRING is deprecated. Define CL_HPP_NO_STD_STRING instead")
413*c217d954SCole Faust # define CL_HPP_NO_STD_STRING
414*c217d954SCole Faust #endif
415*c217d954SCole Faust #if defined(VECTOR_CLASS)
416*c217d954SCole Faust # pragma message("opencl.hpp: VECTOR_CLASS is deprecated. Alias cl::vector instead")
417*c217d954SCole Faust #endif
418*c217d954SCole Faust #if defined(STRING_CLASS)
419*c217d954SCole Faust # pragma message("opencl.hpp: STRING_CLASS is deprecated. Alias cl::string instead.")
420*c217d954SCole Faust #endif
421*c217d954SCole Faust #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS) && defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
422*c217d954SCole Faust # pragma message("opencl.hpp: __CL_USER_OVERRIDE_ERROR_STRINGS is deprecated. Define CL_HPP_USER_OVERRIDE_ERROR_STRINGS instead")
423*c217d954SCole Faust # define CL_HPP_USER_OVERRIDE_ERROR_STRINGS
424*c217d954SCole Faust #endif
425*c217d954SCole Faust
426*c217d954SCole Faust /* Warn about features that are no longer supported
427*c217d954SCole Faust */
428*c217d954SCole Faust #if defined(__USE_DEV_VECTOR)
429*c217d954SCole Faust # pragma message("opencl.hpp: __USE_DEV_VECTOR is no longer supported. Expect compilation errors")
430*c217d954SCole Faust #endif
431*c217d954SCole Faust #if defined(__USE_DEV_STRING)
432*c217d954SCole Faust # pragma message("opencl.hpp: __USE_DEV_STRING is no longer supported. Expect compilation errors")
433*c217d954SCole Faust #endif
434*c217d954SCole Faust
435*c217d954SCole Faust /* Detect which version to target */
436*c217d954SCole Faust #if !defined(CL_HPP_TARGET_OPENCL_VERSION)
437*c217d954SCole Faust # pragma message("opencl.hpp: CL_HPP_TARGET_OPENCL_VERSION is not defined. It will default to 300 (OpenCL 3.0)")
438*c217d954SCole Faust # define CL_HPP_TARGET_OPENCL_VERSION 300
439*c217d954SCole Faust #endif
440*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION != 100 && \
441*c217d954SCole Faust CL_HPP_TARGET_OPENCL_VERSION != 110 && \
442*c217d954SCole Faust CL_HPP_TARGET_OPENCL_VERSION != 120 && \
443*c217d954SCole Faust CL_HPP_TARGET_OPENCL_VERSION != 200 && \
444*c217d954SCole Faust CL_HPP_TARGET_OPENCL_VERSION != 210 && \
445*c217d954SCole Faust CL_HPP_TARGET_OPENCL_VERSION != 220 && \
446*c217d954SCole Faust CL_HPP_TARGET_OPENCL_VERSION != 300
447*c217d954SCole Faust # pragma message("opencl.hpp: CL_HPP_TARGET_OPENCL_VERSION is not a valid value (100, 110, 120, 200, 210, 220 or 300). It will be set to 300 (OpenCL 3.0).")
448*c217d954SCole Faust # undef CL_HPP_TARGET_OPENCL_VERSION
449*c217d954SCole Faust # define CL_HPP_TARGET_OPENCL_VERSION 300
450*c217d954SCole Faust #endif
451*c217d954SCole Faust
452*c217d954SCole Faust /* Forward target OpenCL version to C headers if necessary */
453*c217d954SCole Faust #if defined(CL_TARGET_OPENCL_VERSION)
454*c217d954SCole Faust /* Warn if prior definition of CL_TARGET_OPENCL_VERSION is lower than
455*c217d954SCole Faust * requested C++ bindings version */
456*c217d954SCole Faust #if CL_TARGET_OPENCL_VERSION < CL_HPP_TARGET_OPENCL_VERSION
457*c217d954SCole Faust # pragma message("CL_TARGET_OPENCL_VERSION is already defined as is lower than CL_HPP_TARGET_OPENCL_VERSION")
458*c217d954SCole Faust #endif
459*c217d954SCole Faust #else
460*c217d954SCole Faust # define CL_TARGET_OPENCL_VERSION CL_HPP_TARGET_OPENCL_VERSION
461*c217d954SCole Faust #endif
462*c217d954SCole Faust
463*c217d954SCole Faust #if !defined(CL_HPP_MINIMUM_OPENCL_VERSION)
464*c217d954SCole Faust # define CL_HPP_MINIMUM_OPENCL_VERSION 200
465*c217d954SCole Faust #endif
466*c217d954SCole Faust #if CL_HPP_MINIMUM_OPENCL_VERSION != 100 && \
467*c217d954SCole Faust CL_HPP_MINIMUM_OPENCL_VERSION != 110 && \
468*c217d954SCole Faust CL_HPP_MINIMUM_OPENCL_VERSION != 120 && \
469*c217d954SCole Faust CL_HPP_MINIMUM_OPENCL_VERSION != 200 && \
470*c217d954SCole Faust CL_HPP_MINIMUM_OPENCL_VERSION != 210 && \
471*c217d954SCole Faust CL_HPP_MINIMUM_OPENCL_VERSION != 220 && \
472*c217d954SCole Faust CL_HPP_MINIMUM_OPENCL_VERSION != 300
473*c217d954SCole Faust # pragma message("opencl.hpp: CL_HPP_MINIMUM_OPENCL_VERSION is not a valid value (100, 110, 120, 200, 210, 220 or 300). It will be set to 100")
474*c217d954SCole Faust # undef CL_HPP_MINIMUM_OPENCL_VERSION
475*c217d954SCole Faust # define CL_HPP_MINIMUM_OPENCL_VERSION 100
476*c217d954SCole Faust #endif
477*c217d954SCole Faust #if CL_HPP_MINIMUM_OPENCL_VERSION > CL_HPP_TARGET_OPENCL_VERSION
478*c217d954SCole Faust # error "CL_HPP_MINIMUM_OPENCL_VERSION must not be greater than CL_HPP_TARGET_OPENCL_VERSION"
479*c217d954SCole Faust #endif
480*c217d954SCole Faust
481*c217d954SCole Faust #if CL_HPP_MINIMUM_OPENCL_VERSION <= 100 && !defined(CL_USE_DEPRECATED_OPENCL_1_0_APIS)
482*c217d954SCole Faust # define CL_USE_DEPRECATED_OPENCL_1_0_APIS
483*c217d954SCole Faust #endif
484*c217d954SCole Faust #if CL_HPP_MINIMUM_OPENCL_VERSION <= 110 && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
485*c217d954SCole Faust # define CL_USE_DEPRECATED_OPENCL_1_1_APIS
486*c217d954SCole Faust #endif
487*c217d954SCole Faust #if CL_HPP_MINIMUM_OPENCL_VERSION <= 120 && !defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
488*c217d954SCole Faust # define CL_USE_DEPRECATED_OPENCL_1_2_APIS
489*c217d954SCole Faust #endif
490*c217d954SCole Faust #if CL_HPP_MINIMUM_OPENCL_VERSION <= 200 && !defined(CL_USE_DEPRECATED_OPENCL_2_0_APIS)
491*c217d954SCole Faust # define CL_USE_DEPRECATED_OPENCL_2_0_APIS
492*c217d954SCole Faust #endif
493*c217d954SCole Faust #if CL_HPP_MINIMUM_OPENCL_VERSION <= 210 && !defined(CL_USE_DEPRECATED_OPENCL_2_1_APIS)
494*c217d954SCole Faust # define CL_USE_DEPRECATED_OPENCL_2_1_APIS
495*c217d954SCole Faust #endif
496*c217d954SCole Faust #if CL_HPP_MINIMUM_OPENCL_VERSION <= 220 && !defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
497*c217d954SCole Faust # define CL_USE_DEPRECATED_OPENCL_2_2_APIS
498*c217d954SCole Faust #endif
499*c217d954SCole Faust
500*c217d954SCole Faust #ifdef _WIN32
501*c217d954SCole Faust
502*c217d954SCole Faust #include <malloc.h>
503*c217d954SCole Faust
504*c217d954SCole Faust #if defined(CL_HPP_USE_DX_INTEROP)
505*c217d954SCole Faust #include <CL/cl_d3d10.h>
506*c217d954SCole Faust #include <CL/cl_dx9_media_sharing.h>
507*c217d954SCole Faust #endif
508*c217d954SCole Faust #endif // _WIN32
509*c217d954SCole Faust
510*c217d954SCole Faust #if defined(_MSC_VER)
511*c217d954SCole Faust #include <intrin.h>
512*c217d954SCole Faust #endif // _MSC_VER
513*c217d954SCole Faust
514*c217d954SCole Faust // Check for a valid C++ version
515*c217d954SCole Faust
516*c217d954SCole Faust // Need to do both tests here because for some reason __cplusplus is not
517*c217d954SCole Faust // updated in visual studio
518*c217d954SCole Faust #if (!defined(_MSC_VER) && __cplusplus < 201103L) || (defined(_MSC_VER) && _MSC_VER < 1700)
519*c217d954SCole Faust #error Visual studio 2013 or another C++11-supporting compiler required
520*c217d954SCole Faust #endif
521*c217d954SCole Faust
522*c217d954SCole Faust //
523*c217d954SCole Faust #if defined(CL_HPP_USE_CL_DEVICE_FISSION) || defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)
524*c217d954SCole Faust #include <CL/cl_ext.h>
525*c217d954SCole Faust #endif
526*c217d954SCole Faust
527*c217d954SCole Faust #if defined(__APPLE__) || defined(__MACOSX)
528*c217d954SCole Faust #include <OpenCL/opencl.h>
529*c217d954SCole Faust #else
530*c217d954SCole Faust #include <CL/opencl.h>
531*c217d954SCole Faust #endif // !__APPLE__
532*c217d954SCole Faust
533*c217d954SCole Faust #if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L )
534*c217d954SCole Faust #define CL_HPP_NOEXCEPT_ noexcept
535*c217d954SCole Faust #else
536*c217d954SCole Faust #define CL_HPP_NOEXCEPT_
537*c217d954SCole Faust #endif
538*c217d954SCole Faust
539*c217d954SCole Faust #if __cplusplus >= 201703L
540*c217d954SCole Faust # define CL_HPP_DEFINE_STATIC_MEMBER_ inline
541*c217d954SCole Faust #elif defined(_MSC_VER)
542*c217d954SCole Faust # define CL_HPP_DEFINE_STATIC_MEMBER_ __declspec(selectany)
543*c217d954SCole Faust #elif defined(__MINGW32__)
544*c217d954SCole Faust # define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((selectany))
545*c217d954SCole Faust #else
546*c217d954SCole Faust # define CL_HPP_DEFINE_STATIC_MEMBER_ __attribute__((weak))
547*c217d954SCole Faust #endif // !_MSC_VER
548*c217d954SCole Faust
549*c217d954SCole Faust // Define deprecated prefixes and suffixes to ensure compilation
550*c217d954SCole Faust // in case they are not pre-defined
551*c217d954SCole Faust #if !defined(CL_API_PREFIX__VERSION_1_1_DEPRECATED)
552*c217d954SCole Faust #define CL_API_PREFIX__VERSION_1_1_DEPRECATED
553*c217d954SCole Faust #endif // #if !defined(CL_API_PREFIX__VERSION_1_1_DEPRECATED)
554*c217d954SCole Faust #if !defined(CL_API_SUFFIX__VERSION_1_1_DEPRECATED)
555*c217d954SCole Faust #define CL_API_SUFFIX__VERSION_1_1_DEPRECATED
556*c217d954SCole Faust #endif // #if !defined(CL_API_PREFIX__VERSION_1_1_DEPRECATED)
557*c217d954SCole Faust
558*c217d954SCole Faust #if !defined(CL_API_PREFIX__VERSION_1_2_DEPRECATED)
559*c217d954SCole Faust #define CL_API_PREFIX__VERSION_1_2_DEPRECATED
560*c217d954SCole Faust #endif // #if !defined(CL_API_PREFIX__VERSION_1_2_DEPRECATED)
561*c217d954SCole Faust #if !defined(CL_API_SUFFIX__VERSION_1_2_DEPRECATED)
562*c217d954SCole Faust #define CL_API_SUFFIX__VERSION_1_2_DEPRECATED
563*c217d954SCole Faust #endif // #if !defined(CL_API_PREFIX__VERSION_1_2_DEPRECATED)
564*c217d954SCole Faust
565*c217d954SCole Faust #if !defined(CL_CALLBACK)
566*c217d954SCole Faust #define CL_CALLBACK
567*c217d954SCole Faust #endif //CL_CALLBACK
568*c217d954SCole Faust
569*c217d954SCole Faust #include <utility>
570*c217d954SCole Faust #include <limits>
571*c217d954SCole Faust #include <iterator>
572*c217d954SCole Faust #include <mutex>
573*c217d954SCole Faust #include <cstring>
574*c217d954SCole Faust #include <functional>
575*c217d954SCole Faust
576*c217d954SCole Faust
577*c217d954SCole Faust // Define a size_type to represent a correctly resolved size_t
578*c217d954SCole Faust #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
579*c217d954SCole Faust namespace cl {
580*c217d954SCole Faust using size_type = ::size_t;
581*c217d954SCole Faust } // namespace cl
582*c217d954SCole Faust #else // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
583*c217d954SCole Faust namespace cl {
584*c217d954SCole Faust using size_type = size_t;
585*c217d954SCole Faust } // namespace cl
586*c217d954SCole Faust #endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
587*c217d954SCole Faust
588*c217d954SCole Faust
589*c217d954SCole Faust #if defined(CL_HPP_ENABLE_EXCEPTIONS)
590*c217d954SCole Faust #include <exception>
591*c217d954SCole Faust #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
592*c217d954SCole Faust
593*c217d954SCole Faust #if !defined(CL_HPP_NO_STD_VECTOR)
594*c217d954SCole Faust #include <vector>
595*c217d954SCole Faust namespace cl {
596*c217d954SCole Faust template < class T, class Alloc = std::allocator<T> >
597*c217d954SCole Faust using vector = std::vector<T, Alloc>;
598*c217d954SCole Faust } // namespace cl
599*c217d954SCole Faust #endif // #if !defined(CL_HPP_NO_STD_VECTOR)
600*c217d954SCole Faust
601*c217d954SCole Faust #if !defined(CL_HPP_NO_STD_STRING)
602*c217d954SCole Faust #include <string>
603*c217d954SCole Faust namespace cl {
604*c217d954SCole Faust using string = std::string;
605*c217d954SCole Faust } // namespace cl
606*c217d954SCole Faust #endif // #if !defined(CL_HPP_NO_STD_STRING)
607*c217d954SCole Faust
608*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
609*c217d954SCole Faust
610*c217d954SCole Faust #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
611*c217d954SCole Faust #include <memory>
612*c217d954SCole Faust namespace cl {
613*c217d954SCole Faust // Replace unique_ptr and allocate_pointer for internal use
614*c217d954SCole Faust // to allow user to replace them
615*c217d954SCole Faust template<class T, class D>
616*c217d954SCole Faust using pointer = std::unique_ptr<T, D>;
617*c217d954SCole Faust } // namespace cl
618*c217d954SCole Faust #endif
619*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
620*c217d954SCole Faust #if !defined(CL_HPP_NO_STD_ARRAY)
621*c217d954SCole Faust #include <array>
622*c217d954SCole Faust namespace cl {
623*c217d954SCole Faust template < class T, size_type N >
624*c217d954SCole Faust using array = std::array<T, N>;
625*c217d954SCole Faust } // namespace cl
626*c217d954SCole Faust #endif // #if !defined(CL_HPP_NO_STD_ARRAY)
627*c217d954SCole Faust
628*c217d954SCole Faust // Define size_type appropriately to allow backward-compatibility
629*c217d954SCole Faust // use of the old size_t interface class
630*c217d954SCole Faust #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
631*c217d954SCole Faust namespace cl {
632*c217d954SCole Faust namespace compatibility {
633*c217d954SCole Faust /*! \brief class used to interface between C++ and
634*c217d954SCole Faust * OpenCL C calls that require arrays of size_t values, whose
635*c217d954SCole Faust * size is known statically.
636*c217d954SCole Faust */
637*c217d954SCole Faust template <int N>
638*c217d954SCole Faust class size_t
639*c217d954SCole Faust {
640*c217d954SCole Faust private:
641*c217d954SCole Faust size_type data_[N];
642*c217d954SCole Faust
643*c217d954SCole Faust public:
644*c217d954SCole Faust //! \brief Initialize size_t to all 0s
size_t()645*c217d954SCole Faust size_t()
646*c217d954SCole Faust {
647*c217d954SCole Faust for (int i = 0; i < N; ++i) {
648*c217d954SCole Faust data_[i] = 0;
649*c217d954SCole Faust }
650*c217d954SCole Faust }
651*c217d954SCole Faust
size_t(const array<size_type,N> & rhs)652*c217d954SCole Faust size_t(const array<size_type, N> &rhs)
653*c217d954SCole Faust {
654*c217d954SCole Faust for (int i = 0; i < N; ++i) {
655*c217d954SCole Faust data_[i] = rhs[i];
656*c217d954SCole Faust }
657*c217d954SCole Faust }
658*c217d954SCole Faust
operator [](int index)659*c217d954SCole Faust size_type& operator[](int index)
660*c217d954SCole Faust {
661*c217d954SCole Faust return data_[index];
662*c217d954SCole Faust }
663*c217d954SCole Faust
operator [](int index) const664*c217d954SCole Faust const size_type& operator[](int index) const
665*c217d954SCole Faust {
666*c217d954SCole Faust return data_[index];
667*c217d954SCole Faust }
668*c217d954SCole Faust
669*c217d954SCole Faust //! \brief Conversion operator to T*.
operator size_type*()670*c217d954SCole Faust operator size_type* () { return data_; }
671*c217d954SCole Faust
672*c217d954SCole Faust //! \brief Conversion operator to const T*.
operator const size_type*() const673*c217d954SCole Faust operator const size_type* () const { return data_; }
674*c217d954SCole Faust
operator array<size_type,N>() const675*c217d954SCole Faust operator array<size_type, N>() const
676*c217d954SCole Faust {
677*c217d954SCole Faust array<size_type, N> ret;
678*c217d954SCole Faust
679*c217d954SCole Faust for (int i = 0; i < N; ++i) {
680*c217d954SCole Faust ret[i] = data_[i];
681*c217d954SCole Faust }
682*c217d954SCole Faust return ret;
683*c217d954SCole Faust }
684*c217d954SCole Faust };
685*c217d954SCole Faust } // namespace compatibility
686*c217d954SCole Faust
687*c217d954SCole Faust template<int N>
688*c217d954SCole Faust using size_t = compatibility::size_t<N>;
689*c217d954SCole Faust } // namespace cl
690*c217d954SCole Faust #endif // #if defined(CL_HPP_ENABLE_SIZE_T_COMPATIBILITY)
691*c217d954SCole Faust
692*c217d954SCole Faust // Helper alias to avoid confusing the macros
693*c217d954SCole Faust namespace cl {
694*c217d954SCole Faust namespace detail {
695*c217d954SCole Faust using size_t_array = array<size_type, 3>;
696*c217d954SCole Faust } // namespace detail
697*c217d954SCole Faust } // namespace cl
698*c217d954SCole Faust
699*c217d954SCole Faust
700*c217d954SCole Faust /*! \namespace cl
701*c217d954SCole Faust *
702*c217d954SCole Faust * \brief The OpenCL C++ bindings are defined within this namespace.
703*c217d954SCole Faust *
704*c217d954SCole Faust */
705*c217d954SCole Faust namespace cl {
706*c217d954SCole Faust class Memory;
707*c217d954SCole Faust
708*c217d954SCole Faust #define CL_HPP_INIT_CL_EXT_FCN_PTR_(name) \
709*c217d954SCole Faust if (!pfn_##name) { \
710*c217d954SCole Faust pfn_##name = (PFN_##name) \
711*c217d954SCole Faust clGetExtensionFunctionAddress(#name); \
712*c217d954SCole Faust if (!pfn_##name) { \
713*c217d954SCole Faust } \
714*c217d954SCole Faust }
715*c217d954SCole Faust
716*c217d954SCole Faust #define CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, name) \
717*c217d954SCole Faust if (!pfn_##name) { \
718*c217d954SCole Faust pfn_##name = (PFN_##name) \
719*c217d954SCole Faust clGetExtensionFunctionAddressForPlatform(platform, #name); \
720*c217d954SCole Faust if (!pfn_##name) { \
721*c217d954SCole Faust } \
722*c217d954SCole Faust }
723*c217d954SCole Faust
724*c217d954SCole Faust class Program;
725*c217d954SCole Faust class Device;
726*c217d954SCole Faust class Context;
727*c217d954SCole Faust class CommandQueue;
728*c217d954SCole Faust class DeviceCommandQueue;
729*c217d954SCole Faust class Memory;
730*c217d954SCole Faust class Buffer;
731*c217d954SCole Faust class Pipe;
732*c217d954SCole Faust
733*c217d954SCole Faust #if defined(CL_HPP_ENABLE_EXCEPTIONS)
734*c217d954SCole Faust /*! \brief Exception class
735*c217d954SCole Faust *
736*c217d954SCole Faust * This may be thrown by API functions when CL_HPP_ENABLE_EXCEPTIONS is defined.
737*c217d954SCole Faust */
738*c217d954SCole Faust class Error : public std::exception
739*c217d954SCole Faust {
740*c217d954SCole Faust private:
741*c217d954SCole Faust cl_int err_;
742*c217d954SCole Faust const char * errStr_;
743*c217d954SCole Faust public:
744*c217d954SCole Faust /*! \brief Create a new CL error exception for a given error code
745*c217d954SCole Faust * and corresponding message.
746*c217d954SCole Faust *
747*c217d954SCole Faust * \param err error code value.
748*c217d954SCole Faust *
749*c217d954SCole Faust * \param errStr a descriptive string that must remain in scope until
750*c217d954SCole Faust * handling of the exception has concluded. If set, it
751*c217d954SCole Faust * will be returned by what().
752*c217d954SCole Faust */
Error(cl_int err,const char * errStr=NULL)753*c217d954SCole Faust Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr)
754*c217d954SCole Faust {}
755*c217d954SCole Faust
~Error()756*c217d954SCole Faust ~Error() throw() {}
757*c217d954SCole Faust
758*c217d954SCole Faust /*! \brief Get error string associated with exception
759*c217d954SCole Faust *
760*c217d954SCole Faust * \return A memory pointer to the error message string.
761*c217d954SCole Faust */
what() const762*c217d954SCole Faust virtual const char * what() const throw ()
763*c217d954SCole Faust {
764*c217d954SCole Faust if (errStr_ == NULL) {
765*c217d954SCole Faust return "empty";
766*c217d954SCole Faust }
767*c217d954SCole Faust else {
768*c217d954SCole Faust return errStr_;
769*c217d954SCole Faust }
770*c217d954SCole Faust }
771*c217d954SCole Faust
772*c217d954SCole Faust /*! \brief Get error code associated with exception
773*c217d954SCole Faust *
774*c217d954SCole Faust * \return The error code.
775*c217d954SCole Faust */
err(void) const776*c217d954SCole Faust cl_int err(void) const { return err_; }
777*c217d954SCole Faust };
778*c217d954SCole Faust #define CL_HPP_ERR_STR_(x) #x
779*c217d954SCole Faust #else
780*c217d954SCole Faust #define CL_HPP_ERR_STR_(x) NULL
781*c217d954SCole Faust #endif // CL_HPP_ENABLE_EXCEPTIONS
782*c217d954SCole Faust
783*c217d954SCole Faust
784*c217d954SCole Faust namespace detail
785*c217d954SCole Faust {
786*c217d954SCole Faust #if defined(CL_HPP_ENABLE_EXCEPTIONS)
errHandler(cl_int err,const char * errStr=NULL)787*c217d954SCole Faust static inline cl_int errHandler (
788*c217d954SCole Faust cl_int err,
789*c217d954SCole Faust const char * errStr = NULL)
790*c217d954SCole Faust {
791*c217d954SCole Faust if (err != CL_SUCCESS) {
792*c217d954SCole Faust throw Error(err, errStr);
793*c217d954SCole Faust }
794*c217d954SCole Faust return err;
795*c217d954SCole Faust }
796*c217d954SCole Faust #else
797*c217d954SCole Faust static inline cl_int errHandler (cl_int err, const char * errStr = NULL)
798*c217d954SCole Faust {
799*c217d954SCole Faust (void) errStr; // suppress unused variable warning
800*c217d954SCole Faust return err;
801*c217d954SCole Faust }
802*c217d954SCole Faust #endif // CL_HPP_ENABLE_EXCEPTIONS
803*c217d954SCole Faust }
804*c217d954SCole Faust
805*c217d954SCole Faust
806*c217d954SCole Faust
807*c217d954SCole Faust //! \cond DOXYGEN_DETAIL
808*c217d954SCole Faust #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
809*c217d954SCole Faust #define __GET_DEVICE_INFO_ERR CL_HPP_ERR_STR_(clGetDeviceInfo)
810*c217d954SCole Faust #define __GET_PLATFORM_INFO_ERR CL_HPP_ERR_STR_(clGetPlatformInfo)
811*c217d954SCole Faust #define __GET_DEVICE_IDS_ERR CL_HPP_ERR_STR_(clGetDeviceIDs)
812*c217d954SCole Faust #define __GET_PLATFORM_IDS_ERR CL_HPP_ERR_STR_(clGetPlatformIDs)
813*c217d954SCole Faust #define __GET_CONTEXT_INFO_ERR CL_HPP_ERR_STR_(clGetContextInfo)
814*c217d954SCole Faust #define __GET_EVENT_INFO_ERR CL_HPP_ERR_STR_(clGetEventInfo)
815*c217d954SCole Faust #define __GET_EVENT_PROFILE_INFO_ERR CL_HPP_ERR_STR_(clGetEventProfileInfo)
816*c217d954SCole Faust #define __GET_MEM_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetMemObjectInfo)
817*c217d954SCole Faust #define __GET_IMAGE_INFO_ERR CL_HPP_ERR_STR_(clGetImageInfo)
818*c217d954SCole Faust #define __GET_SAMPLER_INFO_ERR CL_HPP_ERR_STR_(clGetSamplerInfo)
819*c217d954SCole Faust #define __GET_KERNEL_INFO_ERR CL_HPP_ERR_STR_(clGetKernelInfo)
820*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
821*c217d954SCole Faust #define __GET_KERNEL_ARG_INFO_ERR CL_HPP_ERR_STR_(clGetKernelArgInfo)
822*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
823*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
824*c217d954SCole Faust #define __GET_KERNEL_SUB_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelSubGroupInfo)
825*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
826*c217d954SCole Faust #define __GET_KERNEL_WORK_GROUP_INFO_ERR CL_HPP_ERR_STR_(clGetKernelWorkGroupInfo)
827*c217d954SCole Faust #define __GET_PROGRAM_INFO_ERR CL_HPP_ERR_STR_(clGetProgramInfo)
828*c217d954SCole Faust #define __GET_PROGRAM_BUILD_INFO_ERR CL_HPP_ERR_STR_(clGetProgramBuildInfo)
829*c217d954SCole Faust #define __GET_COMMAND_QUEUE_INFO_ERR CL_HPP_ERR_STR_(clGetCommandQueueInfo)
830*c217d954SCole Faust
831*c217d954SCole Faust #define __CREATE_CONTEXT_ERR CL_HPP_ERR_STR_(clCreateContext)
832*c217d954SCole Faust #define __CREATE_CONTEXT_FROM_TYPE_ERR CL_HPP_ERR_STR_(clCreateContextFromType)
833*c217d954SCole Faust #define __GET_SUPPORTED_IMAGE_FORMATS_ERR CL_HPP_ERR_STR_(clGetSupportedImageFormats)
834*c217d954SCole Faust
835*c217d954SCole Faust #define __CREATE_BUFFER_ERR CL_HPP_ERR_STR_(clCreateBuffer)
836*c217d954SCole Faust #define __COPY_ERR CL_HPP_ERR_STR_(cl::copy)
837*c217d954SCole Faust #define __CREATE_SUBBUFFER_ERR CL_HPP_ERR_STR_(clCreateSubBuffer)
838*c217d954SCole Faust #define __CREATE_GL_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
839*c217d954SCole Faust #define __CREATE_GL_RENDER_BUFFER_ERR CL_HPP_ERR_STR_(clCreateFromGLBuffer)
840*c217d954SCole Faust #define __GET_GL_OBJECT_INFO_ERR CL_HPP_ERR_STR_(clGetGLObjectInfo)
841*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
842*c217d954SCole Faust #define __CREATE_IMAGE_ERR CL_HPP_ERR_STR_(clCreateImage)
843*c217d954SCole Faust #define __CREATE_GL_TEXTURE_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture)
844*c217d954SCole Faust #define __IMAGE_DIMENSION_ERR CL_HPP_ERR_STR_(Incorrect image dimensions)
845*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
846*c217d954SCole Faust #define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR CL_HPP_ERR_STR_(clSetMemObjectDestructorCallback)
847*c217d954SCole Faust
848*c217d954SCole Faust #define __CREATE_USER_EVENT_ERR CL_HPP_ERR_STR_(clCreateUserEvent)
849*c217d954SCole Faust #define __SET_USER_EVENT_STATUS_ERR CL_HPP_ERR_STR_(clSetUserEventStatus)
850*c217d954SCole Faust #define __SET_EVENT_CALLBACK_ERR CL_HPP_ERR_STR_(clSetEventCallback)
851*c217d954SCole Faust #define __WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clWaitForEvents)
852*c217d954SCole Faust
853*c217d954SCole Faust #define __CREATE_KERNEL_ERR CL_HPP_ERR_STR_(clCreateKernel)
854*c217d954SCole Faust #define __SET_KERNEL_ARGS_ERR CL_HPP_ERR_STR_(clSetKernelArg)
855*c217d954SCole Faust #define __CREATE_PROGRAM_WITH_SOURCE_ERR CL_HPP_ERR_STR_(clCreateProgramWithSource)
856*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
857*c217d954SCole Faust #define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
858*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
859*c217d954SCole Faust #define __CREATE_PROGRAM_WITH_BINARY_ERR CL_HPP_ERR_STR_(clCreateProgramWithBinary)
860*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 210
861*c217d954SCole Faust #define __CREATE_PROGRAM_WITH_IL_ERR CL_HPP_ERR_STR_(clCreateProgramWithIL)
862*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
863*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
864*c217d954SCole Faust #define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR CL_HPP_ERR_STR_(clCreateProgramWithBuiltInKernels)
865*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
866*c217d954SCole Faust #define __BUILD_PROGRAM_ERR CL_HPP_ERR_STR_(clBuildProgram)
867*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
868*c217d954SCole Faust #define __COMPILE_PROGRAM_ERR CL_HPP_ERR_STR_(clCompileProgram)
869*c217d954SCole Faust #define __LINK_PROGRAM_ERR CL_HPP_ERR_STR_(clLinkProgram)
870*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
871*c217d954SCole Faust #define __CREATE_KERNELS_IN_PROGRAM_ERR CL_HPP_ERR_STR_(clCreateKernelsInProgram)
872*c217d954SCole Faust
873*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
874*c217d954SCole Faust #define __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateCommandQueueWithProperties)
875*c217d954SCole Faust #define __CREATE_SAMPLER_WITH_PROPERTIES_ERR CL_HPP_ERR_STR_(clCreateSamplerWithProperties)
876*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
877*c217d954SCole Faust #define __SET_COMMAND_QUEUE_PROPERTY_ERR CL_HPP_ERR_STR_(clSetCommandQueueProperty)
878*c217d954SCole Faust #define __ENQUEUE_READ_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueReadBuffer)
879*c217d954SCole Faust #define __ENQUEUE_READ_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueReadBufferRect)
880*c217d954SCole Faust #define __ENQUEUE_WRITE_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueWriteBuffer)
881*c217d954SCole Faust #define __ENQUEUE_WRITE_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueWriteBufferRect)
882*c217d954SCole Faust #define __ENQEUE_COPY_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyBuffer)
883*c217d954SCole Faust #define __ENQEUE_COPY_BUFFER_RECT_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferRect)
884*c217d954SCole Faust #define __ENQUEUE_FILL_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueFillBuffer)
885*c217d954SCole Faust #define __ENQUEUE_READ_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueReadImage)
886*c217d954SCole Faust #define __ENQUEUE_WRITE_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueWriteImage)
887*c217d954SCole Faust #define __ENQUEUE_COPY_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyImage)
888*c217d954SCole Faust #define __ENQUEUE_FILL_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueFillImage)
889*c217d954SCole Faust #define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueCopyImageToBuffer)
890*c217d954SCole Faust #define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueCopyBufferToImage)
891*c217d954SCole Faust #define __ENQUEUE_MAP_BUFFER_ERR CL_HPP_ERR_STR_(clEnqueueMapBuffer)
892*c217d954SCole Faust #define __ENQUEUE_MAP_IMAGE_ERR CL_HPP_ERR_STR_(clEnqueueMapImage)
893*c217d954SCole Faust #define __ENQUEUE_UNMAP_MEM_OBJECT_ERR CL_HPP_ERR_STR_(clEnqueueUnMapMemObject)
894*c217d954SCole Faust #define __ENQUEUE_NDRANGE_KERNEL_ERR CL_HPP_ERR_STR_(clEnqueueNDRangeKernel)
895*c217d954SCole Faust #define __ENQUEUE_NATIVE_KERNEL CL_HPP_ERR_STR_(clEnqueueNativeKernel)
896*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
897*c217d954SCole Faust #define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR CL_HPP_ERR_STR_(clEnqueueMigrateMemObjects)
898*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
899*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 210
900*c217d954SCole Faust #define __ENQUEUE_MIGRATE_SVM_ERR CL_HPP_ERR_STR_(clEnqueueSVMMigrateMem)
901*c217d954SCole Faust #define __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clSetDefaultDeviceCommandQueue)
902*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
903*c217d954SCole Faust
904*c217d954SCole Faust
905*c217d954SCole Faust #define __ENQUEUE_ACQUIRE_GL_ERR CL_HPP_ERR_STR_(clEnqueueAcquireGLObjects)
906*c217d954SCole Faust #define __ENQUEUE_RELEASE_GL_ERR CL_HPP_ERR_STR_(clEnqueueReleaseGLObjects)
907*c217d954SCole Faust
908*c217d954SCole Faust #define __CREATE_PIPE_ERR CL_HPP_ERR_STR_(clCreatePipe)
909*c217d954SCole Faust #define __GET_PIPE_INFO_ERR CL_HPP_ERR_STR_(clGetPipeInfo)
910*c217d954SCole Faust
911*c217d954SCole Faust
912*c217d954SCole Faust #define __RETAIN_ERR CL_HPP_ERR_STR_(Retain Object)
913*c217d954SCole Faust #define __RELEASE_ERR CL_HPP_ERR_STR_(Release Object)
914*c217d954SCole Faust #define __FLUSH_ERR CL_HPP_ERR_STR_(clFlush)
915*c217d954SCole Faust #define __FINISH_ERR CL_HPP_ERR_STR_(clFinish)
916*c217d954SCole Faust #define __VECTOR_CAPACITY_ERR CL_HPP_ERR_STR_(Vector capacity error)
917*c217d954SCole Faust
918*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 210
919*c217d954SCole Faust #define __GET_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetHostTimer)
920*c217d954SCole Faust #define __GET_DEVICE_AND_HOST_TIMER_ERR CL_HPP_ERR_STR_(clGetDeviceAndHostTimer)
921*c217d954SCole Faust #endif
922*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 220
923*c217d954SCole Faust #define __SET_PROGRAM_RELEASE_CALLBACK_ERR CL_HPP_ERR_STR_(clSetProgramReleaseCallback)
924*c217d954SCole Faust #define __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR CL_HPP_ERR_STR_(clSetProgramSpecializationConstant)
925*c217d954SCole Faust #endif
926*c217d954SCole Faust
927*c217d954SCole Faust
928*c217d954SCole Faust /**
929*c217d954SCole Faust * CL 1.2 version that uses device fission.
930*c217d954SCole Faust */
931*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
932*c217d954SCole Faust #define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevices)
933*c217d954SCole Faust #else
934*c217d954SCole Faust #define __CREATE_SUB_DEVICES_ERR CL_HPP_ERR_STR_(clCreateSubDevicesEXT)
935*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
936*c217d954SCole Faust
937*c217d954SCole Faust /**
938*c217d954SCole Faust * Deprecated APIs for 1.2
939*c217d954SCole Faust */
940*c217d954SCole Faust #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
941*c217d954SCole Faust #define __ENQUEUE_MARKER_ERR CL_HPP_ERR_STR_(clEnqueueMarker)
942*c217d954SCole Faust #define __ENQUEUE_WAIT_FOR_EVENTS_ERR CL_HPP_ERR_STR_(clEnqueueWaitForEvents)
943*c217d954SCole Faust #define __ENQUEUE_BARRIER_ERR CL_HPP_ERR_STR_(clEnqueueBarrier)
944*c217d954SCole Faust #define __UNLOAD_COMPILER_ERR CL_HPP_ERR_STR_(clUnloadCompiler)
945*c217d954SCole Faust #define __CREATE_GL_TEXTURE_2D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture2D)
946*c217d954SCole Faust #define __CREATE_GL_TEXTURE_3D_ERR CL_HPP_ERR_STR_(clCreateFromGLTexture3D)
947*c217d954SCole Faust #define __CREATE_IMAGE2D_ERR CL_HPP_ERR_STR_(clCreateImage2D)
948*c217d954SCole Faust #define __CREATE_IMAGE3D_ERR CL_HPP_ERR_STR_(clCreateImage3D)
949*c217d954SCole Faust #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
950*c217d954SCole Faust
951*c217d954SCole Faust /**
952*c217d954SCole Faust * Deprecated APIs for 2.0
953*c217d954SCole Faust */
954*c217d954SCole Faust #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
955*c217d954SCole Faust #define __CREATE_COMMAND_QUEUE_ERR CL_HPP_ERR_STR_(clCreateCommandQueue)
956*c217d954SCole Faust #define __ENQUEUE_TASK_ERR CL_HPP_ERR_STR_(clEnqueueTask)
957*c217d954SCole Faust #define __CREATE_SAMPLER_ERR CL_HPP_ERR_STR_(clCreateSampler)
958*c217d954SCole Faust #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
959*c217d954SCole Faust
960*c217d954SCole Faust /**
961*c217d954SCole Faust * CL 1.2 marker and barrier commands
962*c217d954SCole Faust */
963*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
964*c217d954SCole Faust #define __ENQUEUE_MARKER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueMarkerWithWaitList)
965*c217d954SCole Faust #define __ENQUEUE_BARRIER_WAIT_LIST_ERR CL_HPP_ERR_STR_(clEnqueueBarrierWithWaitList)
966*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
967*c217d954SCole Faust
968*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 210
969*c217d954SCole Faust #define __CLONE_KERNEL_ERR CL_HPP_ERR_STR_(clCloneKernel)
970*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
971*c217d954SCole Faust
972*c217d954SCole Faust #endif // CL_HPP_USER_OVERRIDE_ERROR_STRINGS
973*c217d954SCole Faust //! \endcond
974*c217d954SCole Faust
975*c217d954SCole Faust
976*c217d954SCole Faust namespace detail {
977*c217d954SCole Faust
978*c217d954SCole Faust // Generic getInfoHelper. The final parameter is used to guide overload
979*c217d954SCole Faust // resolution: the actual parameter passed is an int, which makes this
980*c217d954SCole Faust // a worse conversion sequence than a specialization that declares the
981*c217d954SCole Faust // parameter as an int.
982*c217d954SCole Faust template<typename Functor, typename T>
getInfoHelper(Functor f,cl_uint name,T * param,long)983*c217d954SCole Faust inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long)
984*c217d954SCole Faust {
985*c217d954SCole Faust return f(name, sizeof(T), param, NULL);
986*c217d954SCole Faust }
987*c217d954SCole Faust
988*c217d954SCole Faust // Specialized for getInfo<CL_PROGRAM_BINARIES>
989*c217d954SCole Faust // Assumes that the output vector was correctly resized on the way in
990*c217d954SCole Faust template <typename Func>
getInfoHelper(Func f,cl_uint name,vector<vector<unsigned char>> * param,int)991*c217d954SCole Faust inline cl_int getInfoHelper(Func f, cl_uint name, vector<vector<unsigned char>>* param, int)
992*c217d954SCole Faust {
993*c217d954SCole Faust if (name != CL_PROGRAM_BINARIES) {
994*c217d954SCole Faust return CL_INVALID_VALUE;
995*c217d954SCole Faust }
996*c217d954SCole Faust if (param) {
997*c217d954SCole Faust // Create array of pointers, calculate total size and pass pointer array in
998*c217d954SCole Faust size_type numBinaries = param->size();
999*c217d954SCole Faust vector<unsigned char*> binariesPointers(numBinaries);
1000*c217d954SCole Faust
1001*c217d954SCole Faust for (size_type i = 0; i < numBinaries; ++i)
1002*c217d954SCole Faust {
1003*c217d954SCole Faust binariesPointers[i] = (*param)[i].data();
1004*c217d954SCole Faust }
1005*c217d954SCole Faust
1006*c217d954SCole Faust cl_int err = f(name, numBinaries * sizeof(unsigned char*), binariesPointers.data(), NULL);
1007*c217d954SCole Faust
1008*c217d954SCole Faust if (err != CL_SUCCESS) {
1009*c217d954SCole Faust return err;
1010*c217d954SCole Faust }
1011*c217d954SCole Faust }
1012*c217d954SCole Faust
1013*c217d954SCole Faust
1014*c217d954SCole Faust return CL_SUCCESS;
1015*c217d954SCole Faust }
1016*c217d954SCole Faust
1017*c217d954SCole Faust // Specialized getInfoHelper for vector params
1018*c217d954SCole Faust template <typename Func, typename T>
getInfoHelper(Func f,cl_uint name,vector<T> * param,long)1019*c217d954SCole Faust inline cl_int getInfoHelper(Func f, cl_uint name, vector<T>* param, long)
1020*c217d954SCole Faust {
1021*c217d954SCole Faust size_type required;
1022*c217d954SCole Faust cl_int err = f(name, 0, NULL, &required);
1023*c217d954SCole Faust if (err != CL_SUCCESS) {
1024*c217d954SCole Faust return err;
1025*c217d954SCole Faust }
1026*c217d954SCole Faust const size_type elements = required / sizeof(T);
1027*c217d954SCole Faust
1028*c217d954SCole Faust // Temporary to avoid changing param on an error
1029*c217d954SCole Faust vector<T> localData(elements);
1030*c217d954SCole Faust err = f(name, required, localData.data(), NULL);
1031*c217d954SCole Faust if (err != CL_SUCCESS) {
1032*c217d954SCole Faust return err;
1033*c217d954SCole Faust }
1034*c217d954SCole Faust if (param) {
1035*c217d954SCole Faust *param = std::move(localData);
1036*c217d954SCole Faust }
1037*c217d954SCole Faust
1038*c217d954SCole Faust return CL_SUCCESS;
1039*c217d954SCole Faust }
1040*c217d954SCole Faust
1041*c217d954SCole Faust /* Specialization for reference-counted types. This depends on the
1042*c217d954SCole Faust * existence of Wrapper<T>::cl_type, and none of the other types having the
1043*c217d954SCole Faust * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1044*c217d954SCole Faust * does not work, because when using a derived type (e.g. Context) the generic
1045*c217d954SCole Faust * template will provide a better match.
1046*c217d954SCole Faust */
1047*c217d954SCole Faust template <typename Func, typename T>
getInfoHelper(Func f,cl_uint name,vector<T> * param,int,typename T::cl_type=0)1048*c217d954SCole Faust inline cl_int getInfoHelper(
1049*c217d954SCole Faust Func f, cl_uint name, vector<T>* param, int, typename T::cl_type = 0)
1050*c217d954SCole Faust {
1051*c217d954SCole Faust size_type required;
1052*c217d954SCole Faust cl_int err = f(name, 0, NULL, &required);
1053*c217d954SCole Faust if (err != CL_SUCCESS) {
1054*c217d954SCole Faust return err;
1055*c217d954SCole Faust }
1056*c217d954SCole Faust
1057*c217d954SCole Faust const size_type elements = required / sizeof(typename T::cl_type);
1058*c217d954SCole Faust
1059*c217d954SCole Faust vector<typename T::cl_type> value(elements);
1060*c217d954SCole Faust err = f(name, required, value.data(), NULL);
1061*c217d954SCole Faust if (err != CL_SUCCESS) {
1062*c217d954SCole Faust return err;
1063*c217d954SCole Faust }
1064*c217d954SCole Faust
1065*c217d954SCole Faust if (param) {
1066*c217d954SCole Faust // Assign to convert CL type to T for each element
1067*c217d954SCole Faust param->resize(elements);
1068*c217d954SCole Faust
1069*c217d954SCole Faust // Assign to param, constructing with retain behaviour
1070*c217d954SCole Faust // to correctly capture each underlying CL object
1071*c217d954SCole Faust for (size_type i = 0; i < elements; i++) {
1072*c217d954SCole Faust (*param)[i] = T(value[i], true);
1073*c217d954SCole Faust }
1074*c217d954SCole Faust }
1075*c217d954SCole Faust return CL_SUCCESS;
1076*c217d954SCole Faust }
1077*c217d954SCole Faust
1078*c217d954SCole Faust // Specialized GetInfoHelper for string params
1079*c217d954SCole Faust template <typename Func>
getInfoHelper(Func f,cl_uint name,string * param,long)1080*c217d954SCole Faust inline cl_int getInfoHelper(Func f, cl_uint name, string* param, long)
1081*c217d954SCole Faust {
1082*c217d954SCole Faust size_type required;
1083*c217d954SCole Faust cl_int err = f(name, 0, NULL, &required);
1084*c217d954SCole Faust if (err != CL_SUCCESS) {
1085*c217d954SCole Faust return err;
1086*c217d954SCole Faust }
1087*c217d954SCole Faust
1088*c217d954SCole Faust // std::string has a constant data member
1089*c217d954SCole Faust // a char vector does not
1090*c217d954SCole Faust if (required > 0) {
1091*c217d954SCole Faust vector<char> value(required);
1092*c217d954SCole Faust err = f(name, required, value.data(), NULL);
1093*c217d954SCole Faust if (err != CL_SUCCESS) {
1094*c217d954SCole Faust return err;
1095*c217d954SCole Faust }
1096*c217d954SCole Faust if (param) {
1097*c217d954SCole Faust param->assign(begin(value), prev(end(value)));
1098*c217d954SCole Faust }
1099*c217d954SCole Faust }
1100*c217d954SCole Faust else if (param) {
1101*c217d954SCole Faust param->assign("");
1102*c217d954SCole Faust }
1103*c217d954SCole Faust return CL_SUCCESS;
1104*c217d954SCole Faust }
1105*c217d954SCole Faust
1106*c217d954SCole Faust // Specialized GetInfoHelper for clsize_t params
1107*c217d954SCole Faust template <typename Func, size_type N>
getInfoHelper(Func f,cl_uint name,array<size_type,N> * param,long)1108*c217d954SCole Faust inline cl_int getInfoHelper(Func f, cl_uint name, array<size_type, N>* param, long)
1109*c217d954SCole Faust {
1110*c217d954SCole Faust size_type required;
1111*c217d954SCole Faust cl_int err = f(name, 0, NULL, &required);
1112*c217d954SCole Faust if (err != CL_SUCCESS) {
1113*c217d954SCole Faust return err;
1114*c217d954SCole Faust }
1115*c217d954SCole Faust
1116*c217d954SCole Faust size_type elements = required / sizeof(size_type);
1117*c217d954SCole Faust vector<size_type> value(elements, 0);
1118*c217d954SCole Faust
1119*c217d954SCole Faust err = f(name, required, value.data(), NULL);
1120*c217d954SCole Faust if (err != CL_SUCCESS) {
1121*c217d954SCole Faust return err;
1122*c217d954SCole Faust }
1123*c217d954SCole Faust
1124*c217d954SCole Faust // Bound the copy with N to prevent overruns
1125*c217d954SCole Faust // if passed N > than the amount copied
1126*c217d954SCole Faust if (elements > N) {
1127*c217d954SCole Faust elements = N;
1128*c217d954SCole Faust }
1129*c217d954SCole Faust for (size_type i = 0; i < elements; ++i) {
1130*c217d954SCole Faust (*param)[i] = value[i];
1131*c217d954SCole Faust }
1132*c217d954SCole Faust
1133*c217d954SCole Faust return CL_SUCCESS;
1134*c217d954SCole Faust }
1135*c217d954SCole Faust
1136*c217d954SCole Faust template<typename T> struct ReferenceHandler;
1137*c217d954SCole Faust
1138*c217d954SCole Faust /* Specialization for reference-counted types. This depends on the
1139*c217d954SCole Faust * existence of Wrapper<T>::cl_type, and none of the other types having the
1140*c217d954SCole Faust * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
1141*c217d954SCole Faust * does not work, because when using a derived type (e.g. Context) the generic
1142*c217d954SCole Faust * template will provide a better match.
1143*c217d954SCole Faust */
1144*c217d954SCole Faust template<typename Func, typename T>
getInfoHelper(Func f,cl_uint name,T * param,int,typename T::cl_type=0)1145*c217d954SCole Faust inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0)
1146*c217d954SCole Faust {
1147*c217d954SCole Faust typename T::cl_type value;
1148*c217d954SCole Faust cl_int err = f(name, sizeof(value), &value, NULL);
1149*c217d954SCole Faust if (err != CL_SUCCESS) {
1150*c217d954SCole Faust return err;
1151*c217d954SCole Faust }
1152*c217d954SCole Faust *param = value;
1153*c217d954SCole Faust if (value != NULL)
1154*c217d954SCole Faust {
1155*c217d954SCole Faust err = param->retain();
1156*c217d954SCole Faust if (err != CL_SUCCESS) {
1157*c217d954SCole Faust return err;
1158*c217d954SCole Faust }
1159*c217d954SCole Faust }
1160*c217d954SCole Faust return CL_SUCCESS;
1161*c217d954SCole Faust }
1162*c217d954SCole Faust
1163*c217d954SCole Faust #define CL_HPP_PARAM_NAME_INFO_1_0_(F) \
1164*c217d954SCole Faust F(cl_platform_info, CL_PLATFORM_PROFILE, string) \
1165*c217d954SCole Faust F(cl_platform_info, CL_PLATFORM_VERSION, string) \
1166*c217d954SCole Faust F(cl_platform_info, CL_PLATFORM_NAME, string) \
1167*c217d954SCole Faust F(cl_platform_info, CL_PLATFORM_VENDOR, string) \
1168*c217d954SCole Faust F(cl_platform_info, CL_PLATFORM_EXTENSIONS, string) \
1169*c217d954SCole Faust \
1170*c217d954SCole Faust F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
1171*c217d954SCole Faust F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
1172*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
1173*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
1174*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, size_type) \
1175*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, cl::vector<size_type>) \
1176*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
1177*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
1178*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
1179*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
1180*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
1181*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
1182*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
1183*c217d954SCole Faust F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \
1184*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
1185*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
1186*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
1187*c217d954SCole Faust F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, size_type) \
1188*c217d954SCole Faust F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, size_type) \
1189*c217d954SCole Faust F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, size_type) \
1190*c217d954SCole Faust F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, size_type) \
1191*c217d954SCole Faust F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, size_type) \
1192*c217d954SCole Faust F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \
1193*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, size_type) \
1194*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
1195*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
1196*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
1197*c217d954SCole Faust F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
1198*c217d954SCole Faust F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
1199*c217d954SCole Faust F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
1200*c217d954SCole Faust F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
1201*c217d954SCole Faust F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
1202*c217d954SCole Faust F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
1203*c217d954SCole Faust F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
1204*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
1205*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
1206*c217d954SCole Faust F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
1207*c217d954SCole Faust F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
1208*c217d954SCole Faust F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
1209*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, size_type) \
1210*c217d954SCole Faust F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
1211*c217d954SCole Faust F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
1212*c217d954SCole Faust F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
1213*c217d954SCole Faust F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
1214*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
1215*c217d954SCole Faust F(cl_device_info, CL_DEVICE_NAME, string) \
1216*c217d954SCole Faust F(cl_device_info, CL_DEVICE_VENDOR, string) \
1217*c217d954SCole Faust F(cl_device_info, CL_DRIVER_VERSION, string) \
1218*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PROFILE, string) \
1219*c217d954SCole Faust F(cl_device_info, CL_DEVICE_VERSION, string) \
1220*c217d954SCole Faust F(cl_device_info, CL_DEVICE_EXTENSIONS, string) \
1221*c217d954SCole Faust \
1222*c217d954SCole Faust F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
1223*c217d954SCole Faust F(cl_context_info, CL_CONTEXT_DEVICES, cl::vector<Device>) \
1224*c217d954SCole Faust F(cl_context_info, CL_CONTEXT_PROPERTIES, cl::vector<cl_context_properties>) \
1225*c217d954SCole Faust \
1226*c217d954SCole Faust F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
1227*c217d954SCole Faust F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
1228*c217d954SCole Faust F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
1229*c217d954SCole Faust F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \
1230*c217d954SCole Faust \
1231*c217d954SCole Faust F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
1232*c217d954SCole Faust F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
1233*c217d954SCole Faust F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
1234*c217d954SCole Faust F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
1235*c217d954SCole Faust \
1236*c217d954SCole Faust F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
1237*c217d954SCole Faust F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
1238*c217d954SCole Faust F(cl_mem_info, CL_MEM_SIZE, size_type) \
1239*c217d954SCole Faust F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
1240*c217d954SCole Faust F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
1241*c217d954SCole Faust F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
1242*c217d954SCole Faust F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
1243*c217d954SCole Faust \
1244*c217d954SCole Faust F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
1245*c217d954SCole Faust F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, size_type) \
1246*c217d954SCole Faust F(cl_image_info, CL_IMAGE_ROW_PITCH, size_type) \
1247*c217d954SCole Faust F(cl_image_info, CL_IMAGE_SLICE_PITCH, size_type) \
1248*c217d954SCole Faust F(cl_image_info, CL_IMAGE_WIDTH, size_type) \
1249*c217d954SCole Faust F(cl_image_info, CL_IMAGE_HEIGHT, size_type) \
1250*c217d954SCole Faust F(cl_image_info, CL_IMAGE_DEPTH, size_type) \
1251*c217d954SCole Faust \
1252*c217d954SCole Faust F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
1253*c217d954SCole Faust F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
1254*c217d954SCole Faust F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \
1255*c217d954SCole Faust F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \
1256*c217d954SCole Faust F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \
1257*c217d954SCole Faust \
1258*c217d954SCole Faust F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
1259*c217d954SCole Faust F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
1260*c217d954SCole Faust F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
1261*c217d954SCole Faust F(cl_program_info, CL_PROGRAM_DEVICES, cl::vector<Device>) \
1262*c217d954SCole Faust F(cl_program_info, CL_PROGRAM_SOURCE, string) \
1263*c217d954SCole Faust F(cl_program_info, CL_PROGRAM_BINARY_SIZES, cl::vector<size_type>) \
1264*c217d954SCole Faust F(cl_program_info, CL_PROGRAM_BINARIES, cl::vector<cl::vector<unsigned char>>) \
1265*c217d954SCole Faust \
1266*c217d954SCole Faust F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
1267*c217d954SCole Faust F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, string) \
1268*c217d954SCole Faust F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, string) \
1269*c217d954SCole Faust \
1270*c217d954SCole Faust F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, string) \
1271*c217d954SCole Faust F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
1272*c217d954SCole Faust F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
1273*c217d954SCole Faust F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
1274*c217d954SCole Faust F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
1275*c217d954SCole Faust \
1276*c217d954SCole Faust F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, size_type) \
1277*c217d954SCole Faust F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::detail::size_t_array) \
1278*c217d954SCole Faust F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
1279*c217d954SCole Faust \
1280*c217d954SCole Faust F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
1281*c217d954SCole Faust F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
1282*c217d954SCole Faust F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
1283*c217d954SCole Faust F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
1284*c217d954SCole Faust
1285*c217d954SCole Faust
1286*c217d954SCole Faust #define CL_HPP_PARAM_NAME_INFO_1_1_(F) \
1287*c217d954SCole Faust F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
1288*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
1289*c217d954SCole Faust F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
1290*c217d954SCole Faust F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
1291*c217d954SCole Faust F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
1292*c217d954SCole Faust F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
1293*c217d954SCole Faust F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
1294*c217d954SCole Faust F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
1295*c217d954SCole Faust F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
1296*c217d954SCole Faust F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, string) \
1297*c217d954SCole Faust \
1298*c217d954SCole Faust F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
1299*c217d954SCole Faust F(cl_mem_info, CL_MEM_OFFSET, size_type) \
1300*c217d954SCole Faust \
1301*c217d954SCole Faust F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1302*c217d954SCole Faust F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
1303*c217d954SCole Faust \
1304*c217d954SCole Faust F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
1305*c217d954SCole Faust
1306*c217d954SCole Faust #define CL_HPP_PARAM_NAME_INFO_1_2_(F) \
1307*c217d954SCole Faust F(cl_program_info, CL_PROGRAM_NUM_KERNELS, size_type) \
1308*c217d954SCole Faust F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, string) \
1309*c217d954SCole Faust \
1310*c217d954SCole Faust F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \
1311*c217d954SCole Faust \
1312*c217d954SCole Faust F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, string) \
1313*c217d954SCole Faust \
1314*c217d954SCole Faust F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \
1315*c217d954SCole Faust F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \
1316*c217d954SCole Faust F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, string) \
1317*c217d954SCole Faust F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, string) \
1318*c217d954SCole Faust F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \
1319*c217d954SCole Faust \
1320*c217d954SCole Faust F(cl_kernel_work_group_info, CL_KERNEL_GLOBAL_WORK_SIZE, cl::detail::size_t_array) \
1321*c217d954SCole Faust \
1322*c217d954SCole Faust F(cl_device_info, CL_DEVICE_LINKER_AVAILABLE, cl_bool) \
1323*c217d954SCole Faust F(cl_device_info, CL_DEVICE_IMAGE_MAX_BUFFER_SIZE, size_type) \
1324*c217d954SCole Faust F(cl_device_info, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, size_type) \
1325*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl::Device) \
1326*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PARTITION_MAX_SUB_DEVICES, cl_uint) \
1327*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, cl::vector<cl_device_partition_property>) \
1328*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PARTITION_TYPE, cl::vector<cl_device_partition_property>) \
1329*c217d954SCole Faust F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \
1330*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, cl_bool) \
1331*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \
1332*c217d954SCole Faust F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, string) \
1333*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PRINTF_BUFFER_SIZE, size_type) \
1334*c217d954SCole Faust \
1335*c217d954SCole Faust F(cl_image_info, CL_IMAGE_ARRAY_SIZE, size_type) \
1336*c217d954SCole Faust F(cl_image_info, CL_IMAGE_NUM_MIP_LEVELS, cl_uint) \
1337*c217d954SCole Faust F(cl_image_info, CL_IMAGE_NUM_SAMPLES, cl_uint)
1338*c217d954SCole Faust
1339*c217d954SCole Faust #define CL_HPP_PARAM_NAME_INFO_2_0_(F) \
1340*c217d954SCole Faust F(cl_device_info, CL_DEVICE_QUEUE_ON_HOST_PROPERTIES, cl_command_queue_properties) \
1341*c217d954SCole Faust F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES, cl_command_queue_properties) \
1342*c217d954SCole Faust F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, cl_uint) \
1343*c217d954SCole Faust F(cl_device_info, CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, cl_uint) \
1344*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_QUEUES, cl_uint) \
1345*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MAX_ON_DEVICE_EVENTS, cl_uint) \
1346*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MAX_PIPE_ARGS, cl_uint) \
1347*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS, cl_uint) \
1348*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PIPE_MAX_PACKET_SIZE, cl_uint) \
1349*c217d954SCole Faust F(cl_device_info, CL_DEVICE_SVM_CAPABILITIES, cl_device_svm_capabilities) \
1350*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT, cl_uint) \
1351*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT, cl_uint) \
1352*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT, cl_uint) \
1353*c217d954SCole Faust F(cl_device_info, CL_DEVICE_IMAGE_PITCH_ALIGNMENT, cl_uint) \
1354*c217d954SCole Faust F(cl_device_info, CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT, cl_uint) \
1355*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS, cl_uint ) \
1356*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE, size_type ) \
1357*c217d954SCole Faust F(cl_device_info, CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE, size_type ) \
1358*c217d954SCole Faust F(cl_profiling_info, CL_PROFILING_COMMAND_COMPLETE, cl_ulong) \
1359*c217d954SCole Faust F(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM, cl_bool) \
1360*c217d954SCole Faust F(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_SVM_PTRS, void**) \
1361*c217d954SCole Faust F(cl_command_queue_info, CL_QUEUE_SIZE, cl_uint) \
1362*c217d954SCole Faust F(cl_mem_info, CL_MEM_USES_SVM_POINTER, cl_bool) \
1363*c217d954SCole Faust F(cl_program_build_info, CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, size_type) \
1364*c217d954SCole Faust F(cl_pipe_info, CL_PIPE_PACKET_SIZE, cl_uint) \
1365*c217d954SCole Faust F(cl_pipe_info, CL_PIPE_MAX_PACKETS, cl_uint)
1366*c217d954SCole Faust
1367*c217d954SCole Faust #define CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(F) \
1368*c217d954SCole Faust F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR, size_type) \
1369*c217d954SCole Faust F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR, size_type)
1370*c217d954SCole Faust
1371*c217d954SCole Faust #define CL_HPP_PARAM_NAME_INFO_IL_KHR_(F) \
1372*c217d954SCole Faust F(cl_device_info, CL_DEVICE_IL_VERSION_KHR, string) \
1373*c217d954SCole Faust F(cl_program_info, CL_PROGRAM_IL_KHR, cl::vector<unsigned char>)
1374*c217d954SCole Faust
1375*c217d954SCole Faust #define CL_HPP_PARAM_NAME_INFO_2_1_(F) \
1376*c217d954SCole Faust F(cl_platform_info, CL_PLATFORM_HOST_TIMER_RESOLUTION, cl_ulong) \
1377*c217d954SCole Faust F(cl_program_info, CL_PROGRAM_IL, cl::vector<unsigned char>) \
1378*c217d954SCole Faust F(cl_device_info, CL_DEVICE_MAX_NUM_SUB_GROUPS, cl_uint) \
1379*c217d954SCole Faust F(cl_device_info, CL_DEVICE_IL_VERSION, string) \
1380*c217d954SCole Faust F(cl_device_info, CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS, cl_bool) \
1381*c217d954SCole Faust F(cl_command_queue_info, CL_QUEUE_DEVICE_DEFAULT, cl::DeviceCommandQueue) \
1382*c217d954SCole Faust F(cl_kernel_sub_group_info, CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE, size_type) \
1383*c217d954SCole Faust F(cl_kernel_sub_group_info, CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE, size_type) \
1384*c217d954SCole Faust F(cl_kernel_sub_group_info, CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT, cl::detail::size_t_array) \
1385*c217d954SCole Faust F(cl_kernel_sub_group_info, CL_KERNEL_MAX_NUM_SUB_GROUPS, size_type) \
1386*c217d954SCole Faust F(cl_kernel_sub_group_info, CL_KERNEL_COMPILE_NUM_SUB_GROUPS, size_type)
1387*c217d954SCole Faust
1388*c217d954SCole Faust #define CL_HPP_PARAM_NAME_INFO_2_2_(F) \
1389*c217d954SCole Faust F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_CTORS_PRESENT, cl_bool) \
1390*c217d954SCole Faust F(cl_program_info, CL_PROGRAM_SCOPE_GLOBAL_DTORS_PRESENT, cl_bool)
1391*c217d954SCole Faust
1392*c217d954SCole Faust #define CL_HPP_PARAM_NAME_DEVICE_FISSION_(F) \
1393*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
1394*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, cl::vector<cl_device_partition_property_ext>) \
1395*c217d954SCole Faust F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, cl::vector<cl_device_partition_property_ext>) \
1396*c217d954SCole Faust F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
1397*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, cl::vector<cl_device_partition_property_ext>)
1398*c217d954SCole Faust
1399*c217d954SCole Faust #define CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_CL3_SHARED_(F) \
1400*c217d954SCole Faust F(cl_platform_info, CL_PLATFORM_NUMERIC_VERSION_KHR, cl_version_khr) \
1401*c217d954SCole Faust F(cl_platform_info, CL_PLATFORM_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1402*c217d954SCole Faust \
1403*c217d954SCole Faust F(cl_device_info, CL_DEVICE_NUMERIC_VERSION_KHR, cl_version_khr) \
1404*c217d954SCole Faust F(cl_device_info, CL_DEVICE_EXTENSIONS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1405*c217d954SCole Faust F(cl_device_info, CL_DEVICE_ILS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>) \
1406*c217d954SCole Faust F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION_KHR, cl::vector<cl_name_version_khr>)
1407*c217d954SCole Faust
1408*c217d954SCole Faust #define CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_KHRONLY_(F) \
1409*c217d954SCole Faust F(cl_device_info, CL_DEVICE_OPENCL_C_NUMERIC_VERSION_KHR, cl_version_khr)
1410*c217d954SCole Faust
1411*c217d954SCole Faust #define CL_HPP_PARAM_NAME_INFO_3_0_(F) \
1412*c217d954SCole Faust F(cl_platform_info, CL_PLATFORM_NUMERIC_VERSION, cl_version) \
1413*c217d954SCole Faust F(cl_platform_info, CL_PLATFORM_EXTENSIONS_WITH_VERSION, cl::vector<cl_name_version>) \
1414*c217d954SCole Faust \
1415*c217d954SCole Faust F(cl_device_info, CL_DEVICE_NUMERIC_VERSION, cl_version) \
1416*c217d954SCole Faust F(cl_device_info, CL_DEVICE_EXTENSIONS_WITH_VERSION, cl::vector<cl_name_version>) \
1417*c217d954SCole Faust F(cl_device_info, CL_DEVICE_ILS_WITH_VERSION, cl::vector<cl_name_version>) \
1418*c217d954SCole Faust F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION, cl::vector<cl_name_version>) \
1419*c217d954SCole Faust F(cl_device_info, CL_DEVICE_ATOMIC_MEMORY_CAPABILITIES, cl_device_atomic_capabilities) \
1420*c217d954SCole Faust F(cl_device_info, CL_DEVICE_ATOMIC_FENCE_CAPABILITIES, cl_device_atomic_capabilities) \
1421*c217d954SCole Faust F(cl_device_info, CL_DEVICE_NON_UNIFORM_WORK_GROUP_SUPPORT, cl_bool) \
1422*c217d954SCole Faust F(cl_device_info, CL_DEVICE_OPENCL_C_ALL_VERSIONS, cl::vector<cl_name_version>) \
1423*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, size_type) \
1424*c217d954SCole Faust F(cl_device_info, CL_DEVICE_WORK_GROUP_COLLECTIVE_FUNCTIONS_SUPPORT, cl_bool) \
1425*c217d954SCole Faust F(cl_device_info, CL_DEVICE_GENERIC_ADDRESS_SPACE_SUPPORT, cl_bool) \
1426*c217d954SCole Faust F(cl_device_info, CL_DEVICE_OPENCL_C_FEATURES, cl::vector<cl_name_version>) \
1427*c217d954SCole Faust F(cl_device_info, CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES, cl_device_device_enqueue_capabilities) \
1428*c217d954SCole Faust F(cl_device_info, CL_DEVICE_PIPE_SUPPORT, cl_bool) \
1429*c217d954SCole Faust F(cl_device_info, CL_DEVICE_LATEST_CONFORMANCE_VERSION_PASSED, string) \
1430*c217d954SCole Faust \
1431*c217d954SCole Faust F(cl_command_queue_info, CL_QUEUE_PROPERTIES_ARRAY, cl::vector<cl_queue_properties>) \
1432*c217d954SCole Faust F(cl_mem_info, CL_MEM_PROPERTIES, cl::vector<cl_mem_properties>) \
1433*c217d954SCole Faust F(cl_pipe_info, CL_PIPE_PROPERTIES, cl::vector<cl_pipe_properties>) \
1434*c217d954SCole Faust F(cl_sampler_info, CL_SAMPLER_PROPERTIES, cl::vector<cl_sampler_properties>)
1435*c217d954SCole Faust
1436*c217d954SCole Faust template <typename enum_type, cl_int Name>
1437*c217d954SCole Faust struct param_traits {};
1438*c217d954SCole Faust
1439*c217d954SCole Faust #define CL_HPP_DECLARE_PARAM_TRAITS_(token, param_name, T) \
1440*c217d954SCole Faust struct token; \
1441*c217d954SCole Faust template<> \
1442*c217d954SCole Faust struct param_traits<detail:: token,param_name> \
1443*c217d954SCole Faust { \
1444*c217d954SCole Faust enum { value = param_name }; \
1445*c217d954SCole Faust typedef T param_type; \
1446*c217d954SCole Faust };
1447*c217d954SCole Faust
1448*c217d954SCole Faust CL_HPP_PARAM_NAME_INFO_1_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1449*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 110
1450*c217d954SCole Faust CL_HPP_PARAM_NAME_INFO_1_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1451*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
1452*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1453*c217d954SCole Faust CL_HPP_PARAM_NAME_INFO_1_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1454*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1455*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
1456*c217d954SCole Faust CL_HPP_PARAM_NAME_INFO_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1457*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
1458*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 210
1459*c217d954SCole Faust CL_HPP_PARAM_NAME_INFO_2_1_(CL_HPP_DECLARE_PARAM_TRAITS_)
1460*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 210
1461*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 220
1462*c217d954SCole Faust CL_HPP_PARAM_NAME_INFO_2_2_(CL_HPP_DECLARE_PARAM_TRAITS_)
1463*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
1464*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 300
1465*c217d954SCole Faust CL_HPP_PARAM_NAME_INFO_3_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1466*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 300
1467*c217d954SCole Faust
1468*c217d954SCole Faust #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1469*c217d954SCole Faust CL_HPP_PARAM_NAME_INFO_SUBGROUP_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1470*c217d954SCole Faust #endif // #if defined(CL_HPP_USE_CL_SUB_GROUPS_KHR) && CL_HPP_TARGET_OPENCL_VERSION < 210
1471*c217d954SCole Faust
1472*c217d954SCole Faust #if defined(CL_HPP_USE_IL_KHR)
1473*c217d954SCole Faust CL_HPP_PARAM_NAME_INFO_IL_KHR_(CL_HPP_DECLARE_PARAM_TRAITS_)
1474*c217d954SCole Faust #endif // #if defined(CL_HPP_USE_IL_KHR)
1475*c217d954SCole Faust
1476*c217d954SCole Faust
1477*c217d954SCole Faust // Flags deprecated in OpenCL 2.0
1478*c217d954SCole Faust #define CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(F) \
1479*c217d954SCole Faust F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties)
1480*c217d954SCole Faust
1481*c217d954SCole Faust #define CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(F) \
1482*c217d954SCole Faust F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool)
1483*c217d954SCole Faust
1484*c217d954SCole Faust #define CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(F) \
1485*c217d954SCole Faust F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer)
1486*c217d954SCole Faust
1487*c217d954SCole Faust // Include deprecated query flags based on versions
1488*c217d954SCole Faust // Only include deprecated 1.0 flags if 2.0 not active as there is an enum clash
1489*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION > 100 && CL_HPP_MINIMUM_OPENCL_VERSION < 200 && CL_HPP_TARGET_OPENCL_VERSION < 200
1490*c217d954SCole Faust CL_HPP_PARAM_NAME_INFO_1_0_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1491*c217d954SCole Faust #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 110
1492*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION > 110 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1493*c217d954SCole Faust CL_HPP_PARAM_NAME_INFO_1_1_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1494*c217d954SCole Faust #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1495*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION > 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
1496*c217d954SCole Faust CL_HPP_PARAM_NAME_INFO_1_2_DEPRECATED_IN_2_0_(CL_HPP_DECLARE_PARAM_TRAITS_)
1497*c217d954SCole Faust #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
1498*c217d954SCole Faust
1499*c217d954SCole Faust #if defined(CL_HPP_USE_CL_DEVICE_FISSION)
1500*c217d954SCole Faust CL_HPP_PARAM_NAME_DEVICE_FISSION_(CL_HPP_DECLARE_PARAM_TRAITS_);
1501*c217d954SCole Faust #endif // CL_HPP_USE_CL_DEVICE_FISSION
1502*c217d954SCole Faust
1503*c217d954SCole Faust #if defined(cl_khr_extended_versioning)
1504*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION < 300
1505*c217d954SCole Faust CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_CL3_SHARED_(CL_HPP_DECLARE_PARAM_TRAITS_)
1506*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION < 300
1507*c217d954SCole Faust CL_HPP_PARAM_NAME_CL_KHR_EXTENDED_VERSIONING_KHRONLY_(CL_HPP_DECLARE_PARAM_TRAITS_)
1508*c217d954SCole Faust #endif // cl_khr_extended_versioning
1509*c217d954SCole Faust
1510*c217d954SCole Faust #if defined(cl_khr_device_uuid)
1511*c217d954SCole Faust using uuid_array = array<cl_uchar, CL_UUID_SIZE_KHR>;
1512*c217d954SCole Faust using luid_array = array<cl_uchar, CL_LUID_SIZE_KHR>;
CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info,CL_DEVICE_UUID_KHR,uuid_array)1513*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_UUID_KHR, uuid_array)
1514*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DRIVER_UUID_KHR, uuid_array)
1515*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LUID_VALID_KHR, cl_bool)
1516*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LUID_KHR, luid_array)
1517*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_NODE_MASK_KHR, cl_uint)
1518*c217d954SCole Faust #endif
1519*c217d954SCole Faust
1520*c217d954SCole Faust #if defined(cl_khr_pci_bus_info)
1521*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PCI_BUS_INFO_KHR, cl_device_pci_bus_info_khr)
1522*c217d954SCole Faust #endif
1523*c217d954SCole Faust
1524*c217d954SCole Faust #if defined(cl_khr_integer_dot_product)
1525*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGER_DOT_PRODUCT_CAPABILITIES_KHR, cl_device_integer_dot_product_capabilities_khr)
1526*c217d954SCole Faust #endif
1527*c217d954SCole Faust
1528*c217d954SCole Faust #ifdef CL_PLATFORM_ICD_SUFFIX_KHR
1529*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, string)
1530*c217d954SCole Faust #endif
1531*c217d954SCole Faust
1532*c217d954SCole Faust #ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
1533*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong)
1534*c217d954SCole Faust #endif
1535*c217d954SCole Faust #ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
1536*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, vector<size_type>)
1537*c217d954SCole Faust #endif
1538*c217d954SCole Faust #ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
1539*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint)
1540*c217d954SCole Faust #endif
1541*c217d954SCole Faust #ifdef CL_DEVICE_SIMD_WIDTH_AMD
1542*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint)
1543*c217d954SCole Faust #endif
1544*c217d954SCole Faust #ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD
1545*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint)
1546*c217d954SCole Faust #endif
1547*c217d954SCole Faust #ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD
1548*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint)
1549*c217d954SCole Faust #endif
1550*c217d954SCole Faust #ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
1551*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint)
1552*c217d954SCole Faust #endif
1553*c217d954SCole Faust #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
1554*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint)
1555*c217d954SCole Faust #endif
1556*c217d954SCole Faust #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
1557*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint)
1558*c217d954SCole Faust #endif
1559*c217d954SCole Faust #ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
1560*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint)
1561*c217d954SCole Faust #endif
1562*c217d954SCole Faust #ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
1563*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint)
1564*c217d954SCole Faust #endif
1565*c217d954SCole Faust
1566*c217d954SCole Faust #ifdef CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM
1567*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM, cl_ulong)
1568*c217d954SCole Faust #endif
1569*c217d954SCole Faust #ifdef CL_DEVICE_JOB_SLOTS_ARM
1570*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_JOB_SLOTS_ARM, cl_uint)
1571*c217d954SCole Faust #endif
1572*c217d954SCole Faust #ifdef CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM
1573*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_SCHEDULING_CONTROLS_CAPABILITIES_ARM, cl_bitfield)
1574*c217d954SCole Faust #endif
1575*c217d954SCole Faust #ifdef CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_ARM
1576*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_ARM, cl_uint)
1577*c217d954SCole Faust #endif
1578*c217d954SCole Faust #ifdef CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM
1579*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_kernel_exec_info, CL_KERNEL_EXEC_INFO_WORKGROUP_BATCH_SIZE_MODIFIER_ARM, cl_int)
1580*c217d954SCole Faust #endif
1581*c217d954SCole Faust
1582*c217d954SCole Faust #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
1583*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint)
1584*c217d954SCole Faust #endif
1585*c217d954SCole Faust #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV
1586*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint)
1587*c217d954SCole Faust #endif
1588*c217d954SCole Faust #ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV
1589*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint)
1590*c217d954SCole Faust #endif
1591*c217d954SCole Faust #ifdef CL_DEVICE_WARP_SIZE_NV
1592*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint)
1593*c217d954SCole Faust #endif
1594*c217d954SCole Faust #ifdef CL_DEVICE_GPU_OVERLAP_NV
1595*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool)
1596*c217d954SCole Faust #endif
1597*c217d954SCole Faust #ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV
1598*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool)
1599*c217d954SCole Faust #endif
1600*c217d954SCole Faust #ifdef CL_DEVICE_INTEGRATED_MEMORY_NV
1601*c217d954SCole Faust CL_HPP_DECLARE_PARAM_TRAITS_(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool)
1602*c217d954SCole Faust #endif
1603*c217d954SCole Faust
1604*c217d954SCole Faust // Convenience functions
1605*c217d954SCole Faust
1606*c217d954SCole Faust template <typename Func, typename T>
1607*c217d954SCole Faust inline cl_int
1608*c217d954SCole Faust getInfo(Func f, cl_uint name, T* param)
1609*c217d954SCole Faust {
1610*c217d954SCole Faust return getInfoHelper(f, name, param, 0);
1611*c217d954SCole Faust }
1612*c217d954SCole Faust
1613*c217d954SCole Faust template <typename Func, typename Arg0>
1614*c217d954SCole Faust struct GetInfoFunctor0
1615*c217d954SCole Faust {
1616*c217d954SCole Faust Func f_; const Arg0& arg0_;
operator ()cl::detail::GetInfoFunctor01617*c217d954SCole Faust cl_int operator ()(
1618*c217d954SCole Faust cl_uint param, size_type size, void* value, size_type* size_ret)
1619*c217d954SCole Faust { return f_(arg0_, param, size, value, size_ret); }
1620*c217d954SCole Faust };
1621*c217d954SCole Faust
1622*c217d954SCole Faust template <typename Func, typename Arg0, typename Arg1>
1623*c217d954SCole Faust struct GetInfoFunctor1
1624*c217d954SCole Faust {
1625*c217d954SCole Faust Func f_; const Arg0& arg0_; const Arg1& arg1_;
operator ()cl::detail::GetInfoFunctor11626*c217d954SCole Faust cl_int operator ()(
1627*c217d954SCole Faust cl_uint param, size_type size, void* value, size_type* size_ret)
1628*c217d954SCole Faust { return f_(arg0_, arg1_, param, size, value, size_ret); }
1629*c217d954SCole Faust };
1630*c217d954SCole Faust
1631*c217d954SCole Faust template <typename Func, typename Arg0, typename T>
1632*c217d954SCole Faust inline cl_int
getInfo(Func f,const Arg0 & arg0,cl_uint name,T * param)1633*c217d954SCole Faust getInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
1634*c217d954SCole Faust {
1635*c217d954SCole Faust GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
1636*c217d954SCole Faust return getInfoHelper(f0, name, param, 0);
1637*c217d954SCole Faust }
1638*c217d954SCole Faust
1639*c217d954SCole Faust template <typename Func, typename Arg0, typename Arg1, typename T>
1640*c217d954SCole Faust inline cl_int
getInfo(Func f,const Arg0 & arg0,const Arg1 & arg1,cl_uint name,T * param)1641*c217d954SCole Faust getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
1642*c217d954SCole Faust {
1643*c217d954SCole Faust GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
1644*c217d954SCole Faust return getInfoHelper(f0, name, param, 0);
1645*c217d954SCole Faust }
1646*c217d954SCole Faust
1647*c217d954SCole Faust
1648*c217d954SCole Faust template<typename T>
1649*c217d954SCole Faust struct ReferenceHandler
1650*c217d954SCole Faust { };
1651*c217d954SCole Faust
1652*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1653*c217d954SCole Faust /**
1654*c217d954SCole Faust * OpenCL 1.2 devices do have retain/release.
1655*c217d954SCole Faust */
1656*c217d954SCole Faust template <>
1657*c217d954SCole Faust struct ReferenceHandler<cl_device_id>
1658*c217d954SCole Faust {
1659*c217d954SCole Faust /**
1660*c217d954SCole Faust * Retain the device.
1661*c217d954SCole Faust * \param device A valid device created using createSubDevices
1662*c217d954SCole Faust * \return
1663*c217d954SCole Faust * CL_SUCCESS if the function executed successfully.
1664*c217d954SCole Faust * CL_INVALID_DEVICE if device was not a valid subdevice
1665*c217d954SCole Faust * CL_OUT_OF_RESOURCES
1666*c217d954SCole Faust * CL_OUT_OF_HOST_MEMORY
1667*c217d954SCole Faust */
retaincl::detail::ReferenceHandler1668*c217d954SCole Faust static cl_int retain(cl_device_id device)
1669*c217d954SCole Faust { return ::clRetainDevice(device); }
1670*c217d954SCole Faust /**
1671*c217d954SCole Faust * Retain the device.
1672*c217d954SCole Faust * \param device A valid device created using createSubDevices
1673*c217d954SCole Faust * \return
1674*c217d954SCole Faust * CL_SUCCESS if the function executed successfully.
1675*c217d954SCole Faust * CL_INVALID_DEVICE if device was not a valid subdevice
1676*c217d954SCole Faust * CL_OUT_OF_RESOURCES
1677*c217d954SCole Faust * CL_OUT_OF_HOST_MEMORY
1678*c217d954SCole Faust */
releasecl::detail::ReferenceHandler1679*c217d954SCole Faust static cl_int release(cl_device_id device)
1680*c217d954SCole Faust { return ::clReleaseDevice(device); }
1681*c217d954SCole Faust };
1682*c217d954SCole Faust #else // CL_HPP_TARGET_OPENCL_VERSION >= 120
1683*c217d954SCole Faust /**
1684*c217d954SCole Faust * OpenCL 1.1 devices do not have retain/release.
1685*c217d954SCole Faust */
1686*c217d954SCole Faust template <>
1687*c217d954SCole Faust struct ReferenceHandler<cl_device_id>
1688*c217d954SCole Faust {
1689*c217d954SCole Faust // cl_device_id does not have retain().
retaincl::detail::ReferenceHandler1690*c217d954SCole Faust static cl_int retain(cl_device_id)
1691*c217d954SCole Faust { return CL_SUCCESS; }
1692*c217d954SCole Faust // cl_device_id does not have release().
releasecl::detail::ReferenceHandler1693*c217d954SCole Faust static cl_int release(cl_device_id)
1694*c217d954SCole Faust { return CL_SUCCESS; }
1695*c217d954SCole Faust };
1696*c217d954SCole Faust #endif // ! (CL_HPP_TARGET_OPENCL_VERSION >= 120)
1697*c217d954SCole Faust
1698*c217d954SCole Faust template <>
1699*c217d954SCole Faust struct ReferenceHandler<cl_platform_id>
1700*c217d954SCole Faust {
1701*c217d954SCole Faust // cl_platform_id does not have retain().
retaincl::detail::ReferenceHandler1702*c217d954SCole Faust static cl_int retain(cl_platform_id)
1703*c217d954SCole Faust { return CL_SUCCESS; }
1704*c217d954SCole Faust // cl_platform_id does not have release().
releasecl::detail::ReferenceHandler1705*c217d954SCole Faust static cl_int release(cl_platform_id)
1706*c217d954SCole Faust { return CL_SUCCESS; }
1707*c217d954SCole Faust };
1708*c217d954SCole Faust
1709*c217d954SCole Faust template <>
1710*c217d954SCole Faust struct ReferenceHandler<cl_context>
1711*c217d954SCole Faust {
retaincl::detail::ReferenceHandler1712*c217d954SCole Faust static cl_int retain(cl_context context)
1713*c217d954SCole Faust { return ::clRetainContext(context); }
releasecl::detail::ReferenceHandler1714*c217d954SCole Faust static cl_int release(cl_context context)
1715*c217d954SCole Faust { return ::clReleaseContext(context); }
1716*c217d954SCole Faust };
1717*c217d954SCole Faust
1718*c217d954SCole Faust template <>
1719*c217d954SCole Faust struct ReferenceHandler<cl_command_queue>
1720*c217d954SCole Faust {
retaincl::detail::ReferenceHandler1721*c217d954SCole Faust static cl_int retain(cl_command_queue queue)
1722*c217d954SCole Faust { return ::clRetainCommandQueue(queue); }
releasecl::detail::ReferenceHandler1723*c217d954SCole Faust static cl_int release(cl_command_queue queue)
1724*c217d954SCole Faust { return ::clReleaseCommandQueue(queue); }
1725*c217d954SCole Faust };
1726*c217d954SCole Faust
1727*c217d954SCole Faust template <>
1728*c217d954SCole Faust struct ReferenceHandler<cl_mem>
1729*c217d954SCole Faust {
retaincl::detail::ReferenceHandler1730*c217d954SCole Faust static cl_int retain(cl_mem memory)
1731*c217d954SCole Faust { return ::clRetainMemObject(memory); }
releasecl::detail::ReferenceHandler1732*c217d954SCole Faust static cl_int release(cl_mem memory)
1733*c217d954SCole Faust { return ::clReleaseMemObject(memory); }
1734*c217d954SCole Faust };
1735*c217d954SCole Faust
1736*c217d954SCole Faust template <>
1737*c217d954SCole Faust struct ReferenceHandler<cl_sampler>
1738*c217d954SCole Faust {
retaincl::detail::ReferenceHandler1739*c217d954SCole Faust static cl_int retain(cl_sampler sampler)
1740*c217d954SCole Faust { return ::clRetainSampler(sampler); }
releasecl::detail::ReferenceHandler1741*c217d954SCole Faust static cl_int release(cl_sampler sampler)
1742*c217d954SCole Faust { return ::clReleaseSampler(sampler); }
1743*c217d954SCole Faust };
1744*c217d954SCole Faust
1745*c217d954SCole Faust template <>
1746*c217d954SCole Faust struct ReferenceHandler<cl_program>
1747*c217d954SCole Faust {
retaincl::detail::ReferenceHandler1748*c217d954SCole Faust static cl_int retain(cl_program program)
1749*c217d954SCole Faust { return ::clRetainProgram(program); }
releasecl::detail::ReferenceHandler1750*c217d954SCole Faust static cl_int release(cl_program program)
1751*c217d954SCole Faust { return ::clReleaseProgram(program); }
1752*c217d954SCole Faust };
1753*c217d954SCole Faust
1754*c217d954SCole Faust template <>
1755*c217d954SCole Faust struct ReferenceHandler<cl_kernel>
1756*c217d954SCole Faust {
retaincl::detail::ReferenceHandler1757*c217d954SCole Faust static cl_int retain(cl_kernel kernel)
1758*c217d954SCole Faust { return ::clRetainKernel(kernel); }
releasecl::detail::ReferenceHandler1759*c217d954SCole Faust static cl_int release(cl_kernel kernel)
1760*c217d954SCole Faust { return ::clReleaseKernel(kernel); }
1761*c217d954SCole Faust };
1762*c217d954SCole Faust
1763*c217d954SCole Faust template <>
1764*c217d954SCole Faust struct ReferenceHandler<cl_event>
1765*c217d954SCole Faust {
retaincl::detail::ReferenceHandler1766*c217d954SCole Faust static cl_int retain(cl_event event)
1767*c217d954SCole Faust { return ::clRetainEvent(event); }
releasecl::detail::ReferenceHandler1768*c217d954SCole Faust static cl_int release(cl_event event)
1769*c217d954SCole Faust { return ::clReleaseEvent(event); }
1770*c217d954SCole Faust };
1771*c217d954SCole Faust
1772*c217d954SCole Faust
1773*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1774*c217d954SCole Faust // Extracts version number with major in the upper 16 bits, minor in the lower 16
getVersion(const vector<char> & versionInfo)1775*c217d954SCole Faust static cl_uint getVersion(const vector<char> &versionInfo)
1776*c217d954SCole Faust {
1777*c217d954SCole Faust int highVersion = 0;
1778*c217d954SCole Faust int lowVersion = 0;
1779*c217d954SCole Faust int index = 7;
1780*c217d954SCole Faust while(versionInfo[index] != '.' ) {
1781*c217d954SCole Faust highVersion *= 10;
1782*c217d954SCole Faust highVersion += versionInfo[index]-'0';
1783*c217d954SCole Faust ++index;
1784*c217d954SCole Faust }
1785*c217d954SCole Faust ++index;
1786*c217d954SCole Faust while(versionInfo[index] != ' ' && versionInfo[index] != '\0') {
1787*c217d954SCole Faust lowVersion *= 10;
1788*c217d954SCole Faust lowVersion += versionInfo[index]-'0';
1789*c217d954SCole Faust ++index;
1790*c217d954SCole Faust }
1791*c217d954SCole Faust return (highVersion << 16) | lowVersion;
1792*c217d954SCole Faust }
1793*c217d954SCole Faust
getPlatformVersion(cl_platform_id platform)1794*c217d954SCole Faust static cl_uint getPlatformVersion(cl_platform_id platform)
1795*c217d954SCole Faust {
1796*c217d954SCole Faust size_type size = 0;
1797*c217d954SCole Faust clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size);
1798*c217d954SCole Faust
1799*c217d954SCole Faust vector<char> versionInfo(size);
1800*c217d954SCole Faust clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, versionInfo.data(), &size);
1801*c217d954SCole Faust return getVersion(versionInfo);
1802*c217d954SCole Faust }
1803*c217d954SCole Faust
getDevicePlatformVersion(cl_device_id device)1804*c217d954SCole Faust static cl_uint getDevicePlatformVersion(cl_device_id device)
1805*c217d954SCole Faust {
1806*c217d954SCole Faust cl_platform_id platform;
1807*c217d954SCole Faust clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL);
1808*c217d954SCole Faust return getPlatformVersion(platform);
1809*c217d954SCole Faust }
1810*c217d954SCole Faust
getContextPlatformVersion(cl_context context)1811*c217d954SCole Faust static cl_uint getContextPlatformVersion(cl_context context)
1812*c217d954SCole Faust {
1813*c217d954SCole Faust // The platform cannot be queried directly, so we first have to grab a
1814*c217d954SCole Faust // device and obtain its context
1815*c217d954SCole Faust size_type size = 0;
1816*c217d954SCole Faust clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size);
1817*c217d954SCole Faust if (size == 0)
1818*c217d954SCole Faust return 0;
1819*c217d954SCole Faust vector<cl_device_id> devices(size/sizeof(cl_device_id));
1820*c217d954SCole Faust clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices.data(), NULL);
1821*c217d954SCole Faust return getDevicePlatformVersion(devices[0]);
1822*c217d954SCole Faust }
1823*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
1824*c217d954SCole Faust
1825*c217d954SCole Faust template <typename T>
1826*c217d954SCole Faust class Wrapper
1827*c217d954SCole Faust {
1828*c217d954SCole Faust public:
1829*c217d954SCole Faust typedef T cl_type;
1830*c217d954SCole Faust
1831*c217d954SCole Faust protected:
1832*c217d954SCole Faust cl_type object_;
1833*c217d954SCole Faust
1834*c217d954SCole Faust public:
Wrapper()1835*c217d954SCole Faust Wrapper() : object_(NULL) { }
1836*c217d954SCole Faust
Wrapper(const cl_type & obj,bool retainObject)1837*c217d954SCole Faust Wrapper(const cl_type &obj, bool retainObject) : object_(obj)
1838*c217d954SCole Faust {
1839*c217d954SCole Faust if (retainObject) {
1840*c217d954SCole Faust detail::errHandler(retain(), __RETAIN_ERR);
1841*c217d954SCole Faust }
1842*c217d954SCole Faust }
1843*c217d954SCole Faust
~Wrapper()1844*c217d954SCole Faust ~Wrapper()
1845*c217d954SCole Faust {
1846*c217d954SCole Faust if (object_ != NULL) { release(); }
1847*c217d954SCole Faust }
1848*c217d954SCole Faust
Wrapper(const Wrapper<cl_type> & rhs)1849*c217d954SCole Faust Wrapper(const Wrapper<cl_type>& rhs)
1850*c217d954SCole Faust {
1851*c217d954SCole Faust object_ = rhs.object_;
1852*c217d954SCole Faust detail::errHandler(retain(), __RETAIN_ERR);
1853*c217d954SCole Faust }
1854*c217d954SCole Faust
Wrapper(Wrapper<cl_type> && rhs)1855*c217d954SCole Faust Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT_
1856*c217d954SCole Faust {
1857*c217d954SCole Faust object_ = rhs.object_;
1858*c217d954SCole Faust rhs.object_ = NULL;
1859*c217d954SCole Faust }
1860*c217d954SCole Faust
operator =(const Wrapper<cl_type> & rhs)1861*c217d954SCole Faust Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
1862*c217d954SCole Faust {
1863*c217d954SCole Faust if (this != &rhs) {
1864*c217d954SCole Faust detail::errHandler(release(), __RELEASE_ERR);
1865*c217d954SCole Faust object_ = rhs.object_;
1866*c217d954SCole Faust detail::errHandler(retain(), __RETAIN_ERR);
1867*c217d954SCole Faust }
1868*c217d954SCole Faust return *this;
1869*c217d954SCole Faust }
1870*c217d954SCole Faust
operator =(Wrapper<cl_type> && rhs)1871*c217d954SCole Faust Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
1872*c217d954SCole Faust {
1873*c217d954SCole Faust if (this != &rhs) {
1874*c217d954SCole Faust detail::errHandler(release(), __RELEASE_ERR);
1875*c217d954SCole Faust object_ = rhs.object_;
1876*c217d954SCole Faust rhs.object_ = NULL;
1877*c217d954SCole Faust }
1878*c217d954SCole Faust return *this;
1879*c217d954SCole Faust }
1880*c217d954SCole Faust
operator =(const cl_type & rhs)1881*c217d954SCole Faust Wrapper<cl_type>& operator = (const cl_type &rhs)
1882*c217d954SCole Faust {
1883*c217d954SCole Faust detail::errHandler(release(), __RELEASE_ERR);
1884*c217d954SCole Faust object_ = rhs;
1885*c217d954SCole Faust return *this;
1886*c217d954SCole Faust }
1887*c217d954SCole Faust
operator ()() const1888*c217d954SCole Faust const cl_type& operator ()() const { return object_; }
1889*c217d954SCole Faust
operator ()()1890*c217d954SCole Faust cl_type& operator ()() { return object_; }
1891*c217d954SCole Faust
get() const1892*c217d954SCole Faust cl_type get() const { return object_; }
1893*c217d954SCole Faust
1894*c217d954SCole Faust protected:
1895*c217d954SCole Faust template<typename Func, typename U>
1896*c217d954SCole Faust friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
1897*c217d954SCole Faust
retain() const1898*c217d954SCole Faust cl_int retain() const
1899*c217d954SCole Faust {
1900*c217d954SCole Faust if (object_ != nullptr) {
1901*c217d954SCole Faust return ReferenceHandler<cl_type>::retain(object_);
1902*c217d954SCole Faust }
1903*c217d954SCole Faust else {
1904*c217d954SCole Faust return CL_SUCCESS;
1905*c217d954SCole Faust }
1906*c217d954SCole Faust }
1907*c217d954SCole Faust
release() const1908*c217d954SCole Faust cl_int release() const
1909*c217d954SCole Faust {
1910*c217d954SCole Faust if (object_ != nullptr) {
1911*c217d954SCole Faust return ReferenceHandler<cl_type>::release(object_);
1912*c217d954SCole Faust }
1913*c217d954SCole Faust else {
1914*c217d954SCole Faust return CL_SUCCESS;
1915*c217d954SCole Faust }
1916*c217d954SCole Faust }
1917*c217d954SCole Faust };
1918*c217d954SCole Faust
1919*c217d954SCole Faust template <>
1920*c217d954SCole Faust class Wrapper<cl_device_id>
1921*c217d954SCole Faust {
1922*c217d954SCole Faust public:
1923*c217d954SCole Faust typedef cl_device_id cl_type;
1924*c217d954SCole Faust
1925*c217d954SCole Faust protected:
1926*c217d954SCole Faust cl_type object_;
1927*c217d954SCole Faust bool referenceCountable_;
1928*c217d954SCole Faust
isReferenceCountable(cl_device_id device)1929*c217d954SCole Faust static bool isReferenceCountable(cl_device_id device)
1930*c217d954SCole Faust {
1931*c217d954SCole Faust bool retVal = false;
1932*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
1933*c217d954SCole Faust #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
1934*c217d954SCole Faust if (device != NULL) {
1935*c217d954SCole Faust int version = getDevicePlatformVersion(device);
1936*c217d954SCole Faust if(version > ((1 << 16) + 1)) {
1937*c217d954SCole Faust retVal = true;
1938*c217d954SCole Faust }
1939*c217d954SCole Faust }
1940*c217d954SCole Faust #else // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1941*c217d954SCole Faust retVal = true;
1942*c217d954SCole Faust #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
1943*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
1944*c217d954SCole Faust return retVal;
1945*c217d954SCole Faust }
1946*c217d954SCole Faust
1947*c217d954SCole Faust public:
Wrapper()1948*c217d954SCole Faust Wrapper() : object_(NULL), referenceCountable_(false)
1949*c217d954SCole Faust {
1950*c217d954SCole Faust }
1951*c217d954SCole Faust
Wrapper(const cl_type & obj,bool retainObject)1952*c217d954SCole Faust Wrapper(const cl_type &obj, bool retainObject) :
1953*c217d954SCole Faust object_(obj),
1954*c217d954SCole Faust referenceCountable_(false)
1955*c217d954SCole Faust {
1956*c217d954SCole Faust referenceCountable_ = isReferenceCountable(obj);
1957*c217d954SCole Faust
1958*c217d954SCole Faust if (retainObject) {
1959*c217d954SCole Faust detail::errHandler(retain(), __RETAIN_ERR);
1960*c217d954SCole Faust }
1961*c217d954SCole Faust }
1962*c217d954SCole Faust
~Wrapper()1963*c217d954SCole Faust ~Wrapper()
1964*c217d954SCole Faust {
1965*c217d954SCole Faust release();
1966*c217d954SCole Faust }
1967*c217d954SCole Faust
Wrapper(const Wrapper<cl_type> & rhs)1968*c217d954SCole Faust Wrapper(const Wrapper<cl_type>& rhs)
1969*c217d954SCole Faust {
1970*c217d954SCole Faust object_ = rhs.object_;
1971*c217d954SCole Faust referenceCountable_ = isReferenceCountable(object_);
1972*c217d954SCole Faust detail::errHandler(retain(), __RETAIN_ERR);
1973*c217d954SCole Faust }
1974*c217d954SCole Faust
Wrapper(Wrapper<cl_type> && rhs)1975*c217d954SCole Faust Wrapper(Wrapper<cl_type>&& rhs) CL_HPP_NOEXCEPT_
1976*c217d954SCole Faust {
1977*c217d954SCole Faust object_ = rhs.object_;
1978*c217d954SCole Faust referenceCountable_ = rhs.referenceCountable_;
1979*c217d954SCole Faust rhs.object_ = NULL;
1980*c217d954SCole Faust rhs.referenceCountable_ = false;
1981*c217d954SCole Faust }
1982*c217d954SCole Faust
operator =(const Wrapper<cl_type> & rhs)1983*c217d954SCole Faust Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
1984*c217d954SCole Faust {
1985*c217d954SCole Faust if (this != &rhs) {
1986*c217d954SCole Faust detail::errHandler(release(), __RELEASE_ERR);
1987*c217d954SCole Faust object_ = rhs.object_;
1988*c217d954SCole Faust referenceCountable_ = rhs.referenceCountable_;
1989*c217d954SCole Faust detail::errHandler(retain(), __RETAIN_ERR);
1990*c217d954SCole Faust }
1991*c217d954SCole Faust return *this;
1992*c217d954SCole Faust }
1993*c217d954SCole Faust
operator =(Wrapper<cl_type> && rhs)1994*c217d954SCole Faust Wrapper<cl_type>& operator = (Wrapper<cl_type>&& rhs)
1995*c217d954SCole Faust {
1996*c217d954SCole Faust if (this != &rhs) {
1997*c217d954SCole Faust detail::errHandler(release(), __RELEASE_ERR);
1998*c217d954SCole Faust object_ = rhs.object_;
1999*c217d954SCole Faust referenceCountable_ = rhs.referenceCountable_;
2000*c217d954SCole Faust rhs.object_ = NULL;
2001*c217d954SCole Faust rhs.referenceCountable_ = false;
2002*c217d954SCole Faust }
2003*c217d954SCole Faust return *this;
2004*c217d954SCole Faust }
2005*c217d954SCole Faust
operator =(const cl_type & rhs)2006*c217d954SCole Faust Wrapper<cl_type>& operator = (const cl_type &rhs)
2007*c217d954SCole Faust {
2008*c217d954SCole Faust detail::errHandler(release(), __RELEASE_ERR);
2009*c217d954SCole Faust object_ = rhs;
2010*c217d954SCole Faust referenceCountable_ = isReferenceCountable(object_);
2011*c217d954SCole Faust return *this;
2012*c217d954SCole Faust }
2013*c217d954SCole Faust
operator ()() const2014*c217d954SCole Faust const cl_type& operator ()() const { return object_; }
2015*c217d954SCole Faust
operator ()()2016*c217d954SCole Faust cl_type& operator ()() { return object_; }
2017*c217d954SCole Faust
get() const2018*c217d954SCole Faust cl_type get() const { return object_; }
2019*c217d954SCole Faust
2020*c217d954SCole Faust protected:
2021*c217d954SCole Faust template<typename Func, typename U>
2022*c217d954SCole Faust friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
2023*c217d954SCole Faust
2024*c217d954SCole Faust template<typename Func, typename U>
2025*c217d954SCole Faust friend inline cl_int getInfoHelper(Func, cl_uint, vector<U>*, int, typename U::cl_type);
2026*c217d954SCole Faust
retain() const2027*c217d954SCole Faust cl_int retain() const
2028*c217d954SCole Faust {
2029*c217d954SCole Faust if( object_ != nullptr && referenceCountable_ ) {
2030*c217d954SCole Faust return ReferenceHandler<cl_type>::retain(object_);
2031*c217d954SCole Faust }
2032*c217d954SCole Faust else {
2033*c217d954SCole Faust return CL_SUCCESS;
2034*c217d954SCole Faust }
2035*c217d954SCole Faust }
2036*c217d954SCole Faust
release() const2037*c217d954SCole Faust cl_int release() const
2038*c217d954SCole Faust {
2039*c217d954SCole Faust if (object_ != nullptr && referenceCountable_) {
2040*c217d954SCole Faust return ReferenceHandler<cl_type>::release(object_);
2041*c217d954SCole Faust }
2042*c217d954SCole Faust else {
2043*c217d954SCole Faust return CL_SUCCESS;
2044*c217d954SCole Faust }
2045*c217d954SCole Faust }
2046*c217d954SCole Faust };
2047*c217d954SCole Faust
2048*c217d954SCole Faust template <typename T>
operator ==(const Wrapper<T> & lhs,const Wrapper<T> & rhs)2049*c217d954SCole Faust inline bool operator==(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
2050*c217d954SCole Faust {
2051*c217d954SCole Faust return lhs() == rhs();
2052*c217d954SCole Faust }
2053*c217d954SCole Faust
2054*c217d954SCole Faust template <typename T>
operator !=(const Wrapper<T> & lhs,const Wrapper<T> & rhs)2055*c217d954SCole Faust inline bool operator!=(const Wrapper<T> &lhs, const Wrapper<T> &rhs)
2056*c217d954SCole Faust {
2057*c217d954SCole Faust return !operator==(lhs, rhs);
2058*c217d954SCole Faust }
2059*c217d954SCole Faust
2060*c217d954SCole Faust } // namespace detail
2061*c217d954SCole Faust //! \endcond
2062*c217d954SCole Faust
2063*c217d954SCole Faust
2064*c217d954SCole Faust using BuildLogType = vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, CL_PROGRAM_BUILD_LOG>::param_type>>;
2065*c217d954SCole Faust #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2066*c217d954SCole Faust /**
2067*c217d954SCole Faust * Exception class for build errors to carry build info
2068*c217d954SCole Faust */
2069*c217d954SCole Faust class BuildError : public Error
2070*c217d954SCole Faust {
2071*c217d954SCole Faust private:
2072*c217d954SCole Faust BuildLogType buildLogs;
2073*c217d954SCole Faust public:
BuildError(cl_int err,const char * errStr,const BuildLogType & vec)2074*c217d954SCole Faust BuildError(cl_int err, const char * errStr, const BuildLogType &vec) : Error(err, errStr), buildLogs(vec)
2075*c217d954SCole Faust {
2076*c217d954SCole Faust }
2077*c217d954SCole Faust
getBuildLog() const2078*c217d954SCole Faust BuildLogType getBuildLog() const
2079*c217d954SCole Faust {
2080*c217d954SCole Faust return buildLogs;
2081*c217d954SCole Faust }
2082*c217d954SCole Faust };
2083*c217d954SCole Faust namespace detail {
buildErrHandler(cl_int err,const char * errStr,const BuildLogType & buildLogs)2084*c217d954SCole Faust static inline cl_int buildErrHandler(
2085*c217d954SCole Faust cl_int err,
2086*c217d954SCole Faust const char * errStr,
2087*c217d954SCole Faust const BuildLogType &buildLogs)
2088*c217d954SCole Faust {
2089*c217d954SCole Faust if (err != CL_SUCCESS) {
2090*c217d954SCole Faust throw BuildError(err, errStr, buildLogs);
2091*c217d954SCole Faust }
2092*c217d954SCole Faust return err;
2093*c217d954SCole Faust }
2094*c217d954SCole Faust } // namespace detail
2095*c217d954SCole Faust
2096*c217d954SCole Faust #else
2097*c217d954SCole Faust namespace detail {
buildErrHandler(cl_int err,const char * errStr,const BuildLogType & buildLogs)2098*c217d954SCole Faust static inline cl_int buildErrHandler(
2099*c217d954SCole Faust cl_int err,
2100*c217d954SCole Faust const char * errStr,
2101*c217d954SCole Faust const BuildLogType &buildLogs)
2102*c217d954SCole Faust {
2103*c217d954SCole Faust (void)buildLogs; // suppress unused variable warning
2104*c217d954SCole Faust (void)errStr;
2105*c217d954SCole Faust return err;
2106*c217d954SCole Faust }
2107*c217d954SCole Faust } // namespace detail
2108*c217d954SCole Faust #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2109*c217d954SCole Faust
2110*c217d954SCole Faust
2111*c217d954SCole Faust /*! \stuct ImageFormat
2112*c217d954SCole Faust * \brief Adds constructors and member functions for cl_image_format.
2113*c217d954SCole Faust *
2114*c217d954SCole Faust * \see cl_image_format
2115*c217d954SCole Faust */
2116*c217d954SCole Faust struct ImageFormat : public cl_image_format
2117*c217d954SCole Faust {
2118*c217d954SCole Faust //! \brief Default constructor - performs no initialization.
ImageFormatcl::ImageFormat2119*c217d954SCole Faust ImageFormat(){}
2120*c217d954SCole Faust
2121*c217d954SCole Faust //! \brief Initializing constructor.
ImageFormatcl::ImageFormat2122*c217d954SCole Faust ImageFormat(cl_channel_order order, cl_channel_type type)
2123*c217d954SCole Faust {
2124*c217d954SCole Faust image_channel_order = order;
2125*c217d954SCole Faust image_channel_data_type = type;
2126*c217d954SCole Faust }
2127*c217d954SCole Faust
2128*c217d954SCole Faust //! \brief Copy constructor.
ImageFormatcl::ImageFormat2129*c217d954SCole Faust ImageFormat(const ImageFormat &other) { *this = other; }
2130*c217d954SCole Faust
2131*c217d954SCole Faust //! \brief Assignment operator.
operator =cl::ImageFormat2132*c217d954SCole Faust ImageFormat& operator = (const ImageFormat& rhs)
2133*c217d954SCole Faust {
2134*c217d954SCole Faust if (this != &rhs) {
2135*c217d954SCole Faust this->image_channel_data_type = rhs.image_channel_data_type;
2136*c217d954SCole Faust this->image_channel_order = rhs.image_channel_order;
2137*c217d954SCole Faust }
2138*c217d954SCole Faust return *this;
2139*c217d954SCole Faust }
2140*c217d954SCole Faust };
2141*c217d954SCole Faust
2142*c217d954SCole Faust /*! \brief Class interface for cl_device_id.
2143*c217d954SCole Faust *
2144*c217d954SCole Faust * \note Copies of these objects are inexpensive, since they don't 'own'
2145*c217d954SCole Faust * any underlying resources or data structures.
2146*c217d954SCole Faust *
2147*c217d954SCole Faust * \see cl_device_id
2148*c217d954SCole Faust */
2149*c217d954SCole Faust class Device : public detail::Wrapper<cl_device_id>
2150*c217d954SCole Faust {
2151*c217d954SCole Faust private:
2152*c217d954SCole Faust static std::once_flag default_initialized_;
2153*c217d954SCole Faust static Device default_;
2154*c217d954SCole Faust static cl_int default_error_;
2155*c217d954SCole Faust
2156*c217d954SCole Faust /*! \brief Create the default context.
2157*c217d954SCole Faust *
2158*c217d954SCole Faust * This sets @c default_ and @c default_error_. It does not throw
2159*c217d954SCole Faust * @c cl::Error.
2160*c217d954SCole Faust */
2161*c217d954SCole Faust static void makeDefault();
2162*c217d954SCole Faust
2163*c217d954SCole Faust /*! \brief Create the default platform from a provided platform.
2164*c217d954SCole Faust *
2165*c217d954SCole Faust * This sets @c default_. It does not throw
2166*c217d954SCole Faust * @c cl::Error.
2167*c217d954SCole Faust */
makeDefaultProvided(const Device & p)2168*c217d954SCole Faust static void makeDefaultProvided(const Device &p) {
2169*c217d954SCole Faust default_ = p;
2170*c217d954SCole Faust }
2171*c217d954SCole Faust
2172*c217d954SCole Faust public:
2173*c217d954SCole Faust #ifdef CL_HPP_UNIT_TEST_ENABLE
2174*c217d954SCole Faust /*! \brief Reset the default.
2175*c217d954SCole Faust *
2176*c217d954SCole Faust * This sets @c default_ to an empty value to support cleanup in
2177*c217d954SCole Faust * the unit test framework.
2178*c217d954SCole Faust * This function is not thread safe.
2179*c217d954SCole Faust */
unitTestClearDefault()2180*c217d954SCole Faust static void unitTestClearDefault() {
2181*c217d954SCole Faust default_ = Device();
2182*c217d954SCole Faust }
2183*c217d954SCole Faust #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2184*c217d954SCole Faust
2185*c217d954SCole Faust //! \brief Default constructor - initializes to NULL.
Device()2186*c217d954SCole Faust Device() : detail::Wrapper<cl_type>() { }
2187*c217d954SCole Faust
2188*c217d954SCole Faust /*! \brief Constructor from cl_device_id.
2189*c217d954SCole Faust *
2190*c217d954SCole Faust * This simply copies the device ID value, which is an inexpensive operation.
2191*c217d954SCole Faust */
Device(const cl_device_id & device,bool retainObject=false)2192*c217d954SCole Faust explicit Device(const cl_device_id &device, bool retainObject = false) :
2193*c217d954SCole Faust detail::Wrapper<cl_type>(device, retainObject) { }
2194*c217d954SCole Faust
2195*c217d954SCole Faust /*! \brief Returns the first device on the default context.
2196*c217d954SCole Faust *
2197*c217d954SCole Faust * \see Context::getDefault()
2198*c217d954SCole Faust */
getDefault(cl_int * errResult=NULL)2199*c217d954SCole Faust static Device getDefault(
2200*c217d954SCole Faust cl_int *errResult = NULL)
2201*c217d954SCole Faust {
2202*c217d954SCole Faust std::call_once(default_initialized_, makeDefault);
2203*c217d954SCole Faust detail::errHandler(default_error_);
2204*c217d954SCole Faust if (errResult != NULL) {
2205*c217d954SCole Faust *errResult = default_error_;
2206*c217d954SCole Faust }
2207*c217d954SCole Faust return default_;
2208*c217d954SCole Faust }
2209*c217d954SCole Faust
2210*c217d954SCole Faust /**
2211*c217d954SCole Faust * Modify the default device to be used by
2212*c217d954SCole Faust * subsequent operations.
2213*c217d954SCole Faust * Will only set the default if no default was previously created.
2214*c217d954SCole Faust * @return updated default device.
2215*c217d954SCole Faust * Should be compared to the passed value to ensure that it was updated.
2216*c217d954SCole Faust */
setDefault(const Device & default_device)2217*c217d954SCole Faust static Device setDefault(const Device &default_device)
2218*c217d954SCole Faust {
2219*c217d954SCole Faust std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_device));
2220*c217d954SCole Faust detail::errHandler(default_error_);
2221*c217d954SCole Faust return default_;
2222*c217d954SCole Faust }
2223*c217d954SCole Faust
2224*c217d954SCole Faust /*! \brief Assignment operator from cl_device_id.
2225*c217d954SCole Faust *
2226*c217d954SCole Faust * This simply copies the device ID value, which is an inexpensive operation.
2227*c217d954SCole Faust */
operator =(const cl_device_id & rhs)2228*c217d954SCole Faust Device& operator = (const cl_device_id& rhs)
2229*c217d954SCole Faust {
2230*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(rhs);
2231*c217d954SCole Faust return *this;
2232*c217d954SCole Faust }
2233*c217d954SCole Faust
2234*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
2235*c217d954SCole Faust * Required for MSVC.
2236*c217d954SCole Faust */
Device(const Device & dev)2237*c217d954SCole Faust Device(const Device& dev) : detail::Wrapper<cl_type>(dev) {}
2238*c217d954SCole Faust
2239*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
2240*c217d954SCole Faust * Required for MSVC.
2241*c217d954SCole Faust */
operator =(const Device & dev)2242*c217d954SCole Faust Device& operator = (const Device &dev)
2243*c217d954SCole Faust {
2244*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(dev);
2245*c217d954SCole Faust return *this;
2246*c217d954SCole Faust }
2247*c217d954SCole Faust
2248*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
2249*c217d954SCole Faust * Required for MSVC.
2250*c217d954SCole Faust */
Device(Device && dev)2251*c217d954SCole Faust Device(Device&& dev) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(dev)) {}
2252*c217d954SCole Faust
2253*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
2254*c217d954SCole Faust * Required for MSVC.
2255*c217d954SCole Faust */
operator =(Device && dev)2256*c217d954SCole Faust Device& operator = (Device &&dev)
2257*c217d954SCole Faust {
2258*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(std::move(dev));
2259*c217d954SCole Faust return *this;
2260*c217d954SCole Faust }
2261*c217d954SCole Faust
2262*c217d954SCole Faust //! \brief Wrapper for clGetDeviceInfo().
2263*c217d954SCole Faust template <typename T>
getInfo(cl_device_info name,T * param) const2264*c217d954SCole Faust cl_int getInfo(cl_device_info name, T* param) const
2265*c217d954SCole Faust {
2266*c217d954SCole Faust return detail::errHandler(
2267*c217d954SCole Faust detail::getInfo(&::clGetDeviceInfo, object_, name, param),
2268*c217d954SCole Faust __GET_DEVICE_INFO_ERR);
2269*c217d954SCole Faust }
2270*c217d954SCole Faust
2271*c217d954SCole Faust //! \brief Wrapper for clGetDeviceInfo() that returns by value.
2272*c217d954SCole Faust template <cl_device_info name> typename
2273*c217d954SCole Faust detail::param_traits<detail::cl_device_info, name>::param_type
getInfo(cl_int * err=NULL) const2274*c217d954SCole Faust getInfo(cl_int* err = NULL) const
2275*c217d954SCole Faust {
2276*c217d954SCole Faust typename detail::param_traits<
2277*c217d954SCole Faust detail::cl_device_info, name>::param_type param;
2278*c217d954SCole Faust cl_int result = getInfo(name, ¶m);
2279*c217d954SCole Faust if (err != NULL) {
2280*c217d954SCole Faust *err = result;
2281*c217d954SCole Faust }
2282*c217d954SCole Faust return param;
2283*c217d954SCole Faust }
2284*c217d954SCole Faust
2285*c217d954SCole Faust
2286*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2287*c217d954SCole Faust /**
2288*c217d954SCole Faust * Return the current value of the host clock as seen by the device.
2289*c217d954SCole Faust * The resolution of the device timer may be queried with the
2290*c217d954SCole Faust * CL_DEVICE_PROFILING_TIMER_RESOLUTION query.
2291*c217d954SCole Faust * @return The host timer value.
2292*c217d954SCole Faust */
getHostTimer(cl_int * error=nullptr)2293*c217d954SCole Faust cl_ulong getHostTimer(cl_int *error = nullptr)
2294*c217d954SCole Faust {
2295*c217d954SCole Faust cl_ulong retVal = 0;
2296*c217d954SCole Faust cl_int err =
2297*c217d954SCole Faust clGetHostTimer(this->get(), &retVal);
2298*c217d954SCole Faust detail::errHandler(
2299*c217d954SCole Faust err,
2300*c217d954SCole Faust __GET_HOST_TIMER_ERR);
2301*c217d954SCole Faust if (error) {
2302*c217d954SCole Faust *error = err;
2303*c217d954SCole Faust }
2304*c217d954SCole Faust return retVal;
2305*c217d954SCole Faust }
2306*c217d954SCole Faust
2307*c217d954SCole Faust /**
2308*c217d954SCole Faust * Return a synchronized pair of host and device timestamps as seen by device.
2309*c217d954SCole Faust * Use to correlate the clocks and get the host timer only using getHostTimer
2310*c217d954SCole Faust * as a lower cost mechanism in between calls.
2311*c217d954SCole Faust * The resolution of the host timer may be queried with the
2312*c217d954SCole Faust * CL_PLATFORM_HOST_TIMER_RESOLUTION query.
2313*c217d954SCole Faust * The resolution of the device timer may be queried with the
2314*c217d954SCole Faust * CL_DEVICE_PROFILING_TIMER_RESOLUTION query.
2315*c217d954SCole Faust * @return A pair of (device timer, host timer) timer values.
2316*c217d954SCole Faust */
getDeviceAndHostTimer(cl_int * error=nullptr)2317*c217d954SCole Faust std::pair<cl_ulong, cl_ulong> getDeviceAndHostTimer(cl_int *error = nullptr)
2318*c217d954SCole Faust {
2319*c217d954SCole Faust std::pair<cl_ulong, cl_ulong> retVal;
2320*c217d954SCole Faust cl_int err =
2321*c217d954SCole Faust clGetDeviceAndHostTimer(this->get(), &(retVal.first), &(retVal.second));
2322*c217d954SCole Faust detail::errHandler(
2323*c217d954SCole Faust err,
2324*c217d954SCole Faust __GET_DEVICE_AND_HOST_TIMER_ERR);
2325*c217d954SCole Faust if (error) {
2326*c217d954SCole Faust *error = err;
2327*c217d954SCole Faust }
2328*c217d954SCole Faust return retVal;
2329*c217d954SCole Faust }
2330*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
2331*c217d954SCole Faust
2332*c217d954SCole Faust /**
2333*c217d954SCole Faust * CL 1.2 version
2334*c217d954SCole Faust */
2335*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
2336*c217d954SCole Faust //! \brief Wrapper for clCreateSubDevices().
createSubDevices(const cl_device_partition_property * properties,vector<Device> * devices)2337*c217d954SCole Faust cl_int createSubDevices(
2338*c217d954SCole Faust const cl_device_partition_property * properties,
2339*c217d954SCole Faust vector<Device>* devices)
2340*c217d954SCole Faust {
2341*c217d954SCole Faust cl_uint n = 0;
2342*c217d954SCole Faust cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n);
2343*c217d954SCole Faust if (err != CL_SUCCESS) {
2344*c217d954SCole Faust return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2345*c217d954SCole Faust }
2346*c217d954SCole Faust
2347*c217d954SCole Faust vector<cl_device_id> ids(n);
2348*c217d954SCole Faust err = clCreateSubDevices(object_, properties, n, ids.data(), NULL);
2349*c217d954SCole Faust if (err != CL_SUCCESS) {
2350*c217d954SCole Faust return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2351*c217d954SCole Faust }
2352*c217d954SCole Faust
2353*c217d954SCole Faust // Cannot trivially assign because we need to capture intermediates
2354*c217d954SCole Faust // with safe construction
2355*c217d954SCole Faust if (devices) {
2356*c217d954SCole Faust devices->resize(ids.size());
2357*c217d954SCole Faust
2358*c217d954SCole Faust // Assign to param, constructing with retain behaviour
2359*c217d954SCole Faust // to correctly capture each underlying CL object
2360*c217d954SCole Faust for (size_type i = 0; i < ids.size(); i++) {
2361*c217d954SCole Faust // We do not need to retain because this device is being created
2362*c217d954SCole Faust // by the runtime
2363*c217d954SCole Faust (*devices)[i] = Device(ids[i], false);
2364*c217d954SCole Faust }
2365*c217d954SCole Faust }
2366*c217d954SCole Faust
2367*c217d954SCole Faust return CL_SUCCESS;
2368*c217d954SCole Faust }
2369*c217d954SCole Faust #elif defined(CL_HPP_USE_CL_DEVICE_FISSION)
2370*c217d954SCole Faust
2371*c217d954SCole Faust /**
2372*c217d954SCole Faust * CL 1.1 version that uses device fission extension.
2373*c217d954SCole Faust */
createSubDevices(const cl_device_partition_property_ext * properties,vector<Device> * devices)2374*c217d954SCole Faust cl_int createSubDevices(
2375*c217d954SCole Faust const cl_device_partition_property_ext * properties,
2376*c217d954SCole Faust vector<Device>* devices)
2377*c217d954SCole Faust {
2378*c217d954SCole Faust typedef CL_API_ENTRY cl_int
2379*c217d954SCole Faust ( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
2380*c217d954SCole Faust cl_device_id /*in_device*/,
2381*c217d954SCole Faust const cl_device_partition_property_ext * /* properties */,
2382*c217d954SCole Faust cl_uint /*num_entries*/,
2383*c217d954SCole Faust cl_device_id * /*out_devices*/,
2384*c217d954SCole Faust cl_uint * /*num_devices*/ ) CL_API_SUFFIX__VERSION_1_1;
2385*c217d954SCole Faust
2386*c217d954SCole Faust static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
2387*c217d954SCole Faust CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateSubDevicesEXT);
2388*c217d954SCole Faust
2389*c217d954SCole Faust cl_uint n = 0;
2390*c217d954SCole Faust cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
2391*c217d954SCole Faust if (err != CL_SUCCESS) {
2392*c217d954SCole Faust return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2393*c217d954SCole Faust }
2394*c217d954SCole Faust
2395*c217d954SCole Faust vector<cl_device_id> ids(n);
2396*c217d954SCole Faust err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids.data(), NULL);
2397*c217d954SCole Faust if (err != CL_SUCCESS) {
2398*c217d954SCole Faust return detail::errHandler(err, __CREATE_SUB_DEVICES_ERR);
2399*c217d954SCole Faust }
2400*c217d954SCole Faust // Cannot trivially assign because we need to capture intermediates
2401*c217d954SCole Faust // with safe construction
2402*c217d954SCole Faust if (devices) {
2403*c217d954SCole Faust devices->resize(ids.size());
2404*c217d954SCole Faust
2405*c217d954SCole Faust // Assign to param, constructing with retain behaviour
2406*c217d954SCole Faust // to correctly capture each underlying CL object
2407*c217d954SCole Faust for (size_type i = 0; i < ids.size(); i++) {
2408*c217d954SCole Faust // We do not need to retain because this device is being created
2409*c217d954SCole Faust // by the runtime
2410*c217d954SCole Faust (*devices)[i] = Device(ids[i], false);
2411*c217d954SCole Faust }
2412*c217d954SCole Faust }
2413*c217d954SCole Faust return CL_SUCCESS;
2414*c217d954SCole Faust }
2415*c217d954SCole Faust #endif // defined(CL_HPP_USE_CL_DEVICE_FISSION)
2416*c217d954SCole Faust };
2417*c217d954SCole Faust
2418*c217d954SCole Faust CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Device::default_initialized_;
2419*c217d954SCole Faust CL_HPP_DEFINE_STATIC_MEMBER_ Device Device::default_;
2420*c217d954SCole Faust CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Device::default_error_ = CL_SUCCESS;
2421*c217d954SCole Faust
2422*c217d954SCole Faust /*! \brief Class interface for cl_platform_id.
2423*c217d954SCole Faust *
2424*c217d954SCole Faust * \note Copies of these objects are inexpensive, since they don't 'own'
2425*c217d954SCole Faust * any underlying resources or data structures.
2426*c217d954SCole Faust *
2427*c217d954SCole Faust * \see cl_platform_id
2428*c217d954SCole Faust */
2429*c217d954SCole Faust class Platform : public detail::Wrapper<cl_platform_id>
2430*c217d954SCole Faust {
2431*c217d954SCole Faust private:
2432*c217d954SCole Faust static std::once_flag default_initialized_;
2433*c217d954SCole Faust static Platform default_;
2434*c217d954SCole Faust static cl_int default_error_;
2435*c217d954SCole Faust
2436*c217d954SCole Faust /*! \brief Create the default context.
2437*c217d954SCole Faust *
2438*c217d954SCole Faust * This sets @c default_ and @c default_error_. It does not throw
2439*c217d954SCole Faust * @c cl::Error.
2440*c217d954SCole Faust */
makeDefault()2441*c217d954SCole Faust static void makeDefault() {
2442*c217d954SCole Faust /* Throwing an exception from a call_once invocation does not do
2443*c217d954SCole Faust * what we wish, so we catch it and save the error.
2444*c217d954SCole Faust */
2445*c217d954SCole Faust #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2446*c217d954SCole Faust try
2447*c217d954SCole Faust #endif
2448*c217d954SCole Faust {
2449*c217d954SCole Faust // If default wasn't passed ,generate one
2450*c217d954SCole Faust // Otherwise set it
2451*c217d954SCole Faust cl_uint n = 0;
2452*c217d954SCole Faust
2453*c217d954SCole Faust cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2454*c217d954SCole Faust if (err != CL_SUCCESS) {
2455*c217d954SCole Faust default_error_ = err;
2456*c217d954SCole Faust return;
2457*c217d954SCole Faust }
2458*c217d954SCole Faust if (n == 0) {
2459*c217d954SCole Faust default_error_ = CL_INVALID_PLATFORM;
2460*c217d954SCole Faust return;
2461*c217d954SCole Faust }
2462*c217d954SCole Faust
2463*c217d954SCole Faust vector<cl_platform_id> ids(n);
2464*c217d954SCole Faust err = ::clGetPlatformIDs(n, ids.data(), NULL);
2465*c217d954SCole Faust if (err != CL_SUCCESS) {
2466*c217d954SCole Faust default_error_ = err;
2467*c217d954SCole Faust return;
2468*c217d954SCole Faust }
2469*c217d954SCole Faust
2470*c217d954SCole Faust default_ = Platform(ids[0]);
2471*c217d954SCole Faust }
2472*c217d954SCole Faust #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2473*c217d954SCole Faust catch (cl::Error &e) {
2474*c217d954SCole Faust default_error_ = e.err();
2475*c217d954SCole Faust }
2476*c217d954SCole Faust #endif
2477*c217d954SCole Faust }
2478*c217d954SCole Faust
2479*c217d954SCole Faust /*! \brief Create the default platform from a provided platform.
2480*c217d954SCole Faust *
2481*c217d954SCole Faust * This sets @c default_. It does not throw
2482*c217d954SCole Faust * @c cl::Error.
2483*c217d954SCole Faust */
makeDefaultProvided(const Platform & p)2484*c217d954SCole Faust static void makeDefaultProvided(const Platform &p) {
2485*c217d954SCole Faust default_ = p;
2486*c217d954SCole Faust }
2487*c217d954SCole Faust
2488*c217d954SCole Faust public:
2489*c217d954SCole Faust #ifdef CL_HPP_UNIT_TEST_ENABLE
2490*c217d954SCole Faust /*! \brief Reset the default.
2491*c217d954SCole Faust *
2492*c217d954SCole Faust * This sets @c default_ to an empty value to support cleanup in
2493*c217d954SCole Faust * the unit test framework.
2494*c217d954SCole Faust * This function is not thread safe.
2495*c217d954SCole Faust */
unitTestClearDefault()2496*c217d954SCole Faust static void unitTestClearDefault() {
2497*c217d954SCole Faust default_ = Platform();
2498*c217d954SCole Faust }
2499*c217d954SCole Faust #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2500*c217d954SCole Faust
2501*c217d954SCole Faust //! \brief Default constructor - initializes to NULL.
Platform()2502*c217d954SCole Faust Platform() : detail::Wrapper<cl_type>() { }
2503*c217d954SCole Faust
2504*c217d954SCole Faust /*! \brief Constructor from cl_platform_id.
2505*c217d954SCole Faust *
2506*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
2507*c217d954SCole Faust * Defaults to false to maintain compatibility with
2508*c217d954SCole Faust * earlier versions.
2509*c217d954SCole Faust * This simply copies the platform ID value, which is an inexpensive operation.
2510*c217d954SCole Faust */
Platform(const cl_platform_id & platform,bool retainObject=false)2511*c217d954SCole Faust explicit Platform(const cl_platform_id &platform, bool retainObject = false) :
2512*c217d954SCole Faust detail::Wrapper<cl_type>(platform, retainObject) { }
2513*c217d954SCole Faust
2514*c217d954SCole Faust /*! \brief Assignment operator from cl_platform_id.
2515*c217d954SCole Faust *
2516*c217d954SCole Faust * This simply copies the platform ID value, which is an inexpensive operation.
2517*c217d954SCole Faust */
operator =(const cl_platform_id & rhs)2518*c217d954SCole Faust Platform& operator = (const cl_platform_id& rhs)
2519*c217d954SCole Faust {
2520*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(rhs);
2521*c217d954SCole Faust return *this;
2522*c217d954SCole Faust }
2523*c217d954SCole Faust
getDefault(cl_int * errResult=NULL)2524*c217d954SCole Faust static Platform getDefault(
2525*c217d954SCole Faust cl_int *errResult = NULL)
2526*c217d954SCole Faust {
2527*c217d954SCole Faust std::call_once(default_initialized_, makeDefault);
2528*c217d954SCole Faust detail::errHandler(default_error_);
2529*c217d954SCole Faust if (errResult != NULL) {
2530*c217d954SCole Faust *errResult = default_error_;
2531*c217d954SCole Faust }
2532*c217d954SCole Faust return default_;
2533*c217d954SCole Faust }
2534*c217d954SCole Faust
2535*c217d954SCole Faust /**
2536*c217d954SCole Faust * Modify the default platform to be used by
2537*c217d954SCole Faust * subsequent operations.
2538*c217d954SCole Faust * Will only set the default if no default was previously created.
2539*c217d954SCole Faust * @return updated default platform.
2540*c217d954SCole Faust * Should be compared to the passed value to ensure that it was updated.
2541*c217d954SCole Faust */
setDefault(const Platform & default_platform)2542*c217d954SCole Faust static Platform setDefault(const Platform &default_platform)
2543*c217d954SCole Faust {
2544*c217d954SCole Faust std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_platform));
2545*c217d954SCole Faust detail::errHandler(default_error_);
2546*c217d954SCole Faust return default_;
2547*c217d954SCole Faust }
2548*c217d954SCole Faust
2549*c217d954SCole Faust //! \brief Wrapper for clGetPlatformInfo().
2550*c217d954SCole Faust template <typename T>
getInfo(cl_platform_info name,T * param) const2551*c217d954SCole Faust cl_int getInfo(cl_platform_info name, T* param) const
2552*c217d954SCole Faust {
2553*c217d954SCole Faust return detail::errHandler(
2554*c217d954SCole Faust detail::getInfo(&::clGetPlatformInfo, object_, name, param),
2555*c217d954SCole Faust __GET_PLATFORM_INFO_ERR);
2556*c217d954SCole Faust }
2557*c217d954SCole Faust
2558*c217d954SCole Faust //! \brief Wrapper for clGetPlatformInfo() that returns by value.
2559*c217d954SCole Faust template <cl_platform_info name> typename
2560*c217d954SCole Faust detail::param_traits<detail::cl_platform_info, name>::param_type
getInfo(cl_int * err=NULL) const2561*c217d954SCole Faust getInfo(cl_int* err = NULL) const
2562*c217d954SCole Faust {
2563*c217d954SCole Faust typename detail::param_traits<
2564*c217d954SCole Faust detail::cl_platform_info, name>::param_type param;
2565*c217d954SCole Faust cl_int result = getInfo(name, ¶m);
2566*c217d954SCole Faust if (err != NULL) {
2567*c217d954SCole Faust *err = result;
2568*c217d954SCole Faust }
2569*c217d954SCole Faust return param;
2570*c217d954SCole Faust }
2571*c217d954SCole Faust
2572*c217d954SCole Faust /*! \brief Gets a list of devices for this platform.
2573*c217d954SCole Faust *
2574*c217d954SCole Faust * Wraps clGetDeviceIDs().
2575*c217d954SCole Faust */
getDevices(cl_device_type type,vector<Device> * devices) const2576*c217d954SCole Faust cl_int getDevices(
2577*c217d954SCole Faust cl_device_type type,
2578*c217d954SCole Faust vector<Device>* devices) const
2579*c217d954SCole Faust {
2580*c217d954SCole Faust cl_uint n = 0;
2581*c217d954SCole Faust if( devices == NULL ) {
2582*c217d954SCole Faust return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2583*c217d954SCole Faust }
2584*c217d954SCole Faust cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
2585*c217d954SCole Faust if (err != CL_SUCCESS && err != CL_DEVICE_NOT_FOUND) {
2586*c217d954SCole Faust return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2587*c217d954SCole Faust }
2588*c217d954SCole Faust
2589*c217d954SCole Faust vector<cl_device_id> ids(n);
2590*c217d954SCole Faust if (n>0) {
2591*c217d954SCole Faust err = ::clGetDeviceIDs(object_, type, n, ids.data(), NULL);
2592*c217d954SCole Faust if (err != CL_SUCCESS) {
2593*c217d954SCole Faust return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2594*c217d954SCole Faust }
2595*c217d954SCole Faust }
2596*c217d954SCole Faust
2597*c217d954SCole Faust // Cannot trivially assign because we need to capture intermediates
2598*c217d954SCole Faust // with safe construction
2599*c217d954SCole Faust // We must retain things we obtain from the API to avoid releasing
2600*c217d954SCole Faust // API-owned objects.
2601*c217d954SCole Faust if (devices) {
2602*c217d954SCole Faust devices->resize(ids.size());
2603*c217d954SCole Faust
2604*c217d954SCole Faust // Assign to param, constructing with retain behaviour
2605*c217d954SCole Faust // to correctly capture each underlying CL object
2606*c217d954SCole Faust for (size_type i = 0; i < ids.size(); i++) {
2607*c217d954SCole Faust (*devices)[i] = Device(ids[i], true);
2608*c217d954SCole Faust }
2609*c217d954SCole Faust }
2610*c217d954SCole Faust return CL_SUCCESS;
2611*c217d954SCole Faust }
2612*c217d954SCole Faust
2613*c217d954SCole Faust #if defined(CL_HPP_USE_DX_INTEROP)
2614*c217d954SCole Faust /*! \brief Get the list of available D3D10 devices.
2615*c217d954SCole Faust *
2616*c217d954SCole Faust * \param d3d_device_source.
2617*c217d954SCole Faust *
2618*c217d954SCole Faust * \param d3d_object.
2619*c217d954SCole Faust *
2620*c217d954SCole Faust * \param d3d_device_set.
2621*c217d954SCole Faust *
2622*c217d954SCole Faust * \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device
2623*c217d954SCole Faust * values returned in devices can be used to identify a specific OpenCL
2624*c217d954SCole Faust * device. If \a devices argument is NULL, this argument is ignored.
2625*c217d954SCole Faust *
2626*c217d954SCole Faust * \return One of the following values:
2627*c217d954SCole Faust * - CL_SUCCESS if the function is executed successfully.
2628*c217d954SCole Faust *
2629*c217d954SCole Faust * The application can query specific capabilities of the OpenCL device(s)
2630*c217d954SCole Faust * returned by cl::getDevices. This can be used by the application to
2631*c217d954SCole Faust * determine which device(s) to use.
2632*c217d954SCole Faust *
2633*c217d954SCole Faust * \note In the case that exceptions are enabled and a return value
2634*c217d954SCole Faust * other than CL_SUCCESS is generated, then cl::Error exception is
2635*c217d954SCole Faust * generated.
2636*c217d954SCole Faust */
getDevices(cl_d3d10_device_source_khr d3d_device_source,void * d3d_object,cl_d3d10_device_set_khr d3d_device_set,vector<Device> * devices) const2637*c217d954SCole Faust cl_int getDevices(
2638*c217d954SCole Faust cl_d3d10_device_source_khr d3d_device_source,
2639*c217d954SCole Faust void * d3d_object,
2640*c217d954SCole Faust cl_d3d10_device_set_khr d3d_device_set,
2641*c217d954SCole Faust vector<Device>* devices) const
2642*c217d954SCole Faust {
2643*c217d954SCole Faust typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
2644*c217d954SCole Faust cl_platform_id platform,
2645*c217d954SCole Faust cl_d3d10_device_source_khr d3d_device_source,
2646*c217d954SCole Faust void * d3d_object,
2647*c217d954SCole Faust cl_d3d10_device_set_khr d3d_device_set,
2648*c217d954SCole Faust cl_uint num_entries,
2649*c217d954SCole Faust cl_device_id * devices,
2650*c217d954SCole Faust cl_uint* num_devices);
2651*c217d954SCole Faust
2652*c217d954SCole Faust if( devices == NULL ) {
2653*c217d954SCole Faust return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
2654*c217d954SCole Faust }
2655*c217d954SCole Faust
2656*c217d954SCole Faust static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
2657*c217d954SCole Faust CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(object_, clGetDeviceIDsFromD3D10KHR);
2658*c217d954SCole Faust
2659*c217d954SCole Faust cl_uint n = 0;
2660*c217d954SCole Faust cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
2661*c217d954SCole Faust object_,
2662*c217d954SCole Faust d3d_device_source,
2663*c217d954SCole Faust d3d_object,
2664*c217d954SCole Faust d3d_device_set,
2665*c217d954SCole Faust 0,
2666*c217d954SCole Faust NULL,
2667*c217d954SCole Faust &n);
2668*c217d954SCole Faust if (err != CL_SUCCESS) {
2669*c217d954SCole Faust return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2670*c217d954SCole Faust }
2671*c217d954SCole Faust
2672*c217d954SCole Faust vector<cl_device_id> ids(n);
2673*c217d954SCole Faust err = pfn_clGetDeviceIDsFromD3D10KHR(
2674*c217d954SCole Faust object_,
2675*c217d954SCole Faust d3d_device_source,
2676*c217d954SCole Faust d3d_object,
2677*c217d954SCole Faust d3d_device_set,
2678*c217d954SCole Faust n,
2679*c217d954SCole Faust ids.data(),
2680*c217d954SCole Faust NULL);
2681*c217d954SCole Faust if (err != CL_SUCCESS) {
2682*c217d954SCole Faust return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
2683*c217d954SCole Faust }
2684*c217d954SCole Faust
2685*c217d954SCole Faust // Cannot trivially assign because we need to capture intermediates
2686*c217d954SCole Faust // with safe construction
2687*c217d954SCole Faust // We must retain things we obtain from the API to avoid releasing
2688*c217d954SCole Faust // API-owned objects.
2689*c217d954SCole Faust if (devices) {
2690*c217d954SCole Faust devices->resize(ids.size());
2691*c217d954SCole Faust
2692*c217d954SCole Faust // Assign to param, constructing with retain behaviour
2693*c217d954SCole Faust // to correctly capture each underlying CL object
2694*c217d954SCole Faust for (size_type i = 0; i < ids.size(); i++) {
2695*c217d954SCole Faust (*devices)[i] = Device(ids[i], true);
2696*c217d954SCole Faust }
2697*c217d954SCole Faust }
2698*c217d954SCole Faust return CL_SUCCESS;
2699*c217d954SCole Faust }
2700*c217d954SCole Faust #endif
2701*c217d954SCole Faust
2702*c217d954SCole Faust /*! \brief Gets a list of available platforms.
2703*c217d954SCole Faust *
2704*c217d954SCole Faust * Wraps clGetPlatformIDs().
2705*c217d954SCole Faust */
get(vector<Platform> * platforms)2706*c217d954SCole Faust static cl_int get(
2707*c217d954SCole Faust vector<Platform>* platforms)
2708*c217d954SCole Faust {
2709*c217d954SCole Faust cl_uint n = 0;
2710*c217d954SCole Faust
2711*c217d954SCole Faust if( platforms == NULL ) {
2712*c217d954SCole Faust return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
2713*c217d954SCole Faust }
2714*c217d954SCole Faust
2715*c217d954SCole Faust cl_int err = ::clGetPlatformIDs(0, NULL, &n);
2716*c217d954SCole Faust if (err != CL_SUCCESS) {
2717*c217d954SCole Faust return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2718*c217d954SCole Faust }
2719*c217d954SCole Faust
2720*c217d954SCole Faust vector<cl_platform_id> ids(n);
2721*c217d954SCole Faust err = ::clGetPlatformIDs(n, ids.data(), NULL);
2722*c217d954SCole Faust if (err != CL_SUCCESS) {
2723*c217d954SCole Faust return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
2724*c217d954SCole Faust }
2725*c217d954SCole Faust
2726*c217d954SCole Faust if (platforms) {
2727*c217d954SCole Faust platforms->resize(ids.size());
2728*c217d954SCole Faust
2729*c217d954SCole Faust // Platforms don't reference count
2730*c217d954SCole Faust for (size_type i = 0; i < ids.size(); i++) {
2731*c217d954SCole Faust (*platforms)[i] = Platform(ids[i]);
2732*c217d954SCole Faust }
2733*c217d954SCole Faust }
2734*c217d954SCole Faust return CL_SUCCESS;
2735*c217d954SCole Faust }
2736*c217d954SCole Faust
2737*c217d954SCole Faust /*! \brief Gets the first available platform.
2738*c217d954SCole Faust *
2739*c217d954SCole Faust * Wraps clGetPlatformIDs(), returning the first result.
2740*c217d954SCole Faust */
get(Platform * platform)2741*c217d954SCole Faust static cl_int get(
2742*c217d954SCole Faust Platform * platform)
2743*c217d954SCole Faust {
2744*c217d954SCole Faust cl_int err;
2745*c217d954SCole Faust Platform default_platform = Platform::getDefault(&err);
2746*c217d954SCole Faust if (platform) {
2747*c217d954SCole Faust *platform = default_platform;
2748*c217d954SCole Faust }
2749*c217d954SCole Faust return err;
2750*c217d954SCole Faust }
2751*c217d954SCole Faust
2752*c217d954SCole Faust /*! \brief Gets the first available platform, returning it by value.
2753*c217d954SCole Faust *
2754*c217d954SCole Faust * \return Returns a valid platform if one is available.
2755*c217d954SCole Faust * If no platform is available will return a null platform.
2756*c217d954SCole Faust * Throws an exception if no platforms are available
2757*c217d954SCole Faust * or an error condition occurs.
2758*c217d954SCole Faust * Wraps clGetPlatformIDs(), returning the first result.
2759*c217d954SCole Faust */
get(cl_int * errResult=NULL)2760*c217d954SCole Faust static Platform get(
2761*c217d954SCole Faust cl_int * errResult = NULL)
2762*c217d954SCole Faust {
2763*c217d954SCole Faust cl_int err;
2764*c217d954SCole Faust Platform default_platform = Platform::getDefault(&err);
2765*c217d954SCole Faust if (errResult) {
2766*c217d954SCole Faust *errResult = err;
2767*c217d954SCole Faust }
2768*c217d954SCole Faust return default_platform;
2769*c217d954SCole Faust }
2770*c217d954SCole Faust
2771*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
2772*c217d954SCole Faust //! \brief Wrapper for clUnloadCompiler().
2773*c217d954SCole Faust cl_int
unloadCompiler()2774*c217d954SCole Faust unloadCompiler()
2775*c217d954SCole Faust {
2776*c217d954SCole Faust return ::clUnloadPlatformCompiler(object_);
2777*c217d954SCole Faust }
2778*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
2779*c217d954SCole Faust }; // class Platform
2780*c217d954SCole Faust
2781*c217d954SCole Faust CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Platform::default_initialized_;
2782*c217d954SCole Faust CL_HPP_DEFINE_STATIC_MEMBER_ Platform Platform::default_;
2783*c217d954SCole Faust CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Platform::default_error_ = CL_SUCCESS;
2784*c217d954SCole Faust
2785*c217d954SCole Faust
2786*c217d954SCole Faust /**
2787*c217d954SCole Faust * Deprecated APIs for 1.2
2788*c217d954SCole Faust */
2789*c217d954SCole Faust #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2790*c217d954SCole Faust /**
2791*c217d954SCole Faust * Unload the OpenCL compiler.
2792*c217d954SCole Faust * \note Deprecated for OpenCL 1.2. Use Platform::unloadCompiler instead.
2793*c217d954SCole Faust */
2794*c217d954SCole Faust inline CL_API_PREFIX__VERSION_1_1_DEPRECATED cl_int
2795*c217d954SCole Faust UnloadCompiler() CL_API_SUFFIX__VERSION_1_1_DEPRECATED;
2796*c217d954SCole Faust inline cl_int
UnloadCompiler()2797*c217d954SCole Faust UnloadCompiler()
2798*c217d954SCole Faust {
2799*c217d954SCole Faust return ::clUnloadCompiler();
2800*c217d954SCole Faust }
2801*c217d954SCole Faust #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
2802*c217d954SCole Faust
2803*c217d954SCole Faust /*! \brief Class interface for cl_context.
2804*c217d954SCole Faust *
2805*c217d954SCole Faust * \note Copies of these objects are shallow, meaning that the copy will refer
2806*c217d954SCole Faust * to the same underlying cl_context as the original. For details, see
2807*c217d954SCole Faust * clRetainContext() and clReleaseContext().
2808*c217d954SCole Faust *
2809*c217d954SCole Faust * \see cl_context
2810*c217d954SCole Faust */
2811*c217d954SCole Faust class Context
2812*c217d954SCole Faust : public detail::Wrapper<cl_context>
2813*c217d954SCole Faust {
2814*c217d954SCole Faust private:
2815*c217d954SCole Faust static std::once_flag default_initialized_;
2816*c217d954SCole Faust static Context default_;
2817*c217d954SCole Faust static cl_int default_error_;
2818*c217d954SCole Faust
2819*c217d954SCole Faust /*! \brief Create the default context from the default device type in the default platform.
2820*c217d954SCole Faust *
2821*c217d954SCole Faust * This sets @c default_ and @c default_error_. It does not throw
2822*c217d954SCole Faust * @c cl::Error.
2823*c217d954SCole Faust */
makeDefault()2824*c217d954SCole Faust static void makeDefault() {
2825*c217d954SCole Faust /* Throwing an exception from a call_once invocation does not do
2826*c217d954SCole Faust * what we wish, so we catch it and save the error.
2827*c217d954SCole Faust */
2828*c217d954SCole Faust #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2829*c217d954SCole Faust try
2830*c217d954SCole Faust #endif
2831*c217d954SCole Faust {
2832*c217d954SCole Faust #if !defined(__APPLE__) && !defined(__MACOS)
2833*c217d954SCole Faust const Platform &p = Platform::getDefault();
2834*c217d954SCole Faust cl_platform_id defaultPlatform = p();
2835*c217d954SCole Faust cl_context_properties properties[3] = {
2836*c217d954SCole Faust CL_CONTEXT_PLATFORM, (cl_context_properties)defaultPlatform, 0
2837*c217d954SCole Faust };
2838*c217d954SCole Faust #else // #if !defined(__APPLE__) && !defined(__MACOS)
2839*c217d954SCole Faust cl_context_properties *properties = nullptr;
2840*c217d954SCole Faust #endif // #if !defined(__APPLE__) && !defined(__MACOS)
2841*c217d954SCole Faust
2842*c217d954SCole Faust default_ = Context(
2843*c217d954SCole Faust CL_DEVICE_TYPE_DEFAULT,
2844*c217d954SCole Faust properties,
2845*c217d954SCole Faust NULL,
2846*c217d954SCole Faust NULL,
2847*c217d954SCole Faust &default_error_);
2848*c217d954SCole Faust }
2849*c217d954SCole Faust #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2850*c217d954SCole Faust catch (cl::Error &e) {
2851*c217d954SCole Faust default_error_ = e.err();
2852*c217d954SCole Faust }
2853*c217d954SCole Faust #endif
2854*c217d954SCole Faust }
2855*c217d954SCole Faust
2856*c217d954SCole Faust
2857*c217d954SCole Faust /*! \brief Create the default context from a provided Context.
2858*c217d954SCole Faust *
2859*c217d954SCole Faust * This sets @c default_. It does not throw
2860*c217d954SCole Faust * @c cl::Error.
2861*c217d954SCole Faust */
makeDefaultProvided(const Context & c)2862*c217d954SCole Faust static void makeDefaultProvided(const Context &c) {
2863*c217d954SCole Faust default_ = c;
2864*c217d954SCole Faust }
2865*c217d954SCole Faust
2866*c217d954SCole Faust public:
2867*c217d954SCole Faust #ifdef CL_HPP_UNIT_TEST_ENABLE
2868*c217d954SCole Faust /*! \brief Reset the default.
2869*c217d954SCole Faust *
2870*c217d954SCole Faust * This sets @c default_ to an empty value to support cleanup in
2871*c217d954SCole Faust * the unit test framework.
2872*c217d954SCole Faust * This function is not thread safe.
2873*c217d954SCole Faust */
unitTestClearDefault()2874*c217d954SCole Faust static void unitTestClearDefault() {
2875*c217d954SCole Faust default_ = Context();
2876*c217d954SCole Faust }
2877*c217d954SCole Faust #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
2878*c217d954SCole Faust
2879*c217d954SCole Faust /*! \brief Constructs a context including a list of specified devices.
2880*c217d954SCole Faust *
2881*c217d954SCole Faust * Wraps clCreateContext().
2882*c217d954SCole Faust */
Context(const vector<Device> & devices,const cl_context_properties * properties=NULL,void (CL_CALLBACK * notifyFptr)(const char *,const void *,size_type,void *)=NULL,void * data=NULL,cl_int * err=NULL)2883*c217d954SCole Faust Context(
2884*c217d954SCole Faust const vector<Device>& devices,
2885*c217d954SCole Faust const cl_context_properties* properties = NULL,
2886*c217d954SCole Faust void (CL_CALLBACK * notifyFptr)(
2887*c217d954SCole Faust const char *,
2888*c217d954SCole Faust const void *,
2889*c217d954SCole Faust size_type,
2890*c217d954SCole Faust void *) = NULL,
2891*c217d954SCole Faust void* data = NULL,
2892*c217d954SCole Faust cl_int* err = NULL)
2893*c217d954SCole Faust {
2894*c217d954SCole Faust cl_int error;
2895*c217d954SCole Faust
2896*c217d954SCole Faust size_type numDevices = devices.size();
2897*c217d954SCole Faust vector<cl_device_id> deviceIDs(numDevices);
2898*c217d954SCole Faust
2899*c217d954SCole Faust for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
2900*c217d954SCole Faust deviceIDs[deviceIndex] = (devices[deviceIndex])();
2901*c217d954SCole Faust }
2902*c217d954SCole Faust
2903*c217d954SCole Faust object_ = ::clCreateContext(
2904*c217d954SCole Faust properties, (cl_uint) numDevices,
2905*c217d954SCole Faust deviceIDs.data(),
2906*c217d954SCole Faust notifyFptr, data, &error);
2907*c217d954SCole Faust
2908*c217d954SCole Faust detail::errHandler(error, __CREATE_CONTEXT_ERR);
2909*c217d954SCole Faust if (err != NULL) {
2910*c217d954SCole Faust *err = error;
2911*c217d954SCole Faust }
2912*c217d954SCole Faust }
2913*c217d954SCole Faust
2914*c217d954SCole Faust /*! \brief Constructs a context including a specific device.
2915*c217d954SCole Faust *
2916*c217d954SCole Faust * Wraps clCreateContext().
2917*c217d954SCole Faust */
Context(const Device & device,const cl_context_properties * properties=NULL,void (CL_CALLBACK * notifyFptr)(const char *,const void *,size_type,void *)=NULL,void * data=NULL,cl_int * err=NULL)2918*c217d954SCole Faust Context(
2919*c217d954SCole Faust const Device& device,
2920*c217d954SCole Faust const cl_context_properties* properties = NULL,
2921*c217d954SCole Faust void (CL_CALLBACK * notifyFptr)(
2922*c217d954SCole Faust const char *,
2923*c217d954SCole Faust const void *,
2924*c217d954SCole Faust size_type,
2925*c217d954SCole Faust void *) = NULL,
2926*c217d954SCole Faust void* data = NULL,
2927*c217d954SCole Faust cl_int* err = NULL)
2928*c217d954SCole Faust {
2929*c217d954SCole Faust cl_int error;
2930*c217d954SCole Faust
2931*c217d954SCole Faust cl_device_id deviceID = device();
2932*c217d954SCole Faust
2933*c217d954SCole Faust object_ = ::clCreateContext(
2934*c217d954SCole Faust properties, 1,
2935*c217d954SCole Faust &deviceID,
2936*c217d954SCole Faust notifyFptr, data, &error);
2937*c217d954SCole Faust
2938*c217d954SCole Faust detail::errHandler(error, __CREATE_CONTEXT_ERR);
2939*c217d954SCole Faust if (err != NULL) {
2940*c217d954SCole Faust *err = error;
2941*c217d954SCole Faust }
2942*c217d954SCole Faust }
2943*c217d954SCole Faust
2944*c217d954SCole Faust /*! \brief Constructs a context including all or a subset of devices of a specified type.
2945*c217d954SCole Faust *
2946*c217d954SCole Faust * Wraps clCreateContextFromType().
2947*c217d954SCole Faust */
Context(cl_device_type type,const cl_context_properties * properties=NULL,void (CL_CALLBACK * notifyFptr)(const char *,const void *,size_type,void *)=NULL,void * data=NULL,cl_int * err=NULL)2948*c217d954SCole Faust Context(
2949*c217d954SCole Faust cl_device_type type,
2950*c217d954SCole Faust const cl_context_properties* properties = NULL,
2951*c217d954SCole Faust void (CL_CALLBACK * notifyFptr)(
2952*c217d954SCole Faust const char *,
2953*c217d954SCole Faust const void *,
2954*c217d954SCole Faust size_type,
2955*c217d954SCole Faust void *) = NULL,
2956*c217d954SCole Faust void* data = NULL,
2957*c217d954SCole Faust cl_int* err = NULL)
2958*c217d954SCole Faust {
2959*c217d954SCole Faust cl_int error;
2960*c217d954SCole Faust
2961*c217d954SCole Faust #if !defined(__APPLE__) && !defined(__MACOS)
2962*c217d954SCole Faust cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 };
2963*c217d954SCole Faust
2964*c217d954SCole Faust if (properties == NULL) {
2965*c217d954SCole Faust // Get a valid platform ID as we cannot send in a blank one
2966*c217d954SCole Faust vector<Platform> platforms;
2967*c217d954SCole Faust error = Platform::get(&platforms);
2968*c217d954SCole Faust if (error != CL_SUCCESS) {
2969*c217d954SCole Faust detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2970*c217d954SCole Faust if (err != NULL) {
2971*c217d954SCole Faust *err = error;
2972*c217d954SCole Faust }
2973*c217d954SCole Faust return;
2974*c217d954SCole Faust }
2975*c217d954SCole Faust
2976*c217d954SCole Faust // Check the platforms we found for a device of our specified type
2977*c217d954SCole Faust cl_context_properties platform_id = 0;
2978*c217d954SCole Faust for (unsigned int i = 0; i < platforms.size(); i++) {
2979*c217d954SCole Faust
2980*c217d954SCole Faust vector<Device> devices;
2981*c217d954SCole Faust
2982*c217d954SCole Faust #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2983*c217d954SCole Faust try {
2984*c217d954SCole Faust #endif
2985*c217d954SCole Faust
2986*c217d954SCole Faust error = platforms[i].getDevices(type, &devices);
2987*c217d954SCole Faust
2988*c217d954SCole Faust #if defined(CL_HPP_ENABLE_EXCEPTIONS)
2989*c217d954SCole Faust } catch (cl::Error& e) {
2990*c217d954SCole Faust error = e.err();
2991*c217d954SCole Faust }
2992*c217d954SCole Faust // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type
2993*c217d954SCole Faust // We do error checking next anyway, and can throw there if needed
2994*c217d954SCole Faust #endif
2995*c217d954SCole Faust
2996*c217d954SCole Faust // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND
2997*c217d954SCole Faust if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) {
2998*c217d954SCole Faust detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
2999*c217d954SCole Faust if (err != NULL) {
3000*c217d954SCole Faust *err = error;
3001*c217d954SCole Faust }
3002*c217d954SCole Faust }
3003*c217d954SCole Faust
3004*c217d954SCole Faust if (devices.size() > 0) {
3005*c217d954SCole Faust platform_id = (cl_context_properties)platforms[i]();
3006*c217d954SCole Faust break;
3007*c217d954SCole Faust }
3008*c217d954SCole Faust }
3009*c217d954SCole Faust
3010*c217d954SCole Faust if (platform_id == 0) {
3011*c217d954SCole Faust detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR);
3012*c217d954SCole Faust if (err != NULL) {
3013*c217d954SCole Faust *err = CL_DEVICE_NOT_FOUND;
3014*c217d954SCole Faust }
3015*c217d954SCole Faust return;
3016*c217d954SCole Faust }
3017*c217d954SCole Faust
3018*c217d954SCole Faust prop[1] = platform_id;
3019*c217d954SCole Faust properties = &prop[0];
3020*c217d954SCole Faust }
3021*c217d954SCole Faust #endif
3022*c217d954SCole Faust object_ = ::clCreateContextFromType(
3023*c217d954SCole Faust properties, type, notifyFptr, data, &error);
3024*c217d954SCole Faust
3025*c217d954SCole Faust detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
3026*c217d954SCole Faust if (err != NULL) {
3027*c217d954SCole Faust *err = error;
3028*c217d954SCole Faust }
3029*c217d954SCole Faust }
3030*c217d954SCole Faust
3031*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
3032*c217d954SCole Faust * Required for MSVC.
3033*c217d954SCole Faust */
Context(const Context & ctx)3034*c217d954SCole Faust Context(const Context& ctx) : detail::Wrapper<cl_type>(ctx) {}
3035*c217d954SCole Faust
3036*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
3037*c217d954SCole Faust * Required for MSVC.
3038*c217d954SCole Faust */
operator =(const Context & ctx)3039*c217d954SCole Faust Context& operator = (const Context &ctx)
3040*c217d954SCole Faust {
3041*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(ctx);
3042*c217d954SCole Faust return *this;
3043*c217d954SCole Faust }
3044*c217d954SCole Faust
3045*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
3046*c217d954SCole Faust * Required for MSVC.
3047*c217d954SCole Faust */
Context(Context && ctx)3048*c217d954SCole Faust Context(Context&& ctx) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(ctx)) {}
3049*c217d954SCole Faust
3050*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
3051*c217d954SCole Faust * Required for MSVC.
3052*c217d954SCole Faust */
operator =(Context && ctx)3053*c217d954SCole Faust Context& operator = (Context &&ctx)
3054*c217d954SCole Faust {
3055*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(std::move(ctx));
3056*c217d954SCole Faust return *this;
3057*c217d954SCole Faust }
3058*c217d954SCole Faust
3059*c217d954SCole Faust
3060*c217d954SCole Faust /*! \brief Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT.
3061*c217d954SCole Faust *
3062*c217d954SCole Faust * \note All calls to this function return the same cl_context as the first.
3063*c217d954SCole Faust */
getDefault(cl_int * err=NULL)3064*c217d954SCole Faust static Context getDefault(cl_int * err = NULL)
3065*c217d954SCole Faust {
3066*c217d954SCole Faust std::call_once(default_initialized_, makeDefault);
3067*c217d954SCole Faust detail::errHandler(default_error_);
3068*c217d954SCole Faust if (err != NULL) {
3069*c217d954SCole Faust *err = default_error_;
3070*c217d954SCole Faust }
3071*c217d954SCole Faust return default_;
3072*c217d954SCole Faust }
3073*c217d954SCole Faust
3074*c217d954SCole Faust /**
3075*c217d954SCole Faust * Modify the default context to be used by
3076*c217d954SCole Faust * subsequent operations.
3077*c217d954SCole Faust * Will only set the default if no default was previously created.
3078*c217d954SCole Faust * @return updated default context.
3079*c217d954SCole Faust * Should be compared to the passed value to ensure that it was updated.
3080*c217d954SCole Faust */
setDefault(const Context & default_context)3081*c217d954SCole Faust static Context setDefault(const Context &default_context)
3082*c217d954SCole Faust {
3083*c217d954SCole Faust std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_context));
3084*c217d954SCole Faust detail::errHandler(default_error_);
3085*c217d954SCole Faust return default_;
3086*c217d954SCole Faust }
3087*c217d954SCole Faust
3088*c217d954SCole Faust //! \brief Default constructor - initializes to NULL.
Context()3089*c217d954SCole Faust Context() : detail::Wrapper<cl_type>() { }
3090*c217d954SCole Faust
3091*c217d954SCole Faust /*! \brief Constructor from cl_context - takes ownership.
3092*c217d954SCole Faust *
3093*c217d954SCole Faust * This effectively transfers ownership of a refcount on the cl_context
3094*c217d954SCole Faust * into the new Context object.
3095*c217d954SCole Faust */
Context(const cl_context & context,bool retainObject=false)3096*c217d954SCole Faust explicit Context(const cl_context& context, bool retainObject = false) :
3097*c217d954SCole Faust detail::Wrapper<cl_type>(context, retainObject) { }
3098*c217d954SCole Faust
3099*c217d954SCole Faust /*! \brief Assignment operator from cl_context - takes ownership.
3100*c217d954SCole Faust *
3101*c217d954SCole Faust * This effectively transfers ownership of a refcount on the rhs and calls
3102*c217d954SCole Faust * clReleaseContext() on the value previously held by this instance.
3103*c217d954SCole Faust */
operator =(const cl_context & rhs)3104*c217d954SCole Faust Context& operator = (const cl_context& rhs)
3105*c217d954SCole Faust {
3106*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(rhs);
3107*c217d954SCole Faust return *this;
3108*c217d954SCole Faust }
3109*c217d954SCole Faust
3110*c217d954SCole Faust //! \brief Wrapper for clGetContextInfo().
3111*c217d954SCole Faust template <typename T>
getInfo(cl_context_info name,T * param) const3112*c217d954SCole Faust cl_int getInfo(cl_context_info name, T* param) const
3113*c217d954SCole Faust {
3114*c217d954SCole Faust return detail::errHandler(
3115*c217d954SCole Faust detail::getInfo(&::clGetContextInfo, object_, name, param),
3116*c217d954SCole Faust __GET_CONTEXT_INFO_ERR);
3117*c217d954SCole Faust }
3118*c217d954SCole Faust
3119*c217d954SCole Faust //! \brief Wrapper for clGetContextInfo() that returns by value.
3120*c217d954SCole Faust template <cl_context_info name> typename
3121*c217d954SCole Faust detail::param_traits<detail::cl_context_info, name>::param_type
getInfo(cl_int * err=NULL) const3122*c217d954SCole Faust getInfo(cl_int* err = NULL) const
3123*c217d954SCole Faust {
3124*c217d954SCole Faust typename detail::param_traits<
3125*c217d954SCole Faust detail::cl_context_info, name>::param_type param;
3126*c217d954SCole Faust cl_int result = getInfo(name, ¶m);
3127*c217d954SCole Faust if (err != NULL) {
3128*c217d954SCole Faust *err = result;
3129*c217d954SCole Faust }
3130*c217d954SCole Faust return param;
3131*c217d954SCole Faust }
3132*c217d954SCole Faust
3133*c217d954SCole Faust /*! \brief Gets a list of supported image formats.
3134*c217d954SCole Faust *
3135*c217d954SCole Faust * Wraps clGetSupportedImageFormats().
3136*c217d954SCole Faust */
getSupportedImageFormats(cl_mem_flags flags,cl_mem_object_type type,vector<ImageFormat> * formats) const3137*c217d954SCole Faust cl_int getSupportedImageFormats(
3138*c217d954SCole Faust cl_mem_flags flags,
3139*c217d954SCole Faust cl_mem_object_type type,
3140*c217d954SCole Faust vector<ImageFormat>* formats) const
3141*c217d954SCole Faust {
3142*c217d954SCole Faust cl_uint numEntries;
3143*c217d954SCole Faust
3144*c217d954SCole Faust if (!formats) {
3145*c217d954SCole Faust return CL_SUCCESS;
3146*c217d954SCole Faust }
3147*c217d954SCole Faust
3148*c217d954SCole Faust cl_int err = ::clGetSupportedImageFormats(
3149*c217d954SCole Faust object_,
3150*c217d954SCole Faust flags,
3151*c217d954SCole Faust type,
3152*c217d954SCole Faust 0,
3153*c217d954SCole Faust NULL,
3154*c217d954SCole Faust &numEntries);
3155*c217d954SCole Faust if (err != CL_SUCCESS) {
3156*c217d954SCole Faust return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3157*c217d954SCole Faust }
3158*c217d954SCole Faust
3159*c217d954SCole Faust if (numEntries > 0) {
3160*c217d954SCole Faust vector<ImageFormat> value(numEntries);
3161*c217d954SCole Faust err = ::clGetSupportedImageFormats(
3162*c217d954SCole Faust object_,
3163*c217d954SCole Faust flags,
3164*c217d954SCole Faust type,
3165*c217d954SCole Faust numEntries,
3166*c217d954SCole Faust (cl_image_format*)value.data(),
3167*c217d954SCole Faust NULL);
3168*c217d954SCole Faust if (err != CL_SUCCESS) {
3169*c217d954SCole Faust return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
3170*c217d954SCole Faust }
3171*c217d954SCole Faust
3172*c217d954SCole Faust formats->assign(begin(value), end(value));
3173*c217d954SCole Faust }
3174*c217d954SCole Faust else {
3175*c217d954SCole Faust // If no values are being returned, ensure an empty vector comes back
3176*c217d954SCole Faust formats->clear();
3177*c217d954SCole Faust }
3178*c217d954SCole Faust
3179*c217d954SCole Faust return CL_SUCCESS;
3180*c217d954SCole Faust }
3181*c217d954SCole Faust };
3182*c217d954SCole Faust
makeDefault()3183*c217d954SCole Faust inline void Device::makeDefault()
3184*c217d954SCole Faust {
3185*c217d954SCole Faust /* Throwing an exception from a call_once invocation does not do
3186*c217d954SCole Faust * what we wish, so we catch it and save the error.
3187*c217d954SCole Faust */
3188*c217d954SCole Faust #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3189*c217d954SCole Faust try
3190*c217d954SCole Faust #endif
3191*c217d954SCole Faust {
3192*c217d954SCole Faust cl_int error = 0;
3193*c217d954SCole Faust
3194*c217d954SCole Faust Context context = Context::getDefault(&error);
3195*c217d954SCole Faust detail::errHandler(error, __CREATE_CONTEXT_ERR);
3196*c217d954SCole Faust
3197*c217d954SCole Faust if (error != CL_SUCCESS) {
3198*c217d954SCole Faust default_error_ = error;
3199*c217d954SCole Faust }
3200*c217d954SCole Faust else {
3201*c217d954SCole Faust default_ = context.getInfo<CL_CONTEXT_DEVICES>()[0];
3202*c217d954SCole Faust default_error_ = CL_SUCCESS;
3203*c217d954SCole Faust }
3204*c217d954SCole Faust }
3205*c217d954SCole Faust #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3206*c217d954SCole Faust catch (cl::Error &e) {
3207*c217d954SCole Faust default_error_ = e.err();
3208*c217d954SCole Faust }
3209*c217d954SCole Faust #endif
3210*c217d954SCole Faust }
3211*c217d954SCole Faust
3212*c217d954SCole Faust CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag Context::default_initialized_;
3213*c217d954SCole Faust CL_HPP_DEFINE_STATIC_MEMBER_ Context Context::default_;
3214*c217d954SCole Faust CL_HPP_DEFINE_STATIC_MEMBER_ cl_int Context::default_error_ = CL_SUCCESS;
3215*c217d954SCole Faust
3216*c217d954SCole Faust /*! \brief Class interface for cl_event.
3217*c217d954SCole Faust *
3218*c217d954SCole Faust * \note Copies of these objects are shallow, meaning that the copy will refer
3219*c217d954SCole Faust * to the same underlying cl_event as the original. For details, see
3220*c217d954SCole Faust * clRetainEvent() and clReleaseEvent().
3221*c217d954SCole Faust *
3222*c217d954SCole Faust * \see cl_event
3223*c217d954SCole Faust */
3224*c217d954SCole Faust class Event : public detail::Wrapper<cl_event>
3225*c217d954SCole Faust {
3226*c217d954SCole Faust public:
3227*c217d954SCole Faust //! \brief Default constructor - initializes to NULL.
Event()3228*c217d954SCole Faust Event() : detail::Wrapper<cl_type>() { }
3229*c217d954SCole Faust
3230*c217d954SCole Faust /*! \brief Constructor from cl_event - takes ownership.
3231*c217d954SCole Faust *
3232*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
3233*c217d954SCole Faust * Defaults to false to maintain compatibility with
3234*c217d954SCole Faust * earlier versions.
3235*c217d954SCole Faust * This effectively transfers ownership of a refcount on the cl_event
3236*c217d954SCole Faust * into the new Event object.
3237*c217d954SCole Faust */
Event(const cl_event & event,bool retainObject=false)3238*c217d954SCole Faust explicit Event(const cl_event& event, bool retainObject = false) :
3239*c217d954SCole Faust detail::Wrapper<cl_type>(event, retainObject) { }
3240*c217d954SCole Faust
3241*c217d954SCole Faust /*! \brief Assignment operator from cl_event - takes ownership.
3242*c217d954SCole Faust *
3243*c217d954SCole Faust * This effectively transfers ownership of a refcount on the rhs and calls
3244*c217d954SCole Faust * clReleaseEvent() on the value previously held by this instance.
3245*c217d954SCole Faust */
operator =(const cl_event & rhs)3246*c217d954SCole Faust Event& operator = (const cl_event& rhs)
3247*c217d954SCole Faust {
3248*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(rhs);
3249*c217d954SCole Faust return *this;
3250*c217d954SCole Faust }
3251*c217d954SCole Faust
3252*c217d954SCole Faust //! \brief Wrapper for clGetEventInfo().
3253*c217d954SCole Faust template <typename T>
getInfo(cl_event_info name,T * param) const3254*c217d954SCole Faust cl_int getInfo(cl_event_info name, T* param) const
3255*c217d954SCole Faust {
3256*c217d954SCole Faust return detail::errHandler(
3257*c217d954SCole Faust detail::getInfo(&::clGetEventInfo, object_, name, param),
3258*c217d954SCole Faust __GET_EVENT_INFO_ERR);
3259*c217d954SCole Faust }
3260*c217d954SCole Faust
3261*c217d954SCole Faust //! \brief Wrapper for clGetEventInfo() that returns by value.
3262*c217d954SCole Faust template <cl_event_info name> typename
3263*c217d954SCole Faust detail::param_traits<detail::cl_event_info, name>::param_type
getInfo(cl_int * err=NULL) const3264*c217d954SCole Faust getInfo(cl_int* err = NULL) const
3265*c217d954SCole Faust {
3266*c217d954SCole Faust typename detail::param_traits<
3267*c217d954SCole Faust detail::cl_event_info, name>::param_type param;
3268*c217d954SCole Faust cl_int result = getInfo(name, ¶m);
3269*c217d954SCole Faust if (err != NULL) {
3270*c217d954SCole Faust *err = result;
3271*c217d954SCole Faust }
3272*c217d954SCole Faust return param;
3273*c217d954SCole Faust }
3274*c217d954SCole Faust
3275*c217d954SCole Faust //! \brief Wrapper for clGetEventProfilingInfo().
3276*c217d954SCole Faust template <typename T>
getProfilingInfo(cl_profiling_info name,T * param) const3277*c217d954SCole Faust cl_int getProfilingInfo(cl_profiling_info name, T* param) const
3278*c217d954SCole Faust {
3279*c217d954SCole Faust return detail::errHandler(detail::getInfo(
3280*c217d954SCole Faust &::clGetEventProfilingInfo, object_, name, param),
3281*c217d954SCole Faust __GET_EVENT_PROFILE_INFO_ERR);
3282*c217d954SCole Faust }
3283*c217d954SCole Faust
3284*c217d954SCole Faust //! \brief Wrapper for clGetEventProfilingInfo() that returns by value.
3285*c217d954SCole Faust template <cl_profiling_info name> typename
3286*c217d954SCole Faust detail::param_traits<detail::cl_profiling_info, name>::param_type
getProfilingInfo(cl_int * err=NULL) const3287*c217d954SCole Faust getProfilingInfo(cl_int* err = NULL) const
3288*c217d954SCole Faust {
3289*c217d954SCole Faust typename detail::param_traits<
3290*c217d954SCole Faust detail::cl_profiling_info, name>::param_type param;
3291*c217d954SCole Faust cl_int result = getProfilingInfo(name, ¶m);
3292*c217d954SCole Faust if (err != NULL) {
3293*c217d954SCole Faust *err = result;
3294*c217d954SCole Faust }
3295*c217d954SCole Faust return param;
3296*c217d954SCole Faust }
3297*c217d954SCole Faust
3298*c217d954SCole Faust /*! \brief Blocks the calling thread until this event completes.
3299*c217d954SCole Faust *
3300*c217d954SCole Faust * Wraps clWaitForEvents().
3301*c217d954SCole Faust */
wait() const3302*c217d954SCole Faust cl_int wait() const
3303*c217d954SCole Faust {
3304*c217d954SCole Faust return detail::errHandler(
3305*c217d954SCole Faust ::clWaitForEvents(1, &object_),
3306*c217d954SCole Faust __WAIT_FOR_EVENTS_ERR);
3307*c217d954SCole Faust }
3308*c217d954SCole Faust
3309*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3310*c217d954SCole Faust /*! \brief Registers a user callback function for a specific command execution status.
3311*c217d954SCole Faust *
3312*c217d954SCole Faust * Wraps clSetEventCallback().
3313*c217d954SCole Faust */
setCallback(cl_int type,void (CL_CALLBACK * pfn_notify)(cl_event,cl_int,void *),void * user_data=NULL)3314*c217d954SCole Faust cl_int setCallback(
3315*c217d954SCole Faust cl_int type,
3316*c217d954SCole Faust void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
3317*c217d954SCole Faust void * user_data = NULL)
3318*c217d954SCole Faust {
3319*c217d954SCole Faust return detail::errHandler(
3320*c217d954SCole Faust ::clSetEventCallback(
3321*c217d954SCole Faust object_,
3322*c217d954SCole Faust type,
3323*c217d954SCole Faust pfn_notify,
3324*c217d954SCole Faust user_data),
3325*c217d954SCole Faust __SET_EVENT_CALLBACK_ERR);
3326*c217d954SCole Faust }
3327*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3328*c217d954SCole Faust
3329*c217d954SCole Faust /*! \brief Blocks the calling thread until every event specified is complete.
3330*c217d954SCole Faust *
3331*c217d954SCole Faust * Wraps clWaitForEvents().
3332*c217d954SCole Faust */
3333*c217d954SCole Faust static cl_int
waitForEvents(const vector<Event> & events)3334*c217d954SCole Faust waitForEvents(const vector<Event>& events)
3335*c217d954SCole Faust {
3336*c217d954SCole Faust return detail::errHandler(
3337*c217d954SCole Faust ::clWaitForEvents(
3338*c217d954SCole Faust (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3339*c217d954SCole Faust __WAIT_FOR_EVENTS_ERR);
3340*c217d954SCole Faust }
3341*c217d954SCole Faust };
3342*c217d954SCole Faust
3343*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3344*c217d954SCole Faust /*! \brief Class interface for user events (a subset of cl_event's).
3345*c217d954SCole Faust *
3346*c217d954SCole Faust * See Event for details about copy semantics, etc.
3347*c217d954SCole Faust */
3348*c217d954SCole Faust class UserEvent : public Event
3349*c217d954SCole Faust {
3350*c217d954SCole Faust public:
3351*c217d954SCole Faust /*! \brief Constructs a user event on a given context.
3352*c217d954SCole Faust *
3353*c217d954SCole Faust * Wraps clCreateUserEvent().
3354*c217d954SCole Faust */
UserEvent(const Context & context,cl_int * err=NULL)3355*c217d954SCole Faust UserEvent(
3356*c217d954SCole Faust const Context& context,
3357*c217d954SCole Faust cl_int * err = NULL)
3358*c217d954SCole Faust {
3359*c217d954SCole Faust cl_int error;
3360*c217d954SCole Faust object_ = ::clCreateUserEvent(
3361*c217d954SCole Faust context(),
3362*c217d954SCole Faust &error);
3363*c217d954SCole Faust
3364*c217d954SCole Faust detail::errHandler(error, __CREATE_USER_EVENT_ERR);
3365*c217d954SCole Faust if (err != NULL) {
3366*c217d954SCole Faust *err = error;
3367*c217d954SCole Faust }
3368*c217d954SCole Faust }
3369*c217d954SCole Faust
3370*c217d954SCole Faust //! \brief Default constructor - initializes to NULL.
UserEvent()3371*c217d954SCole Faust UserEvent() : Event() { }
3372*c217d954SCole Faust
3373*c217d954SCole Faust /*! \brief Sets the execution status of a user event object.
3374*c217d954SCole Faust *
3375*c217d954SCole Faust * Wraps clSetUserEventStatus().
3376*c217d954SCole Faust */
setStatus(cl_int status)3377*c217d954SCole Faust cl_int setStatus(cl_int status)
3378*c217d954SCole Faust {
3379*c217d954SCole Faust return detail::errHandler(
3380*c217d954SCole Faust ::clSetUserEventStatus(object_,status),
3381*c217d954SCole Faust __SET_USER_EVENT_STATUS_ERR);
3382*c217d954SCole Faust }
3383*c217d954SCole Faust };
3384*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3385*c217d954SCole Faust
3386*c217d954SCole Faust /*! \brief Blocks the calling thread until every event specified is complete.
3387*c217d954SCole Faust *
3388*c217d954SCole Faust * Wraps clWaitForEvents().
3389*c217d954SCole Faust */
3390*c217d954SCole Faust inline static cl_int
WaitForEvents(const vector<Event> & events)3391*c217d954SCole Faust WaitForEvents(const vector<Event>& events)
3392*c217d954SCole Faust {
3393*c217d954SCole Faust return detail::errHandler(
3394*c217d954SCole Faust ::clWaitForEvents(
3395*c217d954SCole Faust (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL),
3396*c217d954SCole Faust __WAIT_FOR_EVENTS_ERR);
3397*c217d954SCole Faust }
3398*c217d954SCole Faust
3399*c217d954SCole Faust /*! \brief Class interface for cl_mem.
3400*c217d954SCole Faust *
3401*c217d954SCole Faust * \note Copies of these objects are shallow, meaning that the copy will refer
3402*c217d954SCole Faust * to the same underlying cl_mem as the original. For details, see
3403*c217d954SCole Faust * clRetainMemObject() and clReleaseMemObject().
3404*c217d954SCole Faust *
3405*c217d954SCole Faust * \see cl_mem
3406*c217d954SCole Faust */
3407*c217d954SCole Faust class Memory : public detail::Wrapper<cl_mem>
3408*c217d954SCole Faust {
3409*c217d954SCole Faust public:
3410*c217d954SCole Faust //! \brief Default constructor - initializes to NULL.
Memory()3411*c217d954SCole Faust Memory() : detail::Wrapper<cl_type>() { }
3412*c217d954SCole Faust
3413*c217d954SCole Faust /*! \brief Constructor from cl_mem - takes ownership.
3414*c217d954SCole Faust *
3415*c217d954SCole Faust * Optionally transfer ownership of a refcount on the cl_mem
3416*c217d954SCole Faust * into the new Memory object.
3417*c217d954SCole Faust *
3418*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
3419*c217d954SCole Faust * Defaults to false to maintain compatibility with
3420*c217d954SCole Faust * earlier versions.
3421*c217d954SCole Faust *
3422*c217d954SCole Faust * See Memory for further details.
3423*c217d954SCole Faust */
Memory(const cl_mem & memory,bool retainObject)3424*c217d954SCole Faust explicit Memory(const cl_mem& memory, bool retainObject) :
3425*c217d954SCole Faust detail::Wrapper<cl_type>(memory, retainObject) { }
3426*c217d954SCole Faust
3427*c217d954SCole Faust /*! \brief Assignment operator from cl_mem - takes ownership.
3428*c217d954SCole Faust *
3429*c217d954SCole Faust * This effectively transfers ownership of a refcount on the rhs and calls
3430*c217d954SCole Faust * clReleaseMemObject() on the value previously held by this instance.
3431*c217d954SCole Faust */
operator =(const cl_mem & rhs)3432*c217d954SCole Faust Memory& operator = (const cl_mem& rhs)
3433*c217d954SCole Faust {
3434*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(rhs);
3435*c217d954SCole Faust return *this;
3436*c217d954SCole Faust }
3437*c217d954SCole Faust
3438*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
3439*c217d954SCole Faust * Required for MSVC.
3440*c217d954SCole Faust */
Memory(const Memory & mem)3441*c217d954SCole Faust Memory(const Memory& mem) : detail::Wrapper<cl_type>(mem) {}
3442*c217d954SCole Faust
3443*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
3444*c217d954SCole Faust * Required for MSVC.
3445*c217d954SCole Faust */
operator =(const Memory & mem)3446*c217d954SCole Faust Memory& operator = (const Memory &mem)
3447*c217d954SCole Faust {
3448*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(mem);
3449*c217d954SCole Faust return *this;
3450*c217d954SCole Faust }
3451*c217d954SCole Faust
3452*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
3453*c217d954SCole Faust * Required for MSVC.
3454*c217d954SCole Faust */
Memory(Memory && mem)3455*c217d954SCole Faust Memory(Memory&& mem) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(mem)) {}
3456*c217d954SCole Faust
3457*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
3458*c217d954SCole Faust * Required for MSVC.
3459*c217d954SCole Faust */
operator =(Memory && mem)3460*c217d954SCole Faust Memory& operator = (Memory &&mem)
3461*c217d954SCole Faust {
3462*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(std::move(mem));
3463*c217d954SCole Faust return *this;
3464*c217d954SCole Faust }
3465*c217d954SCole Faust
3466*c217d954SCole Faust
3467*c217d954SCole Faust //! \brief Wrapper for clGetMemObjectInfo().
3468*c217d954SCole Faust template <typename T>
getInfo(cl_mem_info name,T * param) const3469*c217d954SCole Faust cl_int getInfo(cl_mem_info name, T* param) const
3470*c217d954SCole Faust {
3471*c217d954SCole Faust return detail::errHandler(
3472*c217d954SCole Faust detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
3473*c217d954SCole Faust __GET_MEM_OBJECT_INFO_ERR);
3474*c217d954SCole Faust }
3475*c217d954SCole Faust
3476*c217d954SCole Faust //! \brief Wrapper for clGetMemObjectInfo() that returns by value.
3477*c217d954SCole Faust template <cl_mem_info name> typename
3478*c217d954SCole Faust detail::param_traits<detail::cl_mem_info, name>::param_type
getInfo(cl_int * err=NULL) const3479*c217d954SCole Faust getInfo(cl_int* err = NULL) const
3480*c217d954SCole Faust {
3481*c217d954SCole Faust typename detail::param_traits<
3482*c217d954SCole Faust detail::cl_mem_info, name>::param_type param;
3483*c217d954SCole Faust cl_int result = getInfo(name, ¶m);
3484*c217d954SCole Faust if (err != NULL) {
3485*c217d954SCole Faust *err = result;
3486*c217d954SCole Faust }
3487*c217d954SCole Faust return param;
3488*c217d954SCole Faust }
3489*c217d954SCole Faust
3490*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 110
3491*c217d954SCole Faust /*! \brief Registers a callback function to be called when the memory object
3492*c217d954SCole Faust * is no longer needed.
3493*c217d954SCole Faust *
3494*c217d954SCole Faust * Wraps clSetMemObjectDestructorCallback().
3495*c217d954SCole Faust *
3496*c217d954SCole Faust * Repeated calls to this function, for a given cl_mem value, will append
3497*c217d954SCole Faust * to the list of functions called (in reverse order) when memory object's
3498*c217d954SCole Faust * resources are freed and the memory object is deleted.
3499*c217d954SCole Faust *
3500*c217d954SCole Faust * \note
3501*c217d954SCole Faust * The registered callbacks are associated with the underlying cl_mem
3502*c217d954SCole Faust * value - not the Memory class instance.
3503*c217d954SCole Faust */
setDestructorCallback(void (CL_CALLBACK * pfn_notify)(cl_mem,void *),void * user_data=NULL)3504*c217d954SCole Faust cl_int setDestructorCallback(
3505*c217d954SCole Faust void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
3506*c217d954SCole Faust void * user_data = NULL)
3507*c217d954SCole Faust {
3508*c217d954SCole Faust return detail::errHandler(
3509*c217d954SCole Faust ::clSetMemObjectDestructorCallback(
3510*c217d954SCole Faust object_,
3511*c217d954SCole Faust pfn_notify,
3512*c217d954SCole Faust user_data),
3513*c217d954SCole Faust __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
3514*c217d954SCole Faust }
3515*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
3516*c217d954SCole Faust
3517*c217d954SCole Faust };
3518*c217d954SCole Faust
3519*c217d954SCole Faust // Pre-declare copy functions
3520*c217d954SCole Faust class Buffer;
3521*c217d954SCole Faust template< typename IteratorType >
3522*c217d954SCole Faust cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3523*c217d954SCole Faust template< typename IteratorType >
3524*c217d954SCole Faust cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3525*c217d954SCole Faust template< typename IteratorType >
3526*c217d954SCole Faust cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
3527*c217d954SCole Faust template< typename IteratorType >
3528*c217d954SCole Faust cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
3529*c217d954SCole Faust
3530*c217d954SCole Faust
3531*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
3532*c217d954SCole Faust namespace detail
3533*c217d954SCole Faust {
3534*c217d954SCole Faust class SVMTraitNull
3535*c217d954SCole Faust {
3536*c217d954SCole Faust public:
getSVMMemFlags()3537*c217d954SCole Faust static cl_svm_mem_flags getSVMMemFlags()
3538*c217d954SCole Faust {
3539*c217d954SCole Faust return 0;
3540*c217d954SCole Faust }
3541*c217d954SCole Faust };
3542*c217d954SCole Faust } // namespace detail
3543*c217d954SCole Faust
3544*c217d954SCole Faust template<class Trait = detail::SVMTraitNull>
3545*c217d954SCole Faust class SVMTraitReadWrite
3546*c217d954SCole Faust {
3547*c217d954SCole Faust public:
getSVMMemFlags()3548*c217d954SCole Faust static cl_svm_mem_flags getSVMMemFlags()
3549*c217d954SCole Faust {
3550*c217d954SCole Faust return CL_MEM_READ_WRITE |
3551*c217d954SCole Faust Trait::getSVMMemFlags();
3552*c217d954SCole Faust }
3553*c217d954SCole Faust };
3554*c217d954SCole Faust
3555*c217d954SCole Faust template<class Trait = detail::SVMTraitNull>
3556*c217d954SCole Faust class SVMTraitReadOnly
3557*c217d954SCole Faust {
3558*c217d954SCole Faust public:
getSVMMemFlags()3559*c217d954SCole Faust static cl_svm_mem_flags getSVMMemFlags()
3560*c217d954SCole Faust {
3561*c217d954SCole Faust return CL_MEM_READ_ONLY |
3562*c217d954SCole Faust Trait::getSVMMemFlags();
3563*c217d954SCole Faust }
3564*c217d954SCole Faust };
3565*c217d954SCole Faust
3566*c217d954SCole Faust template<class Trait = detail::SVMTraitNull>
3567*c217d954SCole Faust class SVMTraitWriteOnly
3568*c217d954SCole Faust {
3569*c217d954SCole Faust public:
getSVMMemFlags()3570*c217d954SCole Faust static cl_svm_mem_flags getSVMMemFlags()
3571*c217d954SCole Faust {
3572*c217d954SCole Faust return CL_MEM_WRITE_ONLY |
3573*c217d954SCole Faust Trait::getSVMMemFlags();
3574*c217d954SCole Faust }
3575*c217d954SCole Faust };
3576*c217d954SCole Faust
3577*c217d954SCole Faust template<class Trait = SVMTraitReadWrite<>>
3578*c217d954SCole Faust class SVMTraitCoarse
3579*c217d954SCole Faust {
3580*c217d954SCole Faust public:
getSVMMemFlags()3581*c217d954SCole Faust static cl_svm_mem_flags getSVMMemFlags()
3582*c217d954SCole Faust {
3583*c217d954SCole Faust return Trait::getSVMMemFlags();
3584*c217d954SCole Faust }
3585*c217d954SCole Faust };
3586*c217d954SCole Faust
3587*c217d954SCole Faust template<class Trait = SVMTraitReadWrite<>>
3588*c217d954SCole Faust class SVMTraitFine
3589*c217d954SCole Faust {
3590*c217d954SCole Faust public:
getSVMMemFlags()3591*c217d954SCole Faust static cl_svm_mem_flags getSVMMemFlags()
3592*c217d954SCole Faust {
3593*c217d954SCole Faust return CL_MEM_SVM_FINE_GRAIN_BUFFER |
3594*c217d954SCole Faust Trait::getSVMMemFlags();
3595*c217d954SCole Faust }
3596*c217d954SCole Faust };
3597*c217d954SCole Faust
3598*c217d954SCole Faust template<class Trait = SVMTraitReadWrite<>>
3599*c217d954SCole Faust class SVMTraitAtomic
3600*c217d954SCole Faust {
3601*c217d954SCole Faust public:
getSVMMemFlags()3602*c217d954SCole Faust static cl_svm_mem_flags getSVMMemFlags()
3603*c217d954SCole Faust {
3604*c217d954SCole Faust return
3605*c217d954SCole Faust CL_MEM_SVM_FINE_GRAIN_BUFFER |
3606*c217d954SCole Faust CL_MEM_SVM_ATOMICS |
3607*c217d954SCole Faust Trait::getSVMMemFlags();
3608*c217d954SCole Faust }
3609*c217d954SCole Faust };
3610*c217d954SCole Faust
3611*c217d954SCole Faust // Pre-declare SVM map function
3612*c217d954SCole Faust template<typename T>
3613*c217d954SCole Faust inline cl_int enqueueMapSVM(
3614*c217d954SCole Faust T* ptr,
3615*c217d954SCole Faust cl_bool blocking,
3616*c217d954SCole Faust cl_map_flags flags,
3617*c217d954SCole Faust size_type size,
3618*c217d954SCole Faust const vector<Event>* events = NULL,
3619*c217d954SCole Faust Event* event = NULL);
3620*c217d954SCole Faust
3621*c217d954SCole Faust /**
3622*c217d954SCole Faust * STL-like allocator class for managing SVM objects provided for convenience.
3623*c217d954SCole Faust *
3624*c217d954SCole Faust * Note that while this behaves like an allocator for the purposes of constructing vectors and similar objects,
3625*c217d954SCole Faust * care must be taken when using with smart pointers.
3626*c217d954SCole Faust * The allocator should not be used to construct a unique_ptr if we are using coarse-grained SVM mode because
3627*c217d954SCole Faust * the coarse-grained management behaviour would behave incorrectly with respect to reference counting.
3628*c217d954SCole Faust *
3629*c217d954SCole Faust * Instead the allocator embeds a Deleter which may be used with unique_ptr and is used
3630*c217d954SCole Faust * with the allocate_shared and allocate_ptr supplied operations.
3631*c217d954SCole Faust */
3632*c217d954SCole Faust template<typename T, class SVMTrait>
3633*c217d954SCole Faust class SVMAllocator {
3634*c217d954SCole Faust private:
3635*c217d954SCole Faust Context context_;
3636*c217d954SCole Faust
3637*c217d954SCole Faust public:
3638*c217d954SCole Faust typedef T value_type;
3639*c217d954SCole Faust typedef value_type* pointer;
3640*c217d954SCole Faust typedef const value_type* const_pointer;
3641*c217d954SCole Faust typedef value_type& reference;
3642*c217d954SCole Faust typedef const value_type& const_reference;
3643*c217d954SCole Faust typedef std::size_t size_type;
3644*c217d954SCole Faust typedef std::ptrdiff_t difference_type;
3645*c217d954SCole Faust
3646*c217d954SCole Faust template<typename U>
3647*c217d954SCole Faust struct rebind
3648*c217d954SCole Faust {
3649*c217d954SCole Faust typedef SVMAllocator<U, SVMTrait> other;
3650*c217d954SCole Faust };
3651*c217d954SCole Faust
3652*c217d954SCole Faust template<typename U, typename V>
3653*c217d954SCole Faust friend class SVMAllocator;
3654*c217d954SCole Faust
SVMAllocator()3655*c217d954SCole Faust SVMAllocator() :
3656*c217d954SCole Faust context_(Context::getDefault())
3657*c217d954SCole Faust {
3658*c217d954SCole Faust }
3659*c217d954SCole Faust
SVMAllocator(cl::Context context)3660*c217d954SCole Faust explicit SVMAllocator(cl::Context context) :
3661*c217d954SCole Faust context_(context)
3662*c217d954SCole Faust {
3663*c217d954SCole Faust }
3664*c217d954SCole Faust
3665*c217d954SCole Faust
SVMAllocator(const SVMAllocator & other)3666*c217d954SCole Faust SVMAllocator(const SVMAllocator &other) :
3667*c217d954SCole Faust context_(other.context_)
3668*c217d954SCole Faust {
3669*c217d954SCole Faust }
3670*c217d954SCole Faust
3671*c217d954SCole Faust template<typename U>
SVMAllocator(const SVMAllocator<U,SVMTrait> & other)3672*c217d954SCole Faust SVMAllocator(const SVMAllocator<U, SVMTrait> &other) :
3673*c217d954SCole Faust context_(other.context_)
3674*c217d954SCole Faust {
3675*c217d954SCole Faust }
3676*c217d954SCole Faust
~SVMAllocator()3677*c217d954SCole Faust ~SVMAllocator()
3678*c217d954SCole Faust {
3679*c217d954SCole Faust }
3680*c217d954SCole Faust
address(reference r)3681*c217d954SCole Faust pointer address(reference r) CL_HPP_NOEXCEPT_
3682*c217d954SCole Faust {
3683*c217d954SCole Faust return std::addressof(r);
3684*c217d954SCole Faust }
3685*c217d954SCole Faust
address(const_reference r)3686*c217d954SCole Faust const_pointer address(const_reference r) CL_HPP_NOEXCEPT_
3687*c217d954SCole Faust {
3688*c217d954SCole Faust return std::addressof(r);
3689*c217d954SCole Faust }
3690*c217d954SCole Faust
3691*c217d954SCole Faust /**
3692*c217d954SCole Faust * Allocate an SVM pointer.
3693*c217d954SCole Faust *
3694*c217d954SCole Faust * If the allocator is coarse-grained, this will take ownership to allow
3695*c217d954SCole Faust * containers to correctly construct data in place.
3696*c217d954SCole Faust */
allocate(size_type size,typename cl::SVMAllocator<void,SVMTrait>::const_pointer=0)3697*c217d954SCole Faust pointer allocate(
3698*c217d954SCole Faust size_type size,
3699*c217d954SCole Faust typename cl::SVMAllocator<void, SVMTrait>::const_pointer = 0)
3700*c217d954SCole Faust {
3701*c217d954SCole Faust // Allocate memory with default alignment matching the size of the type
3702*c217d954SCole Faust void* voidPointer =
3703*c217d954SCole Faust clSVMAlloc(
3704*c217d954SCole Faust context_(),
3705*c217d954SCole Faust SVMTrait::getSVMMemFlags(),
3706*c217d954SCole Faust size*sizeof(T),
3707*c217d954SCole Faust 0);
3708*c217d954SCole Faust pointer retValue = reinterpret_cast<pointer>(
3709*c217d954SCole Faust voidPointer);
3710*c217d954SCole Faust #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3711*c217d954SCole Faust if (!retValue) {
3712*c217d954SCole Faust std::bad_alloc excep;
3713*c217d954SCole Faust throw excep;
3714*c217d954SCole Faust }
3715*c217d954SCole Faust #endif // #if defined(CL_HPP_ENABLE_EXCEPTIONS)
3716*c217d954SCole Faust
3717*c217d954SCole Faust // If allocation was coarse-grained then map it
3718*c217d954SCole Faust if (!(SVMTrait::getSVMMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) {
3719*c217d954SCole Faust cl_int err = enqueueMapSVM(retValue, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, size*sizeof(T));
3720*c217d954SCole Faust if (err != CL_SUCCESS) {
3721*c217d954SCole Faust std::bad_alloc excep;
3722*c217d954SCole Faust throw excep;
3723*c217d954SCole Faust }
3724*c217d954SCole Faust }
3725*c217d954SCole Faust
3726*c217d954SCole Faust // If exceptions disabled, return null pointer from allocator
3727*c217d954SCole Faust return retValue;
3728*c217d954SCole Faust }
3729*c217d954SCole Faust
deallocate(pointer p,size_type)3730*c217d954SCole Faust void deallocate(pointer p, size_type)
3731*c217d954SCole Faust {
3732*c217d954SCole Faust clSVMFree(context_(), p);
3733*c217d954SCole Faust }
3734*c217d954SCole Faust
3735*c217d954SCole Faust /**
3736*c217d954SCole Faust * Return the maximum possible allocation size.
3737*c217d954SCole Faust * This is the minimum of the maximum sizes of all devices in the context.
3738*c217d954SCole Faust */
max_size() const3739*c217d954SCole Faust size_type max_size() const CL_HPP_NOEXCEPT_
3740*c217d954SCole Faust {
3741*c217d954SCole Faust size_type maxSize = std::numeric_limits<size_type>::max() / sizeof(T);
3742*c217d954SCole Faust
3743*c217d954SCole Faust for (const Device &d : context_.getInfo<CL_CONTEXT_DEVICES>()) {
3744*c217d954SCole Faust maxSize = std::min(
3745*c217d954SCole Faust maxSize,
3746*c217d954SCole Faust static_cast<size_type>(d.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>()));
3747*c217d954SCole Faust }
3748*c217d954SCole Faust
3749*c217d954SCole Faust return maxSize;
3750*c217d954SCole Faust }
3751*c217d954SCole Faust
3752*c217d954SCole Faust template< class U, class... Args >
construct(U * p,Args &&...args)3753*c217d954SCole Faust void construct(U* p, Args&&... args)
3754*c217d954SCole Faust {
3755*c217d954SCole Faust new(p)T(args...);
3756*c217d954SCole Faust }
3757*c217d954SCole Faust
3758*c217d954SCole Faust template< class U >
destroy(U * p)3759*c217d954SCole Faust void destroy(U* p)
3760*c217d954SCole Faust {
3761*c217d954SCole Faust p->~U();
3762*c217d954SCole Faust }
3763*c217d954SCole Faust
3764*c217d954SCole Faust /**
3765*c217d954SCole Faust * Returns true if the contexts match.
3766*c217d954SCole Faust */
operator ==(SVMAllocator const & rhs)3767*c217d954SCole Faust inline bool operator==(SVMAllocator const& rhs)
3768*c217d954SCole Faust {
3769*c217d954SCole Faust return (context_==rhs.context_);
3770*c217d954SCole Faust }
3771*c217d954SCole Faust
operator !=(SVMAllocator const & a)3772*c217d954SCole Faust inline bool operator!=(SVMAllocator const& a)
3773*c217d954SCole Faust {
3774*c217d954SCole Faust return !operator==(a);
3775*c217d954SCole Faust }
3776*c217d954SCole Faust }; // class SVMAllocator return cl::pointer<T>(tmp, detail::Deleter<T, Alloc>{alloc, copies});
3777*c217d954SCole Faust
3778*c217d954SCole Faust
3779*c217d954SCole Faust template<class SVMTrait>
3780*c217d954SCole Faust class SVMAllocator<void, SVMTrait> {
3781*c217d954SCole Faust public:
3782*c217d954SCole Faust typedef void value_type;
3783*c217d954SCole Faust typedef value_type* pointer;
3784*c217d954SCole Faust typedef const value_type* const_pointer;
3785*c217d954SCole Faust
3786*c217d954SCole Faust template<typename U>
3787*c217d954SCole Faust struct rebind
3788*c217d954SCole Faust {
3789*c217d954SCole Faust typedef SVMAllocator<U, SVMTrait> other;
3790*c217d954SCole Faust };
3791*c217d954SCole Faust
3792*c217d954SCole Faust template<typename U, typename V>
3793*c217d954SCole Faust friend class SVMAllocator;
3794*c217d954SCole Faust };
3795*c217d954SCole Faust
3796*c217d954SCole Faust #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3797*c217d954SCole Faust namespace detail
3798*c217d954SCole Faust {
3799*c217d954SCole Faust template<class Alloc>
3800*c217d954SCole Faust class Deleter {
3801*c217d954SCole Faust private:
3802*c217d954SCole Faust Alloc alloc_;
3803*c217d954SCole Faust size_type copies_;
3804*c217d954SCole Faust
3805*c217d954SCole Faust public:
3806*c217d954SCole Faust typedef typename std::allocator_traits<Alloc>::pointer pointer;
3807*c217d954SCole Faust
Deleter(const Alloc & alloc,size_type copies)3808*c217d954SCole Faust Deleter(const Alloc &alloc, size_type copies) : alloc_{ alloc }, copies_{ copies }
3809*c217d954SCole Faust {
3810*c217d954SCole Faust }
3811*c217d954SCole Faust
operator ()(pointer ptr) const3812*c217d954SCole Faust void operator()(pointer ptr) const {
3813*c217d954SCole Faust Alloc tmpAlloc{ alloc_ };
3814*c217d954SCole Faust std::allocator_traits<Alloc>::destroy(tmpAlloc, std::addressof(*ptr));
3815*c217d954SCole Faust std::allocator_traits<Alloc>::deallocate(tmpAlloc, ptr, copies_);
3816*c217d954SCole Faust }
3817*c217d954SCole Faust };
3818*c217d954SCole Faust } // namespace detail
3819*c217d954SCole Faust
3820*c217d954SCole Faust /**
3821*c217d954SCole Faust * Allocation operation compatible with std::allocate_ptr.
3822*c217d954SCole Faust * Creates a unique_ptr<T> by default.
3823*c217d954SCole Faust * This requirement is to ensure that the control block is not
3824*c217d954SCole Faust * allocated in memory inaccessible to the host.
3825*c217d954SCole Faust */
3826*c217d954SCole Faust template <class T, class Alloc, class... Args>
allocate_pointer(const Alloc & alloc_,Args &&...args)3827*c217d954SCole Faust cl::pointer<T, detail::Deleter<Alloc>> allocate_pointer(const Alloc &alloc_, Args&&... args)
3828*c217d954SCole Faust {
3829*c217d954SCole Faust Alloc alloc(alloc_);
3830*c217d954SCole Faust static const size_type copies = 1;
3831*c217d954SCole Faust
3832*c217d954SCole Faust // Ensure that creation of the management block and the
3833*c217d954SCole Faust // object are dealt with separately such that we only provide a deleter
3834*c217d954SCole Faust
3835*c217d954SCole Faust T* tmp = std::allocator_traits<Alloc>::allocate(alloc, copies);
3836*c217d954SCole Faust if (!tmp) {
3837*c217d954SCole Faust std::bad_alloc excep;
3838*c217d954SCole Faust throw excep;
3839*c217d954SCole Faust }
3840*c217d954SCole Faust try {
3841*c217d954SCole Faust std::allocator_traits<Alloc>::construct(
3842*c217d954SCole Faust alloc,
3843*c217d954SCole Faust std::addressof(*tmp),
3844*c217d954SCole Faust std::forward<Args>(args)...);
3845*c217d954SCole Faust
3846*c217d954SCole Faust return cl::pointer<T, detail::Deleter<Alloc>>(tmp, detail::Deleter<Alloc>{alloc, copies});
3847*c217d954SCole Faust }
3848*c217d954SCole Faust catch (std::bad_alloc& b)
3849*c217d954SCole Faust {
3850*c217d954SCole Faust std::allocator_traits<Alloc>::deallocate(alloc, tmp, copies);
3851*c217d954SCole Faust throw;
3852*c217d954SCole Faust }
3853*c217d954SCole Faust }
3854*c217d954SCole Faust
3855*c217d954SCole Faust template< class T, class SVMTrait, class... Args >
allocate_svm(Args...args)3856*c217d954SCole Faust cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(Args... args)
3857*c217d954SCole Faust {
3858*c217d954SCole Faust SVMAllocator<T, SVMTrait> alloc;
3859*c217d954SCole Faust return cl::allocate_pointer<T>(alloc, args...);
3860*c217d954SCole Faust }
3861*c217d954SCole Faust
3862*c217d954SCole Faust template< class T, class SVMTrait, class... Args >
allocate_svm(const cl::Context & c,Args...args)3863*c217d954SCole Faust cl::pointer<T, detail::Deleter<SVMAllocator<T, SVMTrait>>> allocate_svm(const cl::Context &c, Args... args)
3864*c217d954SCole Faust {
3865*c217d954SCole Faust SVMAllocator<T, SVMTrait> alloc(c);
3866*c217d954SCole Faust return cl::allocate_pointer<T>(alloc, args...);
3867*c217d954SCole Faust }
3868*c217d954SCole Faust #endif // #if !defined(CL_HPP_NO_STD_UNIQUE_PTR)
3869*c217d954SCole Faust
3870*c217d954SCole Faust /*! \brief Vector alias to simplify contruction of coarse-grained SVM containers.
3871*c217d954SCole Faust *
3872*c217d954SCole Faust */
3873*c217d954SCole Faust template < class T >
3874*c217d954SCole Faust using coarse_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitCoarse<>>>;
3875*c217d954SCole Faust
3876*c217d954SCole Faust /*! \brief Vector alias to simplify contruction of fine-grained SVM containers.
3877*c217d954SCole Faust *
3878*c217d954SCole Faust */
3879*c217d954SCole Faust template < class T >
3880*c217d954SCole Faust using fine_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitFine<>>>;
3881*c217d954SCole Faust
3882*c217d954SCole Faust /*! \brief Vector alias to simplify contruction of fine-grained SVM containers that support platform atomics.
3883*c217d954SCole Faust *
3884*c217d954SCole Faust */
3885*c217d954SCole Faust template < class T >
3886*c217d954SCole Faust using atomic_svm_vector = vector<T, cl::SVMAllocator<int, cl::SVMTraitAtomic<>>>;
3887*c217d954SCole Faust
3888*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
3889*c217d954SCole Faust
3890*c217d954SCole Faust
3891*c217d954SCole Faust /*! \brief Class interface for Buffer Memory Objects.
3892*c217d954SCole Faust *
3893*c217d954SCole Faust * See Memory for details about copy semantics, etc.
3894*c217d954SCole Faust *
3895*c217d954SCole Faust * \see Memory
3896*c217d954SCole Faust */
3897*c217d954SCole Faust class Buffer : public Memory
3898*c217d954SCole Faust {
3899*c217d954SCole Faust public:
3900*c217d954SCole Faust
3901*c217d954SCole Faust /*! \brief Constructs a Buffer in a specified context.
3902*c217d954SCole Faust *
3903*c217d954SCole Faust * Wraps clCreateBuffer().
3904*c217d954SCole Faust *
3905*c217d954SCole Faust * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
3906*c217d954SCole Faust * specified. Note alignment & exclusivity requirements.
3907*c217d954SCole Faust */
Buffer(const Context & context,cl_mem_flags flags,size_type size,void * host_ptr=NULL,cl_int * err=NULL)3908*c217d954SCole Faust Buffer(
3909*c217d954SCole Faust const Context& context,
3910*c217d954SCole Faust cl_mem_flags flags,
3911*c217d954SCole Faust size_type size,
3912*c217d954SCole Faust void* host_ptr = NULL,
3913*c217d954SCole Faust cl_int* err = NULL)
3914*c217d954SCole Faust {
3915*c217d954SCole Faust cl_int error;
3916*c217d954SCole Faust object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3917*c217d954SCole Faust
3918*c217d954SCole Faust detail::errHandler(error, __CREATE_BUFFER_ERR);
3919*c217d954SCole Faust if (err != NULL) {
3920*c217d954SCole Faust *err = error;
3921*c217d954SCole Faust }
3922*c217d954SCole Faust }
3923*c217d954SCole Faust
3924*c217d954SCole Faust /*! \brief Constructs a Buffer in the default context.
3925*c217d954SCole Faust *
3926*c217d954SCole Faust * Wraps clCreateBuffer().
3927*c217d954SCole Faust *
3928*c217d954SCole Faust * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
3929*c217d954SCole Faust * specified. Note alignment & exclusivity requirements.
3930*c217d954SCole Faust *
3931*c217d954SCole Faust * \see Context::getDefault()
3932*c217d954SCole Faust */
Buffer(cl_mem_flags flags,size_type size,void * host_ptr=NULL,cl_int * err=NULL)3933*c217d954SCole Faust Buffer(
3934*c217d954SCole Faust cl_mem_flags flags,
3935*c217d954SCole Faust size_type size,
3936*c217d954SCole Faust void* host_ptr = NULL,
3937*c217d954SCole Faust cl_int* err = NULL)
3938*c217d954SCole Faust {
3939*c217d954SCole Faust cl_int error;
3940*c217d954SCole Faust
3941*c217d954SCole Faust Context context = Context::getDefault(err);
3942*c217d954SCole Faust
3943*c217d954SCole Faust object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
3944*c217d954SCole Faust
3945*c217d954SCole Faust detail::errHandler(error, __CREATE_BUFFER_ERR);
3946*c217d954SCole Faust if (err != NULL) {
3947*c217d954SCole Faust *err = error;
3948*c217d954SCole Faust }
3949*c217d954SCole Faust }
3950*c217d954SCole Faust
3951*c217d954SCole Faust /*!
3952*c217d954SCole Faust * \brief Construct a Buffer from a host container via iterators.
3953*c217d954SCole Faust * IteratorType must be random access.
3954*c217d954SCole Faust * If useHostPtr is specified iterators must represent contiguous data.
3955*c217d954SCole Faust */
3956*c217d954SCole Faust template< typename IteratorType >
Buffer(IteratorType startIterator,IteratorType endIterator,bool readOnly,bool useHostPtr=false,cl_int * err=NULL)3957*c217d954SCole Faust Buffer(
3958*c217d954SCole Faust IteratorType startIterator,
3959*c217d954SCole Faust IteratorType endIterator,
3960*c217d954SCole Faust bool readOnly,
3961*c217d954SCole Faust bool useHostPtr = false,
3962*c217d954SCole Faust cl_int* err = NULL)
3963*c217d954SCole Faust {
3964*c217d954SCole Faust typedef typename std::iterator_traits<IteratorType>::value_type DataType;
3965*c217d954SCole Faust cl_int error;
3966*c217d954SCole Faust
3967*c217d954SCole Faust cl_mem_flags flags = 0;
3968*c217d954SCole Faust if( readOnly ) {
3969*c217d954SCole Faust flags |= CL_MEM_READ_ONLY;
3970*c217d954SCole Faust }
3971*c217d954SCole Faust else {
3972*c217d954SCole Faust flags |= CL_MEM_READ_WRITE;
3973*c217d954SCole Faust }
3974*c217d954SCole Faust if( useHostPtr ) {
3975*c217d954SCole Faust flags |= CL_MEM_USE_HOST_PTR;
3976*c217d954SCole Faust }
3977*c217d954SCole Faust
3978*c217d954SCole Faust size_type size = sizeof(DataType)*(endIterator - startIterator);
3979*c217d954SCole Faust
3980*c217d954SCole Faust Context context = Context::getDefault(err);
3981*c217d954SCole Faust
3982*c217d954SCole Faust if( useHostPtr ) {
3983*c217d954SCole Faust object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
3984*c217d954SCole Faust } else {
3985*c217d954SCole Faust object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
3986*c217d954SCole Faust }
3987*c217d954SCole Faust
3988*c217d954SCole Faust detail::errHandler(error, __CREATE_BUFFER_ERR);
3989*c217d954SCole Faust if (err != NULL) {
3990*c217d954SCole Faust *err = error;
3991*c217d954SCole Faust }
3992*c217d954SCole Faust
3993*c217d954SCole Faust if( !useHostPtr ) {
3994*c217d954SCole Faust error = cl::copy(startIterator, endIterator, *this);
3995*c217d954SCole Faust detail::errHandler(error, __CREATE_BUFFER_ERR);
3996*c217d954SCole Faust if (err != NULL) {
3997*c217d954SCole Faust *err = error;
3998*c217d954SCole Faust }
3999*c217d954SCole Faust }
4000*c217d954SCole Faust }
4001*c217d954SCole Faust
4002*c217d954SCole Faust /*!
4003*c217d954SCole Faust * \brief Construct a Buffer from a host container via iterators using a specified context.
4004*c217d954SCole Faust * IteratorType must be random access.
4005*c217d954SCole Faust * If useHostPtr is specified iterators must represent contiguous data.
4006*c217d954SCole Faust */
4007*c217d954SCole Faust template< typename IteratorType >
4008*c217d954SCole Faust Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator,
4009*c217d954SCole Faust bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
4010*c217d954SCole Faust
4011*c217d954SCole Faust /*!
4012*c217d954SCole Faust * \brief Construct a Buffer from a host container via iterators using a specified queue.
4013*c217d954SCole Faust * If useHostPtr is specified iterators must be random access.
4014*c217d954SCole Faust */
4015*c217d954SCole Faust template< typename IteratorType >
4016*c217d954SCole Faust Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator,
4017*c217d954SCole Faust bool readOnly, bool useHostPtr = false, cl_int* err = NULL);
4018*c217d954SCole Faust
4019*c217d954SCole Faust //! \brief Default constructor - initializes to NULL.
Buffer()4020*c217d954SCole Faust Buffer() : Memory() { }
4021*c217d954SCole Faust
4022*c217d954SCole Faust /*! \brief Constructor from cl_mem - takes ownership.
4023*c217d954SCole Faust *
4024*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
4025*c217d954SCole Faust * Defaults to false to maintain compatibility with earlier versions.
4026*c217d954SCole Faust *
4027*c217d954SCole Faust * See Memory for further details.
4028*c217d954SCole Faust */
Buffer(const cl_mem & buffer,bool retainObject=false)4029*c217d954SCole Faust explicit Buffer(const cl_mem& buffer, bool retainObject = false) :
4030*c217d954SCole Faust Memory(buffer, retainObject) { }
4031*c217d954SCole Faust
4032*c217d954SCole Faust /*! \brief Assignment from cl_mem - performs shallow copy.
4033*c217d954SCole Faust *
4034*c217d954SCole Faust * See Memory for further details.
4035*c217d954SCole Faust */
operator =(const cl_mem & rhs)4036*c217d954SCole Faust Buffer& operator = (const cl_mem& rhs)
4037*c217d954SCole Faust {
4038*c217d954SCole Faust Memory::operator=(rhs);
4039*c217d954SCole Faust return *this;
4040*c217d954SCole Faust }
4041*c217d954SCole Faust
4042*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
4043*c217d954SCole Faust * Required for MSVC.
4044*c217d954SCole Faust */
Buffer(const Buffer & buf)4045*c217d954SCole Faust Buffer(const Buffer& buf) : Memory(buf) {}
4046*c217d954SCole Faust
4047*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
4048*c217d954SCole Faust * Required for MSVC.
4049*c217d954SCole Faust */
operator =(const Buffer & buf)4050*c217d954SCole Faust Buffer& operator = (const Buffer &buf)
4051*c217d954SCole Faust {
4052*c217d954SCole Faust Memory::operator=(buf);
4053*c217d954SCole Faust return *this;
4054*c217d954SCole Faust }
4055*c217d954SCole Faust
4056*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
4057*c217d954SCole Faust * Required for MSVC.
4058*c217d954SCole Faust */
Buffer(Buffer && buf)4059*c217d954SCole Faust Buffer(Buffer&& buf) CL_HPP_NOEXCEPT_ : Memory(std::move(buf)) {}
4060*c217d954SCole Faust
4061*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
4062*c217d954SCole Faust * Required for MSVC.
4063*c217d954SCole Faust */
operator =(Buffer && buf)4064*c217d954SCole Faust Buffer& operator = (Buffer &&buf)
4065*c217d954SCole Faust {
4066*c217d954SCole Faust Memory::operator=(std::move(buf));
4067*c217d954SCole Faust return *this;
4068*c217d954SCole Faust }
4069*c217d954SCole Faust
4070*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 110
4071*c217d954SCole Faust /*! \brief Creates a new buffer object from this.
4072*c217d954SCole Faust *
4073*c217d954SCole Faust * Wraps clCreateSubBuffer().
4074*c217d954SCole Faust */
createSubBuffer(cl_mem_flags flags,cl_buffer_create_type buffer_create_type,const void * buffer_create_info,cl_int * err=NULL)4075*c217d954SCole Faust Buffer createSubBuffer(
4076*c217d954SCole Faust cl_mem_flags flags,
4077*c217d954SCole Faust cl_buffer_create_type buffer_create_type,
4078*c217d954SCole Faust const void * buffer_create_info,
4079*c217d954SCole Faust cl_int * err = NULL)
4080*c217d954SCole Faust {
4081*c217d954SCole Faust Buffer result;
4082*c217d954SCole Faust cl_int error;
4083*c217d954SCole Faust result.object_ = ::clCreateSubBuffer(
4084*c217d954SCole Faust object_,
4085*c217d954SCole Faust flags,
4086*c217d954SCole Faust buffer_create_type,
4087*c217d954SCole Faust buffer_create_info,
4088*c217d954SCole Faust &error);
4089*c217d954SCole Faust
4090*c217d954SCole Faust detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
4091*c217d954SCole Faust if (err != NULL) {
4092*c217d954SCole Faust *err = error;
4093*c217d954SCole Faust }
4094*c217d954SCole Faust
4095*c217d954SCole Faust return result;
4096*c217d954SCole Faust }
4097*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
4098*c217d954SCole Faust };
4099*c217d954SCole Faust
4100*c217d954SCole Faust #if defined (CL_HPP_USE_DX_INTEROP)
4101*c217d954SCole Faust /*! \brief Class interface for creating OpenCL buffers from ID3D10Buffer's.
4102*c217d954SCole Faust *
4103*c217d954SCole Faust * This is provided to facilitate interoperability with Direct3D.
4104*c217d954SCole Faust *
4105*c217d954SCole Faust * See Memory for details about copy semantics, etc.
4106*c217d954SCole Faust *
4107*c217d954SCole Faust * \see Memory
4108*c217d954SCole Faust */
4109*c217d954SCole Faust class BufferD3D10 : public Buffer
4110*c217d954SCole Faust {
4111*c217d954SCole Faust public:
4112*c217d954SCole Faust
4113*c217d954SCole Faust
4114*c217d954SCole Faust /*! \brief Constructs a BufferD3D10, in a specified context, from a
4115*c217d954SCole Faust * given ID3D10Buffer.
4116*c217d954SCole Faust *
4117*c217d954SCole Faust * Wraps clCreateFromD3D10BufferKHR().
4118*c217d954SCole Faust */
BufferD3D10(const Context & context,cl_mem_flags flags,ID3D10Buffer * bufobj,cl_int * err=NULL)4119*c217d954SCole Faust BufferD3D10(
4120*c217d954SCole Faust const Context& context,
4121*c217d954SCole Faust cl_mem_flags flags,
4122*c217d954SCole Faust ID3D10Buffer* bufobj,
4123*c217d954SCole Faust cl_int * err = NULL) : pfn_clCreateFromD3D10BufferKHR(nullptr)
4124*c217d954SCole Faust {
4125*c217d954SCole Faust typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
4126*c217d954SCole Faust cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
4127*c217d954SCole Faust cl_int* errcode_ret);
4128*c217d954SCole Faust PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR;
4129*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4130*c217d954SCole Faust vector<cl_context_properties> props = context.getInfo<CL_CONTEXT_PROPERTIES>();
4131*c217d954SCole Faust cl_platform platform = -1;
4132*c217d954SCole Faust for( int i = 0; i < props.size(); ++i ) {
4133*c217d954SCole Faust if( props[i] == CL_CONTEXT_PLATFORM ) {
4134*c217d954SCole Faust platform = props[i+1];
4135*c217d954SCole Faust }
4136*c217d954SCole Faust }
4137*c217d954SCole Faust CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clCreateFromD3D10BufferKHR);
4138*c217d954SCole Faust #elif CL_HPP_TARGET_OPENCL_VERSION >= 110
4139*c217d954SCole Faust CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateFromD3D10BufferKHR);
4140*c217d954SCole Faust #endif
4141*c217d954SCole Faust
4142*c217d954SCole Faust cl_int error;
4143*c217d954SCole Faust object_ = pfn_clCreateFromD3D10BufferKHR(
4144*c217d954SCole Faust context(),
4145*c217d954SCole Faust flags,
4146*c217d954SCole Faust bufobj,
4147*c217d954SCole Faust &error);
4148*c217d954SCole Faust
4149*c217d954SCole Faust detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4150*c217d954SCole Faust if (err != NULL) {
4151*c217d954SCole Faust *err = error;
4152*c217d954SCole Faust }
4153*c217d954SCole Faust }
4154*c217d954SCole Faust
4155*c217d954SCole Faust //! \brief Default constructor - initializes to NULL.
BufferD3D10()4156*c217d954SCole Faust BufferD3D10() : Buffer() { }
4157*c217d954SCole Faust
4158*c217d954SCole Faust /*! \brief Constructor from cl_mem - takes ownership.
4159*c217d954SCole Faust *
4160*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
4161*c217d954SCole Faust * Defaults to false to maintain compatibility with
4162*c217d954SCole Faust * earlier versions.
4163*c217d954SCole Faust * See Memory for further details.
4164*c217d954SCole Faust */
BufferD3D10(const cl_mem & buffer,bool retainObject=false)4165*c217d954SCole Faust explicit BufferD3D10(const cl_mem& buffer, bool retainObject = false) :
4166*c217d954SCole Faust Buffer(buffer, retainObject) { }
4167*c217d954SCole Faust
4168*c217d954SCole Faust /*! \brief Assignment from cl_mem - performs shallow copy.
4169*c217d954SCole Faust *
4170*c217d954SCole Faust * See Memory for further details.
4171*c217d954SCole Faust */
operator =(const cl_mem & rhs)4172*c217d954SCole Faust BufferD3D10& operator = (const cl_mem& rhs)
4173*c217d954SCole Faust {
4174*c217d954SCole Faust Buffer::operator=(rhs);
4175*c217d954SCole Faust return *this;
4176*c217d954SCole Faust }
4177*c217d954SCole Faust
4178*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
4179*c217d954SCole Faust * Required for MSVC.
4180*c217d954SCole Faust */
BufferD3D10(const BufferD3D10 & buf)4181*c217d954SCole Faust BufferD3D10(const BufferD3D10& buf) :
4182*c217d954SCole Faust Buffer(buf) {}
4183*c217d954SCole Faust
4184*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
4185*c217d954SCole Faust * Required for MSVC.
4186*c217d954SCole Faust */
operator =(const BufferD3D10 & buf)4187*c217d954SCole Faust BufferD3D10& operator = (const BufferD3D10 &buf)
4188*c217d954SCole Faust {
4189*c217d954SCole Faust Buffer::operator=(buf);
4190*c217d954SCole Faust return *this;
4191*c217d954SCole Faust }
4192*c217d954SCole Faust
4193*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
4194*c217d954SCole Faust * Required for MSVC.
4195*c217d954SCole Faust */
BufferD3D10(BufferD3D10 && buf)4196*c217d954SCole Faust BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4197*c217d954SCole Faust
4198*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
4199*c217d954SCole Faust * Required for MSVC.
4200*c217d954SCole Faust */
operator =(BufferD3D10 && buf)4201*c217d954SCole Faust BufferD3D10& operator = (BufferD3D10 &&buf)
4202*c217d954SCole Faust {
4203*c217d954SCole Faust Buffer::operator=(std::move(buf));
4204*c217d954SCole Faust return *this;
4205*c217d954SCole Faust }
4206*c217d954SCole Faust };
4207*c217d954SCole Faust #endif
4208*c217d954SCole Faust
4209*c217d954SCole Faust /*! \brief Class interface for GL Buffer Memory Objects.
4210*c217d954SCole Faust *
4211*c217d954SCole Faust * This is provided to facilitate interoperability with OpenGL.
4212*c217d954SCole Faust *
4213*c217d954SCole Faust * See Memory for details about copy semantics, etc.
4214*c217d954SCole Faust *
4215*c217d954SCole Faust * \see Memory
4216*c217d954SCole Faust */
4217*c217d954SCole Faust class BufferGL : public Buffer
4218*c217d954SCole Faust {
4219*c217d954SCole Faust public:
4220*c217d954SCole Faust /*! \brief Constructs a BufferGL in a specified context, from a given
4221*c217d954SCole Faust * GL buffer.
4222*c217d954SCole Faust *
4223*c217d954SCole Faust * Wraps clCreateFromGLBuffer().
4224*c217d954SCole Faust */
BufferGL(const Context & context,cl_mem_flags flags,cl_GLuint bufobj,cl_int * err=NULL)4225*c217d954SCole Faust BufferGL(
4226*c217d954SCole Faust const Context& context,
4227*c217d954SCole Faust cl_mem_flags flags,
4228*c217d954SCole Faust cl_GLuint bufobj,
4229*c217d954SCole Faust cl_int * err = NULL)
4230*c217d954SCole Faust {
4231*c217d954SCole Faust cl_int error;
4232*c217d954SCole Faust object_ = ::clCreateFromGLBuffer(
4233*c217d954SCole Faust context(),
4234*c217d954SCole Faust flags,
4235*c217d954SCole Faust bufobj,
4236*c217d954SCole Faust &error);
4237*c217d954SCole Faust
4238*c217d954SCole Faust detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
4239*c217d954SCole Faust if (err != NULL) {
4240*c217d954SCole Faust *err = error;
4241*c217d954SCole Faust }
4242*c217d954SCole Faust }
4243*c217d954SCole Faust
4244*c217d954SCole Faust //! \brief Default constructor - initializes to NULL.
BufferGL()4245*c217d954SCole Faust BufferGL() : Buffer() { }
4246*c217d954SCole Faust
4247*c217d954SCole Faust /*! \brief Constructor from cl_mem - takes ownership.
4248*c217d954SCole Faust *
4249*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
4250*c217d954SCole Faust * Defaults to false to maintain compatibility with
4251*c217d954SCole Faust * earlier versions.
4252*c217d954SCole Faust * See Memory for further details.
4253*c217d954SCole Faust */
BufferGL(const cl_mem & buffer,bool retainObject=false)4254*c217d954SCole Faust explicit BufferGL(const cl_mem& buffer, bool retainObject = false) :
4255*c217d954SCole Faust Buffer(buffer, retainObject) { }
4256*c217d954SCole Faust
4257*c217d954SCole Faust /*! \brief Assignment from cl_mem - performs shallow copy.
4258*c217d954SCole Faust *
4259*c217d954SCole Faust * See Memory for further details.
4260*c217d954SCole Faust */
operator =(const cl_mem & rhs)4261*c217d954SCole Faust BufferGL& operator = (const cl_mem& rhs)
4262*c217d954SCole Faust {
4263*c217d954SCole Faust Buffer::operator=(rhs);
4264*c217d954SCole Faust return *this;
4265*c217d954SCole Faust }
4266*c217d954SCole Faust
4267*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
4268*c217d954SCole Faust * Required for MSVC.
4269*c217d954SCole Faust */
BufferGL(const BufferGL & buf)4270*c217d954SCole Faust BufferGL(const BufferGL& buf) : Buffer(buf) {}
4271*c217d954SCole Faust
4272*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
4273*c217d954SCole Faust * Required for MSVC.
4274*c217d954SCole Faust */
operator =(const BufferGL & buf)4275*c217d954SCole Faust BufferGL& operator = (const BufferGL &buf)
4276*c217d954SCole Faust {
4277*c217d954SCole Faust Buffer::operator=(buf);
4278*c217d954SCole Faust return *this;
4279*c217d954SCole Faust }
4280*c217d954SCole Faust
4281*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
4282*c217d954SCole Faust * Required for MSVC.
4283*c217d954SCole Faust */
BufferGL(BufferGL && buf)4284*c217d954SCole Faust BufferGL(BufferGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4285*c217d954SCole Faust
4286*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
4287*c217d954SCole Faust * Required for MSVC.
4288*c217d954SCole Faust */
operator =(BufferGL && buf)4289*c217d954SCole Faust BufferGL& operator = (BufferGL &&buf)
4290*c217d954SCole Faust {
4291*c217d954SCole Faust Buffer::operator=(std::move(buf));
4292*c217d954SCole Faust return *this;
4293*c217d954SCole Faust }
4294*c217d954SCole Faust
4295*c217d954SCole Faust //! \brief Wrapper for clGetGLObjectInfo().
getObjectInfo(cl_gl_object_type * type,cl_GLuint * gl_object_name)4296*c217d954SCole Faust cl_int getObjectInfo(
4297*c217d954SCole Faust cl_gl_object_type *type,
4298*c217d954SCole Faust cl_GLuint * gl_object_name)
4299*c217d954SCole Faust {
4300*c217d954SCole Faust return detail::errHandler(
4301*c217d954SCole Faust ::clGetGLObjectInfo(object_,type,gl_object_name),
4302*c217d954SCole Faust __GET_GL_OBJECT_INFO_ERR);
4303*c217d954SCole Faust }
4304*c217d954SCole Faust };
4305*c217d954SCole Faust
4306*c217d954SCole Faust /*! \brief Class interface for GL Render Buffer Memory Objects.
4307*c217d954SCole Faust *
4308*c217d954SCole Faust * This is provided to facilitate interoperability with OpenGL.
4309*c217d954SCole Faust *
4310*c217d954SCole Faust * See Memory for details about copy semantics, etc.
4311*c217d954SCole Faust *
4312*c217d954SCole Faust * \see Memory
4313*c217d954SCole Faust */
4314*c217d954SCole Faust class BufferRenderGL : public Buffer
4315*c217d954SCole Faust {
4316*c217d954SCole Faust public:
4317*c217d954SCole Faust /*! \brief Constructs a BufferRenderGL in a specified context, from a given
4318*c217d954SCole Faust * GL Renderbuffer.
4319*c217d954SCole Faust *
4320*c217d954SCole Faust * Wraps clCreateFromGLRenderbuffer().
4321*c217d954SCole Faust */
BufferRenderGL(const Context & context,cl_mem_flags flags,cl_GLuint bufobj,cl_int * err=NULL)4322*c217d954SCole Faust BufferRenderGL(
4323*c217d954SCole Faust const Context& context,
4324*c217d954SCole Faust cl_mem_flags flags,
4325*c217d954SCole Faust cl_GLuint bufobj,
4326*c217d954SCole Faust cl_int * err = NULL)
4327*c217d954SCole Faust {
4328*c217d954SCole Faust cl_int error;
4329*c217d954SCole Faust object_ = ::clCreateFromGLRenderbuffer(
4330*c217d954SCole Faust context(),
4331*c217d954SCole Faust flags,
4332*c217d954SCole Faust bufobj,
4333*c217d954SCole Faust &error);
4334*c217d954SCole Faust
4335*c217d954SCole Faust detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR);
4336*c217d954SCole Faust if (err != NULL) {
4337*c217d954SCole Faust *err = error;
4338*c217d954SCole Faust }
4339*c217d954SCole Faust }
4340*c217d954SCole Faust
4341*c217d954SCole Faust //! \brief Default constructor - initializes to NULL.
BufferRenderGL()4342*c217d954SCole Faust BufferRenderGL() : Buffer() { }
4343*c217d954SCole Faust
4344*c217d954SCole Faust /*! \brief Constructor from cl_mem - takes ownership.
4345*c217d954SCole Faust *
4346*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
4347*c217d954SCole Faust * Defaults to false to maintain compatibility with
4348*c217d954SCole Faust * earlier versions.
4349*c217d954SCole Faust * See Memory for further details.
4350*c217d954SCole Faust */
BufferRenderGL(const cl_mem & buffer,bool retainObject=false)4351*c217d954SCole Faust explicit BufferRenderGL(const cl_mem& buffer, bool retainObject = false) :
4352*c217d954SCole Faust Buffer(buffer, retainObject) { }
4353*c217d954SCole Faust
4354*c217d954SCole Faust /*! \brief Assignment from cl_mem - performs shallow copy.
4355*c217d954SCole Faust *
4356*c217d954SCole Faust * See Memory for further details.
4357*c217d954SCole Faust */
operator =(const cl_mem & rhs)4358*c217d954SCole Faust BufferRenderGL& operator = (const cl_mem& rhs)
4359*c217d954SCole Faust {
4360*c217d954SCole Faust Buffer::operator=(rhs);
4361*c217d954SCole Faust return *this;
4362*c217d954SCole Faust }
4363*c217d954SCole Faust
4364*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
4365*c217d954SCole Faust * Required for MSVC.
4366*c217d954SCole Faust */
BufferRenderGL(const BufferRenderGL & buf)4367*c217d954SCole Faust BufferRenderGL(const BufferRenderGL& buf) : Buffer(buf) {}
4368*c217d954SCole Faust
4369*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
4370*c217d954SCole Faust * Required for MSVC.
4371*c217d954SCole Faust */
operator =(const BufferRenderGL & buf)4372*c217d954SCole Faust BufferRenderGL& operator = (const BufferRenderGL &buf)
4373*c217d954SCole Faust {
4374*c217d954SCole Faust Buffer::operator=(buf);
4375*c217d954SCole Faust return *this;
4376*c217d954SCole Faust }
4377*c217d954SCole Faust
4378*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
4379*c217d954SCole Faust * Required for MSVC.
4380*c217d954SCole Faust */
BufferRenderGL(BufferRenderGL && buf)4381*c217d954SCole Faust BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT_ : Buffer(std::move(buf)) {}
4382*c217d954SCole Faust
4383*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
4384*c217d954SCole Faust * Required for MSVC.
4385*c217d954SCole Faust */
operator =(BufferRenderGL && buf)4386*c217d954SCole Faust BufferRenderGL& operator = (BufferRenderGL &&buf)
4387*c217d954SCole Faust {
4388*c217d954SCole Faust Buffer::operator=(std::move(buf));
4389*c217d954SCole Faust return *this;
4390*c217d954SCole Faust }
4391*c217d954SCole Faust
4392*c217d954SCole Faust //! \brief Wrapper for clGetGLObjectInfo().
getObjectInfo(cl_gl_object_type * type,cl_GLuint * gl_object_name)4393*c217d954SCole Faust cl_int getObjectInfo(
4394*c217d954SCole Faust cl_gl_object_type *type,
4395*c217d954SCole Faust cl_GLuint * gl_object_name)
4396*c217d954SCole Faust {
4397*c217d954SCole Faust return detail::errHandler(
4398*c217d954SCole Faust ::clGetGLObjectInfo(object_,type,gl_object_name),
4399*c217d954SCole Faust __GET_GL_OBJECT_INFO_ERR);
4400*c217d954SCole Faust }
4401*c217d954SCole Faust };
4402*c217d954SCole Faust
4403*c217d954SCole Faust /*! \brief C++ base class for Image Memory objects.
4404*c217d954SCole Faust *
4405*c217d954SCole Faust * See Memory for details about copy semantics, etc.
4406*c217d954SCole Faust *
4407*c217d954SCole Faust * \see Memory
4408*c217d954SCole Faust */
4409*c217d954SCole Faust class Image : public Memory
4410*c217d954SCole Faust {
4411*c217d954SCole Faust protected:
4412*c217d954SCole Faust //! \brief Default constructor - initializes to NULL.
Image()4413*c217d954SCole Faust Image() : Memory() { }
4414*c217d954SCole Faust
4415*c217d954SCole Faust /*! \brief Constructor from cl_mem - takes ownership.
4416*c217d954SCole Faust *
4417*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
4418*c217d954SCole Faust * Defaults to false to maintain compatibility with
4419*c217d954SCole Faust * earlier versions.
4420*c217d954SCole Faust * See Memory for further details.
4421*c217d954SCole Faust */
Image(const cl_mem & image,bool retainObject=false)4422*c217d954SCole Faust explicit Image(const cl_mem& image, bool retainObject = false) :
4423*c217d954SCole Faust Memory(image, retainObject) { }
4424*c217d954SCole Faust
4425*c217d954SCole Faust /*! \brief Assignment from cl_mem - performs shallow copy.
4426*c217d954SCole Faust *
4427*c217d954SCole Faust * See Memory for further details.
4428*c217d954SCole Faust */
operator =(const cl_mem & rhs)4429*c217d954SCole Faust Image& operator = (const cl_mem& rhs)
4430*c217d954SCole Faust {
4431*c217d954SCole Faust Memory::operator=(rhs);
4432*c217d954SCole Faust return *this;
4433*c217d954SCole Faust }
4434*c217d954SCole Faust
4435*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
4436*c217d954SCole Faust * Required for MSVC.
4437*c217d954SCole Faust */
Image(const Image & img)4438*c217d954SCole Faust Image(const Image& img) : Memory(img) {}
4439*c217d954SCole Faust
4440*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
4441*c217d954SCole Faust * Required for MSVC.
4442*c217d954SCole Faust */
operator =(const Image & img)4443*c217d954SCole Faust Image& operator = (const Image &img)
4444*c217d954SCole Faust {
4445*c217d954SCole Faust Memory::operator=(img);
4446*c217d954SCole Faust return *this;
4447*c217d954SCole Faust }
4448*c217d954SCole Faust
4449*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
4450*c217d954SCole Faust * Required for MSVC.
4451*c217d954SCole Faust */
Image(Image && img)4452*c217d954SCole Faust Image(Image&& img) CL_HPP_NOEXCEPT_ : Memory(std::move(img)) {}
4453*c217d954SCole Faust
4454*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
4455*c217d954SCole Faust * Required for MSVC.
4456*c217d954SCole Faust */
operator =(Image && img)4457*c217d954SCole Faust Image& operator = (Image &&img)
4458*c217d954SCole Faust {
4459*c217d954SCole Faust Memory::operator=(std::move(img));
4460*c217d954SCole Faust return *this;
4461*c217d954SCole Faust }
4462*c217d954SCole Faust
4463*c217d954SCole Faust
4464*c217d954SCole Faust public:
4465*c217d954SCole Faust //! \brief Wrapper for clGetImageInfo().
4466*c217d954SCole Faust template <typename T>
getImageInfo(cl_image_info name,T * param) const4467*c217d954SCole Faust cl_int getImageInfo(cl_image_info name, T* param) const
4468*c217d954SCole Faust {
4469*c217d954SCole Faust return detail::errHandler(
4470*c217d954SCole Faust detail::getInfo(&::clGetImageInfo, object_, name, param),
4471*c217d954SCole Faust __GET_IMAGE_INFO_ERR);
4472*c217d954SCole Faust }
4473*c217d954SCole Faust
4474*c217d954SCole Faust //! \brief Wrapper for clGetImageInfo() that returns by value.
4475*c217d954SCole Faust template <cl_image_info name> typename
4476*c217d954SCole Faust detail::param_traits<detail::cl_image_info, name>::param_type
getImageInfo(cl_int * err=NULL) const4477*c217d954SCole Faust getImageInfo(cl_int* err = NULL) const
4478*c217d954SCole Faust {
4479*c217d954SCole Faust typename detail::param_traits<
4480*c217d954SCole Faust detail::cl_image_info, name>::param_type param;
4481*c217d954SCole Faust cl_int result = getImageInfo(name, ¶m);
4482*c217d954SCole Faust if (err != NULL) {
4483*c217d954SCole Faust *err = result;
4484*c217d954SCole Faust }
4485*c217d954SCole Faust return param;
4486*c217d954SCole Faust }
4487*c217d954SCole Faust };
4488*c217d954SCole Faust
4489*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4490*c217d954SCole Faust /*! \brief Class interface for 1D Image Memory objects.
4491*c217d954SCole Faust *
4492*c217d954SCole Faust * See Memory for details about copy semantics, etc.
4493*c217d954SCole Faust *
4494*c217d954SCole Faust * \see Memory
4495*c217d954SCole Faust */
4496*c217d954SCole Faust class Image1D : public Image
4497*c217d954SCole Faust {
4498*c217d954SCole Faust public:
4499*c217d954SCole Faust /*! \brief Constructs a 1D Image in a specified context.
4500*c217d954SCole Faust *
4501*c217d954SCole Faust * Wraps clCreateImage().
4502*c217d954SCole Faust */
Image1D(const Context & context,cl_mem_flags flags,ImageFormat format,size_type width,void * host_ptr=NULL,cl_int * err=NULL)4503*c217d954SCole Faust Image1D(
4504*c217d954SCole Faust const Context& context,
4505*c217d954SCole Faust cl_mem_flags flags,
4506*c217d954SCole Faust ImageFormat format,
4507*c217d954SCole Faust size_type width,
4508*c217d954SCole Faust void* host_ptr = NULL,
4509*c217d954SCole Faust cl_int* err = NULL)
4510*c217d954SCole Faust {
4511*c217d954SCole Faust cl_int error;
4512*c217d954SCole Faust
4513*c217d954SCole Faust cl_image_desc desc = {0};
4514*c217d954SCole Faust desc.image_type = CL_MEM_OBJECT_IMAGE1D;
4515*c217d954SCole Faust desc.image_width = width;
4516*c217d954SCole Faust
4517*c217d954SCole Faust object_ = ::clCreateImage(
4518*c217d954SCole Faust context(),
4519*c217d954SCole Faust flags,
4520*c217d954SCole Faust &format,
4521*c217d954SCole Faust &desc,
4522*c217d954SCole Faust host_ptr,
4523*c217d954SCole Faust &error);
4524*c217d954SCole Faust
4525*c217d954SCole Faust detail::errHandler(error, __CREATE_IMAGE_ERR);
4526*c217d954SCole Faust if (err != NULL) {
4527*c217d954SCole Faust *err = error;
4528*c217d954SCole Faust }
4529*c217d954SCole Faust }
4530*c217d954SCole Faust
4531*c217d954SCole Faust //! \brief Default constructor - initializes to NULL.
Image1D()4532*c217d954SCole Faust Image1D() { }
4533*c217d954SCole Faust
4534*c217d954SCole Faust /*! \brief Constructor from cl_mem - takes ownership.
4535*c217d954SCole Faust *
4536*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
4537*c217d954SCole Faust * Defaults to false to maintain compatibility with
4538*c217d954SCole Faust * earlier versions.
4539*c217d954SCole Faust * See Memory for further details.
4540*c217d954SCole Faust */
Image1D(const cl_mem & image1D,bool retainObject=false)4541*c217d954SCole Faust explicit Image1D(const cl_mem& image1D, bool retainObject = false) :
4542*c217d954SCole Faust Image(image1D, retainObject) { }
4543*c217d954SCole Faust
4544*c217d954SCole Faust /*! \brief Assignment from cl_mem - performs shallow copy.
4545*c217d954SCole Faust *
4546*c217d954SCole Faust * See Memory for further details.
4547*c217d954SCole Faust */
operator =(const cl_mem & rhs)4548*c217d954SCole Faust Image1D& operator = (const cl_mem& rhs)
4549*c217d954SCole Faust {
4550*c217d954SCole Faust Image::operator=(rhs);
4551*c217d954SCole Faust return *this;
4552*c217d954SCole Faust }
4553*c217d954SCole Faust
4554*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
4555*c217d954SCole Faust * Required for MSVC.
4556*c217d954SCole Faust */
Image1D(const Image1D & img)4557*c217d954SCole Faust Image1D(const Image1D& img) : Image(img) {}
4558*c217d954SCole Faust
4559*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
4560*c217d954SCole Faust * Required for MSVC.
4561*c217d954SCole Faust */
operator =(const Image1D & img)4562*c217d954SCole Faust Image1D& operator = (const Image1D &img)
4563*c217d954SCole Faust {
4564*c217d954SCole Faust Image::operator=(img);
4565*c217d954SCole Faust return *this;
4566*c217d954SCole Faust }
4567*c217d954SCole Faust
4568*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
4569*c217d954SCole Faust * Required for MSVC.
4570*c217d954SCole Faust */
Image1D(Image1D && img)4571*c217d954SCole Faust Image1D(Image1D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4572*c217d954SCole Faust
4573*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
4574*c217d954SCole Faust * Required for MSVC.
4575*c217d954SCole Faust */
operator =(Image1D && img)4576*c217d954SCole Faust Image1D& operator = (Image1D &&img)
4577*c217d954SCole Faust {
4578*c217d954SCole Faust Image::operator=(std::move(img));
4579*c217d954SCole Faust return *this;
4580*c217d954SCole Faust }
4581*c217d954SCole Faust
4582*c217d954SCole Faust };
4583*c217d954SCole Faust
4584*c217d954SCole Faust /*! \class Image1DBuffer
4585*c217d954SCole Faust * \brief Image interface for 1D buffer images.
4586*c217d954SCole Faust */
4587*c217d954SCole Faust class Image1DBuffer : public Image
4588*c217d954SCole Faust {
4589*c217d954SCole Faust public:
Image1DBuffer(const Context & context,cl_mem_flags flags,ImageFormat format,size_type width,const Buffer & buffer,cl_int * err=NULL)4590*c217d954SCole Faust Image1DBuffer(
4591*c217d954SCole Faust const Context& context,
4592*c217d954SCole Faust cl_mem_flags flags,
4593*c217d954SCole Faust ImageFormat format,
4594*c217d954SCole Faust size_type width,
4595*c217d954SCole Faust const Buffer &buffer,
4596*c217d954SCole Faust cl_int* err = NULL)
4597*c217d954SCole Faust {
4598*c217d954SCole Faust cl_int error;
4599*c217d954SCole Faust
4600*c217d954SCole Faust cl_image_desc desc = {0};
4601*c217d954SCole Faust desc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER;
4602*c217d954SCole Faust desc.image_width = width;
4603*c217d954SCole Faust desc.buffer = buffer();
4604*c217d954SCole Faust
4605*c217d954SCole Faust object_ = ::clCreateImage(
4606*c217d954SCole Faust context(),
4607*c217d954SCole Faust flags,
4608*c217d954SCole Faust &format,
4609*c217d954SCole Faust &desc,
4610*c217d954SCole Faust NULL,
4611*c217d954SCole Faust &error);
4612*c217d954SCole Faust
4613*c217d954SCole Faust detail::errHandler(error, __CREATE_IMAGE_ERR);
4614*c217d954SCole Faust if (err != NULL) {
4615*c217d954SCole Faust *err = error;
4616*c217d954SCole Faust }
4617*c217d954SCole Faust }
4618*c217d954SCole Faust
Image1DBuffer()4619*c217d954SCole Faust Image1DBuffer() { }
4620*c217d954SCole Faust
4621*c217d954SCole Faust /*! \brief Constructor from cl_mem - takes ownership.
4622*c217d954SCole Faust *
4623*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
4624*c217d954SCole Faust * Defaults to false to maintain compatibility with
4625*c217d954SCole Faust * earlier versions.
4626*c217d954SCole Faust * See Memory for further details.
4627*c217d954SCole Faust */
Image1DBuffer(const cl_mem & image1D,bool retainObject=false)4628*c217d954SCole Faust explicit Image1DBuffer(const cl_mem& image1D, bool retainObject = false) :
4629*c217d954SCole Faust Image(image1D, retainObject) { }
4630*c217d954SCole Faust
operator =(const cl_mem & rhs)4631*c217d954SCole Faust Image1DBuffer& operator = (const cl_mem& rhs)
4632*c217d954SCole Faust {
4633*c217d954SCole Faust Image::operator=(rhs);
4634*c217d954SCole Faust return *this;
4635*c217d954SCole Faust }
4636*c217d954SCole Faust
4637*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
4638*c217d954SCole Faust * Required for MSVC.
4639*c217d954SCole Faust */
Image1DBuffer(const Image1DBuffer & img)4640*c217d954SCole Faust Image1DBuffer(const Image1DBuffer& img) : Image(img) {}
4641*c217d954SCole Faust
4642*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
4643*c217d954SCole Faust * Required for MSVC.
4644*c217d954SCole Faust */
operator =(const Image1DBuffer & img)4645*c217d954SCole Faust Image1DBuffer& operator = (const Image1DBuffer &img)
4646*c217d954SCole Faust {
4647*c217d954SCole Faust Image::operator=(img);
4648*c217d954SCole Faust return *this;
4649*c217d954SCole Faust }
4650*c217d954SCole Faust
4651*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
4652*c217d954SCole Faust * Required for MSVC.
4653*c217d954SCole Faust */
Image1DBuffer(Image1DBuffer && img)4654*c217d954SCole Faust Image1DBuffer(Image1DBuffer&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4655*c217d954SCole Faust
4656*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
4657*c217d954SCole Faust * Required for MSVC.
4658*c217d954SCole Faust */
operator =(Image1DBuffer && img)4659*c217d954SCole Faust Image1DBuffer& operator = (Image1DBuffer &&img)
4660*c217d954SCole Faust {
4661*c217d954SCole Faust Image::operator=(std::move(img));
4662*c217d954SCole Faust return *this;
4663*c217d954SCole Faust }
4664*c217d954SCole Faust
4665*c217d954SCole Faust };
4666*c217d954SCole Faust
4667*c217d954SCole Faust /*! \class Image1DArray
4668*c217d954SCole Faust * \brief Image interface for arrays of 1D images.
4669*c217d954SCole Faust */
4670*c217d954SCole Faust class Image1DArray : public Image
4671*c217d954SCole Faust {
4672*c217d954SCole Faust public:
Image1DArray(const Context & context,cl_mem_flags flags,ImageFormat format,size_type arraySize,size_type width,size_type rowPitch,void * host_ptr=NULL,cl_int * err=NULL)4673*c217d954SCole Faust Image1DArray(
4674*c217d954SCole Faust const Context& context,
4675*c217d954SCole Faust cl_mem_flags flags,
4676*c217d954SCole Faust ImageFormat format,
4677*c217d954SCole Faust size_type arraySize,
4678*c217d954SCole Faust size_type width,
4679*c217d954SCole Faust size_type rowPitch,
4680*c217d954SCole Faust void* host_ptr = NULL,
4681*c217d954SCole Faust cl_int* err = NULL)
4682*c217d954SCole Faust {
4683*c217d954SCole Faust cl_int error;
4684*c217d954SCole Faust
4685*c217d954SCole Faust cl_image_desc desc = {0};
4686*c217d954SCole Faust desc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
4687*c217d954SCole Faust desc.image_width = width;
4688*c217d954SCole Faust desc.image_array_size = arraySize;
4689*c217d954SCole Faust desc.image_row_pitch = rowPitch;
4690*c217d954SCole Faust
4691*c217d954SCole Faust object_ = ::clCreateImage(
4692*c217d954SCole Faust context(),
4693*c217d954SCole Faust flags,
4694*c217d954SCole Faust &format,
4695*c217d954SCole Faust &desc,
4696*c217d954SCole Faust host_ptr,
4697*c217d954SCole Faust &error);
4698*c217d954SCole Faust
4699*c217d954SCole Faust detail::errHandler(error, __CREATE_IMAGE_ERR);
4700*c217d954SCole Faust if (err != NULL) {
4701*c217d954SCole Faust *err = error;
4702*c217d954SCole Faust }
4703*c217d954SCole Faust }
4704*c217d954SCole Faust
Image1DArray()4705*c217d954SCole Faust Image1DArray() { }
4706*c217d954SCole Faust
4707*c217d954SCole Faust /*! \brief Constructor from cl_mem - takes ownership.
4708*c217d954SCole Faust *
4709*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
4710*c217d954SCole Faust * Defaults to false to maintain compatibility with
4711*c217d954SCole Faust * earlier versions.
4712*c217d954SCole Faust * See Memory for further details.
4713*c217d954SCole Faust */
Image1DArray(const cl_mem & imageArray,bool retainObject=false)4714*c217d954SCole Faust explicit Image1DArray(const cl_mem& imageArray, bool retainObject = false) :
4715*c217d954SCole Faust Image(imageArray, retainObject) { }
4716*c217d954SCole Faust
4717*c217d954SCole Faust
operator =(const cl_mem & rhs)4718*c217d954SCole Faust Image1DArray& operator = (const cl_mem& rhs)
4719*c217d954SCole Faust {
4720*c217d954SCole Faust Image::operator=(rhs);
4721*c217d954SCole Faust return *this;
4722*c217d954SCole Faust }
4723*c217d954SCole Faust
4724*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
4725*c217d954SCole Faust * Required for MSVC.
4726*c217d954SCole Faust */
Image1DArray(const Image1DArray & img)4727*c217d954SCole Faust Image1DArray(const Image1DArray& img) : Image(img) {}
4728*c217d954SCole Faust
4729*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
4730*c217d954SCole Faust * Required for MSVC.
4731*c217d954SCole Faust */
operator =(const Image1DArray & img)4732*c217d954SCole Faust Image1DArray& operator = (const Image1DArray &img)
4733*c217d954SCole Faust {
4734*c217d954SCole Faust Image::operator=(img);
4735*c217d954SCole Faust return *this;
4736*c217d954SCole Faust }
4737*c217d954SCole Faust
4738*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
4739*c217d954SCole Faust * Required for MSVC.
4740*c217d954SCole Faust */
Image1DArray(Image1DArray && img)4741*c217d954SCole Faust Image1DArray(Image1DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4742*c217d954SCole Faust
4743*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
4744*c217d954SCole Faust * Required for MSVC.
4745*c217d954SCole Faust */
operator =(Image1DArray && img)4746*c217d954SCole Faust Image1DArray& operator = (Image1DArray &&img)
4747*c217d954SCole Faust {
4748*c217d954SCole Faust Image::operator=(std::move(img));
4749*c217d954SCole Faust return *this;
4750*c217d954SCole Faust }
4751*c217d954SCole Faust
4752*c217d954SCole Faust };
4753*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4754*c217d954SCole Faust
4755*c217d954SCole Faust
4756*c217d954SCole Faust /*! \brief Class interface for 2D Image Memory objects.
4757*c217d954SCole Faust *
4758*c217d954SCole Faust * See Memory for details about copy semantics, etc.
4759*c217d954SCole Faust *
4760*c217d954SCole Faust * \see Memory
4761*c217d954SCole Faust */
4762*c217d954SCole Faust class Image2D : public Image
4763*c217d954SCole Faust {
4764*c217d954SCole Faust public:
4765*c217d954SCole Faust /*! \brief Constructs a 2D Image in a specified context.
4766*c217d954SCole Faust *
4767*c217d954SCole Faust * Wraps clCreateImage().
4768*c217d954SCole Faust */
Image2D(const Context & context,cl_mem_flags flags,ImageFormat format,size_type width,size_type height,size_type row_pitch=0,void * host_ptr=NULL,cl_int * err=NULL)4769*c217d954SCole Faust Image2D(
4770*c217d954SCole Faust const Context& context,
4771*c217d954SCole Faust cl_mem_flags flags,
4772*c217d954SCole Faust ImageFormat format,
4773*c217d954SCole Faust size_type width,
4774*c217d954SCole Faust size_type height,
4775*c217d954SCole Faust size_type row_pitch = 0,
4776*c217d954SCole Faust void* host_ptr = NULL,
4777*c217d954SCole Faust cl_int* err = NULL)
4778*c217d954SCole Faust {
4779*c217d954SCole Faust cl_int error;
4780*c217d954SCole Faust bool useCreateImage;
4781*c217d954SCole Faust
4782*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
4783*c217d954SCole Faust // Run-time decision based on the actual platform
4784*c217d954SCole Faust {
4785*c217d954SCole Faust cl_uint version = detail::getContextPlatformVersion(context());
4786*c217d954SCole Faust useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
4787*c217d954SCole Faust }
4788*c217d954SCole Faust #elif CL_HPP_TARGET_OPENCL_VERSION >= 120
4789*c217d954SCole Faust useCreateImage = true;
4790*c217d954SCole Faust #else
4791*c217d954SCole Faust useCreateImage = false;
4792*c217d954SCole Faust #endif
4793*c217d954SCole Faust
4794*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
4795*c217d954SCole Faust if (useCreateImage)
4796*c217d954SCole Faust {
4797*c217d954SCole Faust cl_image_desc desc = {0};
4798*c217d954SCole Faust desc.image_type = CL_MEM_OBJECT_IMAGE2D;
4799*c217d954SCole Faust desc.image_width = width;
4800*c217d954SCole Faust desc.image_height = height;
4801*c217d954SCole Faust desc.image_row_pitch = row_pitch;
4802*c217d954SCole Faust
4803*c217d954SCole Faust object_ = ::clCreateImage(
4804*c217d954SCole Faust context(),
4805*c217d954SCole Faust flags,
4806*c217d954SCole Faust &format,
4807*c217d954SCole Faust &desc,
4808*c217d954SCole Faust host_ptr,
4809*c217d954SCole Faust &error);
4810*c217d954SCole Faust
4811*c217d954SCole Faust detail::errHandler(error, __CREATE_IMAGE_ERR);
4812*c217d954SCole Faust if (err != NULL) {
4813*c217d954SCole Faust *err = error;
4814*c217d954SCole Faust }
4815*c217d954SCole Faust }
4816*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
4817*c217d954SCole Faust #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
4818*c217d954SCole Faust if (!useCreateImage)
4819*c217d954SCole Faust {
4820*c217d954SCole Faust object_ = ::clCreateImage2D(
4821*c217d954SCole Faust context(), flags,&format, width, height, row_pitch, host_ptr, &error);
4822*c217d954SCole Faust
4823*c217d954SCole Faust detail::errHandler(error, __CREATE_IMAGE2D_ERR);
4824*c217d954SCole Faust if (err != NULL) {
4825*c217d954SCole Faust *err = error;
4826*c217d954SCole Faust }
4827*c217d954SCole Faust }
4828*c217d954SCole Faust #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
4829*c217d954SCole Faust }
4830*c217d954SCole Faust
4831*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4832*c217d954SCole Faust /*! \brief Constructs a 2D Image from a buffer.
4833*c217d954SCole Faust * \note This will share storage with the underlying buffer.
4834*c217d954SCole Faust *
4835*c217d954SCole Faust * Wraps clCreateImage().
4836*c217d954SCole Faust */
Image2D(const Context & context,ImageFormat format,const Buffer & sourceBuffer,size_type width,size_type height,size_type row_pitch=0,cl_int * err=nullptr)4837*c217d954SCole Faust Image2D(
4838*c217d954SCole Faust const Context& context,
4839*c217d954SCole Faust ImageFormat format,
4840*c217d954SCole Faust const Buffer &sourceBuffer,
4841*c217d954SCole Faust size_type width,
4842*c217d954SCole Faust size_type height,
4843*c217d954SCole Faust size_type row_pitch = 0,
4844*c217d954SCole Faust cl_int* err = nullptr)
4845*c217d954SCole Faust {
4846*c217d954SCole Faust cl_int error;
4847*c217d954SCole Faust
4848*c217d954SCole Faust cl_image_desc desc = {0};
4849*c217d954SCole Faust desc.image_type = CL_MEM_OBJECT_IMAGE2D;
4850*c217d954SCole Faust desc.image_width = width;
4851*c217d954SCole Faust desc.image_height = height;
4852*c217d954SCole Faust desc.image_row_pitch = row_pitch;
4853*c217d954SCole Faust desc.buffer = sourceBuffer();
4854*c217d954SCole Faust
4855*c217d954SCole Faust object_ = ::clCreateImage(
4856*c217d954SCole Faust context(),
4857*c217d954SCole Faust 0, // flags inherited from buffer
4858*c217d954SCole Faust &format,
4859*c217d954SCole Faust &desc,
4860*c217d954SCole Faust nullptr,
4861*c217d954SCole Faust &error);
4862*c217d954SCole Faust
4863*c217d954SCole Faust detail::errHandler(error, __CREATE_IMAGE_ERR);
4864*c217d954SCole Faust if (err != nullptr) {
4865*c217d954SCole Faust *err = error;
4866*c217d954SCole Faust }
4867*c217d954SCole Faust }
4868*c217d954SCole Faust #endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200 || defined(CL_HPP_USE_CL_IMAGE2D_FROM_BUFFER_KHR)
4869*c217d954SCole Faust
4870*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
4871*c217d954SCole Faust /*! \brief Constructs a 2D Image from an image.
4872*c217d954SCole Faust * \note This will share storage with the underlying image but may
4873*c217d954SCole Faust * reinterpret the channel order and type.
4874*c217d954SCole Faust *
4875*c217d954SCole Faust * The image will be created matching with a descriptor matching the source.
4876*c217d954SCole Faust *
4877*c217d954SCole Faust * \param order is the channel order to reinterpret the image data as.
4878*c217d954SCole Faust * The channel order may differ as described in the OpenCL
4879*c217d954SCole Faust * 2.0 API specification.
4880*c217d954SCole Faust *
4881*c217d954SCole Faust * Wraps clCreateImage().
4882*c217d954SCole Faust */
Image2D(const Context & context,cl_channel_order order,const Image & sourceImage,cl_int * err=nullptr)4883*c217d954SCole Faust Image2D(
4884*c217d954SCole Faust const Context& context,
4885*c217d954SCole Faust cl_channel_order order,
4886*c217d954SCole Faust const Image &sourceImage,
4887*c217d954SCole Faust cl_int* err = nullptr)
4888*c217d954SCole Faust {
4889*c217d954SCole Faust cl_int error;
4890*c217d954SCole Faust
4891*c217d954SCole Faust // Descriptor fields have to match source image
4892*c217d954SCole Faust size_type sourceWidth =
4893*c217d954SCole Faust sourceImage.getImageInfo<CL_IMAGE_WIDTH>();
4894*c217d954SCole Faust size_type sourceHeight =
4895*c217d954SCole Faust sourceImage.getImageInfo<CL_IMAGE_HEIGHT>();
4896*c217d954SCole Faust size_type sourceRowPitch =
4897*c217d954SCole Faust sourceImage.getImageInfo<CL_IMAGE_ROW_PITCH>();
4898*c217d954SCole Faust cl_uint sourceNumMIPLevels =
4899*c217d954SCole Faust sourceImage.getImageInfo<CL_IMAGE_NUM_MIP_LEVELS>();
4900*c217d954SCole Faust cl_uint sourceNumSamples =
4901*c217d954SCole Faust sourceImage.getImageInfo<CL_IMAGE_NUM_SAMPLES>();
4902*c217d954SCole Faust cl_image_format sourceFormat =
4903*c217d954SCole Faust sourceImage.getImageInfo<CL_IMAGE_FORMAT>();
4904*c217d954SCole Faust
4905*c217d954SCole Faust // Update only the channel order.
4906*c217d954SCole Faust // Channel format inherited from source.
4907*c217d954SCole Faust sourceFormat.image_channel_order = order;
4908*c217d954SCole Faust
4909*c217d954SCole Faust cl_image_desc desc = {0};
4910*c217d954SCole Faust desc.image_type = CL_MEM_OBJECT_IMAGE2D;
4911*c217d954SCole Faust desc.image_width = sourceWidth;
4912*c217d954SCole Faust desc.image_height = sourceHeight;
4913*c217d954SCole Faust desc.image_row_pitch = sourceRowPitch;
4914*c217d954SCole Faust desc.num_mip_levels = sourceNumMIPLevels;
4915*c217d954SCole Faust desc.num_samples = sourceNumSamples;
4916*c217d954SCole Faust desc.buffer = sourceImage();
4917*c217d954SCole Faust
4918*c217d954SCole Faust object_ = ::clCreateImage(
4919*c217d954SCole Faust context(),
4920*c217d954SCole Faust 0, // flags should be inherited from mem_object
4921*c217d954SCole Faust &sourceFormat,
4922*c217d954SCole Faust &desc,
4923*c217d954SCole Faust nullptr,
4924*c217d954SCole Faust &error);
4925*c217d954SCole Faust
4926*c217d954SCole Faust detail::errHandler(error, __CREATE_IMAGE_ERR);
4927*c217d954SCole Faust if (err != nullptr) {
4928*c217d954SCole Faust *err = error;
4929*c217d954SCole Faust }
4930*c217d954SCole Faust }
4931*c217d954SCole Faust #endif //#if CL_HPP_TARGET_OPENCL_VERSION >= 200
4932*c217d954SCole Faust
4933*c217d954SCole Faust //! \brief Default constructor - initializes to NULL.
Image2D()4934*c217d954SCole Faust Image2D() { }
4935*c217d954SCole Faust
4936*c217d954SCole Faust /*! \brief Constructor from cl_mem - takes ownership.
4937*c217d954SCole Faust *
4938*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
4939*c217d954SCole Faust * Defaults to false to maintain compatibility with
4940*c217d954SCole Faust * earlier versions.
4941*c217d954SCole Faust * See Memory for further details.
4942*c217d954SCole Faust */
Image2D(const cl_mem & image2D,bool retainObject=false)4943*c217d954SCole Faust explicit Image2D(const cl_mem& image2D, bool retainObject = false) :
4944*c217d954SCole Faust Image(image2D, retainObject) { }
4945*c217d954SCole Faust
4946*c217d954SCole Faust /*! \brief Assignment from cl_mem - performs shallow copy.
4947*c217d954SCole Faust *
4948*c217d954SCole Faust * See Memory for further details.
4949*c217d954SCole Faust */
operator =(const cl_mem & rhs)4950*c217d954SCole Faust Image2D& operator = (const cl_mem& rhs)
4951*c217d954SCole Faust {
4952*c217d954SCole Faust Image::operator=(rhs);
4953*c217d954SCole Faust return *this;
4954*c217d954SCole Faust }
4955*c217d954SCole Faust
4956*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
4957*c217d954SCole Faust * Required for MSVC.
4958*c217d954SCole Faust */
Image2D(const Image2D & img)4959*c217d954SCole Faust Image2D(const Image2D& img) : Image(img) {}
4960*c217d954SCole Faust
4961*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
4962*c217d954SCole Faust * Required for MSVC.
4963*c217d954SCole Faust */
operator =(const Image2D & img)4964*c217d954SCole Faust Image2D& operator = (const Image2D &img)
4965*c217d954SCole Faust {
4966*c217d954SCole Faust Image::operator=(img);
4967*c217d954SCole Faust return *this;
4968*c217d954SCole Faust }
4969*c217d954SCole Faust
4970*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
4971*c217d954SCole Faust * Required for MSVC.
4972*c217d954SCole Faust */
Image2D(Image2D && img)4973*c217d954SCole Faust Image2D(Image2D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
4974*c217d954SCole Faust
4975*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
4976*c217d954SCole Faust * Required for MSVC.
4977*c217d954SCole Faust */
operator =(Image2D && img)4978*c217d954SCole Faust Image2D& operator = (Image2D &&img)
4979*c217d954SCole Faust {
4980*c217d954SCole Faust Image::operator=(std::move(img));
4981*c217d954SCole Faust return *this;
4982*c217d954SCole Faust }
4983*c217d954SCole Faust
4984*c217d954SCole Faust };
4985*c217d954SCole Faust
4986*c217d954SCole Faust
4987*c217d954SCole Faust #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
4988*c217d954SCole Faust /*! \brief Class interface for GL 2D Image Memory objects.
4989*c217d954SCole Faust *
4990*c217d954SCole Faust * This is provided to facilitate interoperability with OpenGL.
4991*c217d954SCole Faust *
4992*c217d954SCole Faust * See Memory for details about copy semantics, etc.
4993*c217d954SCole Faust *
4994*c217d954SCole Faust * \see Memory
4995*c217d954SCole Faust * \note Deprecated for OpenCL 1.2. Please use ImageGL instead.
4996*c217d954SCole Faust */
4997*c217d954SCole Faust class CL_API_PREFIX__VERSION_1_1_DEPRECATED Image2DGL : public Image2D
4998*c217d954SCole Faust {
4999*c217d954SCole Faust public:
5000*c217d954SCole Faust /*! \brief Constructs an Image2DGL in a specified context, from a given
5001*c217d954SCole Faust * GL Texture.
5002*c217d954SCole Faust *
5003*c217d954SCole Faust * Wraps clCreateFromGLTexture2D().
5004*c217d954SCole Faust */
Image2DGL(const Context & context,cl_mem_flags flags,cl_GLenum target,cl_GLint miplevel,cl_GLuint texobj,cl_int * err=NULL)5005*c217d954SCole Faust Image2DGL(
5006*c217d954SCole Faust const Context& context,
5007*c217d954SCole Faust cl_mem_flags flags,
5008*c217d954SCole Faust cl_GLenum target,
5009*c217d954SCole Faust cl_GLint miplevel,
5010*c217d954SCole Faust cl_GLuint texobj,
5011*c217d954SCole Faust cl_int * err = NULL)
5012*c217d954SCole Faust {
5013*c217d954SCole Faust cl_int error;
5014*c217d954SCole Faust object_ = ::clCreateFromGLTexture2D(
5015*c217d954SCole Faust context(),
5016*c217d954SCole Faust flags,
5017*c217d954SCole Faust target,
5018*c217d954SCole Faust miplevel,
5019*c217d954SCole Faust texobj,
5020*c217d954SCole Faust &error);
5021*c217d954SCole Faust
5022*c217d954SCole Faust detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR);
5023*c217d954SCole Faust if (err != NULL) {
5024*c217d954SCole Faust *err = error;
5025*c217d954SCole Faust }
5026*c217d954SCole Faust
5027*c217d954SCole Faust }
5028*c217d954SCole Faust
5029*c217d954SCole Faust //! \brief Default constructor - initializes to NULL.
Image2DGL()5030*c217d954SCole Faust Image2DGL() : Image2D() { }
5031*c217d954SCole Faust
5032*c217d954SCole Faust /*! \brief Constructor from cl_mem - takes ownership.
5033*c217d954SCole Faust *
5034*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
5035*c217d954SCole Faust * Defaults to false to maintain compatibility with
5036*c217d954SCole Faust * earlier versions.
5037*c217d954SCole Faust * See Memory for further details.
5038*c217d954SCole Faust */
Image2DGL(const cl_mem & image,bool retainObject=false)5039*c217d954SCole Faust explicit Image2DGL(const cl_mem& image, bool retainObject = false) :
5040*c217d954SCole Faust Image2D(image, retainObject) { }
5041*c217d954SCole Faust
5042*c217d954SCole Faust /*! \brief Assignment from cl_mem - performs shallow copy.
5043*c217d954SCole Faust *c
5044*c217d954SCole Faust * See Memory for further details.
5045*c217d954SCole Faust */
operator =(const cl_mem & rhs)5046*c217d954SCole Faust Image2DGL& operator = (const cl_mem& rhs)
5047*c217d954SCole Faust {
5048*c217d954SCole Faust Image2D::operator=(rhs);
5049*c217d954SCole Faust return *this;
5050*c217d954SCole Faust }
5051*c217d954SCole Faust
5052*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
5053*c217d954SCole Faust * Required for MSVC.
5054*c217d954SCole Faust */
Image2DGL(const Image2DGL & img)5055*c217d954SCole Faust Image2DGL(const Image2DGL& img) : Image2D(img) {}
5056*c217d954SCole Faust
5057*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
5058*c217d954SCole Faust * Required for MSVC.
5059*c217d954SCole Faust */
operator =(const Image2DGL & img)5060*c217d954SCole Faust Image2DGL& operator = (const Image2DGL &img)
5061*c217d954SCole Faust {
5062*c217d954SCole Faust Image2D::operator=(img);
5063*c217d954SCole Faust return *this;
5064*c217d954SCole Faust }
5065*c217d954SCole Faust
5066*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
5067*c217d954SCole Faust * Required for MSVC.
5068*c217d954SCole Faust */
Image2DGL(Image2DGL && img)5069*c217d954SCole Faust Image2DGL(Image2DGL&& img) CL_HPP_NOEXCEPT_ : Image2D(std::move(img)) {}
5070*c217d954SCole Faust
5071*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
5072*c217d954SCole Faust * Required for MSVC.
5073*c217d954SCole Faust */
operator =(Image2DGL && img)5074*c217d954SCole Faust Image2DGL& operator = (Image2DGL &&img)
5075*c217d954SCole Faust {
5076*c217d954SCole Faust Image2D::operator=(std::move(img));
5077*c217d954SCole Faust return *this;
5078*c217d954SCole Faust }
5079*c217d954SCole Faust
5080*c217d954SCole Faust } CL_API_SUFFIX__VERSION_1_1_DEPRECATED;
5081*c217d954SCole Faust #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5082*c217d954SCole Faust
5083*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5084*c217d954SCole Faust /*! \class Image2DArray
5085*c217d954SCole Faust * \brief Image interface for arrays of 2D images.
5086*c217d954SCole Faust */
5087*c217d954SCole Faust class Image2DArray : public Image
5088*c217d954SCole Faust {
5089*c217d954SCole Faust public:
Image2DArray(const Context & context,cl_mem_flags flags,ImageFormat format,size_type arraySize,size_type width,size_type height,size_type rowPitch,size_type slicePitch,void * host_ptr=NULL,cl_int * err=NULL)5090*c217d954SCole Faust Image2DArray(
5091*c217d954SCole Faust const Context& context,
5092*c217d954SCole Faust cl_mem_flags flags,
5093*c217d954SCole Faust ImageFormat format,
5094*c217d954SCole Faust size_type arraySize,
5095*c217d954SCole Faust size_type width,
5096*c217d954SCole Faust size_type height,
5097*c217d954SCole Faust size_type rowPitch,
5098*c217d954SCole Faust size_type slicePitch,
5099*c217d954SCole Faust void* host_ptr = NULL,
5100*c217d954SCole Faust cl_int* err = NULL)
5101*c217d954SCole Faust {
5102*c217d954SCole Faust cl_int error;
5103*c217d954SCole Faust
5104*c217d954SCole Faust cl_image_desc desc = {0};
5105*c217d954SCole Faust desc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
5106*c217d954SCole Faust desc.image_width = width;
5107*c217d954SCole Faust desc.image_height = height;
5108*c217d954SCole Faust desc.image_array_size = arraySize;
5109*c217d954SCole Faust desc.image_row_pitch = rowPitch;
5110*c217d954SCole Faust desc.image_slice_pitch = slicePitch;
5111*c217d954SCole Faust
5112*c217d954SCole Faust object_ = ::clCreateImage(
5113*c217d954SCole Faust context(),
5114*c217d954SCole Faust flags,
5115*c217d954SCole Faust &format,
5116*c217d954SCole Faust &desc,
5117*c217d954SCole Faust host_ptr,
5118*c217d954SCole Faust &error);
5119*c217d954SCole Faust
5120*c217d954SCole Faust detail::errHandler(error, __CREATE_IMAGE_ERR);
5121*c217d954SCole Faust if (err != NULL) {
5122*c217d954SCole Faust *err = error;
5123*c217d954SCole Faust }
5124*c217d954SCole Faust }
5125*c217d954SCole Faust
Image2DArray()5126*c217d954SCole Faust Image2DArray() { }
5127*c217d954SCole Faust
5128*c217d954SCole Faust /*! \brief Constructor from cl_mem - takes ownership.
5129*c217d954SCole Faust *
5130*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
5131*c217d954SCole Faust * Defaults to false to maintain compatibility with
5132*c217d954SCole Faust * earlier versions.
5133*c217d954SCole Faust * See Memory for further details.
5134*c217d954SCole Faust */
Image2DArray(const cl_mem & imageArray,bool retainObject=false)5135*c217d954SCole Faust explicit Image2DArray(const cl_mem& imageArray, bool retainObject = false) : Image(imageArray, retainObject) { }
5136*c217d954SCole Faust
operator =(const cl_mem & rhs)5137*c217d954SCole Faust Image2DArray& operator = (const cl_mem& rhs)
5138*c217d954SCole Faust {
5139*c217d954SCole Faust Image::operator=(rhs);
5140*c217d954SCole Faust return *this;
5141*c217d954SCole Faust }
5142*c217d954SCole Faust
5143*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
5144*c217d954SCole Faust * Required for MSVC.
5145*c217d954SCole Faust */
Image2DArray(const Image2DArray & img)5146*c217d954SCole Faust Image2DArray(const Image2DArray& img) : Image(img) {}
5147*c217d954SCole Faust
5148*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
5149*c217d954SCole Faust * Required for MSVC.
5150*c217d954SCole Faust */
operator =(const Image2DArray & img)5151*c217d954SCole Faust Image2DArray& operator = (const Image2DArray &img)
5152*c217d954SCole Faust {
5153*c217d954SCole Faust Image::operator=(img);
5154*c217d954SCole Faust return *this;
5155*c217d954SCole Faust }
5156*c217d954SCole Faust
5157*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
5158*c217d954SCole Faust * Required for MSVC.
5159*c217d954SCole Faust */
Image2DArray(Image2DArray && img)5160*c217d954SCole Faust Image2DArray(Image2DArray&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5161*c217d954SCole Faust
5162*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
5163*c217d954SCole Faust * Required for MSVC.
5164*c217d954SCole Faust */
operator =(Image2DArray && img)5165*c217d954SCole Faust Image2DArray& operator = (Image2DArray &&img)
5166*c217d954SCole Faust {
5167*c217d954SCole Faust Image::operator=(std::move(img));
5168*c217d954SCole Faust return *this;
5169*c217d954SCole Faust }
5170*c217d954SCole Faust };
5171*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5172*c217d954SCole Faust
5173*c217d954SCole Faust /*! \brief Class interface for 3D Image Memory objects.
5174*c217d954SCole Faust *
5175*c217d954SCole Faust * See Memory for details about copy semantics, etc.
5176*c217d954SCole Faust *
5177*c217d954SCole Faust * \see Memory
5178*c217d954SCole Faust */
5179*c217d954SCole Faust class Image3D : public Image
5180*c217d954SCole Faust {
5181*c217d954SCole Faust public:
5182*c217d954SCole Faust /*! \brief Constructs a 3D Image in a specified context.
5183*c217d954SCole Faust *
5184*c217d954SCole Faust * Wraps clCreateImage().
5185*c217d954SCole Faust */
Image3D(const Context & context,cl_mem_flags flags,ImageFormat format,size_type width,size_type height,size_type depth,size_type row_pitch=0,size_type slice_pitch=0,void * host_ptr=NULL,cl_int * err=NULL)5186*c217d954SCole Faust Image3D(
5187*c217d954SCole Faust const Context& context,
5188*c217d954SCole Faust cl_mem_flags flags,
5189*c217d954SCole Faust ImageFormat format,
5190*c217d954SCole Faust size_type width,
5191*c217d954SCole Faust size_type height,
5192*c217d954SCole Faust size_type depth,
5193*c217d954SCole Faust size_type row_pitch = 0,
5194*c217d954SCole Faust size_type slice_pitch = 0,
5195*c217d954SCole Faust void* host_ptr = NULL,
5196*c217d954SCole Faust cl_int* err = NULL)
5197*c217d954SCole Faust {
5198*c217d954SCole Faust cl_int error;
5199*c217d954SCole Faust bool useCreateImage;
5200*c217d954SCole Faust
5201*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120 && CL_HPP_MINIMUM_OPENCL_VERSION < 120
5202*c217d954SCole Faust // Run-time decision based on the actual platform
5203*c217d954SCole Faust {
5204*c217d954SCole Faust cl_uint version = detail::getContextPlatformVersion(context());
5205*c217d954SCole Faust useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
5206*c217d954SCole Faust }
5207*c217d954SCole Faust #elif CL_HPP_TARGET_OPENCL_VERSION >= 120
5208*c217d954SCole Faust useCreateImage = true;
5209*c217d954SCole Faust #else
5210*c217d954SCole Faust useCreateImage = false;
5211*c217d954SCole Faust #endif
5212*c217d954SCole Faust
5213*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5214*c217d954SCole Faust if (useCreateImage)
5215*c217d954SCole Faust {
5216*c217d954SCole Faust cl_image_desc desc = {0};
5217*c217d954SCole Faust desc.image_type = CL_MEM_OBJECT_IMAGE3D;
5218*c217d954SCole Faust desc.image_width = width;
5219*c217d954SCole Faust desc.image_height = height;
5220*c217d954SCole Faust desc.image_depth = depth;
5221*c217d954SCole Faust desc.image_row_pitch = row_pitch;
5222*c217d954SCole Faust desc.image_slice_pitch = slice_pitch;
5223*c217d954SCole Faust
5224*c217d954SCole Faust object_ = ::clCreateImage(
5225*c217d954SCole Faust context(),
5226*c217d954SCole Faust flags,
5227*c217d954SCole Faust &format,
5228*c217d954SCole Faust &desc,
5229*c217d954SCole Faust host_ptr,
5230*c217d954SCole Faust &error);
5231*c217d954SCole Faust
5232*c217d954SCole Faust detail::errHandler(error, __CREATE_IMAGE_ERR);
5233*c217d954SCole Faust if (err != NULL) {
5234*c217d954SCole Faust *err = error;
5235*c217d954SCole Faust }
5236*c217d954SCole Faust }
5237*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5238*c217d954SCole Faust #if CL_HPP_MINIMUM_OPENCL_VERSION < 120
5239*c217d954SCole Faust if (!useCreateImage)
5240*c217d954SCole Faust {
5241*c217d954SCole Faust object_ = ::clCreateImage3D(
5242*c217d954SCole Faust context(), flags, &format, width, height, depth, row_pitch,
5243*c217d954SCole Faust slice_pitch, host_ptr, &error);
5244*c217d954SCole Faust
5245*c217d954SCole Faust detail::errHandler(error, __CREATE_IMAGE3D_ERR);
5246*c217d954SCole Faust if (err != NULL) {
5247*c217d954SCole Faust *err = error;
5248*c217d954SCole Faust }
5249*c217d954SCole Faust }
5250*c217d954SCole Faust #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 120
5251*c217d954SCole Faust }
5252*c217d954SCole Faust
5253*c217d954SCole Faust //! \brief Default constructor - initializes to NULL.
Image3D()5254*c217d954SCole Faust Image3D() : Image() { }
5255*c217d954SCole Faust
5256*c217d954SCole Faust /*! \brief Constructor from cl_mem - takes ownership.
5257*c217d954SCole Faust *
5258*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
5259*c217d954SCole Faust * Defaults to false to maintain compatibility with
5260*c217d954SCole Faust * earlier versions.
5261*c217d954SCole Faust * See Memory for further details.
5262*c217d954SCole Faust */
Image3D(const cl_mem & image3D,bool retainObject=false)5263*c217d954SCole Faust explicit Image3D(const cl_mem& image3D, bool retainObject = false) :
5264*c217d954SCole Faust Image(image3D, retainObject) { }
5265*c217d954SCole Faust
5266*c217d954SCole Faust /*! \brief Assignment from cl_mem - performs shallow copy.
5267*c217d954SCole Faust *
5268*c217d954SCole Faust * See Memory for further details.
5269*c217d954SCole Faust */
operator =(const cl_mem & rhs)5270*c217d954SCole Faust Image3D& operator = (const cl_mem& rhs)
5271*c217d954SCole Faust {
5272*c217d954SCole Faust Image::operator=(rhs);
5273*c217d954SCole Faust return *this;
5274*c217d954SCole Faust }
5275*c217d954SCole Faust
5276*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
5277*c217d954SCole Faust * Required for MSVC.
5278*c217d954SCole Faust */
Image3D(const Image3D & img)5279*c217d954SCole Faust Image3D(const Image3D& img) : Image(img) {}
5280*c217d954SCole Faust
5281*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
5282*c217d954SCole Faust * Required for MSVC.
5283*c217d954SCole Faust */
operator =(const Image3D & img)5284*c217d954SCole Faust Image3D& operator = (const Image3D &img)
5285*c217d954SCole Faust {
5286*c217d954SCole Faust Image::operator=(img);
5287*c217d954SCole Faust return *this;
5288*c217d954SCole Faust }
5289*c217d954SCole Faust
5290*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
5291*c217d954SCole Faust * Required for MSVC.
5292*c217d954SCole Faust */
Image3D(Image3D && img)5293*c217d954SCole Faust Image3D(Image3D&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5294*c217d954SCole Faust
5295*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
5296*c217d954SCole Faust * Required for MSVC.
5297*c217d954SCole Faust */
operator =(Image3D && img)5298*c217d954SCole Faust Image3D& operator = (Image3D &&img)
5299*c217d954SCole Faust {
5300*c217d954SCole Faust Image::operator=(std::move(img));
5301*c217d954SCole Faust return *this;
5302*c217d954SCole Faust }
5303*c217d954SCole Faust };
5304*c217d954SCole Faust
5305*c217d954SCole Faust #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
5306*c217d954SCole Faust /*! \brief Class interface for GL 3D Image Memory objects.
5307*c217d954SCole Faust *
5308*c217d954SCole Faust * This is provided to facilitate interoperability with OpenGL.
5309*c217d954SCole Faust *
5310*c217d954SCole Faust * See Memory for details about copy semantics, etc.
5311*c217d954SCole Faust *
5312*c217d954SCole Faust * \see Memory
5313*c217d954SCole Faust */
5314*c217d954SCole Faust class Image3DGL : public Image3D
5315*c217d954SCole Faust {
5316*c217d954SCole Faust public:
5317*c217d954SCole Faust /*! \brief Constructs an Image3DGL in a specified context, from a given
5318*c217d954SCole Faust * GL Texture.
5319*c217d954SCole Faust *
5320*c217d954SCole Faust * Wraps clCreateFromGLTexture3D().
5321*c217d954SCole Faust */
Image3DGL(const Context & context,cl_mem_flags flags,cl_GLenum target,cl_GLint miplevel,cl_GLuint texobj,cl_int * err=NULL)5322*c217d954SCole Faust Image3DGL(
5323*c217d954SCole Faust const Context& context,
5324*c217d954SCole Faust cl_mem_flags flags,
5325*c217d954SCole Faust cl_GLenum target,
5326*c217d954SCole Faust cl_GLint miplevel,
5327*c217d954SCole Faust cl_GLuint texobj,
5328*c217d954SCole Faust cl_int * err = NULL)
5329*c217d954SCole Faust {
5330*c217d954SCole Faust cl_int error;
5331*c217d954SCole Faust object_ = ::clCreateFromGLTexture3D(
5332*c217d954SCole Faust context(),
5333*c217d954SCole Faust flags,
5334*c217d954SCole Faust target,
5335*c217d954SCole Faust miplevel,
5336*c217d954SCole Faust texobj,
5337*c217d954SCole Faust &error);
5338*c217d954SCole Faust
5339*c217d954SCole Faust detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR);
5340*c217d954SCole Faust if (err != NULL) {
5341*c217d954SCole Faust *err = error;
5342*c217d954SCole Faust }
5343*c217d954SCole Faust }
5344*c217d954SCole Faust
5345*c217d954SCole Faust //! \brief Default constructor - initializes to NULL.
Image3DGL()5346*c217d954SCole Faust Image3DGL() : Image3D() { }
5347*c217d954SCole Faust
5348*c217d954SCole Faust /*! \brief Constructor from cl_mem - takes ownership.
5349*c217d954SCole Faust *
5350*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
5351*c217d954SCole Faust * Defaults to false to maintain compatibility with
5352*c217d954SCole Faust * earlier versions.
5353*c217d954SCole Faust * See Memory for further details.
5354*c217d954SCole Faust */
Image3DGL(const cl_mem & image,bool retainObject=false)5355*c217d954SCole Faust explicit Image3DGL(const cl_mem& image, bool retainObject = false) :
5356*c217d954SCole Faust Image3D(image, retainObject) { }
5357*c217d954SCole Faust
5358*c217d954SCole Faust /*! \brief Assignment from cl_mem - performs shallow copy.
5359*c217d954SCole Faust *
5360*c217d954SCole Faust * See Memory for further details.
5361*c217d954SCole Faust */
operator =(const cl_mem & rhs)5362*c217d954SCole Faust Image3DGL& operator = (const cl_mem& rhs)
5363*c217d954SCole Faust {
5364*c217d954SCole Faust Image3D::operator=(rhs);
5365*c217d954SCole Faust return *this;
5366*c217d954SCole Faust }
5367*c217d954SCole Faust
5368*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
5369*c217d954SCole Faust * Required for MSVC.
5370*c217d954SCole Faust */
Image3DGL(const Image3DGL & img)5371*c217d954SCole Faust Image3DGL(const Image3DGL& img) : Image3D(img) {}
5372*c217d954SCole Faust
5373*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
5374*c217d954SCole Faust * Required for MSVC.
5375*c217d954SCole Faust */
operator =(const Image3DGL & img)5376*c217d954SCole Faust Image3DGL& operator = (const Image3DGL &img)
5377*c217d954SCole Faust {
5378*c217d954SCole Faust Image3D::operator=(img);
5379*c217d954SCole Faust return *this;
5380*c217d954SCole Faust }
5381*c217d954SCole Faust
5382*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
5383*c217d954SCole Faust * Required for MSVC.
5384*c217d954SCole Faust */
Image3DGL(Image3DGL && img)5385*c217d954SCole Faust Image3DGL(Image3DGL&& img) CL_HPP_NOEXCEPT_ : Image3D(std::move(img)) {}
5386*c217d954SCole Faust
5387*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
5388*c217d954SCole Faust * Required for MSVC.
5389*c217d954SCole Faust */
operator =(Image3DGL && img)5390*c217d954SCole Faust Image3DGL& operator = (Image3DGL &&img)
5391*c217d954SCole Faust {
5392*c217d954SCole Faust Image3D::operator=(std::move(img));
5393*c217d954SCole Faust return *this;
5394*c217d954SCole Faust }
5395*c217d954SCole Faust };
5396*c217d954SCole Faust #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
5397*c217d954SCole Faust
5398*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5399*c217d954SCole Faust /*! \class ImageGL
5400*c217d954SCole Faust * \brief general image interface for GL interop.
5401*c217d954SCole Faust * We abstract the 2D and 3D GL images into a single instance here
5402*c217d954SCole Faust * that wraps all GL sourced images on the grounds that setup information
5403*c217d954SCole Faust * was performed by OpenCL anyway.
5404*c217d954SCole Faust */
5405*c217d954SCole Faust class ImageGL : public Image
5406*c217d954SCole Faust {
5407*c217d954SCole Faust public:
ImageGL(const Context & context,cl_mem_flags flags,cl_GLenum target,cl_GLint miplevel,cl_GLuint texobj,cl_int * err=NULL)5408*c217d954SCole Faust ImageGL(
5409*c217d954SCole Faust const Context& context,
5410*c217d954SCole Faust cl_mem_flags flags,
5411*c217d954SCole Faust cl_GLenum target,
5412*c217d954SCole Faust cl_GLint miplevel,
5413*c217d954SCole Faust cl_GLuint texobj,
5414*c217d954SCole Faust cl_int * err = NULL)
5415*c217d954SCole Faust {
5416*c217d954SCole Faust cl_int error;
5417*c217d954SCole Faust object_ = ::clCreateFromGLTexture(
5418*c217d954SCole Faust context(),
5419*c217d954SCole Faust flags,
5420*c217d954SCole Faust target,
5421*c217d954SCole Faust miplevel,
5422*c217d954SCole Faust texobj,
5423*c217d954SCole Faust &error);
5424*c217d954SCole Faust
5425*c217d954SCole Faust detail::errHandler(error, __CREATE_GL_TEXTURE_ERR);
5426*c217d954SCole Faust if (err != NULL) {
5427*c217d954SCole Faust *err = error;
5428*c217d954SCole Faust }
5429*c217d954SCole Faust }
5430*c217d954SCole Faust
ImageGL()5431*c217d954SCole Faust ImageGL() : Image() { }
5432*c217d954SCole Faust
5433*c217d954SCole Faust /*! \brief Constructor from cl_mem - takes ownership.
5434*c217d954SCole Faust *
5435*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
5436*c217d954SCole Faust * Defaults to false to maintain compatibility with
5437*c217d954SCole Faust * earlier versions.
5438*c217d954SCole Faust * See Memory for further details.
5439*c217d954SCole Faust */
ImageGL(const cl_mem & image,bool retainObject=false)5440*c217d954SCole Faust explicit ImageGL(const cl_mem& image, bool retainObject = false) :
5441*c217d954SCole Faust Image(image, retainObject) { }
5442*c217d954SCole Faust
operator =(const cl_mem & rhs)5443*c217d954SCole Faust ImageGL& operator = (const cl_mem& rhs)
5444*c217d954SCole Faust {
5445*c217d954SCole Faust Image::operator=(rhs);
5446*c217d954SCole Faust return *this;
5447*c217d954SCole Faust }
5448*c217d954SCole Faust
5449*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
5450*c217d954SCole Faust * Required for MSVC.
5451*c217d954SCole Faust */
ImageGL(const ImageGL & img)5452*c217d954SCole Faust ImageGL(const ImageGL& img) : Image(img) {}
5453*c217d954SCole Faust
5454*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
5455*c217d954SCole Faust * Required for MSVC.
5456*c217d954SCole Faust */
operator =(const ImageGL & img)5457*c217d954SCole Faust ImageGL& operator = (const ImageGL &img)
5458*c217d954SCole Faust {
5459*c217d954SCole Faust Image::operator=(img);
5460*c217d954SCole Faust return *this;
5461*c217d954SCole Faust }
5462*c217d954SCole Faust
5463*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
5464*c217d954SCole Faust * Required for MSVC.
5465*c217d954SCole Faust */
ImageGL(ImageGL && img)5466*c217d954SCole Faust ImageGL(ImageGL&& img) CL_HPP_NOEXCEPT_ : Image(std::move(img)) {}
5467*c217d954SCole Faust
5468*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
5469*c217d954SCole Faust * Required for MSVC.
5470*c217d954SCole Faust */
operator =(ImageGL && img)5471*c217d954SCole Faust ImageGL& operator = (ImageGL &&img)
5472*c217d954SCole Faust {
5473*c217d954SCole Faust Image::operator=(std::move(img));
5474*c217d954SCole Faust return *this;
5475*c217d954SCole Faust }
5476*c217d954SCole Faust };
5477*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5478*c217d954SCole Faust
5479*c217d954SCole Faust
5480*c217d954SCole Faust
5481*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5482*c217d954SCole Faust /*! \brief Class interface for Pipe Memory Objects.
5483*c217d954SCole Faust *
5484*c217d954SCole Faust * See Memory for details about copy semantics, etc.
5485*c217d954SCole Faust *
5486*c217d954SCole Faust * \see Memory
5487*c217d954SCole Faust */
5488*c217d954SCole Faust class Pipe : public Memory
5489*c217d954SCole Faust {
5490*c217d954SCole Faust public:
5491*c217d954SCole Faust
5492*c217d954SCole Faust /*! \brief Constructs a Pipe in a specified context.
5493*c217d954SCole Faust *
5494*c217d954SCole Faust * Wraps clCreatePipe().
5495*c217d954SCole Faust * @param context Context in which to create the pipe.
5496*c217d954SCole Faust * @param flags Bitfield. Only CL_MEM_READ_WRITE and CL_MEM_HOST_NO_ACCESS are valid.
5497*c217d954SCole Faust * @param packet_size Size in bytes of a single packet of the pipe.
5498*c217d954SCole Faust * @param max_packets Number of packets that may be stored in the pipe.
5499*c217d954SCole Faust *
5500*c217d954SCole Faust */
Pipe(const Context & context,cl_uint packet_size,cl_uint max_packets,cl_int * err=NULL)5501*c217d954SCole Faust Pipe(
5502*c217d954SCole Faust const Context& context,
5503*c217d954SCole Faust cl_uint packet_size,
5504*c217d954SCole Faust cl_uint max_packets,
5505*c217d954SCole Faust cl_int* err = NULL)
5506*c217d954SCole Faust {
5507*c217d954SCole Faust cl_int error;
5508*c217d954SCole Faust
5509*c217d954SCole Faust cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5510*c217d954SCole Faust object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error);
5511*c217d954SCole Faust
5512*c217d954SCole Faust detail::errHandler(error, __CREATE_PIPE_ERR);
5513*c217d954SCole Faust if (err != NULL) {
5514*c217d954SCole Faust *err = error;
5515*c217d954SCole Faust }
5516*c217d954SCole Faust }
5517*c217d954SCole Faust
5518*c217d954SCole Faust /*! \brief Constructs a Pipe in a the default context.
5519*c217d954SCole Faust *
5520*c217d954SCole Faust * Wraps clCreatePipe().
5521*c217d954SCole Faust * @param flags Bitfield. Only CL_MEM_READ_WRITE and CL_MEM_HOST_NO_ACCESS are valid.
5522*c217d954SCole Faust * @param packet_size Size in bytes of a single packet of the pipe.
5523*c217d954SCole Faust * @param max_packets Number of packets that may be stored in the pipe.
5524*c217d954SCole Faust *
5525*c217d954SCole Faust */
Pipe(cl_uint packet_size,cl_uint max_packets,cl_int * err=NULL)5526*c217d954SCole Faust Pipe(
5527*c217d954SCole Faust cl_uint packet_size,
5528*c217d954SCole Faust cl_uint max_packets,
5529*c217d954SCole Faust cl_int* err = NULL)
5530*c217d954SCole Faust {
5531*c217d954SCole Faust cl_int error;
5532*c217d954SCole Faust
5533*c217d954SCole Faust Context context = Context::getDefault(err);
5534*c217d954SCole Faust
5535*c217d954SCole Faust cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_HOST_NO_ACCESS;
5536*c217d954SCole Faust object_ = ::clCreatePipe(context(), flags, packet_size, max_packets, nullptr, &error);
5537*c217d954SCole Faust
5538*c217d954SCole Faust detail::errHandler(error, __CREATE_PIPE_ERR);
5539*c217d954SCole Faust if (err != NULL) {
5540*c217d954SCole Faust *err = error;
5541*c217d954SCole Faust }
5542*c217d954SCole Faust }
5543*c217d954SCole Faust
5544*c217d954SCole Faust //! \brief Default constructor - initializes to NULL.
Pipe()5545*c217d954SCole Faust Pipe() : Memory() { }
5546*c217d954SCole Faust
5547*c217d954SCole Faust /*! \brief Constructor from cl_mem - takes ownership.
5548*c217d954SCole Faust *
5549*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
5550*c217d954SCole Faust * Defaults to false to maintain compatibility with earlier versions.
5551*c217d954SCole Faust *
5552*c217d954SCole Faust * See Memory for further details.
5553*c217d954SCole Faust */
Pipe(const cl_mem & pipe,bool retainObject=false)5554*c217d954SCole Faust explicit Pipe(const cl_mem& pipe, bool retainObject = false) :
5555*c217d954SCole Faust Memory(pipe, retainObject) { }
5556*c217d954SCole Faust
5557*c217d954SCole Faust /*! \brief Assignment from cl_mem - performs shallow copy.
5558*c217d954SCole Faust *
5559*c217d954SCole Faust * See Memory for further details.
5560*c217d954SCole Faust */
operator =(const cl_mem & rhs)5561*c217d954SCole Faust Pipe& operator = (const cl_mem& rhs)
5562*c217d954SCole Faust {
5563*c217d954SCole Faust Memory::operator=(rhs);
5564*c217d954SCole Faust return *this;
5565*c217d954SCole Faust }
5566*c217d954SCole Faust
5567*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
5568*c217d954SCole Faust * Required for MSVC.
5569*c217d954SCole Faust */
Pipe(const Pipe & pipe)5570*c217d954SCole Faust Pipe(const Pipe& pipe) : Memory(pipe) {}
5571*c217d954SCole Faust
5572*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
5573*c217d954SCole Faust * Required for MSVC.
5574*c217d954SCole Faust */
operator =(const Pipe & pipe)5575*c217d954SCole Faust Pipe& operator = (const Pipe &pipe)
5576*c217d954SCole Faust {
5577*c217d954SCole Faust Memory::operator=(pipe);
5578*c217d954SCole Faust return *this;
5579*c217d954SCole Faust }
5580*c217d954SCole Faust
5581*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
5582*c217d954SCole Faust * Required for MSVC.
5583*c217d954SCole Faust */
Pipe(Pipe && pipe)5584*c217d954SCole Faust Pipe(Pipe&& pipe) CL_HPP_NOEXCEPT_ : Memory(std::move(pipe)) {}
5585*c217d954SCole Faust
5586*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
5587*c217d954SCole Faust * Required for MSVC.
5588*c217d954SCole Faust */
operator =(Pipe && pipe)5589*c217d954SCole Faust Pipe& operator = (Pipe &&pipe)
5590*c217d954SCole Faust {
5591*c217d954SCole Faust Memory::operator=(std::move(pipe));
5592*c217d954SCole Faust return *this;
5593*c217d954SCole Faust }
5594*c217d954SCole Faust
5595*c217d954SCole Faust //! \brief Wrapper for clGetMemObjectInfo().
5596*c217d954SCole Faust template <typename T>
getInfo(cl_pipe_info name,T * param) const5597*c217d954SCole Faust cl_int getInfo(cl_pipe_info name, T* param) const
5598*c217d954SCole Faust {
5599*c217d954SCole Faust return detail::errHandler(
5600*c217d954SCole Faust detail::getInfo(&::clGetPipeInfo, object_, name, param),
5601*c217d954SCole Faust __GET_PIPE_INFO_ERR);
5602*c217d954SCole Faust }
5603*c217d954SCole Faust
5604*c217d954SCole Faust //! \brief Wrapper for clGetMemObjectInfo() that returns by value.
5605*c217d954SCole Faust template <cl_pipe_info name> typename
5606*c217d954SCole Faust detail::param_traits<detail::cl_pipe_info, name>::param_type
getInfo(cl_int * err=NULL) const5607*c217d954SCole Faust getInfo(cl_int* err = NULL) const
5608*c217d954SCole Faust {
5609*c217d954SCole Faust typename detail::param_traits<
5610*c217d954SCole Faust detail::cl_pipe_info, name>::param_type param;
5611*c217d954SCole Faust cl_int result = getInfo(name, ¶m);
5612*c217d954SCole Faust if (err != NULL) {
5613*c217d954SCole Faust *err = result;
5614*c217d954SCole Faust }
5615*c217d954SCole Faust return param;
5616*c217d954SCole Faust }
5617*c217d954SCole Faust }; // class Pipe
5618*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
5619*c217d954SCole Faust
5620*c217d954SCole Faust
5621*c217d954SCole Faust /*! \brief Class interface for cl_sampler.
5622*c217d954SCole Faust *
5623*c217d954SCole Faust * \note Copies of these objects are shallow, meaning that the copy will refer
5624*c217d954SCole Faust * to the same underlying cl_sampler as the original. For details, see
5625*c217d954SCole Faust * clRetainSampler() and clReleaseSampler().
5626*c217d954SCole Faust *
5627*c217d954SCole Faust * \see cl_sampler
5628*c217d954SCole Faust */
5629*c217d954SCole Faust class Sampler : public detail::Wrapper<cl_sampler>
5630*c217d954SCole Faust {
5631*c217d954SCole Faust public:
5632*c217d954SCole Faust //! \brief Default constructor - initializes to NULL.
Sampler()5633*c217d954SCole Faust Sampler() { }
5634*c217d954SCole Faust
5635*c217d954SCole Faust /*! \brief Constructs a Sampler in a specified context.
5636*c217d954SCole Faust *
5637*c217d954SCole Faust * Wraps clCreateSampler().
5638*c217d954SCole Faust */
Sampler(const Context & context,cl_bool normalized_coords,cl_addressing_mode addressing_mode,cl_filter_mode filter_mode,cl_int * err=NULL)5639*c217d954SCole Faust Sampler(
5640*c217d954SCole Faust const Context& context,
5641*c217d954SCole Faust cl_bool normalized_coords,
5642*c217d954SCole Faust cl_addressing_mode addressing_mode,
5643*c217d954SCole Faust cl_filter_mode filter_mode,
5644*c217d954SCole Faust cl_int* err = NULL)
5645*c217d954SCole Faust {
5646*c217d954SCole Faust cl_int error;
5647*c217d954SCole Faust
5648*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
5649*c217d954SCole Faust cl_sampler_properties sampler_properties[] = {
5650*c217d954SCole Faust CL_SAMPLER_NORMALIZED_COORDS, normalized_coords,
5651*c217d954SCole Faust CL_SAMPLER_ADDRESSING_MODE, addressing_mode,
5652*c217d954SCole Faust CL_SAMPLER_FILTER_MODE, filter_mode,
5653*c217d954SCole Faust 0 };
5654*c217d954SCole Faust object_ = ::clCreateSamplerWithProperties(
5655*c217d954SCole Faust context(),
5656*c217d954SCole Faust sampler_properties,
5657*c217d954SCole Faust &error);
5658*c217d954SCole Faust
5659*c217d954SCole Faust detail::errHandler(error, __CREATE_SAMPLER_WITH_PROPERTIES_ERR);
5660*c217d954SCole Faust if (err != NULL) {
5661*c217d954SCole Faust *err = error;
5662*c217d954SCole Faust }
5663*c217d954SCole Faust #else
5664*c217d954SCole Faust object_ = ::clCreateSampler(
5665*c217d954SCole Faust context(),
5666*c217d954SCole Faust normalized_coords,
5667*c217d954SCole Faust addressing_mode,
5668*c217d954SCole Faust filter_mode,
5669*c217d954SCole Faust &error);
5670*c217d954SCole Faust
5671*c217d954SCole Faust detail::errHandler(error, __CREATE_SAMPLER_ERR);
5672*c217d954SCole Faust if (err != NULL) {
5673*c217d954SCole Faust *err = error;
5674*c217d954SCole Faust }
5675*c217d954SCole Faust #endif
5676*c217d954SCole Faust }
5677*c217d954SCole Faust
5678*c217d954SCole Faust /*! \brief Constructor from cl_sampler - takes ownership.
5679*c217d954SCole Faust *
5680*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
5681*c217d954SCole Faust * Defaults to false to maintain compatibility with
5682*c217d954SCole Faust * earlier versions.
5683*c217d954SCole Faust * This effectively transfers ownership of a refcount on the cl_sampler
5684*c217d954SCole Faust * into the new Sampler object.
5685*c217d954SCole Faust */
Sampler(const cl_sampler & sampler,bool retainObject=false)5686*c217d954SCole Faust explicit Sampler(const cl_sampler& sampler, bool retainObject = false) :
5687*c217d954SCole Faust detail::Wrapper<cl_type>(sampler, retainObject) { }
5688*c217d954SCole Faust
5689*c217d954SCole Faust /*! \brief Assignment operator from cl_sampler - takes ownership.
5690*c217d954SCole Faust *
5691*c217d954SCole Faust * This effectively transfers ownership of a refcount on the rhs and calls
5692*c217d954SCole Faust * clReleaseSampler() on the value previously held by this instance.
5693*c217d954SCole Faust */
operator =(const cl_sampler & rhs)5694*c217d954SCole Faust Sampler& operator = (const cl_sampler& rhs)
5695*c217d954SCole Faust {
5696*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(rhs);
5697*c217d954SCole Faust return *this;
5698*c217d954SCole Faust }
5699*c217d954SCole Faust
5700*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
5701*c217d954SCole Faust * Required for MSVC.
5702*c217d954SCole Faust */
Sampler(const Sampler & sam)5703*c217d954SCole Faust Sampler(const Sampler& sam) : detail::Wrapper<cl_type>(sam) {}
5704*c217d954SCole Faust
5705*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
5706*c217d954SCole Faust * Required for MSVC.
5707*c217d954SCole Faust */
operator =(const Sampler & sam)5708*c217d954SCole Faust Sampler& operator = (const Sampler &sam)
5709*c217d954SCole Faust {
5710*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(sam);
5711*c217d954SCole Faust return *this;
5712*c217d954SCole Faust }
5713*c217d954SCole Faust
5714*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
5715*c217d954SCole Faust * Required for MSVC.
5716*c217d954SCole Faust */
Sampler(Sampler && sam)5717*c217d954SCole Faust Sampler(Sampler&& sam) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(sam)) {}
5718*c217d954SCole Faust
5719*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
5720*c217d954SCole Faust * Required for MSVC.
5721*c217d954SCole Faust */
operator =(Sampler && sam)5722*c217d954SCole Faust Sampler& operator = (Sampler &&sam)
5723*c217d954SCole Faust {
5724*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(std::move(sam));
5725*c217d954SCole Faust return *this;
5726*c217d954SCole Faust }
5727*c217d954SCole Faust
5728*c217d954SCole Faust //! \brief Wrapper for clGetSamplerInfo().
5729*c217d954SCole Faust template <typename T>
getInfo(cl_sampler_info name,T * param) const5730*c217d954SCole Faust cl_int getInfo(cl_sampler_info name, T* param) const
5731*c217d954SCole Faust {
5732*c217d954SCole Faust return detail::errHandler(
5733*c217d954SCole Faust detail::getInfo(&::clGetSamplerInfo, object_, name, param),
5734*c217d954SCole Faust __GET_SAMPLER_INFO_ERR);
5735*c217d954SCole Faust }
5736*c217d954SCole Faust
5737*c217d954SCole Faust //! \brief Wrapper for clGetSamplerInfo() that returns by value.
5738*c217d954SCole Faust template <cl_sampler_info name> typename
5739*c217d954SCole Faust detail::param_traits<detail::cl_sampler_info, name>::param_type
getInfo(cl_int * err=NULL) const5740*c217d954SCole Faust getInfo(cl_int* err = NULL) const
5741*c217d954SCole Faust {
5742*c217d954SCole Faust typename detail::param_traits<
5743*c217d954SCole Faust detail::cl_sampler_info, name>::param_type param;
5744*c217d954SCole Faust cl_int result = getInfo(name, ¶m);
5745*c217d954SCole Faust if (err != NULL) {
5746*c217d954SCole Faust *err = result;
5747*c217d954SCole Faust }
5748*c217d954SCole Faust return param;
5749*c217d954SCole Faust }
5750*c217d954SCole Faust };
5751*c217d954SCole Faust
5752*c217d954SCole Faust class Program;
5753*c217d954SCole Faust class CommandQueue;
5754*c217d954SCole Faust class DeviceCommandQueue;
5755*c217d954SCole Faust class Kernel;
5756*c217d954SCole Faust
5757*c217d954SCole Faust //! \brief Class interface for specifying NDRange values.
5758*c217d954SCole Faust class NDRange
5759*c217d954SCole Faust {
5760*c217d954SCole Faust private:
5761*c217d954SCole Faust size_type sizes_[3];
5762*c217d954SCole Faust cl_uint dimensions_;
5763*c217d954SCole Faust
5764*c217d954SCole Faust public:
5765*c217d954SCole Faust //! \brief Default constructor - resulting range has zero dimensions.
NDRange()5766*c217d954SCole Faust NDRange()
5767*c217d954SCole Faust : dimensions_(0)
5768*c217d954SCole Faust {
5769*c217d954SCole Faust sizes_[0] = 0;
5770*c217d954SCole Faust sizes_[1] = 0;
5771*c217d954SCole Faust sizes_[2] = 0;
5772*c217d954SCole Faust }
5773*c217d954SCole Faust
5774*c217d954SCole Faust //! \brief Constructs one-dimensional range.
NDRange(size_type size0)5775*c217d954SCole Faust NDRange(size_type size0)
5776*c217d954SCole Faust : dimensions_(1)
5777*c217d954SCole Faust {
5778*c217d954SCole Faust sizes_[0] = size0;
5779*c217d954SCole Faust sizes_[1] = 1;
5780*c217d954SCole Faust sizes_[2] = 1;
5781*c217d954SCole Faust }
5782*c217d954SCole Faust
5783*c217d954SCole Faust //! \brief Constructs two-dimensional range.
NDRange(size_type size0,size_type size1)5784*c217d954SCole Faust NDRange(size_type size0, size_type size1)
5785*c217d954SCole Faust : dimensions_(2)
5786*c217d954SCole Faust {
5787*c217d954SCole Faust sizes_[0] = size0;
5788*c217d954SCole Faust sizes_[1] = size1;
5789*c217d954SCole Faust sizes_[2] = 1;
5790*c217d954SCole Faust }
5791*c217d954SCole Faust
5792*c217d954SCole Faust //! \brief Constructs three-dimensional range.
NDRange(size_type size0,size_type size1,size_type size2)5793*c217d954SCole Faust NDRange(size_type size0, size_type size1, size_type size2)
5794*c217d954SCole Faust : dimensions_(3)
5795*c217d954SCole Faust {
5796*c217d954SCole Faust sizes_[0] = size0;
5797*c217d954SCole Faust sizes_[1] = size1;
5798*c217d954SCole Faust sizes_[2] = size2;
5799*c217d954SCole Faust }
5800*c217d954SCole Faust
5801*c217d954SCole Faust /*! \brief Conversion operator to const size_type *.
5802*c217d954SCole Faust *
5803*c217d954SCole Faust * \returns a pointer to the size of the first dimension.
5804*c217d954SCole Faust */
operator const size_type*() const5805*c217d954SCole Faust operator const size_type*() const {
5806*c217d954SCole Faust return sizes_;
5807*c217d954SCole Faust }
5808*c217d954SCole Faust
5809*c217d954SCole Faust //! \brief Queries the number of dimensions in the range.
dimensions() const5810*c217d954SCole Faust size_type dimensions() const
5811*c217d954SCole Faust {
5812*c217d954SCole Faust return dimensions_;
5813*c217d954SCole Faust }
5814*c217d954SCole Faust
5815*c217d954SCole Faust //! \brief Returns the size of the object in bytes based on the
5816*c217d954SCole Faust // runtime number of dimensions
size() const5817*c217d954SCole Faust size_type size() const
5818*c217d954SCole Faust {
5819*c217d954SCole Faust return dimensions_*sizeof(size_type);
5820*c217d954SCole Faust }
5821*c217d954SCole Faust
get()5822*c217d954SCole Faust size_type* get()
5823*c217d954SCole Faust {
5824*c217d954SCole Faust return sizes_;
5825*c217d954SCole Faust }
5826*c217d954SCole Faust
get() const5827*c217d954SCole Faust const size_type* get() const
5828*c217d954SCole Faust {
5829*c217d954SCole Faust return sizes_;
5830*c217d954SCole Faust }
5831*c217d954SCole Faust };
5832*c217d954SCole Faust
5833*c217d954SCole Faust //! \brief A zero-dimensional range.
5834*c217d954SCole Faust static const NDRange NullRange;
5835*c217d954SCole Faust
5836*c217d954SCole Faust //! \brief Local address wrapper for use with Kernel::setArg
5837*c217d954SCole Faust struct LocalSpaceArg
5838*c217d954SCole Faust {
5839*c217d954SCole Faust size_type size_;
5840*c217d954SCole Faust };
5841*c217d954SCole Faust
5842*c217d954SCole Faust namespace detail {
5843*c217d954SCole Faust
5844*c217d954SCole Faust template <typename T, class Enable = void>
5845*c217d954SCole Faust struct KernelArgumentHandler;
5846*c217d954SCole Faust
5847*c217d954SCole Faust // Enable for objects that are not subclasses of memory
5848*c217d954SCole Faust // Pointers, constants etc
5849*c217d954SCole Faust template <typename T>
5850*c217d954SCole Faust struct KernelArgumentHandler<T, typename std::enable_if<!std::is_base_of<cl::Memory, T>::value>::type>
5851*c217d954SCole Faust {
sizecl::detail::KernelArgumentHandler5852*c217d954SCole Faust static size_type size(const T&) { return sizeof(T); }
ptrcl::detail::KernelArgumentHandler5853*c217d954SCole Faust static const T* ptr(const T& value) { return &value; }
5854*c217d954SCole Faust };
5855*c217d954SCole Faust
5856*c217d954SCole Faust // Enable for subclasses of memory where we want to get a reference to the cl_mem out
5857*c217d954SCole Faust // and pass that in for safety
5858*c217d954SCole Faust template <typename T>
5859*c217d954SCole Faust struct KernelArgumentHandler<T, typename std::enable_if<std::is_base_of<cl::Memory, T>::value>::type>
5860*c217d954SCole Faust {
sizecl::detail::KernelArgumentHandler5861*c217d954SCole Faust static size_type size(const T&) { return sizeof(cl_mem); }
ptrcl::detail::KernelArgumentHandler5862*c217d954SCole Faust static const cl_mem* ptr(const T& value) { return &(value()); }
5863*c217d954SCole Faust };
5864*c217d954SCole Faust
5865*c217d954SCole Faust // Specialization for DeviceCommandQueue defined later
5866*c217d954SCole Faust
5867*c217d954SCole Faust template <>
5868*c217d954SCole Faust struct KernelArgumentHandler<LocalSpaceArg, void>
5869*c217d954SCole Faust {
sizecl::detail::KernelArgumentHandler5870*c217d954SCole Faust static size_type size(const LocalSpaceArg& value) { return value.size_; }
ptrcl::detail::KernelArgumentHandler5871*c217d954SCole Faust static const void* ptr(const LocalSpaceArg&) { return NULL; }
5872*c217d954SCole Faust };
5873*c217d954SCole Faust
5874*c217d954SCole Faust }
5875*c217d954SCole Faust //! \endcond
5876*c217d954SCole Faust
5877*c217d954SCole Faust /*! Local
5878*c217d954SCole Faust * \brief Helper function for generating LocalSpaceArg objects.
5879*c217d954SCole Faust */
5880*c217d954SCole Faust inline LocalSpaceArg
Local(size_type size)5881*c217d954SCole Faust Local(size_type size)
5882*c217d954SCole Faust {
5883*c217d954SCole Faust LocalSpaceArg ret = { size };
5884*c217d954SCole Faust return ret;
5885*c217d954SCole Faust }
5886*c217d954SCole Faust
5887*c217d954SCole Faust /*! \brief Class interface for cl_kernel.
5888*c217d954SCole Faust *
5889*c217d954SCole Faust * \note Copies of these objects are shallow, meaning that the copy will refer
5890*c217d954SCole Faust * to the same underlying cl_kernel as the original. For details, see
5891*c217d954SCole Faust * clRetainKernel() and clReleaseKernel().
5892*c217d954SCole Faust *
5893*c217d954SCole Faust * \see cl_kernel
5894*c217d954SCole Faust */
5895*c217d954SCole Faust class Kernel : public detail::Wrapper<cl_kernel>
5896*c217d954SCole Faust {
5897*c217d954SCole Faust public:
5898*c217d954SCole Faust inline Kernel(const Program& program, const char* name, cl_int* err = NULL);
5899*c217d954SCole Faust
5900*c217d954SCole Faust //! \brief Default constructor - initializes to NULL.
Kernel()5901*c217d954SCole Faust Kernel() { }
5902*c217d954SCole Faust
5903*c217d954SCole Faust /*! \brief Constructor from cl_kernel - takes ownership.
5904*c217d954SCole Faust *
5905*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
5906*c217d954SCole Faust * Defaults to false to maintain compatibility with
5907*c217d954SCole Faust * earlier versions.
5908*c217d954SCole Faust * This effectively transfers ownership of a refcount on the cl_kernel
5909*c217d954SCole Faust * into the new Kernel object.
5910*c217d954SCole Faust */
Kernel(const cl_kernel & kernel,bool retainObject=false)5911*c217d954SCole Faust explicit Kernel(const cl_kernel& kernel, bool retainObject = false) :
5912*c217d954SCole Faust detail::Wrapper<cl_type>(kernel, retainObject) { }
5913*c217d954SCole Faust
5914*c217d954SCole Faust /*! \brief Assignment operator from cl_kernel - takes ownership.
5915*c217d954SCole Faust *
5916*c217d954SCole Faust * This effectively transfers ownership of a refcount on the rhs and calls
5917*c217d954SCole Faust * clReleaseKernel() on the value previously held by this instance.
5918*c217d954SCole Faust */
operator =(const cl_kernel & rhs)5919*c217d954SCole Faust Kernel& operator = (const cl_kernel& rhs)
5920*c217d954SCole Faust {
5921*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(rhs);
5922*c217d954SCole Faust return *this;
5923*c217d954SCole Faust }
5924*c217d954SCole Faust
5925*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
5926*c217d954SCole Faust * Required for MSVC.
5927*c217d954SCole Faust */
Kernel(const Kernel & kernel)5928*c217d954SCole Faust Kernel(const Kernel& kernel) : detail::Wrapper<cl_type>(kernel) {}
5929*c217d954SCole Faust
5930*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
5931*c217d954SCole Faust * Required for MSVC.
5932*c217d954SCole Faust */
operator =(const Kernel & kernel)5933*c217d954SCole Faust Kernel& operator = (const Kernel &kernel)
5934*c217d954SCole Faust {
5935*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(kernel);
5936*c217d954SCole Faust return *this;
5937*c217d954SCole Faust }
5938*c217d954SCole Faust
5939*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
5940*c217d954SCole Faust * Required for MSVC.
5941*c217d954SCole Faust */
Kernel(Kernel && kernel)5942*c217d954SCole Faust Kernel(Kernel&& kernel) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(kernel)) {}
5943*c217d954SCole Faust
5944*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
5945*c217d954SCole Faust * Required for MSVC.
5946*c217d954SCole Faust */
operator =(Kernel && kernel)5947*c217d954SCole Faust Kernel& operator = (Kernel &&kernel)
5948*c217d954SCole Faust {
5949*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(std::move(kernel));
5950*c217d954SCole Faust return *this;
5951*c217d954SCole Faust }
5952*c217d954SCole Faust
5953*c217d954SCole Faust template <typename T>
getInfo(cl_kernel_info name,T * param) const5954*c217d954SCole Faust cl_int getInfo(cl_kernel_info name, T* param) const
5955*c217d954SCole Faust {
5956*c217d954SCole Faust return detail::errHandler(
5957*c217d954SCole Faust detail::getInfo(&::clGetKernelInfo, object_, name, param),
5958*c217d954SCole Faust __GET_KERNEL_INFO_ERR);
5959*c217d954SCole Faust }
5960*c217d954SCole Faust
5961*c217d954SCole Faust template <cl_kernel_info name> typename
5962*c217d954SCole Faust detail::param_traits<detail::cl_kernel_info, name>::param_type
getInfo(cl_int * err=NULL) const5963*c217d954SCole Faust getInfo(cl_int* err = NULL) const
5964*c217d954SCole Faust {
5965*c217d954SCole Faust typename detail::param_traits<
5966*c217d954SCole Faust detail::cl_kernel_info, name>::param_type param;
5967*c217d954SCole Faust cl_int result = getInfo(name, ¶m);
5968*c217d954SCole Faust if (err != NULL) {
5969*c217d954SCole Faust *err = result;
5970*c217d954SCole Faust }
5971*c217d954SCole Faust return param;
5972*c217d954SCole Faust }
5973*c217d954SCole Faust
5974*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
5975*c217d954SCole Faust template <typename T>
getArgInfo(cl_uint argIndex,cl_kernel_arg_info name,T * param) const5976*c217d954SCole Faust cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const
5977*c217d954SCole Faust {
5978*c217d954SCole Faust return detail::errHandler(
5979*c217d954SCole Faust detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param),
5980*c217d954SCole Faust __GET_KERNEL_ARG_INFO_ERR);
5981*c217d954SCole Faust }
5982*c217d954SCole Faust
5983*c217d954SCole Faust template <cl_kernel_arg_info name> typename
5984*c217d954SCole Faust detail::param_traits<detail::cl_kernel_arg_info, name>::param_type
getArgInfo(cl_uint argIndex,cl_int * err=NULL) const5985*c217d954SCole Faust getArgInfo(cl_uint argIndex, cl_int* err = NULL) const
5986*c217d954SCole Faust {
5987*c217d954SCole Faust typename detail::param_traits<
5988*c217d954SCole Faust detail::cl_kernel_arg_info, name>::param_type param;
5989*c217d954SCole Faust cl_int result = getArgInfo(argIndex, name, ¶m);
5990*c217d954SCole Faust if (err != NULL) {
5991*c217d954SCole Faust *err = result;
5992*c217d954SCole Faust }
5993*c217d954SCole Faust return param;
5994*c217d954SCole Faust }
5995*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
5996*c217d954SCole Faust
5997*c217d954SCole Faust template <typename T>
getWorkGroupInfo(const Device & device,cl_kernel_work_group_info name,T * param) const5998*c217d954SCole Faust cl_int getWorkGroupInfo(
5999*c217d954SCole Faust const Device& device, cl_kernel_work_group_info name, T* param) const
6000*c217d954SCole Faust {
6001*c217d954SCole Faust return detail::errHandler(
6002*c217d954SCole Faust detail::getInfo(
6003*c217d954SCole Faust &::clGetKernelWorkGroupInfo, object_, device(), name, param),
6004*c217d954SCole Faust __GET_KERNEL_WORK_GROUP_INFO_ERR);
6005*c217d954SCole Faust }
6006*c217d954SCole Faust
6007*c217d954SCole Faust template <cl_kernel_work_group_info name> typename
6008*c217d954SCole Faust detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
getWorkGroupInfo(const Device & device,cl_int * err=NULL) const6009*c217d954SCole Faust getWorkGroupInfo(const Device& device, cl_int* err = NULL) const
6010*c217d954SCole Faust {
6011*c217d954SCole Faust typename detail::param_traits<
6012*c217d954SCole Faust detail::cl_kernel_work_group_info, name>::param_type param;
6013*c217d954SCole Faust cl_int result = getWorkGroupInfo(device, name, ¶m);
6014*c217d954SCole Faust if (err != NULL) {
6015*c217d954SCole Faust *err = result;
6016*c217d954SCole Faust }
6017*c217d954SCole Faust return param;
6018*c217d954SCole Faust }
6019*c217d954SCole Faust
6020*c217d954SCole Faust #if (CL_HPP_TARGET_OPENCL_VERSION >= 200 && defined(CL_HPP_USE_CL_SUB_GROUPS_KHR)) || CL_HPP_TARGET_OPENCL_VERSION >= 210
getSubGroupInfo(const cl::Device & dev,cl_kernel_sub_group_info name,const cl::NDRange & range,size_type * param) const6021*c217d954SCole Faust cl_int getSubGroupInfo(const cl::Device &dev, cl_kernel_sub_group_info name, const cl::NDRange &range, size_type* param) const
6022*c217d954SCole Faust {
6023*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6024*c217d954SCole Faust
6025*c217d954SCole Faust return detail::errHandler(
6026*c217d954SCole Faust clGetKernelSubGroupInfo(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
6027*c217d954SCole Faust __GET_KERNEL_SUB_GROUP_INFO_ERR);
6028*c217d954SCole Faust
6029*c217d954SCole Faust #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6030*c217d954SCole Faust
6031*c217d954SCole Faust typedef clGetKernelSubGroupInfoKHR_fn PFN_clGetKernelSubGroupInfoKHR;
6032*c217d954SCole Faust static PFN_clGetKernelSubGroupInfoKHR pfn_clGetKernelSubGroupInfoKHR = NULL;
6033*c217d954SCole Faust CL_HPP_INIT_CL_EXT_FCN_PTR_(clGetKernelSubGroupInfoKHR);
6034*c217d954SCole Faust
6035*c217d954SCole Faust return detail::errHandler(
6036*c217d954SCole Faust pfn_clGetKernelSubGroupInfoKHR(object_, dev(), name, range.size(), range.get(), sizeof(size_type), param, nullptr),
6037*c217d954SCole Faust __GET_KERNEL_SUB_GROUP_INFO_ERR);
6038*c217d954SCole Faust
6039*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6040*c217d954SCole Faust }
6041*c217d954SCole Faust
6042*c217d954SCole Faust template <cl_kernel_sub_group_info name>
getSubGroupInfo(const cl::Device & dev,const cl::NDRange & range,cl_int * err=NULL) const6043*c217d954SCole Faust size_type getSubGroupInfo(const cl::Device &dev, const cl::NDRange &range, cl_int* err = NULL) const
6044*c217d954SCole Faust {
6045*c217d954SCole Faust size_type param;
6046*c217d954SCole Faust cl_int result = getSubGroupInfo(dev, name, range, ¶m);
6047*c217d954SCole Faust if (err != NULL) {
6048*c217d954SCole Faust *err = result;
6049*c217d954SCole Faust }
6050*c217d954SCole Faust return param;
6051*c217d954SCole Faust }
6052*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6053*c217d954SCole Faust
6054*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6055*c217d954SCole Faust /*! \brief setArg overload taking a shared_ptr type
6056*c217d954SCole Faust */
6057*c217d954SCole Faust template<typename T, class D>
setArg(cl_uint index,const cl::pointer<T,D> & argPtr)6058*c217d954SCole Faust cl_int setArg(cl_uint index, const cl::pointer<T, D> &argPtr)
6059*c217d954SCole Faust {
6060*c217d954SCole Faust return detail::errHandler(
6061*c217d954SCole Faust ::clSetKernelArgSVMPointer(object_, index, argPtr.get()),
6062*c217d954SCole Faust __SET_KERNEL_ARGS_ERR);
6063*c217d954SCole Faust }
6064*c217d954SCole Faust
6065*c217d954SCole Faust /*! \brief setArg overload taking a vector type.
6066*c217d954SCole Faust */
6067*c217d954SCole Faust template<typename T, class Alloc>
setArg(cl_uint index,const cl::vector<T,Alloc> & argPtr)6068*c217d954SCole Faust cl_int setArg(cl_uint index, const cl::vector<T, Alloc> &argPtr)
6069*c217d954SCole Faust {
6070*c217d954SCole Faust return detail::errHandler(
6071*c217d954SCole Faust ::clSetKernelArgSVMPointer(object_, index, argPtr.data()),
6072*c217d954SCole Faust __SET_KERNEL_ARGS_ERR);
6073*c217d954SCole Faust }
6074*c217d954SCole Faust
6075*c217d954SCole Faust /*! \brief setArg overload taking a pointer type
6076*c217d954SCole Faust */
6077*c217d954SCole Faust template<typename T>
6078*c217d954SCole Faust typename std::enable_if<std::is_pointer<T>::value, cl_int>::type
setArg(cl_uint index,const T argPtr)6079*c217d954SCole Faust setArg(cl_uint index, const T argPtr)
6080*c217d954SCole Faust {
6081*c217d954SCole Faust return detail::errHandler(
6082*c217d954SCole Faust ::clSetKernelArgSVMPointer(object_, index, argPtr),
6083*c217d954SCole Faust __SET_KERNEL_ARGS_ERR);
6084*c217d954SCole Faust }
6085*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6086*c217d954SCole Faust
6087*c217d954SCole Faust /*! \brief setArg overload taking a POD type
6088*c217d954SCole Faust */
6089*c217d954SCole Faust template <typename T>
6090*c217d954SCole Faust typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
setArg(cl_uint index,const T & value)6091*c217d954SCole Faust setArg(cl_uint index, const T &value)
6092*c217d954SCole Faust {
6093*c217d954SCole Faust return detail::errHandler(
6094*c217d954SCole Faust ::clSetKernelArg(
6095*c217d954SCole Faust object_,
6096*c217d954SCole Faust index,
6097*c217d954SCole Faust detail::KernelArgumentHandler<T>::size(value),
6098*c217d954SCole Faust detail::KernelArgumentHandler<T>::ptr(value)),
6099*c217d954SCole Faust __SET_KERNEL_ARGS_ERR);
6100*c217d954SCole Faust }
6101*c217d954SCole Faust
setArg(cl_uint index,size_type size,const void * argPtr)6102*c217d954SCole Faust cl_int setArg(cl_uint index, size_type size, const void* argPtr)
6103*c217d954SCole Faust {
6104*c217d954SCole Faust return detail::errHandler(
6105*c217d954SCole Faust ::clSetKernelArg(object_, index, size, argPtr),
6106*c217d954SCole Faust __SET_KERNEL_ARGS_ERR);
6107*c217d954SCole Faust }
6108*c217d954SCole Faust
6109*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6110*c217d954SCole Faust /*!
6111*c217d954SCole Faust * Specify a vector of SVM pointers that the kernel may access in
6112*c217d954SCole Faust * addition to its arguments.
6113*c217d954SCole Faust */
setSVMPointers(const vector<void * > & pointerList)6114*c217d954SCole Faust cl_int setSVMPointers(const vector<void*> &pointerList)
6115*c217d954SCole Faust {
6116*c217d954SCole Faust return detail::errHandler(
6117*c217d954SCole Faust ::clSetKernelExecInfo(
6118*c217d954SCole Faust object_,
6119*c217d954SCole Faust CL_KERNEL_EXEC_INFO_SVM_PTRS,
6120*c217d954SCole Faust sizeof(void*)*pointerList.size(),
6121*c217d954SCole Faust pointerList.data()));
6122*c217d954SCole Faust }
6123*c217d954SCole Faust
6124*c217d954SCole Faust /*!
6125*c217d954SCole Faust * Specify a std::array of SVM pointers that the kernel may access in
6126*c217d954SCole Faust * addition to its arguments.
6127*c217d954SCole Faust */
6128*c217d954SCole Faust template<int ArrayLength>
setSVMPointers(const std::array<void *,ArrayLength> & pointerList)6129*c217d954SCole Faust cl_int setSVMPointers(const std::array<void*, ArrayLength> &pointerList)
6130*c217d954SCole Faust {
6131*c217d954SCole Faust return detail::errHandler(
6132*c217d954SCole Faust ::clSetKernelExecInfo(
6133*c217d954SCole Faust object_,
6134*c217d954SCole Faust CL_KERNEL_EXEC_INFO_SVM_PTRS,
6135*c217d954SCole Faust sizeof(void*)*pointerList.size(),
6136*c217d954SCole Faust pointerList.data()));
6137*c217d954SCole Faust }
6138*c217d954SCole Faust
6139*c217d954SCole Faust /*! \brief Enable fine-grained system SVM.
6140*c217d954SCole Faust *
6141*c217d954SCole Faust * \note It is only possible to enable fine-grained system SVM if all devices
6142*c217d954SCole Faust * in the context associated with kernel support it.
6143*c217d954SCole Faust *
6144*c217d954SCole Faust * \param svmEnabled True if fine-grained system SVM is requested. False otherwise.
6145*c217d954SCole Faust * \return CL_SUCCESS if the function was executed succesfully. CL_INVALID_OPERATION
6146*c217d954SCole Faust * if no devices in the context support fine-grained system SVM.
6147*c217d954SCole Faust *
6148*c217d954SCole Faust * \see clSetKernelExecInfo
6149*c217d954SCole Faust */
enableFineGrainedSystemSVM(bool svmEnabled)6150*c217d954SCole Faust cl_int enableFineGrainedSystemSVM(bool svmEnabled)
6151*c217d954SCole Faust {
6152*c217d954SCole Faust cl_bool svmEnabled_ = svmEnabled ? CL_TRUE : CL_FALSE;
6153*c217d954SCole Faust return detail::errHandler(
6154*c217d954SCole Faust ::clSetKernelExecInfo(
6155*c217d954SCole Faust object_,
6156*c217d954SCole Faust CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM,
6157*c217d954SCole Faust sizeof(cl_bool),
6158*c217d954SCole Faust &svmEnabled_
6159*c217d954SCole Faust )
6160*c217d954SCole Faust );
6161*c217d954SCole Faust }
6162*c217d954SCole Faust
6163*c217d954SCole Faust template<int index, int ArrayLength, class D, typename T0, typename T1, typename... Ts>
setSVMPointersHelper(std::array<void *,ArrayLength> & pointerList,const pointer<T0,D> & t0,const pointer<T1,D> & t1,Ts &...ts)6164*c217d954SCole Faust void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0, const pointer<T1, D> &t1, Ts & ... ts)
6165*c217d954SCole Faust {
6166*c217d954SCole Faust pointerList[index] = static_cast<void*>(t0.get());
6167*c217d954SCole Faust setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6168*c217d954SCole Faust }
6169*c217d954SCole Faust
6170*c217d954SCole Faust template<int index, int ArrayLength, typename T0, typename T1, typename... Ts>
6171*c217d954SCole Faust typename std::enable_if<std::is_pointer<T0>::value, void>::type
setSVMPointersHelper(std::array<void *,ArrayLength> & pointerList,T0 t0,T1 t1,Ts...ts)6172*c217d954SCole Faust setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0, T1 t1, Ts... ts)
6173*c217d954SCole Faust {
6174*c217d954SCole Faust pointerList[index] = static_cast<void*>(t0);
6175*c217d954SCole Faust setSVMPointersHelper<index + 1, ArrayLength>(pointerList, t1, ts...);
6176*c217d954SCole Faust }
6177*c217d954SCole Faust
6178*c217d954SCole Faust template<int index, int ArrayLength, typename T0, class D>
setSVMPointersHelper(std::array<void *,ArrayLength> & pointerList,const pointer<T0,D> & t0)6179*c217d954SCole Faust void setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, const pointer<T0, D> &t0)
6180*c217d954SCole Faust {
6181*c217d954SCole Faust pointerList[index] = static_cast<void*>(t0.get());
6182*c217d954SCole Faust }
6183*c217d954SCole Faust
6184*c217d954SCole Faust
6185*c217d954SCole Faust template<int index, int ArrayLength, typename T0>
6186*c217d954SCole Faust typename std::enable_if<std::is_pointer<T0>::value, void>::type
setSVMPointersHelper(std::array<void *,ArrayLength> & pointerList,T0 t0)6187*c217d954SCole Faust setSVMPointersHelper(std::array<void*, ArrayLength> &pointerList, T0 t0)
6188*c217d954SCole Faust {
6189*c217d954SCole Faust pointerList[index] = static_cast<void*>(t0);
6190*c217d954SCole Faust }
6191*c217d954SCole Faust
6192*c217d954SCole Faust template<typename T0, typename... Ts>
setSVMPointers(const T0 & t0,Ts &...ts)6193*c217d954SCole Faust cl_int setSVMPointers(const T0 &t0, Ts & ... ts)
6194*c217d954SCole Faust {
6195*c217d954SCole Faust std::array<void*, 1 + sizeof...(Ts)> pointerList;
6196*c217d954SCole Faust
6197*c217d954SCole Faust setSVMPointersHelper<0, 1 + sizeof...(Ts)>(pointerList, t0, ts...);
6198*c217d954SCole Faust return detail::errHandler(
6199*c217d954SCole Faust ::clSetKernelExecInfo(
6200*c217d954SCole Faust object_,
6201*c217d954SCole Faust CL_KERNEL_EXEC_INFO_SVM_PTRS,
6202*c217d954SCole Faust sizeof(void*)*(1 + sizeof...(Ts)),
6203*c217d954SCole Faust pointerList.data()));
6204*c217d954SCole Faust }
6205*c217d954SCole Faust
6206*c217d954SCole Faust template<typename T>
setExecInfo(cl_kernel_exec_info param_name,const T & val)6207*c217d954SCole Faust cl_int setExecInfo(cl_kernel_exec_info param_name, const T& val)
6208*c217d954SCole Faust {
6209*c217d954SCole Faust return detail::errHandler(
6210*c217d954SCole Faust ::clSetKernelExecInfo(
6211*c217d954SCole Faust object_,
6212*c217d954SCole Faust param_name,
6213*c217d954SCole Faust sizeof(T),
6214*c217d954SCole Faust &val));
6215*c217d954SCole Faust }
6216*c217d954SCole Faust
6217*c217d954SCole Faust template<cl_kernel_exec_info name>
setExecInfo(typename detail::param_traits<detail::cl_kernel_exec_info,name>::param_type & val)6218*c217d954SCole Faust cl_int setExecInfo(typename detail::param_traits<detail::cl_kernel_exec_info, name>::param_type& val)
6219*c217d954SCole Faust {
6220*c217d954SCole Faust return setExecInfo(name, val);
6221*c217d954SCole Faust }
6222*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
6223*c217d954SCole Faust
6224*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6225*c217d954SCole Faust /**
6226*c217d954SCole Faust * Make a deep copy of the kernel object including its arguments.
6227*c217d954SCole Faust * @return A new kernel object with internal state entirely separate from that
6228*c217d954SCole Faust * of the original but with any arguments set on the original intact.
6229*c217d954SCole Faust */
clone()6230*c217d954SCole Faust Kernel clone()
6231*c217d954SCole Faust {
6232*c217d954SCole Faust cl_int error;
6233*c217d954SCole Faust Kernel retValue(clCloneKernel(this->get(), &error));
6234*c217d954SCole Faust
6235*c217d954SCole Faust detail::errHandler(error, __CLONE_KERNEL_ERR);
6236*c217d954SCole Faust return retValue;
6237*c217d954SCole Faust }
6238*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6239*c217d954SCole Faust };
6240*c217d954SCole Faust
6241*c217d954SCole Faust /*! \class Program
6242*c217d954SCole Faust * \brief Program interface that implements cl_program.
6243*c217d954SCole Faust */
6244*c217d954SCole Faust class Program : public detail::Wrapper<cl_program>
6245*c217d954SCole Faust {
6246*c217d954SCole Faust public:
6247*c217d954SCole Faust #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6248*c217d954SCole Faust typedef vector<vector<unsigned char>> Binaries;
6249*c217d954SCole Faust typedef vector<string> Sources;
6250*c217d954SCole Faust #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6251*c217d954SCole Faust typedef vector<std::pair<const void*, size_type> > Binaries;
6252*c217d954SCole Faust typedef vector<std::pair<const char*, size_type> > Sources;
6253*c217d954SCole Faust #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6254*c217d954SCole Faust
Program(const string & source,bool build=false,cl_int * err=NULL)6255*c217d954SCole Faust Program(
6256*c217d954SCole Faust const string& source,
6257*c217d954SCole Faust bool build = false,
6258*c217d954SCole Faust cl_int* err = NULL)
6259*c217d954SCole Faust {
6260*c217d954SCole Faust cl_int error;
6261*c217d954SCole Faust
6262*c217d954SCole Faust const char * strings = source.c_str();
6263*c217d954SCole Faust const size_type length = source.size();
6264*c217d954SCole Faust
6265*c217d954SCole Faust Context context = Context::getDefault(err);
6266*c217d954SCole Faust
6267*c217d954SCole Faust object_ = ::clCreateProgramWithSource(
6268*c217d954SCole Faust context(), (cl_uint)1, &strings, &length, &error);
6269*c217d954SCole Faust
6270*c217d954SCole Faust detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6271*c217d954SCole Faust
6272*c217d954SCole Faust if (error == CL_SUCCESS && build) {
6273*c217d954SCole Faust
6274*c217d954SCole Faust error = ::clBuildProgram(
6275*c217d954SCole Faust object_,
6276*c217d954SCole Faust 0,
6277*c217d954SCole Faust NULL,
6278*c217d954SCole Faust #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6279*c217d954SCole Faust "-cl-std=CL2.0",
6280*c217d954SCole Faust #else
6281*c217d954SCole Faust "",
6282*c217d954SCole Faust #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6283*c217d954SCole Faust NULL,
6284*c217d954SCole Faust NULL);
6285*c217d954SCole Faust
6286*c217d954SCole Faust detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6287*c217d954SCole Faust }
6288*c217d954SCole Faust
6289*c217d954SCole Faust if (err != NULL) {
6290*c217d954SCole Faust *err = error;
6291*c217d954SCole Faust }
6292*c217d954SCole Faust }
6293*c217d954SCole Faust
Program(const Context & context,const string & source,bool build=false,cl_int * err=NULL)6294*c217d954SCole Faust Program(
6295*c217d954SCole Faust const Context& context,
6296*c217d954SCole Faust const string& source,
6297*c217d954SCole Faust bool build = false,
6298*c217d954SCole Faust cl_int* err = NULL)
6299*c217d954SCole Faust {
6300*c217d954SCole Faust cl_int error;
6301*c217d954SCole Faust
6302*c217d954SCole Faust const char * strings = source.c_str();
6303*c217d954SCole Faust const size_type length = source.size();
6304*c217d954SCole Faust
6305*c217d954SCole Faust object_ = ::clCreateProgramWithSource(
6306*c217d954SCole Faust context(), (cl_uint)1, &strings, &length, &error);
6307*c217d954SCole Faust
6308*c217d954SCole Faust detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6309*c217d954SCole Faust
6310*c217d954SCole Faust if (error == CL_SUCCESS && build) {
6311*c217d954SCole Faust error = ::clBuildProgram(
6312*c217d954SCole Faust object_,
6313*c217d954SCole Faust 0,
6314*c217d954SCole Faust NULL,
6315*c217d954SCole Faust #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6316*c217d954SCole Faust "-cl-std=CL2.0",
6317*c217d954SCole Faust #else
6318*c217d954SCole Faust "",
6319*c217d954SCole Faust #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6320*c217d954SCole Faust NULL,
6321*c217d954SCole Faust NULL);
6322*c217d954SCole Faust
6323*c217d954SCole Faust detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6324*c217d954SCole Faust }
6325*c217d954SCole Faust
6326*c217d954SCole Faust if (err != NULL) {
6327*c217d954SCole Faust *err = error;
6328*c217d954SCole Faust }
6329*c217d954SCole Faust }
6330*c217d954SCole Faust
6331*c217d954SCole Faust /**
6332*c217d954SCole Faust * Create a program from a vector of source strings and the default context.
6333*c217d954SCole Faust * Does not compile or link the program.
6334*c217d954SCole Faust */
Program(const Sources & sources,cl_int * err=NULL)6335*c217d954SCole Faust Program(
6336*c217d954SCole Faust const Sources& sources,
6337*c217d954SCole Faust cl_int* err = NULL)
6338*c217d954SCole Faust {
6339*c217d954SCole Faust cl_int error;
6340*c217d954SCole Faust Context context = Context::getDefault(err);
6341*c217d954SCole Faust
6342*c217d954SCole Faust const size_type n = (size_type)sources.size();
6343*c217d954SCole Faust
6344*c217d954SCole Faust vector<size_type> lengths(n);
6345*c217d954SCole Faust vector<const char*> strings(n);
6346*c217d954SCole Faust
6347*c217d954SCole Faust for (size_type i = 0; i < n; ++i) {
6348*c217d954SCole Faust #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6349*c217d954SCole Faust strings[i] = sources[(int)i].data();
6350*c217d954SCole Faust lengths[i] = sources[(int)i].length();
6351*c217d954SCole Faust #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6352*c217d954SCole Faust strings[i] = sources[(int)i].first;
6353*c217d954SCole Faust lengths[i] = sources[(int)i].second;
6354*c217d954SCole Faust #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6355*c217d954SCole Faust }
6356*c217d954SCole Faust
6357*c217d954SCole Faust object_ = ::clCreateProgramWithSource(
6358*c217d954SCole Faust context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6359*c217d954SCole Faust
6360*c217d954SCole Faust detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6361*c217d954SCole Faust if (err != NULL) {
6362*c217d954SCole Faust *err = error;
6363*c217d954SCole Faust }
6364*c217d954SCole Faust }
6365*c217d954SCole Faust
6366*c217d954SCole Faust /**
6367*c217d954SCole Faust * Create a program from a vector of source strings and a provided context.
6368*c217d954SCole Faust * Does not compile or link the program.
6369*c217d954SCole Faust */
Program(const Context & context,const Sources & sources,cl_int * err=NULL)6370*c217d954SCole Faust Program(
6371*c217d954SCole Faust const Context& context,
6372*c217d954SCole Faust const Sources& sources,
6373*c217d954SCole Faust cl_int* err = NULL)
6374*c217d954SCole Faust {
6375*c217d954SCole Faust cl_int error;
6376*c217d954SCole Faust
6377*c217d954SCole Faust const size_type n = (size_type)sources.size();
6378*c217d954SCole Faust
6379*c217d954SCole Faust vector<size_type> lengths(n);
6380*c217d954SCole Faust vector<const char*> strings(n);
6381*c217d954SCole Faust
6382*c217d954SCole Faust for (size_type i = 0; i < n; ++i) {
6383*c217d954SCole Faust #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6384*c217d954SCole Faust strings[i] = sources[(int)i].data();
6385*c217d954SCole Faust lengths[i] = sources[(int)i].length();
6386*c217d954SCole Faust #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6387*c217d954SCole Faust strings[i] = sources[(int)i].first;
6388*c217d954SCole Faust lengths[i] = sources[(int)i].second;
6389*c217d954SCole Faust #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6390*c217d954SCole Faust }
6391*c217d954SCole Faust
6392*c217d954SCole Faust object_ = ::clCreateProgramWithSource(
6393*c217d954SCole Faust context(), (cl_uint)n, strings.data(), lengths.data(), &error);
6394*c217d954SCole Faust
6395*c217d954SCole Faust detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
6396*c217d954SCole Faust if (err != NULL) {
6397*c217d954SCole Faust *err = error;
6398*c217d954SCole Faust }
6399*c217d954SCole Faust }
6400*c217d954SCole Faust
6401*c217d954SCole Faust
6402*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 210 || (CL_HPP_TARGET_OPENCL_VERSION==200 && defined(CL_HPP_USE_IL_KHR))
6403*c217d954SCole Faust /**
6404*c217d954SCole Faust * Program constructor to allow construction of program from SPIR-V or another IL.
6405*c217d954SCole Faust * Valid for either OpenCL >= 2.1 or when CL_HPP_USE_IL_KHR is defined.
6406*c217d954SCole Faust */
Program(const vector<char> & IL,bool build=false,cl_int * err=NULL)6407*c217d954SCole Faust Program(
6408*c217d954SCole Faust const vector<char>& IL,
6409*c217d954SCole Faust bool build = false,
6410*c217d954SCole Faust cl_int* err = NULL)
6411*c217d954SCole Faust {
6412*c217d954SCole Faust cl_int error;
6413*c217d954SCole Faust
6414*c217d954SCole Faust Context context = Context::getDefault(err);
6415*c217d954SCole Faust
6416*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6417*c217d954SCole Faust
6418*c217d954SCole Faust object_ = ::clCreateProgramWithIL(
6419*c217d954SCole Faust context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6420*c217d954SCole Faust
6421*c217d954SCole Faust #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6422*c217d954SCole Faust
6423*c217d954SCole Faust typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6424*c217d954SCole Faust static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6425*c217d954SCole Faust CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6426*c217d954SCole Faust
6427*c217d954SCole Faust return detail::errHandler(
6428*c217d954SCole Faust pfn_clCreateProgramWithILKHR(
6429*c217d954SCole Faust context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6430*c217d954SCole Faust
6431*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6432*c217d954SCole Faust
6433*c217d954SCole Faust detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6434*c217d954SCole Faust
6435*c217d954SCole Faust if (error == CL_SUCCESS && build) {
6436*c217d954SCole Faust
6437*c217d954SCole Faust error = ::clBuildProgram(
6438*c217d954SCole Faust object_,
6439*c217d954SCole Faust 0,
6440*c217d954SCole Faust NULL,
6441*c217d954SCole Faust #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6442*c217d954SCole Faust "-cl-std=CL2.0",
6443*c217d954SCole Faust #else
6444*c217d954SCole Faust "",
6445*c217d954SCole Faust #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6446*c217d954SCole Faust NULL,
6447*c217d954SCole Faust NULL);
6448*c217d954SCole Faust
6449*c217d954SCole Faust detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6450*c217d954SCole Faust }
6451*c217d954SCole Faust
6452*c217d954SCole Faust if (err != NULL) {
6453*c217d954SCole Faust *err = error;
6454*c217d954SCole Faust }
6455*c217d954SCole Faust }
6456*c217d954SCole Faust
6457*c217d954SCole Faust /**
6458*c217d954SCole Faust * Program constructor to allow construction of program from SPIR-V or another IL
6459*c217d954SCole Faust * for a specific context.
6460*c217d954SCole Faust * Valid for either OpenCL >= 2.1 or when CL_HPP_USE_IL_KHR is defined.
6461*c217d954SCole Faust */
6462*c217d954SCole Faust Program(
6463*c217d954SCole Faust const Context& context,
6464*c217d954SCole Faust const vector<char>& IL,
6465*c217d954SCole Faust bool build = false,
6466*c217d954SCole Faust cl_int* err = NULL)
6467*c217d954SCole Faust {
6468*c217d954SCole Faust cl_int error;
6469*c217d954SCole Faust
6470*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6471*c217d954SCole Faust
6472*c217d954SCole Faust object_ = ::clCreateProgramWithIL(
6473*c217d954SCole Faust context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6474*c217d954SCole Faust
6475*c217d954SCole Faust #else // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6476*c217d954SCole Faust
6477*c217d954SCole Faust typedef clCreateProgramWithILKHR_fn PFN_clCreateProgramWithILKHR;
6478*c217d954SCole Faust static PFN_clCreateProgramWithILKHR pfn_clCreateProgramWithILKHR = NULL;
6479*c217d954SCole Faust CL_HPP_INIT_CL_EXT_FCN_PTR_(clCreateProgramWithILKHR);
6480*c217d954SCole Faust
6481*c217d954SCole Faust return detail::errHandler(
6482*c217d954SCole Faust pfn_clCreateProgramWithILKHR(
6483*c217d954SCole Faust context(), static_cast<const void*>(IL.data()), IL.size(), &error);
6484*c217d954SCole Faust
6485*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6486*c217d954SCole Faust
6487*c217d954SCole Faust detail::errHandler(error, __CREATE_PROGRAM_WITH_IL_ERR);
6488*c217d954SCole Faust
6489*c217d954SCole Faust if (error == CL_SUCCESS && build) {
6490*c217d954SCole Faust error = ::clBuildProgram(
6491*c217d954SCole Faust object_,
6492*c217d954SCole Faust 0,
6493*c217d954SCole Faust NULL,
6494*c217d954SCole Faust #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6495*c217d954SCole Faust "-cl-std=CL2.0",
6496*c217d954SCole Faust #else
6497*c217d954SCole Faust "",
6498*c217d954SCole Faust #endif // #if !defined(CL_HPP_CL_1_2_DEFAULT_BUILD)
6499*c217d954SCole Faust NULL,
6500*c217d954SCole Faust NULL);
6501*c217d954SCole Faust
6502*c217d954SCole Faust detail::buildErrHandler(error, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6503*c217d954SCole Faust }
6504*c217d954SCole Faust
6505*c217d954SCole Faust if (err != NULL) {
6506*c217d954SCole Faust *err = error;
6507*c217d954SCole Faust }
6508*c217d954SCole Faust }
6509*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
6510*c217d954SCole Faust
6511*c217d954SCole Faust /**
6512*c217d954SCole Faust * Construct a program object from a list of devices and a per-device list of binaries.
6513*c217d954SCole Faust * \param context A valid OpenCL context in which to construct the program.
6514*c217d954SCole Faust * \param devices A vector of OpenCL device objects for which the program will be created.
6515*c217d954SCole Faust * \param binaries A vector of pairs of a pointer to a binary object and its length.
6516*c217d954SCole Faust * \param binaryStatus An optional vector that on completion will be resized to
6517*c217d954SCole Faust * match the size of binaries and filled with values to specify if each binary
6518*c217d954SCole Faust * was successfully loaded.
6519*c217d954SCole Faust * Set to CL_SUCCESS if the binary was successfully loaded.
6520*c217d954SCole Faust * Set to CL_INVALID_VALUE if the length is 0 or the binary pointer is NULL.
6521*c217d954SCole Faust * Set to CL_INVALID_BINARY if the binary provided is not valid for the matching device.
6522*c217d954SCole Faust * \param err if non-NULL will be set to CL_SUCCESS on successful operation or one of the following errors:
6523*c217d954SCole Faust * CL_INVALID_CONTEXT if context is not a valid context.
6524*c217d954SCole Faust * CL_INVALID_VALUE if the length of devices is zero; or if the length of binaries does not match the length of devices;
6525*c217d954SCole Faust * or if any entry in binaries is NULL or has length 0.
6526*c217d954SCole Faust * CL_INVALID_DEVICE if OpenCL devices listed in devices are not in the list of devices associated with context.
6527*c217d954SCole Faust * CL_INVALID_BINARY if an invalid program binary was encountered for any device. binaryStatus will return specific status for each device.
6528*c217d954SCole Faust * CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host.
6529*c217d954SCole Faust */
6530*c217d954SCole Faust Program(
6531*c217d954SCole Faust const Context& context,
6532*c217d954SCole Faust const vector<Device>& devices,
6533*c217d954SCole Faust const Binaries& binaries,
6534*c217d954SCole Faust vector<cl_int>* binaryStatus = NULL,
6535*c217d954SCole Faust cl_int* err = NULL)
6536*c217d954SCole Faust {
6537*c217d954SCole Faust cl_int error;
6538*c217d954SCole Faust
6539*c217d954SCole Faust const size_type numDevices = devices.size();
6540*c217d954SCole Faust
6541*c217d954SCole Faust // Catch size mismatch early and return
6542*c217d954SCole Faust if(binaries.size() != numDevices) {
6543*c217d954SCole Faust error = CL_INVALID_VALUE;
6544*c217d954SCole Faust detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6545*c217d954SCole Faust if (err != NULL) {
6546*c217d954SCole Faust *err = error;
6547*c217d954SCole Faust }
6548*c217d954SCole Faust return;
6549*c217d954SCole Faust }
6550*c217d954SCole Faust
6551*c217d954SCole Faust
6552*c217d954SCole Faust vector<size_type> lengths(numDevices);
6553*c217d954SCole Faust vector<const unsigned char*> images(numDevices);
6554*c217d954SCole Faust #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6555*c217d954SCole Faust for (size_type i = 0; i < numDevices; ++i) {
6556*c217d954SCole Faust images[i] = binaries[i].data();
6557*c217d954SCole Faust lengths[i] = binaries[(int)i].size();
6558*c217d954SCole Faust }
6559*c217d954SCole Faust #else // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6560*c217d954SCole Faust for (size_type i = 0; i < numDevices; ++i) {
6561*c217d954SCole Faust images[i] = (const unsigned char*)binaries[i].first;
6562*c217d954SCole Faust lengths[i] = binaries[(int)i].second;
6563*c217d954SCole Faust }
6564*c217d954SCole Faust #endif // #if !defined(CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY)
6565*c217d954SCole Faust
6566*c217d954SCole Faust vector<cl_device_id> deviceIDs(numDevices);
6567*c217d954SCole Faust for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6568*c217d954SCole Faust deviceIDs[deviceIndex] = (devices[deviceIndex])();
6569*c217d954SCole Faust }
6570*c217d954SCole Faust
6571*c217d954SCole Faust if(binaryStatus) {
6572*c217d954SCole Faust binaryStatus->resize(numDevices);
6573*c217d954SCole Faust }
6574*c217d954SCole Faust
6575*c217d954SCole Faust object_ = ::clCreateProgramWithBinary(
6576*c217d954SCole Faust context(), (cl_uint) devices.size(),
6577*c217d954SCole Faust deviceIDs.data(),
6578*c217d954SCole Faust lengths.data(), images.data(), (binaryStatus != NULL && numDevices > 0)
6579*c217d954SCole Faust ? &binaryStatus->front()
6580*c217d954SCole Faust : NULL, &error);
6581*c217d954SCole Faust
6582*c217d954SCole Faust detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
6583*c217d954SCole Faust if (err != NULL) {
6584*c217d954SCole Faust *err = error;
6585*c217d954SCole Faust }
6586*c217d954SCole Faust }
6587*c217d954SCole Faust
6588*c217d954SCole Faust
6589*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6590*c217d954SCole Faust /**
6591*c217d954SCole Faust * Create program using builtin kernels.
6592*c217d954SCole Faust * \param kernelNames Semi-colon separated list of builtin kernel names
6593*c217d954SCole Faust */
6594*c217d954SCole Faust Program(
6595*c217d954SCole Faust const Context& context,
6596*c217d954SCole Faust const vector<Device>& devices,
6597*c217d954SCole Faust const string& kernelNames,
6598*c217d954SCole Faust cl_int* err = NULL)
6599*c217d954SCole Faust {
6600*c217d954SCole Faust cl_int error;
6601*c217d954SCole Faust
6602*c217d954SCole Faust
6603*c217d954SCole Faust size_type numDevices = devices.size();
6604*c217d954SCole Faust vector<cl_device_id> deviceIDs(numDevices);
6605*c217d954SCole Faust for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6606*c217d954SCole Faust deviceIDs[deviceIndex] = (devices[deviceIndex])();
6607*c217d954SCole Faust }
6608*c217d954SCole Faust
6609*c217d954SCole Faust object_ = ::clCreateProgramWithBuiltInKernels(
6610*c217d954SCole Faust context(),
6611*c217d954SCole Faust (cl_uint) devices.size(),
6612*c217d954SCole Faust deviceIDs.data(),
6613*c217d954SCole Faust kernelNames.c_str(),
6614*c217d954SCole Faust &error);
6615*c217d954SCole Faust
6616*c217d954SCole Faust detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR);
6617*c217d954SCole Faust if (err != NULL) {
6618*c217d954SCole Faust *err = error;
6619*c217d954SCole Faust }
6620*c217d954SCole Faust }
6621*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6622*c217d954SCole Faust
6623*c217d954SCole Faust Program() { }
6624*c217d954SCole Faust
6625*c217d954SCole Faust
6626*c217d954SCole Faust /*! \brief Constructor from cl_program - takes ownership.
6627*c217d954SCole Faust *
6628*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
6629*c217d954SCole Faust * Defaults to false to maintain compatibility with
6630*c217d954SCole Faust * earlier versions.
6631*c217d954SCole Faust */
6632*c217d954SCole Faust explicit Program(const cl_program& program, bool retainObject = false) :
6633*c217d954SCole Faust detail::Wrapper<cl_type>(program, retainObject) { }
6634*c217d954SCole Faust
6635*c217d954SCole Faust Program& operator = (const cl_program& rhs)
6636*c217d954SCole Faust {
6637*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(rhs);
6638*c217d954SCole Faust return *this;
6639*c217d954SCole Faust }
6640*c217d954SCole Faust
6641*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
6642*c217d954SCole Faust * Required for MSVC.
6643*c217d954SCole Faust */
6644*c217d954SCole Faust Program(const Program& program) : detail::Wrapper<cl_type>(program) {}
6645*c217d954SCole Faust
6646*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
6647*c217d954SCole Faust * Required for MSVC.
6648*c217d954SCole Faust */
6649*c217d954SCole Faust Program& operator = (const Program &program)
6650*c217d954SCole Faust {
6651*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(program);
6652*c217d954SCole Faust return *this;
6653*c217d954SCole Faust }
6654*c217d954SCole Faust
6655*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
6656*c217d954SCole Faust * Required for MSVC.
6657*c217d954SCole Faust */
6658*c217d954SCole Faust Program(Program&& program) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(program)) {}
6659*c217d954SCole Faust
6660*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
6661*c217d954SCole Faust * Required for MSVC.
6662*c217d954SCole Faust */
6663*c217d954SCole Faust Program& operator = (Program &&program)
6664*c217d954SCole Faust {
6665*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(std::move(program));
6666*c217d954SCole Faust return *this;
6667*c217d954SCole Faust }
6668*c217d954SCole Faust
6669*c217d954SCole Faust cl_int build(
6670*c217d954SCole Faust const vector<Device>& devices,
6671*c217d954SCole Faust const char* options = NULL,
6672*c217d954SCole Faust void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6673*c217d954SCole Faust void* data = NULL) const
6674*c217d954SCole Faust {
6675*c217d954SCole Faust size_type numDevices = devices.size();
6676*c217d954SCole Faust vector<cl_device_id> deviceIDs(numDevices);
6677*c217d954SCole Faust
6678*c217d954SCole Faust for( size_type deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
6679*c217d954SCole Faust deviceIDs[deviceIndex] = (devices[deviceIndex])();
6680*c217d954SCole Faust }
6681*c217d954SCole Faust
6682*c217d954SCole Faust cl_int buildError = ::clBuildProgram(
6683*c217d954SCole Faust object_,
6684*c217d954SCole Faust (cl_uint)
6685*c217d954SCole Faust devices.size(),
6686*c217d954SCole Faust deviceIDs.data(),
6687*c217d954SCole Faust options,
6688*c217d954SCole Faust notifyFptr,
6689*c217d954SCole Faust data);
6690*c217d954SCole Faust
6691*c217d954SCole Faust return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6692*c217d954SCole Faust }
6693*c217d954SCole Faust
6694*c217d954SCole Faust cl_int build(
6695*c217d954SCole Faust const Device& device,
6696*c217d954SCole Faust const char* options = NULL,
6697*c217d954SCole Faust void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6698*c217d954SCole Faust void* data = NULL) const
6699*c217d954SCole Faust {
6700*c217d954SCole Faust cl_device_id deviceID = device();
6701*c217d954SCole Faust
6702*c217d954SCole Faust cl_int buildError = ::clBuildProgram(
6703*c217d954SCole Faust object_,
6704*c217d954SCole Faust 1,
6705*c217d954SCole Faust &deviceID,
6706*c217d954SCole Faust options,
6707*c217d954SCole Faust notifyFptr,
6708*c217d954SCole Faust data);
6709*c217d954SCole Faust
6710*c217d954SCole Faust BuildLogType buildLog(1);
6711*c217d954SCole Faust buildLog.push_back(std::make_pair(device, getBuildInfo<CL_PROGRAM_BUILD_LOG>(device)));
6712*c217d954SCole Faust return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, buildLog);
6713*c217d954SCole Faust }
6714*c217d954SCole Faust
6715*c217d954SCole Faust cl_int build(
6716*c217d954SCole Faust const char* options = NULL,
6717*c217d954SCole Faust void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6718*c217d954SCole Faust void* data = NULL) const
6719*c217d954SCole Faust {
6720*c217d954SCole Faust cl_int buildError = ::clBuildProgram(
6721*c217d954SCole Faust object_,
6722*c217d954SCole Faust 0,
6723*c217d954SCole Faust NULL,
6724*c217d954SCole Faust options,
6725*c217d954SCole Faust notifyFptr,
6726*c217d954SCole Faust data);
6727*c217d954SCole Faust
6728*c217d954SCole Faust return detail::buildErrHandler(buildError, __BUILD_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6729*c217d954SCole Faust }
6730*c217d954SCole Faust
6731*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6732*c217d954SCole Faust cl_int compile(
6733*c217d954SCole Faust const char* options = NULL,
6734*c217d954SCole Faust void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6735*c217d954SCole Faust void* data = NULL) const
6736*c217d954SCole Faust {
6737*c217d954SCole Faust cl_int error = ::clCompileProgram(
6738*c217d954SCole Faust object_,
6739*c217d954SCole Faust 0,
6740*c217d954SCole Faust NULL,
6741*c217d954SCole Faust options,
6742*c217d954SCole Faust 0,
6743*c217d954SCole Faust NULL,
6744*c217d954SCole Faust NULL,
6745*c217d954SCole Faust notifyFptr,
6746*c217d954SCole Faust data);
6747*c217d954SCole Faust return detail::buildErrHandler(error, __COMPILE_PROGRAM_ERR, getBuildInfo<CL_PROGRAM_BUILD_LOG>());
6748*c217d954SCole Faust }
6749*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
6750*c217d954SCole Faust
6751*c217d954SCole Faust template <typename T>
6752*c217d954SCole Faust cl_int getInfo(cl_program_info name, T* param) const
6753*c217d954SCole Faust {
6754*c217d954SCole Faust return detail::errHandler(
6755*c217d954SCole Faust detail::getInfo(&::clGetProgramInfo, object_, name, param),
6756*c217d954SCole Faust __GET_PROGRAM_INFO_ERR);
6757*c217d954SCole Faust }
6758*c217d954SCole Faust
6759*c217d954SCole Faust template <cl_program_info name> typename
6760*c217d954SCole Faust detail::param_traits<detail::cl_program_info, name>::param_type
6761*c217d954SCole Faust getInfo(cl_int* err = NULL) const
6762*c217d954SCole Faust {
6763*c217d954SCole Faust typename detail::param_traits<
6764*c217d954SCole Faust detail::cl_program_info, name>::param_type param;
6765*c217d954SCole Faust cl_int result = getInfo(name, ¶m);
6766*c217d954SCole Faust if (err != NULL) {
6767*c217d954SCole Faust *err = result;
6768*c217d954SCole Faust }
6769*c217d954SCole Faust return param;
6770*c217d954SCole Faust }
6771*c217d954SCole Faust
6772*c217d954SCole Faust template <typename T>
6773*c217d954SCole Faust cl_int getBuildInfo(
6774*c217d954SCole Faust const Device& device, cl_program_build_info name, T* param) const
6775*c217d954SCole Faust {
6776*c217d954SCole Faust return detail::errHandler(
6777*c217d954SCole Faust detail::getInfo(
6778*c217d954SCole Faust &::clGetProgramBuildInfo, object_, device(), name, param),
6779*c217d954SCole Faust __GET_PROGRAM_BUILD_INFO_ERR);
6780*c217d954SCole Faust }
6781*c217d954SCole Faust
6782*c217d954SCole Faust template <cl_program_build_info name> typename
6783*c217d954SCole Faust detail::param_traits<detail::cl_program_build_info, name>::param_type
6784*c217d954SCole Faust getBuildInfo(const Device& device, cl_int* err = NULL) const
6785*c217d954SCole Faust {
6786*c217d954SCole Faust typename detail::param_traits<
6787*c217d954SCole Faust detail::cl_program_build_info, name>::param_type param;
6788*c217d954SCole Faust cl_int result = getBuildInfo(device, name, ¶m);
6789*c217d954SCole Faust if (err != NULL) {
6790*c217d954SCole Faust *err = result;
6791*c217d954SCole Faust }
6792*c217d954SCole Faust return param;
6793*c217d954SCole Faust }
6794*c217d954SCole Faust
6795*c217d954SCole Faust /**
6796*c217d954SCole Faust * Build info function that returns a vector of device/info pairs for the specified
6797*c217d954SCole Faust * info type and for all devices in the program.
6798*c217d954SCole Faust * On an error reading the info for any device, an empty vector of info will be returned.
6799*c217d954SCole Faust */
6800*c217d954SCole Faust template <cl_program_build_info name>
6801*c217d954SCole Faust vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6802*c217d954SCole Faust getBuildInfo(cl_int *err = NULL) const
6803*c217d954SCole Faust {
6804*c217d954SCole Faust cl_int result = CL_SUCCESS;
6805*c217d954SCole Faust
6806*c217d954SCole Faust auto devs = getInfo<CL_PROGRAM_DEVICES>(&result);
6807*c217d954SCole Faust vector<std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>>
6808*c217d954SCole Faust devInfo;
6809*c217d954SCole Faust
6810*c217d954SCole Faust // If there was an initial error from getInfo return the error
6811*c217d954SCole Faust if (result != CL_SUCCESS) {
6812*c217d954SCole Faust if (err != NULL) {
6813*c217d954SCole Faust *err = result;
6814*c217d954SCole Faust }
6815*c217d954SCole Faust return devInfo;
6816*c217d954SCole Faust }
6817*c217d954SCole Faust
6818*c217d954SCole Faust for (const cl::Device &d : devs) {
6819*c217d954SCole Faust typename detail::param_traits<
6820*c217d954SCole Faust detail::cl_program_build_info, name>::param_type param;
6821*c217d954SCole Faust result = getBuildInfo(d, name, ¶m);
6822*c217d954SCole Faust devInfo.push_back(
6823*c217d954SCole Faust std::pair<cl::Device, typename detail::param_traits<detail::cl_program_build_info, name>::param_type>
6824*c217d954SCole Faust (d, param));
6825*c217d954SCole Faust if (result != CL_SUCCESS) {
6826*c217d954SCole Faust // On error, leave the loop and return the error code
6827*c217d954SCole Faust break;
6828*c217d954SCole Faust }
6829*c217d954SCole Faust }
6830*c217d954SCole Faust if (err != NULL) {
6831*c217d954SCole Faust *err = result;
6832*c217d954SCole Faust }
6833*c217d954SCole Faust if (result != CL_SUCCESS) {
6834*c217d954SCole Faust devInfo.clear();
6835*c217d954SCole Faust }
6836*c217d954SCole Faust return devInfo;
6837*c217d954SCole Faust }
6838*c217d954SCole Faust
6839*c217d954SCole Faust cl_int createKernels(vector<Kernel>* kernels)
6840*c217d954SCole Faust {
6841*c217d954SCole Faust cl_uint numKernels;
6842*c217d954SCole Faust cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
6843*c217d954SCole Faust if (err != CL_SUCCESS) {
6844*c217d954SCole Faust return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6845*c217d954SCole Faust }
6846*c217d954SCole Faust
6847*c217d954SCole Faust vector<cl_kernel> value(numKernels);
6848*c217d954SCole Faust
6849*c217d954SCole Faust err = ::clCreateKernelsInProgram(
6850*c217d954SCole Faust object_, numKernels, value.data(), NULL);
6851*c217d954SCole Faust if (err != CL_SUCCESS) {
6852*c217d954SCole Faust return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
6853*c217d954SCole Faust }
6854*c217d954SCole Faust
6855*c217d954SCole Faust if (kernels) {
6856*c217d954SCole Faust kernels->resize(value.size());
6857*c217d954SCole Faust
6858*c217d954SCole Faust // Assign to param, constructing with retain behaviour
6859*c217d954SCole Faust // to correctly capture each underlying CL object
6860*c217d954SCole Faust for (size_type i = 0; i < value.size(); i++) {
6861*c217d954SCole Faust // We do not need to retain because this kernel is being created
6862*c217d954SCole Faust // by the runtime
6863*c217d954SCole Faust (*kernels)[i] = Kernel(value[i], false);
6864*c217d954SCole Faust }
6865*c217d954SCole Faust }
6866*c217d954SCole Faust return CL_SUCCESS;
6867*c217d954SCole Faust }
6868*c217d954SCole Faust
6869*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 220
6870*c217d954SCole Faust #if defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
6871*c217d954SCole Faust /*! \brief Registers a callback function to be called when destructors for
6872*c217d954SCole Faust * program scope global variables are complete and before the
6873*c217d954SCole Faust * program is released.
6874*c217d954SCole Faust *
6875*c217d954SCole Faust * Wraps clSetProgramReleaseCallback().
6876*c217d954SCole Faust *
6877*c217d954SCole Faust * Each call to this function registers the specified user callback function
6878*c217d954SCole Faust * on a callback stack associated with program. The registered user callback
6879*c217d954SCole Faust * functions are called in the reverse order in which they were registered.
6880*c217d954SCole Faust */
6881*c217d954SCole Faust CL_API_PREFIX__VERSION_2_2_DEPRECATED cl_int setReleaseCallback(
6882*c217d954SCole Faust void (CL_CALLBACK * pfn_notify)(cl_program program, void * user_data),
6883*c217d954SCole Faust void * user_data = NULL) CL_API_SUFFIX__VERSION_2_2_DEPRECATED
6884*c217d954SCole Faust {
6885*c217d954SCole Faust return detail::errHandler(
6886*c217d954SCole Faust ::clSetProgramReleaseCallback(
6887*c217d954SCole Faust object_,
6888*c217d954SCole Faust pfn_notify,
6889*c217d954SCole Faust user_data),
6890*c217d954SCole Faust __SET_PROGRAM_RELEASE_CALLBACK_ERR);
6891*c217d954SCole Faust }
6892*c217d954SCole Faust #endif // #if defined(CL_USE_DEPRECATED_OPENCL_2_2_APIS)
6893*c217d954SCole Faust
6894*c217d954SCole Faust /*! \brief Sets a SPIR-V specialization constant.
6895*c217d954SCole Faust *
6896*c217d954SCole Faust * Wraps clSetProgramSpecializationConstant().
6897*c217d954SCole Faust */
6898*c217d954SCole Faust template <typename T>
6899*c217d954SCole Faust typename std::enable_if<!std::is_pointer<T>::value, cl_int>::type
6900*c217d954SCole Faust setSpecializationConstant(cl_uint index, const T &value)
6901*c217d954SCole Faust {
6902*c217d954SCole Faust return detail::errHandler(
6903*c217d954SCole Faust ::clSetProgramSpecializationConstant(
6904*c217d954SCole Faust object_,
6905*c217d954SCole Faust index,
6906*c217d954SCole Faust sizeof(value),
6907*c217d954SCole Faust &value),
6908*c217d954SCole Faust __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6909*c217d954SCole Faust }
6910*c217d954SCole Faust
6911*c217d954SCole Faust /*! \brief Sets a SPIR-V specialization constant.
6912*c217d954SCole Faust *
6913*c217d954SCole Faust * Wraps clSetProgramSpecializationConstant().
6914*c217d954SCole Faust */
6915*c217d954SCole Faust cl_int setSpecializationConstant(cl_uint index, size_type size, const void* value)
6916*c217d954SCole Faust {
6917*c217d954SCole Faust return detail::errHandler(
6918*c217d954SCole Faust ::clSetProgramSpecializationConstant(
6919*c217d954SCole Faust object_,
6920*c217d954SCole Faust index,
6921*c217d954SCole Faust size,
6922*c217d954SCole Faust value),
6923*c217d954SCole Faust __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
6924*c217d954SCole Faust }
6925*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
6926*c217d954SCole Faust };
6927*c217d954SCole Faust
6928*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
6929*c217d954SCole Faust inline Program linkProgram(
6930*c217d954SCole Faust Program input1,
6931*c217d954SCole Faust Program input2,
6932*c217d954SCole Faust const char* options = NULL,
6933*c217d954SCole Faust void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6934*c217d954SCole Faust void* data = NULL,
6935*c217d954SCole Faust cl_int* err = NULL)
6936*c217d954SCole Faust {
6937*c217d954SCole Faust cl_int error_local = CL_SUCCESS;
6938*c217d954SCole Faust
6939*c217d954SCole Faust cl_program programs[2] = { input1(), input2() };
6940*c217d954SCole Faust
6941*c217d954SCole Faust Context ctx = input1.getInfo<CL_PROGRAM_CONTEXT>(&error_local);
6942*c217d954SCole Faust if(error_local!=CL_SUCCESS) {
6943*c217d954SCole Faust detail::errHandler(error_local, __LINK_PROGRAM_ERR);
6944*c217d954SCole Faust }
6945*c217d954SCole Faust
6946*c217d954SCole Faust cl_program prog = ::clLinkProgram(
6947*c217d954SCole Faust ctx(),
6948*c217d954SCole Faust 0,
6949*c217d954SCole Faust NULL,
6950*c217d954SCole Faust options,
6951*c217d954SCole Faust 2,
6952*c217d954SCole Faust programs,
6953*c217d954SCole Faust notifyFptr,
6954*c217d954SCole Faust data,
6955*c217d954SCole Faust &error_local);
6956*c217d954SCole Faust
6957*c217d954SCole Faust detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
6958*c217d954SCole Faust if (err != NULL) {
6959*c217d954SCole Faust *err = error_local;
6960*c217d954SCole Faust }
6961*c217d954SCole Faust
6962*c217d954SCole Faust return Program(prog);
6963*c217d954SCole Faust }
6964*c217d954SCole Faust
6965*c217d954SCole Faust inline Program linkProgram(
6966*c217d954SCole Faust vector<Program> inputPrograms,
6967*c217d954SCole Faust const char* options = NULL,
6968*c217d954SCole Faust void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
6969*c217d954SCole Faust void* data = NULL,
6970*c217d954SCole Faust cl_int* err = NULL)
6971*c217d954SCole Faust {
6972*c217d954SCole Faust cl_int error_local = CL_SUCCESS;
6973*c217d954SCole Faust
6974*c217d954SCole Faust vector<cl_program> programs(inputPrograms.size());
6975*c217d954SCole Faust
6976*c217d954SCole Faust for (unsigned int i = 0; i < inputPrograms.size(); i++) {
6977*c217d954SCole Faust programs[i] = inputPrograms[i]();
6978*c217d954SCole Faust }
6979*c217d954SCole Faust
6980*c217d954SCole Faust Context ctx;
6981*c217d954SCole Faust if(inputPrograms.size() > 0) {
6982*c217d954SCole Faust ctx = inputPrograms[0].getInfo<CL_PROGRAM_CONTEXT>(&error_local);
6983*c217d954SCole Faust if(error_local!=CL_SUCCESS) {
6984*c217d954SCole Faust detail::errHandler(error_local, __LINK_PROGRAM_ERR);
6985*c217d954SCole Faust }
6986*c217d954SCole Faust }
6987*c217d954SCole Faust cl_program prog = ::clLinkProgram(
6988*c217d954SCole Faust ctx(),
6989*c217d954SCole Faust 0,
6990*c217d954SCole Faust NULL,
6991*c217d954SCole Faust options,
6992*c217d954SCole Faust (cl_uint)inputPrograms.size(),
6993*c217d954SCole Faust programs.data(),
6994*c217d954SCole Faust notifyFptr,
6995*c217d954SCole Faust data,
6996*c217d954SCole Faust &error_local);
6997*c217d954SCole Faust
6998*c217d954SCole Faust detail::errHandler(error_local,__COMPILE_PROGRAM_ERR);
6999*c217d954SCole Faust if (err != NULL) {
7000*c217d954SCole Faust *err = error_local;
7001*c217d954SCole Faust }
7002*c217d954SCole Faust
7003*c217d954SCole Faust return Program(prog, false);
7004*c217d954SCole Faust }
7005*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7006*c217d954SCole Faust
7007*c217d954SCole Faust // Template specialization for CL_PROGRAM_BINARIES
7008*c217d954SCole Faust template <>
7009*c217d954SCole Faust inline cl_int cl::Program::getInfo(cl_program_info name, vector<vector<unsigned char>>* param) const
7010*c217d954SCole Faust {
7011*c217d954SCole Faust if (name != CL_PROGRAM_BINARIES) {
7012*c217d954SCole Faust return CL_INVALID_VALUE;
7013*c217d954SCole Faust }
7014*c217d954SCole Faust if (param) {
7015*c217d954SCole Faust // Resize the parameter array appropriately for each allocation
7016*c217d954SCole Faust // and pass down to the helper
7017*c217d954SCole Faust
7018*c217d954SCole Faust vector<size_type> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>();
7019*c217d954SCole Faust size_type numBinaries = sizes.size();
7020*c217d954SCole Faust
7021*c217d954SCole Faust // Resize the parameter array and constituent arrays
7022*c217d954SCole Faust param->resize(numBinaries);
7023*c217d954SCole Faust for (size_type i = 0; i < numBinaries; ++i) {
7024*c217d954SCole Faust (*param)[i].resize(sizes[i]);
7025*c217d954SCole Faust }
7026*c217d954SCole Faust
7027*c217d954SCole Faust return detail::errHandler(
7028*c217d954SCole Faust detail::getInfo(&::clGetProgramInfo, object_, name, param),
7029*c217d954SCole Faust __GET_PROGRAM_INFO_ERR);
7030*c217d954SCole Faust }
7031*c217d954SCole Faust
7032*c217d954SCole Faust return CL_SUCCESS;
7033*c217d954SCole Faust }
7034*c217d954SCole Faust
7035*c217d954SCole Faust template<>
7036*c217d954SCole Faust inline vector<vector<unsigned char>> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err) const
7037*c217d954SCole Faust {
7038*c217d954SCole Faust vector<vector<unsigned char>> binariesVectors;
7039*c217d954SCole Faust
7040*c217d954SCole Faust cl_int result = getInfo(CL_PROGRAM_BINARIES, &binariesVectors);
7041*c217d954SCole Faust if (err != NULL) {
7042*c217d954SCole Faust *err = result;
7043*c217d954SCole Faust }
7044*c217d954SCole Faust return binariesVectors;
7045*c217d954SCole Faust }
7046*c217d954SCole Faust
7047*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 220
7048*c217d954SCole Faust // Template specialization for clSetProgramSpecializationConstant
7049*c217d954SCole Faust template <>
7050*c217d954SCole Faust inline cl_int cl::Program::setSpecializationConstant(cl_uint index, const bool &value)
7051*c217d954SCole Faust {
7052*c217d954SCole Faust cl_uchar ucValue = value ? CL_UCHAR_MAX : 0;
7053*c217d954SCole Faust return detail::errHandler(
7054*c217d954SCole Faust ::clSetProgramSpecializationConstant(
7055*c217d954SCole Faust object_,
7056*c217d954SCole Faust index,
7057*c217d954SCole Faust sizeof(ucValue),
7058*c217d954SCole Faust &ucValue),
7059*c217d954SCole Faust __SET_PROGRAM_SPECIALIZATION_CONSTANT_ERR);
7060*c217d954SCole Faust }
7061*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 220
7062*c217d954SCole Faust
7063*c217d954SCole Faust inline Kernel::Kernel(const Program& program, const char* name, cl_int* err)
7064*c217d954SCole Faust {
7065*c217d954SCole Faust cl_int error;
7066*c217d954SCole Faust
7067*c217d954SCole Faust object_ = ::clCreateKernel(program(), name, &error);
7068*c217d954SCole Faust detail::errHandler(error, __CREATE_KERNEL_ERR);
7069*c217d954SCole Faust
7070*c217d954SCole Faust if (err != NULL) {
7071*c217d954SCole Faust *err = error;
7072*c217d954SCole Faust }
7073*c217d954SCole Faust
7074*c217d954SCole Faust }
7075*c217d954SCole Faust
7076*c217d954SCole Faust enum class QueueProperties : cl_command_queue_properties
7077*c217d954SCole Faust {
7078*c217d954SCole Faust None = 0,
7079*c217d954SCole Faust Profiling = CL_QUEUE_PROFILING_ENABLE,
7080*c217d954SCole Faust OutOfOrder = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,
7081*c217d954SCole Faust };
7082*c217d954SCole Faust
7083*c217d954SCole Faust inline QueueProperties operator|(QueueProperties lhs, QueueProperties rhs)
7084*c217d954SCole Faust {
7085*c217d954SCole Faust return static_cast<QueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
7086*c217d954SCole Faust }
7087*c217d954SCole Faust
7088*c217d954SCole Faust /*! \class CommandQueue
7089*c217d954SCole Faust * \brief CommandQueue interface for cl_command_queue.
7090*c217d954SCole Faust */
7091*c217d954SCole Faust class CommandQueue : public detail::Wrapper<cl_command_queue>
7092*c217d954SCole Faust {
7093*c217d954SCole Faust private:
7094*c217d954SCole Faust static std::once_flag default_initialized_;
7095*c217d954SCole Faust static CommandQueue default_;
7096*c217d954SCole Faust static cl_int default_error_;
7097*c217d954SCole Faust
7098*c217d954SCole Faust /*! \brief Create the default command queue returned by @ref getDefault.
7099*c217d954SCole Faust *
7100*c217d954SCole Faust * It sets default_error_ to indicate success or failure. It does not throw
7101*c217d954SCole Faust * @c cl::Error.
7102*c217d954SCole Faust */
7103*c217d954SCole Faust static void makeDefault()
7104*c217d954SCole Faust {
7105*c217d954SCole Faust /* We don't want to throw an error from this function, so we have to
7106*c217d954SCole Faust * catch and set the error flag.
7107*c217d954SCole Faust */
7108*c217d954SCole Faust #if defined(CL_HPP_ENABLE_EXCEPTIONS)
7109*c217d954SCole Faust try
7110*c217d954SCole Faust #endif
7111*c217d954SCole Faust {
7112*c217d954SCole Faust int error;
7113*c217d954SCole Faust Context context = Context::getDefault(&error);
7114*c217d954SCole Faust
7115*c217d954SCole Faust if (error != CL_SUCCESS) {
7116*c217d954SCole Faust default_error_ = error;
7117*c217d954SCole Faust }
7118*c217d954SCole Faust else {
7119*c217d954SCole Faust Device device = Device::getDefault();
7120*c217d954SCole Faust default_ = CommandQueue(context, device, 0, &default_error_);
7121*c217d954SCole Faust }
7122*c217d954SCole Faust }
7123*c217d954SCole Faust #if defined(CL_HPP_ENABLE_EXCEPTIONS)
7124*c217d954SCole Faust catch (cl::Error &e) {
7125*c217d954SCole Faust default_error_ = e.err();
7126*c217d954SCole Faust }
7127*c217d954SCole Faust #endif
7128*c217d954SCole Faust }
7129*c217d954SCole Faust
7130*c217d954SCole Faust /*! \brief Create the default command queue.
7131*c217d954SCole Faust *
7132*c217d954SCole Faust * This sets @c default_. It does not throw
7133*c217d954SCole Faust * @c cl::Error.
7134*c217d954SCole Faust */
7135*c217d954SCole Faust static void makeDefaultProvided(const CommandQueue &c) {
7136*c217d954SCole Faust default_ = c;
7137*c217d954SCole Faust }
7138*c217d954SCole Faust
7139*c217d954SCole Faust public:
7140*c217d954SCole Faust #ifdef CL_HPP_UNIT_TEST_ENABLE
7141*c217d954SCole Faust /*! \brief Reset the default.
7142*c217d954SCole Faust *
7143*c217d954SCole Faust * This sets @c default_ to an empty value to support cleanup in
7144*c217d954SCole Faust * the unit test framework.
7145*c217d954SCole Faust * This function is not thread safe.
7146*c217d954SCole Faust */
7147*c217d954SCole Faust static void unitTestClearDefault() {
7148*c217d954SCole Faust default_ = CommandQueue();
7149*c217d954SCole Faust }
7150*c217d954SCole Faust #endif // #ifdef CL_HPP_UNIT_TEST_ENABLE
7151*c217d954SCole Faust
7152*c217d954SCole Faust
7153*c217d954SCole Faust /*!
7154*c217d954SCole Faust * \brief Constructs a CommandQueue based on passed properties.
7155*c217d954SCole Faust * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
7156*c217d954SCole Faust */
7157*c217d954SCole Faust CommandQueue(
7158*c217d954SCole Faust cl_command_queue_properties properties,
7159*c217d954SCole Faust cl_int* err = NULL)
7160*c217d954SCole Faust {
7161*c217d954SCole Faust cl_int error;
7162*c217d954SCole Faust
7163*c217d954SCole Faust Context context = Context::getDefault(&error);
7164*c217d954SCole Faust detail::errHandler(error, __CREATE_CONTEXT_ERR);
7165*c217d954SCole Faust
7166*c217d954SCole Faust if (error != CL_SUCCESS) {
7167*c217d954SCole Faust if (err != NULL) {
7168*c217d954SCole Faust *err = error;
7169*c217d954SCole Faust }
7170*c217d954SCole Faust }
7171*c217d954SCole Faust else {
7172*c217d954SCole Faust Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7173*c217d954SCole Faust bool useWithProperties;
7174*c217d954SCole Faust
7175*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7176*c217d954SCole Faust // Run-time decision based on the actual platform
7177*c217d954SCole Faust {
7178*c217d954SCole Faust cl_uint version = detail::getContextPlatformVersion(context());
7179*c217d954SCole Faust useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7180*c217d954SCole Faust }
7181*c217d954SCole Faust #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7182*c217d954SCole Faust useWithProperties = true;
7183*c217d954SCole Faust #else
7184*c217d954SCole Faust useWithProperties = false;
7185*c217d954SCole Faust #endif
7186*c217d954SCole Faust
7187*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7188*c217d954SCole Faust if (useWithProperties) {
7189*c217d954SCole Faust cl_queue_properties queue_properties[] = {
7190*c217d954SCole Faust CL_QUEUE_PROPERTIES, properties, 0 };
7191*c217d954SCole Faust if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7192*c217d954SCole Faust object_ = ::clCreateCommandQueueWithProperties(
7193*c217d954SCole Faust context(), device(), queue_properties, &error);
7194*c217d954SCole Faust }
7195*c217d954SCole Faust else {
7196*c217d954SCole Faust error = CL_INVALID_QUEUE_PROPERTIES;
7197*c217d954SCole Faust }
7198*c217d954SCole Faust
7199*c217d954SCole Faust detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7200*c217d954SCole Faust if (err != NULL) {
7201*c217d954SCole Faust *err = error;
7202*c217d954SCole Faust }
7203*c217d954SCole Faust }
7204*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7205*c217d954SCole Faust #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7206*c217d954SCole Faust if (!useWithProperties) {
7207*c217d954SCole Faust object_ = ::clCreateCommandQueue(
7208*c217d954SCole Faust context(), device(), properties, &error);
7209*c217d954SCole Faust
7210*c217d954SCole Faust detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7211*c217d954SCole Faust if (err != NULL) {
7212*c217d954SCole Faust *err = error;
7213*c217d954SCole Faust }
7214*c217d954SCole Faust }
7215*c217d954SCole Faust #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7216*c217d954SCole Faust }
7217*c217d954SCole Faust }
7218*c217d954SCole Faust
7219*c217d954SCole Faust /*!
7220*c217d954SCole Faust * \brief Constructs a CommandQueue based on passed properties.
7221*c217d954SCole Faust * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
7222*c217d954SCole Faust */
7223*c217d954SCole Faust CommandQueue(
7224*c217d954SCole Faust QueueProperties properties,
7225*c217d954SCole Faust cl_int* err = NULL)
7226*c217d954SCole Faust {
7227*c217d954SCole Faust cl_int error;
7228*c217d954SCole Faust
7229*c217d954SCole Faust Context context = Context::getDefault(&error);
7230*c217d954SCole Faust detail::errHandler(error, __CREATE_CONTEXT_ERR);
7231*c217d954SCole Faust
7232*c217d954SCole Faust if (error != CL_SUCCESS) {
7233*c217d954SCole Faust if (err != NULL) {
7234*c217d954SCole Faust *err = error;
7235*c217d954SCole Faust }
7236*c217d954SCole Faust }
7237*c217d954SCole Faust else {
7238*c217d954SCole Faust Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
7239*c217d954SCole Faust bool useWithProperties;
7240*c217d954SCole Faust
7241*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7242*c217d954SCole Faust // Run-time decision based on the actual platform
7243*c217d954SCole Faust {
7244*c217d954SCole Faust cl_uint version = detail::getContextPlatformVersion(context());
7245*c217d954SCole Faust useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7246*c217d954SCole Faust }
7247*c217d954SCole Faust #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7248*c217d954SCole Faust useWithProperties = true;
7249*c217d954SCole Faust #else
7250*c217d954SCole Faust useWithProperties = false;
7251*c217d954SCole Faust #endif
7252*c217d954SCole Faust
7253*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7254*c217d954SCole Faust if (useWithProperties) {
7255*c217d954SCole Faust cl_queue_properties queue_properties[] = {
7256*c217d954SCole Faust CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7257*c217d954SCole Faust
7258*c217d954SCole Faust object_ = ::clCreateCommandQueueWithProperties(
7259*c217d954SCole Faust context(), device(), queue_properties, &error);
7260*c217d954SCole Faust
7261*c217d954SCole Faust detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7262*c217d954SCole Faust if (err != NULL) {
7263*c217d954SCole Faust *err = error;
7264*c217d954SCole Faust }
7265*c217d954SCole Faust }
7266*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7267*c217d954SCole Faust #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7268*c217d954SCole Faust if (!useWithProperties) {
7269*c217d954SCole Faust object_ = ::clCreateCommandQueue(
7270*c217d954SCole Faust context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
7271*c217d954SCole Faust
7272*c217d954SCole Faust detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7273*c217d954SCole Faust if (err != NULL) {
7274*c217d954SCole Faust *err = error;
7275*c217d954SCole Faust }
7276*c217d954SCole Faust }
7277*c217d954SCole Faust #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7278*c217d954SCole Faust
7279*c217d954SCole Faust }
7280*c217d954SCole Faust }
7281*c217d954SCole Faust
7282*c217d954SCole Faust /*!
7283*c217d954SCole Faust * \brief Constructs a CommandQueue for an implementation defined device in the given context
7284*c217d954SCole Faust * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
7285*c217d954SCole Faust */
7286*c217d954SCole Faust explicit CommandQueue(
7287*c217d954SCole Faust const Context& context,
7288*c217d954SCole Faust cl_command_queue_properties properties = 0,
7289*c217d954SCole Faust cl_int* err = NULL)
7290*c217d954SCole Faust {
7291*c217d954SCole Faust cl_int error;
7292*c217d954SCole Faust bool useWithProperties;
7293*c217d954SCole Faust vector<cl::Device> devices;
7294*c217d954SCole Faust error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7295*c217d954SCole Faust
7296*c217d954SCole Faust detail::errHandler(error, __CREATE_CONTEXT_ERR);
7297*c217d954SCole Faust
7298*c217d954SCole Faust if (error != CL_SUCCESS)
7299*c217d954SCole Faust {
7300*c217d954SCole Faust if (err != NULL) {
7301*c217d954SCole Faust *err = error;
7302*c217d954SCole Faust }
7303*c217d954SCole Faust return;
7304*c217d954SCole Faust }
7305*c217d954SCole Faust
7306*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7307*c217d954SCole Faust // Run-time decision based on the actual platform
7308*c217d954SCole Faust {
7309*c217d954SCole Faust cl_uint version = detail::getContextPlatformVersion(context());
7310*c217d954SCole Faust useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7311*c217d954SCole Faust }
7312*c217d954SCole Faust #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7313*c217d954SCole Faust useWithProperties = true;
7314*c217d954SCole Faust #else
7315*c217d954SCole Faust useWithProperties = false;
7316*c217d954SCole Faust #endif
7317*c217d954SCole Faust
7318*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7319*c217d954SCole Faust if (useWithProperties) {
7320*c217d954SCole Faust cl_queue_properties queue_properties[] = {
7321*c217d954SCole Faust CL_QUEUE_PROPERTIES, properties, 0 };
7322*c217d954SCole Faust if ((properties & CL_QUEUE_ON_DEVICE) == 0) {
7323*c217d954SCole Faust object_ = ::clCreateCommandQueueWithProperties(
7324*c217d954SCole Faust context(), devices[0](), queue_properties, &error);
7325*c217d954SCole Faust }
7326*c217d954SCole Faust else {
7327*c217d954SCole Faust error = CL_INVALID_QUEUE_PROPERTIES;
7328*c217d954SCole Faust }
7329*c217d954SCole Faust
7330*c217d954SCole Faust detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7331*c217d954SCole Faust if (err != NULL) {
7332*c217d954SCole Faust *err = error;
7333*c217d954SCole Faust }
7334*c217d954SCole Faust }
7335*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7336*c217d954SCole Faust #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7337*c217d954SCole Faust if (!useWithProperties) {
7338*c217d954SCole Faust object_ = ::clCreateCommandQueue(
7339*c217d954SCole Faust context(), devices[0](), properties, &error);
7340*c217d954SCole Faust
7341*c217d954SCole Faust detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7342*c217d954SCole Faust if (err != NULL) {
7343*c217d954SCole Faust *err = error;
7344*c217d954SCole Faust }
7345*c217d954SCole Faust }
7346*c217d954SCole Faust #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7347*c217d954SCole Faust }
7348*c217d954SCole Faust
7349*c217d954SCole Faust /*!
7350*c217d954SCole Faust * \brief Constructs a CommandQueue for an implementation defined device in the given context
7351*c217d954SCole Faust * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
7352*c217d954SCole Faust */
7353*c217d954SCole Faust explicit CommandQueue(
7354*c217d954SCole Faust const Context& context,
7355*c217d954SCole Faust QueueProperties properties,
7356*c217d954SCole Faust cl_int* err = NULL)
7357*c217d954SCole Faust {
7358*c217d954SCole Faust cl_int error;
7359*c217d954SCole Faust bool useWithProperties;
7360*c217d954SCole Faust vector<cl::Device> devices;
7361*c217d954SCole Faust error = context.getInfo(CL_CONTEXT_DEVICES, &devices);
7362*c217d954SCole Faust
7363*c217d954SCole Faust detail::errHandler(error, __CREATE_CONTEXT_ERR);
7364*c217d954SCole Faust
7365*c217d954SCole Faust if (error != CL_SUCCESS)
7366*c217d954SCole Faust {
7367*c217d954SCole Faust if (err != NULL) {
7368*c217d954SCole Faust *err = error;
7369*c217d954SCole Faust }
7370*c217d954SCole Faust return;
7371*c217d954SCole Faust }
7372*c217d954SCole Faust
7373*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7374*c217d954SCole Faust // Run-time decision based on the actual platform
7375*c217d954SCole Faust {
7376*c217d954SCole Faust cl_uint version = detail::getContextPlatformVersion(context());
7377*c217d954SCole Faust useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7378*c217d954SCole Faust }
7379*c217d954SCole Faust #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7380*c217d954SCole Faust useWithProperties = true;
7381*c217d954SCole Faust #else
7382*c217d954SCole Faust useWithProperties = false;
7383*c217d954SCole Faust #endif
7384*c217d954SCole Faust
7385*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7386*c217d954SCole Faust if (useWithProperties) {
7387*c217d954SCole Faust cl_queue_properties queue_properties[] = {
7388*c217d954SCole Faust CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7389*c217d954SCole Faust object_ = ::clCreateCommandQueueWithProperties(
7390*c217d954SCole Faust context(), devices[0](), queue_properties, &error);
7391*c217d954SCole Faust
7392*c217d954SCole Faust detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7393*c217d954SCole Faust if (err != NULL) {
7394*c217d954SCole Faust *err = error;
7395*c217d954SCole Faust }
7396*c217d954SCole Faust }
7397*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7398*c217d954SCole Faust #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7399*c217d954SCole Faust if (!useWithProperties) {
7400*c217d954SCole Faust object_ = ::clCreateCommandQueue(
7401*c217d954SCole Faust context(), devices[0](), static_cast<cl_command_queue_properties>(properties), &error);
7402*c217d954SCole Faust
7403*c217d954SCole Faust detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7404*c217d954SCole Faust if (err != NULL) {
7405*c217d954SCole Faust *err = error;
7406*c217d954SCole Faust }
7407*c217d954SCole Faust }
7408*c217d954SCole Faust #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7409*c217d954SCole Faust }
7410*c217d954SCole Faust
7411*c217d954SCole Faust /*!
7412*c217d954SCole Faust * \brief Constructs a CommandQueue for a passed device and context
7413*c217d954SCole Faust * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
7414*c217d954SCole Faust */
7415*c217d954SCole Faust CommandQueue(
7416*c217d954SCole Faust const Context& context,
7417*c217d954SCole Faust const Device& device,
7418*c217d954SCole Faust cl_command_queue_properties properties = 0,
7419*c217d954SCole Faust cl_int* err = NULL)
7420*c217d954SCole Faust {
7421*c217d954SCole Faust cl_int error;
7422*c217d954SCole Faust bool useWithProperties;
7423*c217d954SCole Faust
7424*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7425*c217d954SCole Faust // Run-time decision based on the actual platform
7426*c217d954SCole Faust {
7427*c217d954SCole Faust cl_uint version = detail::getContextPlatformVersion(context());
7428*c217d954SCole Faust useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7429*c217d954SCole Faust }
7430*c217d954SCole Faust #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7431*c217d954SCole Faust useWithProperties = true;
7432*c217d954SCole Faust #else
7433*c217d954SCole Faust useWithProperties = false;
7434*c217d954SCole Faust #endif
7435*c217d954SCole Faust
7436*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7437*c217d954SCole Faust if (useWithProperties) {
7438*c217d954SCole Faust cl_queue_properties queue_properties[] = {
7439*c217d954SCole Faust CL_QUEUE_PROPERTIES, properties, 0 };
7440*c217d954SCole Faust object_ = ::clCreateCommandQueueWithProperties(
7441*c217d954SCole Faust context(), device(), queue_properties, &error);
7442*c217d954SCole Faust
7443*c217d954SCole Faust detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7444*c217d954SCole Faust if (err != NULL) {
7445*c217d954SCole Faust *err = error;
7446*c217d954SCole Faust }
7447*c217d954SCole Faust }
7448*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7449*c217d954SCole Faust #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7450*c217d954SCole Faust if (!useWithProperties) {
7451*c217d954SCole Faust object_ = ::clCreateCommandQueue(
7452*c217d954SCole Faust context(), device(), properties, &error);
7453*c217d954SCole Faust
7454*c217d954SCole Faust detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7455*c217d954SCole Faust if (err != NULL) {
7456*c217d954SCole Faust *err = error;
7457*c217d954SCole Faust }
7458*c217d954SCole Faust }
7459*c217d954SCole Faust #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7460*c217d954SCole Faust }
7461*c217d954SCole Faust
7462*c217d954SCole Faust /*!
7463*c217d954SCole Faust * \brief Constructs a CommandQueue for a passed device and context
7464*c217d954SCole Faust * Will return an CL_INVALID_QUEUE_PROPERTIES error if CL_QUEUE_ON_DEVICE is specified.
7465*c217d954SCole Faust */
7466*c217d954SCole Faust CommandQueue(
7467*c217d954SCole Faust const Context& context,
7468*c217d954SCole Faust const Device& device,
7469*c217d954SCole Faust QueueProperties properties,
7470*c217d954SCole Faust cl_int* err = NULL)
7471*c217d954SCole Faust {
7472*c217d954SCole Faust cl_int error;
7473*c217d954SCole Faust bool useWithProperties;
7474*c217d954SCole Faust
7475*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200 && CL_HPP_MINIMUM_OPENCL_VERSION < 200
7476*c217d954SCole Faust // Run-time decision based on the actual platform
7477*c217d954SCole Faust {
7478*c217d954SCole Faust cl_uint version = detail::getContextPlatformVersion(context());
7479*c217d954SCole Faust useWithProperties = (version >= 0x20000); // OpenCL 2.0 or above
7480*c217d954SCole Faust }
7481*c217d954SCole Faust #elif CL_HPP_TARGET_OPENCL_VERSION >= 200
7482*c217d954SCole Faust useWithProperties = true;
7483*c217d954SCole Faust #else
7484*c217d954SCole Faust useWithProperties = false;
7485*c217d954SCole Faust #endif
7486*c217d954SCole Faust
7487*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7488*c217d954SCole Faust if (useWithProperties) {
7489*c217d954SCole Faust cl_queue_properties queue_properties[] = {
7490*c217d954SCole Faust CL_QUEUE_PROPERTIES, static_cast<cl_queue_properties>(properties), 0 };
7491*c217d954SCole Faust object_ = ::clCreateCommandQueueWithProperties(
7492*c217d954SCole Faust context(), device(), queue_properties, &error);
7493*c217d954SCole Faust
7494*c217d954SCole Faust detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7495*c217d954SCole Faust if (err != NULL) {
7496*c217d954SCole Faust *err = error;
7497*c217d954SCole Faust }
7498*c217d954SCole Faust }
7499*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7500*c217d954SCole Faust #if CL_HPP_MINIMUM_OPENCL_VERSION < 200
7501*c217d954SCole Faust if (!useWithProperties) {
7502*c217d954SCole Faust object_ = ::clCreateCommandQueue(
7503*c217d954SCole Faust context(), device(), static_cast<cl_command_queue_properties>(properties), &error);
7504*c217d954SCole Faust
7505*c217d954SCole Faust detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
7506*c217d954SCole Faust if (err != NULL) {
7507*c217d954SCole Faust *err = error;
7508*c217d954SCole Faust }
7509*c217d954SCole Faust }
7510*c217d954SCole Faust #endif // CL_HPP_MINIMUM_OPENCL_VERSION < 200
7511*c217d954SCole Faust }
7512*c217d954SCole Faust
7513*c217d954SCole Faust static CommandQueue getDefault(cl_int * err = NULL)
7514*c217d954SCole Faust {
7515*c217d954SCole Faust std::call_once(default_initialized_, makeDefault);
7516*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
7517*c217d954SCole Faust detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
7518*c217d954SCole Faust #else // CL_HPP_TARGET_OPENCL_VERSION >= 200
7519*c217d954SCole Faust detail::errHandler(default_error_, __CREATE_COMMAND_QUEUE_ERR);
7520*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 200
7521*c217d954SCole Faust if (err != NULL) {
7522*c217d954SCole Faust *err = default_error_;
7523*c217d954SCole Faust }
7524*c217d954SCole Faust return default_;
7525*c217d954SCole Faust }
7526*c217d954SCole Faust
7527*c217d954SCole Faust /**
7528*c217d954SCole Faust * Modify the default command queue to be used by
7529*c217d954SCole Faust * subsequent operations.
7530*c217d954SCole Faust * Will only set the default if no default was previously created.
7531*c217d954SCole Faust * @return updated default command queue.
7532*c217d954SCole Faust * Should be compared to the passed value to ensure that it was updated.
7533*c217d954SCole Faust */
7534*c217d954SCole Faust static CommandQueue setDefault(const CommandQueue &default_queue)
7535*c217d954SCole Faust {
7536*c217d954SCole Faust std::call_once(default_initialized_, makeDefaultProvided, std::cref(default_queue));
7537*c217d954SCole Faust detail::errHandler(default_error_);
7538*c217d954SCole Faust return default_;
7539*c217d954SCole Faust }
7540*c217d954SCole Faust
7541*c217d954SCole Faust CommandQueue() { }
7542*c217d954SCole Faust
7543*c217d954SCole Faust
7544*c217d954SCole Faust /*! \brief Constructor from cl_command_queue - takes ownership.
7545*c217d954SCole Faust *
7546*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
7547*c217d954SCole Faust * Defaults to false to maintain compatibility with
7548*c217d954SCole Faust * earlier versions.
7549*c217d954SCole Faust */
7550*c217d954SCole Faust explicit CommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
7551*c217d954SCole Faust detail::Wrapper<cl_type>(commandQueue, retainObject) { }
7552*c217d954SCole Faust
7553*c217d954SCole Faust CommandQueue& operator = (const cl_command_queue& rhs)
7554*c217d954SCole Faust {
7555*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(rhs);
7556*c217d954SCole Faust return *this;
7557*c217d954SCole Faust }
7558*c217d954SCole Faust
7559*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
7560*c217d954SCole Faust * Required for MSVC.
7561*c217d954SCole Faust */
7562*c217d954SCole Faust CommandQueue(const CommandQueue& queue) : detail::Wrapper<cl_type>(queue) {}
7563*c217d954SCole Faust
7564*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
7565*c217d954SCole Faust * Required for MSVC.
7566*c217d954SCole Faust */
7567*c217d954SCole Faust CommandQueue& operator = (const CommandQueue &queue)
7568*c217d954SCole Faust {
7569*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(queue);
7570*c217d954SCole Faust return *this;
7571*c217d954SCole Faust }
7572*c217d954SCole Faust
7573*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
7574*c217d954SCole Faust * Required for MSVC.
7575*c217d954SCole Faust */
7576*c217d954SCole Faust CommandQueue(CommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(queue)) {}
7577*c217d954SCole Faust
7578*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
7579*c217d954SCole Faust * Required for MSVC.
7580*c217d954SCole Faust */
7581*c217d954SCole Faust CommandQueue& operator = (CommandQueue &&queue)
7582*c217d954SCole Faust {
7583*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(std::move(queue));
7584*c217d954SCole Faust return *this;
7585*c217d954SCole Faust }
7586*c217d954SCole Faust
7587*c217d954SCole Faust template <typename T>
7588*c217d954SCole Faust cl_int getInfo(cl_command_queue_info name, T* param) const
7589*c217d954SCole Faust {
7590*c217d954SCole Faust return detail::errHandler(
7591*c217d954SCole Faust detail::getInfo(
7592*c217d954SCole Faust &::clGetCommandQueueInfo, object_, name, param),
7593*c217d954SCole Faust __GET_COMMAND_QUEUE_INFO_ERR);
7594*c217d954SCole Faust }
7595*c217d954SCole Faust
7596*c217d954SCole Faust template <cl_command_queue_info name> typename
7597*c217d954SCole Faust detail::param_traits<detail::cl_command_queue_info, name>::param_type
7598*c217d954SCole Faust getInfo(cl_int* err = NULL) const
7599*c217d954SCole Faust {
7600*c217d954SCole Faust typename detail::param_traits<
7601*c217d954SCole Faust detail::cl_command_queue_info, name>::param_type param;
7602*c217d954SCole Faust cl_int result = getInfo(name, ¶m);
7603*c217d954SCole Faust if (err != NULL) {
7604*c217d954SCole Faust *err = result;
7605*c217d954SCole Faust }
7606*c217d954SCole Faust return param;
7607*c217d954SCole Faust }
7608*c217d954SCole Faust
7609*c217d954SCole Faust cl_int enqueueReadBuffer(
7610*c217d954SCole Faust const Buffer& buffer,
7611*c217d954SCole Faust cl_bool blocking,
7612*c217d954SCole Faust size_type offset,
7613*c217d954SCole Faust size_type size,
7614*c217d954SCole Faust void* ptr,
7615*c217d954SCole Faust const vector<Event>* events = NULL,
7616*c217d954SCole Faust Event* event = NULL) const
7617*c217d954SCole Faust {
7618*c217d954SCole Faust cl_event tmp;
7619*c217d954SCole Faust cl_int err = detail::errHandler(
7620*c217d954SCole Faust ::clEnqueueReadBuffer(
7621*c217d954SCole Faust object_, buffer(), blocking, offset, size,
7622*c217d954SCole Faust ptr,
7623*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
7624*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7625*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
7626*c217d954SCole Faust __ENQUEUE_READ_BUFFER_ERR);
7627*c217d954SCole Faust
7628*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
7629*c217d954SCole Faust *event = tmp;
7630*c217d954SCole Faust
7631*c217d954SCole Faust return err;
7632*c217d954SCole Faust }
7633*c217d954SCole Faust
7634*c217d954SCole Faust cl_int enqueueWriteBuffer(
7635*c217d954SCole Faust const Buffer& buffer,
7636*c217d954SCole Faust cl_bool blocking,
7637*c217d954SCole Faust size_type offset,
7638*c217d954SCole Faust size_type size,
7639*c217d954SCole Faust const void* ptr,
7640*c217d954SCole Faust const vector<Event>* events = NULL,
7641*c217d954SCole Faust Event* event = NULL) const
7642*c217d954SCole Faust {
7643*c217d954SCole Faust cl_event tmp;
7644*c217d954SCole Faust cl_int err = detail::errHandler(
7645*c217d954SCole Faust ::clEnqueueWriteBuffer(
7646*c217d954SCole Faust object_, buffer(), blocking, offset, size,
7647*c217d954SCole Faust ptr,
7648*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
7649*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7650*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
7651*c217d954SCole Faust __ENQUEUE_WRITE_BUFFER_ERR);
7652*c217d954SCole Faust
7653*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
7654*c217d954SCole Faust *event = tmp;
7655*c217d954SCole Faust
7656*c217d954SCole Faust return err;
7657*c217d954SCole Faust }
7658*c217d954SCole Faust
7659*c217d954SCole Faust cl_int enqueueCopyBuffer(
7660*c217d954SCole Faust const Buffer& src,
7661*c217d954SCole Faust const Buffer& dst,
7662*c217d954SCole Faust size_type src_offset,
7663*c217d954SCole Faust size_type dst_offset,
7664*c217d954SCole Faust size_type size,
7665*c217d954SCole Faust const vector<Event>* events = NULL,
7666*c217d954SCole Faust Event* event = NULL) const
7667*c217d954SCole Faust {
7668*c217d954SCole Faust cl_event tmp;
7669*c217d954SCole Faust cl_int err = detail::errHandler(
7670*c217d954SCole Faust ::clEnqueueCopyBuffer(
7671*c217d954SCole Faust object_, src(), dst(), src_offset, dst_offset, size,
7672*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
7673*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7674*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
7675*c217d954SCole Faust __ENQEUE_COPY_BUFFER_ERR);
7676*c217d954SCole Faust
7677*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
7678*c217d954SCole Faust *event = tmp;
7679*c217d954SCole Faust
7680*c217d954SCole Faust return err;
7681*c217d954SCole Faust }
7682*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 110
7683*c217d954SCole Faust cl_int enqueueReadBufferRect(
7684*c217d954SCole Faust const Buffer& buffer,
7685*c217d954SCole Faust cl_bool blocking,
7686*c217d954SCole Faust const array<size_type, 3>& buffer_offset,
7687*c217d954SCole Faust const array<size_type, 3>& host_offset,
7688*c217d954SCole Faust const array<size_type, 3>& region,
7689*c217d954SCole Faust size_type buffer_row_pitch,
7690*c217d954SCole Faust size_type buffer_slice_pitch,
7691*c217d954SCole Faust size_type host_row_pitch,
7692*c217d954SCole Faust size_type host_slice_pitch,
7693*c217d954SCole Faust void *ptr,
7694*c217d954SCole Faust const vector<Event>* events = NULL,
7695*c217d954SCole Faust Event* event = NULL) const
7696*c217d954SCole Faust {
7697*c217d954SCole Faust cl_event tmp;
7698*c217d954SCole Faust cl_int err = detail::errHandler(
7699*c217d954SCole Faust ::clEnqueueReadBufferRect(
7700*c217d954SCole Faust object_,
7701*c217d954SCole Faust buffer(),
7702*c217d954SCole Faust blocking,
7703*c217d954SCole Faust buffer_offset.data(),
7704*c217d954SCole Faust host_offset.data(),
7705*c217d954SCole Faust region.data(),
7706*c217d954SCole Faust buffer_row_pitch,
7707*c217d954SCole Faust buffer_slice_pitch,
7708*c217d954SCole Faust host_row_pitch,
7709*c217d954SCole Faust host_slice_pitch,
7710*c217d954SCole Faust ptr,
7711*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
7712*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7713*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
7714*c217d954SCole Faust __ENQUEUE_READ_BUFFER_RECT_ERR);
7715*c217d954SCole Faust
7716*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
7717*c217d954SCole Faust *event = tmp;
7718*c217d954SCole Faust
7719*c217d954SCole Faust return err;
7720*c217d954SCole Faust }
7721*c217d954SCole Faust
7722*c217d954SCole Faust cl_int enqueueWriteBufferRect(
7723*c217d954SCole Faust const Buffer& buffer,
7724*c217d954SCole Faust cl_bool blocking,
7725*c217d954SCole Faust const array<size_type, 3>& buffer_offset,
7726*c217d954SCole Faust const array<size_type, 3>& host_offset,
7727*c217d954SCole Faust const array<size_type, 3>& region,
7728*c217d954SCole Faust size_type buffer_row_pitch,
7729*c217d954SCole Faust size_type buffer_slice_pitch,
7730*c217d954SCole Faust size_type host_row_pitch,
7731*c217d954SCole Faust size_type host_slice_pitch,
7732*c217d954SCole Faust const void *ptr,
7733*c217d954SCole Faust const vector<Event>* events = NULL,
7734*c217d954SCole Faust Event* event = NULL) const
7735*c217d954SCole Faust {
7736*c217d954SCole Faust cl_event tmp;
7737*c217d954SCole Faust cl_int err = detail::errHandler(
7738*c217d954SCole Faust ::clEnqueueWriteBufferRect(
7739*c217d954SCole Faust object_,
7740*c217d954SCole Faust buffer(),
7741*c217d954SCole Faust blocking,
7742*c217d954SCole Faust buffer_offset.data(),
7743*c217d954SCole Faust host_offset.data(),
7744*c217d954SCole Faust region.data(),
7745*c217d954SCole Faust buffer_row_pitch,
7746*c217d954SCole Faust buffer_slice_pitch,
7747*c217d954SCole Faust host_row_pitch,
7748*c217d954SCole Faust host_slice_pitch,
7749*c217d954SCole Faust ptr,
7750*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
7751*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7752*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
7753*c217d954SCole Faust __ENQUEUE_WRITE_BUFFER_RECT_ERR);
7754*c217d954SCole Faust
7755*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
7756*c217d954SCole Faust *event = tmp;
7757*c217d954SCole Faust
7758*c217d954SCole Faust return err;
7759*c217d954SCole Faust }
7760*c217d954SCole Faust
7761*c217d954SCole Faust cl_int enqueueCopyBufferRect(
7762*c217d954SCole Faust const Buffer& src,
7763*c217d954SCole Faust const Buffer& dst,
7764*c217d954SCole Faust const array<size_type, 3>& src_origin,
7765*c217d954SCole Faust const array<size_type, 3>& dst_origin,
7766*c217d954SCole Faust const array<size_type, 3>& region,
7767*c217d954SCole Faust size_type src_row_pitch,
7768*c217d954SCole Faust size_type src_slice_pitch,
7769*c217d954SCole Faust size_type dst_row_pitch,
7770*c217d954SCole Faust size_type dst_slice_pitch,
7771*c217d954SCole Faust const vector<Event>* events = NULL,
7772*c217d954SCole Faust Event* event = NULL) const
7773*c217d954SCole Faust {
7774*c217d954SCole Faust cl_event tmp;
7775*c217d954SCole Faust cl_int err = detail::errHandler(
7776*c217d954SCole Faust ::clEnqueueCopyBufferRect(
7777*c217d954SCole Faust object_,
7778*c217d954SCole Faust src(),
7779*c217d954SCole Faust dst(),
7780*c217d954SCole Faust src_origin.data(),
7781*c217d954SCole Faust dst_origin.data(),
7782*c217d954SCole Faust region.data(),
7783*c217d954SCole Faust src_row_pitch,
7784*c217d954SCole Faust src_slice_pitch,
7785*c217d954SCole Faust dst_row_pitch,
7786*c217d954SCole Faust dst_slice_pitch,
7787*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
7788*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7789*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
7790*c217d954SCole Faust __ENQEUE_COPY_BUFFER_RECT_ERR);
7791*c217d954SCole Faust
7792*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
7793*c217d954SCole Faust *event = tmp;
7794*c217d954SCole Faust
7795*c217d954SCole Faust return err;
7796*c217d954SCole Faust }
7797*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
7798*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
7799*c217d954SCole Faust /**
7800*c217d954SCole Faust * Enqueue a command to fill a buffer object with a pattern
7801*c217d954SCole Faust * of a given size. The pattern is specified as a vector type.
7802*c217d954SCole Faust * \tparam PatternType The datatype of the pattern field.
7803*c217d954SCole Faust * The pattern type must be an accepted OpenCL data type.
7804*c217d954SCole Faust * \tparam offset Is the offset in bytes into the buffer at
7805*c217d954SCole Faust * which to start filling. This must be a multiple of
7806*c217d954SCole Faust * the pattern size.
7807*c217d954SCole Faust * \tparam size Is the size in bytes of the region to fill.
7808*c217d954SCole Faust * This must be a multiple of the pattern size.
7809*c217d954SCole Faust */
7810*c217d954SCole Faust template<typename PatternType>
7811*c217d954SCole Faust cl_int enqueueFillBuffer(
7812*c217d954SCole Faust const Buffer& buffer,
7813*c217d954SCole Faust PatternType pattern,
7814*c217d954SCole Faust size_type offset,
7815*c217d954SCole Faust size_type size,
7816*c217d954SCole Faust const vector<Event>* events = NULL,
7817*c217d954SCole Faust Event* event = NULL) const
7818*c217d954SCole Faust {
7819*c217d954SCole Faust cl_event tmp;
7820*c217d954SCole Faust cl_int err = detail::errHandler(
7821*c217d954SCole Faust ::clEnqueueFillBuffer(
7822*c217d954SCole Faust object_,
7823*c217d954SCole Faust buffer(),
7824*c217d954SCole Faust static_cast<void*>(&pattern),
7825*c217d954SCole Faust sizeof(PatternType),
7826*c217d954SCole Faust offset,
7827*c217d954SCole Faust size,
7828*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
7829*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7830*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
7831*c217d954SCole Faust __ENQUEUE_FILL_BUFFER_ERR);
7832*c217d954SCole Faust
7833*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
7834*c217d954SCole Faust *event = tmp;
7835*c217d954SCole Faust
7836*c217d954SCole Faust return err;
7837*c217d954SCole Faust }
7838*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
7839*c217d954SCole Faust
7840*c217d954SCole Faust cl_int enqueueReadImage(
7841*c217d954SCole Faust const Image& image,
7842*c217d954SCole Faust cl_bool blocking,
7843*c217d954SCole Faust const array<size_type, 3>& origin,
7844*c217d954SCole Faust const array<size_type, 3>& region,
7845*c217d954SCole Faust size_type row_pitch,
7846*c217d954SCole Faust size_type slice_pitch,
7847*c217d954SCole Faust void* ptr,
7848*c217d954SCole Faust const vector<Event>* events = NULL,
7849*c217d954SCole Faust Event* event = NULL) const
7850*c217d954SCole Faust {
7851*c217d954SCole Faust cl_event tmp;
7852*c217d954SCole Faust cl_int err = detail::errHandler(
7853*c217d954SCole Faust ::clEnqueueReadImage(
7854*c217d954SCole Faust object_,
7855*c217d954SCole Faust image(),
7856*c217d954SCole Faust blocking,
7857*c217d954SCole Faust origin.data(),
7858*c217d954SCole Faust region.data(),
7859*c217d954SCole Faust row_pitch,
7860*c217d954SCole Faust slice_pitch,
7861*c217d954SCole Faust ptr,
7862*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
7863*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7864*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
7865*c217d954SCole Faust __ENQUEUE_READ_IMAGE_ERR);
7866*c217d954SCole Faust
7867*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
7868*c217d954SCole Faust *event = tmp;
7869*c217d954SCole Faust
7870*c217d954SCole Faust return err;
7871*c217d954SCole Faust }
7872*c217d954SCole Faust
7873*c217d954SCole Faust cl_int enqueueWriteImage(
7874*c217d954SCole Faust const Image& image,
7875*c217d954SCole Faust cl_bool blocking,
7876*c217d954SCole Faust const array<size_type, 3>& origin,
7877*c217d954SCole Faust const array<size_type, 3>& region,
7878*c217d954SCole Faust size_type row_pitch,
7879*c217d954SCole Faust size_type slice_pitch,
7880*c217d954SCole Faust const void* ptr,
7881*c217d954SCole Faust const vector<Event>* events = NULL,
7882*c217d954SCole Faust Event* event = NULL) const
7883*c217d954SCole Faust {
7884*c217d954SCole Faust cl_event tmp;
7885*c217d954SCole Faust cl_int err = detail::errHandler(
7886*c217d954SCole Faust ::clEnqueueWriteImage(
7887*c217d954SCole Faust object_,
7888*c217d954SCole Faust image(),
7889*c217d954SCole Faust blocking,
7890*c217d954SCole Faust origin.data(),
7891*c217d954SCole Faust region.data(),
7892*c217d954SCole Faust row_pitch,
7893*c217d954SCole Faust slice_pitch,
7894*c217d954SCole Faust ptr,
7895*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
7896*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7897*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
7898*c217d954SCole Faust __ENQUEUE_WRITE_IMAGE_ERR);
7899*c217d954SCole Faust
7900*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
7901*c217d954SCole Faust *event = tmp;
7902*c217d954SCole Faust
7903*c217d954SCole Faust return err;
7904*c217d954SCole Faust }
7905*c217d954SCole Faust
7906*c217d954SCole Faust cl_int enqueueCopyImage(
7907*c217d954SCole Faust const Image& src,
7908*c217d954SCole Faust const Image& dst,
7909*c217d954SCole Faust const array<size_type, 3>& src_origin,
7910*c217d954SCole Faust const array<size_type, 3>& dst_origin,
7911*c217d954SCole Faust const array<size_type, 3>& region,
7912*c217d954SCole Faust const vector<Event>* events = NULL,
7913*c217d954SCole Faust Event* event = NULL) const
7914*c217d954SCole Faust {
7915*c217d954SCole Faust cl_event tmp;
7916*c217d954SCole Faust cl_int err = detail::errHandler(
7917*c217d954SCole Faust ::clEnqueueCopyImage(
7918*c217d954SCole Faust object_,
7919*c217d954SCole Faust src(),
7920*c217d954SCole Faust dst(),
7921*c217d954SCole Faust src_origin.data(),
7922*c217d954SCole Faust dst_origin.data(),
7923*c217d954SCole Faust region.data(),
7924*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
7925*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7926*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
7927*c217d954SCole Faust __ENQUEUE_COPY_IMAGE_ERR);
7928*c217d954SCole Faust
7929*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
7930*c217d954SCole Faust *event = tmp;
7931*c217d954SCole Faust
7932*c217d954SCole Faust return err;
7933*c217d954SCole Faust }
7934*c217d954SCole Faust
7935*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
7936*c217d954SCole Faust /**
7937*c217d954SCole Faust * Enqueue a command to fill an image object with a specified color.
7938*c217d954SCole Faust * \param fillColor is the color to use to fill the image.
7939*c217d954SCole Faust * This is a four component RGBA floating-point color value if
7940*c217d954SCole Faust * the image channel data type is not an unnormalized signed or
7941*c217d954SCole Faust * unsigned data type.
7942*c217d954SCole Faust */
7943*c217d954SCole Faust cl_int enqueueFillImage(
7944*c217d954SCole Faust const Image& image,
7945*c217d954SCole Faust cl_float4 fillColor,
7946*c217d954SCole Faust const array<size_type, 3>& origin,
7947*c217d954SCole Faust const array<size_type, 3>& region,
7948*c217d954SCole Faust const vector<Event>* events = NULL,
7949*c217d954SCole Faust Event* event = NULL) const
7950*c217d954SCole Faust {
7951*c217d954SCole Faust cl_event tmp;
7952*c217d954SCole Faust cl_int err = detail::errHandler(
7953*c217d954SCole Faust ::clEnqueueFillImage(
7954*c217d954SCole Faust object_,
7955*c217d954SCole Faust image(),
7956*c217d954SCole Faust static_cast<void*>(&fillColor),
7957*c217d954SCole Faust origin.data(),
7958*c217d954SCole Faust region.data(),
7959*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
7960*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7961*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
7962*c217d954SCole Faust __ENQUEUE_FILL_IMAGE_ERR);
7963*c217d954SCole Faust
7964*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
7965*c217d954SCole Faust *event = tmp;
7966*c217d954SCole Faust
7967*c217d954SCole Faust return err;
7968*c217d954SCole Faust }
7969*c217d954SCole Faust
7970*c217d954SCole Faust /**
7971*c217d954SCole Faust * Enqueue a command to fill an image object with a specified color.
7972*c217d954SCole Faust * \param fillColor is the color to use to fill the image.
7973*c217d954SCole Faust * This is a four component RGBA signed integer color value if
7974*c217d954SCole Faust * the image channel data type is an unnormalized signed integer
7975*c217d954SCole Faust * type.
7976*c217d954SCole Faust */
7977*c217d954SCole Faust cl_int enqueueFillImage(
7978*c217d954SCole Faust const Image& image,
7979*c217d954SCole Faust cl_int4 fillColor,
7980*c217d954SCole Faust const array<size_type, 3>& origin,
7981*c217d954SCole Faust const array<size_type, 3>& region,
7982*c217d954SCole Faust const vector<Event>* events = NULL,
7983*c217d954SCole Faust Event* event = NULL) const
7984*c217d954SCole Faust {
7985*c217d954SCole Faust cl_event tmp;
7986*c217d954SCole Faust cl_int err = detail::errHandler(
7987*c217d954SCole Faust ::clEnqueueFillImage(
7988*c217d954SCole Faust object_,
7989*c217d954SCole Faust image(),
7990*c217d954SCole Faust static_cast<void*>(&fillColor),
7991*c217d954SCole Faust origin.data(),
7992*c217d954SCole Faust region.data(),
7993*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
7994*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
7995*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
7996*c217d954SCole Faust __ENQUEUE_FILL_IMAGE_ERR);
7997*c217d954SCole Faust
7998*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
7999*c217d954SCole Faust *event = tmp;
8000*c217d954SCole Faust
8001*c217d954SCole Faust return err;
8002*c217d954SCole Faust }
8003*c217d954SCole Faust
8004*c217d954SCole Faust /**
8005*c217d954SCole Faust * Enqueue a command to fill an image object with a specified color.
8006*c217d954SCole Faust * \param fillColor is the color to use to fill the image.
8007*c217d954SCole Faust * This is a four component RGBA unsigned integer color value if
8008*c217d954SCole Faust * the image channel data type is an unnormalized unsigned integer
8009*c217d954SCole Faust * type.
8010*c217d954SCole Faust */
8011*c217d954SCole Faust cl_int enqueueFillImage(
8012*c217d954SCole Faust const Image& image,
8013*c217d954SCole Faust cl_uint4 fillColor,
8014*c217d954SCole Faust const array<size_type, 3>& origin,
8015*c217d954SCole Faust const array<size_type, 3>& region,
8016*c217d954SCole Faust const vector<Event>* events = NULL,
8017*c217d954SCole Faust Event* event = NULL) const
8018*c217d954SCole Faust {
8019*c217d954SCole Faust cl_event tmp;
8020*c217d954SCole Faust cl_int err = detail::errHandler(
8021*c217d954SCole Faust ::clEnqueueFillImage(
8022*c217d954SCole Faust object_,
8023*c217d954SCole Faust image(),
8024*c217d954SCole Faust static_cast<void*>(&fillColor),
8025*c217d954SCole Faust origin.data(),
8026*c217d954SCole Faust region.data(),
8027*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
8028*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8029*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8030*c217d954SCole Faust __ENQUEUE_FILL_IMAGE_ERR);
8031*c217d954SCole Faust
8032*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8033*c217d954SCole Faust *event = tmp;
8034*c217d954SCole Faust
8035*c217d954SCole Faust return err;
8036*c217d954SCole Faust }
8037*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8038*c217d954SCole Faust
8039*c217d954SCole Faust cl_int enqueueCopyImageToBuffer(
8040*c217d954SCole Faust const Image& src,
8041*c217d954SCole Faust const Buffer& dst,
8042*c217d954SCole Faust const array<size_type, 3>& src_origin,
8043*c217d954SCole Faust const array<size_type, 3>& region,
8044*c217d954SCole Faust size_type dst_offset,
8045*c217d954SCole Faust const vector<Event>* events = NULL,
8046*c217d954SCole Faust Event* event = NULL) const
8047*c217d954SCole Faust {
8048*c217d954SCole Faust cl_event tmp;
8049*c217d954SCole Faust cl_int err = detail::errHandler(
8050*c217d954SCole Faust ::clEnqueueCopyImageToBuffer(
8051*c217d954SCole Faust object_,
8052*c217d954SCole Faust src(),
8053*c217d954SCole Faust dst(),
8054*c217d954SCole Faust src_origin.data(),
8055*c217d954SCole Faust region.data(),
8056*c217d954SCole Faust dst_offset,
8057*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
8058*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8059*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8060*c217d954SCole Faust __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
8061*c217d954SCole Faust
8062*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8063*c217d954SCole Faust *event = tmp;
8064*c217d954SCole Faust
8065*c217d954SCole Faust return err;
8066*c217d954SCole Faust }
8067*c217d954SCole Faust
8068*c217d954SCole Faust cl_int enqueueCopyBufferToImage(
8069*c217d954SCole Faust const Buffer& src,
8070*c217d954SCole Faust const Image& dst,
8071*c217d954SCole Faust size_type src_offset,
8072*c217d954SCole Faust const array<size_type, 3>& dst_origin,
8073*c217d954SCole Faust const array<size_type, 3>& region,
8074*c217d954SCole Faust const vector<Event>* events = NULL,
8075*c217d954SCole Faust Event* event = NULL) const
8076*c217d954SCole Faust {
8077*c217d954SCole Faust cl_event tmp;
8078*c217d954SCole Faust cl_int err = detail::errHandler(
8079*c217d954SCole Faust ::clEnqueueCopyBufferToImage(
8080*c217d954SCole Faust object_,
8081*c217d954SCole Faust src(),
8082*c217d954SCole Faust dst(),
8083*c217d954SCole Faust src_offset,
8084*c217d954SCole Faust dst_origin.data(),
8085*c217d954SCole Faust region.data(),
8086*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
8087*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8088*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8089*c217d954SCole Faust __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
8090*c217d954SCole Faust
8091*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8092*c217d954SCole Faust *event = tmp;
8093*c217d954SCole Faust
8094*c217d954SCole Faust return err;
8095*c217d954SCole Faust }
8096*c217d954SCole Faust
8097*c217d954SCole Faust void* enqueueMapBuffer(
8098*c217d954SCole Faust const Buffer& buffer,
8099*c217d954SCole Faust cl_bool blocking,
8100*c217d954SCole Faust cl_map_flags flags,
8101*c217d954SCole Faust size_type offset,
8102*c217d954SCole Faust size_type size,
8103*c217d954SCole Faust const vector<Event>* events = NULL,
8104*c217d954SCole Faust Event* event = NULL,
8105*c217d954SCole Faust cl_int* err = NULL) const
8106*c217d954SCole Faust {
8107*c217d954SCole Faust cl_event tmp;
8108*c217d954SCole Faust cl_int error;
8109*c217d954SCole Faust void * result = ::clEnqueueMapBuffer(
8110*c217d954SCole Faust object_, buffer(), blocking, flags, offset, size,
8111*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
8112*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8113*c217d954SCole Faust (event != NULL) ? &tmp : NULL,
8114*c217d954SCole Faust &error);
8115*c217d954SCole Faust
8116*c217d954SCole Faust detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
8117*c217d954SCole Faust if (err != NULL) {
8118*c217d954SCole Faust *err = error;
8119*c217d954SCole Faust }
8120*c217d954SCole Faust if (event != NULL && error == CL_SUCCESS)
8121*c217d954SCole Faust *event = tmp;
8122*c217d954SCole Faust
8123*c217d954SCole Faust return result;
8124*c217d954SCole Faust }
8125*c217d954SCole Faust
8126*c217d954SCole Faust void* enqueueMapImage(
8127*c217d954SCole Faust const Image& buffer,
8128*c217d954SCole Faust cl_bool blocking,
8129*c217d954SCole Faust cl_map_flags flags,
8130*c217d954SCole Faust const array<size_type, 3>& origin,
8131*c217d954SCole Faust const array<size_type, 3>& region,
8132*c217d954SCole Faust size_type * row_pitch,
8133*c217d954SCole Faust size_type * slice_pitch,
8134*c217d954SCole Faust const vector<Event>* events = NULL,
8135*c217d954SCole Faust Event* event = NULL,
8136*c217d954SCole Faust cl_int* err = NULL) const
8137*c217d954SCole Faust {
8138*c217d954SCole Faust cl_event tmp;
8139*c217d954SCole Faust cl_int error;
8140*c217d954SCole Faust void * result = ::clEnqueueMapImage(
8141*c217d954SCole Faust object_, buffer(), blocking, flags,
8142*c217d954SCole Faust origin.data(),
8143*c217d954SCole Faust region.data(),
8144*c217d954SCole Faust row_pitch, slice_pitch,
8145*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
8146*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8147*c217d954SCole Faust (event != NULL) ? &tmp : NULL,
8148*c217d954SCole Faust &error);
8149*c217d954SCole Faust
8150*c217d954SCole Faust detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
8151*c217d954SCole Faust if (err != NULL) {
8152*c217d954SCole Faust *err = error;
8153*c217d954SCole Faust }
8154*c217d954SCole Faust if (event != NULL && error == CL_SUCCESS)
8155*c217d954SCole Faust *event = tmp;
8156*c217d954SCole Faust return result;
8157*c217d954SCole Faust }
8158*c217d954SCole Faust
8159*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8160*c217d954SCole Faust /**
8161*c217d954SCole Faust * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer.
8162*c217d954SCole Faust * This variant takes a raw SVM pointer.
8163*c217d954SCole Faust */
8164*c217d954SCole Faust template<typename T>
8165*c217d954SCole Faust cl_int enqueueMapSVM(
8166*c217d954SCole Faust T* ptr,
8167*c217d954SCole Faust cl_bool blocking,
8168*c217d954SCole Faust cl_map_flags flags,
8169*c217d954SCole Faust size_type size,
8170*c217d954SCole Faust const vector<Event>* events = NULL,
8171*c217d954SCole Faust Event* event = NULL) const
8172*c217d954SCole Faust {
8173*c217d954SCole Faust cl_event tmp;
8174*c217d954SCole Faust cl_int err = detail::errHandler(::clEnqueueSVMMap(
8175*c217d954SCole Faust object_, blocking, flags, static_cast<void*>(ptr), size,
8176*c217d954SCole Faust (events != NULL) ? (cl_uint)events->size() : 0,
8177*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8178*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8179*c217d954SCole Faust __ENQUEUE_MAP_BUFFER_ERR);
8180*c217d954SCole Faust
8181*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8182*c217d954SCole Faust *event = tmp;
8183*c217d954SCole Faust
8184*c217d954SCole Faust return err;
8185*c217d954SCole Faust }
8186*c217d954SCole Faust
8187*c217d954SCole Faust
8188*c217d954SCole Faust /**
8189*c217d954SCole Faust * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer.
8190*c217d954SCole Faust * This variant takes a cl::pointer instance.
8191*c217d954SCole Faust */
8192*c217d954SCole Faust template<typename T, class D>
8193*c217d954SCole Faust cl_int enqueueMapSVM(
8194*c217d954SCole Faust cl::pointer<T, D> &ptr,
8195*c217d954SCole Faust cl_bool blocking,
8196*c217d954SCole Faust cl_map_flags flags,
8197*c217d954SCole Faust size_type size,
8198*c217d954SCole Faust const vector<Event>* events = NULL,
8199*c217d954SCole Faust Event* event = NULL) const
8200*c217d954SCole Faust {
8201*c217d954SCole Faust cl_event tmp;
8202*c217d954SCole Faust cl_int err = detail::errHandler(::clEnqueueSVMMap(
8203*c217d954SCole Faust object_, blocking, flags, static_cast<void*>(ptr.get()), size,
8204*c217d954SCole Faust (events != NULL) ? (cl_uint)events->size() : 0,
8205*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8206*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8207*c217d954SCole Faust __ENQUEUE_MAP_BUFFER_ERR);
8208*c217d954SCole Faust
8209*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8210*c217d954SCole Faust *event = tmp;
8211*c217d954SCole Faust
8212*c217d954SCole Faust return err;
8213*c217d954SCole Faust }
8214*c217d954SCole Faust
8215*c217d954SCole Faust /**
8216*c217d954SCole Faust * Enqueues a command that will allow the host to update a region of a coarse-grained SVM buffer.
8217*c217d954SCole Faust * This variant takes a cl::vector instance.
8218*c217d954SCole Faust */
8219*c217d954SCole Faust template<typename T, class Alloc>
8220*c217d954SCole Faust cl_int enqueueMapSVM(
8221*c217d954SCole Faust cl::vector<T, Alloc> &container,
8222*c217d954SCole Faust cl_bool blocking,
8223*c217d954SCole Faust cl_map_flags flags,
8224*c217d954SCole Faust const vector<Event>* events = NULL,
8225*c217d954SCole Faust Event* event = NULL) const
8226*c217d954SCole Faust {
8227*c217d954SCole Faust cl_event tmp;
8228*c217d954SCole Faust cl_int err = detail::errHandler(::clEnqueueSVMMap(
8229*c217d954SCole Faust object_, blocking, flags, static_cast<void*>(container.data()), container.size()*sizeof(T),
8230*c217d954SCole Faust (events != NULL) ? (cl_uint)events->size() : 0,
8231*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8232*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8233*c217d954SCole Faust __ENQUEUE_MAP_BUFFER_ERR);
8234*c217d954SCole Faust
8235*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8236*c217d954SCole Faust *event = tmp;
8237*c217d954SCole Faust
8238*c217d954SCole Faust return err;
8239*c217d954SCole Faust }
8240*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8241*c217d954SCole Faust
8242*c217d954SCole Faust cl_int enqueueUnmapMemObject(
8243*c217d954SCole Faust const Memory& memory,
8244*c217d954SCole Faust void* mapped_ptr,
8245*c217d954SCole Faust const vector<Event>* events = NULL,
8246*c217d954SCole Faust Event* event = NULL) const
8247*c217d954SCole Faust {
8248*c217d954SCole Faust cl_event tmp;
8249*c217d954SCole Faust cl_int err = detail::errHandler(
8250*c217d954SCole Faust ::clEnqueueUnmapMemObject(
8251*c217d954SCole Faust object_, memory(), mapped_ptr,
8252*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
8253*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8254*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8255*c217d954SCole Faust __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8256*c217d954SCole Faust
8257*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8258*c217d954SCole Faust *event = tmp;
8259*c217d954SCole Faust
8260*c217d954SCole Faust return err;
8261*c217d954SCole Faust }
8262*c217d954SCole Faust
8263*c217d954SCole Faust
8264*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8265*c217d954SCole Faust /**
8266*c217d954SCole Faust * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime.
8267*c217d954SCole Faust * This variant takes a raw SVM pointer.
8268*c217d954SCole Faust */
8269*c217d954SCole Faust template<typename T>
8270*c217d954SCole Faust cl_int enqueueUnmapSVM(
8271*c217d954SCole Faust T* ptr,
8272*c217d954SCole Faust const vector<Event>* events = NULL,
8273*c217d954SCole Faust Event* event = NULL) const
8274*c217d954SCole Faust {
8275*c217d954SCole Faust cl_event tmp;
8276*c217d954SCole Faust cl_int err = detail::errHandler(
8277*c217d954SCole Faust ::clEnqueueSVMUnmap(
8278*c217d954SCole Faust object_, static_cast<void*>(ptr),
8279*c217d954SCole Faust (events != NULL) ? (cl_uint)events->size() : 0,
8280*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8281*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8282*c217d954SCole Faust __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8283*c217d954SCole Faust
8284*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8285*c217d954SCole Faust *event = tmp;
8286*c217d954SCole Faust
8287*c217d954SCole Faust return err;
8288*c217d954SCole Faust }
8289*c217d954SCole Faust
8290*c217d954SCole Faust /**
8291*c217d954SCole Faust * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime.
8292*c217d954SCole Faust * This variant takes a cl::pointer instance.
8293*c217d954SCole Faust */
8294*c217d954SCole Faust template<typename T, class D>
8295*c217d954SCole Faust cl_int enqueueUnmapSVM(
8296*c217d954SCole Faust cl::pointer<T, D> &ptr,
8297*c217d954SCole Faust const vector<Event>* events = NULL,
8298*c217d954SCole Faust Event* event = NULL) const
8299*c217d954SCole Faust {
8300*c217d954SCole Faust cl_event tmp;
8301*c217d954SCole Faust cl_int err = detail::errHandler(
8302*c217d954SCole Faust ::clEnqueueSVMUnmap(
8303*c217d954SCole Faust object_, static_cast<void*>(ptr.get()),
8304*c217d954SCole Faust (events != NULL) ? (cl_uint)events->size() : 0,
8305*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8306*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8307*c217d954SCole Faust __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8308*c217d954SCole Faust
8309*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8310*c217d954SCole Faust *event = tmp;
8311*c217d954SCole Faust
8312*c217d954SCole Faust return err;
8313*c217d954SCole Faust }
8314*c217d954SCole Faust
8315*c217d954SCole Faust /**
8316*c217d954SCole Faust * Enqueues a command that will release a coarse-grained SVM buffer back to the OpenCL runtime.
8317*c217d954SCole Faust * This variant takes a cl::vector instance.
8318*c217d954SCole Faust */
8319*c217d954SCole Faust template<typename T, class Alloc>
8320*c217d954SCole Faust cl_int enqueueUnmapSVM(
8321*c217d954SCole Faust cl::vector<T, Alloc> &container,
8322*c217d954SCole Faust const vector<Event>* events = NULL,
8323*c217d954SCole Faust Event* event = NULL) const
8324*c217d954SCole Faust {
8325*c217d954SCole Faust cl_event tmp;
8326*c217d954SCole Faust cl_int err = detail::errHandler(
8327*c217d954SCole Faust ::clEnqueueSVMUnmap(
8328*c217d954SCole Faust object_, static_cast<void*>(container.data()),
8329*c217d954SCole Faust (events != NULL) ? (cl_uint)events->size() : 0,
8330*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8331*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8332*c217d954SCole Faust __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8333*c217d954SCole Faust
8334*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8335*c217d954SCole Faust *event = tmp;
8336*c217d954SCole Faust
8337*c217d954SCole Faust return err;
8338*c217d954SCole Faust }
8339*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8340*c217d954SCole Faust
8341*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8342*c217d954SCole Faust /**
8343*c217d954SCole Faust * Enqueues a marker command which waits for either a list of events to complete,
8344*c217d954SCole Faust * or all previously enqueued commands to complete.
8345*c217d954SCole Faust *
8346*c217d954SCole Faust * Enqueues a marker command which waits for either a list of events to complete,
8347*c217d954SCole Faust * or if the list is empty it waits for all commands previously enqueued in command_queue
8348*c217d954SCole Faust * to complete before it completes. This command returns an event which can be waited on,
8349*c217d954SCole Faust * i.e. this event can be waited on to insure that all events either in the event_wait_list
8350*c217d954SCole Faust * or all previously enqueued commands, queued before this command to command_queue,
8351*c217d954SCole Faust * have completed.
8352*c217d954SCole Faust */
8353*c217d954SCole Faust cl_int enqueueMarkerWithWaitList(
8354*c217d954SCole Faust const vector<Event> *events = 0,
8355*c217d954SCole Faust Event *event = 0) const
8356*c217d954SCole Faust {
8357*c217d954SCole Faust cl_event tmp;
8358*c217d954SCole Faust cl_int err = detail::errHandler(
8359*c217d954SCole Faust ::clEnqueueMarkerWithWaitList(
8360*c217d954SCole Faust object_,
8361*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
8362*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8363*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8364*c217d954SCole Faust __ENQUEUE_MARKER_WAIT_LIST_ERR);
8365*c217d954SCole Faust
8366*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8367*c217d954SCole Faust *event = tmp;
8368*c217d954SCole Faust
8369*c217d954SCole Faust return err;
8370*c217d954SCole Faust }
8371*c217d954SCole Faust
8372*c217d954SCole Faust /**
8373*c217d954SCole Faust * A synchronization point that enqueues a barrier operation.
8374*c217d954SCole Faust *
8375*c217d954SCole Faust * Enqueues a barrier command which waits for either a list of events to complete,
8376*c217d954SCole Faust * or if the list is empty it waits for all commands previously enqueued in command_queue
8377*c217d954SCole Faust * to complete before it completes. This command blocks command execution, that is, any
8378*c217d954SCole Faust * following commands enqueued after it do not execute until it completes. This command
8379*c217d954SCole Faust * returns an event which can be waited on, i.e. this event can be waited on to insure that
8380*c217d954SCole Faust * all events either in the event_wait_list or all previously enqueued commands, queued
8381*c217d954SCole Faust * before this command to command_queue, have completed.
8382*c217d954SCole Faust */
8383*c217d954SCole Faust cl_int enqueueBarrierWithWaitList(
8384*c217d954SCole Faust const vector<Event> *events = 0,
8385*c217d954SCole Faust Event *event = 0) const
8386*c217d954SCole Faust {
8387*c217d954SCole Faust cl_event tmp;
8388*c217d954SCole Faust cl_int err = detail::errHandler(
8389*c217d954SCole Faust ::clEnqueueBarrierWithWaitList(
8390*c217d954SCole Faust object_,
8391*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
8392*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8393*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8394*c217d954SCole Faust __ENQUEUE_BARRIER_WAIT_LIST_ERR);
8395*c217d954SCole Faust
8396*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8397*c217d954SCole Faust *event = tmp;
8398*c217d954SCole Faust
8399*c217d954SCole Faust return err;
8400*c217d954SCole Faust }
8401*c217d954SCole Faust
8402*c217d954SCole Faust /**
8403*c217d954SCole Faust * Enqueues a command to indicate with which device a set of memory objects
8404*c217d954SCole Faust * should be associated.
8405*c217d954SCole Faust */
8406*c217d954SCole Faust cl_int enqueueMigrateMemObjects(
8407*c217d954SCole Faust const vector<Memory> &memObjects,
8408*c217d954SCole Faust cl_mem_migration_flags flags,
8409*c217d954SCole Faust const vector<Event>* events = NULL,
8410*c217d954SCole Faust Event* event = NULL
8411*c217d954SCole Faust ) const
8412*c217d954SCole Faust {
8413*c217d954SCole Faust cl_event tmp;
8414*c217d954SCole Faust
8415*c217d954SCole Faust vector<cl_mem> localMemObjects(memObjects.size());
8416*c217d954SCole Faust
8417*c217d954SCole Faust for( int i = 0; i < (int)memObjects.size(); ++i ) {
8418*c217d954SCole Faust localMemObjects[i] = memObjects[i]();
8419*c217d954SCole Faust }
8420*c217d954SCole Faust
8421*c217d954SCole Faust cl_int err = detail::errHandler(
8422*c217d954SCole Faust ::clEnqueueMigrateMemObjects(
8423*c217d954SCole Faust object_,
8424*c217d954SCole Faust (cl_uint)memObjects.size(),
8425*c217d954SCole Faust localMemObjects.data(),
8426*c217d954SCole Faust flags,
8427*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
8428*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8429*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8430*c217d954SCole Faust __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
8431*c217d954SCole Faust
8432*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8433*c217d954SCole Faust *event = tmp;
8434*c217d954SCole Faust
8435*c217d954SCole Faust return err;
8436*c217d954SCole Faust }
8437*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8438*c217d954SCole Faust
8439*c217d954SCole Faust
8440*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8441*c217d954SCole Faust /**
8442*c217d954SCole Faust * Enqueues a command that will allow the host associate ranges within a set of
8443*c217d954SCole Faust * SVM allocations with a device.
8444*c217d954SCole Faust * @param sizes - The length from each pointer to migrate.
8445*c217d954SCole Faust */
8446*c217d954SCole Faust template<typename T>
8447*c217d954SCole Faust cl_int enqueueMigrateSVM(
8448*c217d954SCole Faust const cl::vector<T*> &svmRawPointers,
8449*c217d954SCole Faust const cl::vector<size_type> &sizes,
8450*c217d954SCole Faust cl_mem_migration_flags flags = 0,
8451*c217d954SCole Faust const vector<Event>* events = NULL,
8452*c217d954SCole Faust Event* event = NULL) const
8453*c217d954SCole Faust {
8454*c217d954SCole Faust cl_event tmp;
8455*c217d954SCole Faust cl_int err = detail::errHandler(::clEnqueueSVMMigrateMem(
8456*c217d954SCole Faust object_,
8457*c217d954SCole Faust svmRawPointers.size(), static_cast<void**>(svmRawPointers.data()),
8458*c217d954SCole Faust sizes.data(), // array of sizes not passed
8459*c217d954SCole Faust flags,
8460*c217d954SCole Faust (events != NULL) ? (cl_uint)events->size() : 0,
8461*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
8462*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8463*c217d954SCole Faust __ENQUEUE_MIGRATE_SVM_ERR);
8464*c217d954SCole Faust
8465*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8466*c217d954SCole Faust *event = tmp;
8467*c217d954SCole Faust
8468*c217d954SCole Faust return err;
8469*c217d954SCole Faust }
8470*c217d954SCole Faust
8471*c217d954SCole Faust /**
8472*c217d954SCole Faust * Enqueues a command that will allow the host associate a set of SVM allocations with
8473*c217d954SCole Faust * a device.
8474*c217d954SCole Faust */
8475*c217d954SCole Faust template<typename T>
8476*c217d954SCole Faust cl_int enqueueMigrateSVM(
8477*c217d954SCole Faust const cl::vector<T*> &svmRawPointers,
8478*c217d954SCole Faust cl_mem_migration_flags flags = 0,
8479*c217d954SCole Faust const vector<Event>* events = NULL,
8480*c217d954SCole Faust Event* event = NULL) const
8481*c217d954SCole Faust {
8482*c217d954SCole Faust return enqueueMigrateSVM(svmRawPointers, cl::vector<size_type>(svmRawPointers.size()), flags, events, event);
8483*c217d954SCole Faust }
8484*c217d954SCole Faust
8485*c217d954SCole Faust
8486*c217d954SCole Faust /**
8487*c217d954SCole Faust * Enqueues a command that will allow the host associate ranges within a set of
8488*c217d954SCole Faust * SVM allocations with a device.
8489*c217d954SCole Faust * @param sizes - The length from each pointer to migrate.
8490*c217d954SCole Faust */
8491*c217d954SCole Faust template<typename T, class D>
8492*c217d954SCole Faust cl_int enqueueMigrateSVM(
8493*c217d954SCole Faust const cl::vector<cl::pointer<T, D>> &svmPointers,
8494*c217d954SCole Faust const cl::vector<size_type> &sizes,
8495*c217d954SCole Faust cl_mem_migration_flags flags = 0,
8496*c217d954SCole Faust const vector<Event>* events = NULL,
8497*c217d954SCole Faust Event* event = NULL) const
8498*c217d954SCole Faust {
8499*c217d954SCole Faust cl::vector<void*> svmRawPointers;
8500*c217d954SCole Faust svmRawPointers.reserve(svmPointers.size());
8501*c217d954SCole Faust for (auto p : svmPointers) {
8502*c217d954SCole Faust svmRawPointers.push_back(static_cast<void*>(p.get()));
8503*c217d954SCole Faust }
8504*c217d954SCole Faust
8505*c217d954SCole Faust return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
8506*c217d954SCole Faust }
8507*c217d954SCole Faust
8508*c217d954SCole Faust
8509*c217d954SCole Faust /**
8510*c217d954SCole Faust * Enqueues a command that will allow the host associate a set of SVM allocations with
8511*c217d954SCole Faust * a device.
8512*c217d954SCole Faust */
8513*c217d954SCole Faust template<typename T, class D>
8514*c217d954SCole Faust cl_int enqueueMigrateSVM(
8515*c217d954SCole Faust const cl::vector<cl::pointer<T, D>> &svmPointers,
8516*c217d954SCole Faust cl_mem_migration_flags flags = 0,
8517*c217d954SCole Faust const vector<Event>* events = NULL,
8518*c217d954SCole Faust Event* event = NULL) const
8519*c217d954SCole Faust {
8520*c217d954SCole Faust return enqueueMigrateSVM(svmPointers, cl::vector<size_type>(svmPointers.size()), flags, events, event);
8521*c217d954SCole Faust }
8522*c217d954SCole Faust
8523*c217d954SCole Faust /**
8524*c217d954SCole Faust * Enqueues a command that will allow the host associate ranges within a set of
8525*c217d954SCole Faust * SVM allocations with a device.
8526*c217d954SCole Faust * @param sizes - The length from the beginning of each container to migrate.
8527*c217d954SCole Faust */
8528*c217d954SCole Faust template<typename T, class Alloc>
8529*c217d954SCole Faust cl_int enqueueMigrateSVM(
8530*c217d954SCole Faust const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8531*c217d954SCole Faust const cl::vector<size_type> &sizes,
8532*c217d954SCole Faust cl_mem_migration_flags flags = 0,
8533*c217d954SCole Faust const vector<Event>* events = NULL,
8534*c217d954SCole Faust Event* event = NULL) const
8535*c217d954SCole Faust {
8536*c217d954SCole Faust cl::vector<void*> svmRawPointers;
8537*c217d954SCole Faust svmRawPointers.reserve(svmContainers.size());
8538*c217d954SCole Faust for (auto p : svmContainers) {
8539*c217d954SCole Faust svmRawPointers.push_back(static_cast<void*>(p.data()));
8540*c217d954SCole Faust }
8541*c217d954SCole Faust
8542*c217d954SCole Faust return enqueueMigrateSVM(svmRawPointers, sizes, flags, events, event);
8543*c217d954SCole Faust }
8544*c217d954SCole Faust
8545*c217d954SCole Faust /**
8546*c217d954SCole Faust * Enqueues a command that will allow the host associate a set of SVM allocations with
8547*c217d954SCole Faust * a device.
8548*c217d954SCole Faust */
8549*c217d954SCole Faust template<typename T, class Alloc>
8550*c217d954SCole Faust cl_int enqueueMigrateSVM(
8551*c217d954SCole Faust const cl::vector<cl::vector<T, Alloc>> &svmContainers,
8552*c217d954SCole Faust cl_mem_migration_flags flags = 0,
8553*c217d954SCole Faust const vector<Event>* events = NULL,
8554*c217d954SCole Faust Event* event = NULL) const
8555*c217d954SCole Faust {
8556*c217d954SCole Faust return enqueueMigrateSVM(svmContainers, cl::vector<size_type>(svmContainers.size()), flags, events, event);
8557*c217d954SCole Faust }
8558*c217d954SCole Faust
8559*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
8560*c217d954SCole Faust
8561*c217d954SCole Faust cl_int enqueueNDRangeKernel(
8562*c217d954SCole Faust const Kernel& kernel,
8563*c217d954SCole Faust const NDRange& offset,
8564*c217d954SCole Faust const NDRange& global,
8565*c217d954SCole Faust const NDRange& local = NullRange,
8566*c217d954SCole Faust const vector<Event>* events = NULL,
8567*c217d954SCole Faust Event* event = NULL) const
8568*c217d954SCole Faust {
8569*c217d954SCole Faust cl_event tmp;
8570*c217d954SCole Faust cl_int err = detail::errHandler(
8571*c217d954SCole Faust ::clEnqueueNDRangeKernel(
8572*c217d954SCole Faust object_, kernel(), (cl_uint) global.dimensions(),
8573*c217d954SCole Faust offset.dimensions() != 0 ? (const size_type*) offset : NULL,
8574*c217d954SCole Faust (const size_type*) global,
8575*c217d954SCole Faust local.dimensions() != 0 ? (const size_type*) local : NULL,
8576*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
8577*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8578*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8579*c217d954SCole Faust __ENQUEUE_NDRANGE_KERNEL_ERR);
8580*c217d954SCole Faust
8581*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8582*c217d954SCole Faust *event = tmp;
8583*c217d954SCole Faust
8584*c217d954SCole Faust return err;
8585*c217d954SCole Faust }
8586*c217d954SCole Faust
8587*c217d954SCole Faust #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8588*c217d954SCole Faust CL_API_PREFIX__VERSION_1_2_DEPRECATED cl_int enqueueTask(
8589*c217d954SCole Faust const Kernel& kernel,
8590*c217d954SCole Faust const vector<Event>* events = NULL,
8591*c217d954SCole Faust Event* event = NULL) const CL_API_SUFFIX__VERSION_1_2_DEPRECATED
8592*c217d954SCole Faust {
8593*c217d954SCole Faust cl_event tmp;
8594*c217d954SCole Faust cl_int err = detail::errHandler(
8595*c217d954SCole Faust ::clEnqueueTask(
8596*c217d954SCole Faust object_, kernel(),
8597*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
8598*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8599*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8600*c217d954SCole Faust __ENQUEUE_TASK_ERR);
8601*c217d954SCole Faust
8602*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8603*c217d954SCole Faust *event = tmp;
8604*c217d954SCole Faust
8605*c217d954SCole Faust return err;
8606*c217d954SCole Faust }
8607*c217d954SCole Faust #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS)
8608*c217d954SCole Faust
8609*c217d954SCole Faust cl_int enqueueNativeKernel(
8610*c217d954SCole Faust void (CL_CALLBACK *userFptr)(void *),
8611*c217d954SCole Faust std::pair<void*, size_type> args,
8612*c217d954SCole Faust const vector<Memory>* mem_objects = NULL,
8613*c217d954SCole Faust const vector<const void*>* mem_locs = NULL,
8614*c217d954SCole Faust const vector<Event>* events = NULL,
8615*c217d954SCole Faust Event* event = NULL) const
8616*c217d954SCole Faust {
8617*c217d954SCole Faust size_type elements = 0;
8618*c217d954SCole Faust if (mem_objects != NULL) {
8619*c217d954SCole Faust elements = mem_objects->size();
8620*c217d954SCole Faust }
8621*c217d954SCole Faust vector<cl_mem> mems(elements);
8622*c217d954SCole Faust for (unsigned int i = 0; i < elements; i++) {
8623*c217d954SCole Faust mems[i] = ((*mem_objects)[i])();
8624*c217d954SCole Faust }
8625*c217d954SCole Faust
8626*c217d954SCole Faust cl_event tmp;
8627*c217d954SCole Faust cl_int err = detail::errHandler(
8628*c217d954SCole Faust ::clEnqueueNativeKernel(
8629*c217d954SCole Faust object_, userFptr, args.first, args.second,
8630*c217d954SCole Faust (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8631*c217d954SCole Faust mems.data(),
8632*c217d954SCole Faust (mem_locs != NULL && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : NULL,
8633*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
8634*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8635*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8636*c217d954SCole Faust __ENQUEUE_NATIVE_KERNEL);
8637*c217d954SCole Faust
8638*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8639*c217d954SCole Faust *event = tmp;
8640*c217d954SCole Faust
8641*c217d954SCole Faust return err;
8642*c217d954SCole Faust }
8643*c217d954SCole Faust
8644*c217d954SCole Faust /**
8645*c217d954SCole Faust * Deprecated APIs for 1.2
8646*c217d954SCole Faust */
8647*c217d954SCole Faust #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8648*c217d954SCole Faust CL_API_PREFIX__VERSION_1_1_DEPRECATED
8649*c217d954SCole Faust cl_int enqueueMarker(Event* event = NULL) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
8650*c217d954SCole Faust {
8651*c217d954SCole Faust cl_event tmp;
8652*c217d954SCole Faust cl_int err = detail::errHandler(
8653*c217d954SCole Faust ::clEnqueueMarker(
8654*c217d954SCole Faust object_,
8655*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8656*c217d954SCole Faust __ENQUEUE_MARKER_ERR);
8657*c217d954SCole Faust
8658*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8659*c217d954SCole Faust *event = tmp;
8660*c217d954SCole Faust
8661*c217d954SCole Faust return err;
8662*c217d954SCole Faust }
8663*c217d954SCole Faust
8664*c217d954SCole Faust CL_API_PREFIX__VERSION_1_1_DEPRECATED
8665*c217d954SCole Faust cl_int enqueueWaitForEvents(const vector<Event>& events) const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
8666*c217d954SCole Faust {
8667*c217d954SCole Faust return detail::errHandler(
8668*c217d954SCole Faust ::clEnqueueWaitForEvents(
8669*c217d954SCole Faust object_,
8670*c217d954SCole Faust (cl_uint) events.size(),
8671*c217d954SCole Faust events.size() > 0 ? (const cl_event*) &events.front() : NULL),
8672*c217d954SCole Faust __ENQUEUE_WAIT_FOR_EVENTS_ERR);
8673*c217d954SCole Faust }
8674*c217d954SCole Faust #endif // defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8675*c217d954SCole Faust
8676*c217d954SCole Faust cl_int enqueueAcquireGLObjects(
8677*c217d954SCole Faust const vector<Memory>* mem_objects = NULL,
8678*c217d954SCole Faust const vector<Event>* events = NULL,
8679*c217d954SCole Faust Event* event = NULL) const
8680*c217d954SCole Faust {
8681*c217d954SCole Faust cl_event tmp;
8682*c217d954SCole Faust cl_int err = detail::errHandler(
8683*c217d954SCole Faust ::clEnqueueAcquireGLObjects(
8684*c217d954SCole Faust object_,
8685*c217d954SCole Faust (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8686*c217d954SCole Faust (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8687*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
8688*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8689*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8690*c217d954SCole Faust __ENQUEUE_ACQUIRE_GL_ERR);
8691*c217d954SCole Faust
8692*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8693*c217d954SCole Faust *event = tmp;
8694*c217d954SCole Faust
8695*c217d954SCole Faust return err;
8696*c217d954SCole Faust }
8697*c217d954SCole Faust
8698*c217d954SCole Faust cl_int enqueueReleaseGLObjects(
8699*c217d954SCole Faust const vector<Memory>* mem_objects = NULL,
8700*c217d954SCole Faust const vector<Event>* events = NULL,
8701*c217d954SCole Faust Event* event = NULL) const
8702*c217d954SCole Faust {
8703*c217d954SCole Faust cl_event tmp;
8704*c217d954SCole Faust cl_int err = detail::errHandler(
8705*c217d954SCole Faust ::clEnqueueReleaseGLObjects(
8706*c217d954SCole Faust object_,
8707*c217d954SCole Faust (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8708*c217d954SCole Faust (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8709*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
8710*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8711*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8712*c217d954SCole Faust __ENQUEUE_RELEASE_GL_ERR);
8713*c217d954SCole Faust
8714*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8715*c217d954SCole Faust *event = tmp;
8716*c217d954SCole Faust
8717*c217d954SCole Faust return err;
8718*c217d954SCole Faust }
8719*c217d954SCole Faust
8720*c217d954SCole Faust #if defined (CL_HPP_USE_DX_INTEROP)
8721*c217d954SCole Faust typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
8722*c217d954SCole Faust cl_command_queue command_queue, cl_uint num_objects,
8723*c217d954SCole Faust const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8724*c217d954SCole Faust const cl_event* event_wait_list, cl_event* event);
8725*c217d954SCole Faust typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
8726*c217d954SCole Faust cl_command_queue command_queue, cl_uint num_objects,
8727*c217d954SCole Faust const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
8728*c217d954SCole Faust const cl_event* event_wait_list, cl_event* event);
8729*c217d954SCole Faust
8730*c217d954SCole Faust cl_int enqueueAcquireD3D10Objects(
8731*c217d954SCole Faust const vector<Memory>* mem_objects = NULL,
8732*c217d954SCole Faust const vector<Event>* events = NULL,
8733*c217d954SCole Faust Event* event = NULL) const
8734*c217d954SCole Faust {
8735*c217d954SCole Faust static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
8736*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8737*c217d954SCole Faust cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8738*c217d954SCole Faust cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8739*c217d954SCole Faust cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8740*c217d954SCole Faust CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireD3D10ObjectsKHR);
8741*c217d954SCole Faust #endif
8742*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 110
8743*c217d954SCole Faust CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueAcquireD3D10ObjectsKHR);
8744*c217d954SCole Faust #endif
8745*c217d954SCole Faust
8746*c217d954SCole Faust cl_event tmp;
8747*c217d954SCole Faust cl_int err = detail::errHandler(
8748*c217d954SCole Faust pfn_clEnqueueAcquireD3D10ObjectsKHR(
8749*c217d954SCole Faust object_,
8750*c217d954SCole Faust (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8751*c217d954SCole Faust (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8752*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
8753*c217d954SCole Faust (events != NULL) ? (cl_event*) &events->front() : NULL,
8754*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8755*c217d954SCole Faust __ENQUEUE_ACQUIRE_GL_ERR);
8756*c217d954SCole Faust
8757*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8758*c217d954SCole Faust *event = tmp;
8759*c217d954SCole Faust
8760*c217d954SCole Faust return err;
8761*c217d954SCole Faust }
8762*c217d954SCole Faust
8763*c217d954SCole Faust cl_int enqueueReleaseD3D10Objects(
8764*c217d954SCole Faust const vector<Memory>* mem_objects = NULL,
8765*c217d954SCole Faust const vector<Event>* events = NULL,
8766*c217d954SCole Faust Event* event = NULL) const
8767*c217d954SCole Faust {
8768*c217d954SCole Faust static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL;
8769*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 120
8770*c217d954SCole Faust cl_context context = getInfo<CL_QUEUE_CONTEXT>();
8771*c217d954SCole Faust cl::Device device(getInfo<CL_QUEUE_DEVICE>());
8772*c217d954SCole Faust cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
8773*c217d954SCole Faust CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueReleaseD3D10ObjectsKHR);
8774*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 120
8775*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 110
8776*c217d954SCole Faust CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueReleaseD3D10ObjectsKHR);
8777*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
8778*c217d954SCole Faust
8779*c217d954SCole Faust cl_event tmp;
8780*c217d954SCole Faust cl_int err = detail::errHandler(
8781*c217d954SCole Faust pfn_clEnqueueReleaseD3D10ObjectsKHR(
8782*c217d954SCole Faust object_,
8783*c217d954SCole Faust (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
8784*c217d954SCole Faust (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL,
8785*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
8786*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
8787*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
8788*c217d954SCole Faust __ENQUEUE_RELEASE_GL_ERR);
8789*c217d954SCole Faust
8790*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
8791*c217d954SCole Faust *event = tmp;
8792*c217d954SCole Faust
8793*c217d954SCole Faust return err;
8794*c217d954SCole Faust }
8795*c217d954SCole Faust #endif
8796*c217d954SCole Faust
8797*c217d954SCole Faust /**
8798*c217d954SCole Faust * Deprecated APIs for 1.2
8799*c217d954SCole Faust */
8800*c217d954SCole Faust #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
8801*c217d954SCole Faust CL_API_PREFIX__VERSION_1_1_DEPRECATED
8802*c217d954SCole Faust cl_int enqueueBarrier() const CL_API_SUFFIX__VERSION_1_1_DEPRECATED
8803*c217d954SCole Faust {
8804*c217d954SCole Faust return detail::errHandler(
8805*c217d954SCole Faust ::clEnqueueBarrier(object_),
8806*c217d954SCole Faust __ENQUEUE_BARRIER_ERR);
8807*c217d954SCole Faust }
8808*c217d954SCole Faust #endif // CL_USE_DEPRECATED_OPENCL_1_1_APIS
8809*c217d954SCole Faust
8810*c217d954SCole Faust cl_int flush() const
8811*c217d954SCole Faust {
8812*c217d954SCole Faust return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
8813*c217d954SCole Faust }
8814*c217d954SCole Faust
8815*c217d954SCole Faust cl_int finish() const
8816*c217d954SCole Faust {
8817*c217d954SCole Faust return detail::errHandler(::clFinish(object_), __FINISH_ERR);
8818*c217d954SCole Faust }
8819*c217d954SCole Faust }; // CommandQueue
8820*c217d954SCole Faust
8821*c217d954SCole Faust CL_HPP_DEFINE_STATIC_MEMBER_ std::once_flag CommandQueue::default_initialized_;
8822*c217d954SCole Faust CL_HPP_DEFINE_STATIC_MEMBER_ CommandQueue CommandQueue::default_;
8823*c217d954SCole Faust CL_HPP_DEFINE_STATIC_MEMBER_ cl_int CommandQueue::default_error_ = CL_SUCCESS;
8824*c217d954SCole Faust
8825*c217d954SCole Faust
8826*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
8827*c217d954SCole Faust enum class DeviceQueueProperties : cl_command_queue_properties
8828*c217d954SCole Faust {
8829*c217d954SCole Faust None = 0,
8830*c217d954SCole Faust Profiling = CL_QUEUE_PROFILING_ENABLE,
8831*c217d954SCole Faust };
8832*c217d954SCole Faust
8833*c217d954SCole Faust inline DeviceQueueProperties operator|(DeviceQueueProperties lhs, DeviceQueueProperties rhs)
8834*c217d954SCole Faust {
8835*c217d954SCole Faust return static_cast<DeviceQueueProperties>(static_cast<cl_command_queue_properties>(lhs) | static_cast<cl_command_queue_properties>(rhs));
8836*c217d954SCole Faust }
8837*c217d954SCole Faust
8838*c217d954SCole Faust /*! \class DeviceCommandQueue
8839*c217d954SCole Faust * \brief DeviceCommandQueue interface for device cl_command_queues.
8840*c217d954SCole Faust */
8841*c217d954SCole Faust class DeviceCommandQueue : public detail::Wrapper<cl_command_queue>
8842*c217d954SCole Faust {
8843*c217d954SCole Faust public:
8844*c217d954SCole Faust
8845*c217d954SCole Faust /*!
8846*c217d954SCole Faust * Trivial empty constructor to create a null queue.
8847*c217d954SCole Faust */
8848*c217d954SCole Faust DeviceCommandQueue() { }
8849*c217d954SCole Faust
8850*c217d954SCole Faust /*!
8851*c217d954SCole Faust * Default construct device command queue on default context and device
8852*c217d954SCole Faust */
8853*c217d954SCole Faust DeviceCommandQueue(DeviceQueueProperties properties, cl_int* err = NULL)
8854*c217d954SCole Faust {
8855*c217d954SCole Faust cl_int error;
8856*c217d954SCole Faust cl::Context context = cl::Context::getDefault();
8857*c217d954SCole Faust cl::Device device = cl::Device::getDefault();
8858*c217d954SCole Faust
8859*c217d954SCole Faust cl_command_queue_properties mergedProperties =
8860*c217d954SCole Faust CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8861*c217d954SCole Faust
8862*c217d954SCole Faust cl_queue_properties queue_properties[] = {
8863*c217d954SCole Faust CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8864*c217d954SCole Faust object_ = ::clCreateCommandQueueWithProperties(
8865*c217d954SCole Faust context(), device(), queue_properties, &error);
8866*c217d954SCole Faust
8867*c217d954SCole Faust detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8868*c217d954SCole Faust if (err != NULL) {
8869*c217d954SCole Faust *err = error;
8870*c217d954SCole Faust }
8871*c217d954SCole Faust }
8872*c217d954SCole Faust
8873*c217d954SCole Faust /*!
8874*c217d954SCole Faust * Create a device command queue for a specified device in the passed context.
8875*c217d954SCole Faust */
8876*c217d954SCole Faust DeviceCommandQueue(
8877*c217d954SCole Faust const Context& context,
8878*c217d954SCole Faust const Device& device,
8879*c217d954SCole Faust DeviceQueueProperties properties = DeviceQueueProperties::None,
8880*c217d954SCole Faust cl_int* err = NULL)
8881*c217d954SCole Faust {
8882*c217d954SCole Faust cl_int error;
8883*c217d954SCole Faust
8884*c217d954SCole Faust cl_command_queue_properties mergedProperties =
8885*c217d954SCole Faust CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8886*c217d954SCole Faust cl_queue_properties queue_properties[] = {
8887*c217d954SCole Faust CL_QUEUE_PROPERTIES, mergedProperties, 0 };
8888*c217d954SCole Faust object_ = ::clCreateCommandQueueWithProperties(
8889*c217d954SCole Faust context(), device(), queue_properties, &error);
8890*c217d954SCole Faust
8891*c217d954SCole Faust detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8892*c217d954SCole Faust if (err != NULL) {
8893*c217d954SCole Faust *err = error;
8894*c217d954SCole Faust }
8895*c217d954SCole Faust }
8896*c217d954SCole Faust
8897*c217d954SCole Faust /*!
8898*c217d954SCole Faust * Create a device command queue for a specified device in the passed context.
8899*c217d954SCole Faust */
8900*c217d954SCole Faust DeviceCommandQueue(
8901*c217d954SCole Faust const Context& context,
8902*c217d954SCole Faust const Device& device,
8903*c217d954SCole Faust cl_uint queueSize,
8904*c217d954SCole Faust DeviceQueueProperties properties = DeviceQueueProperties::None,
8905*c217d954SCole Faust cl_int* err = NULL)
8906*c217d954SCole Faust {
8907*c217d954SCole Faust cl_int error;
8908*c217d954SCole Faust
8909*c217d954SCole Faust cl_command_queue_properties mergedProperties =
8910*c217d954SCole Faust CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | static_cast<cl_command_queue_properties>(properties);
8911*c217d954SCole Faust cl_queue_properties queue_properties[] = {
8912*c217d954SCole Faust CL_QUEUE_PROPERTIES, mergedProperties,
8913*c217d954SCole Faust CL_QUEUE_SIZE, queueSize,
8914*c217d954SCole Faust 0 };
8915*c217d954SCole Faust object_ = ::clCreateCommandQueueWithProperties(
8916*c217d954SCole Faust context(), device(), queue_properties, &error);
8917*c217d954SCole Faust
8918*c217d954SCole Faust detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
8919*c217d954SCole Faust if (err != NULL) {
8920*c217d954SCole Faust *err = error;
8921*c217d954SCole Faust }
8922*c217d954SCole Faust }
8923*c217d954SCole Faust
8924*c217d954SCole Faust /*! \brief Constructor from cl_command_queue - takes ownership.
8925*c217d954SCole Faust *
8926*c217d954SCole Faust * \param retainObject will cause the constructor to retain its cl object.
8927*c217d954SCole Faust * Defaults to false to maintain compatibility with
8928*c217d954SCole Faust * earlier versions.
8929*c217d954SCole Faust */
8930*c217d954SCole Faust explicit DeviceCommandQueue(const cl_command_queue& commandQueue, bool retainObject = false) :
8931*c217d954SCole Faust detail::Wrapper<cl_type>(commandQueue, retainObject) { }
8932*c217d954SCole Faust
8933*c217d954SCole Faust DeviceCommandQueue& operator = (const cl_command_queue& rhs)
8934*c217d954SCole Faust {
8935*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(rhs);
8936*c217d954SCole Faust return *this;
8937*c217d954SCole Faust }
8938*c217d954SCole Faust
8939*c217d954SCole Faust /*! \brief Copy constructor to forward copy to the superclass correctly.
8940*c217d954SCole Faust * Required for MSVC.
8941*c217d954SCole Faust */
8942*c217d954SCole Faust DeviceCommandQueue(const DeviceCommandQueue& queue) : detail::Wrapper<cl_type>(queue) {}
8943*c217d954SCole Faust
8944*c217d954SCole Faust /*! \brief Copy assignment to forward copy to the superclass correctly.
8945*c217d954SCole Faust * Required for MSVC.
8946*c217d954SCole Faust */
8947*c217d954SCole Faust DeviceCommandQueue& operator = (const DeviceCommandQueue &queue)
8948*c217d954SCole Faust {
8949*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(queue);
8950*c217d954SCole Faust return *this;
8951*c217d954SCole Faust }
8952*c217d954SCole Faust
8953*c217d954SCole Faust /*! \brief Move constructor to forward move to the superclass correctly.
8954*c217d954SCole Faust * Required for MSVC.
8955*c217d954SCole Faust */
8956*c217d954SCole Faust DeviceCommandQueue(DeviceCommandQueue&& queue) CL_HPP_NOEXCEPT_ : detail::Wrapper<cl_type>(std::move(queue)) {}
8957*c217d954SCole Faust
8958*c217d954SCole Faust /*! \brief Move assignment to forward move to the superclass correctly.
8959*c217d954SCole Faust * Required for MSVC.
8960*c217d954SCole Faust */
8961*c217d954SCole Faust DeviceCommandQueue& operator = (DeviceCommandQueue &&queue)
8962*c217d954SCole Faust {
8963*c217d954SCole Faust detail::Wrapper<cl_type>::operator=(std::move(queue));
8964*c217d954SCole Faust return *this;
8965*c217d954SCole Faust }
8966*c217d954SCole Faust
8967*c217d954SCole Faust template <typename T>
8968*c217d954SCole Faust cl_int getInfo(cl_command_queue_info name, T* param) const
8969*c217d954SCole Faust {
8970*c217d954SCole Faust return detail::errHandler(
8971*c217d954SCole Faust detail::getInfo(
8972*c217d954SCole Faust &::clGetCommandQueueInfo, object_, name, param),
8973*c217d954SCole Faust __GET_COMMAND_QUEUE_INFO_ERR);
8974*c217d954SCole Faust }
8975*c217d954SCole Faust
8976*c217d954SCole Faust template <cl_command_queue_info name> typename
8977*c217d954SCole Faust detail::param_traits<detail::cl_command_queue_info, name>::param_type
8978*c217d954SCole Faust getInfo(cl_int* err = NULL) const
8979*c217d954SCole Faust {
8980*c217d954SCole Faust typename detail::param_traits<
8981*c217d954SCole Faust detail::cl_command_queue_info, name>::param_type param;
8982*c217d954SCole Faust cl_int result = getInfo(name, ¶m);
8983*c217d954SCole Faust if (err != NULL) {
8984*c217d954SCole Faust *err = result;
8985*c217d954SCole Faust }
8986*c217d954SCole Faust return param;
8987*c217d954SCole Faust }
8988*c217d954SCole Faust
8989*c217d954SCole Faust /*!
8990*c217d954SCole Faust * Create a new default device command queue for the default device,
8991*c217d954SCole Faust * in the default context and of the default size.
8992*c217d954SCole Faust * If there is already a default queue for the specified device this
8993*c217d954SCole Faust * function will return the pre-existing queue.
8994*c217d954SCole Faust */
8995*c217d954SCole Faust static DeviceCommandQueue makeDefault(
8996*c217d954SCole Faust cl_int *err = nullptr)
8997*c217d954SCole Faust {
8998*c217d954SCole Faust cl_int error;
8999*c217d954SCole Faust cl::Context context = cl::Context::getDefault();
9000*c217d954SCole Faust cl::Device device = cl::Device::getDefault();
9001*c217d954SCole Faust
9002*c217d954SCole Faust cl_command_queue_properties properties =
9003*c217d954SCole Faust CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9004*c217d954SCole Faust cl_queue_properties queue_properties[] = {
9005*c217d954SCole Faust CL_QUEUE_PROPERTIES, properties,
9006*c217d954SCole Faust 0 };
9007*c217d954SCole Faust DeviceCommandQueue deviceQueue(
9008*c217d954SCole Faust ::clCreateCommandQueueWithProperties(
9009*c217d954SCole Faust context(), device(), queue_properties, &error));
9010*c217d954SCole Faust
9011*c217d954SCole Faust detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9012*c217d954SCole Faust if (err != NULL) {
9013*c217d954SCole Faust *err = error;
9014*c217d954SCole Faust }
9015*c217d954SCole Faust
9016*c217d954SCole Faust return deviceQueue;
9017*c217d954SCole Faust }
9018*c217d954SCole Faust
9019*c217d954SCole Faust /*!
9020*c217d954SCole Faust * Create a new default device command queue for the specified device
9021*c217d954SCole Faust * and of the default size.
9022*c217d954SCole Faust * If there is already a default queue for the specified device this
9023*c217d954SCole Faust * function will return the pre-existing queue.
9024*c217d954SCole Faust */
9025*c217d954SCole Faust static DeviceCommandQueue makeDefault(
9026*c217d954SCole Faust const Context &context, const Device &device, cl_int *err = nullptr)
9027*c217d954SCole Faust {
9028*c217d954SCole Faust cl_int error;
9029*c217d954SCole Faust
9030*c217d954SCole Faust cl_command_queue_properties properties =
9031*c217d954SCole Faust CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9032*c217d954SCole Faust cl_queue_properties queue_properties[] = {
9033*c217d954SCole Faust CL_QUEUE_PROPERTIES, properties,
9034*c217d954SCole Faust 0 };
9035*c217d954SCole Faust DeviceCommandQueue deviceQueue(
9036*c217d954SCole Faust ::clCreateCommandQueueWithProperties(
9037*c217d954SCole Faust context(), device(), queue_properties, &error));
9038*c217d954SCole Faust
9039*c217d954SCole Faust detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9040*c217d954SCole Faust if (err != NULL) {
9041*c217d954SCole Faust *err = error;
9042*c217d954SCole Faust }
9043*c217d954SCole Faust
9044*c217d954SCole Faust return deviceQueue;
9045*c217d954SCole Faust }
9046*c217d954SCole Faust
9047*c217d954SCole Faust /*!
9048*c217d954SCole Faust * Create a new default device command queue for the specified device
9049*c217d954SCole Faust * and of the requested size in bytes.
9050*c217d954SCole Faust * If there is already a default queue for the specified device this
9051*c217d954SCole Faust * function will return the pre-existing queue.
9052*c217d954SCole Faust */
9053*c217d954SCole Faust static DeviceCommandQueue makeDefault(
9054*c217d954SCole Faust const Context &context, const Device &device, cl_uint queueSize, cl_int *err = nullptr)
9055*c217d954SCole Faust {
9056*c217d954SCole Faust cl_int error;
9057*c217d954SCole Faust
9058*c217d954SCole Faust cl_command_queue_properties properties =
9059*c217d954SCole Faust CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT;
9060*c217d954SCole Faust cl_queue_properties queue_properties[] = {
9061*c217d954SCole Faust CL_QUEUE_PROPERTIES, properties,
9062*c217d954SCole Faust CL_QUEUE_SIZE, queueSize,
9063*c217d954SCole Faust 0 };
9064*c217d954SCole Faust DeviceCommandQueue deviceQueue(
9065*c217d954SCole Faust ::clCreateCommandQueueWithProperties(
9066*c217d954SCole Faust context(), device(), queue_properties, &error));
9067*c217d954SCole Faust
9068*c217d954SCole Faust detail::errHandler(error, __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR);
9069*c217d954SCole Faust if (err != NULL) {
9070*c217d954SCole Faust *err = error;
9071*c217d954SCole Faust }
9072*c217d954SCole Faust
9073*c217d954SCole Faust return deviceQueue;
9074*c217d954SCole Faust }
9075*c217d954SCole Faust
9076*c217d954SCole Faust
9077*c217d954SCole Faust
9078*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 210
9079*c217d954SCole Faust /*!
9080*c217d954SCole Faust * Modify the default device command queue to be used for subsequent kernels.
9081*c217d954SCole Faust * This can update the default command queue for a device repeatedly to account
9082*c217d954SCole Faust * for kernels that rely on the default.
9083*c217d954SCole Faust * @return updated default device command queue.
9084*c217d954SCole Faust */
9085*c217d954SCole Faust static DeviceCommandQueue updateDefault(const Context &context, const Device &device, const DeviceCommandQueue &default_queue, cl_int *err = nullptr)
9086*c217d954SCole Faust {
9087*c217d954SCole Faust cl_int error;
9088*c217d954SCole Faust error = clSetDefaultDeviceCommandQueue(context.get(), device.get(), default_queue.get());
9089*c217d954SCole Faust
9090*c217d954SCole Faust detail::errHandler(error, __SET_DEFAULT_DEVICE_COMMAND_QUEUE_ERR);
9091*c217d954SCole Faust if (err != NULL) {
9092*c217d954SCole Faust *err = error;
9093*c217d954SCole Faust }
9094*c217d954SCole Faust return default_queue;
9095*c217d954SCole Faust }
9096*c217d954SCole Faust
9097*c217d954SCole Faust /*!
9098*c217d954SCole Faust * Return the current default command queue for the specified command queue
9099*c217d954SCole Faust */
9100*c217d954SCole Faust static DeviceCommandQueue getDefault(const CommandQueue &queue, cl_int * err = NULL)
9101*c217d954SCole Faust {
9102*c217d954SCole Faust return queue.getInfo<CL_QUEUE_DEVICE_DEFAULT>(err);
9103*c217d954SCole Faust }
9104*c217d954SCole Faust
9105*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 210
9106*c217d954SCole Faust }; // DeviceCommandQueue
9107*c217d954SCole Faust
9108*c217d954SCole Faust namespace detail
9109*c217d954SCole Faust {
9110*c217d954SCole Faust // Specialization for device command queue
9111*c217d954SCole Faust template <>
9112*c217d954SCole Faust struct KernelArgumentHandler<cl::DeviceCommandQueue, void>
9113*c217d954SCole Faust {
9114*c217d954SCole Faust static size_type size(const cl::DeviceCommandQueue&) { return sizeof(cl_command_queue); }
9115*c217d954SCole Faust static const cl_command_queue* ptr(const cl::DeviceCommandQueue& value) { return &(value()); }
9116*c217d954SCole Faust };
9117*c217d954SCole Faust } // namespace detail
9118*c217d954SCole Faust
9119*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9120*c217d954SCole Faust
9121*c217d954SCole Faust
9122*c217d954SCole Faust template< typename IteratorType >
9123*c217d954SCole Faust Buffer::Buffer(
9124*c217d954SCole Faust const Context &context,
9125*c217d954SCole Faust IteratorType startIterator,
9126*c217d954SCole Faust IteratorType endIterator,
9127*c217d954SCole Faust bool readOnly,
9128*c217d954SCole Faust bool useHostPtr,
9129*c217d954SCole Faust cl_int* err)
9130*c217d954SCole Faust {
9131*c217d954SCole Faust typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9132*c217d954SCole Faust cl_int error;
9133*c217d954SCole Faust
9134*c217d954SCole Faust cl_mem_flags flags = 0;
9135*c217d954SCole Faust if( readOnly ) {
9136*c217d954SCole Faust flags |= CL_MEM_READ_ONLY;
9137*c217d954SCole Faust }
9138*c217d954SCole Faust else {
9139*c217d954SCole Faust flags |= CL_MEM_READ_WRITE;
9140*c217d954SCole Faust }
9141*c217d954SCole Faust if( useHostPtr ) {
9142*c217d954SCole Faust flags |= CL_MEM_USE_HOST_PTR;
9143*c217d954SCole Faust }
9144*c217d954SCole Faust
9145*c217d954SCole Faust size_type size = sizeof(DataType)*(endIterator - startIterator);
9146*c217d954SCole Faust
9147*c217d954SCole Faust if( useHostPtr ) {
9148*c217d954SCole Faust object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
9149*c217d954SCole Faust } else {
9150*c217d954SCole Faust object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9151*c217d954SCole Faust }
9152*c217d954SCole Faust
9153*c217d954SCole Faust detail::errHandler(error, __CREATE_BUFFER_ERR);
9154*c217d954SCole Faust if (err != NULL) {
9155*c217d954SCole Faust *err = error;
9156*c217d954SCole Faust }
9157*c217d954SCole Faust
9158*c217d954SCole Faust if( !useHostPtr ) {
9159*c217d954SCole Faust CommandQueue queue(context, 0, &error);
9160*c217d954SCole Faust detail::errHandler(error, __CREATE_BUFFER_ERR);
9161*c217d954SCole Faust if (err != NULL) {
9162*c217d954SCole Faust *err = error;
9163*c217d954SCole Faust }
9164*c217d954SCole Faust
9165*c217d954SCole Faust error = cl::copy(queue, startIterator, endIterator, *this);
9166*c217d954SCole Faust detail::errHandler(error, __CREATE_BUFFER_ERR);
9167*c217d954SCole Faust if (err != NULL) {
9168*c217d954SCole Faust *err = error;
9169*c217d954SCole Faust }
9170*c217d954SCole Faust }
9171*c217d954SCole Faust }
9172*c217d954SCole Faust
9173*c217d954SCole Faust template< typename IteratorType >
9174*c217d954SCole Faust Buffer::Buffer(
9175*c217d954SCole Faust const CommandQueue &queue,
9176*c217d954SCole Faust IteratorType startIterator,
9177*c217d954SCole Faust IteratorType endIterator,
9178*c217d954SCole Faust bool readOnly,
9179*c217d954SCole Faust bool useHostPtr,
9180*c217d954SCole Faust cl_int* err)
9181*c217d954SCole Faust {
9182*c217d954SCole Faust typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9183*c217d954SCole Faust cl_int error;
9184*c217d954SCole Faust
9185*c217d954SCole Faust cl_mem_flags flags = 0;
9186*c217d954SCole Faust if (readOnly) {
9187*c217d954SCole Faust flags |= CL_MEM_READ_ONLY;
9188*c217d954SCole Faust }
9189*c217d954SCole Faust else {
9190*c217d954SCole Faust flags |= CL_MEM_READ_WRITE;
9191*c217d954SCole Faust }
9192*c217d954SCole Faust if (useHostPtr) {
9193*c217d954SCole Faust flags |= CL_MEM_USE_HOST_PTR;
9194*c217d954SCole Faust }
9195*c217d954SCole Faust
9196*c217d954SCole Faust size_type size = sizeof(DataType)*(endIterator - startIterator);
9197*c217d954SCole Faust
9198*c217d954SCole Faust Context context = queue.getInfo<CL_QUEUE_CONTEXT>();
9199*c217d954SCole Faust
9200*c217d954SCole Faust if (useHostPtr) {
9201*c217d954SCole Faust object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
9202*c217d954SCole Faust }
9203*c217d954SCole Faust else {
9204*c217d954SCole Faust object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
9205*c217d954SCole Faust }
9206*c217d954SCole Faust
9207*c217d954SCole Faust detail::errHandler(error, __CREATE_BUFFER_ERR);
9208*c217d954SCole Faust if (err != NULL) {
9209*c217d954SCole Faust *err = error;
9210*c217d954SCole Faust }
9211*c217d954SCole Faust
9212*c217d954SCole Faust if (!useHostPtr) {
9213*c217d954SCole Faust error = cl::copy(queue, startIterator, endIterator, *this);
9214*c217d954SCole Faust detail::errHandler(error, __CREATE_BUFFER_ERR);
9215*c217d954SCole Faust if (err != NULL) {
9216*c217d954SCole Faust *err = error;
9217*c217d954SCole Faust }
9218*c217d954SCole Faust }
9219*c217d954SCole Faust }
9220*c217d954SCole Faust
9221*c217d954SCole Faust inline cl_int enqueueReadBuffer(
9222*c217d954SCole Faust const Buffer& buffer,
9223*c217d954SCole Faust cl_bool blocking,
9224*c217d954SCole Faust size_type offset,
9225*c217d954SCole Faust size_type size,
9226*c217d954SCole Faust void* ptr,
9227*c217d954SCole Faust const vector<Event>* events = NULL,
9228*c217d954SCole Faust Event* event = NULL)
9229*c217d954SCole Faust {
9230*c217d954SCole Faust cl_int error;
9231*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9232*c217d954SCole Faust
9233*c217d954SCole Faust if (error != CL_SUCCESS) {
9234*c217d954SCole Faust return error;
9235*c217d954SCole Faust }
9236*c217d954SCole Faust
9237*c217d954SCole Faust return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event);
9238*c217d954SCole Faust }
9239*c217d954SCole Faust
9240*c217d954SCole Faust inline cl_int enqueueWriteBuffer(
9241*c217d954SCole Faust const Buffer& buffer,
9242*c217d954SCole Faust cl_bool blocking,
9243*c217d954SCole Faust size_type offset,
9244*c217d954SCole Faust size_type size,
9245*c217d954SCole Faust const void* ptr,
9246*c217d954SCole Faust const vector<Event>* events = NULL,
9247*c217d954SCole Faust Event* event = NULL)
9248*c217d954SCole Faust {
9249*c217d954SCole Faust cl_int error;
9250*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9251*c217d954SCole Faust
9252*c217d954SCole Faust if (error != CL_SUCCESS) {
9253*c217d954SCole Faust return error;
9254*c217d954SCole Faust }
9255*c217d954SCole Faust
9256*c217d954SCole Faust return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event);
9257*c217d954SCole Faust }
9258*c217d954SCole Faust
9259*c217d954SCole Faust inline void* enqueueMapBuffer(
9260*c217d954SCole Faust const Buffer& buffer,
9261*c217d954SCole Faust cl_bool blocking,
9262*c217d954SCole Faust cl_map_flags flags,
9263*c217d954SCole Faust size_type offset,
9264*c217d954SCole Faust size_type size,
9265*c217d954SCole Faust const vector<Event>* events = NULL,
9266*c217d954SCole Faust Event* event = NULL,
9267*c217d954SCole Faust cl_int* err = NULL)
9268*c217d954SCole Faust {
9269*c217d954SCole Faust cl_int error;
9270*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9271*c217d954SCole Faust detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9272*c217d954SCole Faust if (err != NULL) {
9273*c217d954SCole Faust *err = error;
9274*c217d954SCole Faust }
9275*c217d954SCole Faust
9276*c217d954SCole Faust void * result = ::clEnqueueMapBuffer(
9277*c217d954SCole Faust queue(), buffer(), blocking, flags, offset, size,
9278*c217d954SCole Faust (events != NULL) ? (cl_uint) events->size() : 0,
9279*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
9280*c217d954SCole Faust (cl_event*) event,
9281*c217d954SCole Faust &error);
9282*c217d954SCole Faust
9283*c217d954SCole Faust detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9284*c217d954SCole Faust if (err != NULL) {
9285*c217d954SCole Faust *err = error;
9286*c217d954SCole Faust }
9287*c217d954SCole Faust return result;
9288*c217d954SCole Faust }
9289*c217d954SCole Faust
9290*c217d954SCole Faust
9291*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9292*c217d954SCole Faust /**
9293*c217d954SCole Faust * Enqueues to the default queue a command that will allow the host to
9294*c217d954SCole Faust * update a region of a coarse-grained SVM buffer.
9295*c217d954SCole Faust * This variant takes a raw SVM pointer.
9296*c217d954SCole Faust */
9297*c217d954SCole Faust template<typename T>
9298*c217d954SCole Faust inline cl_int enqueueMapSVM(
9299*c217d954SCole Faust T* ptr,
9300*c217d954SCole Faust cl_bool blocking,
9301*c217d954SCole Faust cl_map_flags flags,
9302*c217d954SCole Faust size_type size,
9303*c217d954SCole Faust const vector<Event>* events,
9304*c217d954SCole Faust Event* event)
9305*c217d954SCole Faust {
9306*c217d954SCole Faust cl_int error;
9307*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9308*c217d954SCole Faust if (error != CL_SUCCESS) {
9309*c217d954SCole Faust return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9310*c217d954SCole Faust }
9311*c217d954SCole Faust
9312*c217d954SCole Faust return queue.enqueueMapSVM(
9313*c217d954SCole Faust ptr, blocking, flags, size, events, event);
9314*c217d954SCole Faust }
9315*c217d954SCole Faust
9316*c217d954SCole Faust /**
9317*c217d954SCole Faust * Enqueues to the default queue a command that will allow the host to
9318*c217d954SCole Faust * update a region of a coarse-grained SVM buffer.
9319*c217d954SCole Faust * This variant takes a cl::pointer instance.
9320*c217d954SCole Faust */
9321*c217d954SCole Faust template<typename T, class D>
9322*c217d954SCole Faust inline cl_int enqueueMapSVM(
9323*c217d954SCole Faust cl::pointer<T, D> ptr,
9324*c217d954SCole Faust cl_bool blocking,
9325*c217d954SCole Faust cl_map_flags flags,
9326*c217d954SCole Faust size_type size,
9327*c217d954SCole Faust const vector<Event>* events = NULL,
9328*c217d954SCole Faust Event* event = NULL)
9329*c217d954SCole Faust {
9330*c217d954SCole Faust cl_int error;
9331*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9332*c217d954SCole Faust if (error != CL_SUCCESS) {
9333*c217d954SCole Faust return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9334*c217d954SCole Faust }
9335*c217d954SCole Faust
9336*c217d954SCole Faust return queue.enqueueMapSVM(
9337*c217d954SCole Faust ptr, blocking, flags, size, events, event);
9338*c217d954SCole Faust }
9339*c217d954SCole Faust
9340*c217d954SCole Faust /**
9341*c217d954SCole Faust * Enqueues to the default queue a command that will allow the host to
9342*c217d954SCole Faust * update a region of a coarse-grained SVM buffer.
9343*c217d954SCole Faust * This variant takes a cl::vector instance.
9344*c217d954SCole Faust */
9345*c217d954SCole Faust template<typename T, class Alloc>
9346*c217d954SCole Faust inline cl_int enqueueMapSVM(
9347*c217d954SCole Faust cl::vector<T, Alloc> container,
9348*c217d954SCole Faust cl_bool blocking,
9349*c217d954SCole Faust cl_map_flags flags,
9350*c217d954SCole Faust const vector<Event>* events = NULL,
9351*c217d954SCole Faust Event* event = NULL)
9352*c217d954SCole Faust {
9353*c217d954SCole Faust cl_int error;
9354*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9355*c217d954SCole Faust if (error != CL_SUCCESS) {
9356*c217d954SCole Faust return detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9357*c217d954SCole Faust }
9358*c217d954SCole Faust
9359*c217d954SCole Faust return queue.enqueueMapSVM(
9360*c217d954SCole Faust container, blocking, flags, events, event);
9361*c217d954SCole Faust }
9362*c217d954SCole Faust
9363*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9364*c217d954SCole Faust
9365*c217d954SCole Faust inline cl_int enqueueUnmapMemObject(
9366*c217d954SCole Faust const Memory& memory,
9367*c217d954SCole Faust void* mapped_ptr,
9368*c217d954SCole Faust const vector<Event>* events = NULL,
9369*c217d954SCole Faust Event* event = NULL)
9370*c217d954SCole Faust {
9371*c217d954SCole Faust cl_int error;
9372*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9373*c217d954SCole Faust detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
9374*c217d954SCole Faust if (error != CL_SUCCESS) {
9375*c217d954SCole Faust return error;
9376*c217d954SCole Faust }
9377*c217d954SCole Faust
9378*c217d954SCole Faust cl_event tmp;
9379*c217d954SCole Faust cl_int err = detail::errHandler(
9380*c217d954SCole Faust ::clEnqueueUnmapMemObject(
9381*c217d954SCole Faust queue(), memory(), mapped_ptr,
9382*c217d954SCole Faust (events != NULL) ? (cl_uint)events->size() : 0,
9383*c217d954SCole Faust (events != NULL && events->size() > 0) ? (cl_event*)&events->front() : NULL,
9384*c217d954SCole Faust (event != NULL) ? &tmp : NULL),
9385*c217d954SCole Faust __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9386*c217d954SCole Faust
9387*c217d954SCole Faust if (event != NULL && err == CL_SUCCESS)
9388*c217d954SCole Faust *event = tmp;
9389*c217d954SCole Faust
9390*c217d954SCole Faust return err;
9391*c217d954SCole Faust }
9392*c217d954SCole Faust
9393*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9394*c217d954SCole Faust /**
9395*c217d954SCole Faust * Enqueues to the default queue a command that will release a coarse-grained
9396*c217d954SCole Faust * SVM buffer back to the OpenCL runtime.
9397*c217d954SCole Faust * This variant takes a raw SVM pointer.
9398*c217d954SCole Faust */
9399*c217d954SCole Faust template<typename T>
9400*c217d954SCole Faust inline cl_int enqueueUnmapSVM(
9401*c217d954SCole Faust T* ptr,
9402*c217d954SCole Faust const vector<Event>* events = NULL,
9403*c217d954SCole Faust Event* event = NULL)
9404*c217d954SCole Faust {
9405*c217d954SCole Faust cl_int error;
9406*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9407*c217d954SCole Faust if (error != CL_SUCCESS) {
9408*c217d954SCole Faust return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9409*c217d954SCole Faust }
9410*c217d954SCole Faust
9411*c217d954SCole Faust return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
9412*c217d954SCole Faust __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9413*c217d954SCole Faust
9414*c217d954SCole Faust }
9415*c217d954SCole Faust
9416*c217d954SCole Faust /**
9417*c217d954SCole Faust * Enqueues to the default queue a command that will release a coarse-grained
9418*c217d954SCole Faust * SVM buffer back to the OpenCL runtime.
9419*c217d954SCole Faust * This variant takes a cl::pointer instance.
9420*c217d954SCole Faust */
9421*c217d954SCole Faust template<typename T, class D>
9422*c217d954SCole Faust inline cl_int enqueueUnmapSVM(
9423*c217d954SCole Faust cl::pointer<T, D> &ptr,
9424*c217d954SCole Faust const vector<Event>* events = NULL,
9425*c217d954SCole Faust Event* event = NULL)
9426*c217d954SCole Faust {
9427*c217d954SCole Faust cl_int error;
9428*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9429*c217d954SCole Faust if (error != CL_SUCCESS) {
9430*c217d954SCole Faust return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9431*c217d954SCole Faust }
9432*c217d954SCole Faust
9433*c217d954SCole Faust return detail::errHandler(queue.enqueueUnmapSVM(ptr, events, event),
9434*c217d954SCole Faust __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9435*c217d954SCole Faust }
9436*c217d954SCole Faust
9437*c217d954SCole Faust /**
9438*c217d954SCole Faust * Enqueues to the default queue a command that will release a coarse-grained
9439*c217d954SCole Faust * SVM buffer back to the OpenCL runtime.
9440*c217d954SCole Faust * This variant takes a cl::vector instance.
9441*c217d954SCole Faust */
9442*c217d954SCole Faust template<typename T, class Alloc>
9443*c217d954SCole Faust inline cl_int enqueueUnmapSVM(
9444*c217d954SCole Faust cl::vector<T, Alloc> &container,
9445*c217d954SCole Faust const vector<Event>* events = NULL,
9446*c217d954SCole Faust Event* event = NULL)
9447*c217d954SCole Faust {
9448*c217d954SCole Faust cl_int error;
9449*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9450*c217d954SCole Faust if (error != CL_SUCCESS) {
9451*c217d954SCole Faust return detail::errHandler(error, __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9452*c217d954SCole Faust }
9453*c217d954SCole Faust
9454*c217d954SCole Faust return detail::errHandler(queue.enqueueUnmapSVM(container, events, event),
9455*c217d954SCole Faust __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
9456*c217d954SCole Faust }
9457*c217d954SCole Faust
9458*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9459*c217d954SCole Faust
9460*c217d954SCole Faust inline cl_int enqueueCopyBuffer(
9461*c217d954SCole Faust const Buffer& src,
9462*c217d954SCole Faust const Buffer& dst,
9463*c217d954SCole Faust size_type src_offset,
9464*c217d954SCole Faust size_type dst_offset,
9465*c217d954SCole Faust size_type size,
9466*c217d954SCole Faust const vector<Event>* events = NULL,
9467*c217d954SCole Faust Event* event = NULL)
9468*c217d954SCole Faust {
9469*c217d954SCole Faust cl_int error;
9470*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9471*c217d954SCole Faust
9472*c217d954SCole Faust if (error != CL_SUCCESS) {
9473*c217d954SCole Faust return error;
9474*c217d954SCole Faust }
9475*c217d954SCole Faust
9476*c217d954SCole Faust return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event);
9477*c217d954SCole Faust }
9478*c217d954SCole Faust
9479*c217d954SCole Faust /**
9480*c217d954SCole Faust * Blocking copy operation between iterators and a buffer.
9481*c217d954SCole Faust * Host to Device.
9482*c217d954SCole Faust * Uses default command queue.
9483*c217d954SCole Faust */
9484*c217d954SCole Faust template< typename IteratorType >
9485*c217d954SCole Faust inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
9486*c217d954SCole Faust {
9487*c217d954SCole Faust cl_int error;
9488*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9489*c217d954SCole Faust if (error != CL_SUCCESS)
9490*c217d954SCole Faust return error;
9491*c217d954SCole Faust
9492*c217d954SCole Faust return cl::copy(queue, startIterator, endIterator, buffer);
9493*c217d954SCole Faust }
9494*c217d954SCole Faust
9495*c217d954SCole Faust /**
9496*c217d954SCole Faust * Blocking copy operation between iterators and a buffer.
9497*c217d954SCole Faust * Device to Host.
9498*c217d954SCole Faust * Uses default command queue.
9499*c217d954SCole Faust */
9500*c217d954SCole Faust template< typename IteratorType >
9501*c217d954SCole Faust inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
9502*c217d954SCole Faust {
9503*c217d954SCole Faust cl_int error;
9504*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9505*c217d954SCole Faust if (error != CL_SUCCESS)
9506*c217d954SCole Faust return error;
9507*c217d954SCole Faust
9508*c217d954SCole Faust return cl::copy(queue, buffer, startIterator, endIterator);
9509*c217d954SCole Faust }
9510*c217d954SCole Faust
9511*c217d954SCole Faust /**
9512*c217d954SCole Faust * Blocking copy operation between iterators and a buffer.
9513*c217d954SCole Faust * Host to Device.
9514*c217d954SCole Faust * Uses specified queue.
9515*c217d954SCole Faust */
9516*c217d954SCole Faust template< typename IteratorType >
9517*c217d954SCole Faust inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
9518*c217d954SCole Faust {
9519*c217d954SCole Faust typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9520*c217d954SCole Faust cl_int error;
9521*c217d954SCole Faust
9522*c217d954SCole Faust size_type length = endIterator-startIterator;
9523*c217d954SCole Faust size_type byteLength = length*sizeof(DataType);
9524*c217d954SCole Faust
9525*c217d954SCole Faust DataType *pointer =
9526*c217d954SCole Faust static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error));
9527*c217d954SCole Faust // if exceptions enabled, enqueueMapBuffer will throw
9528*c217d954SCole Faust if( error != CL_SUCCESS ) {
9529*c217d954SCole Faust return error;
9530*c217d954SCole Faust }
9531*c217d954SCole Faust #if defined(_MSC_VER)
9532*c217d954SCole Faust std::copy(
9533*c217d954SCole Faust startIterator,
9534*c217d954SCole Faust endIterator,
9535*c217d954SCole Faust stdext::checked_array_iterator<DataType*>(
9536*c217d954SCole Faust pointer, length));
9537*c217d954SCole Faust #else
9538*c217d954SCole Faust std::copy(startIterator, endIterator, pointer);
9539*c217d954SCole Faust #endif
9540*c217d954SCole Faust Event endEvent;
9541*c217d954SCole Faust error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9542*c217d954SCole Faust // if exceptions enabled, enqueueUnmapMemObject will throw
9543*c217d954SCole Faust if( error != CL_SUCCESS ) {
9544*c217d954SCole Faust return error;
9545*c217d954SCole Faust }
9546*c217d954SCole Faust endEvent.wait();
9547*c217d954SCole Faust return CL_SUCCESS;
9548*c217d954SCole Faust }
9549*c217d954SCole Faust
9550*c217d954SCole Faust /**
9551*c217d954SCole Faust * Blocking copy operation between iterators and a buffer.
9552*c217d954SCole Faust * Device to Host.
9553*c217d954SCole Faust * Uses specified queue.
9554*c217d954SCole Faust */
9555*c217d954SCole Faust template< typename IteratorType >
9556*c217d954SCole Faust inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
9557*c217d954SCole Faust {
9558*c217d954SCole Faust typedef typename std::iterator_traits<IteratorType>::value_type DataType;
9559*c217d954SCole Faust cl_int error;
9560*c217d954SCole Faust
9561*c217d954SCole Faust size_type length = endIterator-startIterator;
9562*c217d954SCole Faust size_type byteLength = length*sizeof(DataType);
9563*c217d954SCole Faust
9564*c217d954SCole Faust DataType *pointer =
9565*c217d954SCole Faust static_cast<DataType*>(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error));
9566*c217d954SCole Faust // if exceptions enabled, enqueueMapBuffer will throw
9567*c217d954SCole Faust if( error != CL_SUCCESS ) {
9568*c217d954SCole Faust return error;
9569*c217d954SCole Faust }
9570*c217d954SCole Faust std::copy(pointer, pointer + length, startIterator);
9571*c217d954SCole Faust Event endEvent;
9572*c217d954SCole Faust error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
9573*c217d954SCole Faust // if exceptions enabled, enqueueUnmapMemObject will throw
9574*c217d954SCole Faust if( error != CL_SUCCESS ) {
9575*c217d954SCole Faust return error;
9576*c217d954SCole Faust }
9577*c217d954SCole Faust endEvent.wait();
9578*c217d954SCole Faust return CL_SUCCESS;
9579*c217d954SCole Faust }
9580*c217d954SCole Faust
9581*c217d954SCole Faust
9582*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9583*c217d954SCole Faust /**
9584*c217d954SCole Faust * Blocking SVM map operation - performs a blocking map underneath.
9585*c217d954SCole Faust */
9586*c217d954SCole Faust template<typename T, class Alloc>
9587*c217d954SCole Faust inline cl_int mapSVM(cl::vector<T, Alloc> &container)
9588*c217d954SCole Faust {
9589*c217d954SCole Faust return enqueueMapSVM(container, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE);
9590*c217d954SCole Faust }
9591*c217d954SCole Faust
9592*c217d954SCole Faust /**
9593*c217d954SCole Faust * Blocking SVM map operation - performs a blocking map underneath.
9594*c217d954SCole Faust */
9595*c217d954SCole Faust template<typename T, class Alloc>
9596*c217d954SCole Faust inline cl_int unmapSVM(cl::vector<T, Alloc> &container)
9597*c217d954SCole Faust {
9598*c217d954SCole Faust return enqueueUnmapSVM(container);
9599*c217d954SCole Faust }
9600*c217d954SCole Faust
9601*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
9602*c217d954SCole Faust
9603*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 110
9604*c217d954SCole Faust inline cl_int enqueueReadBufferRect(
9605*c217d954SCole Faust const Buffer& buffer,
9606*c217d954SCole Faust cl_bool blocking,
9607*c217d954SCole Faust const array<size_type, 3>& buffer_offset,
9608*c217d954SCole Faust const array<size_type, 3>& host_offset,
9609*c217d954SCole Faust const array<size_type, 3>& region,
9610*c217d954SCole Faust size_type buffer_row_pitch,
9611*c217d954SCole Faust size_type buffer_slice_pitch,
9612*c217d954SCole Faust size_type host_row_pitch,
9613*c217d954SCole Faust size_type host_slice_pitch,
9614*c217d954SCole Faust void *ptr,
9615*c217d954SCole Faust const vector<Event>* events = NULL,
9616*c217d954SCole Faust Event* event = NULL)
9617*c217d954SCole Faust {
9618*c217d954SCole Faust cl_int error;
9619*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9620*c217d954SCole Faust
9621*c217d954SCole Faust if (error != CL_SUCCESS) {
9622*c217d954SCole Faust return error;
9623*c217d954SCole Faust }
9624*c217d954SCole Faust
9625*c217d954SCole Faust return queue.enqueueReadBufferRect(
9626*c217d954SCole Faust buffer,
9627*c217d954SCole Faust blocking,
9628*c217d954SCole Faust buffer_offset,
9629*c217d954SCole Faust host_offset,
9630*c217d954SCole Faust region,
9631*c217d954SCole Faust buffer_row_pitch,
9632*c217d954SCole Faust buffer_slice_pitch,
9633*c217d954SCole Faust host_row_pitch,
9634*c217d954SCole Faust host_slice_pitch,
9635*c217d954SCole Faust ptr,
9636*c217d954SCole Faust events,
9637*c217d954SCole Faust event);
9638*c217d954SCole Faust }
9639*c217d954SCole Faust
9640*c217d954SCole Faust inline cl_int enqueueWriteBufferRect(
9641*c217d954SCole Faust const Buffer& buffer,
9642*c217d954SCole Faust cl_bool blocking,
9643*c217d954SCole Faust const array<size_type, 3>& buffer_offset,
9644*c217d954SCole Faust const array<size_type, 3>& host_offset,
9645*c217d954SCole Faust const array<size_type, 3>& region,
9646*c217d954SCole Faust size_type buffer_row_pitch,
9647*c217d954SCole Faust size_type buffer_slice_pitch,
9648*c217d954SCole Faust size_type host_row_pitch,
9649*c217d954SCole Faust size_type host_slice_pitch,
9650*c217d954SCole Faust const void *ptr,
9651*c217d954SCole Faust const vector<Event>* events = NULL,
9652*c217d954SCole Faust Event* event = NULL)
9653*c217d954SCole Faust {
9654*c217d954SCole Faust cl_int error;
9655*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9656*c217d954SCole Faust
9657*c217d954SCole Faust if (error != CL_SUCCESS) {
9658*c217d954SCole Faust return error;
9659*c217d954SCole Faust }
9660*c217d954SCole Faust
9661*c217d954SCole Faust return queue.enqueueWriteBufferRect(
9662*c217d954SCole Faust buffer,
9663*c217d954SCole Faust blocking,
9664*c217d954SCole Faust buffer_offset,
9665*c217d954SCole Faust host_offset,
9666*c217d954SCole Faust region,
9667*c217d954SCole Faust buffer_row_pitch,
9668*c217d954SCole Faust buffer_slice_pitch,
9669*c217d954SCole Faust host_row_pitch,
9670*c217d954SCole Faust host_slice_pitch,
9671*c217d954SCole Faust ptr,
9672*c217d954SCole Faust events,
9673*c217d954SCole Faust event);
9674*c217d954SCole Faust }
9675*c217d954SCole Faust
9676*c217d954SCole Faust inline cl_int enqueueCopyBufferRect(
9677*c217d954SCole Faust const Buffer& src,
9678*c217d954SCole Faust const Buffer& dst,
9679*c217d954SCole Faust const array<size_type, 3>& src_origin,
9680*c217d954SCole Faust const array<size_type, 3>& dst_origin,
9681*c217d954SCole Faust const array<size_type, 3>& region,
9682*c217d954SCole Faust size_type src_row_pitch,
9683*c217d954SCole Faust size_type src_slice_pitch,
9684*c217d954SCole Faust size_type dst_row_pitch,
9685*c217d954SCole Faust size_type dst_slice_pitch,
9686*c217d954SCole Faust const vector<Event>* events = NULL,
9687*c217d954SCole Faust Event* event = NULL)
9688*c217d954SCole Faust {
9689*c217d954SCole Faust cl_int error;
9690*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9691*c217d954SCole Faust
9692*c217d954SCole Faust if (error != CL_SUCCESS) {
9693*c217d954SCole Faust return error;
9694*c217d954SCole Faust }
9695*c217d954SCole Faust
9696*c217d954SCole Faust return queue.enqueueCopyBufferRect(
9697*c217d954SCole Faust src,
9698*c217d954SCole Faust dst,
9699*c217d954SCole Faust src_origin,
9700*c217d954SCole Faust dst_origin,
9701*c217d954SCole Faust region,
9702*c217d954SCole Faust src_row_pitch,
9703*c217d954SCole Faust src_slice_pitch,
9704*c217d954SCole Faust dst_row_pitch,
9705*c217d954SCole Faust dst_slice_pitch,
9706*c217d954SCole Faust events,
9707*c217d954SCole Faust event);
9708*c217d954SCole Faust }
9709*c217d954SCole Faust #endif // CL_HPP_TARGET_OPENCL_VERSION >= 110
9710*c217d954SCole Faust
9711*c217d954SCole Faust inline cl_int enqueueReadImage(
9712*c217d954SCole Faust const Image& image,
9713*c217d954SCole Faust cl_bool blocking,
9714*c217d954SCole Faust const array<size_type, 3>& origin,
9715*c217d954SCole Faust const array<size_type, 3>& region,
9716*c217d954SCole Faust size_type row_pitch,
9717*c217d954SCole Faust size_type slice_pitch,
9718*c217d954SCole Faust void* ptr,
9719*c217d954SCole Faust const vector<Event>* events = NULL,
9720*c217d954SCole Faust Event* event = NULL)
9721*c217d954SCole Faust {
9722*c217d954SCole Faust cl_int error;
9723*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9724*c217d954SCole Faust
9725*c217d954SCole Faust if (error != CL_SUCCESS) {
9726*c217d954SCole Faust return error;
9727*c217d954SCole Faust }
9728*c217d954SCole Faust
9729*c217d954SCole Faust return queue.enqueueReadImage(
9730*c217d954SCole Faust image,
9731*c217d954SCole Faust blocking,
9732*c217d954SCole Faust origin,
9733*c217d954SCole Faust region,
9734*c217d954SCole Faust row_pitch,
9735*c217d954SCole Faust slice_pitch,
9736*c217d954SCole Faust ptr,
9737*c217d954SCole Faust events,
9738*c217d954SCole Faust event);
9739*c217d954SCole Faust }
9740*c217d954SCole Faust
9741*c217d954SCole Faust inline cl_int enqueueWriteImage(
9742*c217d954SCole Faust const Image& image,
9743*c217d954SCole Faust cl_bool blocking,
9744*c217d954SCole Faust const array<size_type, 3>& origin,
9745*c217d954SCole Faust const array<size_type, 3>& region,
9746*c217d954SCole Faust size_type row_pitch,
9747*c217d954SCole Faust size_type slice_pitch,
9748*c217d954SCole Faust const void* ptr,
9749*c217d954SCole Faust const vector<Event>* events = NULL,
9750*c217d954SCole Faust Event* event = NULL)
9751*c217d954SCole Faust {
9752*c217d954SCole Faust cl_int error;
9753*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9754*c217d954SCole Faust
9755*c217d954SCole Faust if (error != CL_SUCCESS) {
9756*c217d954SCole Faust return error;
9757*c217d954SCole Faust }
9758*c217d954SCole Faust
9759*c217d954SCole Faust return queue.enqueueWriteImage(
9760*c217d954SCole Faust image,
9761*c217d954SCole Faust blocking,
9762*c217d954SCole Faust origin,
9763*c217d954SCole Faust region,
9764*c217d954SCole Faust row_pitch,
9765*c217d954SCole Faust slice_pitch,
9766*c217d954SCole Faust ptr,
9767*c217d954SCole Faust events,
9768*c217d954SCole Faust event);
9769*c217d954SCole Faust }
9770*c217d954SCole Faust
9771*c217d954SCole Faust inline cl_int enqueueCopyImage(
9772*c217d954SCole Faust const Image& src,
9773*c217d954SCole Faust const Image& dst,
9774*c217d954SCole Faust const array<size_type, 3>& src_origin,
9775*c217d954SCole Faust const array<size_type, 3>& dst_origin,
9776*c217d954SCole Faust const array<size_type, 3>& region,
9777*c217d954SCole Faust const vector<Event>* events = NULL,
9778*c217d954SCole Faust Event* event = NULL)
9779*c217d954SCole Faust {
9780*c217d954SCole Faust cl_int error;
9781*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9782*c217d954SCole Faust
9783*c217d954SCole Faust if (error != CL_SUCCESS) {
9784*c217d954SCole Faust return error;
9785*c217d954SCole Faust }
9786*c217d954SCole Faust
9787*c217d954SCole Faust return queue.enqueueCopyImage(
9788*c217d954SCole Faust src,
9789*c217d954SCole Faust dst,
9790*c217d954SCole Faust src_origin,
9791*c217d954SCole Faust dst_origin,
9792*c217d954SCole Faust region,
9793*c217d954SCole Faust events,
9794*c217d954SCole Faust event);
9795*c217d954SCole Faust }
9796*c217d954SCole Faust
9797*c217d954SCole Faust inline cl_int enqueueCopyImageToBuffer(
9798*c217d954SCole Faust const Image& src,
9799*c217d954SCole Faust const Buffer& dst,
9800*c217d954SCole Faust const array<size_type, 3>& src_origin,
9801*c217d954SCole Faust const array<size_type, 3>& region,
9802*c217d954SCole Faust size_type dst_offset,
9803*c217d954SCole Faust const vector<Event>* events = NULL,
9804*c217d954SCole Faust Event* event = NULL)
9805*c217d954SCole Faust {
9806*c217d954SCole Faust cl_int error;
9807*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9808*c217d954SCole Faust
9809*c217d954SCole Faust if (error != CL_SUCCESS) {
9810*c217d954SCole Faust return error;
9811*c217d954SCole Faust }
9812*c217d954SCole Faust
9813*c217d954SCole Faust return queue.enqueueCopyImageToBuffer(
9814*c217d954SCole Faust src,
9815*c217d954SCole Faust dst,
9816*c217d954SCole Faust src_origin,
9817*c217d954SCole Faust region,
9818*c217d954SCole Faust dst_offset,
9819*c217d954SCole Faust events,
9820*c217d954SCole Faust event);
9821*c217d954SCole Faust }
9822*c217d954SCole Faust
9823*c217d954SCole Faust inline cl_int enqueueCopyBufferToImage(
9824*c217d954SCole Faust const Buffer& src,
9825*c217d954SCole Faust const Image& dst,
9826*c217d954SCole Faust size_type src_offset,
9827*c217d954SCole Faust const array<size_type, 3>& dst_origin,
9828*c217d954SCole Faust const array<size_type, 3>& region,
9829*c217d954SCole Faust const vector<Event>* events = NULL,
9830*c217d954SCole Faust Event* event = NULL)
9831*c217d954SCole Faust {
9832*c217d954SCole Faust cl_int error;
9833*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9834*c217d954SCole Faust
9835*c217d954SCole Faust if (error != CL_SUCCESS) {
9836*c217d954SCole Faust return error;
9837*c217d954SCole Faust }
9838*c217d954SCole Faust
9839*c217d954SCole Faust return queue.enqueueCopyBufferToImage(
9840*c217d954SCole Faust src,
9841*c217d954SCole Faust dst,
9842*c217d954SCole Faust src_offset,
9843*c217d954SCole Faust dst_origin,
9844*c217d954SCole Faust region,
9845*c217d954SCole Faust events,
9846*c217d954SCole Faust event);
9847*c217d954SCole Faust }
9848*c217d954SCole Faust
9849*c217d954SCole Faust
9850*c217d954SCole Faust inline cl_int flush(void)
9851*c217d954SCole Faust {
9852*c217d954SCole Faust cl_int error;
9853*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9854*c217d954SCole Faust
9855*c217d954SCole Faust if (error != CL_SUCCESS) {
9856*c217d954SCole Faust return error;
9857*c217d954SCole Faust }
9858*c217d954SCole Faust
9859*c217d954SCole Faust return queue.flush();
9860*c217d954SCole Faust }
9861*c217d954SCole Faust
9862*c217d954SCole Faust inline cl_int finish(void)
9863*c217d954SCole Faust {
9864*c217d954SCole Faust cl_int error;
9865*c217d954SCole Faust CommandQueue queue = CommandQueue::getDefault(&error);
9866*c217d954SCole Faust
9867*c217d954SCole Faust if (error != CL_SUCCESS) {
9868*c217d954SCole Faust return error;
9869*c217d954SCole Faust }
9870*c217d954SCole Faust
9871*c217d954SCole Faust
9872*c217d954SCole Faust return queue.finish();
9873*c217d954SCole Faust }
9874*c217d954SCole Faust
9875*c217d954SCole Faust class EnqueueArgs
9876*c217d954SCole Faust {
9877*c217d954SCole Faust private:
9878*c217d954SCole Faust CommandQueue queue_;
9879*c217d954SCole Faust const NDRange offset_;
9880*c217d954SCole Faust const NDRange global_;
9881*c217d954SCole Faust const NDRange local_;
9882*c217d954SCole Faust vector<Event> events_;
9883*c217d954SCole Faust
9884*c217d954SCole Faust template<typename... Ts>
9885*c217d954SCole Faust friend class KernelFunctor;
9886*c217d954SCole Faust
9887*c217d954SCole Faust public:
9888*c217d954SCole Faust EnqueueArgs(NDRange global) :
9889*c217d954SCole Faust queue_(CommandQueue::getDefault()),
9890*c217d954SCole Faust offset_(NullRange),
9891*c217d954SCole Faust global_(global),
9892*c217d954SCole Faust local_(NullRange)
9893*c217d954SCole Faust {
9894*c217d954SCole Faust
9895*c217d954SCole Faust }
9896*c217d954SCole Faust
9897*c217d954SCole Faust EnqueueArgs(NDRange global, NDRange local) :
9898*c217d954SCole Faust queue_(CommandQueue::getDefault()),
9899*c217d954SCole Faust offset_(NullRange),
9900*c217d954SCole Faust global_(global),
9901*c217d954SCole Faust local_(local)
9902*c217d954SCole Faust {
9903*c217d954SCole Faust
9904*c217d954SCole Faust }
9905*c217d954SCole Faust
9906*c217d954SCole Faust EnqueueArgs(NDRange offset, NDRange global, NDRange local) :
9907*c217d954SCole Faust queue_(CommandQueue::getDefault()),
9908*c217d954SCole Faust offset_(offset),
9909*c217d954SCole Faust global_(global),
9910*c217d954SCole Faust local_(local)
9911*c217d954SCole Faust {
9912*c217d954SCole Faust
9913*c217d954SCole Faust }
9914*c217d954SCole Faust
9915*c217d954SCole Faust EnqueueArgs(Event e, NDRange global) :
9916*c217d954SCole Faust queue_(CommandQueue::getDefault()),
9917*c217d954SCole Faust offset_(NullRange),
9918*c217d954SCole Faust global_(global),
9919*c217d954SCole Faust local_(NullRange)
9920*c217d954SCole Faust {
9921*c217d954SCole Faust events_.push_back(e);
9922*c217d954SCole Faust }
9923*c217d954SCole Faust
9924*c217d954SCole Faust EnqueueArgs(Event e, NDRange global, NDRange local) :
9925*c217d954SCole Faust queue_(CommandQueue::getDefault()),
9926*c217d954SCole Faust offset_(NullRange),
9927*c217d954SCole Faust global_(global),
9928*c217d954SCole Faust local_(local)
9929*c217d954SCole Faust {
9930*c217d954SCole Faust events_.push_back(e);
9931*c217d954SCole Faust }
9932*c217d954SCole Faust
9933*c217d954SCole Faust EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) :
9934*c217d954SCole Faust queue_(CommandQueue::getDefault()),
9935*c217d954SCole Faust offset_(offset),
9936*c217d954SCole Faust global_(global),
9937*c217d954SCole Faust local_(local)
9938*c217d954SCole Faust {
9939*c217d954SCole Faust events_.push_back(e);
9940*c217d954SCole Faust }
9941*c217d954SCole Faust
9942*c217d954SCole Faust EnqueueArgs(const vector<Event> &events, NDRange global) :
9943*c217d954SCole Faust queue_(CommandQueue::getDefault()),
9944*c217d954SCole Faust offset_(NullRange),
9945*c217d954SCole Faust global_(global),
9946*c217d954SCole Faust local_(NullRange),
9947*c217d954SCole Faust events_(events)
9948*c217d954SCole Faust {
9949*c217d954SCole Faust
9950*c217d954SCole Faust }
9951*c217d954SCole Faust
9952*c217d954SCole Faust EnqueueArgs(const vector<Event> &events, NDRange global, NDRange local) :
9953*c217d954SCole Faust queue_(CommandQueue::getDefault()),
9954*c217d954SCole Faust offset_(NullRange),
9955*c217d954SCole Faust global_(global),
9956*c217d954SCole Faust local_(local),
9957*c217d954SCole Faust events_(events)
9958*c217d954SCole Faust {
9959*c217d954SCole Faust
9960*c217d954SCole Faust }
9961*c217d954SCole Faust
9962*c217d954SCole Faust EnqueueArgs(const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
9963*c217d954SCole Faust queue_(CommandQueue::getDefault()),
9964*c217d954SCole Faust offset_(offset),
9965*c217d954SCole Faust global_(global),
9966*c217d954SCole Faust local_(local),
9967*c217d954SCole Faust events_(events)
9968*c217d954SCole Faust {
9969*c217d954SCole Faust
9970*c217d954SCole Faust }
9971*c217d954SCole Faust
9972*c217d954SCole Faust EnqueueArgs(CommandQueue &queue, NDRange global) :
9973*c217d954SCole Faust queue_(queue),
9974*c217d954SCole Faust offset_(NullRange),
9975*c217d954SCole Faust global_(global),
9976*c217d954SCole Faust local_(NullRange)
9977*c217d954SCole Faust {
9978*c217d954SCole Faust
9979*c217d954SCole Faust }
9980*c217d954SCole Faust
9981*c217d954SCole Faust EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) :
9982*c217d954SCole Faust queue_(queue),
9983*c217d954SCole Faust offset_(NullRange),
9984*c217d954SCole Faust global_(global),
9985*c217d954SCole Faust local_(local)
9986*c217d954SCole Faust {
9987*c217d954SCole Faust
9988*c217d954SCole Faust }
9989*c217d954SCole Faust
9990*c217d954SCole Faust EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) :
9991*c217d954SCole Faust queue_(queue),
9992*c217d954SCole Faust offset_(offset),
9993*c217d954SCole Faust global_(global),
9994*c217d954SCole Faust local_(local)
9995*c217d954SCole Faust {
9996*c217d954SCole Faust
9997*c217d954SCole Faust }
9998*c217d954SCole Faust
9999*c217d954SCole Faust EnqueueArgs(CommandQueue &queue, Event e, NDRange global) :
10000*c217d954SCole Faust queue_(queue),
10001*c217d954SCole Faust offset_(NullRange),
10002*c217d954SCole Faust global_(global),
10003*c217d954SCole Faust local_(NullRange)
10004*c217d954SCole Faust {
10005*c217d954SCole Faust events_.push_back(e);
10006*c217d954SCole Faust }
10007*c217d954SCole Faust
10008*c217d954SCole Faust EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) :
10009*c217d954SCole Faust queue_(queue),
10010*c217d954SCole Faust offset_(NullRange),
10011*c217d954SCole Faust global_(global),
10012*c217d954SCole Faust local_(local)
10013*c217d954SCole Faust {
10014*c217d954SCole Faust events_.push_back(e);
10015*c217d954SCole Faust }
10016*c217d954SCole Faust
10017*c217d954SCole Faust EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) :
10018*c217d954SCole Faust queue_(queue),
10019*c217d954SCole Faust offset_(offset),
10020*c217d954SCole Faust global_(global),
10021*c217d954SCole Faust local_(local)
10022*c217d954SCole Faust {
10023*c217d954SCole Faust events_.push_back(e);
10024*c217d954SCole Faust }
10025*c217d954SCole Faust
10026*c217d954SCole Faust EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global) :
10027*c217d954SCole Faust queue_(queue),
10028*c217d954SCole Faust offset_(NullRange),
10029*c217d954SCole Faust global_(global),
10030*c217d954SCole Faust local_(NullRange),
10031*c217d954SCole Faust events_(events)
10032*c217d954SCole Faust {
10033*c217d954SCole Faust
10034*c217d954SCole Faust }
10035*c217d954SCole Faust
10036*c217d954SCole Faust EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange global, NDRange local) :
10037*c217d954SCole Faust queue_(queue),
10038*c217d954SCole Faust offset_(NullRange),
10039*c217d954SCole Faust global_(global),
10040*c217d954SCole Faust local_(local),
10041*c217d954SCole Faust events_(events)
10042*c217d954SCole Faust {
10043*c217d954SCole Faust
10044*c217d954SCole Faust }
10045*c217d954SCole Faust
10046*c217d954SCole Faust EnqueueArgs(CommandQueue &queue, const vector<Event> &events, NDRange offset, NDRange global, NDRange local) :
10047*c217d954SCole Faust queue_(queue),
10048*c217d954SCole Faust offset_(offset),
10049*c217d954SCole Faust global_(global),
10050*c217d954SCole Faust local_(local),
10051*c217d954SCole Faust events_(events)
10052*c217d954SCole Faust {
10053*c217d954SCole Faust
10054*c217d954SCole Faust }
10055*c217d954SCole Faust };
10056*c217d954SCole Faust
10057*c217d954SCole Faust
10058*c217d954SCole Faust //----------------------------------------------------------------------------------------------
10059*c217d954SCole Faust
10060*c217d954SCole Faust
10061*c217d954SCole Faust /**
10062*c217d954SCole Faust * Type safe kernel functor.
10063*c217d954SCole Faust *
10064*c217d954SCole Faust */
10065*c217d954SCole Faust template<typename... Ts>
10066*c217d954SCole Faust class KernelFunctor
10067*c217d954SCole Faust {
10068*c217d954SCole Faust private:
10069*c217d954SCole Faust Kernel kernel_;
10070*c217d954SCole Faust
10071*c217d954SCole Faust template<int index, typename T0, typename... T1s>
10072*c217d954SCole Faust void setArgs(T0&& t0, T1s&&... t1s)
10073*c217d954SCole Faust {
10074*c217d954SCole Faust kernel_.setArg(index, t0);
10075*c217d954SCole Faust setArgs<index + 1, T1s...>(std::forward<T1s>(t1s)...);
10076*c217d954SCole Faust }
10077*c217d954SCole Faust
10078*c217d954SCole Faust template<int index, typename T0>
10079*c217d954SCole Faust void setArgs(T0&& t0)
10080*c217d954SCole Faust {
10081*c217d954SCole Faust kernel_.setArg(index, t0);
10082*c217d954SCole Faust }
10083*c217d954SCole Faust
10084*c217d954SCole Faust template<int index>
10085*c217d954SCole Faust void setArgs()
10086*c217d954SCole Faust {
10087*c217d954SCole Faust }
10088*c217d954SCole Faust
10089*c217d954SCole Faust
10090*c217d954SCole Faust public:
10091*c217d954SCole Faust KernelFunctor(Kernel kernel) : kernel_(kernel)
10092*c217d954SCole Faust {}
10093*c217d954SCole Faust
10094*c217d954SCole Faust KernelFunctor(
10095*c217d954SCole Faust const Program& program,
10096*c217d954SCole Faust const string name,
10097*c217d954SCole Faust cl_int * err = NULL) :
10098*c217d954SCole Faust kernel_(program, name.c_str(), err)
10099*c217d954SCole Faust {}
10100*c217d954SCole Faust
10101*c217d954SCole Faust //! \brief Return type of the functor
10102*c217d954SCole Faust typedef Event result_type;
10103*c217d954SCole Faust
10104*c217d954SCole Faust /**
10105*c217d954SCole Faust * Enqueue kernel.
10106*c217d954SCole Faust * @param args Launch parameters of the kernel.
10107*c217d954SCole Faust * @param t0... List of kernel arguments based on the template type of the functor.
10108*c217d954SCole Faust */
10109*c217d954SCole Faust Event operator() (
10110*c217d954SCole Faust const EnqueueArgs& args,
10111*c217d954SCole Faust Ts... ts)
10112*c217d954SCole Faust {
10113*c217d954SCole Faust Event event;
10114*c217d954SCole Faust setArgs<0>(std::forward<Ts>(ts)...);
10115*c217d954SCole Faust
10116*c217d954SCole Faust args.queue_.enqueueNDRangeKernel(
10117*c217d954SCole Faust kernel_,
10118*c217d954SCole Faust args.offset_,
10119*c217d954SCole Faust args.global_,
10120*c217d954SCole Faust args.local_,
10121*c217d954SCole Faust &args.events_,
10122*c217d954SCole Faust &event);
10123*c217d954SCole Faust
10124*c217d954SCole Faust return event;
10125*c217d954SCole Faust }
10126*c217d954SCole Faust
10127*c217d954SCole Faust /**
10128*c217d954SCole Faust * Enqueue kernel with support for error code.
10129*c217d954SCole Faust * @param args Launch parameters of the kernel.
10130*c217d954SCole Faust * @param t0... List of kernel arguments based on the template type of the functor.
10131*c217d954SCole Faust * @param error Out parameter returning the error code from the execution.
10132*c217d954SCole Faust */
10133*c217d954SCole Faust Event operator() (
10134*c217d954SCole Faust const EnqueueArgs& args,
10135*c217d954SCole Faust Ts... ts,
10136*c217d954SCole Faust cl_int &error)
10137*c217d954SCole Faust {
10138*c217d954SCole Faust Event event;
10139*c217d954SCole Faust setArgs<0>(std::forward<Ts>(ts)...);
10140*c217d954SCole Faust
10141*c217d954SCole Faust error = args.queue_.enqueueNDRangeKernel(
10142*c217d954SCole Faust kernel_,
10143*c217d954SCole Faust args.offset_,
10144*c217d954SCole Faust args.global_,
10145*c217d954SCole Faust args.local_,
10146*c217d954SCole Faust &args.events_,
10147*c217d954SCole Faust &event);
10148*c217d954SCole Faust
10149*c217d954SCole Faust return event;
10150*c217d954SCole Faust }
10151*c217d954SCole Faust
10152*c217d954SCole Faust #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10153*c217d954SCole Faust cl_int setSVMPointers(const vector<void*> &pointerList)
10154*c217d954SCole Faust {
10155*c217d954SCole Faust return kernel_.setSVMPointers(pointerList);
10156*c217d954SCole Faust }
10157*c217d954SCole Faust
10158*c217d954SCole Faust template<typename T0, typename... T1s>
10159*c217d954SCole Faust cl_int setSVMPointers(const T0 &t0, T1s &... ts)
10160*c217d954SCole Faust {
10161*c217d954SCole Faust return kernel_.setSVMPointers(t0, ts...);
10162*c217d954SCole Faust }
10163*c217d954SCole Faust #endif // #if CL_HPP_TARGET_OPENCL_VERSION >= 200
10164*c217d954SCole Faust
10165*c217d954SCole Faust Kernel getKernel()
10166*c217d954SCole Faust {
10167*c217d954SCole Faust return kernel_;
10168*c217d954SCole Faust }
10169*c217d954SCole Faust };
10170*c217d954SCole Faust
10171*c217d954SCole Faust namespace compatibility {
10172*c217d954SCole Faust /**
10173*c217d954SCole Faust * Backward compatibility class to ensure that cl.hpp code works with opencl.hpp.
10174*c217d954SCole Faust * Please use KernelFunctor directly.
10175*c217d954SCole Faust */
10176*c217d954SCole Faust template<typename... Ts>
10177*c217d954SCole Faust struct make_kernel
10178*c217d954SCole Faust {
10179*c217d954SCole Faust typedef KernelFunctor<Ts...> FunctorType;
10180*c217d954SCole Faust
10181*c217d954SCole Faust FunctorType functor_;
10182*c217d954SCole Faust
10183*c217d954SCole Faust make_kernel(
10184*c217d954SCole Faust const Program& program,
10185*c217d954SCole Faust const string name,
10186*c217d954SCole Faust cl_int * err = NULL) :
10187*c217d954SCole Faust functor_(FunctorType(program, name, err))
10188*c217d954SCole Faust {}
10189*c217d954SCole Faust
10190*c217d954SCole Faust make_kernel(
10191*c217d954SCole Faust const Kernel kernel) :
10192*c217d954SCole Faust functor_(FunctorType(kernel))
10193*c217d954SCole Faust {}
10194*c217d954SCole Faust
10195*c217d954SCole Faust //! \brief Return type of the functor
10196*c217d954SCole Faust typedef Event result_type;
10197*c217d954SCole Faust
10198*c217d954SCole Faust //! \brief Function signature of kernel functor with no event dependency.
10199*c217d954SCole Faust typedef Event type_(
10200*c217d954SCole Faust const EnqueueArgs&,
10201*c217d954SCole Faust Ts...);
10202*c217d954SCole Faust
10203*c217d954SCole Faust Event operator()(
10204*c217d954SCole Faust const EnqueueArgs& enqueueArgs,
10205*c217d954SCole Faust Ts... args)
10206*c217d954SCole Faust {
10207*c217d954SCole Faust return functor_(
10208*c217d954SCole Faust enqueueArgs, args...);
10209*c217d954SCole Faust }
10210*c217d954SCole Faust };
10211*c217d954SCole Faust } // namespace compatibility
10212*c217d954SCole Faust
10213*c217d954SCole Faust
10214*c217d954SCole Faust //----------------------------------------------------------------------------------------------------------------------
10215*c217d954SCole Faust
10216*c217d954SCole Faust #undef CL_HPP_ERR_STR_
10217*c217d954SCole Faust #if !defined(CL_HPP_USER_OVERRIDE_ERROR_STRINGS)
10218*c217d954SCole Faust #undef __GET_DEVICE_INFO_ERR
10219*c217d954SCole Faust #undef __GET_PLATFORM_INFO_ERR
10220*c217d954SCole Faust #undef __GET_DEVICE_IDS_ERR
10221*c217d954SCole Faust #undef __GET_PLATFORM_IDS_ERR
10222*c217d954SCole Faust #undef __GET_CONTEXT_INFO_ERR
10223*c217d954SCole Faust #undef __GET_EVENT_INFO_ERR
10224*c217d954SCole Faust #undef __GET_EVENT_PROFILE_INFO_ERR
10225*c217d954SCole Faust #undef __GET_MEM_OBJECT_INFO_ERR
10226*c217d954SCole Faust #undef __GET_IMAGE_INFO_ERR
10227*c217d954SCole Faust #undef __GET_SAMPLER_INFO_ERR
10228*c217d954SCole Faust #undef __GET_KERNEL_INFO_ERR
10229*c217d954SCole Faust #undef __GET_KERNEL_ARG_INFO_ERR
10230*c217d954SCole Faust #undef __GET_KERNEL_SUB_GROUP_INFO_ERR
10231*c217d954SCole Faust #undef __GET_KERNEL_WORK_GROUP_INFO_ERR
10232*c217d954SCole Faust #undef __GET_PROGRAM_INFO_ERR
10233*c217d954SCole Faust #undef __GET_PROGRAM_BUILD_INFO_ERR
10234*c217d954SCole Faust #undef __GET_COMMAND_QUEUE_INFO_ERR
10235*c217d954SCole Faust #undef __CREATE_CONTEXT_ERR
10236*c217d954SCole Faust #undef __CREATE_CONTEXT_FROM_TYPE_ERR
10237*c217d954SCole Faust #undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
10238*c217d954SCole Faust #undef __CREATE_BUFFER_ERR
10239*c217d954SCole Faust #undef __COPY_ERR
10240*c217d954SCole Faust #undef __CREATE_SUBBUFFER_ERR
10241*c217d954SCole Faust #undef __CREATE_GL_BUFFER_ERR
10242*c217d954SCole Faust #undef __CREATE_GL_RENDER_BUFFER_ERR
10243*c217d954SCole Faust #undef __GET_GL_OBJECT_INFO_ERR
10244*c217d954SCole Faust #undef __CREATE_IMAGE_ERR
10245*c217d954SCole Faust #undef __CREATE_GL_TEXTURE_ERR
10246*c217d954SCole Faust #undef __IMAGE_DIMENSION_ERR
10247*c217d954SCole Faust #undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
10248*c217d954SCole Faust #undef __CREATE_USER_EVENT_ERR
10249*c217d954SCole Faust #undef __SET_USER_EVENT_STATUS_ERR
10250*c217d954SCole Faust #undef __SET_EVENT_CALLBACK_ERR
10251*c217d954SCole Faust #undef __WAIT_FOR_EVENTS_ERR
10252*c217d954SCole Faust #undef __CREATE_KERNEL_ERR
10253*c217d954SCole Faust #undef __SET_KERNEL_ARGS_ERR
10254*c217d954SCole Faust #undef __CREATE_PROGRAM_WITH_SOURCE_ERR
10255*c217d954SCole Faust #undef __CREATE_PROGRAM_WITH_IL_ERR
10256*c217d954SCole Faust #undef __CREATE_PROGRAM_WITH_BINARY_ERR
10257*c217d954SCole Faust #undef __CREATE_PROGRAM_WITH_IL_ERR
10258*c217d954SCole Faust #undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR
10259*c217d954SCole Faust #undef __BUILD_PROGRAM_ERR
10260*c217d954SCole Faust #undef __COMPILE_PROGRAM_ERR
10261*c217d954SCole Faust #undef __LINK_PROGRAM_ERR
10262*c217d954SCole Faust #undef __CREATE_KERNELS_IN_PROGRAM_ERR
10263*c217d954SCole Faust #undef __CREATE_COMMAND_QUEUE_WITH_PROPERTIES_ERR
10264*c217d954SCole Faust #undef __CREATE_SAMPLER_WITH_PROPERTIES_ERR
10265*c217d954SCole Faust #undef __SET_COMMAND_QUEUE_PROPERTY_ERR
10266*c217d954SCole Faust #undef __ENQUEUE_READ_BUFFER_ERR
10267*c217d954SCole Faust #undef __ENQUEUE_READ_BUFFER_RECT_ERR
10268*c217d954SCole Faust #undef __ENQUEUE_WRITE_BUFFER_ERR
10269*c217d954SCole Faust #undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
10270*c217d954SCole Faust #undef __ENQEUE_COPY_BUFFER_ERR
10271*c217d954SCole Faust #undef __ENQEUE_COPY_BUFFER_RECT_ERR
10272*c217d954SCole Faust #undef __ENQUEUE_FILL_BUFFER_ERR
10273*c217d954SCole Faust #undef __ENQUEUE_READ_IMAGE_ERR
10274*c217d954SCole Faust #undef __ENQUEUE_WRITE_IMAGE_ERR
10275*c217d954SCole Faust #undef __ENQUEUE_COPY_IMAGE_ERR
10276*c217d954SCole Faust #undef __ENQUEUE_FILL_IMAGE_ERR
10277*c217d954SCole Faust #undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
10278*c217d954SCole Faust #undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
10279*c217d954SCole Faust #undef __ENQUEUE_MAP_BUFFER_ERR
10280*c217d954SCole Faust #undef __ENQUEUE_MAP_IMAGE_ERR
10281*c217d954SCole Faust #undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
10282*c217d954SCole Faust #undef __ENQUEUE_NDRANGE_KERNEL_ERR
10283*c217d954SCole Faust #undef __ENQUEUE_NATIVE_KERNEL
10284*c217d954SCole Faust #undef __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR
10285*c217d954SCole Faust #undef __ENQUEUE_MIGRATE_SVM_ERR
10286*c217d954SCole Faust #undef __ENQUEUE_ACQUIRE_GL_ERR
10287*c217d954SCole Faust #undef __ENQUEUE_RELEASE_GL_ERR
10288*c217d954SCole Faust #undef __CREATE_PIPE_ERR
10289*c217d954SCole Faust #undef __GET_PIPE_INFO_ERR
10290*c217d954SCole Faust #undef __RETAIN_ERR
10291*c217d954SCole Faust #undef __RELEASE_ERR
10292*c217d954SCole Faust #undef __FLUSH_ERR
10293*c217d954SCole Faust #undef __FINISH_ERR
10294*c217d954SCole Faust #undef __VECTOR_CAPACITY_ERR
10295*c217d954SCole Faust #undef __CREATE_SUB_DEVICES_ERR
10296*c217d954SCole Faust #undef __CREATE_SUB_DEVICES_ERR
10297*c217d954SCole Faust #undef __ENQUEUE_MARKER_ERR
10298*c217d954SCole Faust #undef __ENQUEUE_WAIT_FOR_EVENTS_ERR
10299*c217d954SCole Faust #undef __ENQUEUE_BARRIER_ERR
10300*c217d954SCole Faust #undef __UNLOAD_COMPILER_ERR
10301*c217d954SCole Faust #undef __CREATE_GL_TEXTURE_2D_ERR
10302*c217d954SCole Faust #undef __CREATE_GL_TEXTURE_3D_ERR
10303*c217d954SCole Faust #undef __CREATE_IMAGE2D_ERR
10304*c217d954SCole Faust #undef __CREATE_IMAGE3D_ERR
10305*c217d954SCole Faust #undef __CREATE_COMMAND_QUEUE_ERR
10306*c217d954SCole Faust #undef __ENQUEUE_TASK_ERR
10307*c217d954SCole Faust #undef __CREATE_SAMPLER_ERR
10308*c217d954SCole Faust #undef __ENQUEUE_MARKER_WAIT_LIST_ERR
10309*c217d954SCole Faust #undef __ENQUEUE_BARRIER_WAIT_LIST_ERR
10310*c217d954SCole Faust #undef __CLONE_KERNEL_ERR
10311*c217d954SCole Faust #undef __GET_HOST_TIMER_ERR
10312*c217d954SCole Faust #undef __GET_DEVICE_AND_HOST_TIMER_ERR
10313*c217d954SCole Faust
10314*c217d954SCole Faust #endif //CL_HPP_USER_OVERRIDE_ERROR_STRINGS
10315*c217d954SCole Faust
10316*c217d954SCole Faust // Extensions
10317*c217d954SCole Faust #undef CL_HPP_INIT_CL_EXT_FCN_PTR_
10318*c217d954SCole Faust #undef CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_
10319*c217d954SCole Faust
10320*c217d954SCole Faust #if defined(CL_HPP_USE_CL_DEVICE_FISSION)
10321*c217d954SCole Faust #undef CL_HPP_PARAM_NAME_DEVICE_FISSION_
10322*c217d954SCole Faust #endif // CL_HPP_USE_CL_DEVICE_FISSION
10323*c217d954SCole Faust
10324*c217d954SCole Faust #undef CL_HPP_NOEXCEPT_
10325*c217d954SCole Faust #undef CL_HPP_DEFINE_STATIC_MEMBER_
10326*c217d954SCole Faust
10327*c217d954SCole Faust } // namespace cl
10328*c217d954SCole Faust
10329*c217d954SCole Faust #endif // CL_HPP_
10330