1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*******************************************************************************
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright (c) 2008-2010 The Khronos Group Inc.
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and/or associated documentation files (the
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * "Materials"), to deal in the Materials without restriction, including
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * without limitation the rights to use, copy, modify, merge, publish,
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * distribute, sublicense, and/or sell copies of the Materials, and to
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * permit persons to whom the Materials are furnished to do so, subject to
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the following conditions:
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice shall be included
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * in all copies or substantial portions of the Materials.
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org ******************************************************************************/
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \file
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *   \brief C++ bindings for OpenCL 1.0 (rev 48) and OpenCL 1.1 (rev 33)
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *   \author Benedict R. Gaster and Laurent Morichetti
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *   Additions and fixes from Brian Cole, March 3rd 2010.
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *   \version 1.1
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *   \date June 2010
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *   Optional extension support
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *         cl
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *         cl_ext_device_fission
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *				#define USE_CL_DEVICE_FISSION
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \mainpage
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \section intro Introduction
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * For many large applications C++ is the language of choice and so it seems
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * reasonable to define C++ bindings for OpenCL.
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The interface is contained with a single C++ header file \em cl.hpp and all
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * definitions are contained within the namespace \em cl. There is no additional
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * requirement to include \em cl.h and to use either the C++ or original C
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * bindings it is enough to simply include \em cl.hpp.
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The bindings themselves are lightweight and correspond closely to the
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * underlying C API. Using the C++ bindings introduces no additional execution
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * overhead.
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * For detail documentation on the bindings see:
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The OpenCL C++ Wrapper API 1.1 (revision 04)
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *  http://www.khronos.org/registry/cl/specs/opencl-cplusplus-1.1.pdf
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \section example Example
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The following example shows a general use case for the C++
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * bindings, including support for the optional exception feature and
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * also the supplied vector and string classes, see following sections for
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * decriptions of these features.
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \code
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * #define __CL_ENABLE_EXCEPTIONS
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * #if defined(__APPLE__) || defined(__MACOSX)
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * #include <OpenCL/cl.hpp>
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * #else
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * #include <CL/cl.hpp>
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * #endif
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * #include <cstdio>
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * #include <cstdlib>
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * #include <iostream>
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *  const char * helloStr  = "__kernel void "
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *                           "hello(void) "
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *                           "{ "
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *                           "  "
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *                           "} ";
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *  int
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *  main(void)
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *  {
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *     cl_int err = CL_SUCCESS;
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *     try {
91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *       std::vector<cl::Platform> platforms;
93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *       cl::Platform::get(&platforms);
94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *       if (platforms.size() == 0) {
95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *           std::cout << "Platform size 0\n";
96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *           return -1;
97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *       }
98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *       cl_context_properties properties[] =
100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *          { CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0};
101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *       cl::Context context(CL_DEVICE_TYPE_CPU, properties);
102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *       std::vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>();
104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *       cl::Program::Sources source(1,
106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *           std::make_pair(helloStr,strlen(helloStr)));
107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *       cl::Program program_ = cl::Program(context, source);
108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *       program_.build(devices);
109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *       cl::Kernel kernel(program_, "hello", &err);
111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *       cl::Event event;
113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *       cl::CommandQueue queue(context, devices[0], 0, &err);
114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *       queue.enqueueNDRangeKernel(
115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *           kernel,
116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *           cl::NullRange,
117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *           cl::NDRange(4,4),
118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *           cl::NullRange,
119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *           NULL,
120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *           &event);
121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *       event.wait();
123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *     }
124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *     catch (cl::Error err) {
125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *        std::cerr
126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *           << "ERROR: "
127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *           << err.what()
128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *           << "("
129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *           << err.err()
130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *           << ")"
131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *           << std::endl;
132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *     }
133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *    return EXIT_SUCCESS;
135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *  }
136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \endcode
138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef CL_HPP_
141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define CL_HPP_
142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef _WIN32
144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <windows.h>
145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <malloc.h>
146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(USE_DX_INTEROP)
147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <CL/cl_d3d10.h>
148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif // _WIN32
150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//
152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(USE_CL_DEVICE_FISSION)
153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <CL/cl_ext.h>
154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(__APPLE__) || defined(__MACOSX)
157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <OpenGL/OpenGL.h>
158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <OpenCL/opencl.h>
159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else
160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <GL/gl.h>
161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <CL/opencl.h>
162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif // !__APPLE__
163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !defined(CL_CALLBACK)
165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define CL_CALLBACK
166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif //CL_CALLBACK
167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <utility>
169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !defined(__NO_STD_VECTOR)
171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <vector>
172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !defined(__NO_STD_STRING)
175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <string>
176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(linux) || defined(__APPLE__) || defined(__MACOSX)
179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# include <alloca.h>
180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif // linux
181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <cstring>
183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \namespace cl
185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief The OpenCL C++ bindings are defined within this namespace.
187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgnamespace cl {
190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __INIT_CL_EXT_FCN_PTR(name) \
192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if(!pfn_##name) { \
193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        pfn_##name = (PFN_##name) \
194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            clGetExtensionFunctionAddress(#name); \
195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if(!pfn_##name) { \
196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        } \
197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Program;
200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Device;
201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Context;
202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass CommandQueue;
203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Memory;
204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(__CL_ENABLE_EXCEPTIONS)
206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <exception>
207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class Error
208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Exception class
209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Error : public std::exception
211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgprivate:
213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int err_;
214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const char * errStr_;
215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /*! Create a new CL error exception for a given error code
217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *  and corresponding message.
218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr)
220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {}
221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ~Error() throw() {}
223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /*! \brief Get error string associated with exception
225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \return A memory pointer to the error message string.
227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    virtual const char * what() const throw ()
229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (errStr_ == NULL) {
231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return "empty";
232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        else {
234f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return errStr_;
235f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
236f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
237f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
238f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /*! \brief Get error code associated with exception
239f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
240f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *  \return The error code.
241f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
242f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const cl_int err(void) const { return err_; }
243f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
244f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
245f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ERR_STR(x) #x
246f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else
247f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ERR_STR(x) NULL
248f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif // __CL_ENABLE_EXCEPTIONS
249f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
250f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//! \cond DOXYGEN_DETAIL
251f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
252f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __GET_DEVICE_INFO_ERR               __ERR_STR(clgetDeviceInfo)
253f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __GET_PLATFORM_INFO_ERR             __ERR_STR(clGetPlatformInfo)
254f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __GET_DEVICE_IDS_ERR                __ERR_STR(clGetDeviceIDs)
255f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __GET_PLATFORM_IDS_ERR              __ERR_STR(clGetPlatformIDs)
256f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __GET_CONTEXT_INFO_ERR              __ERR_STR(clGetContextInfo)
257f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __GET_EVENT_INFO_ERR                __ERR_STR(clGetEventInfo)
258f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __GET_EVENT_PROFILE_INFO_ERR        __ERR_STR(clGetEventProfileInfo)
259f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __GET_MEM_OBJECT_INFO_ERR           __ERR_STR(clGetMemObjectInfo)
260f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __GET_IMAGE_INFO_ERR                __ERR_STR(clGetImageInfo)
261f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __GET_SAMPLER_INFO_ERR              __ERR_STR(clGetSamplerInfo)
262f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __GET_KERNEL_INFO_ERR               __ERR_STR(clGetKernelInfo)
263f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __GET_KERNEL_WORK_GROUP_INFO_ERR    __ERR_STR(clGetKernelWorkGroupInfo)
264f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __GET_PROGRAM_INFO_ERR              __ERR_STR(clGetProgramInfo)
265f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __GET_PROGRAM_BUILD_INFO_ERR        __ERR_STR(clGetProgramBuildInfo)
266f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __GET_COMMAND_QUEUE_INFO_ERR        __ERR_STR(clGetCommandQueueInfo)
267f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
268f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __CREATE_CONTEXT_FROM_TYPE_ERR      __ERR_STR(clCreateContextFromType)
269f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __GET_SUPPORTED_IMAGE_FORMATS_ERR   __ERR_STR(clGetSupportedImageFormats)
270f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
271f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __CREATE_BUFFER_ERR                 __ERR_STR(clCreateBuffer)
272f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __CREATE_SUBBUFFER_ERR              __ERR_STR(clCreateSubBuffer)
273f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __CREATE_GL_BUFFER_ERR              __ERR_STR(clCreateFromGLBuffer)
274f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __GET_GL_OBJECT_INFO_ERR            __ERR_STR(clGetGLObjectInfo)
275f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __CREATE_IMAGE2D_ERR                __ERR_STR(clCreateImage2D)
276f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __CREATE_IMAGE3D_ERR                __ERR_STR(clCreateImage3D)
277f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __CREATE_SAMPLER_ERR                __ERR_STR(clCreateSampler)
278f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR __ERR_STR(clSetMemObjectDestructorCallback)
279f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
280f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __CREATE_USER_EVENT_ERR             __ERR_STR(clCreateUserEvent)
281f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __SET_USER_EVENT_STATUS_ERR         __ERR_STR(clSetUserEventStatus)
282f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __SET_EVENT_CALLBACK_ERR            __ERR_STR(clSetEventCallback)
283f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __WAIT_FOR_EVENTS_ERR               __ERR_STR(clWaitForEvents)
284f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
285f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __CREATE_KERNEL_ERR                 __ERR_STR(clCreateKernel)
286f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __SET_KERNEL_ARGS_ERR               __ERR_STR(clSetKernelArg)
287f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __CREATE_PROGRAM_WITH_SOURCE_ERR    __ERR_STR(clCreateProgramWithSource)
288f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __CREATE_PROGRAM_WITH_BINARY_ERR    __ERR_STR(clCreateProgramWithBinary)
289f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __BUILD_PROGRAM_ERR                 __ERR_STR(clBuildProgram)
290f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __CREATE_KERNELS_IN_PROGRAM_ERR     __ERR_STR(clCreateKernelsInProgram)
291f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
292f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __CREATE_COMMAND_QUEUE_ERR          __ERR_STR(clCreateCommandQueue)
293f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __SET_COMMAND_QUEUE_PROPERTY_ERR    __ERR_STR(clSetCommandQueueProperty)
294f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_READ_BUFFER_ERR           __ERR_STR(clEnqueueReadBuffer)
295f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_READ_BUFFER_RECT_ERR      __ERR_STR(clEnqueueReadBufferRect)
296f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_WRITE_BUFFER_ERR          __ERR_STR(clEnqueueWriteBuffer)
297f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_WRITE_BUFFER_RECT_ERR     __ERR_STR(clEnqueueWriteBufferRect)
298f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQEUE_COPY_BUFFER_ERR            __ERR_STR(clEnqueueCopyBuffer)
299f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQEUE_COPY_BUFFER_RECT_ERR       __ERR_STR(clEnqueueCopyBufferRect)
300f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_READ_IMAGE_ERR            __ERR_STR(clEnqueueReadImage)
301f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_WRITE_IMAGE_ERR           __ERR_STR(clEnqueueWriteImage)
302f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_COPY_IMAGE_ERR            __ERR_STR(clEnqueueCopyImage)
303f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR  __ERR_STR(clEnqueueCopyImageToBuffer)
304f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR  __ERR_STR(clEnqueueCopyBufferToImage)
305f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_MAP_BUFFER_ERR            __ERR_STR(clEnqueueMapBuffer)
306f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_MAP_IMAGE_ERR             __ERR_STR(clEnqueueMapImage)
307f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_UNMAP_MEM_OBJECT_ERR      __ERR_STR(clEnqueueUnMapMemObject)
308f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_NDRANGE_KERNEL_ERR        __ERR_STR(clEnqueueNDRangeKernel)
309f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_TASK_ERR                  __ERR_STR(clEnqueueTask)
310f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_NATIVE_KERNEL             __ERR_STR(clEnqueueNativeKernel)
311f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_MARKER_ERR                __ERR_STR(clEnqueueMarker)
312f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_WAIT_FOR_EVENTS_ERR       __ERR_STR(clEnqueueWaitForEvents)
313f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_BARRIER_ERR               __ERR_STR(clEnqueueBarrier)
314f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
315f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_ACQUIRE_GL_ERR            __ERR_STR(clEnqueueAcquireGLObjects)
316f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __ENQUEUE_RELEASE_GL_ERR            __ERR_STR(clEnqueueReleaseGLObjects)
317f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
318f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __UNLOAD_COMPILER_ERR               __ERR_STR(clUnloadCompiler)
319f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
320f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __FLUSH_ERR                         __ERR_STR(clFlush)
321f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __FINISH_ERR                        __ERR_STR(clFinish)
322f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
323f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __CREATE_SUB_DEVICES                __ERR_STR(clCreateSubDevicesEXT)
324f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif // __CL_USER_OVERRIDE_ERROR_STRINGS
325f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//! \endcond
326f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
327f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class string
328f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Simple string class, that provides a limited subset of std::string
329f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * functionality but avoids many of the issues that come with that class.
330f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
331f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass string
332f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
333f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgprivate:
334f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ::size_t size_;
335f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    char * str_;
336f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
337f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    string(void) : size_(0), str_(NULL)
338f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
339f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
340f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
341f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    string(char * str, ::size_t size) :
342f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        size_(size),
343f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        str_(NULL)
344f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
345f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        str_ = new char[size_+1];
346f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (str_ != NULL) {
347f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            memcpy(str_, str, size_  * sizeof(char));
348f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            str_[size_] = '\0';
349f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
350f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        else {
351f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            size_ = 0;
352f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
353f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
354f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
355f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    string(char * str) :
356f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        str_(NULL)
357f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
358f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        size_= ::strlen(str);
359f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        str_ = new char[size_ + 1];
360f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (str_ != NULL) {
361f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            memcpy(str_, str, (size_ + 1) * sizeof(char));
362f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
363f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        else {
364f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            size_ = 0;
365f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
366f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
367f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
368f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    string& operator=(const string& rhs)
369f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
370f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this == &rhs) {
371f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return *this;
372f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
373f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
374f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (rhs.size_ == 0 || rhs.str_ == NULL) {
375f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            size_ = 0;
376f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            str_  = NULL;
377f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
378f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        else {
379f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            size_ = rhs.size_;
380f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            str_ = new char[size_ + 1];
381f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            if (str_ != NULL) {
382f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                memcpy(str_, rhs.str_, (size_ + 1) * sizeof(char));
383f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            }
384f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            else {
385f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                size_ = 0;
386f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            }
387f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
388f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
389f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
390f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
391f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
392f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    string(const string& rhs)
393f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
394f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        *this = rhs;
395f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
396f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
397f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ~string()
398f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
399f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (str_ != NULL) {
400f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            delete[] str_;
401f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
402f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
403f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
404f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ::size_t size(void) const   { return size_; }
405f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ::size_t length(void) const { return size(); }
406f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
407f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const char * c_str(void) const { return (str_) ? str_ : "";}
408f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
409f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
410f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !defined(__USE_DEV_STRING) && !defined(__NO_STD_STRING)
411f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <string>
412f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef std::string STRING_CLASS;
413f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif !defined(__USE_DEV_STRING)
414f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef cl::string STRING_CLASS;
415f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
416f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
417f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR)
418f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <vector>
419f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define VECTOR_CLASS std::vector
420f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif !defined(__USE_DEV_VECTOR)
421f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define VECTOR_CLASS cl::vector
422f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
423f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
424f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !defined(__MAX_DEFAULT_VECTOR_SIZE)
425f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __MAX_DEFAULT_VECTOR_SIZE 10
426f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
427f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
428f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class vector
429f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Fixed sized vector implementation that mirroring
430f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * std::vector functionality.
431f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
432f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T, unsigned int N = __MAX_DEFAULT_VECTOR_SIZE>
433f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass vector
434f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
435f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgprivate:
436f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    T data_[N];
437f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    unsigned int size_;
438f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    bool empty_;
439f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
440f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    vector() :
441f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        size_(-1),
442f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        empty_(true)
443f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {}
444f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
445f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ~vector() {}
446f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
447f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    unsigned int size(void) const
448f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
449f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return size_ + 1;
450f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
451f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
452f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    void clear()
453f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
454f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        size_ = -1;
455f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        empty_ = true;
456f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
457f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
458f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    void push_back (const T& x)
459f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
460f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (size() < N) {
461f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            size_++;
462f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            data_[size_] = x;
463f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            empty_ = false;
464f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
465f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
466f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
467f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    void pop_back(void)
468f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
469f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (!empty_) {
470f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            data_[size_].~T();
471f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            size_--;
472f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            if (size_ == -1) {
473f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                empty_ = true;
474f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            }
475f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
476f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
477f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
478f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    vector(const vector<T, N>& vec) :
479f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        size_(vec.size_),
480f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        empty_(vec.empty_)
481f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
482f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (!empty_) {
483f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            memcpy(&data_[0], &vec.data_[0], size() * sizeof(T));
484f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
485f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
486f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
487f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    vector(unsigned int size, const T& val = T()) :
488f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        size_(-1),
489f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        empty_(true)
490f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
491f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        for (unsigned int i = 0; i < size; i++) {
492f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            push_back(val);
493f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
494f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
495f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
496f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    vector<T, N>& operator=(const vector<T, N>& rhs)
497f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
498f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this == &rhs) {
499f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return *this;
500f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
501f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
502f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        size_  = rhs.size_;
503f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        empty_ = rhs.empty_;
504f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
505f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (!empty_) {
506f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            memcpy(&data_[0], &rhs.data_[0], size() * sizeof(T));
507f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
508f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
509f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
510f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
511f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
512f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    bool operator==(vector<T,N> &vec)
513f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
514f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (empty_ && vec.empty_) {
515f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return true;
516f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
517f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
518f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (size() != vec.size()) {
519f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return false;
520f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
521f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
522f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return memcmp(&data_[0], &vec.data_[0], size() * sizeof(T)) == 0 ? true : false;
523f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
524f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
525f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    operator T* ()             { return data_; }
526f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    operator const T* () const { return data_; }
527f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
528f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    bool empty (void) const
529f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
530f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return empty_;
531f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
532f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
533f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    unsigned int max_size (void) const
534f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
535f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return N;
536f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
537f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
538f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    unsigned int capacity () const
539f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
540f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return sizeof(T) * N;
541f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
542f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
543f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    T& operator[](int index)
544f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
545f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return data_[index];
546f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
547f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
548f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    T operator[](int index) const
549f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
550f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return data_[index];
551f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
552f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
553f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template<class I>
554f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    void assign(I start, I end)
555f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
556f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        clear();
557f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        while(start < end) {
558f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            push_back(*start);
559f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            start++;
560f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
561f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
562f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
563f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    /*! \class iterator
564f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \brief Iterator class for vectors
565f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
566f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    class iterator
567f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
568f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    private:
569f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        vector<T,N> vec_;
570f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        int index_;
571f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        bool initialized_;
572f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    public:
573f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        iterator(void) :
574f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            index_(-1),
575f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            initialized_(false)
576f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        {
577f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            index_ = -1;
578f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            initialized_ = false;
579f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
580f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
581f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ~iterator(void) {}
582f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
583f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        static iterator begin(vector<T,N> &vec)
584f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        {
585f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            iterator i;
586f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
587f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            if (!vec.empty()) {
588f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                i.index_ = 0;
589f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            }
590f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
591f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            i.vec_ = vec;
592f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            i.initialized_ = true;
593f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return i;
594f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
595f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
596f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        static iterator end(vector<T,N> &vec)
597f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        {
598f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            iterator i;
599f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
600f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            if (!vec.empty()) {
601f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                i.index_ = vec.size();
602f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            }
603f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            i.vec_ = vec;
604f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            i.initialized_ = true;
605f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return i;
606f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
607f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
608f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        bool operator==(iterator i)
609f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        {
610f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return ((vec_ == i.vec_) &&
611f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                    (index_ == i.index_) &&
612f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                    (initialized_ == i.initialized_));
613f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
614f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
615f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        bool operator!=(iterator i)
616f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        {
617f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return (!(*this==i));
618f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
619f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
620f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        void operator++()
621f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        {
622f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            index_++;
623f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
624f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
625f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        void operator++(int x)
626f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        {
627f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            index_ += x;
628f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
629f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
630f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        void operator--()
631f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        {
632f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            index_--;
633f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
634f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
635f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        void operator--(int x)
636f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        {
637f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            index_ -= x;
638f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
639f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
640f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        T operator *()
641f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        {
642f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return vec_[index_];
643f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
644f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    };
645f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
646f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    iterator begin(void)
647f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
648f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return iterator::begin(*this);
649f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
650f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
651f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    iterator end(void)
652f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
653f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return iterator::end(*this);
654f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
655f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
656f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    T& front(void)
657f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
658f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return data_[0];
659f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
660f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
661f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    T& back(void)
662f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
663f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return data_[size_];
664f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
665f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
666f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const T& front(void) const
667f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
668f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return data_[0];
669f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
670f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
671f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const T& back(void) const
672f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
673f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return data_[size_];
674f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
675f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
676f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
677f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*!
678f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief size_t class used to interface between C++ and
679f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OpenCL C calls that require arrays of size_t values, who's
680f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * size is known statically.
681f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
682f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <int N>
683f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct size_t : public cl::vector< ::size_t, N> { };
684f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
685f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgnamespace detail {
686f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
687f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// GetInfo help struct
688f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename Functor, typename T>
689f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct GetInfoHelper
690f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
691f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int
692f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    get(Functor f, cl_uint name, T* param)
693f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
694f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return f(name, sizeof(T), param, NULL);
695f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
696f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
697f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
698f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Specialized GetInfoHelper for VECTOR_CLASS params
699f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename Func, typename T>
700f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct GetInfoHelper<Func, VECTOR_CLASS<T> >
701f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
702f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int get(Func f, cl_uint name, VECTOR_CLASS<T>* param)
703f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
704f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ::size_t required;
705f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int err = f(name, 0, NULL, &required);
706f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != CL_SUCCESS) {
707f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return err;
708f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
709f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
710f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        T* value = (T*) alloca(required);
711f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        err = f(name, required, value, NULL);
712f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != CL_SUCCESS) {
713f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return err;
714f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
715f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
716f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        param->assign(&value[0], &value[required/sizeof(T)]);
717f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return CL_SUCCESS;
718f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
719f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
720f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
721f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Specialized for getInfo<CL_PROGRAM_BINARIES>
722f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename Func>
723f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct GetInfoHelper<Func, VECTOR_CLASS<char *> >
724f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
725f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int
726f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    get(Func f, cl_uint name, VECTOR_CLASS<char *>* param)
727f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
728f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      cl_uint err = f(name, param->size() * sizeof(char *), &(*param)[0], NULL);
729f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      if (err != CL_SUCCESS) {
730f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return err;
731f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      }
732f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
733f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return CL_SUCCESS;
734f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
735f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
736f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
737f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Specialized GetInfoHelper for STRING_CLASS params
738f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename Func>
739f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct GetInfoHelper<Func, STRING_CLASS>
740f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
741f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int get(Func f, cl_uint name, STRING_CLASS* param)
742f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
743f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ::size_t required;
744f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int err = f(name, 0, NULL, &required);
745f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != CL_SUCCESS) {
746f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return err;
747f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
748f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
749f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        char* value = (char*) alloca(required);
750f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        err = f(name, required, value, NULL);
751f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != CL_SUCCESS) {
752f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return err;
753f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
754f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
755f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        *param = value;
756f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return CL_SUCCESS;
757f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
758f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
759f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
760f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __GET_INFO_HELPER_WITH_RETAIN(CPP_TYPE) \
761f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgnamespace detail { \
762f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename Func> \
763f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct GetInfoHelper<Func, CPP_TYPE> \
764f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ \
765f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int get(Func f, cl_uint name, CPP_TYPE* param) \
766f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { \
767f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      cl_uint err = f(name, sizeof(CPP_TYPE), param, NULL); \
768f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      if (err != CL_SUCCESS) { \
769f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return err; \
770f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      } \
771f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      \
772f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return ReferenceHandler<CPP_TYPE::cl_type>::retain((*param)()); \
773f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    } \
774f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}; \
775f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
776f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
777f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
778f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __PARAM_NAME_INFO_1_0(F) \
779f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_platform_info, CL_PLATFORM_PROFILE, STRING_CLASS) \
780f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_platform_info, CL_PLATFORM_VERSION, STRING_CLASS) \
781f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_platform_info, CL_PLATFORM_NAME, STRING_CLASS) \
782f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_platform_info, CL_PLATFORM_VENDOR, STRING_CLASS) \
783f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_platform_info, CL_PLATFORM_EXTENSIONS, STRING_CLASS) \
784f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    \
785f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
786f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
787f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
788f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
789f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, ::size_t) \
790f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, VECTOR_CLASS< ::size_t>) \
791f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
792f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
793f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
794f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
795f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
796f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
797f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
798f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_bitfield) \
799f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
800f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
801f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
802f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, ::size_t) \
803f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, ::size_t) \
804f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, ::size_t) \
805f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, ::size_t) \
806f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, ::size_t) \
807f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_uint) \
808f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, ::size_t) \
809f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
810f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
811f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
812f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
813f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
814f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
815f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
816f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
817f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
818f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
819f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
820f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
821f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
822f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, ::size_t) \
823f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
824f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
825f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
826f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
827f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties) \
828f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
829f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_NAME, STRING_CLASS) \
830f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_VENDOR, STRING_CLASS) \
831f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DRIVER_VERSION, STRING_CLASS) \
832f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_PROFILE, STRING_CLASS) \
833f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_VERSION, STRING_CLASS) \
834f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_EXTENSIONS, STRING_CLASS) \
835f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    \
836f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
837f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_context_info, CL_CONTEXT_DEVICES, VECTOR_CLASS<Device>) \
838f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_context_info, CL_CONTEXT_PROPERTIES, VECTOR_CLASS<cl_context_properties>) \
839f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    \
840f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
841f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
842f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
843f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_uint) \
844f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    \
845f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
846f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
847f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
848f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
849f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    \
850f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
851f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
852f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_mem_info, CL_MEM_SIZE, ::size_t) \
853f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
854f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
855f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
856f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
857f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    \
858f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
859f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, ::size_t) \
860f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_image_info, CL_IMAGE_ROW_PITCH, ::size_t) \
861f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_image_info, CL_IMAGE_SLICE_PITCH, ::size_t) \
862f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_image_info, CL_IMAGE_WIDTH, ::size_t) \
863f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_image_info, CL_IMAGE_HEIGHT, ::size_t) \
864f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_image_info, CL_IMAGE_DEPTH, ::size_t) \
865f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    \
866f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
867f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
868f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_addressing_mode) \
869f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_filter_mode) \
870f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_bool) \
871f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    \
872f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
873f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
874f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
875f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_program_info, CL_PROGRAM_DEVICES, VECTOR_CLASS<cl_device_id>) \
876f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_program_info, CL_PROGRAM_SOURCE, STRING_CLASS) \
877f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_program_info, CL_PROGRAM_BINARY_SIZES, VECTOR_CLASS< ::size_t>) \
878f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_program_info, CL_PROGRAM_BINARIES, VECTOR_CLASS<char *>) \
879f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    \
880f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
881f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, STRING_CLASS) \
882f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, STRING_CLASS) \
883f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    \
884f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, STRING_CLASS) \
885f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
886f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
887f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
888f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
889f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    \
890f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, ::size_t) \
891f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::size_t<3>) \
892f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
893f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    \
894f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
895f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
896f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
897f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
898f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
899f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(CL_VERSION_1_1)
900f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __PARAM_NAME_INFO_1_1(F) \
901f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
902f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
903f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
904f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
905f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
906f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
907f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
908f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
909f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
910f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
911f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
912f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) \
913f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    \
914f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
915f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_mem_info, CL_MEM_OFFSET, ::size_t) \
916f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    \
917f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, ::size_t) \
918f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
919f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    \
920f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
921f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif // CL_VERSION_1_1
922f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
923f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(USE_CL_DEVICE_FISSION)
924f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __PARAM_NAME_DEVICE_FISSION(F) \
925f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
926f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \
927f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \
928f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
929f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, VECTOR_CLASS<cl_device_partition_property_ext>)
930f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif // USE_CL_DEVICE_FISSION
931f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
932f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename enum_type, cl_int Name>
933f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct param_traits {};
934f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
935f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __DECLARE_PARAM_TRAITS(token, param_name, T) \
936f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct token;                                        \
937f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate<>                                           \
938f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct param_traits<detail:: token,param_name>       \
939f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{                                                    \
940f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    enum { value = param_name };                     \
941f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    typedef T param_type;                            \
942f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
943f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
944f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org__PARAM_NAME_INFO_1_0(__DECLARE_PARAM_TRAITS);
945f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(CL_VERSION_1_1)
946f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org__PARAM_NAME_INFO_1_1(__DECLARE_PARAM_TRAITS);
947f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif // CL_VERSION_1_1
948f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
949f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(USE_CL_DEVICE_FISSION)
950f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org__PARAM_NAME_DEVICE_FISSION(__DECLARE_PARAM_TRAITS);
951f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif // USE_CL_DEVICE_FISSION
952f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
953f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#undef __DECLARE_PARAM_TRAITS
954f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
955f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Convenience functions
956f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
957f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename Func, typename T>
958f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline cl_int
959f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orggetInfo(Func f, cl_uint name, T* param)
960f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
961f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return GetInfoHelper<Func, T>::get(f, name, param);
962f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
963f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
964f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename Func, typename Arg0>
965f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct GetInfoFunctor0
966f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
967f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Func f_; const Arg0& arg0_;
968f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int operator ()(
969f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
970f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return f_(arg0_, param, size, value, size_ret); }
971f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
972f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
973f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename Func, typename Arg0, typename Arg1>
974f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct GetInfoFunctor1
975f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
976f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Func f_; const Arg0& arg0_; const Arg1& arg1_;
977f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int operator ()(
978f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
979f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return f_(arg0_, arg1_, param, size, value, size_ret); }
980f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
981f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
982f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename Func, typename Arg0, typename T>
983f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline cl_int
984f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orggetInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
985f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
986f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
987f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return GetInfoHelper<GetInfoFunctor0<Func, Arg0>, T>
988f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ::get(f0, name, param);
989f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
990f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
991f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename Func, typename Arg0, typename Arg1, typename T>
992f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline cl_int
993f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orggetInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
994f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
995f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
996f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return GetInfoHelper<GetInfoFunctor1<Func, Arg0, Arg1>, T>
997f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ::get(f0, name, param);
998f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
999f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1000f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate<typename T>
1001f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct ReferenceHandler
1002f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ };
1003f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1004f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <>
1005f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct ReferenceHandler<cl_device_id>
1006f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1007f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // cl_device_id does not have retain().
1008f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int retain(cl_device_id)
1009f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return CL_INVALID_DEVICE; }
1010f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // cl_device_id does not have release().
1011f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int release(cl_device_id)
1012f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return CL_INVALID_DEVICE; }
1013f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1014f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1015f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <>
1016f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct ReferenceHandler<cl_platform_id>
1017f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1018f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // cl_platform_id does not have retain().
1019f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int retain(cl_platform_id)
1020f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return CL_INVALID_PLATFORM; }
1021f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // cl_platform_id does not have release().
1022f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int release(cl_platform_id)
1023f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return CL_INVALID_PLATFORM; }
1024f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1025f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1026f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <>
1027f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct ReferenceHandler<cl_context>
1028f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1029f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int retain(cl_context context)
1030f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return ::clRetainContext(context); }
1031f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int release(cl_context context)
1032f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return ::clReleaseContext(context); }
1033f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1034f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1035f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <>
1036f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct ReferenceHandler<cl_command_queue>
1037f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1038f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int retain(cl_command_queue queue)
1039f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return ::clRetainCommandQueue(queue); }
1040f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int release(cl_command_queue queue)
1041f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return ::clReleaseCommandQueue(queue); }
1042f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1043f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1044f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <>
1045f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct ReferenceHandler<cl_mem>
1046f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1047f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int retain(cl_mem memory)
1048f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return ::clRetainMemObject(memory); }
1049f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int release(cl_mem memory)
1050f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return ::clReleaseMemObject(memory); }
1051f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1052f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1053f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <>
1054f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct ReferenceHandler<cl_sampler>
1055f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1056f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int retain(cl_sampler sampler)
1057f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return ::clRetainSampler(sampler); }
1058f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int release(cl_sampler sampler)
1059f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return ::clReleaseSampler(sampler); }
1060f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1061f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1062f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <>
1063f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct ReferenceHandler<cl_program>
1064f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1065f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int retain(cl_program program)
1066f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return ::clRetainProgram(program); }
1067f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int release(cl_program program)
1068f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return ::clReleaseProgram(program); }
1069f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1070f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1071f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <>
1072f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct ReferenceHandler<cl_kernel>
1073f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1074f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int retain(cl_kernel kernel)
1075f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return ::clRetainKernel(kernel); }
1076f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int release(cl_kernel kernel)
1077f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return ::clReleaseKernel(kernel); }
1078f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1079f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1080f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <>
1081f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct ReferenceHandler<cl_event>
1082f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1083f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int retain(cl_event event)
1084f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return ::clRetainEvent(event); }
1085f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int release(cl_event event)
1086f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { return ::clReleaseEvent(event); }
1087f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1088f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1089f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T>
1090f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Wrapper
1091f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1092f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
1093f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    typedef T cl_type;
1094f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1095f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgprotected:
1096f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_type object_;
1097f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1098f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
1099f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Wrapper() : object_(NULL) { }
1100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ~Wrapper()
1102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (object_ != NULL) { release(); }
1104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Wrapper(const Wrapper<cl_type>& rhs)
1107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        object_ = rhs.object_;
1109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (object_ != NULL) { retain(); }
1110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
1113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (object_ != NULL) { release(); }
1115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        object_ = rhs.object_;
1116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (object_ != NULL) { retain(); }
1117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
1118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_type operator ()() const { return object_; }
1121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_type& operator ()() { return object_; }
1123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgprotected:
1125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int retain() const
1127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return ReferenceHandler<cl_type>::retain(object_);
1129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int release() const
1132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return ReferenceHandler<cl_type>::release(object_);
1134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(__CL_ENABLE_EXCEPTIONS)
1138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic inline cl_int errHandler (
1139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int err,
1140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    const char * errStr = NULL) throw(Error)
1141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if (err != CL_SUCCESS) {
1143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        throw Error(err, errStr);
1144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return err;
1146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else
1148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic inline cl_int errHandler (cl_int err, const char * errStr = NULL)
1149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return err;
1151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif // __CL_ENABLE_EXCEPTIONS
1153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} // namespace detail
1155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//! \endcond
1156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \stuct ImageFormat
1158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief ImageFormat interface fro cl_image_format.
1159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
1160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct ImageFormat : public cl_image_format
1161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ImageFormat(){}
1163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ImageFormat(cl_channel_order order, cl_channel_type type)
1165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        image_channel_order = order;
1167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        image_channel_data_type = type;
1168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ImageFormat& operator = (const ImageFormat& rhs)
1171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this != &rhs) {
1173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            this->image_channel_data_type = rhs.image_channel_data_type;
1174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            this->image_channel_order     = rhs.image_channel_order;
1175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
1177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class Device
1181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Device interface for cl_device_id.
1182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
1183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Device : public detail::Wrapper<cl_device_id>
1184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
1186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Device(cl_device_id device) { object_ = device; }
1187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Device() : detail::Wrapper<cl_type>() { }
1189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Device(const Device& device) : detail::Wrapper<cl_type>(device) { }
1191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Device& operator = (const Device& rhs)
1193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this != &rhs) {
1195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::Wrapper<cl_type>::operator=(rhs);
1196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
1198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <typename T>
1201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int getInfo(cl_device_info name, T* param) const
1202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return detail::errHandler(
1204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::getInfo(&::clGetDeviceInfo, object_, name, param),
1205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            __GET_DEVICE_INFO_ERR);
1206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <cl_int name> typename
1209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    detail::param_traits<detail::cl_device_info, name>::param_type
1210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    getInfo(cl_int* err = NULL) const
1211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        typename detail::param_traits<
1213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::cl_device_info, name>::param_type param;
1214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int result = getInfo(name, &param);
1215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
1216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = result;
1217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return param;
1219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(USE_CL_DEVICE_FISSION)
1222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	cl_int createSubDevices(
1223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		const cl_device_partition_property_ext * properties,
1224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		VECTOR_CLASS<Device>* devices)
1225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	{
1226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		typedef CL_API_ENTRY cl_int
1227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org			( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
1228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org				cl_device_id /*in_device*/,
1229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                const cl_device_partition_property_ext * /* properties */,
1230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                cl_uint /*num_entries*/,
1231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                cl_device_id * /*out_devices*/,
1232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1;
1233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1234f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
1235f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		__INIT_CL_EXT_FCN_PTR(clCreateSubDevicesEXT);
1236f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1237f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		cl_uint n = 0;
1238f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
1239f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != CL_SUCCESS) {
1240f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return detail::errHandler(err, __CREATE_SUB_DEVICES);
1241f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1242f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1243f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
1244f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids, NULL);
1245f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != CL_SUCCESS) {
1246f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return detail::errHandler(err, __CREATE_SUB_DEVICES);
1247f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1248f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1249f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        devices->assign(&ids[0], &ids[n]);
1250f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return CL_SUCCESS;
1251f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 	}
1252f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1253f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1254f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1255f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class Platform
1256f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *  \brief Platform interface.
1257f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
1258f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Platform : public detail::Wrapper<cl_platform_id>
1259f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1260f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
1261f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static const Platform null();
1262f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1263f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Platform(cl_platform_id platform) { object_ = platform; }
1264f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1265f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Platform() : detail::Wrapper<cl_type>()  { }
1266f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1267f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Platform(const Platform& platform) : detail::Wrapper<cl_type>(platform) { }
1268f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1269f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Platform& operator = (const Platform& rhs)
1270f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1271f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this != &rhs) {
1272f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::Wrapper<cl_type>::operator=(rhs);
1273f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1274f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
1275f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1276f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1277f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int getInfo(cl_platform_info name, STRING_CLASS* param) const
1278f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1279f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return detail::errHandler(
1280f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::getInfo(&::clGetPlatformInfo, object_, name, param),
1281f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            __GET_PLATFORM_INFO_ERR);
1282f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1283f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1284f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <cl_int name> typename
1285f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    detail::param_traits<detail::cl_platform_info, name>::param_type
1286f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    getInfo(cl_int* err = NULL) const
1287f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1288f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        typename detail::param_traits<
1289f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::cl_platform_info, name>::param_type param;
1290f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int result = getInfo(name, &param);
1291f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
1292f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = result;
1293f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1294f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return param;
1295f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1296f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1297f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int getDevices(
1298f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_device_type type,
1299f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        VECTOR_CLASS<Device>* devices) const
1300f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1301f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_uint n = 0;
1302f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
1303f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != CL_SUCCESS) {
1304f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
1305f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1306f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1307f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
1308f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        err = ::clGetDeviceIDs(object_, type, n, ids, NULL);
1309f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != CL_SUCCESS) {
1310f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
1311f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1312f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1313f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        devices->assign(&ids[0], &ids[n]);
1314f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return CL_SUCCESS;
1315f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1316f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1317f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(USE_DX_INTEROP)
1318f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /*! \brief Get the list of available D3D10 devices.
1319f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
1320f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *  \param d3d_device_source.
1321f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
1322f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *  \param d3d_object.
1323f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
1324f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *  \param d3d_device_set.
1325f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
1326f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *  \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device
1327f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *  values returned in devices can be used to identify a specific OpenCL
1328f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *  device. If \a devices argument is NULL, this argument is ignored.
1329f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
1330f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *  \return One of the following values:
1331f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *    - CL_SUCCESS if the function is executed successfully.
1332f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
1333f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *  The application can query specific capabilities of the OpenCL device(s)
1334f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *  returned by cl::getDevices. This can be used by the application to
1335f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *  determine which device(s) to use.
1336f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     *
1337f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * \note In the case that exceptions are enabled and a return value
1338f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * other than CL_SUCCESS is generated, then cl::Error exception is
1339f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     * generated.
1340f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org     */
1341f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int getDevices(
1342f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_d3d10_device_source_khr d3d_device_source,
1343f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        void *                     d3d_object,
1344f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_d3d10_device_set_khr    d3d_device_set,
1345f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        VECTOR_CLASS<Device>* devices) const
1346f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1347f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
1348f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            cl_platform_id platform,
1349f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            cl_d3d10_device_source_khr d3d_device_source,
1350f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            void * d3d_object,
1351f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            cl_d3d10_device_set_khr d3d_device_set,
1352f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            cl_uint num_entries,
1353f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            cl_device_id * devices,
1354f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            cl_uint* num_devices);
1355f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1356f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
1357f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        __INIT_CL_EXT_FCN_PTR(clGetDeviceIDsFromD3D10KHR);
1358f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1359f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_uint n = 0;
1360f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
1361f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            object_,
1362f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            d3d_device_source,
1363f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            d3d_object,
1364f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            d3d_device_set,
1365f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            0,
1366f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            NULL,
1367f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            &n);
1368f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != CL_SUCCESS) {
1369f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
1370f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1371f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1372f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
1373f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        err = pfn_clGetDeviceIDsFromD3D10KHR(
1374f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            object_,
1375f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            d3d_device_source,
1376f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            d3d_object,
1377f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            d3d_device_set,
1378f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            n,
1379f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            ids,
1380f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            NULL);
1381f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != CL_SUCCESS) {
1382f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
1383f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1384f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1385f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        devices->assign(&ids[0], &ids[n]);
1386f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return CL_SUCCESS;
1387f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1388f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1389f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1390f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int get(
1391f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        VECTOR_CLASS<Platform>* platforms)
1392f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1393f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_uint n = 0;
1394f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int err = ::clGetPlatformIDs(0, NULL, &n);
1395f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != CL_SUCCESS) {
1396f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
1397f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1398f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1399f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_platform_id* ids = (cl_platform_id*) alloca(
1400f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            n * sizeof(cl_platform_id));
1401f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        err = ::clGetPlatformIDs(n, ids, NULL);
1402f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != CL_SUCCESS) {
1403f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
1404f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1405f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1406f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        platforms->assign(&ids[0], &ids[n]);
1407f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return CL_SUCCESS;
1408f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1409f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1410f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1411f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic inline cl_int
1412f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgUnloadCompiler()
1413f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1414f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return ::clUnloadCompiler();
1415f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1416f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1417f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Context : public detail::Wrapper<cl_context>
1418f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1419f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
1420f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Context(
1421f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const VECTOR_CLASS<Device>& devices,
1422f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_context_properties* properties = NULL,
1423f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        void (CL_CALLBACK * notifyFptr)(
1424f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            const char *,
1425f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            const void *,
1426f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            ::size_t,
1427f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            void *) = NULL,
1428f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        void* data = NULL,
1429f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int* err = NULL)
1430f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1431f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int error;
1432f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        object_ = ::clCreateContext(
1433f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            properties, (cl_uint) devices.size(),
1434f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            (cl_device_id*) &devices.front(),
1435f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            notifyFptr, data, &error);
1436f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1437f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
1438f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
1439f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = error;
1440f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1441f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1442f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1443f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Context(
1444f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_device_type type,
1445f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_context_properties* properties = NULL,
1446f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        void (CL_CALLBACK * notifyFptr)(
1447f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            const char *,
1448f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            const void *,
1449f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            ::size_t,
1450f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            void *) = NULL,
1451f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        void* data = NULL,
1452f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int* err = NULL)
1453f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1454f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int error;
1455f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        object_ = ::clCreateContextFromType(
1456f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            properties, type, notifyFptr, data, &error);
1457f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1458f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
1459f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
1460f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = error;
1461f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1462f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1463f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1464f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Context() : detail::Wrapper<cl_type>() { }
1465f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1466f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Context(const Context& context) : detail::Wrapper<cl_type>(context) { }
1467f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1468f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Context& operator = (const Context& rhs)
1469f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1470f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this != &rhs) {
1471f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::Wrapper<cl_type>::operator=(rhs);
1472f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1473f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
1474f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1475f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1476f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <typename T>
1477f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int getInfo(cl_context_info name, T* param) const
1478f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1479f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return detail::errHandler(
1480f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::getInfo(&::clGetContextInfo, object_, name, param),
1481f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            __GET_CONTEXT_INFO_ERR);
1482f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1483f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1484f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <cl_int name> typename
1485f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    detail::param_traits<detail::cl_context_info, name>::param_type
1486f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    getInfo(cl_int* err = NULL) const
1487f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1488f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        typename detail::param_traits<
1489f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::cl_context_info, name>::param_type param;
1490f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int result = getInfo(name, &param);
1491f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
1492f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = result;
1493f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1494f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return param;
1495f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1496f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1497f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int getSupportedImageFormats(
1498f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_mem_flags flags,
1499f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_mem_object_type type,
1500f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        VECTOR_CLASS<ImageFormat>* formats) const
1501f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1502f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_uint numEntries;
1503f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int err = ::clGetSupportedImageFormats(
1504f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org           object_,
1505f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org           flags,
1506f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org           type,
1507f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org           0,
1508f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org           NULL,
1509f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org           &numEntries);
1510f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != CL_SUCCESS) {
1511f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
1512f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1513f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1514f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ImageFormat* value = (ImageFormat*)
1515f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            alloca(numEntries * sizeof(ImageFormat));
1516f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        err = ::clGetSupportedImageFormats(
1517f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            object_,
1518f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            flags,
1519f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            type,
1520f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            numEntries,
1521f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            (cl_image_format*) value,
1522f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            NULL);
1523f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != CL_SUCCESS) {
1524f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
1525f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1526f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1527f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        formats->assign(&value[0], &value[numEntries]);
1528f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return CL_SUCCESS;
1529f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1530f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1531f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1532f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org__GET_INFO_HELPER_WITH_RETAIN(cl::Context)
1533f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1534f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class Event
1535f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Event interface for cl_event.
1536f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
1537f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Event : public detail::Wrapper<cl_event>
1538f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1539f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
1540f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Event() : detail::Wrapper<cl_type>() { }
1541f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1542f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Event(const Event& event) : detail::Wrapper<cl_type>(event) { }
1543f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1544f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Event& operator = (const Event& rhs)
1545f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1546f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this != &rhs) {
1547f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::Wrapper<cl_type>::operator=(rhs);
1548f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1549f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
1550f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1551f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1552f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <typename T>
1553f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int getInfo(cl_event_info name, T* param) const
1554f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1555f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return detail::errHandler(
1556f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::getInfo(&::clGetEventInfo, object_, name, param),
1557f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            __GET_EVENT_INFO_ERR);
1558f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1559f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1560f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <cl_int name> typename
1561f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    detail::param_traits<detail::cl_event_info, name>::param_type
1562f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    getInfo(cl_int* err = NULL) const
1563f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1564f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        typename detail::param_traits<
1565f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::cl_event_info, name>::param_type param;
1566f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int result = getInfo(name, &param);
1567f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
1568f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = result;
1569f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1570f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return param;
1571f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1572f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1573f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <typename T>
1574f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int getProfilingInfo(cl_profiling_info name, T* param) const
1575f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1576f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return detail::errHandler(detail::getInfo(
1577f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            &::clGetEventProfilingInfo, object_, name, param),
1578f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            __GET_EVENT_PROFILE_INFO_ERR);
1579f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1580f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1581f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <cl_int name> typename
1582f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    detail::param_traits<detail::cl_profiling_info, name>::param_type
1583f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    getProfilingInfo(cl_int* err = NULL) const
1584f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1585f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        typename detail::param_traits<
1586f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::cl_profiling_info, name>::param_type param;
1587f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int result = getProfilingInfo(name, &param);
1588f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
1589f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = result;
1590f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1591f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return param;
1592f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1593f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1594f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int wait() const
1595f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1596f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return detail::errHandler(
1597f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            ::clWaitForEvents(1, &object_),
1598f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            __WAIT_FOR_EVENTS_ERR);
1599f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1600f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1601f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(CL_VERSION_1_1)
1602f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int setCallback(
1603f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int type,
1604f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
1605f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        void * user_data = NULL)
1606f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1607f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return detail::errHandler(
1608f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            ::clSetEventCallback(
1609f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                object_,
1610f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                type,
1611f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                pfn_notify,
1612f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                user_data),
1613f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            __SET_EVENT_CALLBACK_ERR);
1614f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1615f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1616f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1617f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static cl_int
1618f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    waitForEvents(const VECTOR_CLASS<Event>& events)
1619f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1620f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return detail::errHandler(
1621f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            ::clWaitForEvents(
1622f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                (cl_uint) events.size(), (cl_event*)&events.front()),
1623f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            __WAIT_FOR_EVENTS_ERR);
1624f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1625f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1626f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1627f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org__GET_INFO_HELPER_WITH_RETAIN(cl::Event)
1628f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1629f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(CL_VERSION_1_1)
1630f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class UserEvent
1631f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief User event interface for cl_event.
1632f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
1633f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass UserEvent : public Event
1634f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1635f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
1636f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    UserEvent(
1637f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const Context& context,
1638f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int * err = NULL)
1639f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1640f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int error;
1641f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        object_ = ::clCreateUserEvent(
1642f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            context(),
1643f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            &error);
1644f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1645f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        detail::errHandler(error, __CREATE_USER_EVENT_ERR);
1646f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
1647f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = error;
1648f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1649f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1650f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1651f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    UserEvent() : Event() { }
1652f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1653f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    UserEvent(const UserEvent& event) : Event(event) { }
1654f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1655f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    UserEvent& operator = (const UserEvent& rhs)
1656f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1657f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this != &rhs) {
1658f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            Event::operator=(rhs);
1659f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1660f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
1661f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1662f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1663f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int setStatus(cl_int status)
1664f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1665f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return detail::errHandler(
1666f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            ::clSetUserEventStatus(object_,status),
1667f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            __SET_USER_EVENT_STATUS_ERR);
1668f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1669f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1670f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1671f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1672f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline static cl_int
1673f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgWaitForEvents(const VECTOR_CLASS<Event>& events)
1674f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1675f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return detail::errHandler(
1676f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ::clWaitForEvents(
1677f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            (cl_uint) events.size(), (cl_event*)&events.front()),
1678f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        __WAIT_FOR_EVENTS_ERR);
1679f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
1680f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1681f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class Memory
1682f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Memory interface for cl_mem.
1683f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
1684f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Memory : public detail::Wrapper<cl_mem>
1685f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1686f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
1687f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Memory() : detail::Wrapper<cl_type>() { }
1688f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1689f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Memory(const Memory& memory) : detail::Wrapper<cl_type>(memory) { }
1690f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1691f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Memory& operator = (const Memory& rhs)
1692f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1693f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this != &rhs) {
1694f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::Wrapper<cl_type>::operator=(rhs);
1695f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1696f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
1697f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1698f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1699f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <typename T>
1700f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int getInfo(cl_mem_info name, T* param) const
1701f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1702f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return detail::errHandler(
1703f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
1704f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            __GET_MEM_OBJECT_INFO_ERR);
1705f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1706f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1707f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <cl_int name> typename
1708f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    detail::param_traits<detail::cl_mem_info, name>::param_type
1709f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    getInfo(cl_int* err = NULL) const
1710f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1711f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        typename detail::param_traits<
1712f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::cl_mem_info, name>::param_type param;
1713f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int result = getInfo(name, &param);
1714f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
1715f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = result;
1716f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1717f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return param;
1718f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1719f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1720f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(CL_VERSION_1_1)
1721f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int setDestructorCallback(
1722f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
1723f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        void * user_data = NULL)
1724f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1725f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return detail::errHandler(
1726f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            ::clSetMemObjectDestructorCallback(
1727f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                object_,
1728f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                pfn_notify,
1729f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                user_data),
1730f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
1731f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1732f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1733f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1734f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1735f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1736f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org__GET_INFO_HELPER_WITH_RETAIN(cl::Memory)
1737f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1738f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class Buffer
1739f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Memory buffer interface.
1740f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
1741f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Buffer : public Memory
1742f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1743f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
1744f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Buffer(
1745f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const Context& context,
1746f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_mem_flags flags,
1747f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ::size_t size,
1748f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        void* host_ptr = NULL,
1749f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int* err = NULL)
1750f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1751f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int error;
1752f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
1753f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1754f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        detail::errHandler(error, __CREATE_BUFFER_ERR);
1755f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
1756f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = error;
1757f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1758f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1759f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1760f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Buffer() : Memory() { }
1761f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1762f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Buffer(const Buffer& buffer) : Memory(buffer) { }
1763f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1764f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Buffer& operator = (const Buffer& rhs)
1765f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1766f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this != &rhs) {
1767f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            Memory::operator=(rhs);
1768f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1769f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
1770f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1771f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1772f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(CL_VERSION_1_1)
1773f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Buffer createSubBuffer(
1774f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_mem_flags flags,
1775f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_buffer_create_type buffer_create_type,
1776f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const void * buffer_create_info,
1777f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int * err = NULL)
1778f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1779f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        Buffer result;
1780f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int error;
1781f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        result.object_ = ::clCreateSubBuffer(
1782f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            object_,
1783f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            flags,
1784f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            buffer_create_type,
1785f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            buffer_create_info,
1786f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            &error);
1787f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1788f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
1789f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
1790f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = error;
1791f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1792f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1793f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return result;
1794f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	}
1795f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1796f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1797f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1798f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined (USE_DX_INTEROP)
1799f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass BufferD3D10 : public Buffer
1800f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1801f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
1802f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
1803f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_context context, cl_mem_flags flags, ID3D10Buffer*  buffer,
1804f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int* errcode_ret);
1805f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1806f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    BufferD3D10(
1807f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const Context& context,
1808f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_mem_flags flags,
1809f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ID3D10Buffer* bufobj,
1810f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int * err = NULL)
1811f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1812f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        static PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR = NULL;
1813f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        __INIT_CL_EXT_FCN_PTR(clCreateFromD3D10BufferKHR);
1814f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1815f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int error;
1816f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        object_ = pfn_clCreateFromD3D10BufferKHR(
1817f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            context(),
1818f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            flags,
1819f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            bufobj,
1820f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            &error);
1821f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1822f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
1823f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
1824f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = error;
1825f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1826f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1827f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1828f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    BufferD3D10() : Buffer() { }
1829f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1830f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    BufferD3D10(const BufferD3D10& buffer) : Buffer(buffer) { }
1831f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1832f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    BufferD3D10& operator = (const BufferD3D10& rhs)
1833f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1834f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this != &rhs) {
1835f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            Buffer::operator=(rhs);
1836f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1837f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
1838f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1839f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1840f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
1841f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1842f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class BufferGL
1843f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Memory buffer interface for GL interop.
1844f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
1845f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass BufferGL : public Buffer
1846f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1847f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
1848f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    BufferGL(
1849f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const Context& context,
1850f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_mem_flags flags,
1851f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        GLuint bufobj,
1852f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int * err = NULL)
1853f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1854f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int error;
1855f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        object_ = ::clCreateFromGLBuffer(
1856f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            context(),
1857f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            flags,
1858f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            bufobj,
1859f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            &error);
1860f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1861f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
1862f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
1863f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = error;
1864f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1865f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1866f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1867f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    BufferGL() : Buffer() { }
1868f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1869f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    BufferGL(const BufferGL& buffer) : Buffer(buffer) { }
1870f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1871f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    BufferGL& operator = (const BufferGL& rhs)
1872f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1873f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this != &rhs) {
1874f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            Buffer::operator=(rhs);
1875f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1876f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
1877f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1878f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1879f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int getObjectInfo(
1880f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_gl_object_type *type,
1881f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        GLuint * gl_object_name)
1882f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1883f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return detail::errHandler(
1884f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            ::clGetGLObjectInfo(object_,type,gl_object_name),
1885f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            __GET_GL_OBJECT_INFO_ERR);
1886f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1887f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1888f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1889f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class BufferRenderGL
1890f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Memory buffer interface for GL interop with renderbuffer.
1891f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
1892f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass BufferRenderGL : public Buffer
1893f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1894f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
1895f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    BufferRenderGL(
1896f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const Context& context,
1897f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_mem_flags flags,
1898f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        GLuint bufobj,
1899f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int * err = NULL)
1900f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1901f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int error;
1902f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        object_ = ::clCreateFromGLRenderbuffer(
1903f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            context(),
1904f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            flags,
1905f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            bufobj,
1906f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            &error);
1907f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1908f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
1909f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
1910f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = error;
1911f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1912f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1913f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1914f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    BufferRenderGL() : Buffer() { }
1915f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1916f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    BufferRenderGL(const BufferGL& buffer) : Buffer(buffer) { }
1917f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1918f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    BufferRenderGL& operator = (const BufferRenderGL& rhs)
1919f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1920f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this != &rhs) {
1921f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            Buffer::operator=(rhs);
1922f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1923f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
1924f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1925f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1926f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int getObjectInfo(
1927f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_gl_object_type *type,
1928f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        GLuint * gl_object_name)
1929f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1930f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return detail::errHandler(
1931f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            ::clGetGLObjectInfo(object_,type,gl_object_name),
1932f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            __GET_GL_OBJECT_INFO_ERR);
1933f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1934f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1935f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1936f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class Image
1937f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Base class  interface for all images.
1938f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
1939f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Image : public Memory
1940f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1941f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgprotected:
1942f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Image() : Memory() { }
1943f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1944f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Image(const Image& image) : Memory(image) { }
1945f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1946f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Image& operator = (const Image& rhs)
1947f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1948f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this != &rhs) {
1949f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            Memory::operator=(rhs);
1950f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1951f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
1952f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1953f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
1954f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <typename T>
1955f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int getImageInfo(cl_image_info name, T* param) const
1956f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1957f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return detail::errHandler(
1958f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::getInfo(&::clGetImageInfo, object_, name, param),
1959f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            __GET_IMAGE_INFO_ERR);
1960f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1961f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1962f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <cl_int name> typename
1963f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    detail::param_traits<detail::cl_image_info, name>::param_type
1964f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    getImageInfo(cl_int* err = NULL) const
1965f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1966f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        typename detail::param_traits<
1967f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::cl_image_info, name>::param_type param;
1968f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int result = getImageInfo(name, &param);
1969f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
1970f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = result;
1971f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
1972f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return param;
1973f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
1974f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
1975f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1976f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class Image2D
1977f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Image interface for 2D images.
1978f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
1979f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Image2D : public Image
1980f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
1981f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
1982f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Image2D(
1983f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const Context& context,
1984f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_mem_flags flags,
1985f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ImageFormat format,
1986f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ::size_t width,
1987f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ::size_t height,
1988f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ::size_t row_pitch = 0,
1989f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        void* host_ptr = NULL,
1990f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int* err = NULL)
1991f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
1992f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int error;
1993f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        object_ = ::clCreateImage2D(
1994f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            context(), flags,&format, width, height, row_pitch, host_ptr, &error);
1995f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
1996f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        detail::errHandler(error, __CREATE_IMAGE2D_ERR);
1997f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
1998f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = error;
1999f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
2000f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2001f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2002f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Image2D() { }
2003f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2004f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Image2D(const Image2D& image2D) : Image(image2D) { }
2005f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2006f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Image2D& operator = (const Image2D& rhs)
2007f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2008f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this != &rhs) {
2009f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            Image::operator=(rhs);
2010f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
2011f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
2012f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2013f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
2014f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2015f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class Image2DGL
2016f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief 2D image interface for GL interop.
2017f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
2018f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Image2DGL : public Image2D
2019f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
2020f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
2021f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Image2DGL(
2022f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const Context& context,
2023f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_mem_flags flags,
2024f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        GLenum target,
2025f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        GLint  miplevel,
2026f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        GLuint texobj,
2027f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int * err = NULL)
2028f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2029f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int error;
2030f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        object_ = ::clCreateFromGLTexture2D(
2031f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            context(),
2032f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            flags,
2033f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            target,
2034f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            miplevel,
2035f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            texobj,
2036f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            &error);
2037f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2038f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
2039f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
2040f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = error;
2041f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
2042f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2043f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2044f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Image2DGL() : Image2D() { }
2045f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2046f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Image2DGL(const Image2DGL& image) : Image2D(image) { }
2047f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2048f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Image2DGL& operator = (const Image2DGL& rhs)
2049f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2050f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this != &rhs) {
2051f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            Image2D::operator=(rhs);
2052f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
2053f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
2054f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2055f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
2056f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2057f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class Image3D
2058f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Image interface for 3D images.
2059f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
2060f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Image3D : public Image
2061f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
2062f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
2063f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Image3D(
2064f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const Context& context,
2065f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_mem_flags flags,
2066f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ImageFormat format,
2067f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ::size_t width,
2068f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ::size_t height,
2069f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ::size_t depth,
2070f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ::size_t row_pitch = 0,
2071f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ::size_t slice_pitch = 0,
2072f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        void* host_ptr = NULL,
2073f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int* err = NULL)
2074f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2075f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int error;
2076f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        object_ = ::clCreateImage3D(
2077f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            context(), flags, &format, width, height, depth, row_pitch,
2078f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            slice_pitch, host_ptr, &error);
2079f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2080f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        detail::errHandler(error, __CREATE_IMAGE3D_ERR);
2081f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
2082f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = error;
2083f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
2084f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2085f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2086f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Image3D() { }
2087f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2088f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Image3D(const Image3D& image3D) : Image(image3D) { }
2089f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2090f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Image3D& operator = (const Image3D& rhs)
2091f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2092f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this != &rhs) {
2093f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            Image::operator=(rhs);
2094f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
2095f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
2096f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2097f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
2098f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2099f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class Image2DGL
2100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief 2D image interface for GL interop.
2101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
2102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Image3DGL : public Image3D
2103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
2104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
2105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Image3DGL(
2106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const Context& context,
2107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_mem_flags flags,
2108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        GLenum target,
2109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        GLint  miplevel,
2110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        GLuint texobj,
2111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int * err = NULL)
2112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int error;
2114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        object_ = ::clCreateFromGLTexture3D(
2115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            context(),
2116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            flags,
2117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            target,
2118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            miplevel,
2119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            texobj,
2120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            &error);
2121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
2123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
2124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = error;
2125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
2126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Image3DGL() : Image3D() { }
2129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Image3DGL(const Image3DGL& image) : Image3D(image) { }
2131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Image3DGL& operator = (const Image3DGL& rhs)
2133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this != &rhs) {
2135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            Image3D::operator=(rhs);
2136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
2137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
2138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
2140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class Sampler
2142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Sampler interface for cl_sampler.
2143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
2144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Sampler : public detail::Wrapper<cl_sampler>
2145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
2146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
2147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Sampler() { }
2148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Sampler(
2150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const Context& context,
2151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_bool normalized_coords,
2152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_addressing_mode addressing_mode,
2153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_filter_mode filter_mode,
2154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int* err = NULL)
2155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int error;
2157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        object_ = ::clCreateSampler(
2158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            context(),
2159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            normalized_coords,
2160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            addressing_mode,
2161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            filter_mode,
2162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            &error);
2163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        detail::errHandler(error, __CREATE_SAMPLER_ERR);
2165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
2166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = error;
2167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
2168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Sampler(const Sampler& sampler) : detail::Wrapper<cl_type>(sampler) { }
2171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Sampler& operator = (const Sampler& rhs)
2173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this != &rhs) {
2175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::Wrapper<cl_type>::operator=(rhs);
2176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
2177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
2178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <typename T>
2181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int getInfo(cl_sampler_info name, T* param) const
2182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return detail::errHandler(
2184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::getInfo(&::clGetSamplerInfo, object_, name, param),
2185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            __GET_SAMPLER_INFO_ERR);
2186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <cl_int name> typename
2189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    detail::param_traits<detail::cl_sampler_info, name>::param_type
2190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    getInfo(cl_int* err = NULL) const
2191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        typename detail::param_traits<
2193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::cl_sampler_info, name>::param_type param;
2194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int result = getInfo(name, &param);
2195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
2196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = result;
2197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
2198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return param;
2199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
2201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org__GET_INFO_HELPER_WITH_RETAIN(cl::Sampler)
2203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Program;
2205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass CommandQueue;
2206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Kernel;
2207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class NDRange
2209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief NDRange interface
2210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
2211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass NDRange
2212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
2213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgprivate:
2214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    size_t<3> sizes_;
2215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_uint dimensions_;
2216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
2218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    NDRange()
2219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        : dimensions_(0)
2220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    { }
2221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    NDRange(::size_t size0)
2223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        : dimensions_(1)
2224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        sizes_.push_back(size0);
2226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    NDRange(::size_t size0, ::size_t size1)
2229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        : dimensions_(2)
2230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        sizes_.push_back(size0);
2232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        sizes_.push_back(size1);
2233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2234f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2235f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    NDRange(::size_t size0, ::size_t size1, ::size_t size2)
2236f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        : dimensions_(3)
2237f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2238f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        sizes_.push_back(size0);
2239f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        sizes_.push_back(size1);
2240f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        sizes_.push_back(size2);
2241f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2242f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2243f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    operator const ::size_t*() const { return (const ::size_t*) sizes_; }
2244f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ::size_t dimensions() const { return dimensions_; }
2245f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
2246f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2247f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic const NDRange NullRange;
2248f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2249f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*!
2250f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \struct LocalSpaceArg
2251f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Local address raper for use with Kernel::setArg
2252f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
2253f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct LocalSpaceArg
2254f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
2255f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    ::size_t size_;
2256f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
2257f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2258f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgnamespace detail {
2259f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2260f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <typename T>
2261f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct KernelArgumentHandler
2262f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
2263f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static ::size_t size(const T&) { return sizeof(T); }
2264f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static T* ptr(T& value) { return &value; }
2265f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
2266f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2267f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtemplate <>
2268f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct KernelArgumentHandler<LocalSpaceArg>
2269f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
2270f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static ::size_t size(const LocalSpaceArg& value) { return value.size_; }
2271f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    static void* ptr(LocalSpaceArg&) { return NULL; }
2272f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
2273f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2274f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
2275f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org//! \endcond
2276f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2277f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orginline LocalSpaceArg
2278f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org__local(::size_t size)
2279f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
2280f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    LocalSpaceArg ret = { size };
2281f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    return ret;
2282f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
2283f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2284f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass KernelFunctor;
2285f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2286f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class Kernel
2287f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Kernel interface that implements cl_kernel
2288f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
2289f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Kernel : public detail::Wrapper<cl_kernel>
2290f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
2291f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
2292f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    inline Kernel(const Program& program, const char* name, cl_int* err = NULL);
2293f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2294f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Kernel() { }
2295f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2296f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Kernel(const Kernel& kernel) : detail::Wrapper<cl_type>(kernel) { }
2297f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2298f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Kernel& operator = (const Kernel& rhs)
2299f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2300f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (this != &rhs) {
2301f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::Wrapper<cl_type>::operator=(rhs);
2302f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
2303f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return *this;
2304f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2305f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2306f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <typename T>
2307f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int getInfo(cl_kernel_info name, T* param) const
2308f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2309f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return detail::errHandler(
2310f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::getInfo(&::clGetKernelInfo, object_, name, param),
2311f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            __GET_KERNEL_INFO_ERR);
2312f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2313f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2314f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <cl_int name> typename
2315f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    detail::param_traits<detail::cl_kernel_info, name>::param_type
2316f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    getInfo(cl_int* err = NULL) const
2317f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2318f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        typename detail::param_traits<
2319f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::cl_kernel_info, name>::param_type param;
2320f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int result = getInfo(name, &param);
2321f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
2322f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = result;
2323f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
2324f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return param;
2325f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2326f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2327f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <typename T>
2328f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int getWorkGroupInfo(
2329f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const Device& device, cl_kernel_work_group_info name, T* param) const
2330f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2331f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return detail::errHandler(
2332f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            detail::getInfo(
2333f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                &::clGetKernelWorkGroupInfo, object_, device(), name, param),
2334f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                __GET_KERNEL_WORK_GROUP_INFO_ERR);
2335f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2336f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2337f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <cl_int name> typename
2338f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
2339f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        getWorkGroupInfo(const Device& device, cl_int* err = NULL) const
2340f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2341f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        typename detail::param_traits<
2342f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        detail::cl_kernel_work_group_info, name>::param_type param;
2343f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int result = getWorkGroupInfo(device, name, &param);
2344f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        if (err != NULL) {
2345f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            *err = result;
2346f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
2347f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return param;
2348f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2349f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2350f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    template <typename T>
2351f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int setArg(cl_uint index, T value)
2352f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2353f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return detail::errHandler(
2354f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            ::clSetKernelArg(
2355f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                object_,
2356f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                index,
2357f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                detail::KernelArgumentHandler<T>::size(value),
2358f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                detail::KernelArgumentHandler<T>::ptr(value)),
2359f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            __SET_KERNEL_ARGS_ERR);
2360f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2361f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2362f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    cl_int setArg(cl_uint index, ::size_t size, void* argPtr)
2363f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2364f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        return detail::errHandler(
2365f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            ::clSetKernelArg(object_, index, size, argPtr),
2366f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            __SET_KERNEL_ARGS_ERR);
2367f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    }
2368f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2369f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    KernelFunctor bind(
2370f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const CommandQueue& queue,
2371f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const NDRange& offset,
2372f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const NDRange& global,
2373f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const NDRange& local);
2374f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2375f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    KernelFunctor bind(
2376f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const CommandQueue& queue,
2377f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const NDRange& global,
2378f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const NDRange& local);
2379f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
2380f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2381f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org__GET_INFO_HELPER_WITH_RETAIN(cl::Kernel)
2382f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2383f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*! \class Program
2384f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Program interface that implements cl_program.
2385f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
2386f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgclass Program : public detail::Wrapper<cl_program>
2387f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
2388f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgpublic:
2389f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    typedef VECTOR_CLASS<std::pair<const void*, ::size_t> > Binaries;
2390f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    typedef VECTOR_CLASS<std::pair<const char*, ::size_t> > Sources;
2391f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2392f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    Program(
2393f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const Context& context,
2394f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const Sources& sources,
2395f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int* err = NULL)
2396f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    {
2397f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        cl_int error;
2398f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2399f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const ::size_t n = (::size_t)sources.size();
2400f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        ::size_t* lengths = (::size_t*) alloca(n * sizeof(::size_t));
2401f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        const char** strings = (const char**) alloca(n * sizeof(const char*));
2402f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
2403f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        for (::size_t i = 0; i < n; ++i) {
2404f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            strings[i] = sources[(int)i].first;
2405f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            lengths[i] = sources[(int)i].second;
2406f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org        }
2407f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org<